/* ============================================================================
   RCS Traffic Dashboard — "Signal Desk" theme
   Instrument/telemetry aesthetic · Jio Azure accent · dark + light
   Fonts: Bricolage Grotesque (display) · Hanken Grotesk (UI) · IBM Plex Mono (data)
   ========================================================================== */

/* ---------- DARK (default) ---------- */
:root {
  --font-display: "Bricolage Grotesque", "Hanken Grotesk", system-ui, sans-serif;
  --font-ui: "Hanken Grotesk", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", monospace;

  --bg: #060a13;
  --bg-glow: #12203a;
  --panel: #0d1626;
  --panel-2: #131f33;
  --line: #1f2c44;
  --line-soft: rgba(255,255,255,.06);
  --grid: rgba(120,160,220,.045);
  --text: #e9eef8;
  --muted: #8696b4;

  --accent: #2f7dff;          /* Jio Azure */
  --accent-soft: rgba(47,125,255,.16);
  --accent-glow: rgba(47,125,255,.45);

  --jio: #2f7dff;
  --airtel: #ff4d57;
  --bsnl: #f5a524;
  --voda: #c44be0;
  --other: #6b7a96;
  --good: #2ed98a;
  --warn: #f5a524;
  --bad: #ff5b66;

  --shadow: 0 10px 34px -12px rgba(0,0,0,.7);
  --shadow-soft: 0 4px 18px -8px rgba(0,0,0,.55);
  --readout: #d9e6ff;         /* numeric readouts */
  --cell-hot-text: #ffffff;
}

/* ---------- LIGHT ---------- */
html[data-theme="light"] {
  --bg: #eaeef5;
  --bg-glow: #d4e2ff;
  --panel: #ffffff;
  --panel-2: #f3f6fc;
  --line: #d9e0ec;
  --line-soft: rgba(13,23,38,.06);
  --grid: rgba(31,90,180,.06);
  --text: #0e1828;
  --muted: #5d6c87;

  --accent: #1f6feb;
  --accent-soft: rgba(31,111,235,.12);
  --accent-glow: rgba(31,111,235,.28);

  --jio: #1f6feb;
  --airtel: #e23744;
  --bsnl: #c8810a;
  --voda: #a32fc4;
  --other: #768297;
  --good: #14a05a;
  --warn: #c47f00;
  --bad: #d8323f;

  --shadow: 0 12px 30px -16px rgba(20,40,80,.35);
  --shadow-soft: 0 4px 14px -8px rgba(20,40,80,.25);
  --readout: #0a2a6b;
  --cell-hot-text: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
/* atmosphere: fixed engineered grid + signal glow (doesn't scroll) */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -2; pointer-events: none;
  background:
    radial-gradient(900px 520px at 82% -8%, var(--bg-glow) 0%, transparent 60%),
    radial-gradient(700px 500px at 0% 100%, var(--accent-soft) 0%, transparent 55%),
    var(--bg);
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 44px 44px, 44px 44px;
  mask-image: linear-gradient(180deg, #000 0%, transparent 70%);
}

/* ---------------- masthead ---------------- */
header.app {
  display: flex; align-items: center; gap: 18px;
  padding: 14px 26px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px) saturate(1.1);
  position: sticky; top: 0; z-index: 30;
}
.masthead-kicker {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .32em;
  text-transform: uppercase; color: var(--accent); margin: 0 0 3px;
}
header.app h1 {
  font-family: var(--font-display); font-size: 21px; margin: 0;
  font-weight: 800; letter-spacing: -.01em; line-height: 1;
}
header.app .sub { color: var(--muted); font-size: 11.5px; margin-top: 4px; font-family: var(--font-mono); letter-spacing: .02em; }
.brand-dot {
  width: 11px; height: 11px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent-glow); animation: pulse 2.4s ease-out infinite; flex: none;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 var(--accent-glow); }
  70% { box-shadow: 0 0 0 9px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.spacer { flex: 1; }

.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 9px 14px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  font-family: var(--font-ui); display: inline-flex; align-items: center; gap: 7px;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
  box-shadow: 0 4px 16px -6px var(--accent-glow);
}
.btn.secondary { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); box-shadow: none; }
.btn:hover { filter: brightness(1.07); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

/* theme toggle */
.theme-toggle {
  width: 38px; height: 38px; border-radius: 9px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; font-size: 16px;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

.wrap { padding: 20px 26px 70px; max-width: 1520px; margin: 0 auto; }

/* ---------------- filters toolbar ---------------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-top: none; border-radius: 0 0 14px 14px;
  padding: 15px 18px; margin-bottom: 22px;
  position: sticky; top: calc(var(--hdr-h, 64px) - 1px); z-index: 20;
  box-shadow: 0 14px 26px -14px rgba(0,0,0,.6);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-family: var(--font-mono); font-size: 9.5px; text-transform: uppercase;
  letter-spacing: .18em; color: var(--muted);
}
select, input[type=file] {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; min-width: 150px; font-family: var(--font-ui);
}

/* ---------------- KPI instrument readouts ---------------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px,1fr)); gap: 14px; margin-bottom: 22px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 18px 16px; box-shadow: var(--shadow-soft);
  position: relative; overflow: hidden; transition: transform .15s ease, border-color .15s ease;
}
.card::before {   /* top signal-rule */
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px;
  background: var(--stripe-c, var(--accent)); opacity: .9;
}
.card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.card .k {
  font-family: var(--font-mono); font-size: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .16em;
}
.card .v {
  font-family: var(--font-mono); font-size: 30px; font-weight: 600; margin-top: 10px;
  color: var(--readout); letter-spacing: -.02em; font-variant-numeric: tabular-nums;
}
.card .d { font-size: 11.5px; color: var(--muted); margin-top: 7px; }
.card .stripe { display: none; }   /* replaced by ::before rule */
.card .delta { font-weight: 600; font-family: var(--font-mono); }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); }

/* ---------------- layout ---------------- */
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: 1.4fr 1fr 1fr; }
@media (max-width: 1100px){ .grid.two, .grid.three { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px 20px; box-shadow: var(--shadow-soft); margin-bottom: 18px;
}
.panel h3 {
  margin: 0 0 4px; font-family: var(--font-display); font-size: 16px; font-weight: 700;
  letter-spacing: -.01em; display: flex; align-items: center; gap: 10px;
}
.panel h3::before {   /* accent tick before section titles (flex item) */
  content: ""; flex: none; width: 4px; height: 17px; border-radius: 2px; background: var(--accent);
}
.panel h3 .dl-csv { margin-left: auto; }   /* push the CSV button to the right */
.panel .hint { color: var(--muted); font-size: 12px; margin: 0 0 14px; max-width: 70ch; }
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 340px; }

/* ---------------- tables ---------------- */
table.matrix, table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.matrix th, table.matrix td, table.data th, table.data td {
  padding: 9px 11px; text-align: right; border-bottom: 1px solid var(--line-soft); white-space: nowrap;
  font-variant-numeric: tabular-nums; font-family: var(--font-mono); font-size: 12.5px;
}
table.matrix th:first-child, table.matrix td:first-child,
table.data th:first-child, table.data td:first-child { text-align: left; font-family: var(--font-ui); }
table.matrix thead th, table.data thead th {
  color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 10px;
  letter-spacing: .12em; font-family: var(--font-mono);
}
table.matrix td.cell { color: var(--text); font-weight: 600; border-radius: 4px; }
td.unknown { color: var(--muted); font-style: italic; background: repeating-linear-gradient(45deg, transparent, transparent 6px, var(--line-soft) 6px, var(--line-soft) 12px); }
td.unknown small { font-style: normal; opacity: .8; }
tr.total-row td { font-weight: 700; border-top: 1.5px solid var(--line); color: var(--text); }
table.matrix tbody tr:hover td, table.data tbody tr:hover td { background: var(--accent-soft); }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend span.box { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------------- advisory callout ---------------- */
.callout {
  border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line));
  border-left: 3px solid var(--warn);
  background: color-mix(in srgb, var(--warn) 9%, var(--panel));
  border-radius: 10px; padding: 13px 17px; font-size: 13px; color: var(--text); margin-bottom: 20px;
}
.callout::before {
  content: "⚠ ADVISORY"; display: block; font-family: var(--font-mono); font-size: 9.5px;
  letter-spacing: .2em; color: var(--warn); margin-bottom: 5px;
}
.callout b { color: var(--text); font-weight: 700; }

/* ---------------- sources ---------------- */
.sources { font-size: 13px; }
.sources .row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.sources .row span:first-child { font-family: var(--font-mono); font-size: 12px; }
.tag { font-size: 10px; padding: 2px 9px; border-radius: 20px; font-weight: 700; font-family: var(--font-mono); letter-spacing: .06em; text-transform: uppercase; }
.tag.ok { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.tag.dup { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.tag.up { background: var(--accent-soft); color: var(--accent); }
.muted { color: var(--muted); }

/* ---------------- toast ---------------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); opacity: 0;
  transition: all .25s ease; z-index: 3000; max-width: 80vw; font-size: 13px;
  border-left: 3px solid var(--accent);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { border-left-color: var(--bad); }
.foot { color: var(--muted); font-size: 11.5px; text-align: center; margin-top: 28px; font-family: var(--font-mono); line-height: 1.8; }

/* ---------------- pills (units) ---------------- */
.pill-group { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 11px; font-size: 11.5px; cursor: pointer; color: var(--muted); font-family: var(--font-mono); letter-spacing: .02em; }
.pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------------- multi-select filters ---------------- */
.filter-fields { display: flex; flex-wrap: wrap; gap: 14px; }
.ms { position: relative; display: flex; flex-direction: column; gap: 6px; }
.ms-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-width: 168px; max-width: 230px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; font-size: 13px; cursor: pointer;
  font-family: var(--font-ui); transition: border-color .12s ease;
}
.ms-btn:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.ms.active .ms-btn { border-color: var(--accent); color: var(--accent); }
.ms-btn .ms-sum { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-btn .ms-caret { color: var(--muted); font-size: 11px; }
.ms-pop {
  position: absolute; top: 100%; left: 0; margin-top: 6px; z-index: 60;
  width: 264px; max-width: 80vw; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 10px;
}
.ms-pop[hidden] { display: none; }
.ms-search { width: 100%; margin-bottom: 8px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; font-size: 13px; font-family: var(--font-ui); }
.ms-list { max-height: 240px; overflow: auto; }
.ms-opt { display: flex; align-items: center; gap: 8px; padding: 6px; font-size: 13px; border-radius: 6px; cursor: pointer; }
.ms-opt:hover { background: var(--accent-soft); }
.ms-opt input { accent-color: var(--accent); }
.ms-all { border-bottom: 1px solid var(--line); margin-bottom: 4px; padding-bottom: 7px; font-weight: 600; }
.ms-foot { display: flex; justify-content: flex-end; margin-top: 8px; }
.ms-done { padding: 5px 12px; font-size: 12px; }

/* ---------------- download buttons ---------------- */
.dl-btn {
  position: absolute; top: 8px; right: 10px; z-index: 5;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
  border-radius: 6px; padding: 3px 9px; font-size: 10px; font-weight: 600; cursor: pointer;
  font-family: var(--font-mono); letter-spacing: .04em;
}
.dl-btn:hover { color: var(--accent); border-color: var(--accent); }
.dl-csv { padding: 4px 10px !important; font-size: 10px !important; font-family: var(--font-mono); }

/* ---------------- top nav ---------------- */
.topnav { display: flex; gap: 4px; margin-left: 14px; }
.topnav a {
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
  padding: 6px 12px; border-radius: 8px; font-family: var(--font-mono); letter-spacing: .04em;
}
.topnav a:hover { color: var(--text); background: var(--panel-2); }
@media (max-width: 900px){ .topnav { display: none; } }

/* ---------------- AI insights ---------------- */
.ai-controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; margin-bottom: 12px; }
.ai-block { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.ai-block input { min-width: 220px; }
input[type=text], input[type=password] {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; font-family: var(--font-ui);
}
.ai-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
#ai-status { font-family: var(--font-mono); font-size: 11.5px; }
.ai-output {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 22px; margin-top: 12px; line-height: 1.65; max-height: 680px; overflow: auto;
}
.ai-output h2 { font-family: var(--font-display); font-size: 17px; margin: 18px 0 8px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.ai-output h3 { font-family: var(--font-display); font-size: 14px; margin: 14px 0 6px; color: var(--text); }
.ai-output p { margin: 8px 0; }
.ai-output ul, .ai-output ol { margin: 8px 0 8px 4px; padding-left: 22px; }
.ai-output li { margin: 4px 0; }
.ai-output code { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 12px; font-family: var(--font-mono); }
.ai-output strong { color: var(--text); }
.ai-err { color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); border-left: 3px solid var(--bad); padding: 12px 14px; border-radius: 8px; }

/* ---------------- PivotTable.js theme overrides ---------------- */
#pivot { font-size: 13px; font-family: var(--font-ui); }
.pvtUi { color: var(--text); border-collapse: separate; }
.pvtUi select, .pvtUi input[type=text] { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
.pvtAxisContainer, .pvtVals { border: 1px solid var(--line) !important; background: var(--panel-2) !important; border-radius: 8px; padding: 6px !important; }
.pvtAxisContainer li span.pvtAttr { background: var(--panel) !important; border: 1px solid var(--line) !important; color: var(--text) !important; border-radius: 6px; padding: 3px 7px; font-family: var(--font-mono); font-size: 12px; }
.pvtAxisContainer li span.pvtAttr:hover { border-color: var(--accent) !important; }
.pvtTriangle { color: var(--muted); }
.pvtTable { color: var(--text); font-variant-numeric: tabular-nums; }
.pvtTable thead tr th, .pvtTable tbody tr th { background: var(--panel-2) !important; color: var(--muted) !important; border: 1px solid var(--line) !important; font-weight: 600; }
.pvtTable tbody tr td { border: 1px solid var(--line) !important; color: var(--text); background: transparent; font-family: var(--font-mono); }
.pvtTable .pvtTotal, .pvtTable .pvtGrandTotal, .pvtTable .pvtTotalLabel { font-weight: 700; background: var(--panel) !important; }
.pvtVal { color: var(--text); }
.pvtFilterBox {
  position: fixed !important; top: 50% !important; left: 50% !important;
  transform: translate(-50%, -50%) !important;
  width: 380px !important; max-width: 92vw; max-height: 82vh; overflow: auto;
  z-index: 2000 !important;
  background: var(--panel) !important; color: var(--text); border: 1px solid var(--line) !important;
  box-shadow: var(--shadow); border-radius: 10px; padding-bottom: 8px;
}
.pvtFilterBox h4, .pvtFilterBox p, .pvtFilterBox label { color: var(--text) !important; }
.pvtCheckContainer { color: var(--text); max-height: 52vh !important; overflow-y: auto !important; }
.pvtCheckContainer p { border-bottom: 1px solid var(--line); }
.pvtCheckContainer p.selected { background: var(--accent); color: #fff; }
.pvtButton { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; }
.pvtRowOrder, .pvtColOrder { background: var(--panel) !important; color: var(--text); border: 1px solid var(--line); }
.pvtUi .pvtTriangle { cursor: pointer; }

/* ---------------- scrollbar / focus / selection ---------------- */
::selection { background: var(--accent); color: #fff; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------------- load reveal animation ---------------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.reveal { opacity: 0; animation: rise .55s cubic-bezier(.2,.7,.2,1) forwards; }
.cards .card { animation: rise .5s cubic-bezier(.2,.7,.2,1) backwards; }
.cards .card:nth-child(1){ animation-delay: .05s; }
.cards .card:nth-child(2){ animation-delay: .12s; }
.cards .card:nth-child(3){ animation-delay: .19s; }
.cards .card:nth-child(4){ animation-delay: .26s; }
.wrap > .panel, .wrap > .grid { animation: rise .55s cubic-bezier(.2,.7,.2,1) backwards; animation-delay: .18s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .brand-dot { animation: none !important; }
}
