/* AIIHServer - 深色科技感 UI（参考 EdgeOps） */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-primary: #0b1020;
    --bg-secondary: #111827;
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-input: rgba(15, 23, 42, 0.8);
    --border: rgba(100, 116, 139, 0.3);
    --border-hover: rgba(59, 130, 246, 0.5);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --transition: all 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: radial-gradient(circle at top, #1e293b, #0b1020);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
.text-muted { color: var(--text-muted); }

#app { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}
.sidebar-header { padding: 20px; border-bottom: 1px solid var(--border); text-align: center; }
.sidebar-header h1 { font-size: 20px; color: var(--accent); letter-spacing: 2px; }
.sidebar-header .subtitle { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

/* 细滚动条（侧栏 + 自运维等） */
.sidebar-nav,
.ai-ops-scrollable {
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 130, 246, 0.45) rgba(15, 23, 42, 0.35);
}
.sidebar-nav::-webkit-scrollbar,
.ai-ops-scrollable::-webkit-scrollbar { width: 8px; height: 8px; }
.sidebar-nav::-webkit-scrollbar-track,
.ai-ops-scrollable::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.35);
    border-radius: 8px;
}
.sidebar-nav::-webkit-scrollbar-thumb,
.ai-ops-scrollable::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(59, 130, 246, 0.55), rgba(6, 182, 212, 0.4));
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover,
.ai-ops-scrollable::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(59, 130, 246, 0.75), rgba(6, 182, 212, 0.55));
    background-clip: padding-box;
}
.nav-item {
    display: flex; align-items: center; padding: 10px 20px;
    color: var(--text-secondary); cursor: pointer; transition: var(--transition);
    border-left: 3px solid transparent; gap: 10px; font-size: 14px;
}
.nav-item:hover { background: rgba(59, 130, 246, 0.1); color: var(--text-primary); }
.nav-item.active { background: rgba(59, 130, 246, 0.15); color: var(--accent); border-left-color: var(--accent); }
.nav-divider { height: 1px; background: var(--border); margin: 8px 16px; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); }
.sidebar-footer .username { color: var(--text-secondary); font-weight: 500; }
.sidebar-footer .sidebar-version { margin-top: 8px; font-size: 11px; opacity: 0.8; }

.main-content { margin-left: 240px; flex: 1; min-height: 100vh; display: flex; flex-direction: column; }
/* AI 自运维页：聊天与历史区域与网页高度一致 */
.main-content.ai-ops-page #page-content { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0; }
.main-content.ai-ops-page #page-content .ai-ops-body { flex: 1; min-height: 0; display: flex; gap: 16px; padding: 0 24px 24px 24px; }
.topbar {
    height: 56px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar h2 { font-size: 16px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.page-content { padding: 24px; }

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(10px);
    padding: 20px;
    margin-bottom: 16px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.card-header h3 { font-size: 15px; font-weight: 600; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-align: center;
    backdrop-filter: blur(10px);
    transition: var(--transition);
}
.stat-card .stat-value { font-size: 32px; font-weight: 700; margin-bottom: 4px; }
.stat-card .stat-label { font-size: 13px; color: var(--text-secondary); }
.stat-card.total .stat-value { color: var(--accent); }

.table-container { overflow-x: auto; }
.table-container table { width: 100%; border-collapse: collapse; }
.table-container th, .table-container td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.table-container th { color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.form-control {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}
.form-control:focus { border-color: var(--accent); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition);
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-online { background: rgba(16,185,129,0.2); color: var(--success); }
.badge-admin { background: rgba(59,130,246,0.2); color: var(--accent); }
.badge-user { background: rgba(100,116,139,0.2); color: var(--text-secondary); }
.badge-warning { background: rgba(245,158,11,0.2); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.2); color: var(--danger); }
.badge-muted { background: rgba(100,116,139,0.2); color: var(--text-muted); }

.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 800px;
    min-width: 800px;
    max-width: 95vw;
    height: 80vh;
    min-height: 400px;
    max-height: 90vh;
    overflow: auto;
    resize: both;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 20px; }
.modal-body { padding: 20px; overflow: auto; flex: 1; min-height: 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--border); flex-shrink: 0; }

.toast-container { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: var(--radius); border: 1px solid var(--border); font-size: 13px; max-width: 400px; }
.toast-success { background: rgba(16,185,129,0.15); border-color: var(--success); color: var(--success); }
.toast-error { background: rgba(239,68,68,0.15); border-color: var(--danger); color: var(--danger); }
.toast-info { background: rgba(59,130,246,0.15); border-color: var(--accent); color: var(--accent); }

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top, #1e293b, #0b1020);
}
.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 400px;
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
}
.auth-card h1 { text-align: center; margin-bottom: 8px; color: var(--accent); font-size: 24px; letter-spacing: 3px; }
.auth-card .auth-subtitle { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 32px; }
.auth-card .form-control { padding: 10px 14px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 10px; font-size: 15px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-muted); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { color: var(--text-secondary); margin-bottom: 8px; }

.loading-overlay { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px; gap: 12px; min-height: 120px; }
.loading-overlay .spinner { flex-shrink: 0; }
.loading-overlay .loading-text { font-size: 13px; color: var(--text-muted); }
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.code-block { font-family: monospace; font-size: 12px; background: var(--bg-input); padding: 12px; border-radius: var(--radius); word-break: break-all; }

/* AI 自运维 Markdown 输出（含表格） */
.ai-ops-markdown .md-body { font-size: 14px; line-height: 1.6; }
.ai-ops-markdown .md-body p { margin: 0 0 8px; }
.ai-ops-markdown .md-body p:last-child { margin-bottom: 0; }
.ai-ops-markdown .md-body ul, .ai-ops-markdown .md-body ol { margin: 8px 0; padding-left: 24px; }
.ai-ops-markdown .md-body code { background: var(--bg-input); padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.ai-ops-markdown .md-body pre { background: var(--bg-input); padding: 12px; border-radius: var(--radius); overflow-x: auto; margin: 8px 0; }
.ai-ops-markdown .md-body pre code { padding: 0; background: none; }
.ai-ops-markdown .md-body table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.ai-ops-markdown .md-body th, .ai-ops-markdown .md-body td { padding: 8px 12px; text-align: left; border: 1px solid var(--border); }
.ai-ops-markdown .md-body th { background: rgba(59,130,246,0.1); font-weight: 600; }
.ai-ops-markdown .md-body h1, .ai-ops-markdown .md-body h2, .ai-ops-markdown .md-body h3 { margin: 12px 0 8px; font-size: 1em; }

/* AI 自运维：执行过程状态条 */
.ai-ops-status-log {
    font-size: 12px;
    line-height: 1.45;
    margin: 0 0 10px;
    padding: 8px 10px;
    border-radius: var(--radius);
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(100, 116, 139, 0.25);
    max-height: 200px;
    overflow-y: auto;
}
.ai-ops-status-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(100, 116, 139, 0.15);
}
.ai-ops-status-row:last-child { border-bottom: none; padding-bottom: 0; }
.ai-ops-status-row--phase {
    color: var(--text-secondary);
    padding-left: 2px;
}
.ai-ops-status-row--running .ai-ops-status-text { color: var(--text-primary); }
.ai-ops-status-row--ok .ai-ops-status-text { color: var(--success); }
.ai-ops-status-row--err .ai-ops-status-text { color: var(--danger); }
.ai-ops-status-pulse {
    width: 8px;
    height: 8px;
    margin-top: 5px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--accent);
    animation: ai-ops-pulse 1s ease-in-out infinite;
}
@keyframes ai-ops-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.45; transform: scale(0.92); }
}
.ai-ops-status-icon {
    flex-shrink: 0;
    width: 16px;
    text-align: center;
    font-size: 12px;
    line-height: 1.4;
}
.ai-ops-md-streaming { min-height: 1.4em; font-family: inherit; }
.ai-ops-caret {
    display: inline-block;
    margin-left: 1px;
    color: var(--accent);
    font-weight: 300;
    animation: ai-ops-caret-blink 0.95s step-end infinite;
}
@keyframes ai-ops-caret-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* 用量统计页：天/周/月/年条形图 */
.usage-chart { font-size: 13px; }
.usage-chart-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.usage-chart-label { min-width: 90px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.usage-chart-bar-wrap { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.usage-chart-bar { height: 20px; background: linear-gradient(90deg, var(--accent), var(--info)); border-radius: 4px; min-width: 4px; transition: width 0.3s ease; }
.usage-chart-value { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

.dashboard-two-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 720px) { .dashboard-two-charts { grid-template-columns: 1fr; } }

/* 消息通知：Markdown 编辑器所见即所得预览 */
.message-editor-preview-wrap { margin-top: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-input); padding: 12px; }
.message-editor-preview-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.message-editor-preview { min-height: 120px; max-height: 280px; overflow-y: auto; font-size: 14px; line-height: 1.5; }
.message-editor-input { font-family: inherit; resize: vertical; }
.message-view-body { min-height: 60px; padding: 12px; border-radius: var(--radius); background: var(--bg-input); overflow-y: auto; max-height: 360px; }
/* Markdown 渲染（消息编辑预览与查看） */
.md-body h1, .md-body h2, .md-body h3 { margin: 12px 0 8px; font-size: 1.05em; }
.md-body h1 { font-size: 1.25em; }
.md-body p { margin: 8px 0; }
.md-body ul, .md-body ol { margin: 8px 0; padding-left: 24px; }
.md-body code { background: rgba(0,0,0,0.2); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
.md-body pre { margin: 8px 0; padding: 12px; background: rgba(0,0,0,0.2); border-radius: var(--radius); overflow-x: auto; }
.md-body pre code { background: none; padding: 0; }
.md-body blockquote { border-left: 4px solid var(--accent); margin: 8px 0; padding-left: 12px; color: var(--text-secondary); }
.md-body a { color: var(--accent); }
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.md-body table { border-collapse: collapse; width: 100%; margin: 8px 0; }
.md-body th, .md-body td { padding: 6px 10px; text-align: left; border: 1px solid var(--border); }
.md-body th { background: rgba(59,130,246,0.1); font-weight: 600; }
