:root {
  /* Soulspace brand palette — official tokens from brand guidelines */
  --brand-gold: #C5A572;        /* primary gold (decorative) */
  --brand-mint: #B8E4D8;         /* secondary mint (decorative, sidebar) */
  --brand-mint-dark: #8FB8AB;    /* mint shade for hover states on mint bg */
  --brand-mint-accent: #6B9E8E;  /* mint deep — for active state on mint bg */

  --accent: #A77735;            /* darker gold — for UI text/buttons (WCAG AA) */
  --accent-soft: #C4945D;
  --accent-light: #EBDBBC;

  --bg: #FAF6EE;
  --card: #FFFFFF;
  --text: #1C1612;
  --text-muted: #6B5E52;
  --border: #E8DFD1;

  --positive: #4A7C2E;
  --negative: #B85450;

  --chart-total: #A77735;
  --chart-ios: #3E7CB1;
  --chart-android: #5C8A3A;

  /* Revenue chart split palettes — chosen to stay on-brand and legible
     on both light + dark. Distinct from user-chart palette so the two
     hourly stacks read as different data domains. */
  --rev-new:          #6B9E8E;  /* mint-deep: first-time revenue */
  --rev-renewal:      #A77735;  /* brand gold: renewal revenue */
  --rev-stripe:       #8B5CF6;  /* violet: Stripe platform */
  --rev-period-year:  #A77735;
  --rev-period-month: #3E7CB1;
  --rev-period-life:  #6B9E8E;
  --rev-period-unk:   #9B8F80;
  --rev-referral:     #B85450;  /* warm red: referral */
  --rev-no-referral:  #9B8F80;  /* grey: no referral */
  --rev-country-other:#9B8F80;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(28, 22, 18, 0.04), 0 4px 12px rgba(28, 22, 18, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Stage Grotesk", "SF Pro Display", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1612;
    --card: #2A221E;
    --text: #EBDBBC;
    --text-muted: #A89A8A;
    --border: #3A322C;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

h1, h2, h3 { margin: 0; }
h2 { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }

.muted { color: var(--text-muted); }

/* ---------- Auth screen ---------- */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 48px 40px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}
.auth-card h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 12px;
}
.auth-card p { color: var(--text-muted); margin: 0 0 24px; }

.btn-primary {
  background: var(--accent);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 500;
  transition: background 120ms ease;
}
.btn-primary:hover { background: #8E6129; }

.btn-ghost {
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  transition: background 120ms ease, color 120ms ease;
}
.btn-ghost:hover { background: var(--border); color: var(--text); }

.error {
  color: var(--negative);
  margin-top: 16px;
  font-size: 14px;
}

/* ---------- App layout: sidebar + main ---------- */
.app-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--brand-mint);
  border-right: 1px solid color-mix(in srgb, var(--brand-mint-accent) 25%, transparent);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand { padding: 0 8px; color: var(--text); }
.sidebar .brand-mark {
  background: var(--accent);  /* gold crown-dot stands out on mint */
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: color-mix(in srgb, var(--text) 72%, transparent);
  text-decoration: none;
  transition: background 120ms, color 120ms;
}
.nav-item:hover {
  background: color-mix(in srgb, var(--brand-mint-accent) 18%, transparent);
  color: var(--text);
}
.nav-item.active {
  background: var(--accent);
  color: white;
}
.nav-item.active .nav-icon { opacity: 1; }
.nav-icon {
  display: inline-block;
  width: 16px;
  text-align: center;
  font-size: 13px;
  opacity: 0.9;
}

.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 24px 60px;
  width: 100%;
  min-width: 0;
}

.page { display: flex; flex-direction: column; min-width: 0; }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 20px;
}
.page-head h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }

@media (max-width: 720px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav-item { white-space: nowrap; }
}

/* ---------- Dashboard (legacy name, now just the Dashboard page) ---------- */
.dashboard {
  /* Kept for JS compatibility; real layout is .app-layout + .app-main */
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 16px;
  border-bottom: 1px solid var(--border);
}
.app-header-right { display: flex; align-items: center; gap: 12px; }
.app-logo {
  height: 40px;
  width: auto;
  display: block;
}
@media (max-width: 720px) {
  .app-logo { height: 32px; }
  .app-header { flex-wrap: wrap; }
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }

.header-right { display: flex; align-items: center; gap: 12px; }
.live {
  font-size: 12px;
  color: var(--positive);
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--positive) 10%, transparent);
}
.user-chip {
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 10px;
  background: var(--border);
}

.subheader {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 14px 0 24px;
  font-size: 14px;
}
.subheader time { font-weight: 600; color: var(--text); }
.divider { color: var(--text-muted); }

/* ---------- Highlights bar ---------- */
.highlights-bar {
  margin-bottom: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius, 10px);
  overflow: hidden;
}
.highlights-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: left;
}
.highlights-toggle:hover { color: var(--text); }
.highlights-icon {
  color: var(--accent);
  font-size: 14px;
}
.highlights-chevron {
  margin-left: auto;
  font-size: 20px;
  transition: transform 0.2s ease;
}
.highlights-bar.open .highlights-chevron {
  transform: rotate(90deg);
}
.highlights-body {
  padding: 0 16px 14px;
}
.highlights-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  padding-left: 6px;
}
.highlights-text ul {
  margin: 0;
  padding-left: 18px;
  list-style: none;
}
.highlights-text li {
  position: relative;
  padding: 2px 0;
}
.highlights-text li::before {
  content: "–";
  position: absolute;
  left: -14px;
  color: var(--text-muted);
}
.highlights-quiet {
  color: var(--text-muted);
  font-style: italic;
}

/* ---------- KPI row ---------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-tile {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  border: 1px solid var(--border);
}
.kpi-tile label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 12px;
}
.kpi-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1;
}
.kpi-delta {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
}
.kpi-delta.positive { color: var(--positive); }
.kpi-delta.negative { color: var(--negative); }

/* Second sub-line on a KPI tile — used for the platform breakdown on
   the New Users Today tile (below the DoD delta). */
.kpi-subline {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-height: 18px;
}

/* Compact stats strip inside the daily-trend cards (above the chart).
   Three equal cells: avg, low-high, range-pace estimate. Mirrors the
   KPI-tile visual language but tighter so it sits comfortably between
   the card header and the chart. */
.trend-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 4px 0 14px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.trend-stat label {
  display: block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}
.trend-stat .value {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 20px 24px;
  margin-bottom: 20px;
  min-width: 0;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.range-toggle {
  display: inline-flex;
  gap: 2px;
  background: var(--bg);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.range-toggle button {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: background 120ms, color 120ms;
}
.range-toggle button.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.chart-wrap {
  position: relative;
  height: 280px;
}

/* Split toggle — pill-style, only one active. Visually distinct from
   range-toggle (which is a time-window selector) by a slightly warmer
   active state so the two never get confused side-by-side. */
.split-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 16px;
}
.split-toggle button {
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.split-toggle button:hover { color: var(--text); border-color: var(--accent-soft); }
.split-toggle button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Coming-soon cards on the Revenue tab — dimmer so they don't compete
   with live data cards. */
.card.coming-soon { opacity: 0.7; }
.card.coming-soon p { font-size: 13.5px; margin: 0; }

/* Promo-code chip row on the Sharing tab. Toggle-style filter chips. */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 4px 0 14px;
}
.chip {
  padding: 4px 12px;
  font-size: 12.5px;
  font-weight: 500;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.chip:hover { color: var(--text); border-color: var(--accent-soft); }
.chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.chip .chip-count {
  opacity: 0.65;
  font-weight: 400;
  margin-left: 4px;
}

/* Instagram outreach tab */
.account-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.account-split-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.account-split-item label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.account-split-item strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
  color: var(--text);
}
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  background: var(--border);
  color: var(--text-muted);
}
.status-sent { background: #E6EEF8; color: #3060A0; }
.status-replied,
.status-positive_reply,
.status-converted { background: #E8F0E0; color: #4A7A28; }
.status-follow_up_due { background: #F4EBD6; color: #8A6028; }
.status-opt_out,
.status-not_fit { background: #F8E4E0; color: #8A3530; }
.ig-account-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--mono, ui-monospace, monospace);
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.ig-account-app { background: #F4EBD6; color: #8A6028; }
.ig-account-family { background: #E0ECF4; color: #2A6496; }
.message-icon-btn {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}
.message-icon-btn svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
}
.message-icon-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}
.ig-message-text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.5;
  color: var(--text);
}

/* Social Videos decision cockpit. Compact by design: it should support
   repeated production decisions, not read like a strategy document. */
.source-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.source-status-grid article {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.source-status-grid label {
  display: block;
  margin-bottom: 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.source-status-grid strong {
  display: block;
  color: var(--text);
}
.source-status-grid span {
  display: block;
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-muted);
}
.scorecard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.scorecard-item {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.scorecard-item label {
  display: block;
  margin-bottom: 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.scorecard-item strong {
  display: block;
  font-size: 14px;
  line-height: 1.25;
  color: var(--text);
}
.scorecard-item span {
  display: block;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.scorecard-item p {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
}
.decision-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}
.decision-rule {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.decision-rule strong {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
}
.decision-rule p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-muted);
}
.source-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.source-list a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--bg);
  text-decoration: none;
  font-size: 13px;
}
.source-list a:hover {
  border-color: var(--accent-soft);
  color: var(--accent);
}

/* ---------- Social Videos redesign ---------- */
.btn-secondary {
  background: var(--card); color: var(--accent); border: 1px solid var(--border);
  padding: 6px 14px; border-radius: 6px; font-weight: 500; cursor: pointer;
  font-size: 13px;
}
.btn-secondary:hover { border-color: var(--accent); }
.btn-secondary:disabled { opacity: 0.6; cursor: wait; }

.sv-insights { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.sv-insight {
  padding: 8px 12px; border-radius: 6px; font-size: 13.5px; line-height: 1.45;
  background: var(--bg); border-left: 3px solid var(--border);
}
.sv-insight-positive { border-left-color: var(--positive); }
.sv-insight-negative { border-left-color: var(--negative); }
.sv-insight-info { border-left-color: var(--accent); }

.sv-plat-badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  color: #fff; font-size: 11px; font-weight: 600; letter-spacing: 0.5px;
}

.sv-plat-breakdown { display: flex; flex-direction: column; gap: 10px; }
.sv-plat-row { display: flex; align-items: center; gap: 12px; }
.sv-plat-stats { display: flex; gap: 14px; font-size: 13px; flex-wrap: wrap; }
.sv-plat-stats strong { font-weight: 600; }

.sv-best-times-list { padding-left: 20px; margin: 0; }
.sv-best-times-list li { padding: 4px 0; font-size: 13.5px; line-height: 1.5; }

.sv-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.sv-hook-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }

.sv-sortable { cursor: pointer; user-select: none; }
.sv-sortable:hover { color: var(--accent); }
.sv-sort-active { color: var(--accent); font-weight: 700; }

.sv-er-good { color: var(--positive); font-weight: 600; }
.sv-er-bad { color: var(--negative); }

@media (max-width: 720px) {
  .account-split { grid-template-columns: 1fr; }
  .scorecard-grid,
  .decision-grid { grid-template-columns: 1fr; }
  .sv-two-col { grid-template-columns: 1fr; }
}

/* Claude's note on the latest day — conversational, not a KPI. */
#sharing-remark-card .remark-body {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text);
}
#sharing-remark-card .remark-body strong { color: var(--accent); font-weight: 600; }

/* Event-feed rows — compact, scannable. */
#rc-events-table td { padding: 8px 12px; font-size: 13px; }
#rc-events-table .evt-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.3px;
}
#rc-events-table .evt-type.evt-new      { background: #E5F1ED; color: #2E6A58; }
#rc-events-table .evt-type.evt-renewal  { background: #F4EBD6; color: #8A6028; }
#rc-events-table .evt-type.evt-refund   { background: #F8E4E0; color: #8A3530; }
#rc-events-table .evt-type.evt-trial    { background: #E6EEF8; color: #3060A0; }
#rc-events-table .evt-type.evt-other    { background: var(--border); color: var(--text-muted); }
#rc-events-table td.num-amount {
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-weight: 500;
}
#rc-events-table td.num-amount.negative { color: var(--negative); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; max-width: 100%; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }

/* Daily revenue breakdown — transposed table (dates as columns, segments
   as row groups). Pair Revenue + Transactions rows visually by removing
   the inner border between them, and keep segment + metric label cells
   compact. Row-average column gets a subtle accent. */
#revenue-daily-breakdown { font-size: 13px; }
#revenue-daily-breakdown th,
#revenue-daily-breakdown td { padding: 8px 12px; white-space: nowrap; }
#revenue-daily-breakdown td.segment-label {
  font-weight: 600;
  vertical-align: middle;
  color: var(--text);
}
#revenue-daily-breakdown td.metric-label {
  color: var(--text-muted);
  font-weight: 500;
}
#revenue-daily-breakdown tr.revenue-row td { border-bottom: none; }
#revenue-daily-breakdown tr.txn-row td { border-bottom: 1px solid var(--border); }
#revenue-daily-breakdown tr:last-child td { border-bottom: none; }
#revenue-daily-breakdown td.row-avg,
#revenue-daily-breakdown th.num:last-child {
  font-weight: 600;
  border-left: 1px solid var(--border);
}
/* Pin the left segment-label column so Total / Renewal / New stay visible
   while the date columns scroll horizontally (relevant at 30d / 90d).
   The corner header cell (empty <th> at top-left) gets the same treatment
   so it doesn't show through the scrolling date headers. Solid background
   prevents bleed-through. z-index lifts the sticky cells above the
   scrolling cells they overlay. */
#revenue-daily-breakdown thead th:first-child,
#revenue-daily-breakdown td.segment-label {
  position: sticky;
  left: 0;
  background: var(--card);
  z-index: 1;
  border-right: 1px solid var(--border);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--accent);
}
.empty-state { text-align: center; padding: 24px 0; }

.expand-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 16px auto 0;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.expand-btn:hover { background: var(--border); color: var(--text); }
.expand-btn .chevron {
  display: inline-block;
  transition: transform 180ms ease;
}
.expand-btn[aria-expanded="true"] .chevron { transform: rotate(180deg); }

.trend-wrap { margin-top: 16px; height: 240px; }

/* --- Promo codes table --- */
.promo-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.promo-filters input, .promo-filters select {
  padding: 6px 10px; font: inherit; font-size: 13px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
}
.promo-filters input { min-width: 200px; }

.promo-table { width: 100%; border-collapse: collapse; }
.promo-table th, .promo-table td {
  padding: 10px 8px; text-align: left; font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

/* Automations inventory tab (Phase 1) */
.automations-table { width: 100%; border-collapse: collapse; }
.automations-table th, .automations-table td {
  padding: 12px 10px; text-align: left; font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.automations-table th { font-weight: 500; color: var(--text-muted); font-size: 12px; letter-spacing: 0.02em; text-transform: uppercase; }
.automations-table tr:last-child td { border-bottom: none; }
.auto-name { font-weight: 600; color: var(--text); }
.auto-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; margin-top: 2px; }
.auto-purpose { color: var(--text); max-width: 480px; line-height: 1.45; }
.promo-table th { font-weight: 500; color: var(--text-muted); }
.promo-table td.num, .promo-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.promo-code-cell { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 500; color: var(--text); }
.promo-code-desc { display: block; font-family: inherit; font-weight: normal; color: var(--text-muted); font-size: 11.5px; margin-top: 2px; }
.type-badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.3px;
}
.type-gift      { background: #F4EBD6; color: #8A6028; }
.type-promo     { background: #E6EEF8; color: #3060A0; }
.type-affiliate { background: #E8F0E0; color: #4A7A28; }

.switch { position: relative; display: inline-block; width: 34px; height: 18px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0; background: #CBC2B3; border-radius: 18px;
  transition: background 150ms; cursor: pointer;
}
.switch-track::before {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%; background: white;
  transition: transform 150ms;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::before { transform: translateX(16px); }
.switch input:disabled + .switch-track { opacity: 0.5; cursor: not-allowed; }

.btn-delete {
  background: transparent; border: 1px solid transparent;
  color: var(--text-muted); cursor: pointer; font-size: 14px;
  padding: 4px 8px; border-radius: 6px;
}
.btn-delete:hover { background: #F8E4E0; color: var(--negative); border-color: #E8C6C0; }

/* --- Promo code modal --- */
dialog.modal {
  padding: 0;
  border: none;
  border-radius: 12px;
  max-width: 520px;
  width: 92%;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(28, 22, 18, 0.25);
}
dialog.modal::backdrop { background: rgba(28, 22, 18, 0.45); }
.modal-form { display: flex; flex-direction: column; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-close {
  background: transparent; border: none; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--text-muted);
  padding: 4px 10px; border-radius: 6px;
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body { padding: 18px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 22px; border-top: 1px solid var(--border);
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; font-weight: 500; }
.field input[type="text"],
.field input[type="number"],
.field input[type="datetime-local"],
.field select,
.field textarea {
  padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
}
.field input:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 20%, transparent);
}
.field textarea { resize: vertical; min-height: 52px; }
.field small { font-size: 11.5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-inline { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.field-inline input[type="checkbox"] { width: 16px; height: 16px; }
.modal-error { color: var(--negative); font-size: 13px; margin: 0; }
.btn-primary {
  background: var(--accent); color: white; border: none;
  padding: 8px 16px; border-radius: 6px; font-weight: 500; cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }

.app-footer {
  text-align: center;
  padding: 40px 0 0;
  font-size: 12px;
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .app-main { padding: 16px; }
  .kpi-row { grid-template-columns: 1fr; gap: 12px; }
  .kpi-value { font-size: 28px; }
  .card { padding: 16px; }
  .chart-wrap { height: 220px; }
  .app-header { flex-wrap: wrap; gap: 10px; }
  .user-chip { display: none; }
}
