/* ============================================================
   UNION — CEO Dashboard  ·  styles
   Apple-style light theme: neutral gray paper, near-black ink,
   Apple blue accent. Fonts: SF Pro (Apple devices) / Inter.
   ============================================================ */

:root {
  /* palette */
  --paper:      #f5f5f7;
  --surface:    #ffffff;
  --surface-2:  #fafafa;
  --ink:        #1d1d1f;
  --ink-soft:   #6e6e73;
  --ink-faint:  #86868b;
  --line:       #e5e5ea;
  --line-soft:  #f0f0f2;

  --accent:     #0071e3;   /* Apple blue */
  --accent-ink: #0058b0;
  --accent-soft:#e8f1fd;
  --gold:       #ff9500;   /* secondary emphasis (Apple orange) */

  --pos:        #248a3d;
  --pos-soft:   #e4f7e9;
  --neg:        #d70015;
  --neg-soft:   #fdeaec;

  --radius:     18px;
  --radius-sm:  12px;
  --shadow:     0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
  --shadow-lg:  0 12px 40px rgba(0,0,0,.10);

  --font-display: -apple-system, "SF Pro Display", "Inter", "Segoe UI", sans-serif;
  --font-body:    -apple-system, "SF Pro Text", "Inter", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 600; letter-spacing: -0.02em; }

button { font-family: inherit; cursor: pointer; }

[hidden] { display: none !important; }

/* ---------- Brand ---------- */
.brand__mark {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  background: var(--ink); color: var(--paper);
  border-radius: 11px;
  font-family: var(--font-display);
  font-weight: 700; font-size: 20px;
  flex: none;
}
.brand__name { font-family: var(--font-display); font-weight: 700; letter-spacing: .14em; }
.brand__sub  { font-size: 12px; color: var(--ink-faint); letter-spacing: .04em; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid transparent; border-radius: 10px;
  padding: 10px 16px; font-size: 14px; font-weight: 600;
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease, border-color .15s;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-ink); box-shadow: 0 6px 18px rgba(15,110,94,.28); }
.btn--soft { background: var(--accent-soft); color: var(--accent-ink); }
.btn--soft:hover { background: #d5e6f9; }
.btn--ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn--ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn--sm { padding: 5px 10px; font-size: 12.5px; margin-right: 6px; }
.btn--block { width: 100%; }
.btn--back { margin-bottom: 18px; }

/* ============================================================
   LOGIN
   ============================================================ */
.login {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.login__panel {
  display: flex; flex-direction: column; justify-content: center;
  padding: 64px clamp(40px, 7vw, 110px);
  max-width: 620px;
}
.login__brand { display: flex; align-items: center; gap: 14px; margin-bottom: 56px; }
.login__title { font-size: clamp(34px, 4vw, 48px); line-height: 1.05; }
.login__lede  { color: var(--ink-soft); margin: 12px 0 36px; font-size: 16px; }
.login__form  { display: flex; flex-direction: column; gap: 16px; max-width: 380px; }
.login__note  { margin-top: 22px; font-size: 13px; color: var(--ink-faint); letter-spacing: .02em; }
.login__error { margin: 4px 0 12px; padding: 9px 12px; border-radius: 8px; font-size: 13.5px;
  background: var(--neg-soft); color: var(--neg); }
.login .lang-toggle { position: fixed; top: 18px; right: 18px; z-index: 5; padding: 5px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  color: var(--ink-soft); font-size: 12.5px; font-weight: 600; cursor: pointer; }
.login .lang-toggle:hover { border-color: var(--accent); color: var(--accent); }
.sidebar__foot .lang-toggle { margin-top: 8px; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field__label { font-size: 12px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .07em; }
.field input, .month select, .upload-controls select, #upload-month {
  padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); color: var(--ink);
  font-family: inherit; font-size: 15px;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* All dropdowns: drop the native OS arrow, use one custom chevron + states */
select {
  appearance: none; -webkit-appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="%238a8d83" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M2.5 4.5 6 8l3.5-3.5"/></svg>');
  background-repeat: no-repeat; background-position: right 12px center;
  cursor: pointer; transition: border-color .14s, box-shadow .14s;
}
select:hover { border-color: var(--accent); }
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
/* leave room for the chevron on the boxed selects */
.month select, .upload-controls select, #upload-month { padding-right: 38px; }

/* in-table controls (mapping dropdown, segment threshold inputs) —
   boxed like the rest, but compact for table rows */
.map-select, .seg-min {
  padding: 7px 32px 7px 11px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background-color: var(--surface-2);
  color: var(--ink); font-family: inherit; font-size: 13.5px;
  background-position: right 10px center; max-width: 220px; width: 100%;
}
.seg-min { max-width: 150px; text-align: right; }
.seg-min:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.login__aside { position: relative; overflow: hidden; background: var(--ink); }
.login__glow {
  position: absolute; inset: -30%;
  background:
    radial-gradient(40% 40% at 70% 30%, rgba(15,110,94,.55), transparent 70%),
    radial-gradient(45% 45% at 30% 75%, rgba(185,137,59,.40), transparent 70%);
  filter: blur(10px);
}
.login__quote {
  position: absolute; left: 56px; right: 56px; bottom: 64px; margin: 0;
  font-family: var(--font-display); font-size: 26px; line-height: 1.35;
  color: rgba(255,255,255,.92);
}

/* ============================================================
   APP SHELL
   ============================================================ */
.app { display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 22px 16px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar__brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 24px; }
.sidebar__brand .brand__name { font-size: 18px; }

/* min-height:0 lets this flex child shrink below its content so a short
   viewport scrolls the nav instead of clipping the sign-out foot below it */
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; min-height: 0; overflow-y: auto; }
/* injected wrappers (#dept-nav/#camp-nav) must not break the flex flow —
   on mobile the nav becomes a horizontal scroll row and block wrappers
   would stack their buttons vertically inside it */
#dept-nav, #camp-nav { display: contents; }

/* mobile drawer controls (shown only in the ≤820px media query) */
.nav-toggle {
  display: none; align-items: center; justify-content: center;
  width: 42px; height: 42px; flex: none;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font-size: 19px; cursor: pointer;
}
.nav-backdrop { position: fixed; inset: 0; z-index: 39; background: rgba(28,29,26,.4); }
.nav__group-label {
  font-size: 13.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-soft); padding: 18px 12px 6px;
}
/* Q&A-style collapsible nav groups (native <details>) */
.nav__group > summary.nav__group-label {
  cursor: pointer; user-select: none; list-style: none;
  display: flex; align-items: center; justify-content: space-between;
}
.nav__group > summary.nav__group-label::-webkit-details-marker { display: none; }
.nav__group > summary.nav__group-label::after {
  content: "▾"; font-size: 10px; transition: transform .15s; color: var(--ink-faint);
}
.nav__group:not([open]) > summary.nav__group-label::after { transform: rotate(-90deg); }
.nav__group > summary.nav__group-label:hover { color: var(--ink); }
.nav__group .nav__item { width: 100%; }
.nav__item {
  display: flex; align-items: center; gap: 10px;
  text-align: left; border: none; background: transparent;
  padding: 11px 12px; border-radius: 10px;
  font-size: 14.5px; font-weight: 500; color: var(--ink-soft);
  transition: background .14s, color .14s;
}
.nav__item:hover { background: var(--surface-2); color: var(--ink); }
.nav__item.is-active { background: var(--ink); color: #fff; font-weight: 600; }
.nav__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.nav__item.is-active .nav__dot { background: var(--gold); }

/* foot lives inside .nav (flex column): margin-top:auto pins it to the bottom */
.sidebar__foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.who { display: flex; align-items: center; gap: 11px; padding: 0 6px; }
.who__avatar {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  background: var(--accent-soft); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.who__name { font-weight: 600; font-size: 14px; }
.who__role { font-size: 12px; color: var(--ink-faint); }

/* ---------- Main ---------- */
/* min-width:0 — as a grid item .main defaults to min-content width, so a wide
   table or a min-width toolbar stretches the column past the viewport and
   everything (cards included) overflows to the right. */
.main { padding: 0 clamp(20px, 3.5vw, 44px) 56px; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 26px 0 20px; margin-bottom: 8px;
  background: linear-gradient(var(--paper) 78%, rgba(246,244,238,0));
}
.topbar__crumb { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.topbar__title { font-size: clamp(24px, 2.4vw, 32px); margin-top: 4px; }
.topbar__tools { display: flex; gap: 14px; align-items: center; }
.month { display: flex; align-items: center; gap: 10px; }
.month__label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); }
.month select { cursor: pointer; }

/* ---------- Mapping chip (top bar) ---------- */
.map-chip {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 7px 14px 7px 11px;
  box-shadow: var(--shadow);
  transition: border-color .14s, box-shadow .14s, transform .12s;
}
.map-chip:hover { border-color: var(--accent); transform: translateY(-1px); }
.map-chip__text { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.map-chip__title { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.map-chip__meta  { font-size: 11px; color: var(--ink-faint); }
.map-chip__badge {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--pos-soft); color: var(--pos);
}
.map-chip__badge.is-warn { background: var(--neg-soft); color: var(--neg); }

/* ---------- Mapping view: warning ---------- */
.map-warning {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--neg-soft); border: 1px solid #eccabf;
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px;
}
.map-warning__icon { font-size: 18px; line-height: 1.3; }
.map-warning__title { font-weight: 600; color: var(--neg); }
.map-warning__body { font-size: 13.5px; color: var(--ink-soft); margin-top: 2px; }

/* mapping table is all text/pills -> left align every column */
#mapping-table th, #mapping-table td { text-align: left; }

/* ---------- Views ---------- */
.view { display: none; animation: rise .4s ease both; }
.view.is-active { display: block; }
/* ponytail: dismissible notice, no markup change — the ::after "×" is the
   affordance, clicking anywhere on it closes. Session-only (a re-render
   brings it back); persist in localStorage if that turns out to annoy. */
.view__context {
  position: relative;
  color: var(--ink-soft); max-width: 70ch; margin: 0 0 22px;
  padding: 14px 44px 14px 16px;
  background: var(--surface-soft, rgba(127,127,127,.08));
  border: 1px solid var(--line, rgba(127,127,127,.2));
  border-radius: 10px;
  cursor: pointer;
}
.view__context::after {
  content: "×";
  position: absolute; top: 8px; right: 12px;
  font-size: 18px; line-height: 1; opacity: .5;
}
.view__context:hover::after { opacity: 1; }
.view__context[hidden] { display: none; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- KPI cards ---------- */
.kpi-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 22px;
}
.kpi-grid--compact { grid-template-columns: repeat(4, 1fr); }
/* big screens: 4-up KPIs (laptop stays 3, tablet 2, phone 1 below) */
@media (min-width: 1600px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
}

.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
  text-align: left; width: 100%;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s;
  animation: rise .5s ease both;
}
.kpi.is-clickable { cursor: pointer; }
.kpi.is-clickable:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: #d9d4c6; }
.kpi__top { display: flex; align-items: center; justify-content: space-between; }
.kpi__label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); letter-spacing: .02em; }
.kpi__value { font-family: var(--font-display); font-size: 30px; font-weight: 600; line-height: 1; }
.kpi__input {
  font-family: var(--font-display); font-size: 26px; font-weight: 600; line-height: 1;
  width: 100%; padding: 2px 0; color: inherit;
  border: 0; border-bottom: 1px dashed var(--line); background: transparent;
}
.kpi__input:focus { outline: none; border-bottom-color: var(--accent); }
.kpi__foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi__sub { font-size: 12px; color: var(--ink-faint); }

.delta { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 600; padding: 3px 8px; border-radius: 999px; }
.delta--pos { color: var(--pos); background: var(--pos-soft); }
.delta--neg { color: var(--neg); background: var(--neg-soft); }
.delta--flat { color: var(--ink-faint); background: var(--line-soft); }

.kpi__cue { font-size: 11px; color: var(--accent); font-weight: 600; opacity: 0; transition: opacity .14s; }
.kpi.is-clickable:hover .kpi__cue { opacity: 1; }

/* Grid children default to min-width:auto (= min-content), so a Chart.js
   canvas or a long unbreakable label widens its track and pushes the whole
   row past the viewport. Let every track shrink instead. */
.kpi-grid > *, .kpi-grid--compact > *, .panel-grid > *, .seg-cards > * { min-width: 0; }

/* ---------- Panels / charts ---------- */
.panel-grid {
  display: grid; gap: 16px;
  grid-template-columns: 2fr 1fr;
  margin-bottom: 16px;
}
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow);
}
/* Panels stacked straight in a view (Accounts) have no grid gap of their own. */
.view > .panel { margin-bottom: 16px; }
.view > .panel:last-child { margin-bottom: 0; }
.panel--wide { grid-column: span 1; }
.panel-grid .panel--wide:nth-child(odd):last-child { grid-column: 1 / -1; }
.panel--full { grid-column: 1 / -1; }
.panel__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel__title { font-size: 17px; }
.panel__hint { font-size: 12.5px; color: var(--ink-faint); }

.chart-box { position: relative; height: 280px; }
.chart-box--donut { height: 280px; }
.chart-box--tall { height: 340px; }

/* ---------- Department strip ---------- */
.source-strip { display: flex; flex-direction: column; gap: 10px; }
.source-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px 16px; background: var(--surface-2); text-align: left; width: 100%;
  transition: transform .12s, border-color .12s, background .12s;
}
.source-card:hover { transform: translateX(3px); border-color: var(--accent); background: var(--surface); }
.source-card__name { font-weight: 600; }
.source-card__meta { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.source-card__val  { font-family: var(--font-display); font-size: 20px; font-weight: 600; }
.source-card__arrow { color: var(--accent); font-weight: 700; }

/* ---------- Tables ---------- */
/* overflow-x:auto forces overflow-y:auto too, so tall expanded rows (the
   department chip lists) get clipped flush against the card edge — pad it. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 12px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 14px; }
.pager__info { font-size: 12.5px; color: var(--ink-faint); }
.pager button[disabled] { opacity: .4; cursor: default; }
.table-wrap.is-dragging { cursor: grabbing; user-select: none; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table thead th {
  text-align: right; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-faint); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table thead th:first-child, .table tbody td:first-child { text-align: left; }
.table thead th { cursor: pointer; user-select: none; }
.table thead th[data-sort="asc"]::after { content: " ↑"; color: var(--accent); }
.table thead th[data-sort="desc"]::after { content: " ↓"; color: var(--accent); }
.table tbody td { padding: 13px 14px; border-bottom: 1px solid var(--line-soft); text-align: right; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody td.cell-strong { font-weight: 600; }
.table tfoot td { padding: 12px 14px; font-weight: 700; text-align: right; border-top: 2px solid var(--line); }
.table tfoot td:first-child { text-align: left; }
.aff-name { display: flex; flex-direction: column; }
.aff-name small { color: var(--ink-faint); font-size: 11.5px; }

.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.pill--seo { background: #e9eef7; color: #355b9c; }
.pill--marketing { background: #f3ecdd; color: #957223; }
.pill--support { background: var(--accent-soft); color: var(--accent-ink); }
.pill--ok  { background: var(--pos-soft); color: var(--pos); }
.pill--bad { background: var(--neg-soft); color: var(--neg); }

/* ---------- Detail head ---------- */
.detail-head { background: var(--ink); color: #fff; border-radius: var(--radius); padding: 26px 28px; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.detail-head__label { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,.6); }
.detail-head__value { font-family: var(--font-display); font-size: 46px; font-weight: 600; line-height: 1.05; margin-top: 6px; }
.detail-head__sub { color: rgba(255,255,255,.7); margin-top: 6px; font-size: 14px; }

/* ---------- Upload ---------- */
.upload-grid { display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 30px 20px; text-align: center; background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.dropzone.is-drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone__icon { font-size: 26px; color: var(--accent); }
.dropzone__text { margin-top: 8px; color: var(--ink-soft); }
.dropzone__or { color: var(--ink-faint); font-size: 12px; margin: 10px 0; }
.dropzone__file { margin-top: 14px; font-size: 13px; font-weight: 600; color: var(--accent-ink); }
.upload-controls { display: flex; gap: 12px; align-items: flex-end; margin-top: 18px; }
.upload-controls .field { flex: 1; }
.upload-note { font-size: 12.5px; color: var(--ink-faint); margin: 14px 0 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 13px 20px; border-radius: 12px;
  box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500;
  opacity: 0; transition: opacity .25s, transform .25s; z-index: 50;
}
.toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================================
   NEW: range filter, retention band, members, user, high-value,
        campaigns, retention analysis, flags
   ============================================================ */

/* ---- Range filter (Google-Finance style) ---- */
.range-filter { display: inline-flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.range-select {
  border: none; background-color: transparent; color: var(--ink-soft);
  font-size: 12.5px; font-weight: 600; padding: 5px 20px 5px 8px; border-radius: 999px;
  background-position: right 5px center;
}
.range-select:hover { border: none; }
.range-sep { color: var(--ink-faint); font-size: 12.5px; align-self: center; }

/* ---- Retention vs target band ---- */
/* margin-bottom matches .kpi-grid so the three overview sections share one rhythm */
.retention-band { padding: 18px 22px; margin-bottom: 22px; }
.ret-band { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 26px; }
.ret-band__label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-faint); }
.ret-band__scope { display: block; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--ink-faint); margin-top: 2px; }
.ret-band__value { font-family: var(--font-display); font-size: 38px; font-weight: 600; line-height: 1.05; margin-top: 4px; }
.ret-band__value--neg { color: var(--neg); }
.ret-band__status { font-size: 12.5px; font-weight: 600; margin-top: 2px; }
.ret-band__status.pos { color: var(--pos); }
.ret-band__status.neg { color: var(--neg); }
.ret-band__gauge { min-width: 160px; }
.ret-band__track { height: 12px; background: var(--line-soft); border-radius: 999px; overflow: hidden; }
.ret-band__fill { height: 100%; background: linear-gradient(90deg, var(--neg), var(--gold)); border-radius: 999px; transition: width .5s ease; }
.ret-band__scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-faint); margin-top: 5px; }
.ret-band__churn { text-align: center; padding: 0 10px; border-left: 1px solid var(--line); }
.ret-band__more { font-size: 12px; font-weight: 600; color: var(--ink-faint); white-space: nowrap; }
#retention-band .ret-band { grid-template-columns: auto 1fr auto auto; }
#retention-band:hover .ret-band__more { color: var(--ink); }

/* ---- dept strip color bar ---- */
.source-card { position: relative; padding-left: 18px; }
.source-card__bar { position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 999px; }

/* ---- Members ---- */
.members-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.members-search {
  flex: 1; min-width: 220px; padding: 11px 14px; border: 1px solid var(--line);
  border-radius: 10px; font-family: inherit; font-size: 14.5px; background: var(--surface);
}
.members-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.members-toolbar select { padding: 11px 38px 11px 14px; border: 1px solid var(--line); border-radius: 10px; background-color: var(--surface); font-family: inherit; font-size: 14.5px; }
.members-count { font-size: 13px; color: var(--ink-faint); margin-left: auto; }

.table--click tbody tr { cursor: pointer; }

/* ---- Flags / extra pills ---- */
.pill--idle { background: var(--line-soft); color: var(--ink-faint); }
.pill--warn { background: #f3ecdd; color: #957223; }
.flag { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.flag--milli { background: #efe6fb; color: #6c4bb6; }
.flag--whale { background: #e2eef7; color: #2f6ca0; }

/* ---- User detail ---- */
.user-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.user-head__id { display: flex; align-items: center; gap: 14px; }
.user-head__avatar { width: 52px; height: 52px; border-radius: 14px; background: var(--ink); color: #fff; display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 20px; }
.user-head__handle { font-family: var(--font-display); font-size: 24px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.user-head__meta { color: var(--ink-faint); font-size: 13px; margin-top: 4px; display: flex; align-items: center; gap: 8px; }
.user-profile { display: flex; flex-direction: column; gap: 2px; }
.prop { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.prop:last-child { border-bottom: none; }
.prop__k { color: var(--ink-faint); }
.prop__v { font-weight: 600; text-align: right; }
.muted { color: var(--ink-faint); font-weight: 400; }
#user-months tr.is-current td { background: var(--accent-soft); }
#user-months tr.is-muted td { color: var(--ink-faint); }

/* ---- Campaigns ---- */
.campaign-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.camp-card {
  text-align: left; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px; cursor: pointer;
  transition: transform .14s, box-shadow .14s, border-color .14s;
}
.camp-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: #d9d4c6; }
.camp-card.is-live { border-color: var(--accent); }
.camp-card__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.camp-card__name { font-family: var(--font-display); font-size: 18px; font-weight: 600; }
.camp-card__period { font-size: 12.5px; color: var(--ink-faint); }
.camp-card__affs { font-size: 12px; color: var(--ink-soft); }
.camp-card__stats { display: flex; gap: 18px; margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.camp-card__stats div { display: flex; flex-direction: column; font-size: 11.5px; color: var(--ink-faint); }
.camp-card__stats span { font-family: var(--font-display); font-size: 18px; font-weight: 600; color: var(--ink); }

/* ---- Player segment cards ---- */
/* self-responsive: 3-up when there's room, then 2, then 1 — no breakpoints */
.seg-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-bottom: 16px; }
.seg-card {
  background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--seg, var(--accent));
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
  /* clickable: reset button defaults, keep card look */
  width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.seg-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg, var(--shadow)); }
.seg-card.is-active { border-color: var(--seg); box-shadow: 0 0 0 1px var(--seg) inset; }
.seg-ref { margin-bottom: 16px; }
.seg-ref summary { cursor: pointer; font-size: 13px; color: var(--ink-soft); padding: 4px 0; }
.seg-card__title { font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.seg-card__title span { font-size: 13px; color: var(--ink-faint); font-family: var(--font-body); font-weight: 500; }
.seg-card__count { font-family: var(--font-display); font-size: 34px; font-weight: 600; line-height: 1.1; margin-top: 6px; color: var(--seg); }
.seg-card__meta { font-size: 12.5px; color: var(--ink-faint); }
.seg-card__rows { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 6px; }
.seg-card__row { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-soft); }
.seg-card__row b { color: var(--ink); }

/* ============================================================
   RESPONSIVE
   ------------------------------------------------------------
   Breakpoints:
     1200  small laptop  -> narrower sidebar
     1080  tablet land.  -> 2-col KPIs, charts stack full width
      820  tablet port.  -> sidebar becomes sticky top bar
      540  phone         -> single column, condensed type
   ============================================================ */

/* --- small laptop: reclaim width from the sidebar --- */
@media (max-width: 1200px) {
  .app { grid-template-columns: 220px 1fr; }
}

/* --- tablet landscape: stack the chart grid, 2-up KPIs --- */
@media (max-width: 1080px) {
  .kpi-grid, .kpi-grid--compact { grid-template-columns: repeat(2, 1fr); }
  .panel-grid { grid-template-columns: 1fr; }
  .panel--wide { grid-column: 1 / -1; }
  .upload-grid { grid-template-columns: 1fr; }
  .chart-box, .chart-box--donut { height: 260px; }
  .campaign-grid { grid-template-columns: repeat(2, 1fr); }
  /* include the #id form: #retention-band .ret-band (line ~463) outranks .ret-band here */
  .ret-band, #retention-band .ret-band { grid-template-columns: 1fr 1fr; row-gap: 16px; }
  .ret-band__gauge { grid-column: 1 / -1; order: 4; min-width: 0; }
}

/* --- tablet portrait & below: sidebar -> sticky horizontal top bar --- */
@media (max-width: 820px) {
  .login { grid-template-columns: 1fr; }
  .login__aside { display: none; }
  .login__panel { padding: 48px 28px; }

  .app { grid-template-columns: 1fr; }

  .sidebar {
    /* min-width:0 — as a grid item the sidebar defaults to min-content, and the
       no-wrap nav row would stretch it (and the whole page) to ~1400px wide */
    min-width: 0;
    position: sticky; top: 0; z-index: 20;
    height: auto; width: 100%;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    gap: 10px 8px; padding: 12px 16px;
    box-shadow: 0 6px 18px rgba(28,29,26,.06);
  }
  .sidebar__brand { padding: 0; margin-right: auto; }

  /* nav becomes a slide-in drawer behind a hamburger button */
  .nav-toggle { display: flex; order: 10; }
  .nav {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 40;
    width: min(300px, 82vw); min-width: 0;
    flex-direction: column; gap: 4px; overflow-y: auto;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
    background: var(--surface);
    box-shadow: 0 0 40px rgba(28,29,26,.18);
    transform: translateX(-105%); transition: transform .25s ease;
  }
  .nav.is-open { transform: translateX(0); }

  .sidebar__foot { margin-top: 24px; } /* in the drawer: sits after the menu, not glued to screen bottom */
  .who__avatar { display: none; } /* drawer foot: name and position only */

  /* topbar no longer needs to stick (sidebar already does) */
  .topbar { position: static; background: none; padding: 22px 0 16px; }

  .main { padding: 0 18px 48px; }
  .detail-head__value { font-size: 38px; }
}

/* --- narrow screens: collapse Upload History table into stacked cards --- */
@media (max-width: 680px) {
  #history-table { font-size: 13.5px; }
  #history-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  #history-table, #history-table tbody, #history-table tr, #history-table td { display: block; width: 100%; }

  #history-table tbody tr {
    border: 1px solid var(--line-soft); border-radius: 12px;
    padding: 6px 14px; margin-bottom: 12px; background: var(--surface-2);
  }
  #history-table tbody tr:last-child { margin-bottom: 0; }
  #history-table tbody tr:hover { background: var(--surface-2); }

  #history-table tbody td {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 9px 0; text-align: right; white-space: normal; border-bottom: 1px solid var(--line-soft);
  }
  #history-table tbody tr td:last-child { border-bottom: none; }
  #history-table tbody td::before {
    content: attr(data-label); flex: none;
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    color: var(--ink-faint); text-align: left;
  }
  /* file name can be long: let it wrap and break cleanly */
  #history-table tbody td[data-label="File"] { word-break: break-word; }
}

/* --- phone: single column, condensed --- */
@media (max-width: 540px) {
  .kpi-grid, .kpi-grid--compact { grid-template-columns: 1fr; }

  .topbar { flex-direction: column; align-items: stretch; gap: 12px; }
  .topbar__tools { justify-content: space-between; }
  .month { flex: 1; }
  .month select { flex: 1; }

  .panel { padding: 16px; }
  .chart-box, .chart-box--donut { height: 240px; }
  .chart-box--tall { height: 280px; }

  .kpi__value { font-size: 26px; }
  .detail-head { padding: 20px; }
  .detail-head__value { font-size: 32px; }

  .toast { left: 16px; right: 16px; transform: translateY(20px); text-align: center; }
  .toast.is-show { transform: translateY(0); }

  .campaign-grid { grid-template-columns: 1fr; }
  .ret-band, #retention-band .ret-band { grid-template-columns: 1fr; }
  .ret-band__churn { border-left: none; text-align: left; padding: 0; }
  .user-head { flex-direction: column; align-items: flex-start; gap: 12px; }
  .members-count { margin-left: 0; }

  /* compact mapping chip: drop the text column, keep icon + badge */
  .map-chip__text { display: none; }
  .map-chip { padding: 7px 12px; }
}

/* Department rule editor (Accounts) */
.dept-prefix { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); font-family: inherit; font-size: 13px; }
.dept-prefix:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dept-default-lbl { display: flex; align-items: center; gap: 6px; margin-top: 6px;
  font-size: 12px; color: var(--ink-soft); cursor: pointer; }

/* Department membership chips (Accounts) — shows what's ACTUALLY in a department */
.aff-list summary { cursor: pointer; font-size: 13px; color: var(--ink-soft); padding: 2px 0; }
.aff-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; max-height: 180px; overflow-y: auto; }
.aff-chip { display: inline-flex; align-items: baseline; gap: 5px; padding: 3px 8px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); font-size: 12px; }
.aff-chip small { color: var(--ink-faint); font-size: 10.5px; }

/* ---- Campaign verdict + builder ---- */
/* One color scale for "is this campaign working": win / warn / loss / open.
   Used by the sidebar tag, the card badge, and the detail banner. */
.camp-tag {
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  padding: 3px 8px; border-radius: 999px; white-space: nowrap;
}
.camp-tag.is-win  { background: var(--pos-soft); color: var(--pos); }
.camp-tag.is-loss { background: var(--neg-soft); color: var(--neg); }
.camp-tag.is-warn { background: #f3ecdd; color: #957223; }
.camp-tag.is-open { background: var(--surface-2); color: var(--ink-faint); }

.nav__item--add { color: var(--accent); font-weight: 600; }
.nav__item .nav__tag {
  margin-left: auto; font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 999px;
}
.nav__item .nav__tag.is-win  { background: var(--pos-soft); color: var(--pos); }
.nav__item .nav__tag.is-loss { background: var(--neg-soft); color: var(--neg); }
.nav__item .nav__tag.is-warn { background: #f3ecdd; color: #957223; }
.nav__item .nav__tag.is-open { background: var(--surface-2); color: var(--ink-faint); }
.nav__item.is-active .nav__tag { background: rgba(255,255,255,.16); color: #fff; }

#camp-pick-table input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
