/* Wavelength — broadcast-studio-at-night analytics UI */

:root {
  --bg:        #0a0d14;
  --bg-2:      #0d111b;
  --panel:     #121724;
  --panel-2:   #171d2c;
  --panel-hi:  #1d2436;
  --line:      rgba(255, 255, 255, 0.07);
  --line-2:    rgba(255, 255, 255, 0.12);
  --text:      #eef1f8;
  --muted:     #8b95ad;
  --muted-2:   #626d85;

  --amber:     #f5b544;
  --coral:     #ff5a3c;
  --accent:    #ff7a45;
  --grad:      linear-gradient(135deg, #f5b544, #ff5a3c);

  --pos:       #35d0ba;
  --neg:       #ff6a6a;

  /* chart theming (read by cshell-charts.js) */
  --chart-text:  #7b8399;
  --chart-grid:  rgba(255, 255, 255, 0.07);
  --chart-tooltip-bg:   #1c2333;
  --chart-tooltip-text: #eef1f8;
  --chart-center-text:  #eef1f8;
  --chart-c1:  #ff7a45;
  --chart-c2:  #f5b544;
  --chart-c3:  #35d0ba;
  --chart-c4:  #7c7cf6;
  --chart-c5:  #4a9eff;
  --chart-c6:  #f26fb3;

  --r-sm: 8px;
  --r:    14px;
  --r-lg: 20px;
  --sb-w: 250px;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 12px 30px -18px rgba(0,0,0,.7);
  --font-ui: "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-display: "Bricolage Grotesque", var(--font-ui);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01";
}
.tnum { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; margin: 0; letter-spacing: -0.01em; }
button { font-family: inherit; cursor: pointer; }
::selection { background: rgba(255,122,69,.3); }

/* radial studio glow behind everything */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(900px 520px at 78% -8%, rgba(255,90,60,.10), transparent 60%),
    radial-gradient(760px 480px at 0% 0%, rgba(124,124,246,.08), transparent 55%);
}

.app { position: relative; z-index: 1; display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sb-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 22px 16px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 22px; }
.brand-mark { display: grid; place-items: center; filter: drop-shadow(0 6px 14px rgba(255,90,60,.35)); }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 20px; letter-spacing: -0.02em; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0; border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-size: 14.5px; font-weight: 600;
  text-align: left;
  transition: background .16s, color .16s;
}
.nav-item .ic { width: 19px; height: 19px; fill: currentColor; flex-shrink: 0; opacity: .9; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nav-item.is-active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.nav-item.is-active .ic { fill: var(--accent); opacity: 1; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 14px; }
.show-card {
  display: flex; align-items: center; gap: 11px;
  padding: 11px; border-radius: var(--r);
  background: var(--panel); border: 1px solid var(--line);
}
.show-art {
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 10px; background: var(--grad);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800; font-size: 14px; color: #160d0a;
}
.show-meta { min-width: 0; }
.show-name { font-size: 13.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.show-sub { font-size: 11.5px; color: var(--muted-2); }
.live-badge {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; color: var(--muted); padding: 0 4px;
}
.live-badge .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--pos);
  box-shadow: 0 0 0 0 rgba(53,208,186,.5); animation: pulse 2.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(53,208,186,.5); }
  70% { box-shadow: 0 0 0 6px rgba(53,208,186,0); }
  100% { box-shadow: 0 0 0 0 rgba(53,208,186,0); }
}

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 18px 30px;
  background: rgba(10,13,20,.72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 22px; line-height: 1.1; }
.topbar-title p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.range {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.range-btn {
  border: 0; background: transparent; color: var(--muted);
  font-weight: 700; font-size: 12.5px; letter-spacing: .02em;
  padding: 6px 12px; border-radius: 7px;
  transition: background .15s, color .15s;
}
.range-btn:hover { color: var(--text); }
.range-btn.is-active { background: var(--panel-hi); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.04) inset; }
.range-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--panel);
  color: var(--text); font-weight: 600; font-size: 13.5px;
  transition: background .15s, border-color .15s;
}
.btn-ghost svg { width: 16px; height: 16px; }
.btn-ghost:hover { background: var(--panel-hi); border-color: rgba(255,255,255,.2); }
.btn-ghost:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-btn {
  display: none;
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel);
  color: var(--text); place-items: center;
}
.icon-btn svg { width: 20px; height: 20px; }

.views { padding: 26px 30px 48px; }
.view { display: none; animation: fade .3s ease; }
.view.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Grid & cards ---------- */
.grid { display: grid; gap: 16px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 30px 2px 14px; }
.section-head:first-child { margin-top: 4px; }
.section-head h2 { font-size: 16px; font-weight: 700; }
.section-head .hint { font-size: 12.5px; color: var(--muted); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.card-title { font-size: 13.5px; font-weight: 600; color: var(--muted); }
.card-title strong { display: block; color: var(--text); font-weight: 700; font-size: 15px; margin-bottom: 1px; }

/* KPI stat cards */
.kpis { grid-template-columns: repeat(4, 1fr); }
.kpi {
  position: relative; overflow: hidden;
  padding: 18px 18px 16px;
}
.kpi::after {
  content: ""; position: absolute; right: -30px; top: -30px;
  width: 120px; height: 120px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,122,69,.10), transparent 68%);
}
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 7px; }
.kpi-label .ic { width: 15px; height: 15px; fill: var(--accent); opacity: .85; }
.kpi-val { font-family: var(--font-display); font-weight: 700; font-size: 30px; letter-spacing: -0.02em; margin: 9px 0 6px; line-height: 1; }
.kpi-foot { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; padding: 2px 7px 2px 5px; border-radius: 20px; font-size: 12px; }
.delta svg { width: 12px; height: 12px; }
.delta.up { color: var(--pos); background: rgba(53,208,186,.12); }
.delta.down { color: var(--neg); background: rgba(255,106,106,.12); }
.spark { margin-top: 12px; height: 40px; }

/* chart container helper */
.chart { width: 100%; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 560px; }
table.data th, table.data td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data thead th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted-2); font-weight: 700; border-bottom: 1px solid var(--line-2);
  position: sticky; top: 0;
}
table.data th.num, table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--muted); }
table.data th.sortable .arw { opacity: 0; margin-left: 5px; font-size: 10px; transition: opacity .15s; }
table.data th.sorted { color: var(--text); }
table.data th.sorted .arw { opacity: 1; color: var(--accent); }
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover { background: var(--panel-2); }
table.data tbody tr:last-child td { border-bottom: 0; }

.ep-cell { display: flex; align-items: center; gap: 12px; }
.ep-art {
  width: 34px; height: 34px; flex-shrink: 0; border-radius: 8px;
  display: grid; place-items: center; font-weight: 800; font-size: 12px; color: #160d0a;
  font-family: var(--font-display);
}
.ep-title { font-weight: 600; color: var(--text); }
.ep-meta { font-size: 11.5px; color: var(--muted-2); }
.rank { color: var(--muted-2); font-variant-numeric: tabular-nums; width: 22px; }

.pill { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.pill.green { color: var(--pos); background: rgba(53,208,186,.12); }
.pill.amber { color: var(--amber); background: rgba(245,181,68,.13); }
.pill.blue  { color: #6db1ff; background: rgba(74,158,255,.13); }
.pill.gray  { color: var(--muted); background: rgba(255,255,255,.06); }

/* mini progress bar (used in geo + retention) */
.bar-row { display: grid; grid-template-columns: 130px 1fr 56px; align-items: center; gap: 12px; padding: 7px 0; }
.bar-row .lbl { font-size: 13px; color: var(--text); display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .flag { font-size: 15px; }
.bar-track { height: 9px; border-radius: 6px; background: rgba(255,255,255,.08); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 6px; background: var(--grad); width: var(--w); box-shadow: 0 0 12px -2px rgba(255,122,69,.5); transform-origin: left; animation: grow .9s cubic-bezier(.4,0,.2,1); }
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.bar-row .val { font-size: 12.5px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

.legend-inline { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 4px; }
.legend-inline .li { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.legend-inline .sw { width: 9px; height: 9px; border-radius: 3px; }

/* donut + stat combos */
.stat-list { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.stat-line { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.stat-line:last-child { border-bottom: 0; }
.stat-line .k { color: var(--muted); display: flex; align-items: center; gap: 8px; }
.stat-line .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.sw-dot { width: 9px; height: 9px; border-radius: 3px; }

.subtxt { color: var(--muted); font-size: 13px; }
.big-num { font-family: var(--font-display); font-weight: 700; font-size: 26px; letter-spacing: -0.02em; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(10px);
  background: var(--panel-hi); border: 1px solid var(--line-2); color: var(--text);
  padding: 11px 18px; border-radius: 12px; font-size: 13.5px; font-weight: 600;
  box-shadow: 0 16px 40px -14px rgba(0,0,0,.8); opacity: 0; transition: opacity .25s, transform .25s;
  display: flex; align-items: center; gap: 9px; z-index: 60; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pos); }

/* footer */
.dash-footer {
  margin-top: 40px; padding-top: 22px; border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 12.5px; color: var(--muted-2);
}
.dash-footer a { color: var(--muted); text-decoration: none; }
.dash-footer a:hover { color: var(--text); }
.dash-footer .fnav { display: flex; gap: 18px; flex-wrap: wrap; }

/* ---------- Responsive spans ---------- */
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-5 { grid-column: span 5; }
.col-4 { grid-column: span 4; }
.col-12 { grid-column: span 12; }
.grid.g12 { grid-template-columns: repeat(12, 1fr); }

@media (max-width: 1080px) {
  .grid.g12 { grid-template-columns: repeat(6, 1fr); }
  .col-8, .col-6, .col-5, .col-4 { grid-column: span 6; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .sidebar {
    position: fixed; z-index: 50; left: 0; top: 0; height: 100dvh;
    transform: translateX(-100%); transition: transform .28s cubic-bezier(.4,0,.2,1);
    box-shadow: 0 0 60px rgba(0,0,0,.6);
  }
  .sidebar.open { transform: none; }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
  .icon-btn { display: grid; }
  .topbar { padding: 14px 18px; gap: 12px; }
  .topbar-title h1 { font-size: 18px; }
  .topbar-title p { display: none; }
  .btn-ghost span { display: none; }
  .btn-ghost { padding: 8px 10px; }
  .views { padding: 18px 16px 40px; }
  .grid.g12 { grid-template-columns: 1fr; }
  .col-8, .col-6, .col-5, .col-4, .col-12 { grid-column: span 1; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi-val { font-size: 25px; }
  .section-head { margin: 24px 2px 12px; }
}
@media (max-width: 400px) {
  .kpis { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
