/* BirruLabs Control Center — Global Styles */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #08080f;
  --bg2: #0d0d16;
  --bg3: #111120;
  --border: #1a1a2e;
  --border2: #252540;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --text3: #64748b;
  --accent: #6366f1;
  --accent2: #4f46e5;
  --accent-dim: rgba(99,102,241,0.15);
  --green: #22c55e;
  --red: #f87171;
  --yellow: #fbbf24;
  --blue: #38bdf8;
  --radius: 10px;
  --nav-h: 56px;
  --sidebar-w: 220px;
  font-size: 15px;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: 'Inter', system-ui, -apple-system, sans-serif; line-height: 1.5; overflow: hidden; }

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

/* ── Layout ── */
#app { display: flex; flex-direction: column; height: 100vh; }

/* Desktop sidebar layout */
@media (min-width: 768px) {
  #app { flex-direction: row; }
  #sidebar { display: flex; flex-direction: column; width: var(--sidebar-w); min-height: 100vh; background: var(--bg2); border-right: 1px solid var(--border); flex-shrink: 0; }
  #bottom-nav { display: none; }
  #main { flex: 1; overflow-y: auto; height: 100vh; }
}

/* Mobile */
@media (max-width: 767px) {
  #sidebar { display: none; }
  #main { flex: 1; overflow-y: auto; padding-bottom: calc(var(--nav-h) + 8px); }
  #bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h); background: var(--bg2); border-top: 1px solid var(--border); z-index: 100; }
}

/* ── Sidebar ── */
.sidebar-logo { padding: 20px 16px 12px; border-bottom: 1px solid var(--border); }
.sidebar-logo h1 { font-size: 1rem; font-weight: 700; letter-spacing: -0.02em; }
.sidebar-logo h1 span { color: var(--accent); }
.sidebar-logo p { font-size: 0.7rem; color: var(--text3); margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 16px; cursor: pointer; border-radius: 0; color: var(--text2); font-size: 0.85rem; transition: background 0.15s, color 0.15s; border-left: 3px solid transparent; }
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); border-left-color: var(--accent); }
.nav-item .icon { width: 18px; text-align: center; flex-shrink: 0; }

.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 0.75rem; color: var(--text3); }
.sidebar-footer .user { display: flex; align-items: center; justify-content: space-between; }
.logout-btn { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 0.75rem; padding: 2px 6px; border-radius: 4px; transition: color 0.15s; }
.logout-btn:hover { color: var(--red); }

/* ── Bottom nav ── */
.bottom-nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; color: var(--text3); font-size: 0.62rem; border: none; background: none; transition: color 0.15s; }
.bottom-nav-item .icon { font-size: 1.1rem; }
.bottom-nav-item.active { color: var(--accent); }

/* ── Main content ── */
#main { padding: 0; }
.page { display: none; padding: 20px; max-width: 1200px; }
.page.active { display: block; }
.page-header { margin-bottom: 20px; }
.page-header h2 { font-size: 1.15rem; font-weight: 600; letter-spacing: -0.02em; }
.page-header p { color: var(--text3); font-size: 0.8rem; margin-top: 2px; }

/* Terminal page — full screen */
#page-terminal { padding: 0; max-width: none; height: 100%; display: none; flex-direction: column; }
#page-terminal.active { display: flex; }

/* ── Cards ── */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card-title { font-size: 0.75rem; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 12px; }

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 600px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 400px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ── Stat card ── */
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat-label { font-size: 0.7rem; color: var(--text3); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.4rem; font-weight: 700; line-height: 1.2; margin-top: 4px; letter-spacing: -0.02em; }
.stat-sub { font-size: 0.72rem; color: var(--text3); margin-top: 2px; }

/* ── Status badge ── */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 0.72rem; font-weight: 600; padding: 3px 8px; border-radius: 20px; }
.badge-green { background: rgba(34,197,94,0.12); color: var(--green); }
.badge-red { background: rgba(248,113,113,0.12); color: var(--red); }
.badge-yellow { background: rgba(251,191,36,0.12); color: var(--yellow); }
.badge-blue { background: rgba(56,189,248,0.12); color: var(--blue); }
.badge-gray { background: rgba(100,116,139,0.12); color: var(--text3); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.dot-pulse { animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* ── Progress bar ── */
.progress-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; border-radius: 2px; transition: width 0.5s; background: var(--accent); }
.progress-fill.warn { background: var(--yellow); }
.progress-fill.danger { background: var(--red); }

/* ── Button ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: none; font-size: 0.82rem; font-weight: 500; cursor: pointer; transition: background 0.15s, opacity 0.15s; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent2); }
.btn-ghost { background: var(--bg3); color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--border); color: var(--text); }
.btn-danger { background: rgba(248,113,113,0.12); color: var(--red); border: 1px solid rgba(248,113,113,0.2); }
.btn-danger:hover:not(:disabled) { background: rgba(248,113,113,0.2); }
.btn-sm { padding: 5px 10px; font-size: 0.76rem; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
thead th { text-align: left; padding: 8px 12px; font-size: 0.7rem; color: var(--text3); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); color: var(--text2); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg3); color: var(--text); }

/* ── Log viewer ── */
.log-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.log-search { flex: 1; min-width: 160px; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; color: var(--text); font-size: 0.82rem; outline: none; }
.log-search:focus { border-color: var(--accent); }
.log-output { background: #050508; border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 0.76rem; line-height: 1.6; overflow-y: auto; max-height: 420px; white-space: pre-wrap; word-break: break-all; }
.log-output .log-error { color: var(--red); }
.log-output .log-warn { color: var(--yellow); }
.log-output .log-ts { color: var(--text3); }
.log-output .log-match { background: rgba(251,191,36,0.2); }

/* ── Terminal ── */
.term-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.term-status { font-size: 0.76rem; color: var(--text3); flex: 1; }
#terminal-container { flex: 1; overflow: hidden; background: #000; }
.xterm { height: 100%; }
.xterm-viewport { overflow-y: auto !important; }

/* ── Command buttons ── */
.cmd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.cmd-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.cmd-card:hover { border-color: var(--accent); background: var(--bg3); }
.cmd-card.danger { border-color: rgba(248,113,113,0.2); }
.cmd-card.danger:hover { border-color: var(--red); background: rgba(248,113,113,0.05); }
.cmd-card h4 { font-size: 0.82rem; font-weight: 600; }
.cmd-card p { font-size: 0.72rem; color: var(--text3); margin-top: 3px; }
.cmd-output { background: #050508; border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-family: monospace; font-size: 0.76rem; line-height: 1.6; overflow-y: auto; max-height: 300px; white-space: pre-wrap; word-break: break-all; margin-top: 12px; }

/* ── Agent cards ── */
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.agent-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.agent-card h4 { font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.agent-meta { font-size: 0.72rem; color: var(--text3); margin-top: 6px; line-height: 1.6; }

/* ── Model rows ── */
.model-filter { background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; color: var(--text); font-size: 0.82rem; outline: none; width: 100%; max-width: 320px; margin-bottom: 12px; }
.model-filter:focus { border-color: var(--accent); }

/* ── Loading / empty states ── */
.loading { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--text3); font-size: 0.82rem; padding: 32px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--text3); font-size: 0.82rem; padding: 32px; }

/* ── Toast ── */
#toast-container { position: fixed; bottom: 70px; right: 16px; z-index: 999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
@media (min-width: 768px) { #toast-container { bottom: 16px; } }
.toast { background: var(--bg3); border: 1px solid var(--border2); border-radius: 8px; padding: 10px 16px; font-size: 0.8rem; color: var(--text); pointer-events: auto; animation: fadeIn 0.2s; max-width: 280px; }
.toast.success { border-color: rgba(34,197,94,0.3); }
.toast.error { border-color: rgba(248,113,113,0.3); color: var(--red); }
@keyframes fadeIn { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }

/* ── Misc ── */
.section-gap { margin-top: 20px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
select { background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 6px 10px; font-size: 0.82rem; outline: none; }
select:focus { border-color: var(--accent); }
