/* Redpoint Budget Tracker — design tokens + layout.
   Palette follows the validated reference instance (dataviz): categorical slots,
   status colors, and chart chrome are used by role, with light/dark selected
   per-mode rather than auto-flipped. */

:root {
  color-scheme: light;
  /* planes & ink */
  --page: #f9f9f7;
  --panel: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  /* series (categorical slots 1–2) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-1-tint: #e6eefb;
  --series-1-tint-2: #cde2fb;
  --series-2-tint: #fdeee7;
  --series-2-tint-2: #f9dccd;
  /* status (icon + label always accompany color) */
  --status-good: #0ca30c;
  --status-good-text: #006300;
  --status-warn: #fab219;
  --status-crit: #d03b3b;
  --wash-good: #e9f6e9;
  --wash-warn: #fdf3dc;
  --wash-crit: #fbe7e7;
  --wash-info: #e6eefb;
  --info-text: #1c5cab;
  --warn-text: #8a5a00;
  --crit-text: #a32e2e;
  --topbar-h: 64px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --panel: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --ring: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-1-tint: #14263f;
    --series-1-tint-2: #1b3457;
    --series-2-tint: #3a2015;
    --series-2-tint-2: #4d2a1a;
    --status-good-text: #0ca30c;
    --wash-good: #12290f;
    --wash-warn: #33270a;
    --wash-crit: #391414;
    --wash-info: #14263f;
    --info-text: #86b6ef;
    --warn-text: #fab219;
    --crit-text: #e66767;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

/* ---------- top bar (always-dark band, both themes) ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #101623;
  color: #f2f4f8;
  padding: 14px 28px 0;
}
.topbar-row {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.topbar-title h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: #fff;
}
.topbar-title h1 .accent { color: #6ea8f0; font-weight: 400; }
.topbar-title .subtitle {
  display: block;
  font-size: 0.74rem;
  color: #8b95a7;
}

.topbar-controls {
  display: flex;
  gap: 20px;
  align-items: flex-end;
  margin-left: auto;
  flex-wrap: wrap;
}
.topbar-control label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8b95a7;
  margin-bottom: 3px;
}
.topbar-control input[type="date"] {
  padding: 6px 10px;
  border: 1px solid #2c3648;
  border-radius: 8px;
  font-size: 0.86rem;
  font-family: inherit;
  background: #1a2233;
  color: #f2f4f8;
  color-scheme: dark;
}
.topbar-control .multiselect { min-width: 190px; }
.topbar-control .multiselect-toggle {
  background: #1a2233;
  color: #f2f4f8;
  border-color: #2c3648;
}
.topbar-control .multiselect-toggle:hover { border-color: #8b95a7; }

/* view navigation */
.viewnav {
  display: flex;
  gap: 4px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.viewnav-btn {
  position: relative;
  background: none;
  border: none;
  color: #8b95a7;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 550;
  padding: 10px 16px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.viewnav-btn:hover { color: #f2f4f8; }
.viewnav-btn.active {
  color: #fff;
  border-bottom-color: #6ea8f0;
}
.nav-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-warn);
  margin-left: 6px;
  vertical-align: 2px;
}
.nav-dot.hidden { display: none; }

.view { display: none; }
.view.active { display: block; }

/* ---------- hero ---------- */

.hero {
  display: flex;
  gap: 36px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.hero-main { flex: 1 1 380px; min-width: 320px; }
.hero-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.hero-label .hero-sub { text-transform: none; letter-spacing: 0; font-weight: 400; }
.hero-number {
  font-size: 4.2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  margin: 4px 0 14px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.hero-number .dot { width: 16px; height: 16px; }
.hero-before { font-size: 0.85rem; color: var(--ink-2); margin-top: 12px; }
.hero-before b { color: var(--ink); }

/* meter: fill is scaled so 100% of budget sits at the 60% mark of the track */
.meter-track {
  position: relative;
  height: 14px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--ink) 7%, var(--panel));
  overflow: visible;
}
.meter-fill {
  height: 100%;
  border-radius: 7px;
  background: var(--series-1);
  min-width: 6px;
  max-width: 100%;
  transition: width 0.4s;
}
.meter-fill.over { background: var(--status-crit); }
.meter-fill.warn { background: var(--status-warn); }
.meter-marker {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  background: var(--ink-2);
}
.meter-marker-warn { background: var(--baseline); }
.meter-marker span {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
}
.meter { margin-bottom: 26px; }

.hero-stats {
  flex: 1 1 340px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  align-self: center;
}

/* ---------- overview grid & vendor bars ---------- */

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

.vbar-row {
  display: grid;
  grid-template-columns: 150px 1fr minmax(84px, auto);
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 0.82rem;
}
.vbar-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.vbar-track {
  position: relative;
  height: 18px;
  border-radius: 4px;
  border: 1px solid var(--baseline);       /* hollow track = budget */
  background: transparent;
}
.vbar-fill {
  position: absolute;
  top: 2px; bottom: 2px; left: 2px;
  border-radius: 3px;
  background: var(--series-1);
}
.vbar-over {
  position: absolute;
  top: 2px; bottom: 2px;
  border-radius: 0 3px 3px 0;
  background: var(--status-crit);
}
.vbar-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.vbar-over-amt { font-size: 0.72rem; color: var(--crit-text); white-space: nowrap; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.section-head h2 { margin: 0; }

/* segmented control (lives in the dark topbar) */
.segmented {
  display: inline-flex;
  background: #1a2233;
  border: 1px solid #2c3648;
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.seg-btn {
  border: none;
  background: none;
  color: #8b95a7;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 550;
  padding: 5px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.seg-btn:hover { color: #f2f4f8; }
.seg-btn.active { background: #2f6fed; color: #fff; }

/* light variant for use inside content sections */
.segmented.seg-light {
  background: color-mix(in srgb, var(--ink) 5%, var(--panel));
  border-color: var(--grid);
}
.seg-light .seg-btn { color: var(--ink-2); }
.seg-light .seg-btn:hover { color: var(--ink); }
.seg-light .seg-btn.active { background: var(--series-1); color: #fff; }

/* ---------- page ---------- */

.content {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 28px 90px;
}

.asof-note {
  font-size: 0.82rem;
  color: var(--ink-2);
  margin: 0 0 18px;
}
.asof-note strong { color: var(--info-text); font-weight: 600; }

section {
  background: var(--panel);
  border: 1px solid var(--ring);
  border-radius: 14px;
  padding: 20px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

h2 {
  font-size: 1.02rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
}
.caption {
  color: var(--ink-2);
  font-size: 0.82rem;
  margin: 0 0 14px;
  line-height: 1.55;
  max-width: 950px;
}

/* ---------- alerts ---------- */

.alert {
  padding: 9px 14px;
  border-radius: 9px;
  font-size: 0.85rem;
  margin: 10px 0 0;
}
.alert-info { background: var(--wash-info); color: var(--info-text); }
.alert-success { background: var(--wash-good); color: var(--status-good-text); }
.alert-warning { background: var(--wash-warn); color: var(--warn-text); }
.alert-error { background: var(--wash-crit); color: var(--crit-text); }

/* ---------- stat tiles ---------- */

.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.metric-card {
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: 11px;
  padding: 12px 16px 13px;
}
.metric-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.metric-value {
  font-size: 1.45rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  margin-top: 3px;
}
.metric-delta { font-size: 0.78rem; color: var(--ink-2); margin-top: 2px; }

/* ---------- consumption badges (dot carries color; text stays ink) ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.badge .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}
.dot-ok { background: var(--status-good); }
.dot-warn { background: var(--status-warn); border-radius: 2px; }        /* square */
.dot-over {
  background: var(--status-crit);
  border-radius: 1px;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);                          /* triangle */
}
.dot-na { background: transparent; border: 1.5px solid var(--baseline); }

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--grid);
  margin-bottom: 14px;
}
.tab-btn {
  background: none;
  border: none;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.87rem;
  font-family: inherit;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active {
  color: var(--ink);
  border-bottom-color: var(--series-1);
  font-weight: 600;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- drill-down hierarchy ---------- */

details.l1-expander {
  border: 1px solid var(--grid);
  border-radius: 10px;
  margin-bottom: 8px;
  padding: 10px 14px;
  background: var(--panel);
}
details.l1-expander[open] { border-color: var(--baseline); }
details.l1-expander > summary {
  cursor: pointer;
  font-weight: 550;
  font-size: 0.9rem;
  padding: 1px 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
details.l1-expander > summary::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: none;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.12s;
}
details.l1-expander[open] > summary::before { transform: rotate(45deg); }
details.top-expander { background: color-mix(in srgb, var(--series-1) 4%, var(--panel)); }

.rollup {
  display: inline-flex;
  gap: 14px;
  align-items: center;
  margin-left: auto;
  font-weight: 400;
  font-size: 0.83rem;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.rollup b { color: var(--ink); font-weight: 600; }

.l1-body { margin-top: 10px; }

button.l2-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-top: 1px solid var(--grid);
  padding: 8px 10px;
  font-size: 0.86rem;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  border-radius: 6px;
}
button.l2-row:hover { background: color-mix(in srgb, var(--series-1) 6%, transparent); }

.l2-detail {
  margin: 2px 0 10px 10px;
  padding: 10px 12px;
  border-left: 2px solid var(--series-1);
  background: color-mix(in srgb, var(--series-1) 3%, transparent);
  border-radius: 0 8px 8px 0;
}
.l2-detail.hidden { display: none; }

/* ---------- tables ---------- */

table.item-table, table.data-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 0.82rem;
}
table.item-table th, table.item-table td,
table.data-table th, table.data-table td {
  border-bottom: 1px solid var(--grid);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}
table.item-table th, table.data-table th {
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 2;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--baseline);
}
tr.total-row td { font-weight: 650; background: color-mix(in srgb, var(--ink) 5%, var(--panel)); }
tr.dropped-row td { background: var(--wash-crit); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.table-scroll {
  overflow: auto;
  border: 1px solid var(--grid);
  border-radius: 10px;
  background: var(--panel);
}
.monthly-scroll { max-height: 540px; }
.raw-scroll { max-height: 440px; }

/* Monthly Tracker: frozen label columns (side-by-side stickies need cumulative offsets). */
.mt-col-category, .mt-col-vendor, .mt-col-type {
  position: sticky;
  width: 160px; min-width: 160px; max-width: 160px;
  background: var(--panel);
}
.mt-col-vendor { width: 170px; min-width: 170px; max-width: 170px; left: 160px; }
.mt-col-type { width: 105px; min-width: 105px; max-width: 105px; left: 330px; }
.mt-col-category { left: 0; }
.data-table thead th.mt-col-category,
.data-table thead th.mt-col-vendor,
.data-table thead th.mt-col-type { z-index: 3; }
.data-table tbody td.mt-col-category,
.data-table tbody td.mt-col-vendor,
.data-table tbody td.mt-col-type { z-index: 1; }
tr.total-row td.mt-col-category, tr.total-row td.mt-col-vendor, tr.total-row td.mt-col-type {
  background: color-mix(in srgb, var(--ink) 5%, var(--panel));
}

/* Monthly value cells: hue = series (Budget blue / Actual orange), depth = projection. */
td.cell-b { background: var(--series-1-tint); }
td.cell-b.proj { background: var(--series-1-tint-2); }
td.cell-a { background: var(--series-2-tint); }
td.cell-a.proj { background: var(--series-2-tint-2); }
th.proj-col { color: var(--ink-2); }
.proj-tag {
  display: inline-block;
  margin-left: 5px;
  padding: 0 4px;
  border-radius: 4px;
  font-size: 0.62rem;
  letter-spacing: 0.03em;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--ink-2);
}

/* ---------- filters ---------- */

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 12px;
}
.filter-item { min-width: 180px; }
.filter-item label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 3px;
}

.multiselect { position: relative; }
.multiselect-toggle {
  width: 100%;
  text-align: left;
  padding: 6px 12px;
  border: 1px solid var(--baseline);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}
.multiselect-toggle::after { content: " ▾"; color: var(--muted); }
.multiselect-toggle:hover { border-color: var(--muted); }
.multiselect-panel {
  position: absolute;
  z-index: 60;
  top: calc(100% + 4px);
  left: 0;
  min-width: 230px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
  padding: 6px 4px;
}
.multiselect-panel.hidden { display: none; }
.ms-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  font-size: 0.84rem;
  cursor: pointer;
  border-radius: 6px;
}
.ms-option:hover { background: color-mix(in srgb, var(--series-1) 8%, transparent); }
.ms-option input { accent-color: var(--series-1); }

/* ---------- buttons & inputs ---------- */

.btn {
  display: inline-block;
  background: var(--series-1);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 16px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  margin-right: 8px;
}
.btn:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--panel); color: var(--ink); border: 1px solid var(--baseline); }

input.vendor-map-input {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--baseline);
  border-radius: 7px;
  font-size: 0.83rem;
  font-family: inherit;
  background: var(--panel);
  color: var(--ink);
}

textarea.vendormap-output {
  width: 100%;
  margin-top: 10px;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.8rem;
  padding: 10px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--page);
  color: var(--ink);
}

details#vendorMapReview { border: none; }
details#vendorMapReview > summary { cursor: pointer; font-weight: 600; font-size: 0.95rem; }

#trendChart { width: 100%; min-height: 380px; }

@media (max-width: 900px) {
  .topbar { padding: 10px 16px; }
  .topbar-controls { margin-left: 0; }
  .content { padding: 16px 14px 70px; }
  section { padding: 16px; border-radius: 12px; }
}
