:root {
  color-scheme: dark;
  --bg: #050816;
  --surface: #10182a;
  --surface-2: #172033;
  --line: rgba(182, 194, 217, 0.16);
  --text: #ffffff;
  --muted: #8d9bb5;
  --blue: #0a84ff;
  --blue-2: #a5d8ff;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 0%, rgba(10, 132, 255, 0.24), transparent 34%),
    radial-gradient(circle at 100% 20%, rgba(165, 216, 255, 0.12), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#app { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar {
  padding: 24px;
  border-right: 1px solid var(--line);
  background: rgba(5, 8, 22, 0.76);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 34px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 16px;
  display: grid; place-items: center; font-weight: 900;
  background: linear-gradient(135deg, var(--blue), #3b82f6);
  box-shadow: 0 18px 40px rgba(10, 132, 255, 0.32);
  flex-shrink: 0;
}
.brand span, .muted { color: var(--muted); }
nav { display: grid; gap: 6px; }
.nav-btn {
  width: 100%; border: 1px solid transparent; color: var(--muted);
  background: transparent; border-radius: 14px; padding: 12px 14px;
  text-align: left; font-weight: 800; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  font-size: 14px;
}
.nav-btn .nav-icon {
  width: 26px; height: 26px; border-radius: 9px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 12px; font-weight: 900;
  background: rgba(255,255,255,0.06); color: var(--blue-2);
}
.nav-btn.active, .nav-btn:hover {
  color: var(--text); border-color: var(--line);
  background: rgba(255,255,255,0.06);
}
.nav-btn.active .nav-icon { background: var(--blue); color: white; }
.whoami {
  margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
.whoami strong { display: block; color: var(--text); font-size: 13px; margin-bottom: 2px; }

.main { padding: 28px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.topbar-left { display: flex; align-items: center; gap: 14px; }
.top-actions { display: flex; gap: 12px; align-items: center; }
.eyebrow {
  margin: 0 0 6px; color: var(--blue-2); text-transform: uppercase;
  letter-spacing: 0.08em; font-size: 12px; font-weight: 900;
}
h1, h2, h3 { margin: 0; }
h1 { font-size: clamp(24px, 4vw, 42px); }
h2 { font-size: 22px; }
h3 { font-size: 15px; }
.status-pill {
  border: 1px solid var(--line); background: rgba(255,255,255,0.06);
  border-radius: 999px; padding: 9px 12px; color: var(--muted); font-weight: 800;
  font-size: 12px; white-space: nowrap;
}
.status-pill.ok { color: var(--green); border-color: rgba(34,197,94,0.25); }
.status-pill.bad { color: var(--red); border-color: rgba(239,68,68,0.25); }
.status-pill.warn { color: var(--amber); border-color: rgba(245,158,11,0.3); }
button, input, textarea, select {
  font: inherit;
}
.primary, .ghost, .mini, .danger, .success {
  border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 900; cursor: pointer;
}
.primary { color: white; background: linear-gradient(135deg, var(--blue), #3b82f6); }
.ghost { color: var(--blue-2); background: rgba(255,255,255,0.07); border: 1px solid var(--line); }
.mini { padding: 8px 10px; color: var(--text); background: rgba(10,132,255,0.12); border: 1px solid rgba(10,132,255,0.28); font-size: 12px; }
.danger { color: white; background: linear-gradient(135deg, #ef4444, #dc2626); }
.danger.mini { color: var(--red); background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.28); }
.success.mini { color: var(--green); background: rgba(34,197,94,0.12); border: 1px solid rgba(34,197,94,0.28); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.mini + button.mini { margin-left: 6px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }

.login-card, .panel {
  max-width: 520px; border: 1px solid var(--line); border-radius: 24px;
  padding: 24px; background: rgba(16, 24, 42, 0.82);
  box-shadow: 0 24px 80px rgba(0,0,0,0.28);
}
.login-card { display: grid; gap: 12px; margin: 0 auto; }
label { color: var(--muted); font-size: 13px; font-weight: 800; }
input, textarea, select {
  width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 14px;
  background: rgba(255,255,255,0.06); color: var(--text); padding: 0 14px;
}
textarea { min-height: 80px; padding: 12px 14px; resize: vertical; }
select { appearance: none; }
.error { color: var(--red); min-height: 20px; font-size: 13px; }
.content { display: grid; gap: 20px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric {
  border: 1px solid var(--line); border-radius: 20px; padding: 18px;
  background: rgba(16, 24, 42, 0.74);
}
.metric span { color: var(--muted); font-weight: 800; font-size: 12px; text-transform: uppercase; }
.metric strong { display: block; margin-top: 10px; font-size: 28px; }
.panel { max-width: none; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; flex-wrap: wrap; }
.section-controls { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.section-controls input { width: min(220px, 100%); min-height: 42px; }
.table-wrap { overflow: auto; border-radius: 16px; border: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 12px 14px; border-bottom: 1px solid rgba(255,255,255,0.07); text-align: left; vertical-align: top; }
th { color: var(--blue-2); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; }
td { color: #dce6f8; font-size: 13px; }
.tag { display: inline-block; padding: 4px 8px; border-radius: 999px; background: rgba(10,132,255,0.14); color: var(--blue-2); font-weight: 900; font-size: 11px; }
.tag.good { background: rgba(34,197,94,0.14); color: var(--green); }
.tag.bad { background: rgba(239,68,68,0.14); color: var(--red); }
.tag.warn { background: rgba(245,158,11,0.14); color: var(--amber); }
.hidden { display: none !important; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }

/* Settings form */
.settings-grid { display: grid; gap: 14px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px; border: 1px solid var(--line); border-radius: 16px;
  background: rgba(16, 24, 42, 0.5);
}
.setting-row.number-row { flex-wrap: wrap; }
.setting-row .setting-label { max-width: 60%; }
.setting-row .setting-label strong { display: block; font-size: 14px; margin-bottom: 4px; }
.setting-row .setting-label span { font-size: 12px; color: var(--muted); }
.setting-row input[type="number"] { width: 140px; min-height: 42px; }

/* Switch toggle */
.switch { position: relative; width: 50px; height: 28px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px; background: rgba(255,255,255,0.12);
  border: 1px solid var(--line); transition: background 0.15s ease;
}
.switch .thumb {
  position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: white; transition: left 0.15s ease;
}
.switch input:checked + .track { background: linear-gradient(135deg, var(--blue), #3b82f6); border-color: transparent; }
.switch input:checked ~ .thumb { left: 25px; }

/* Admins section */
.admin-form {
  display: grid; grid-template-columns: 2fr 1fr auto; gap: 10px; margin-bottom: 18px;
}
.admin-form input, .admin-form select { min-height: 44px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  max-width: 440px; width: 100%; border: 1px solid var(--line); border-radius: 20px;
  padding: 22px; background: rgba(16, 24, 42, 0.98); box-shadow: 0 24px 80px rgba(0,0,0,0.4);
  display: grid; gap: 12px;
}
.modal-card h3 { font-size: 17px; }
.modal-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 70; padding: 14px 20px; border-radius: 14px; font-weight: 800; font-size: 13px;
  background: rgba(16,24,42,0.98); border: 1px solid var(--line); color: var(--text);
  box-shadow: 0 20px 50px rgba(0,0,0,0.4); max-width: min(420px, calc(100vw - 32px));
}
.toast.ok { border-color: rgba(34,197,94,0.4); color: var(--green); }
.toast.err { border-color: rgba(239,68,68,0.4); color: var(--red); }

/* Mobile drawer */
.menu-toggle {
  display: none; flex-direction: column; justify-content: center; gap: 4px;
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(255,255,255,0.06); cursor: pointer; flex-shrink: 0;
}
.menu-toggle span { width: 18px; height: 2px; background: var(--text); margin: 0 auto; border-radius: 2px; }
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 40;
}

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: min(300px, 84vw);
    z-index: 50; transform: translateX(-100%); transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: flex; }
  .main { padding: 18px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .login-card { max-width: 100%; }
  .admin-form { grid-template-columns: 1fr; }
  .setting-row { flex-direction: column; align-items: flex-start; }
  .setting-row .setting-label { max-width: 100%; }
}

@media (max-width: 480px) {
  .metric-grid { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
  .modal-card { padding: 18px; }
}
