/* ---------- theme: dark is the default look, unchanged ---------- */
:root, :root[data-theme="dark"] {
  --bg: #0c0c0b;
  --panel: #151514;
  --panel-2: #1c1c1a;
  --panel-3: #232321;
  --border: #262624;
  --border-strong: #383733;
  --text: #f4f3f1;
  --muted: #a6a29a;
  --faint: #6e6b64;
  --brand: #e5484d;
  --green: #4ade80;  --green-bg: rgba(74, 222, 128, 0.1);
  --amber: #fbbf24;  --amber-bg: rgba(251, 191, 36, 0.1);
  --red: #f87171;    --red-bg: rgba(248, 113, 113, 0.11);
  --blue: #7dd3fc;   --blue-bg: rgba(125, 211, 252, 0.1);
  --purple: #c4b5fd; --purple-bg: rgba(196, 181, 253, 0.1);
  --gray-bg: rgba(166, 162, 154, 0.1);
  --radius: 10px;
  --sidebar-bg: #100f0e;
  --overlay-bg: rgba(0, 0, 0, 0.55);
  --shadow-modal: 0 16px 48px rgba(0, 0, 0, 0.6);
  --shadow-drop: 0 8px 32px rgba(0, 0, 0, 0.5);
  --row-stripe: rgba(255, 255, 255, 0.015);
  --row-sep: rgba(255, 255, 255, 0.04);
  --toast-ok-bg: #1c1917;   --toast-ok-text: #f4f3f1;
  --toast-err-bg: #b91c1c;  --toast-err-text: #f4f3f1;
  --pill-pink-bg: rgba(249, 168, 212, 0.1); --pink: #f9a8d4;
  --btn-pri-bg: var(--text); --btn-pri-text: #111;
  --red-border: rgba(248, 113, 113, 0.35);
  --amber-border: rgba(251, 191, 36, 0.3);
  --green-border: rgba(74, 222, 128, 0.3);
  --blue-border: rgba(125, 211, 252, 0.4);
  --red-tint: rgba(248, 113, 113, 0.05);
  --amber-tint: rgba(251, 191, 36, 0.05);
  --green-tint: rgba(74, 222, 128, 0.04);
  --blue-tint: rgba(125, 211, 252, 0.05);
}

/* Light theme: real light-UI values (near-white bg, subtle gray tiers, dark
   text), not a naive invert. Same brand accent + one hue per meaning, tuned
   for WCAG AA contrast on light surfaces.
   The "system" choice never reaches this stylesheet as its own state: the
   inline head script (index.html) and app.js resolve prefers-color-scheme to
   an actual "light"/"dark" value and set that as data-theme, re-resolving
   live if the OS preference changes while "system" is selected. That keeps
   the theme's colors defined in exactly one place each, instead of
   duplicating this whole block inside a @media query. */
:root[data-theme="light"] {
  --bg: #f7f6f4;
  --panel: #ffffff;
  --panel-2: #f0efec;
  --panel-3: #e6e4e0;
  --border: #e1dfda;
  --border-strong: #cac7c0;
  --text: #1b1a17;
  --muted: #5c584f;
  --faint: #8a857a;
  --brand: #d3323a;
  --green: #15803d;  --green-bg: rgba(21, 128, 61, 0.1);
  --amber: #a35a00;  --amber-bg: rgba(163, 90, 0, 0.1);
  --red: #b91c1c;    --red-bg: rgba(185, 28, 28, 0.09);
  --blue: #0369a1;   --blue-bg: rgba(3, 105, 161, 0.09);
  --purple: #6d28d9; --purple-bg: rgba(109, 40, 217, 0.09);
  --gray-bg: rgba(92, 88, 79, 0.08);
  --radius: 10px;
  --sidebar-bg: #efeeea;
  --overlay-bg: rgba(20, 18, 15, 0.4);
  --shadow-modal: 0 16px 48px rgba(20, 18, 15, 0.18);
  --shadow-drop: 0 8px 32px rgba(20, 18, 15, 0.14);
  --row-stripe: rgba(20, 18, 15, 0.025);
  --row-sep: rgba(20, 18, 15, 0.06);
  --toast-ok-bg: #1b1a17;  --toast-ok-text: #f7f6f4;
  --toast-err-bg: #b91c1c; --toast-err-text: #ffffff;
  --pill-pink-bg: rgba(190, 24, 93, 0.1); --pink: #be185d;
  --btn-pri-bg: var(--text); --btn-pri-text: #fff;
  --red-border: rgba(185, 28, 28, 0.35);
  --amber-border: rgba(163, 90, 0, 0.35);
  --green-border: rgba(21, 128, 61, 0.35);
  --blue-border: rgba(3, 105, 161, 0.4);
  --red-tint: rgba(185, 28, 28, 0.06);
  --amber-tint: rgba(163, 90, 0, 0.06);
  --green-tint: rgba(21, 128, 61, 0.05);
  --blue-tint: rgba(3, 105, 161, 0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.shell { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.side {
  width: 216px; flex: none; border-right: 1px solid var(--border);
  background: var(--sidebar-bg); padding: 18px 12px 14px; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 600; font-size: 15px; margin: 0 8px 18px; display: flex; align-items: center; gap: 8px; flex: none; }
.brand::before { content: ""; width: 10px; height: 10px; background: var(--brand); border-radius: 2px; flex: none; }
.brand span { color: var(--faint); font-weight: 400; font-size: 12px; }
/* Long nav lists (20+ links) can outgrow the viewport — scroll the nav itself
   so the brand stays pinned at top and the session/role box stays reachable
   at the bottom, instead of the whole sidebar overflowing off-screen. */
#nav { flex: 1; min-height: 0; overflow-y: auto; }
#nav .group { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--faint); margin: 16px 10px 5px; }
#nav a {
  display: block; padding: 6.5px 10px; border-radius: 7px; color: var(--muted);
  text-decoration: none; font-size: 13.5px; border-left: 2px solid transparent;
}
#nav a:hover { background: var(--panel-2); color: var(--text); }
#nav a.on { background: var(--panel-2); color: var(--text); border-left: 2px solid var(--brand); border-radius: 0 7px 7px 0; font-weight: 500; }
#nav .hidden { display: none; }
.session { border-top: 1px solid var(--border); padding: 12px 8px 0; flex: none; }
.session select { width: 100%; margin: 4px 0; }
.lbl { font-size: 12px; color: var(--muted); }

/* ---------- main ---------- */
.main { padding: 18px 32px 48px; max-width: 1080px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 32px 0; max-width: 1080px;
}
.topbar input { width: 320px; max-width: 60vw; background: var(--panel); }
.topbar.hidden { display: none; }
.city-select { margin-left: auto; min-width: 150px; font-weight: 500; }
.search-wrap { position: relative; }
.search-wrap.hidden { display: none; }
.search-drop {
  display: none; position: absolute; top: calc(100% + 6px); left: 0;
  width: 420px; max-width: 90vw;
  background: var(--panel-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-drop);
  z-index: 999; overflow: hidden;
}
.search-drop.open { display: block; }
.search-drop-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); padding: 10px 14px 4px; }
.search-drop-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; cursor: pointer; border-top: 1px solid var(--border);
  text-decoration: none; color: var(--text);
}
.search-drop-item:first-of-type { border-top: none; }
.search-drop-item:hover { background: var(--panel-3); }
.search-drop-item .sdname { font-size: 13.5px; font-weight: 500; flex: 1; }
.search-drop-item .sdmeta { font-size: 12px; color: var(--muted); }
.search-drop-empty { padding: 14px; color: var(--faint); font-size: 13px; text-align: center; }
.search-drop-item.active { background: var(--panel-3); box-shadow: inset 2px 0 0 var(--brand); }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--overlay-bg);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 9vh 16px 16px;
}
.modal {
  width: 460px; max-width: 100%; max-height: 80vh; overflow-y: auto;
  background: var(--panel-2); border: 1px solid var(--border-strong);
  border-radius: 12px; box-shadow: var(--shadow-modal);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px; border-bottom: 1px solid var(--border);
}
.modal-x { padding: 2px 9px; font-size: 13px; }
.modal-body { padding: 14px 18px 18px; }
.modal-body input[type="text"], .modal-body select, .modal-body textarea { margin-top: 3px; }

/* ---------- tabs ---------- */
.tabs { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 8px 12px; font-size: 13.5px; border-radius: 0; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--brand); font-weight: 500; }

/* ---------- perks ---------- */
.perk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.perk-card {
  display: flex; flex-direction: column; text-decoration: none; color: var(--text);
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  transition: border-color 0.12s ease, transform 0.12s ease;
}
.perk-card:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.perk-img { position: relative; width: 100%; aspect-ratio: 16 / 9; background: var(--panel-3); overflow: hidden; }
.perk-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.perk-img-ph {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 600; color: var(--faint); background: var(--panel-3);
}
.perk-body { padding: 11px 13px 13px; }
.perk-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* ---------- login ---------- */
body.unauthed .side, body.unauthed .topbar { display: none; }
body.unauthed .main { max-width: none; }
.login-wrap { min-height: 92vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  width: 360px; max-width: 92vw;
  background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: 14px; padding: 28px 26px 22px;
  box-shadow: var(--shadow-modal);
}
.login-card input { margin-top: 3px; }

/* ---------- a11y & affordances ---------- */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; border-radius: 4px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button { cursor: pointer; }
h1 { font-size: 19px; font-weight: 600; margin: 0 0 4px; }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

/* ---------- surfaces: three shading tiers for readability ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px;
}
.card h3 {
  font-size: 11px; color: var(--muted); font-weight: 600; margin: 0 0 12px;
  text-transform: uppercase; letter-spacing: 0.07em;
  padding-bottom: 9px; border-bottom: 1px solid var(--border);
}
.grid { display: grid; gap: 12px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.metric { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.metric .lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.metric .n { font-size: 24px; font-weight: 600; margin-top: 2px; }
.metric .d { font-size: 12px; margin-top: 2px; }
.row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 10px; border-radius: 7px; margin: 0 -10px; }
.row:nth-child(even) { background: var(--row-stripe); }
.row:hover { background: var(--panel-2); }
.row + .row { border-top: 1px solid var(--row-sep); }

/* ---------- inputs & buttons ---------- */
input[type=text], input[type=number], select, textarea {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: 1.5px solid var(--brand); border-color: var(--brand); }
button {
  font: inherit; font-size: 13px; padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--panel-2); color: var(--text); cursor: pointer;
}
button:hover { background: var(--panel-3); }
button.pri { background: var(--btn-pri-bg); border-color: var(--btn-pri-bg); color: var(--btn-pri-text); font-weight: 500; }
button.pri:hover { opacity: 0.9; }
button.danger { color: var(--red); border-color: var(--red-border); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- pills & dots: one hue per meaning ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 500; padding: 2.5px 10px; border-radius: 999px; white-space: nowrap; flex: none; align-self: center; }
.pill.green  { background: var(--green-bg);  color: var(--green); }
.pill.amber  { background: var(--amber-bg);  color: var(--amber); }
.pill.red    { background: var(--red-bg);    color: var(--red); }
.pill.blue   { background: var(--blue-bg);   color: var(--blue); }
.pill.purple { background: var(--purple-bg); color: var(--purple); }
.pill.gray   { background: var(--gray-bg);   color: var(--muted); }
.pill.pink   { background: var(--pill-pink-bg); color: var(--pink); }

/* ---------- calendar ---------- */
.cal-head, .cal { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-head div { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); padding: 8px 10px; text-align: left; }
.cal { border-top: 1px solid var(--border); border-left: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }
.cal .cell { min-height: 96px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 7px 9px; background: var(--panel); }
.cal .cell.empty { background: var(--bg); }
.cal .cell.today { background: var(--panel-2); }
.cal .dnum { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.cal .cell.today .dnum { color: var(--brand); font-weight: 600; }
.cal .ev { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text); padding: 1.5px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal .ev .cd { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.cal .more { font-size: 11px; color: var(--faint); margin-top: 2px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 10px 0 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; }
.dot.fresh { background: var(--green); }
.dot.stale { background: var(--amber); }
.dot.manual { background: var(--blue); }
.dot.failed { background: var(--red); }
.conf { font-size: 12px; color: var(--muted); }

.banner {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px;
  border: 1px solid; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px;
}
.banner.warn { border-color: var(--amber-border); background: var(--amber-bg); }
.banner.err  { border-color: var(--red-border); background: var(--red-bg); }
.banner.ok   { border-color: var(--green-border); background: var(--green-bg); }

/* ---------- list items with severity shading ---------- */
.list-item {
  display: flex; gap: 12px; align-items: flex-start; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 16px; margin-bottom: 9px;
}
.list-item.critical { border-left: 3px solid var(--red); background: linear-gradient(90deg, var(--red-tint), var(--panel) 45%); border-top-left-radius: 0; border-bottom-left-radius: 0; }
.list-item.warning  { border-left: 3px solid var(--amber); background: linear-gradient(90deg, var(--amber-tint), var(--panel) 45%); border-top-left-radius: 0; border-bottom-left-radius: 0; }
.list-item.good     { border-left: 3px solid var(--green); background: linear-gradient(90deg, var(--green-tint), var(--panel) 45%); border-top-left-radius: 0; border-bottom-left-radius: 0; }
.list-item .body { flex: 1; min-width: 0; }
.list-item .actions { flex: none; }

.member-row { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 8px; cursor: pointer; }
.member-row:hover { background: var(--panel-2); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--panel-3); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 600; flex: none;
  border: 1px solid var(--border-strong);
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 12px; border: 1px solid var(--border-strong); border-radius: 999px;
  padding: 3.5px 12px; cursor: pointer; background: var(--panel-2); user-select: none; color: var(--muted);
}
.chip.on { background: var(--blue-bg); border-color: var(--blue-border); color: var(--blue); }

/* ---------- stepper ---------- */
.stepper { display: flex; align-items: flex-start; margin: 6px 0 4px; }
.step { display: flex; flex-direction: column; align-items: center; gap: 5px; flex: 1; }
.step .c {
  width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center; font-size: 12.5px; color: var(--muted); background: var(--panel-2);
}
.step.done .c { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.step .t { font-size: 12px; color: var(--muted); }
.bar { height: 1.5px; background: var(--border-strong); flex: 1; margin-top: 13px; }
.bar.done { background: var(--green); }

.note { border-left: 2px solid var(--border-strong); padding: 4px 0 4px 12px; margin-bottom: 12px; border-radius: 0; }
.note.ai { border-left-color: var(--blue); background: linear-gradient(90deg, var(--blue-tint), transparent 60%); }

.toast {
  position: fixed; bottom: 18px; right: 18px; background: var(--toast-ok-bg); color: var(--toast-ok-text);
  padding: 10px 16px; border-radius: 9px; font-size: 13px; opacity: 0; transition: opacity 0.25s; pointer-events: none; max-width: 380px; font-weight: 500;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--toast-err-bg); color: var(--toast-err-text); }
a { color: var(--blue); }
.back { font-size: 13px; display: inline-block; margin-bottom: 10px; }
.card:has(> table.t) { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 560px; }
table.t td { padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.t tr:last-child td { border-bottom: none; }
table.t tr:hover td { background: var(--panel-2); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.right { text-align: right; }
.locked { opacity: 0.55; }
.ok-text { color: var(--green); }
.bad-text { color: var(--red); }
.warn-text { color: var(--amber); }

/* ---------- theme toggle ---------- */
.theme-toggle {
  display: inline-flex; align-items: center; border: 1px solid var(--border-strong);
  border-radius: 999px; padding: 2px; gap: 1px; background: var(--panel-2); flex: none;
}
.theme-toggle button {
  border: none; background: none; padding: 5px 8px; border-radius: 999px;
  font-size: 13px; line-height: 1; color: var(--muted); display: flex; align-items: center; justify-content: center;
}
.theme-toggle button:hover { background: var(--panel-3); color: var(--text); }
.theme-toggle button.on { background: var(--panel-3); color: var(--brand); }
.theme-toggle button svg { width: 15px; height: 15px; display: block; }
