/* app.css — shared admin UI styles.
 * Linked from every page <head> so the browser has the theme before first
 * paint. These used to be injected by navbar.js on DOMContentLoaded, which
 * meant every navigation flashed the default white canvas first.
 */

:root { --sidebar-w: 220px; }
[data-theme="dark"] {
  --bg: #0f0f12; --surface: #18181f; --surface2: #22222c;
  --border: #2a2a38; --text: #e8e8f0; --text2: #9090a8;
  --accent: #662F8E; --accent-hover: #7a3aa8; --accent-light: #662f8e22;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f4f4f8; --surface: #ffffff; --surface2: #f0f0f5;
  --border: #dddde8; --text: #1a1a2e; --text2: #6060a0;
  --accent: #662F8E; --accent-hover: #522572; --accent-light: #662f8e15;
  color-scheme: light;
}

/* Paint the canvas from <html>, not just <body> — the background propagates to
   the viewport immediately, and color-scheme above keeps scrollbars and form
   controls from flashing light on a dark page. */
html { background: var(--bg); color: var(--text); }
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; min-height: 100vh;
}
#aqi-sidebar {
  width: var(--sidebar-w); min-height: 100vh;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.brand-icon { font-size: 22px; }
.brand-name { font-size: 14px; font-weight: 700; color: var(--accent); letter-spacing: 0.02em; }
.nav-list { list-style: none; padding: 12px 8px; flex: 1; }
.nav-list li { margin-bottom: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--text2); text-decoration: none; font-size: 13.5px;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--accent-light); color: var(--text); }
.nav-link.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }
.nav-icon { width: 20px; text-align: center; font-size: 15px; }
.sidebar-footer {
  padding: 12px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.theme-btn {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 8px; cursor: pointer;
  font-size: 14px; color: var(--text); flex: 1;
}
.logout-btn {
  background: transparent; border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 10px; cursor: pointer;
  font-size: 12px; color: var(--text2);
}
.logout-btn:hover { color: #e55; border-color: #e55; }
#aqi-main { margin-left: var(--sidebar-w); flex: 1; padding: 28px 32px; min-width: 0; }
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header p { color: var(--text2); font-size: 14px; margin-top: 4px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; margin-bottom: 16px;
}
.card-title { font-size: 12px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.card-value { font-size: 26px; font-weight: 700; }
.card-sub { font-size: 12px; color: var(--text2); margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: repeat(2,1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: none;
  cursor: pointer; font-size: 13px; font-weight: 500;
  transition: background 0.15s; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
}
.badge-green { background: #1a3d1a; color: #4caf50; }
.badge-amber { background: #3d2e00; color: #ffb300; }
.badge-red   { background: #3d1a1a; color: #ef5350; }
.badge-gray  { background: var(--surface2); color: var(--text2); }
[data-theme="light"] .badge-green { background: #e8f5e9; color: #2e7d32; }
[data-theme="light"] .badge-amber { background: #fff8e1; color: #f57f17; }
[data-theme="light"] .badge-red   { background: #fce4ec; color: #c62828; }
[data-theme="light"] .badge-gray  { background: #f0f0f5; color: #6060a0; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; color: var(--text2); border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }
input, textarea, select {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; color: var(--text);
  font-size: 13px; width: 100%; transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
label { font-size: 12px; color: var(--text2); margin-bottom: 4px; display: block; font-weight: 500; }
.form-group { margin-bottom: 12px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 18px; font-size: 13px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  z-index: 9999; animation: slideUp 0.2s ease;
  max-width: 320px;
}
.toast.success { border-left: 3px solid #4caf50; }
.toast.error   { border-left: 3px solid #ef5350; }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@media (max-width: 768px) {
  :root { --sidebar-w: 60px; }
  .nav-label, .brand-name, .logout-btn { display: none; }
  #aqi-main { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
