:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #263248;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }

/* Login */
.login-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: 100%; max-width: 400px; }
.login-card h1 { font-size: 1.5rem; margin: 10px 0 6px; }
.brand-badge { display: inline-block; background: var(--primary); color: #fff; font-size: 0.75rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 250px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 18px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.logo-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--success); box-shadow: 0 0 10px var(--success); }
.sidebar-nav { flex: 1; padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.nav-item { text-align: left; background: transparent; border: none; color: var(--muted); padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 0.9rem; transition: 0.15s; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: space-between; }

.main-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 60px; background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 20px; display: flex; align-items: center; justify-content: space-between; }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.content-area { padding: 20px; flex: 1; overflow-y: auto; }

/* Forms & Buttons */
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); margin-bottom: 12px; }
input, select, textarea { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; font-size: 0.9rem; width: 100%; }
textarea { min-height: 85px; font-family: inherit; }
.btn { border: none; border-radius: 8px; padding: 9px 16px; font-size: 0.88rem; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #111; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 6px 10px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.icon-btn { background: transparent; border: none; color: var(--text); font-size: 1.3rem; cursor: pointer; }
.select-sm { width: auto; padding: 6px 10px; }

/* Cards & Grids */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.kpi-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.kpi-val { font-size: 1.6rem; font-weight: 700; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.card-title { font-size: 1.05rem; font-weight: 600; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); }
.badge-green { background: rgba(16,185,129,0.15); color: #10b981; border-color: rgba(16,185,129,0.3); }
.badge-yellow { background: rgba(245,158,11,0.15); color: #f59e0b; border-color: rgba(245,158,11,0.3); }
.badge-red { background: rgba(239,68,68,0.15); color: #ef4444; border-color: rgba(239,68,68,0.3); }
.badge-blue { background: rgba(59,130,246,0.15); color: #60a5fa; border-color: rgba(59,130,246,0.3); }

/* Charts */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 0.85rem; }
.bar-label { width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 999px; }

/* Modal & Toast */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto; padding: 20px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); padding: 12px 16px; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.25); font-size: 0.88rem; }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

.code-block { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-family: monospace; font-size: 0.82rem; overflow-x: auto; white-space: pre-wrap; }
.mobile-only { display: none; }

@media (max-width: 820px) {
  .mobile-only { display: inline-flex; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 900; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
}

/* Field help / guide block (Firebase JSON etc.) */
.field-help { margin: -4px 0 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); font-size: 0.83rem; }
.field-help > summary { padding: 9px 12px; cursor: pointer; color: var(--primary); font-weight: 600; user-select: none; list-style: none; }
.field-help > summary::-webkit-details-marker { display: none; }
.field-help > summary::before { content: "▸ "; display: inline-block; transition: transform 0.15s; color: var(--muted); }
.field-help[open] > summary::before { content: "▾ "; }
.field-help > summary:hover { color: var(--primary-hover); }
.field-help-body { padding: 4px 14px 12px; border-top: 1px solid var(--border); color: var(--text); line-height: 1.55; }
.field-help-body ol { padding-left: 20px; margin: 8px 0; }
.field-help-body li { margin-bottom: 5px; }
.field-help-body p { margin: 8px 0; }
.field-help-body code { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; font-size: 0.8rem; font-family: monospace; }
.field-help-warn { color: var(--warning); background: rgba(245,158,11,0.08); border: 1px solid rgba(245,158,11,0.25); border-radius: 6px; padding: 8px 10px; }

.field-hint { font-size: 0.78rem; color: var(--muted); margin: -8px 0 12px; line-height: 1.4; }
.field-hint code { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; font-family: monospace; }
