/* ==========================================================================
   River Player — application design system
   One stylesheet for the whole portal. Light theme only.
   ========================================================================== */

:root {
  /* Surfaces */
  --bg:            #ffffff;
  --bg-sunken:     #fafaf9;
  --surface:       #ffffff;
  --surface-hover: #f6f6f5;
  --surface-sunk:  #f7f7f6;

  /* Lines — ~20% more contrast against the white surface than the original
     #e9e9e6 / #dcdcd8 pair, so card edges and table rules read clearly. */
  --line:          #e0e0dc;
  --line-strong:   #cfcfc9;

  /* Type */
  --text:          #14140f;
  --text-2:        #6a6a63;
  --text-3:        #9b9b93;
  --text-invert:   #ffffff;

  /* Brand + data */
  --accent:        #d9622d;
  --accent-hover:  #c35524;
  --accent-soft:   #fbeee7;
  --positive:      #2f8f5b;
  --positive-soft: #e8f3ec;
  --negative:      #c0392b;
  --negative-soft: #fbeceb;

  /* Identity. Three kinds of viewer need telling apart at a glance, and the
     accent is already spoken for as the brand colour, so these borrow the
     data-series hues at the same low saturation as the pair above. */
  --known:        #3d7f96;
  --known-soft:   #e9f0f3;
  --shared:       #7a6bab;
  --shared-soft:  #f0eef7;

  --series-1: #d9622d;
  --series-2: #3d7f96;
  --series-3: #7a6bab;
  --series-4: #4f9268;
  --series-5: #bd9330;
  --series-6: #ab5570;

  /* Shape */
  --r-sm: 6px;
  --r:    10px;
  --r-lg: 14px;
  --r-pill: 999px;

  /* Spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;

  --shadow-sm: 0 1px 2px rgba(20, 20, 15, 0.04);
  --shadow:    0 4px 16px rgba(20, 20, 15, 0.07);
  --shadow-lg: 0 16px 48px rgba(20, 20, 15, 0.12);

  --sidebar-w: 244px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 56px;

  /* Type system
     Display  — Instrument Sans, a grotesque with enough character to keep
                headings from reading as a bootstrap default.
     UI/body  — Inter, which stays legible in dense tables at 13px.
     Mono     — JetBrains Mono for IDs, embed codes and raw values. */
  --font-display: 'Instrument Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ==========================================================================
   Reset
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'tnum' 0;
}

h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.021em;
  line-height: 1.22;
  color: var(--text);
}
h1 { font-size: 1.5rem; letter-spacing: -0.028em; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
h4 { font-size: 0.875rem; letter-spacing: -0.012em; }

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
img, svg, canvas { display: block; max-width: 100%; }
ul, ol { list-style: none; }

::selection { background: var(--accent-soft); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* Icons.
   We load the Rounded variant (softer terminals, better match for the rounded
   UI) but keep the .material-icons class everywhere. The Google-hosted sheet
   for that family only defines .material-icons-round, so bind the class here.
   Glyph names are identical between the variants, so nothing can go missing. */
.material-icons,
.material-icons-round {
  font-family: 'Material Icons Round', 'Material Icons';
  font-weight: normal;
  font-style: normal;
  display: inline-block;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* Scrollbars — thin and unobtrusive */
* { scrollbar-width: thin; scrollbar-color: #d5d5d0 transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #d5d5d0; border-radius: var(--r-pill); }
*::-webkit-scrollbar-thumb:hover { background: #bdbdb7; }

/* ==========================================================================
   App shell
   ========================================================================== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--bg-sunken);
  border-right: 1px solid var(--line);
  transition: width 0.18s ease;
  z-index: 40;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  height: var(--topbar-h);
  padding: 0 0.875rem;
  flex-shrink: 0;
}
.sidebar-brand img { width: 22px; height: 22px; border-radius: var(--r-sm); }
.sidebar-brand .brand-name {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.625rem 0.75rem;
}
.nav-group + .nav-group { margin-top: 1.25rem; }
.nav-label {
  padding: 0 0.5rem 0.375rem;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-3);
  white-space: nowrap;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.5rem 0.5625rem;
  border-radius: var(--r);
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: -0.014em;
  text-align: left;
  color: var(--text-2);
  transition: background 0.12s ease, color 0.12s ease;
  white-space: nowrap;
}
.nav-item .material-symbols-rounded,
.nav-item .material-icons {
  font-size: 20px;
  flex-shrink: 0;
  color: var(--text-3);
  transition: color 0.12s ease;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item:hover .material-icons,
.nav-item:hover .material-symbols-rounded { color: var(--text-2); }
/* A flat tinted pill. No border or shadow, so the row never shifts by a pixel
   between states and it does not read as a stray button. */
.nav-item.active {
  background: rgba(20, 20, 15, 0.055);
  color: var(--text);
  font-weight: 600;
}
.nav-item.active:hover { background: rgba(20, 20, 15, 0.075); }
.nav-item.active .material-icons,
.nav-item.active .material-symbols-rounded { color: var(--accent); }

/* Matches the nav's horizontal padding exactly so Sign out lines up with the
   items above it. */
.sidebar-foot {
  padding: 0.5rem 0.625rem 0.625rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.sidebar-foot form { width: 100%; margin: 0; }
/* Centred and a step down from the nav items, so it reads as a utility
   action rather than another destination. */
.sidebar-foot .nav-item {
  width: 100%;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: -0.012em;
}
.sidebar-foot .nav-item .material-icons { font-size: 18px; }
.sidebar-foot .nav-item:hover { color: var(--negative); }
.sidebar-foot .nav-item:hover .material-icons { color: var(--negative); }

/* Collapsed sidebar */
.sidebar.collapsed { width: var(--sidebar-w-collapsed); }
.sidebar.collapsed .brand-name,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-text { display: none; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 0; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 0.5rem 0; }
.sidebar.collapsed .nav-item.active { padding: calc(0.5rem - 1px) 0; }

/* Main column */
.main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.18s ease;
}
.sidebar.collapsed ~ .main { margin-left: var(--sidebar-w-collapsed); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.crumbs {
  display: flex;
  align-items: center;
  gap: 0.4375rem;
  font-size: 0.9375rem;
  min-width: 0;
}
.crumbs .crumb-current {
  font-family: var(--font-display);
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.018em;
}

.topbar-spacer { flex: 1; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.625rem 0.25rem 0.3125rem;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface);
  transition: background 0.12s ease;
}
.user-chip:hover { background: var(--surface-hover); }
.user-chip .avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--text);
  color: var(--text-invert);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
}
.user-chip .user-name { font-size: 0.8125rem; font-weight: 500; }
.user-chip .chip-caret { font-size: 16px; color: var(--text-3); margin-left: -0.125rem; }
.user-chip:hover .chip-caret { color: var(--text-2); }

.content {
  flex: 1;
  padding: 1.5rem 1.25rem 4rem;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
}
.content-wide { max-width: none; }

/* Page header */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.page-head h1 { font-size: 1.375rem; }
.page-head .page-sub {
  margin-top: 0.1875rem;
  font-size: 0.8438rem;
  color: var(--text-2);
}
.page-head-actions { display: flex; align-items: center; gap: 0.5rem; }

/* ==========================================================================
   Buttons & controls
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 34px;
  padding: 0 0.8125rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 0.8438rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}
.btn:hover { background: var(--surface-hover); }
.btn .material-icons { font-size: 17px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--text);
  border-color: var(--text);
  color: var(--text-invert);
}
.btn-primary:hover { background: #2b2b24; border-color: #2b2b24; }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-invert);
}
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-hover); }

.btn-danger { color: var(--negative); border-color: var(--line-strong); }
.btn-danger:hover { background: var(--negative-soft); border-color: var(--negative); }

.btn-sm { height: 28px; padding: 0 0.625rem; font-size: 0.8125rem; }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }

.input, .select, textarea.input {
  width: 100%;
  height: 34px;
  padding: 0 0.625rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 0.8438rem;
  color: var(--text);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
textarea.input { height: auto; min-height: 84px; padding: 0.5rem 0.625rem; resize: vertical; line-height: 1.5; }
.input::placeholder { color: var(--text-3); }
.input:focus, .select:focus, textarea.input:focus {
  outline: none;
  border-color: var(--text-3);
  box-shadow: 0 0 0 3px rgba(20, 20, 15, 0.05);
}

.select {
  appearance: none;
  padding-right: 1.875rem;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%236a6a63' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
  cursor: pointer;
}

.field { display: flex; flex-direction: column; gap: 0.375rem; }
.field-label { font-size: 0.8125rem; font-weight: 500; color: var(--text-2); }
.field-hint { font-size: 0.75rem; color: var(--text-3); }

.search-input {
  position: relative;
  display: flex;
  align-items: center;
}
.search-input .material-icons {
  position: absolute;
  left: 0.5625rem;
  font-size: 17px;
  color: var(--text-3);
  pointer-events: none;
}
.search-input .input { padding-left: 2rem; }

/* Segmented control */
.segmented {
  display: inline-flex;
  padding: 2px;
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  gap: 2px;
}
.segmented a, .segmented button {
  padding: 0.25rem 0.5625rem;
  border-radius: 5px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}
.segmented a:hover, .segmented button:hover { color: var(--text); }
.segmented a.active, .segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   Hints — a quiet "i" that explains what a metric actually measures.
   The bubble is a single shared, position:fixed element (see base.html), so it
   can never be clipped by a card's overflow or a stat grid's rounded corners.
   ========================================================================== */
.hint-icon {
  display: inline-grid;
  place-items: center;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: transparent;
  color: var(--text-3);
  font-family: var(--font);
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  opacity: 0.65;
  transition: opacity 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  vertical-align: middle;
}
.hint-icon:hover,
.hint-icon:focus-visible {
  opacity: 1;
  color: var(--text);
  border-color: var(--text-2);
}
/* Keep the affordance discoverable but recessive until the row is hovered. */
.card-head .hint-icon,
.stat .hint-icon { opacity: 0.4; }
.card:hover .card-head .hint-icon,
.stat:hover .hint-icon { opacity: 0.7; }
.card-head .hint-icon:hover,
.card-head .hint-icon:focus-visible,
.stat .hint-icon:hover,
.stat .hint-icon:focus-visible { opacity: 1; }

.hint-bubble {
  position: fixed;
  z-index: 1300;
  max-width: 280px;
  padding: 0.5rem 0.625rem;
  background: var(--text);
  color: rgba(255, 255, 255, 0.92);
  border-radius: var(--r-sm);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.5;
  text-align: left;
  letter-spacing: 0;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.hint-bubble.show { opacity: 1; transform: none; }
.hint-bubble[hidden] { display: none; }

/* Chips / badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.4375rem;
  border-radius: var(--r-sm);
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
}
.badge-accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.badge-positive { background: var(--positive-soft); border-color: transparent; color: var(--positive); }
.badge-negative { background: var(--negative-soft); border-color: transparent; color: var(--negative); }
.badge-known  { background: var(--known-soft);  border-color: transparent; color: var(--known); }
.badge-shared { background: var(--shared-soft); border-color: transparent; color: var(--shared); }
.badge-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.tag {
  display: inline-flex;
  padding: 0.1875rem 0.5rem;
  border-radius: var(--r-pill);
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  font-size: 0.75rem;
  color: var(--text-2);
}

/* ==========================================================================
   Cards & panels
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9375rem 1.125rem;
  border-bottom: 1px solid var(--line);
}
.card-head-plain { border-bottom: none; padding-bottom: 0; }
.card-head h2, .card-head h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}
.card-head .card-sub {
  margin-top: 0.125rem;
  font-size: 0.8125rem;
  color: var(--text-2);
}
.card-head-actions { display: flex; align-items: center; gap: 0.375rem; flex-shrink: 0; }
.card-body { padding: 1.125rem; }
.card-body-flush { padding: 0; }
.card-foot {
  padding: 0.75rem 1.125rem;
  border-top: 1px solid var(--line);
  background: var(--bg-sunken);
  font-size: 0.8125rem;
  color: var(--text-2);
}

/* Grid helpers */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-full { grid-column: 1 / -1; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; align-items: center; gap: 0.5rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.wrap { flex-wrap: wrap; }

/* ==========================================================================
   Stat tiles
   ========================================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.stat {
  position: relative;
  padding: 0.9375rem 1.125rem;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
/* Pinned to the tile corner rather than trailing the label, so the labels
   stay left-aligned with each other across the row. */
.stat > .hint-icon {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
}
.stat .stat-label { padding-right: 1.25rem; }
.stat:last-child { border-right: none; }
.stat-label {
  display: flex;
  align-items: center;
  gap: 0.3125rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-label .material-icons { font-size: 15px; color: var(--text-3); }
/* Tiles group into three families, and only the icon carries the colour:
   reach is how far the content travelled, time is how long people stayed,
   engagement is what they did beyond watching. Enough to scan a row of tiles
   by, not enough to turn the grid into a chart. Library tiles stay grey,
   since inventory is not a performance number. */
.stat-reach  .stat-label .material-icons { color: var(--accent); }
.stat-time   .stat-label .material-icons { color: var(--known); }
.stat-engage .stat-label .material-icons { color: var(--shared); }
.stat-value {
  margin-top: 0.375rem;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.034em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat-value small { font-size: 0.875rem; font-weight: 500; color: var(--text-2); letter-spacing: 0; }
.stat-meta {
  margin-top: 0.3125rem;
  font-size: 0.75rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.delta { font-weight: 550; }
.delta-up { color: var(--positive); }
.delta-down { color: var(--negative); }
.delta-flat { color: var(--text-3); }

/* Standalone stat card variant */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 0.9375rem 1.125rem;
}

/* ==========================================================================
   Charts
   ========================================================================== */
.chart { position: relative; width: 100%; }
.chart-sm  { height: 160px; }
.chart-md  { height: 220px; }
.chart-lg  { height: 300px; }
.chart-xl  { height: 380px; }

/* A chart with nothing to plot collapses to a short message rather than
   leaving a tall blank rectangle. */
.chart.is-empty { height: auto; min-height: 120px; }
.chart-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4375rem;
  min-height: 120px;
  padding: 1.25rem 1rem;
  text-align: center;
  color: var(--text-3);
  font-size: 0.8125rem;
  line-height: 1.5;
}
.chart-empty span:last-child { max-width: 34ch; }
.chart-empty .material-icons { font-size: 22px; opacity: 0.55; }

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-2);
}
.legend-item { display: inline-flex; align-items: center; gap: 0.375rem; }
.legend-swatch { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* Heatmap (day-of-week x hour) */
.heatmap { display: grid; gap: 3px; font-size: 0.6875rem; }
.heatmap-grid {
  display: grid;
  grid-template-columns: 30px repeat(24, minmax(0, 1fr));
  gap: 3px;
  align-items: center;
}
.heatmap-hour-label,
.heatmap-day-label {
  font-size: 0.6875rem;
  color: var(--text-3);
  text-align: center;
  white-space: nowrap;
}
.heatmap-day-label { text-align: left; padding-right: 0.25rem; }
.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--surface-sunk);
  min-height: 14px;
  transition: transform 0.1s ease;
}
.heatmap-cell:hover { transform: scale(1.25); z-index: 1; position: relative; }
.heatmap-l0 { background: #f4f4f2; }
.heatmap-l1 { background: #f7ddcd; }
.heatmap-l2 { background: #eeb08a; }
.heatmap-l3 { background: #de8351; }
.heatmap-l4 { background: #c1541f; }
/* Shared shade legend: swatch + the volume range it represents. */
.heatmap-scale,
.map-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  font-size: 0.6875rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.scale-caption { color: var(--text-2); font-weight: 500; margin-right: 0.125rem; }
.scale-step { display: inline-flex; align-items: center; gap: 0.3125rem; }
.scale-step i,
.heatmap-scale > i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: block;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(20, 20, 15, 0.08);
}
.map-legend {
  padding: 0.625rem 1.125rem;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.map-legend .scale-step i { border-radius: 50%; }

/* Bar list — ranked rows with an inline proportional bar */
.bar-list { display: flex; flex-direction: column; }
.bar-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.625rem;
  border-radius: var(--r-sm);
  font-size: 0.8438rem;
  isolation: isolate;
  min-width: 0;
}
.bar-row + .bar-row { margin-top: 2px; }
.bar-row::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--bar, 0%);
  background: var(--accent-soft);
  border-radius: var(--r-sm);
  z-index: -1;
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.bar-row:hover::before { background: #f7e2d6; }
.bar-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  overflow: hidden;
}
.bar-label .rank {
  width: 17px;
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.bar-label .name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 450;
}
.bar-value {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 550;
  font-size: 0.8125rem;
}
.bar-value .muted { font-weight: 400; color: var(--text-3); }

/* ==========================================================================
   Tables
   ========================================================================== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.8438rem; }
.table th {
  padding: 0.5625rem 1.125rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-2);
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td {
  padding: 0.6875rem 1.125rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-sunken); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .cell-strong { font-weight: 550; }
.table .cell-muted { color: var(--text-2); }
.table .cell-title {
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Mini inline progress meter used inside table cells */
.meter {
  position: relative;
  height: 5px;
  min-width: 56px;
  border-radius: var(--r-pill);
  background: var(--surface-sunk);
  overflow: hidden;
}
.meter > span {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--val, 0%);
  background: var(--accent);
  border-radius: var(--r-pill);
}
.meter-positive > span { background: var(--positive); }

/* ==========================================================================
   Empty / loading states
   ========================================================================== */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 2.5rem 1.25rem;
  text-align: center;
  color: var(--text-2);
}
.empty .material-icons { font-size: 26px; color: var(--text-3); }
.empty-title { font-size: 0.875rem; font-weight: 550; color: var(--text); }
.empty-text { font-size: 0.8125rem; color: var(--text-2); max-width: 34ch; }
.empty-sm { padding: 1.5rem 1rem; }

.skeleton {
  background: linear-gradient(90deg, #f2f2f0 25%, #eaeae7 37%, #f2f2f0 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer {
  0%   { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ==========================================================================
   Video cards / library grids
   ========================================================================== */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(224px, 1fr));
  gap: 1.125rem 1rem;
}

.video-card { display: block; min-width: 0; }
.video-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--r);
  overflow: hidden;
  background: var(--surface-sunk) center/cover no-repeat;
  border: 1px solid var(--line);
  transition: box-shadow 0.16s ease, transform 0.16s ease;
}
.video-card:hover .video-thumb {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.video-thumb .thumb-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20, 20, 15, 0.28);
  opacity: 0;
  transition: opacity 0.16s ease;
}
.video-card:hover .thumb-overlay { opacity: 1; }
.thumb-overlay .play-badge {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  box-shadow: var(--shadow);
}
.thumb-overlay .play-badge .material-icons { font-size: 22px; }
.thumb-overlay .overlay-action {
  padding: 0.3125rem 0.75rem;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 550;
}
.video-thumb .duration {
  position: absolute;
  right: 0.375rem;
  bottom: 0.375rem;
  padding: 0.0625rem 0.3125rem;
  border-radius: var(--r-sm);
  background: rgba(20, 20, 15, 0.78);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
/* Title and view count share one line; the count is pinned right and never
   shrinks, the title takes whatever is left. */
.video-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding-top: 0.5rem;
}
.video-meta .title {
  min-width: 0;
  font-size: 0.8438rem;
  font-weight: 550;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.video-meta .views {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
}
.section-head h2 { font-size: 1rem; }
.section-head .count { font-size: 0.8125rem; color: var(--text-3); }
.section + .section { margin-top: 2rem; }

/* ==========================================================================
   Modal
   ========================================================================== */
/* The stream-lytics player paints its processing overlay at z-index 1000 from
   inside its shadow DOM, and the host creates no stacking context of its own,
   so it competes at the root. Overlays must clear that. */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(20, 20, 15, 0.32);
  backdrop-filter: blur(3px);
}
.modal-panel {
  width: 100%;
  max-width: 640px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}
.modal-panel-lg { max-width: 880px; }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(6px) scale(0.99); }
  to   { opacity: 1; transform: none; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 1rem; }
.modal-body { padding: 1.25rem; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--line);
  background: var(--bg-sunken);
}

/* ==========================================================================
   Code blocks
   ========================================================================== */
.code {
  position: relative;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
.code pre {
  margin: 0;
  padding: 0.875rem 1rem 2.75rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}
.code .copy-btn { position: absolute; right: 0.5rem; bottom: 0.5rem; }

/* ==========================================================================
   Utilities
   ========================================================================== */
.muted    { color: var(--text-2); }
.subtle   { color: var(--text-3); }
.tnum     { font-variant-numeric: tabular-nums; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mono     { font-family: var(--mono); }
.fs-xs    { font-size: 0.75rem; }
.fs-sm    { font-size: 0.8125rem; }
.fw-500   { font-weight: 500; }
.fw-600   { font-weight: 600; }
.mt-1 { margin-top: var(--sp-1); } .mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); } .mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); } .mt-6 { margin-top: var(--sp-6); }
.mb-2 { margin-bottom: var(--sp-2); } .mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); } .mb-5 { margin-bottom: var(--sp-5); }
.hidden { display: none !important; }
.divider { height: 1px; background: var(--line); border: 0; }
.scroll-y { overflow-y: auto; }
.max-h-280 { max-height: 280px; }
.max-h-360 { max-height: 360px; }

/* Toast */
.toast-host {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.875rem;
  background: var(--text);
  color: var(--text-invert);
  border-radius: var(--r);
  font-size: 0.8438rem;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.18s ease;
}
.toast .material-icons { font-size: 17px; }
.toast-error { background: var(--negative); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-3 { grid-column: span 2; }
}

@media (max-width: 860px) {
  .sidebar { width: var(--sidebar-w-collapsed); }
  .sidebar .brand-name,
  .sidebar .nav-label,
  .sidebar .nav-text { display: none; }
  .sidebar .sidebar-brand { justify-content: center; padding: 0; }
  .sidebar .nav-item { justify-content: center; padding: 0.5rem 0; }
  .main { margin-left: var(--sidebar-w-collapsed); }
}

@media (max-width: 720px) {
  .content { padding: 1.125rem 0.875rem 3rem; }
  .grid-2, .grid-3, .grid-4, .grid-auto { grid-template-columns: minmax(0, 1fr); }
  .span-2, .span-3 { grid-column: span 1; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(2n) { border-right: none; }
  .page-head { flex-direction: column; align-items: stretch; }
  .heatmap-grid { grid-template-columns: 26px repeat(24, minmax(0, 1fr)); gap: 2px; }
  .table th, .table td { padding-left: 0.75rem; padding-right: 0.75rem; }
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
