/* ===========================================================================
   Theme system
   ---------------------------------------------------------------------------
   Every colour is a CSS variable. The active theme is chosen by the
   `data-theme` attribute on <html> (set from localStorage before paint, see
   index.html). To add a theme, copy a block below and change the values —
   nothing else in this file or app.js needs to change. The chart reads the
   same variables at render time (see cssVar() in app.js), so plots re-colour
   with the rest of the UI.
   =========================================================================== */

:root,
[data-theme="midnight"] {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #161a22;
  --panel2: #1d222c;
  --border: #2a2f3a;
  --border-soft: #20242e;
  --text: #e6e9ef;
  --text-dim: #c7d0e0;
  --muted: #8b93a4;
  --accent: #4f8cff;
  --accent-soft: #4f8cff26;
  --accent-text: #ffffff;
  --active: #21304a;
  --green: #3fb950;
  --red: #f0603f;
  --chip: #2b3242;
  --chip-text: #c7d0e0;
  --warn-bg: #3a2418;
  --warn-border: #7a4a2a;
  --warn-text: #ffd9c0;
  --grid: #20242e;
  --axis: #8b93a4;
  --shadow: 0 2px 10px #00000055;
}

[data-theme="graphite"] {
  color-scheme: dark;
  --bg: #17181a;
  --panel: #1e1f22;
  --panel2: #26282c;
  --border: #34373d;
  --border-soft: #2a2c31;
  --text: #e8e8ea;
  --text-dim: #c5c6ca;
  --muted: #8d8f96;
  --accent: #9b8cff;
  --accent-soft: #9b8cff26;
  --accent-text: #ffffff;
  --active: #2f2a46;
  --green: #4cc38a;
  --red: #ef6f5c;
  --chip: #2e3036;
  --chip-text: #c5c6ca;
  --warn-bg: #2f2718;
  --warn-border: #6e5a2c;
  --warn-text: #f2e2b8;
  --grid: #2a2c31;
  --axis: #8d8f96;
  --shadow: 0 2px 10px #00000055;
}

[data-theme="nord"] {
  color-scheme: dark;
  --bg: #2e3440;
  --panel: #333b4a;
  --panel2: #3b4252;
  --border: #434c5e;
  --border-soft: #3b4252;
  --text: #eceff4;
  --text-dim: #d8dee9;
  --muted: #8893a5;
  --accent: #88c0d0;
  --accent-soft: #88c0d026;
  --accent-text: #1b2330;
  --active: #4c566a;
  --green: #a3be8c;
  --red: #bf616a;
  --chip: #434c5e;
  --chip-text: #d8dee9;
  --warn-bg: #4b3a2a;
  --warn-border: #7a5a38;
  --warn-text: #ebcb8b;
  --grid: #3b4252;
  --axis: #8893a5;
  --shadow: 0 2px 12px #00000055;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel2: #eef1f6;
  --border: #d6dbe4;
  --border-soft: #e7eaf0;
  --text: #1b2330;
  --text-dim: #36404f;
  --muted: #69727f;
  --accent: #2f6df0;
  --accent-soft: #2f6df01a;
  --accent-text: #ffffff;
  --active: #dbe7ff;
  --green: #1a9d4b;
  --red: #d8432a;
  --chip: #e7ecf4;
  --chip-text: #36404f;
  --warn-bg: #fff3e0;
  --warn-border: #e7b878;
  --warn-text: #7a4a12;
  --grid: #e4e8ef;
  --axis: #69727f;
  --shadow: 0 2px 10px #1b233014;
}

[data-theme="solarized"] {
  color-scheme: dark;
  --bg: #002b36;
  --panel: #073642;
  --panel2: #0a3c49;
  --border: #15505c;
  --border-soft: #0d4350;
  --text: #eee8d5;
  --text-dim: #c9c3b0;
  --muted: #7f98a0;
  --accent: #268bd2;
  --accent-soft: #268bd226;
  --accent-text: #ffffff;
  --active: #0f4a57;
  --green: #859900;
  --red: #dc322f;
  --chip: #0d4350;
  --chip-text: #c9c3b0;
  --warn-bg: #3a2d10;
  --warn-border: #7a5e1c;
  --warn-text: #e9d9a0;
  --grid: #0d4350;
  --axis: #7f98a0;
  --shadow: 0 2px 12px #00000055;
}

[data-theme="terminal"] {
  color-scheme: dark;
  --bg: #07090d;
  --panel: #0c0f14;
  --panel2: #11151c;
  --border: #1e2733;
  --border-soft: #161c25;
  --text: #d7e3cf;
  --text-dim: #a9c29a;
  --muted: #6c7d66;
  --accent: #ffb000;
  --accent-soft: #ffb00022;
  --accent-text: #0a0a0a;
  --active: #1c2433;
  --green: #2ee66b;
  --red: #ff5b4a;
  --chip: #14202a;
  --chip-text: #a9c29a;
  --warn-bg: #2a1c08;
  --warn-border: #6e4a10;
  --warn-text: #ffd27a;
  --grid: #141b24;
  --axis: #6c7d66;
  --shadow: 0 2px 12px #000000aa;
}

/* ===========================================================================
   Base
   =========================================================================== */

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex; flex-direction: row; height: 100vh;
  transition: background-color .18s ease, color .18s ease;
}

/* themed scrollbars */
* { scrollbar-color: var(--border) transparent; scrollbar-width: thin; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 6px;
  border: 2px solid var(--panel);
}
*::-webkit-scrollbar-thumb:hover { background: var(--muted); }
*::-webkit-scrollbar-track { background: transparent; }

/* ---- left icon rail -------------------------------------------------- */
.rail {
  width: 76px; flex: none; background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 8px; z-index: 6;
}
.rail-brand {
  width: 38px; height: 38px; border-radius: 11px; margin-bottom: 10px;
  background: linear-gradient(145deg, var(--accent), var(--green));
  box-shadow: var(--shadow);
}
.rail-btn {
  width: 100%; border: 1px solid transparent; background: transparent;
  color: var(--muted); border-radius: 12px; padding: 9px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10px; line-height: 1; cursor: pointer;
  transition: background-color .14s ease, color .14s ease,
    border-color .14s ease;
}
.rail-btn .rail-ico { font-size: 18px; }
.rail-btn:hover {
  background: var(--panel2); color: var(--text); border-color: var(--border);
}
.rail-btn.active {
  background: var(--accent-soft); color: var(--accent);
  border-color: var(--accent);
}
.rail-spacer { flex: 1; }

/* ---- app column: header + content ------------------------------------ */
.app {
  flex: 1; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 14px 22px; border-bottom: 1px solid var(--border);
  background: var(--panel); flex: none;
  position: relative; z-index: 5; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 {
  font-size: 19px; margin: 0; letter-spacing: -.2px; font-weight: 650;
}
.brand .sub { color: var(--muted); font-size: 12px; }
.controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.totals {
  color: var(--muted); font-size: 12px; min-width: 220px; text-align: right;
  font-variant-numeric: tabular-nums;
}

select, input[type="search"], button {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px; padding: 7px 11px;
  font: inherit;
  transition: background-color .15s ease, border-color .15s ease,
    color .15s ease, box-shadow .15s ease;
}
select:focus, input[type="search"]:focus, button:focus-visible {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
.btn-soft:hover { background: var(--panel); }
label {
  color: var(--muted); font-size: 12px; display: inline-flex; gap: 6px;
  align-items: center;
}
label select { color: var(--text); }

/* ---- cards ----------------------------------------------------------- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
}

main {
  flex: 1; display: flex; min-height: 0; gap: 18px; padding: 18px 22px;
}

#sidebar {
  width: 340px; flex: none; overflow: hidden;
  display: flex; flex-direction: column;
}
.filters {
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.filter-row { display: flex; gap: 8px; align-items: center; }
.filter-row select { flex: 1; min-width: 0; }
.filters .chk { color: var(--muted); }
.pill {
  border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 12px; background: var(--panel2); cursor: pointer;
  white-space: nowrap; user-select: none;
}
.pill:hover { border-color: var(--accent); }
.list { overflow-y: auto; flex: 1; padding: 6px; }

.row {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border-radius: 10px; cursor: pointer; margin-bottom: 2px;
  border: 1px solid transparent;
  transition: background-color .12s ease, border-color .12s ease;
}
.row:hover { background: var(--panel2); }
.row.active {
  background: var(--accent-soft); border-color: var(--accent);
}
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.off { background: var(--red); opacity: .6; }
.row .nm {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row.active .nm { font-weight: 600; }
.row .meta { color: var(--muted); font-size: 11px; flex: none; }
.chip {
  background: var(--chip); color: var(--chip-text); border-radius: 999px;
  padding: 2px 10px; font-size: 11px;
}

#detail {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  padding: 22px; overflow: auto;
}
.placeholder { color: var(--muted); margin: auto; text-align: center; }
.placeholder-mark {
  font-size: 40px; color: var(--accent); opacity: .5; margin-bottom: 10px;
}
.placeholder-lead { font-size: 16px; color: var(--text); margin: 0 0 6px; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }

.viewer-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.viewer-head h2 {
  margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.3px;
  word-break: break-all;
}
/* S3 location of the active indicator (bucket + per-series-folder paths) */
.ind-loc {
  margin-top: 12px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel2); padding: 10px 12px;
}
.ind-loc-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 6px;
}
.ind-loc-label {
  color: var(--text-dim); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px;
}
.ind-loc-head .btn-soft { padding: 3px 10px; font-size: 11px; }
#loc-msg { font-size: 11px; color: var(--green); }
.ind-loc-root {
  display: block; color: var(--text-dim); font-size: 11.5px;
  word-break: break-all; margin-bottom: 4px;
}
.ind-loc-list {
  display: flex; flex-direction: column; gap: 2px;
  max-height: 132px; overflow-y: auto;
}
.loc-line {
  color: var(--accent); font-size: 11.5px; cursor: pointer;
  word-break: break-all; padding: 2px 6px; border-radius: 6px;
}
.loc-line:hover { background: var(--accent-soft); }

.viewer-controls {
  display: flex; gap: 18px; align-items: flex-start; margin: 16px 0;
  flex-wrap: wrap;
}
.series-picker { flex: 1; min-width: 260px; }
.series-picker-head {
  color: var(--muted); font-size: 12px; margin-bottom: 4px;
}
.series-list {
  max-height: 140px; overflow-y: auto; border: 1px solid var(--border);
  border-radius: 10px; padding: 8px; background: var(--panel2);
  display: flex; flex-direction: column; gap: 3px;
}
.series-list label {
  color: var(--text); font-size: 12px; display: flex; gap: 6px;
  align-items: center; cursor: pointer; word-break: break-all;
}
#plot {
  align-self: flex-end; padding: 9px 24px; background: var(--accent);
  border-color: var(--accent); color: var(--accent-text); font-weight: 600;
  border-radius: 10px;
}
#plot:hover { filter: brightness(1.08); }

/* chart lives in its own inset card */
.chart-card {
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--panel2); padding: 12px 14px;
}
#chart { flex: 1; min-height: 640px; height: 72vh; }
#chart-status { margin-bottom: 8px; }

.nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin: 0 0 10px; flex-wrap: wrap;
}
.nav .pager { display: flex; align-items: center; gap: 5px; }
.nav button { padding: 5px 11px; font-size: 12px; }
.nav #win-label { min-width: 190px; text-align: center; }
.scroll-hint { font-style: italic; }

.warn {
  margin: 14px 22px 0; padding: 11px 15px; border-radius: 10px;
  background: var(--warn-bg); border: 1px solid var(--warn-border);
  color: var(--warn-text); font-size: 12.5px; line-height: 1.5;
}
.warn code { background: #00000040; padding: 1px 5px; border-radius: 4px; }

#symbols-view {
  flex: 1; display: flex; flex-direction: column;
  min-height: 0; padding: 18px 22px;
}
.sym-card {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  padding: 16px; overflow: hidden;
}
.sym-head {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.sym-head h2 {
  margin: 0; font-size: 20px; font-weight: 650; margin-right: auto;
}
/* id-scoped so it beats the chart table's `.table-scroll { max-height:300px }`
   regardless of stylesheet order */
#symbols-view .table-scroll.sym-scroll {
  max-height: none; flex: 1; min-height: 0; overflow: auto;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel);
}
#sym-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
  font-variant-numeric: tabular-nums;
}
#sym-table th, #sym-table td {
  padding: 6px 14px; text-align: right;
  white-space: nowrap; border-bottom: 1px solid var(--border-soft);
}
#sym-table th {
  position: sticky; top: 0; background: var(--panel2);
  color: var(--muted); z-index: 1; cursor: pointer; user-select: none;
}
#sym-table th:hover { color: var(--text); }
#sym-table th:first-child, #sym-table td:first-child { text-align: left; }
#sym-table td:first-child { color: var(--text); font-weight: 600; }
#sym-table td { color: var(--text-dim); }
#sym-table tr:hover td { background: var(--panel2); }

.table-wrap {
  margin-top: 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel); overflow: hidden;
}
.table-head {
  padding: 6px 10px; border-bottom: 1px solid var(--border);
  background: var(--panel2);
}
.table-scroll { max-height: 300px; overflow: auto; }
#data-table {
  width: 100%; border-collapse: collapse; font-size: 12px;
  font-variant-numeric: tabular-nums;
}
#data-table th, #data-table td {
  padding: 4px 10px; text-align: right;
  white-space: nowrap; border-bottom: 1px solid var(--border-soft);
}
#data-table th {
  position: sticky; top: 0; background: var(--panel2);
  color: var(--muted); text-align: right; z-index: 1;
}
#data-table th:first-child, #data-table td:first-child {
  text-align: left; color: var(--text);
}
#data-table td { color: var(--text-dim); }
#data-table tr:hover td { background: var(--panel2); }

.building { color: var(--accent) !important; }
