:root {
  --bg-0: #08090d; --bg-1: #0f1117; --bg-2: #181b25; --bg-3: #1f2333;
  --border: #2a2e3d; --text: #e4e4e7; --text-2: #9ca3b0; --text-3: #5f6577;
  --accent: #3b82f6; --accent-hover: #2563eb; --success: #22c55e; --warning: #f59e0b; --danger: #ef4444;
  --radius: 8px; --font: 'Inter', system-ui, -apple-system, sans-serif; --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; background: var(--bg-0); color: var(--text); font-family: var(--font); font-size: 14px; overflow: hidden; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 3px; }

/* Login */
#login-overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg-0); z-index: 1000; }
#login-form { background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; padding: 40px; width: 360px; text-align: center; }
#login-form h2 { margin: 12px 0 4px; font-size: 22px; }
#login-form .login-icon { font-size: 48px; }
#login-form input { width: 100%; padding: 10px 14px; margin: 20px 0 12px; background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 14px; outline: none; }
#login-form input:focus { border-color: var(--accent); }
#login-form button { width: 100%; padding: 10px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-size: 14px; cursor: pointer; }
#login-form button:hover { background: var(--accent-hover); }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }

/* Navbar */
#navbar { display: flex; align-items: center; justify-content: space-between; height: 48px; background: var(--bg-1); border-bottom: 1px solid var(--border); padding: 0 16px; flex-shrink: 0; }
.nav-left, .nav-right { display: flex; align-items: center; gap: 4px; }
.nav-brand { font-weight: 700; font-size: 15px; margin-right: 16px; color: var(--accent); }
.nav-tab { background: none; border: none; color: var(--text-2); padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; font-family: var(--font); transition: all .15s; }
.nav-tab:hover { color: var(--text); background: var(--bg-2); }
.nav-tab.active { color: var(--text); background: var(--bg-3); }
.btn-ghost { background: none; border: none; color: var(--text-2); cursor: pointer; font-size: 13px; padding: 4px 10px; border-radius: 4px; font-family: var(--font); }
.btn-ghost:hover { color: var(--text); background: var(--bg-2); }

/* App layout */
#app { display: flex; flex-direction: column; height: 100vh; }
#content { flex: 1; overflow: hidden; }
.tab-content { display: none; height: 100%; overflow-y: auto; padding: 20px; }
.tab-content.active { display: block; }

/* Cards */
.card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: .5px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-header h3 { margin-bottom: 0; }

/* Dashboard */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.stat-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-card h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-2); margin-bottom: 12px; }
.stat-card-wide { grid-column: 1 / -1; text-align: left; }
.gauge-wrap { position: relative; display: inline-block; }
.gauge-val { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 22px; font-weight: 700; }
.core-bars { display: flex; gap: 4px; justify-content: center; margin-top: 10px; }
.core-bar { width: 20px; height: 4px; background: var(--bg-3); border-radius: 2px; overflow: hidden; }
.core-bar-fill { height: 100%; background: var(--accent); transition: width .5s; }
.small { font-size: 12px; margin-top: 6px; }
#net-chart { width: 100%; }

/* Tables */
.table-wrap { overflow-x: auto; max-height: 400px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { position: sticky; top: 0; background: var(--bg-2); text-align: left; padding: 8px 10px; color: var(--text-2); font-weight: 600; border-bottom: 1px solid var(--border); z-index: 1; }
td { padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:hover td { background: var(--bg-3); }
.right { text-align: right; }
.input-small { background: var(--bg-1); border: 1px solid var(--border); border-radius: 4px; padding: 4px 8px; color: var(--text); font-size: 13px; outline: none; width: 180px; }
.input-small:focus { border-color: var(--accent); }

/* Services */
.services-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 16px; }
.svc-list { display: flex; flex-direction: column; gap: 6px; }
.svc-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; background: var(--bg-1); border-radius: 6px; }
.svc-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.svc-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.svc-dot.running { background: var(--success); box-shadow: 0 0 6px var(--success); }
.svc-dot.stopped { background: var(--danger); }
.svc-dot.other { background: var(--warning); }
.svc-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-detail { font-size: 11px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-actions { display: flex; gap: 4px; flex-shrink: 0; }
.svc-actions button { background: var(--bg-3); border: none; color: var(--text-2); padding: 3px 8px; border-radius: 4px; font-size: 11px; cursor: pointer; font-family: var(--font); }
.svc-actions button:hover { background: var(--accent); color: #fff; }
.svc-actions button.danger:hover { background: var(--danger); }

/* Files */
.file-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.breadcrumb { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.breadcrumb a { color: var(--accent); text-decoration: none; cursor: pointer; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb span { color: var(--text-3); }
.file-actions { display: flex; gap: 6px; }
.btn-sm { background: var(--bg-2); border: 1px solid var(--border); color: var(--text); padding: 5px 12px; border-radius: 6px; font-size: 12px; cursor: pointer; font-family: var(--font); }
.btn-sm:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.file-icon { margin-right: 6px; }
.file-link { color: var(--text); text-decoration: none; cursor: pointer; }
.file-link:hover { color: var(--accent); }
.file-dir { color: var(--accent); }

/* Editor Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-content { background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; width: 90%; max-width: 900px; max-height: 85vh; display: flex; flex-direction: column; }
.modal-large { height: 80vh; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 14px; color: var(--text); }
#editor-textarea { flex: 1; background: var(--bg-1); color: var(--text); border: none; padding: 16px; font-family: var(--mono); font-size: 13px; resize: none; outline: none; line-height: 1.6; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }

/* Terminal */
#tab-terminal { padding: 0; display: none; }
#tab-terminal.active { display: flex; }
#terminal-container { flex: 1; width: 100%; height: 100%; }

/* AI Chat */
#tab-ai { display: none; flex-direction: column; padding: 0; }
#tab-ai.active { display: flex; }
#ai-messages { flex: 1; overflow-y: auto; padding: 20px; }
.ai-msg { margin-bottom: 16px; max-width: 85%; }
.ai-msg.user { margin-left: auto; }
.ai-msg .bubble { padding: 10px 14px; border-radius: 12px; font-size: 13px; line-height: 1.6; }
.ai-msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.ai-msg.assistant .bubble { background: var(--bg-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.ai-msg .bubble pre { background: var(--bg-1); padding: 8px 10px; border-radius: 6px; margin: 8px 0; overflow-x: auto; font-family: var(--mono); font-size: 12px; }
.ai-msg .bubble code { font-family: var(--mono); font-size: 12px; background: var(--bg-1); padding: 1px 4px; border-radius: 3px; }
.ai-tool-call { background: var(--bg-1); border: 1px solid var(--border); border-radius: 6px; margin: 8px 0; font-size: 12px; }
.ai-tool-call summary { padding: 6px 10px; cursor: pointer; color: var(--text-2); }
.ai-tool-call pre { padding: 8px 10px; margin: 0; border-top: 1px solid var(--border); overflow-x: auto; }
#ai-input-bar { display: flex; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); background: var(--bg-1); }
#ai-input { flex: 1; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; color: var(--text); font-size: 14px; outline: none; font-family: var(--font); }
#ai-input:focus { border-color: var(--accent); }
#ai-send { background: var(--accent); color: #fff; border: none; border-radius: var(--radius); padding: 10px 20px; cursor: pointer; font-size: 14px; font-family: var(--font); }
#ai-send:hover { background: var(--accent-hover); }
#ai-send:disabled { opacity: .5; cursor: not-allowed; }

.text-muted { color: var(--text-2); }
.loading { opacity: .6; animation: pulse 1.5s infinite; }
@keyframes pulse { 0%, 100% { opacity: .6; } 50% { opacity: .3; } }

/* Responsive */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .services-grid { grid-template-columns: 1fr; }
  .nav-tab { padding: 6px 8px; font-size: 12px; }
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr; }
}
