@font-face { font-family: "DM Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/dm-sans-400.ttf") format("truetype"); }
@font-face { font-family: "DM Sans"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/dm-sans-500.ttf") format("truetype"); }
@font-face { font-family: "DM Sans"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/dm-sans-600.ttf") format("truetype"); }
@font-face { font-family: "DM Sans"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/dm-sans-700.ttf") format("truetype"); }
@font-face { font-family: "DM Sans"; font-style: italic; font-weight: 400; font-display: swap; src: url("../fonts/dm-sans-italic-400.ttf") format("truetype"); }

/* SA Grocery Sales Dashboard — v2 theme: deep teal + warm off-white */
:root {
  --bg: #FAF9F6;
  --surface: #FFFFFF;
  --surface-alt: #F6F4EF;
  --border: #DCD7CC;
  --border-soft: #EAE6DD;
  --text: #1C1F23;
  --text-muted: #6B6B66;
  --text-faint: #A9A69E;
  --primary: #0F766E;
  --primary-hover: #0B5B55;
  --primary-soft: #E3F2F0;
  --header-bg: #12312F;
  --header-text: #F4F7F6;
  --error: #B42318;
  --warning: #B45309;
  --success: #15803D;
  --warning-bg: #FEF6E7;
  --error-bg: #FDECEA;
  --success-bg: #ECF7EF;

  /* Channel colors */
  --ch-ecom: #14B8A6;
  --ch-hs: #EA580C;
  --ch-ty: #9333EA;
  --ch-combo: #6366F1;
  --ch-hm: #1E3A5F;

  --region-akb: #0F766E;
  --region-jed: #EA580C;
  --region-ruh: #6366F1;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(28, 31, 35, 0.05), 0 6px 16px rgba(28, 31, 35, 0.045);
  --shadow-lg: 0 8px 32px rgba(28, 31, 35, 0.12);
  --font: "DM Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --header-h: 64px;
  --filter-h: 56px;
}


*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font-family: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }

/* ========== Layout ========== */
.app-header {
  /* v9: the topbar scrolls away — only the slim sticky bar stays */
  position: relative;
  z-index: 100;
  height: var(--header-h);
  background: linear-gradient(100deg, #0E2A29 0%, var(--header-bg) 45%, #16403C 100%);
  color: var(--header-text);
  border-bottom: 1px solid #0A211F;
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  box-shadow: var(--shadow);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 220px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(140deg, #14B8A6, #0F766E);
  display: grid;
  place-items: center;
  color: #fff;
}
.brand-mark svg { width: 20px; height: 20px; }
.brand h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.brand .subtitle {
  margin: 0;
  font-size: 0.72rem;
  color: rgba(244, 247, 246, 0.68);
  font-weight: 400;
}

.nav-tabs {
  display: flex;
  gap: 0.25rem;
  background: rgba(255, 255, 255, 0.08);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
}
.nav-tab {
  border: none;
  background: transparent;
  color: rgba(244, 247, 246, 0.78);
  padding: 0.45rem 0.95rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s ease;
}
.nav-tab:hover { color: #fff; background: rgba(255,255,255,0.12); }
.nav-tab.active {
  background: #fff;
  color: #0B5B55;
  box-shadow: var(--shadow);
  font-weight: 600;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}
.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.app-header .btn {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.22);
  color: #F4F7F6;
}
.app-header .btn:hover { background: rgba(255, 255, 255, 0.2); color: #fff; border-color: #fff; }
.app-header .btn-primary { background: var(--primary); border-color: var(--primary); color: #06251F; font-weight: 600; }
.app-header .btn-primary:hover { background: #2DD4BF; border-color: #2DD4BF; color: #06251F; }
.app-header .btn-ghost { background: rgba(255,255,255,0.08); color: #F4F7F6; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ========== Filters bar ========== */
.filters-bar {
  position: relative;
  z-index: 90;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.filter-group label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.filter-group select,
.filter-group input[type="text"],
.search-box input {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 0.65rem;
  font-size: 0.8125rem;
  background: var(--surface);
  color: var(--text);
  min-width: 130px;
  max-width: 200px;
}
.filter-group select:focus,
.filter-group input:focus,
.search-box input:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}
.search-box {
  flex: 1;
  min-width: 220px;
  position: relative;
}
.search-box input {
  width: 100%;
  max-width: none;
  padding-left: 2rem;
}
.search-box .search-icon {
  position: absolute;
  left: 0.55rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
  width: 16px;
  height: 16px;
}
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  max-height: 320px;
  overflow-y: auto;
  z-index: 200;
  display: none;
}
.search-results.open { display: block; }
.search-section-title {
  padding: 0.45rem 0.75rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--surface-alt);
}
.search-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--text);
  border-bottom: 1px solid var(--border-soft);
}
.search-item:hover { background: var(--primary-soft); color: var(--primary); }
.search-item .meta { color: var(--text-muted); font-size: 0.72rem; }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.25rem 0.55rem 0.25rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
}
.chip button {
  border: none;
  background: transparent;
  color: var(--primary);
  padding: 0;
  line-height: 1;
  font-size: 1rem;
  opacity: 0.7;
}
.chip button:hover { opacity: 1; }
.chip.warning {
  background: var(--warning-bg);
  color: var(--warning);
}

/* ========== Main ========== */
main {
  padding: 1.25rem;
  max-width: 1600px;
  margin: 0 auto;
}
.view { display: none; }
.view.active { display: block; }

.page-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.page-title-row h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.page-title-row p {
  margin: 0.2rem 0 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}
.data-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.note-pill {
  font-size: 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  color: var(--text-muted);
}

/* ========== KPI cards ========== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.1rem;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--primary);
}
.kpi-card.ecom::before { background: var(--ch-ecom); }
.kpi-card.hs::before { background: var(--ch-hs); }
.kpi-card.ty::before { background: var(--ch-ty); }
.kpi-card.combo::before { background: var(--ch-combo); }
.kpi-card.hm::before { background: var(--ch-hm); }
.kpi-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.kpi-value {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.kpi-sub {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.72rem;
  font-weight: 600;
  margin-top: 0.3rem;
}
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--error); }
.kpi-delta.flat { color: var(--text-muted); }

/* ========== Cards / panels ========== */
.panel-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 0.95rem;
  margin-bottom: 1rem;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel.span-4 { grid-column: span 4; }
.panel.span-5 { grid-column: span 5; }
.panel.span-6 { grid-column: span 6; }
.panel.span-7 { grid-column: span 7; }
.panel.span-8 { grid-column: span 8; }
.panel.span-12 { grid-column: span 12; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem 0.55rem;
  border-bottom: 1px solid var(--border-soft);
}
.panel-header h3 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.panel-header .hint {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.panel-body {
  padding: 0.85rem 1rem 1rem;
  flex: 1;
  min-height: 0;
}
.panel-body.tight { padding: 0; }
.chart-wrap {
  position: relative;
  width: 100%;
  height: 280px;
}
.chart-wrap.sm { height: 220px; }
.chart-wrap.lg { height: 340px; }

/* ========== Channel comparison ========== */
.channel-compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}
.channel-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  background: var(--surface-alt);
  position: relative;
}
.channel-card.weak {
  border-color: #E8B4A0;
  background: var(--warning-bg);
}
.channel-card.weak::after {
  content: "Weakest channel";
  position: absolute;
  top: 0.45rem;
  right: 0.5rem;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--warning);
  background: #fff;
  border: 1px solid #E8B4A0;
  border-radius: 999px;
  padding: 0.1rem 0.4rem;
}
.channel-card .ch-name {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.4rem;
}
.channel-card.ecom .ch-name { color: var(--ch-ecom); }
.channel-card.hs .ch-name { color: var(--ch-hs); }
.channel-card.ty .ch-name { color: var(--ch-ty); }
.channel-card.combo .ch-name { color: var(--ch-combo); }
.channel-card.hm .ch-name { color: var(--ch-hm); }
.channel-card .ch-value {
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.channel-card .ch-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-variant-numeric: tabular-nums;
}
.share-rows {
  margin-top: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.share-row {
  display: grid;
  grid-template-columns: 90px 1fr 52px;
  gap: 0.4rem;
  align-items: center;
  font-size: 0.72rem;
}
.share-row .lbl { color: var(--text-muted); }
.share-bar {
  height: 6px;
  background: var(--border-soft);
  border-radius: 99px;
  overflow: hidden;
}
.share-bar > i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: var(--primary);
}
.share-row .pct {
  text-align: right;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* ========== Tables ========== */
.table-wrap {
  overflow: auto;
  max-height: 420px;
}
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
table.data-table th {
  position: sticky;
  top: 0;
  background: var(--surface-alt);
  text-align: left;
  padding: 0.55rem 0.75rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  z-index: 1;
}
table.data-table th.num,
table.data-table td.num {
  text-align: right;
}
table.data-table td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
table.data-table tr:hover td { background: #F1F8F7; }
table.data-table tr.clickable { cursor: pointer; }
table.data-table .rank {
  color: var(--text-faint);
  font-weight: 600;
  width: 28px;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.68rem;
  font-weight: 650;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-warn {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid #E8C4B0;
}
.badge-multi {
  background: #F3EAFB;
  color: #7A39BB;
  border: 1px solid #D4B8F0;
}
.badge-ok {
  background: var(--success-bg);
  color: var(--success);
}
.badge-ch {
  background: var(--primary-soft);
  color: var(--primary);
}
.mini-bars {
  display: flex;
  gap: 3px;
  align-items: flex-end;
  height: 22px;
}
.mini-bars span {
  width: 8px;
  border-radius: 2px 2px 0 0;
  min-height: 2px;
}
.mini-bars .ecom { background: var(--ch-ecom); }
.mini-bars .hs { background: var(--ch-hs); }
.mini-bars .ty { background: var(--ch-ty); }
.mini-bars .combo { background: var(--ch-combo); }
.mini-bars .hm { background: var(--ch-hm); }

/* ========== Insights strip ========== */
.insights-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.insight-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}
.insight-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 1rem;
}
.insight-card h4 {
  margin: 0 0 0.2rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.insight-card p {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.35;
}
.insight-card .sub {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 0.15rem;
}

/* ========== Vendor panel ========== */
.vendor-alert {
  display: none;
  align-items: flex-start;
  gap: 0.65rem;
  background: #F3EAFB;
  border: 1px solid #D4B8F0;
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.85rem;
  font-size: 0.8125rem;
}
.vendor-alert.show { display: flex; }
.vendor-alert strong { color: #7A39BB; }
.vendor-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 360px;
  overflow-y: auto;
}
.vendor-item {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
  background: var(--surface-alt);
}
.vendor-item.multi {
  border-color: #D4B8F0;
  background: #FBF7FE;
}
.vendor-item .vn {
  font-weight: 650;
  font-size: 0.875rem;
}
.vendor-item .vm {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* ========== Share analysis panel ========== */
.share-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0.75rem;
}
.share-channel-block {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  background: var(--surface-alt);
}
.share-channel-block.weak {
  border-color: #E8B4A0;
  background: var(--warning-bg);
  box-shadow: inset 0 0 0 1px rgba(150, 66, 25, 0.08);
}
.share-channel-block h4 {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.flag-weak {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--warning);
  background: #fff;
  border: 1px solid #E8B4A0;
  border-radius: 999px;
  padding: 0.12rem 0.4rem;
}

/* ========== Empty / loading ========== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(247, 246, 242, 0.85);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  backdrop-filter: blur(4px);
}
.loading-overlay.hidden { display: none; }
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ========== Modal ========== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(40, 37, 29, 0.4);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 14px;
  width: min(520px, 100%);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  /* v10: always fit the screen so the close button stays reachable — matters in
     installed (standalone) mode where there is no browser back button */
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.modal > .modal-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal > .modal-footer { flex: 0 0 auto; }
.modal-header h3 { margin: 0; font-size: 1rem; }
.modal-body { padding: 1.15rem; }
.modal-footer {
  padding: 0.85rem 1.15rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  margin-bottom: 0.85rem;
  background: var(--surface-alt);
}
.upload-zone p { margin: 0.35rem 0 0; font-size: 0.8rem; color: var(--text-muted); }
.upload-zone label.file-label {
  display: inline-flex;
  margin-top: 0.5rem;
}
.help-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.help-list li { margin-bottom: 0.35rem; }
.status-msg {
  font-size: 0.8rem;
  margin-top: 0.5rem;
  min-height: 1.2em;
}
.status-msg.ok { color: var(--success); }
.status-msg.err { color: var(--error); }

/* ========== Legend ========== */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.legend i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}
.legend .ecom i { background: var(--ch-ecom); }
.legend .hs i { background: var(--ch-hs); }
.legend .ty i { background: var(--ch-ty); }
.legend .combo i { background: var(--ch-combo); }
.legend .hm i { background: var(--ch-hm); }
.legend .akb i { background: var(--region-akb); }
.legend .jed i { background: var(--region-jed); }
.legend .ruh i { background: var(--region-ruh); }

/* ========== Breadcrumb flow ========== */
.flow-crumbs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.flow-crumbs button {
  border: none;
  background: none;
  color: var(--primary);
  font-weight: 600;
  padding: 0;
  font-size: inherit;
}
.flow-crumbs button:hover { text-decoration: underline; }
.flow-crumbs .sep { color: var(--text-faint); }
.flow-crumbs .current { color: var(--text); font-weight: 600; }

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--text);
  color: #fff;
  padding: 0.75rem 1.1rem;
  border-radius: 10px;
  font-size: 0.8125rem;
  box-shadow: var(--shadow-lg);
  z-index: 10000;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.25s ease;
  pointer-events: none;
  max-width: 360px;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ========== Responsive ========== */
@media (max-width: 1100px) {
  .panel.span-4, .panel.span-5, .panel.span-6, .panel.span-7, .panel.span-8 {
    grid-column: span 12;
  }
  .channel-compare, .share-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}
@media (max-width: 720px) {
  .app-header { flex-wrap: wrap; height: auto; padding: 0.65rem 0.85rem; }
  .brand { min-width: 0; }
  .nav-tabs { order: 3; width: 100%; overflow-x: auto; }
  .header-actions { margin-left: 0; }
  .filters-bar { top: auto; position: relative; }
  main { padding: 0.85rem; }
  .kpi-value { font-size: 1.2rem; }
  .btn span.hide-sm { display: none; }
}

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

/* =========================================================
 *  v2 components
 * ========================================================= */

/* ---- Channel toggles ---- */
.ch-toggles {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  height: 34px;
  font-size: 0.78rem;
  font-weight: 500;
  flex-wrap: wrap;
}
.ch-toggle-label {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  padding: 0.15rem 0.45rem 0.15rem 0.3rem;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}
.ch-toggle-label input { accent-color: currentColor; margin: 0; }
.ch-toggle-label.ecom { color: #0D8A7D; }
.ch-toggle-label.hs { color: #C2410C; }
.ch-toggle-label.ty { color: #7E22CE; }
.ch-toggle-label.combo { color: #4F46E5; }
.ch-toggle-label.hm { color: var(--ch-hm); }
.ch-toggle-label:hover { border-color: currentColor; }

/* ---- Searchable multi-select ---- */
.ms { position: relative; }
.ms-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  height: 34px;
  min-width: 150px;
  max-width: 220px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.8125rem;
  padding: 0 0.5rem 0 0.65rem;
  text-align: left;
}
.ms-btn svg { width: 14px; height: 14px; color: var(--text-faint); flex-shrink: 0; }
.ms-btn-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-btn:hover { border-color: var(--primary); }
.ms-btn.has-value {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: #0B5B55;
  font-weight: 600;
}
.ms.open .ms-btn { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12); }
.ms-pop {
  display: none;
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  width: 280px;
  max-width: 78vw;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  overflow: hidden;
}
.ms.open .ms-pop { display: block; }
.ms-pop-head { padding: 0.5rem; border-bottom: 1px solid var(--border-soft); }
.ms-search {
  width: 100%;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 0.55rem;
  font-size: 0.8125rem;
  background: var(--surface-alt);
  color: var(--text);
}
.ms-search:focus { outline: none; border-color: var(--primary); background: #fff; }
.ms-list { max-height: 260px; overflow-y: auto; padding: 0.25rem; }
.ms-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  font-size: 0.8125rem;
  cursor: pointer;
}
.ms-item:hover { background: var(--surface-alt); }
.ms-item.sel { background: var(--primary-soft); }
.ms-item input { accent-color: var(--primary); flex-shrink: 0; margin: 0; }
.ms-item-label { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.ms-item-label em {
  font-style: normal;
  font-size: 0.68rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.ms-empty, .ms-more {
  padding: 0.6rem 0.5rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
}
.ms-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  border-top: 1px solid var(--border-soft);
  background: var(--surface-alt);
  font-size: 0.7rem;
  color: var(--text-muted);
}
.ms-clear {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  color: var(--text);
  font-weight: 600;
}
.ms-clear:hover { border-color: var(--primary); color: var(--primary); }

/* ---- Chips ---- */
.chip .chip-k {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.75;
  font-weight: 700;
}
.chip-empty { font-size: 0.72rem; color: var(--text-muted); }

/* ---- Search result rows ---- */
.search-item {
  display: grid;
  grid-template-columns: 74px 1fr auto;
  gap: 0.5rem;
  align-items: baseline;
}
.res-type {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.12rem 0.35rem;
  border-radius: 5px;
  text-align: center;
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border-soft);
}
.res-type.brand { background: var(--primary-soft); color: #0B5B55; border-color: #BFE3DE; }
.res-type.category { background: #FFF1E6; color: #C2410C; border-color: #F8D3B8; }
.res-type.department { background: #EEF0FF; color: #4338CA; border-color: #CBD2FA; }
.res-type.vendor { background: #F3EAFB; color: #7A39BB; border-color: #D4B8F0; }
.res-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-item .meta { font-variant-numeric: tabular-nums; }

/* ---- Share panel v2 ---- */
.share-channel-block { border-top: 3px solid var(--border); }
.share-channel-block.ecom { border-top-color: var(--ch-ecom); }
.share-channel-block.hs { border-top-color: var(--ch-hs); }
.share-channel-block.ty { border-top-color: var(--ch-ty); }
.share-channel-block.combo { border-top-color: var(--ch-combo); }
.share-channel-block.hm { border-top-color: var(--ch-hm); }
.share-channel-block .sc-name { font-size: 0.8rem; font-weight: 700; }
.share-channel-block .sc-value {
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.share-channel-block .sc-qty { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.1rem; }
/* v5: plain-words "share within X" subtitle under each channel name */
.share-channel-block .sc-basis {
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 0.1rem 0 0.3rem;
  color: var(--text-muted);
}
.share-channel-block.ecom .sc-basis { color: var(--ch-ecom); }
.share-channel-block.hs .sc-basis { color: var(--ch-hs); }
.share-channel-block.ty .sc-basis { color: var(--ch-ty); }
.share-channel-block.combo .sc-basis { color: var(--ch-combo); }
.share-channel-block.hm .sc-basis { color: var(--ch-hm); }
.share-row { grid-template-columns: 104px 1fr 54px; }
.share-bar.total > i { background: var(--primary); }
.share-bar.dept > i { background: var(--ch-hs); }
.share-bar.cat > i { background: var(--ch-combo); }
.share-note {
  margin: 0.85rem 0 0;
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.channel-card .ch-tag {
  margin-left: 0.35rem;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 0.05rem 0.35rem;
  vertical-align: middle;
}

/* ---- Cell sub-labels ---- */
.cell-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
table.data-table.compact { font-size: 0.75rem; }

/* ---- Vendor focus ---- */
.vendor-focus {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  padding: 0.85rem;
  margin-bottom: 0.75rem;
}
.vf-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}
.vf-name { font-weight: 700; font-size: 0.95rem; }
.vf-sub { font-size: 0.72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.vf-total {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  text-align: right;
  line-height: 1.15;
}
.vf-total span { display: block; font-size: 0.65rem; color: var(--text-muted); font-weight: 500; }
.vf-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.85rem;
  margin-top: 0.75rem;
}
.vf-cols h5 {
  margin: 0 0 0.35rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.vf-cols ul { list-style: none; margin: 0; padding: 0; font-size: 0.78rem; }
.vf-cols li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.2rem 0;
  border-bottom: 1px dashed var(--border-soft);
}
.vf-cols li b { font-variant-numeric: tabular-nums; }
.vf-cols li em { font-style: normal; color: var(--text-faint); font-size: 0.68rem; }

/* ---- Insights tab ---- */
.explainer {
  margin: 0 0 0.9rem;
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--text-muted);
  background: var(--surface-alt);
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0.7rem 0.9rem;
}
.explainer strong { color: var(--text); }
.insight-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}
.seg {
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
  flex-wrap: wrap;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
}
.seg-btn:hover { color: var(--text); background: rgba(15, 118, 110, 0.07); }
.seg-btn.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 650;
  box-shadow: var(--shadow);
}
.gap-headline { margin-top: 0.9rem; }
.gh-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.gh-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
}
.gh-sep { font-size: 0.72rem; color: var(--text-muted); }
.gh-text { margin: 0.5rem 0 0; font-size: 0.84rem; line-height: 1.5; color: var(--text); }

.gap-top-list { display: flex; flex-direction: column; gap: 0.5rem; }
.gap-card {
  display: grid;
  grid-template-columns: 30px 1fr 84px;
  gap: 0.75rem;
  align-items: center;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  padding: 0.65rem 0.8rem;
}
.gap-card.clickable { cursor: pointer; }
.gap-card:hover { border-color: var(--primary); background: #fff; }
.gc-rank {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: #0B5B55;
  font-weight: 700;
  font-size: 0.78rem;
  display: grid;
  place-items: center;
}
.gc-name { font-weight: 650; font-size: 0.875rem; }
.gc-name em { font-style: normal; font-weight: 400; color: var(--text-muted); font-size: 0.72rem; }
.gc-insight { font-size: 0.74rem; color: var(--text-muted); margin-top: 0.1rem; }
.gc-bars { display: flex; flex-direction: column; gap: 0.2rem; margin-top: 0.4rem; }
.gc-bar {
  display: grid;
  grid-template-columns: 56px 1fr 50px;
  gap: 0.4rem;
  align-items: center;
  font-size: 0.7rem;
}
.gcb-lbl { color: var(--text-muted); }
.gcb-track { height: 7px; background: var(--border-soft); border-radius: 99px; overflow: hidden; }
.gcb-track > i { display: block; height: 100%; border-radius: 99px; }
.gcb-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.gc-gap {
  text-align: center;
  background: var(--warning-bg);
  border: 1px solid #F3D9AE;
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.3rem;
}
.gc-gap b {
  display: block;
  font-size: 1.05rem;
  color: var(--warning);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.gc-gap span { font-size: 0.6rem; color: var(--warning); text-transform: uppercase; letter-spacing: 0.04em; }

table.sortable th[data-sort] { cursor: pointer; user-select: none; }
table.sortable th[data-sort]:hover { color: var(--primary); }
table.sortable th.sorted-asc::after { content: " ▲"; font-size: 0.6rem; }
table.sortable th.sorted-desc::after { content: " ▼"; font-size: 0.6rem; }
#tblGaps td.gap-cell { font-weight: 700; color: var(--warning); }
#tblGaps tr.hot td.gap-cell { background: var(--warning-bg); }
#tblGaps td.insight-cell {
  font-size: 0.75rem;
  color: var(--text-muted);
  max-width: 420px;
}

/* ---- Responsive tweaks ---- */
@media (max-width: 900px) {
  .gap-card { grid-template-columns: 26px 1fr; }
  .gc-gap { grid-column: 2; justify-self: start; padding: 0.25rem 0.6rem; }
}
@media (max-width: 720px) {
  .ms-btn { max-width: none; min-width: 120px; }
  .filter-group { flex: 1 1 130px; }
  .ms-pop { width: min(280px, 86vw); }
  .search-item { grid-template-columns: 64px 1fr; }
  .search-item .meta { grid-column: 2; }
}

[hidden] { display: none !important; }

.nav-tab { white-space: nowrap; }

@media (max-width: 720px) {
  #tblGaps td.insight-cell, #tblGaps th.insight-col { display: none; }
  #tblGaps td, #tblGaps th { vertical-align: top; white-space: nowrap; }
  #tblGaps td .cell-sub { white-space: nowrap; }
}

/* ============ Data export (v4) ============ */
.btn-csv {
  flex: none;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn-csv:hover { background: #D3ECE9; border-color: var(--primary); }
.btn-csv:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.panel-header > h3 { order: 1; margin-right: auto; }
.panel-header > .hint,
.panel-header > .panel-note,
.panel-header > .legend { order: 2; }
.panel-header > .btn-csv { order: 3; }

.export-wrap { position: relative; }
.export-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 210px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 0.35rem;
  display: none;
  z-index: 60;
}
.export-menu.open { display: block; }
.export-menu-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 0.35rem 0.5rem 0.25rem;
}
.export-menu button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.82rem;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 0.45rem 0.5rem;
  cursor: pointer;
}
.export-menu button:hover { background: var(--surface-alt); }

/* ============ Viewer access gate (v4) ============ */
.lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(circle at 30% 20%, #1B4643 0%, var(--header-bg) 55%, #0B211F 100%);
}
.lock-overlay[hidden] { display: none; }
.lock-card {
  width: min(380px, 100%);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.6rem 1.5rem 1.35rem;
}
.lock-brand { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.35rem; }
.lock-brand .brand-mark {
  width: 38px; height: 38px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: var(--header-bg);
  color: var(--header-text);
}
.lock-brand .brand-mark svg { width: 20px; height: 20px; }
.lock-brand h2 { margin: 0; font-size: 1rem; letter-spacing: -0.01em; }
.lock-brand p { margin: 0.15rem 0 0; font-size: 0.7rem; color: var(--text-muted); }
.lock-card label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.lock-card input {
  width: 100%;
  font: inherit;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
.lock-card input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.lock-btn { width: 100%; justify-content: center; margin-top: 0.75rem; }
.lock-error {
  min-height: 1.1rem;
  margin-top: 0.55rem;
  font-size: 0.76rem;
  color: var(--error);
}
.lock-note { margin: 0.35rem 0 0; font-size: 0.72rem; color: var(--text-faint); }

/* =========================================================
 *  v6 — vs-Hypermarket delta chips + brand footprint
 * ========================================================= */
.sc-delta { margin: 0.1rem 0 0.15rem; }
.delta-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  border-radius: 999px;
  padding: 0.14rem 0.42rem;
  font-variant-numeric: tabular-nums;
}
.delta-chip.up {
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid #BFE0C8;
}
.delta-chip.down {
  color: var(--warning);
  background: var(--warning-bg);
  border: 1px solid #EFD3A6;
}
.share-goal-note {
  margin: 0.7rem 0 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.45;
}
.brand-footprint {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-soft);
}
.brand-footprint h4 {
  margin: 0 0 0.2rem;
  font-size: 0.82rem;
  font-weight: 700;
}
.fp-intro {
  margin: 0 0 0.5rem;
  font-size: 0.73rem;
  color: var(--text-muted);
  line-height: 1.45;
}
table.fp-table { font-size: 0.75rem; }
table.fp-table td { padding: 0.4rem 0.5rem; vertical-align: top; }
table.fp-table th { white-space: nowrap; }
.fp-na { color: var(--text-muted); }
.fp-more { margin: 0.4rem 0 0; font-size: 0.7rem; color: var(--text-muted); }
@media (max-width: 520px) {
  .delta-chip { font-size: 0.62rem; padding: 0.12rem 0.34rem; }
  table.fp-table { font-size: 0.7rem; }
  table.fp-table td, table.fp-table th { padding: 0.35rem 0.35rem; }
}
/* keep the amber chip legible on the amber "underperforms" card */
.share-channel-block.weak .delta-chip.down { background: #FFFDF7; }
/* right-align the footprint delta column with the numeric columns */
table.fp-table th:last-child, table.fp-table td:last-child { text-align: right; }
/* narrow screens: drop the repeated "vs Hyper share" wording inside the footprint
   table (the column header already says "Online vs Hyper") so the table fits 375px */
@media (max-width: 520px) {
  table.fp-table .dc-lbl { display: none; }
  table.fp-table td:first-child { max-width: 8.5rem; }
}
@media (max-width: 400px) {
  table.fp-table { font-size: 0.66rem; }
  table.fp-table th, table.fp-table td { padding: 0.3rem 0.22rem; }
  table.fp-table td:first-child { max-width: 7.5rem; }
}
/* phones: the footprint table lives inside a card, so drop the raw value column
   (the "% of brand" column carries the same ranking signal) to avoid clipping */
@media (max-width: 520px) {
  table.fp-table th:nth-child(2), table.fp-table td:nth-child(2) { display: none; }
}

/* =========================================================
   v7 — LuLu branding, vendor strip, leaders, Monthly tab,
   select-all rows, refresh spinner, signature footer
   ========================================================= */

/* --- logo tile (topbar + lock screen + favicon source) --- */
.brand-logo {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 11px;
  object-fit: cover;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(255, 255, 255, 0.14);
}
.brand-logo.lg {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  box-shadow: 0 2px 10px rgba(28, 31, 35, 0.14), 0 0 0 1px var(--border-soft);
}

/* --- crafted-by signature --- */
.signature {
  font-size: 0.74rem;
  color: var(--text-faint);
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.lock-signature { margin: 0.5rem 0 0; text-align: right; }
.app-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.25rem 1.4rem;
  border-top: 1px solid var(--border-soft);
  margin-top: 1.5rem;
}
.footer-meta { font-size: 0.7rem; color: var(--text-faint); }
.app-footer .signature { color: var(--text-muted); opacity: 0.85; }

/* --- refresh button spinner --- */
#btnRefresh .refresh-icon { display: inline-flex; }
#btnRefresh .refresh-icon svg { width: 15px; height: 15px; }
#btnRefresh.is-loading .refresh-icon { animation: spin 0.85s linear infinite; }
#btnRefresh[disabled] { opacity: 0.65; cursor: progress; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  #btnRefresh.is-loading .refresh-icon { animation-duration: 2.4s; }
}

/* --- vendor context strip --- */
.vendor-strip {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
  background: var(--primary-soft);
  border: 1px solid #C9E4E0;
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  margin: 0 0 0.9rem;
  font-size: 0.79rem;
  line-height: 1.45;
}
.vendor-strip .vs-tag {
  flex: none;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff;
  background: var(--primary);
  border-radius: 999px;
  padding: 0.16rem 0.5rem;
}
.vendor-strip .vs-id { color: var(--text-muted); font-size: 0.72rem; }
.vendor-strip .vs-warn { color: var(--warning); font-weight: 600; }

/* --- leaders (Insights, Regions, Monthly) --- */
.leader-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0.75rem;
}
.leader-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  padding: 0.75rem 0.85rem 0.65rem;
}
.leader-card.empty { background: var(--surface); }
.leader-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.leader-name {
  margin-top: 0.28rem;
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.leader-name.pos { color: var(--success); }
.leader-name.neg { color: var(--error); }
.leader-value {
  margin-top: 0.15rem;
  font-size: 1.05rem;
  font-weight: 650;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.leader-meta { margin-top: 0.1rem; font-size: 0.7rem; color: var(--text-muted); }
.leader-note {
  margin: 0.4rem 0 0;
  font-size: 0.71rem;
  line-height: 1.45;
  color: var(--text-muted);
}
.leader-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.8rem;
}
.leader-chip {
  font-size: 0.7rem;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.22rem 0.6rem;
}
.leader-chip .lc-k {
  font-weight: 700;
  font-size: 0.6rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-right: 0.3rem;
}
.leader-chip.ecom { border-color: var(--ch-ecom); }
.leader-chip.hs { border-color: var(--ch-hs); }
.leader-chip.ty { border-color: var(--ch-ty); }
.leader-chip.combo { border-color: var(--ch-combo); }
.leader-chip.hm { border-color: var(--ch-hm); }

/* --- Monthly tab --- */
.monthly-insights { margin-top: 0.85rem; }
.monthly-insights .mi-list {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.3rem;
  font-size: 0.79rem;
  line-height: 1.5;
  color: var(--text);
}
#tblMonthly td.delta.pos { color: var(--success); font-weight: 600; }
#tblMonthly td.delta.neg { color: var(--error); font-weight: 600; }
#tblMonthly tfoot td { border-top: 1px solid var(--border); font-size: 0.76rem; }
.empty-cell { text-align: center; color: var(--text-muted); padding: 1.1rem 0; }

/* --- multi-select bulk actions (select all matching) --- */
.ms-bulk {
  display: flex;
  gap: 0.4rem;
  padding: 0.35rem 0.45rem;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-alt);
  position: sticky;
  top: 0;
  z-index: 2;
}
.ms-bulk-btn {
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
}
.ms-bulk-btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.ms-bulk-btn.ghost { background: transparent; color: var(--primary); }
.ms-bulk-btn.ghost:hover { background: var(--primary-soft); }
.ms-bulk-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

@media (max-width: 640px) {
  .brand-logo { width: 34px; height: 34px; border-radius: 9px; }
  .app-footer { padding: 0.85rem 1rem 1.2rem; }
  .leader-grid { grid-template-columns: 1fr; }
  .vendor-strip { font-size: 0.75rem; }
}

/* ========== v8 — name on unlock + admin usage insights ========== */
.lock-intro {
  margin: 0 0 0.9rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.admin-modal {
  width: min(880px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.admin-modal .modal-body {
  overflow-y: auto;
}
.admin-sub {
  margin: 0.2rem 0 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  max-width: 46ch;
}
.admin-head-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}
.admin-gate-copy {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.admin-key-input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
.admin-key-input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}
.admin-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.6rem;
  margin-bottom: 1.1rem;
}
.admin-kpi {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.admin-kpi-label {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.admin-kpi-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}
.admin-h4 {
  margin: 1.15rem 0 0.5rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.admin-h4-sub {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--text-faint);
}
.admin-table-wrap {
  max-height: 210px;
  overflow: auto;
}
.admin-table-wrap table.data-table th,
.admin-table-wrap table.data-table td {
  white-space: nowrap;
}
tr.is-admin-row td:first-child { font-weight: 600; }
.admin-badge {
  display: inline-block;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.14);
  color: #4338CA;
  vertical-align: middle;
}
.admin-chart-wrap {
  height: 120px;
  position: relative;
}
.admin-feed {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.admin-feed-item {
  display: flex;
  gap: 0.6rem;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.45rem 0.7rem;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
}
.admin-feed-item:last-child { border-bottom: none; }
.admin-feed-text { color: var(--text); }
.admin-feed-time {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.admin-feed-item.ev-login_fail .admin-feed-text { color: var(--error); }
.admin-empty {
  padding: 0.9rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.admin-footer { align-items: center; }
.admin-footer-spacer { flex: 1; }
#btnSwitchUser { font-size: 0.72rem; color: var(--text-muted); }
@media (max-width: 640px) {
  .admin-modal { width: 100%; max-height: 94vh; }
  .admin-sub { font-size: 0.65rem; }
  .admin-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-kpi-value { font-size: 1rem; }
  .admin-table-wrap { max-height: 220px; }
  .admin-feed-item { flex-direction: column; gap: 0.15rem; font-size: 0.75rem; }
  .admin-footer { flex-wrap: wrap; gap: 0.4rem; }
  .admin-footer-spacer { display: none; }
  .admin-footer .btn { flex: 1 1 auto; justify-content: center; }
}

/* =========================================================
   v9 — minimal UX rework: mobile, sticky nav, Data menu,
   popovers, Monthly rank + drill-down, Ask tab, signature
   ========================================================= */

html, body { max-width: 100%; overflow-x: hidden; }

/* ---- filters bar: stacked rows (search / channels / accordion) ---- */
.filters-bar {
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
}
.filters-top { display: flex; gap: 0.5rem; align-items: center; }
.filters-top .search-box { flex: 1 1 auto; min-width: 0; }
.filters-toggle { display: none; flex: none; height: 40px; }
.filters-toggle svg { width: 15px; height: 15px; }
.fcount {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
}
.filters-collapse {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-end;
}
.filters-collapse .clear-btn { height: 34px; }
.ch-row { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.ch-row::-webkit-scrollbar { height: 0; }
.ch-row .ch-toggles { flex-wrap: nowrap; height: auto; gap: 0.4rem; padding-bottom: 2px; }
.ch-toggle-label {
  flex: none;
  height: 30px;
  padding: 0 0.55rem;
  gap: 0.35rem;
  font-size: 0.76rem;
  line-height: 1;
}
.chip-row { width: 100%; }

/* ---- slim sticky bar ---- */
.sticky-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 52px;
  padding: 0.4rem 0.9rem;
  background: linear-gradient(100deg, #0E2A29 0%, var(--header-bg) 60%, #16403C 100%);
  border-bottom: 1px solid #0A211F;
  box-shadow: 0 4px 14px rgba(10, 33, 31, 0.24);
  overflow-x: auto;
  scrollbar-width: none;
}
.sticky-bar::-webkit-scrollbar { height: 0; }
.sticky-bar[hidden] { display: none; }
.sticky-tabs { flex: none; }
.sticky-tabs .nav-tab { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.sticky-ch { display: flex; gap: 0.35rem; flex: none; }
.ch-chip {
  flex: none;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  height: 28px;
  padding: 0 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(244, 247, 246, 0.72);
  white-space: nowrap;
}
.ch-chip[aria-pressed="true"] { background: #fff; color: #0B5B55; border-color: #fff; }
.ch-chip.ecom[aria-pressed="true"] { color: #0B6B60; }
.ch-chip.hs[aria-pressed="true"] { color: #B03C08; }
.ch-chip.ty[aria-pressed="true"] { color: #7E22CE; }
.ch-chip.combo[aria-pressed="true"] { color: #4338CA; }
.ch-chip.hm[aria-pressed="true"] { color: var(--ch-hm); }
.sticky-fchip {
  flex: none;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  height: 26px;
  padding: 0 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.12);
  color: #F4F7F6;
  white-space: nowrap;
}
body.sticky-on { padding-top: 0; }

/* ---- Data menu items ---- */
.data-menu { min-width: 250px; }
.data-menu button, .data-menu .mi-link {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 0.45rem 0.5rem;
  cursor: pointer;
}
.data-menu .mi-link:hover { background: var(--surface-alt); }
.data-menu .mi-hint {
  display: block;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-muted);
}
.mi-tag {
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 0.1rem 0.35rem;
  vertical-align: 1px;
}

/* ---- "?" popovers ---- */
.pop-wrap { position: relative; display: inline-flex; }
.qmark {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
}
.qmark:hover, .pop-wrap.open .qmark { border-color: var(--primary); color: var(--primary); }
.pop-body {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 200;
  width: min(320px, 78vw);
  padding: 0.6rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.74rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
}
.pop-wrap.open .pop-body { display: block; }

/* ---- Monthly: rank + drill-down ---- */
.monthly-table tbody tr { cursor: pointer; }
.monthly-table tbody tr:hover { background: var(--primary-soft); }
.monthly-table tbody tr.is-selected { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.rank-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.14rem 0.45rem;
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border-soft);
}
.rank-badge.top { background: #FEF3C7; color: #92400E; border-color: #F3D48A; }
.drill-close { margin-left: auto; }
.drill-verdict {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.7rem;
  margin-bottom: 0.7rem;
}
.drill-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  background: var(--surface-alt);
}
.drill-card.good { background: var(--success-bg); border-color: #BFE0C8; }
.drill-card.watch { background: var(--warning-bg); border-color: #EFD3A6; }
.drill-card .dc-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.drill-card p { margin: 0.25rem 0 0; font-size: 0.8rem; line-height: 1.45; }
.drill-list { margin: 0; padding-left: 1.1rem; display: grid; gap: 0.28rem; font-size: 0.8rem; line-height: 1.5; }

/* ---- Ask tab ---- */
.ask-panel .panel-body { display: flex; flex-direction: column; gap: 0.7rem; }
.ask-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.ask-chip {
  font: inherit;
  font-size: 0.74rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  min-height: 32px;
}
.ask-chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.ask-log {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 220px;
  max-height: 52vh;
  overflow-y: auto;
  padding: 0.75rem;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}
.ask-msg {
  max-width: min(46rem, 92%);
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  font-size: 0.84rem;
  line-height: 1.55;
}
.ask-msg.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ask-msg.bot {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-bottom-left-radius: 4px;
}
.ask-msg.bot strong { color: var(--primary); }
.ask-msg .ask-note { display: block; margin-top: 0.3rem; font-size: 0.68rem; color: var(--text-faint); }
.ask-msg .ask-sub { display: block; margin-top: 0.3rem; font-size: 0.75rem; color: var(--text-muted); }
.ask-form { display: flex; gap: 0.5rem; }
.ask-form input {
  flex: 1;
  min-width: 0;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 0.75rem;
  font: inherit;
  font-size: 0.86rem;
  background: var(--surface);
  color: var(--text);
}
.ask-form input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.ask-form .btn { height: 42px; }
main.ask-mode .hide-on-ask { display: none !important; }

/* ---- professional signature ---- */
.sig-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.1rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-soft);
  min-width: 168px;
}
.sig-kicker {
  font-size: 0.56rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.sig-name {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--primary);
  font-variant-caps: all-small-caps;
}
.sig-block.sig-sm { margin-top: 0.7rem; min-width: 0; }
.sig-block.sig-sm .sig-kicker { font-size: 0.52rem; letter-spacing: 0.14em; }
.sig-block.sig-sm .sig-name { font-size: 0.74rem; letter-spacing: 0.14em; }

/* ---- mobile portrait ---- */
@media (max-width: 720px) {
  .filters-toggle { display: inline-flex; }
  .filters-collapse { display: none; }
  .filters-collapse.open { display: grid; grid-template-columns: 1fr; gap: 0.5rem; }
  .filters-collapse .filter-group { flex: none; width: 100%; }
  .filters-collapse .ms-btn { max-width: none; width: 100%; }
  .filters-collapse .clear-btn { width: 100%; justify-content: center; height: 40px; }
  .search-box input { height: 40px; }
  .app-header { row-gap: 0.5rem; }
  .header-actions { flex-wrap: wrap; }
  .btn { min-height: 36px; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table th:first-child, .data-table td:first-child {
    position: sticky;
    left: 0;
    background: var(--surface);
    z-index: 1;
  }
  .data-table tbody tr:hover td:first-child { background: var(--primary-soft); }
  .ask-log { max-height: 46vh; }
  .app-footer { justify-content: space-between; }
  .sig-block { align-items: flex-start; }
}

/* ---- mobile landscape (short viewport) ---- */
@media (max-width: 960px) and (max-height: 460px) {
  .app-header { flex-wrap: nowrap; height: auto; row-gap: 0; }
  .brand h1 { font-size: 0.85rem; }
  .brand .subtitle { display: none; }
  .nav-tabs { order: 0; width: auto; max-width: 44vw; overflow-x: auto; }
  .header-actions { margin-left: auto; flex-wrap: nowrap; }
  .filters-collapse.open { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ask-log { max-height: 40vh; min-height: 120px; }
  .sticky-bar { min-height: 46px; }
}

/* ---------- v9.1 mobile polish: tidy chips, less duplication ---------- */
.ch-row label.ch-toggle-wrap,
.ch-row label {
  cursor: pointer;
}
@media (max-width: 720px) {
  /* channel toggles become compact pills (native box hidden) */
  .ch-row label .ch-toggle {
    position: absolute;
    opacity: 0;
    pointer-events: none;
  }
  .ch-row label {
    position: relative;
    padding: 0 12px;
    height: 34px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    background: var(--surface-2, #f1f3f5);
    border: 1px solid var(--border, #dfe3e8);
    color: var(--text-soft, #6b7480);
  }
  .ch-row label:has(.ch-toggle:checked) {
    background: #fff;
    border-color: currentColor;
    box-shadow: inset 0 0 0 1px currentColor;
  }
  /* breadcrumb row duplicates the tab bar on small screens */
  #flowCrumbs {
    display: none;
  }
  /* two KPI cards per row keeps the fold useful */
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .kpi-card {
    padding: 12px;
  }
  .kpi-value {
    font-size: 20px;
  }
  .kpi-sub,
  .kpi-label {
    font-size: 10.5px;
    line-height: 1.35;
  }
}

/* ---------- v9.2: sticky bar rows on small screens, Ask header ---------- */
.sticky-tabs { margin: 0; }
@media (max-width: 720px) {
  .sticky-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    min-height: 0;
    padding: 5px 8px 6px;
    overflow: hidden;
  }
  .sticky-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 0;
    gap: 2px;
  }
  .sticky-tabs::-webkit-scrollbar { height: 0; }
  .sticky-tabs .nav-tab { flex: none; font-size: 0.74rem; padding: 0.28rem 0.55rem; }
  .sticky-ch {
    overflow-x: auto;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .sticky-ch::-webkit-scrollbar { height: 0; }
  .ch-chip { height: 25px; font-size: 0.68rem; }
  .ask-panel .panel-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  .ask-panel .panel-head h2,
  .ask-panel .panel-head h3 { white-space: nowrap; }
}

.sticky-bar .sticky-tabs { order: 0; }
.sticky-bar .sticky-ch { order: 1; }
.sticky-bar .sticky-cls { order: 2; }
.sticky-bar .sticky-fchip { order: 2; }

/* ---------- v9.3: short-viewport (landscape phones) ---------- */
@media (max-height: 460px) and (max-width: 1024px) {
  /* same accordion behaviour as portrait so the fold stays useful */
  .filters-toggle { display: inline-flex; }
  .filters-collapse {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.4rem 0.5rem;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.18s ease, opacity 0.18s ease;
  }
  .filters-collapse.open {
    max-height: 60vh;
    overflow: auto;
    opacity: 1;
  }
  #flowCrumbs { display: none; }
  .filters-bar { padding: 0.45rem 0.9rem; }
  .app-header .nav-tabs {
    overflow-x: auto;
    scrollbar-width: none;
    flex-wrap: nowrap;
    min-width: 0;
  }
  .app-header .nav-tabs::-webkit-scrollbar { height: 0; }
  .app-header .nav-tab { flex: none; }
}
@media (max-width: 720px) {
  .app-header .nav-tabs { overflow-x: auto; scrollbar-width: none; flex-wrap: nowrap; }
  .app-header .nav-tabs::-webkit-scrollbar { height: 0; }
  .app-header .nav-tab { flex: none; }
}

/* landscape phones: keep all six tabs reachable without clipping */
@media (max-height: 460px) and (max-width: 1024px) {
  .app-header { flex-wrap: wrap; row-gap: 4px; padding-top: 0.35rem; padding-bottom: 0.35rem; }
  .app-header .brand { flex: 1 1 auto; min-width: 0; }
  .app-header .subtitle { display: none; }
  .app-header .nav-tabs { order: 5; flex: 1 0 100%; padding: 3px; }
  .app-header .nav-tab { font-size: 0.76rem; padding: 0.3rem 0.6rem; }
}

@media (max-height: 460px) and (max-width: 1024px) {
  .app-header .nav-tabs { width: 100%; max-width: 100%; flex: 0 0 100%; justify-content: flex-start; }
  /* channel pills instead of native checkboxes here too */
  .ch-row label .ch-toggle { position: absolute; opacity: 0; pointer-events: none; }
  .ch-row label {
    position: relative;
    padding: 0 12px;
    height: 30px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    background: var(--surface-2, #f1f3f5);
    border: 1px solid var(--border);
    color: var(--text-soft, #6b7480);
  }
  .ch-row label:has(.ch-toggle:checked) { background: #fff; box-shadow: inset 0 0 0 1px currentColor; border-color: currentColor; }
}

/* drill panel head: title left, close on the right */
#monthDrillPanel .panel-header { justify-content: space-between; }
#monthDrillPanel .panel-header #monthDrillTitle { order: 0; margin-right: auto; }
#monthDrillPanel .panel-header .drill-close { order: 9; margin-left: 0.5rem; }

/* Ask panel header: let the one-line note wrap instead of clipping */
.ask-panel .panel-header { align-items: flex-start; gap: 0.75rem; }
.ask-panel .panel-header h3 { white-space: nowrap; }
.ask-panel .panel-header .hint {
  white-space: normal;
  text-align: right;
  max-width: 58%;
  line-height: 1.35;
}
@media (max-width: 720px) {
  .ask-panel .panel-header { flex-direction: column; gap: 0.3rem; }
  .ask-panel .panel-header .hint { text-align: left; max-width: 100%; }
}

@media (max-width: 720px) {
  #monthDrillPanel .panel-header { flex-wrap: wrap; row-gap: 2px; }
  #monthDrillPanel .panel-header .drill-close { order: 9; margin-left: auto; }
  #monthDrillPanel .panel-header #monthDrillTitle { order: 0; flex: 1 1 auto; }
}

/* =========================================================
 *  v10 — Ask 2.0 chat UI (avatar, badges, dots, typewriter,
 *  in-bubble charts, CSV button) + admin AI mode card
 * ========================================================= */
.ask-brand { font-size: 0.72rem; font-weight: 600; color: var(--primary); letter-spacing: 0.01em; }
.ask-mode-wrap { display: flex; align-items: center; gap: 0.5rem; }
.ask-mode-toggle {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.72rem; color: var(--text-muted); cursor: pointer;
  border: 1px solid var(--border); border-radius: 999px; padding: 0.25rem 0.6rem;
  background: var(--surface);
}
.ask-mode-toggle em { font-style: normal; color: var(--primary); font-size: 0.66rem; }
.ask-msg.bot { position: relative; padding-left: 2.3rem; }
.ask-avatar {
  position: absolute; left: 0.5rem; top: 0.55rem;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 0.7rem; font-weight: 700; line-height: 22px; text-align: center;
}
.ask-badge {
  display: inline-block; margin-right: 0.4rem; vertical-align: 1px;
  font-size: 0.6rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 0.05rem 0.35rem; border-radius: 4px;
  background: var(--border); color: var(--text-muted);
}
.ask-badge.ai { background: var(--primary-soft); color: var(--primary); }
.ask-body { display: inline; }
.ask-msg .ask-nudge { display: block; margin-top: 0.35rem; font-size: 0.7rem; color: var(--primary); }
.ask-chips.inline { margin-top: 0.55rem; }
.ask-dl { margin-top: 0.6rem; height: 32px; font-size: 0.72rem; padding: 0 0.7rem; }
.ask-chart { margin-top: 0.6rem; height: 200px; max-height: 220px; }
.ask-dots { display: inline-flex; gap: 4px; align-items: center; height: 16px; }
.ask-dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
  animation: askPulse 1.1s infinite ease-in-out;
}
.ask-dots i:nth-child(2) { animation-delay: 0.15s; }
.ask-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes askPulse { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.ask-msg.slide-in { animation: askSlide 0.22s ease-out both; }
@keyframes askSlide { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.typing-reveal::after {
  content: "\258D"; color: var(--primary); animation: askCaret 0.8s steps(1) infinite;
}
@keyframes askCaret { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .ask-msg.slide-in, .ask-dots i, .typing-reveal::after { animation: none !important; }
}

/* admin AI mode card */
.ai-card { border: 1px solid var(--border); border-radius: 10px; padding: 0.8rem; background: var(--surface); }
.ai-row { display: flex; flex-wrap: wrap; gap: 0.7rem; align-items: flex-end; }
.ai-row label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.7rem; color: var(--text-muted); }
.ai-row select, .ai-row input[type="password"] {
  height: 34px; min-width: 190px; padding: 0 0.5rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  color: var(--text); font-size: 0.8rem;
}
.ai-row label.ai-check { flex-direction: row; align-items: center; gap: 0.4rem; height: 34px; }
.ai-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.7rem; }
.ai-actions .btn { height: 32px; font-size: 0.75rem; padding: 0 0.7rem; }
.ai-badge { font-size: 0.7rem; padding: 0.2rem 0.5rem; border-radius: 999px; border: 1px solid var(--border); color: var(--text-muted); }
.ai-badge.on { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
.ai-badge.warn { color: #a86400; border-color: #e9c46a; background: rgba(233, 196, 106, 0.15); }
.ai-badge.off { color: var(--text-faint); }
.ai-note { margin: 0.6rem 0 0; font-size: 0.68rem; color: var(--text-faint); }
@media (max-width: 640px) {
  .ai-row select, .ai-row input[type="password"] { min-width: 0; width: 100%; }
  .ai-row label { width: 100%; }
  .ask-chart { height: 170px; }
}

/* v10: markdown-lite formatting inside AI answer bubbles */
.ask-msg .ask-body p { margin: 0 0 0.4rem; }
.ask-msg .ask-body p:last-child { margin-bottom: 0; }
.ask-msg .ask-ul { margin: 0.25rem 0 0.45rem; padding-left: 1.1rem; }
.ask-msg .ask-ul li { margin: 0.1rem 0; }
.ask-msg .ask-body code {
  background: rgba(20, 184, 166, 0.12);
  border-radius: 4px;
  padding: 0 0.25rem;
  font-size: 0.92em;
}

/* Data menu on small screens: fixed sheet pinned inside the viewport */
@media (max-width: 720px) {
  .export-wrap .export-menu {
    position: fixed;
    left: 0.75rem;
    right: 0.75rem;
    min-width: 0;
    max-height: min(70vh, 26rem);
    overflow-y: auto;
    z-index: 120;
  }
}

/* =========================================================
 *  v11 — compact tabs + floating Ask chat (FAB & panel)
 * ========================================================= */

/* ---- 2. compact tab labels: full on desktop, short on phones ---- */
.nav-tab .t-short { display: none; }
@media (max-width: 430px) {
  .nav-tab .t-full { display: none; }
  .nav-tab .t-short { display: inline; }
  /* all 5 tabs share the row — no horizontal scrolling anywhere */
  .app-header .nav-tabs,
  .sticky-bar .sticky-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
    gap: 2px;
    padding: 3px;
  }
  .app-header .nav-tab,
  .sticky-bar .sticky-tabs .nav-tab {
    flex: 1 1 0;
    min-width: 0;
    padding: 0.34rem 0.15rem;
    font-size: 0.72rem;
    line-height: 1.25;
    text-align: center;
    white-space: nowrap;
    letter-spacing: -0.01em;
  }
  .sticky-bar .sticky-tabs .nav-tab { font-size: 0.7rem; padding: 0.28rem 0.1rem; }
}
/* landscape phones keep the compact labels too */
@media (max-height: 460px) and (max-width: 1024px) {
  .nav-tab .t-full { display: none; }
  .nav-tab .t-short { display: inline; }
  .app-header .nav-tabs { overflow-x: hidden; }
  .app-header .nav-tab { flex: 1 1 0; min-width: 0; text-align: center; }
}

/* ---- 1. floating action button ---- */
.ask-fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 130;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(140deg, #14B8A6 0%, var(--primary) 55%, #0B5B55 100%);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 26px rgba(15, 118, 110, 0.34), 0 2px 6px rgba(12, 39, 37, 0.22);
  animation: askFabIn 0.5s cubic-bezier(0.2, 1.2, 0.3, 1) both, askFabPulse 10s ease-in-out 3s infinite;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.ask-fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 14px 30px rgba(15, 118, 110, 0.42); }
.ask-fab:focus-visible { outline: 3px solid rgba(20, 184, 166, 0.5); outline-offset: 3px; }
.ask-fab-icon { width: 26px; height: 26px; }
.ask-fab-ai {
  position: absolute;
  right: 3px;
  bottom: 4px;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: #fff;
  color: var(--primary);
  border-radius: 999px;
  padding: 1px 4px;
  line-height: 1.1;
  box-shadow: 0 1px 3px rgba(12, 39, 37, 0.28);
}
body.ask-open .ask-fab { animation: none; opacity: 0; pointer-events: none; transform: scale(0.85); }
@keyframes askFabIn {
  from { opacity: 0; transform: translateY(18px) scale(0.7); }
  to { opacity: 1; transform: none; }
}
@keyframes askFabPulse {
  0%, 92%, 100% { box-shadow: 0 10px 26px rgba(15, 118, 110, 0.34), 0 0 0 0 rgba(20, 184, 166, 0.5); }
  95% { box-shadow: 0 10px 26px rgba(15, 118, 110, 0.34), 0 0 0 12px rgba(20, 184, 166, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .ask-fab { animation: none; }
}

/* one-time nudge tooltip */
.ask-fab-tip {
  position: fixed;
  right: 82px;
  bottom: calc(30px + env(safe-area-inset-bottom, 0px));
  z-index: 131;
  background: var(--header-bg);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 500;
  padding: 0.4rem 0.65rem;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateX(6px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
  white-space: nowrap;
}
.ask-fab-tip.show { opacity: 1; transform: none; }
.ask-fab-tip[hidden] { display: none; }

/* ---- chat panel: desktop floating card / mobile bottom sheet ---- */
.ask-scrim {
  position: fixed;
  inset: 0;
  z-index: 128;
  background: rgba(18, 49, 47, 0.34);
  animation: askScrimIn 0.2s ease both;
}
.ask-scrim[hidden] { display: none; }
@keyframes askScrimIn { from { opacity: 0; } to { opacity: 1; } }
@media (min-width: 721px) {
  .ask-scrim { background: transparent; }
}

.ask-sheet {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 400; /* above content & sticky bar, below modals (500) */
  width: 400px;
  height: 600px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  box-shadow: 0 22px 60px rgba(12, 39, 37, 0.26), 0 2px 8px rgba(12, 39, 37, 0.1);
  overflow: hidden;
  animation: askSheetIn 0.24s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
.ask-sheet[hidden] { display: none; }
@keyframes askSheetIn {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.ask-grab { display: none; }
.ask-sheet-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.75rem 0.55rem 0.9rem;
  background: linear-gradient(100deg, #0E2A29 0%, var(--header-bg) 65%, #16403C 100%);
  color: #fff;
}
.ask-sheet-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ask-sheet-head .ask-brand { color: rgba(244, 247, 246, 0.72); font-weight: 500; }
.ask-mode-dot {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(244, 247, 246, 0.9);
  white-space: nowrap;
}
.ask-mode-dot i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #B7B9B4;
  box-shadow: none;
}
.ask-mode-dot.ai i { background: #35D6A4; box-shadow: 0 0 0 3px rgba(53, 214, 164, 0.22); }
.ask-sheet-x {
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1;
  flex: none;
}
.ask-sheet-x:hover { background: rgba(255, 255, 255, 0.24); }
.ask-sheet-sub {
  padding: 0.5rem 0.9rem 0.45rem;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-alt);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.ask-sheet-sub .hint { font-size: 0.68rem; color: var(--text-muted); line-height: 1.35; }
.ask-sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.65rem 0.8rem 0.8rem;
}
.ask-sheet-body .ask-log {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}
.ask-sheet-body .ask-chips { flex: none; }
.ask-sheet-body .ask-form { flex: none; }
.ask-sheet .ask-chart { height: 170px; }

/* mobile: bottom sheet ~85% height */
@media (max-width: 720px) {
  .ask-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 85vh;
    max-height: 85vh;
    border-radius: 18px 18px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    animation: askSheetUp 0.26s cubic-bezier(0.2, 0.9, 0.3, 1) both;
  }
  @keyframes askSheetUp {
    from { transform: translateY(100%); }
    to { transform: none; }
  }
  .ask-grab {
    display: block;
    width: 44px;
    height: 4px;
    border-radius: 999px;
    background: var(--border);
    margin: 7px auto 3px;
  }
  .ask-sheet-head { padding: 0.45rem 0.6rem 0.5rem 0.8rem; }
  .ask-sheet-title { font-size: 0.88rem; }
  .ask-sheet-head .ask-brand { display: none; }
  .ask-sheet .ask-chart { height: 160px; }
}
@media (max-height: 460px) and (max-width: 1024px) {
  .ask-sheet { height: 94vh; max-height: 94vh; }
  .ask-sheet-sub .hint { display: none; }
}

/* the FAB floats over content only — keep the footer clear of it */
.app-footer { padding-bottom: calc(1.2rem + 64px); }
@media (max-width: 720px) {
  .app-footer { padding-bottom: calc(1.2rem + 72px); }
}

/* v11: keep transient toasts clear of the floating Ask button */
.toast { bottom: calc(1.25rem + 68px + env(safe-area-inset-bottom, 0px)); }

/* =========================================================
 *  v12 — Department Classification selector + helper chips
 * ========================================================= */
.cls-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.1rem 0 0.35rem;
}
.cls-row-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-soft);
}
.cls-chips { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.cls-chip {
  font: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1;
  height: 28px;
  padding: 0 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.cls-chip:hover { border-color: var(--ch-hm); color: var(--text); }
.cls-chip[aria-pressed="true"] {
  background: var(--ch-hm);
  border-color: var(--ch-hm);
  color: #fff;
}
.cls-chip.all[aria-pressed="true"] { background: var(--primary, #0F766E); border-color: var(--primary, #0F766E); }
.cls-chip .cls-share { opacity: 0.72; font-weight: 500; margin-left: 0.3rem; }
.sticky-cls { display: flex; gap: 0.3rem; flex: none; }
.sticky-cls .cls-chip {
  height: 26px;
  font-size: 0.68rem;
  border-color: rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(244, 247, 246, 0.72);
}
.sticky-cls .cls-chip[aria-pressed="true"] { background: #fff; color: #0B5B55; border-color: #fff; }
.note-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(147, 51, 234, 0.1);
  color: #7E22CE;
  border: 1px solid rgba(147, 51, 234, 0.24);
}
.cls-table tbody tr.is-selected { background: rgba(30, 58, 95, 0.05); }
.cls-table tbody tr.is-selected td:first-child { font-weight: 700; }
@media (max-width: 720px) {
  .sticky-cls { overflow-x: auto; scrollbar-width: none; flex-wrap: nowrap; }
  .sticky-cls::-webkit-scrollbar { height: 0; }
  .cls-row { gap: 0.35rem; }
  .cls-row-label { display: none; }
  .cls-chips { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .cls-chips::-webkit-scrollbar { height: 0; }
}

/* v12 — vendor GR / fill-rate metrics + national region row */
.vendor-metrics { gap: 0.75rem; margin-top: 0.2rem; }
.vmetric { display: inline-flex; align-items: baseline; gap: 0.28rem; }
.vmetric em { font-style: normal; opacity: 0.7; }
.vmetric b { font-variant-numeric: tabular-nums; }
.vmetric b.pos { color: #15803D; }
.vmetric b.neg { color: #B91C1C; }
.badge-top {
  background: rgba(15, 118, 110, 0.12);
  color: var(--primary);
  border: 1px solid rgba(15, 118, 110, 0.3);
}
.natl-row { background: rgba(147, 51, 234, 0.05); }
.natl-row td:first-child strong { color: #7E22CE; }

/* v12 — the second share basis only appears when a classification scope is on */
body:not(.scoped-share) .hyper-col,
body:not(.scoped-share) .hyper-col2 { display: none; }

/* v12 — the channel + classification chip rows must scroll inside the phone
   viewport instead of stretching the filter bar (5 channels + 6 classifications) */
@media (max-width: 720px) {
  .filters-bar { overflow-x: hidden; }
  .ch-row,
  .cls-row,
  .cls-chips,
  .ch-row .ch-toggles {
    min-width: 0;
    max-width: 100%;
  }
  .cls-chips,
  .ch-row {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .cls-chips::-webkit-scrollbar { height: 0; }
  .cls-chip { flex: none; }
}

/* ==========================================================================
   v12 Phase B — Online insights (two sections) + Board tab
   ========================================================================== */
.ins2-sub { margin: 0 0 .85rem; }
.ins2-reload {
  margin-left: auto; font-size: 1rem; line-height: 1; padding: .28rem .5rem;
}
.ins2-grid { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .ins2-grid { grid-template-columns: 1fr; } }

.ins2-sec {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); overflow: hidden;
}
.ins2-sec > summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: .5rem;
  padding: .7rem .85rem; font-weight: 700; font-size: .95rem;
  border-bottom: 1px solid var(--border);
}
.ins2-sec > summary::-webkit-details-marker { display: none; }
.ins2-sec.working > summary { background: #ECFDF5; color: #065F46; }
.ins2-sec.lagging > summary { background: #FEF3C7; color: #92400E; }
.ins2-tick { font-size: .75rem; }
.ins2-count {
  margin-left: auto; background: rgba(0,0,0,.08); border-radius: 999px;
  padding: .05rem .5rem; font-size: .75rem; font-weight: 700;
}
.ins2-cards { display: grid; gap: .7rem; padding: .85rem; }
.ins2-more { margin: 0 .85rem .85rem; width: calc(100% - 1.7rem); }
.ins2-fit {
  margin: .9rem 0 0; font-size: .78rem; color: var(--text-muted); line-height: 1.5;
}

.ins-card {
  border: 1px solid var(--border); border-left: 4px solid var(--border);
  border-radius: 10px; padding: .75rem .85rem; background: var(--bg);
}
.ins-card.working { border-left-color: #10B981; }
.ins-card.lagging { border-left-color: #F59E0B; }
.ic-top { display: flex; align-items: center; gap: .5rem; margin-bottom: .35rem; }
.ic-kind {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .04em;
  font-weight: 700; color: var(--text-muted);
}
.ic-ch {
  margin-left: auto; font-size: .68rem; font-weight: 700; padding: .1rem .45rem;
  border-radius: 999px; background: color-mix(in srgb, var(--ch-hm) 14%, transparent); color: var(--ch-hm);
}
.ic-ch.ch-ecom { background: rgba(20,184,166,.14); color: #0E7490; }
.ic-ch.ch-hs { background: rgba(234,88,12,.14); color: #C2410C; }
.ic-ch.ch-ty { background: rgba(147,51,234,.14); color: #7C3AED; }
.ic-ch.ch-combo { background: rgba(99,102,241,.14); color: #4F46E5; }
.ic-head { margin: 0 0 .5rem; font-size: .92rem; line-height: 1.45; font-weight: 600; }
.ic-chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .5rem; }
.ic-chip {
  display: inline-flex; gap: .3rem; align-items: baseline; font-size: .72rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: .15rem .55rem;
}
.ic-chip .ic-chip-l { color: var(--text-muted); }
.ic-chip.t-good { background: #ECFDF5; border-color: #A7F3D0; }
.ic-chip.t-bad { background: #FEF2F2; border-color: #FECACA; }
.ic-chip.t-warn { background: #FFFBEB; border-color: #FDE68A; }
.ic-data > summary {
  cursor: pointer; font-size: .78rem; font-weight: 700; color: var(--primary);
  list-style: none; padding: .2rem 0;
}
.ic-data > summary::-webkit-details-marker { display: none; }
.ic-data > summary::before { content: "\25B8  "; }
.ic-data[open] > summary::before { content: "\25BE  "; }
.ic-table-wrap { overflow-x: auto; margin: .35rem 0 .2rem; }
.ic-table { width: 100%; border-collapse: collapse; font-size: .74rem; }
.ic-table th, .ic-table td {
  padding: .3rem .4rem; border-bottom: 1px solid var(--border); text-align: right;
  white-space: nowrap;
}
.ic-table th:first-child, .ic-table td:first-child { text-align: left; }
.ic-table th { color: var(--text-muted); font-weight: 700; }
.ic-table tbody tr { cursor: pointer; }
.ic-table tbody tr:hover, .ic-table tbody tr:focus { background: rgba(15,118,110,.07); outline: none; }
.ic-hint, .ic-note { margin: .3rem 0 0; font-size: .7rem; color: var(--text-muted); }
.ic-drill {
  margin-top: .55rem; background: none; border: none; padding: 0;
  color: var(--primary); font-weight: 700; font-size: .78rem; cursor: pointer;
}
.ic-drill:hover { text-decoration: underline; }
.ins-skel {
  height: 92px; border-radius: 10px; margin-bottom: .6rem;
  background: linear-gradient(90deg, #EFEDE7 25%, #F7F5F0 37%, #EFEDE7 63%);
  background-size: 400% 100%; animation: insShimmer 1.3s ease-in-out infinite;
}
@keyframes insShimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.adv-tools {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.adv-tools > summary {
  cursor: pointer; padding: .7rem .9rem; font-weight: 700; font-size: .88rem;
  color: var(--text-muted); list-style: none;
}
.adv-tools > summary::-webkit-details-marker { display: none; }
.adv-tools > summary::before { content: "\25B8  "; }
.adv-tools[open] > summary::before { content: "\25BE  "; }
.adv-tools-body { padding: 0 .5rem .5rem; }

/* ---------- Board ---------- */
.board-panel { margin-bottom: 1rem; }
.board-search-wrap { position: relative; }
.board-search-wrap .search-icon {
  position: absolute; left: .7rem; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--text-muted); pointer-events: none;
}
#boardSearch {
  width: 100%; padding: .6rem .8rem .6rem 2.2rem; font-size: .95rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
  color: var(--text);
}
#boardSearch:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.board-results {
  /* inline (not floating) so it never covers the pills / Add button on phones */
  margin-top: .45rem; max-height: 300px; overflow-y: auto; background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: .35rem;
}
.board-results::after { content: ""; display: block; }
.board-res-group h5 {
  margin: .4rem .4rem .2rem; font-size: .68rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted);
}
.board-res {
  display: flex; align-items: center; gap: .5rem; padding: .35rem .45rem;
  border-radius: 8px; font-size: .85rem; cursor: pointer;
}
.board-res:hover { background: rgba(15,118,110,.07); }
.board-res .br-name { flex: 1; }
.board-res .br-val { color: var(--text-muted); font-size: .75rem; }
.board-res-empty { margin: .5rem; font-size: .82rem; color: var(--text-muted); }
.board-pills { display: flex; flex-wrap: wrap; gap: .35rem; margin: .6rem 0 0; }
.board-pill {
  display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem;
  background: rgba(15,118,110,.08); border: 1px solid rgba(15,118,110,.25);
  border-radius: 999px; padding: .18rem .3rem .18rem .6rem;
}
.board-pill em { font-style: normal; color: var(--text-muted); font-size: .68rem; }
.board-pill button {
  border: none; background: none; cursor: pointer; color: var(--text-muted);
  font-size: .8rem; padding: 0 .25rem;
}
.board-actions { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; margin-top: .75rem; }
.board-hint { margin-left: auto; font-size: .78rem; }
.board-blocks { display: grid; gap: 1rem; }

.bb {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  padding: .9rem 1rem 1rem;
}
.bb.combined { border-color: rgba(15,118,110,.45); box-shadow: inset 3px 0 0 var(--primary); }
.bb.dragging { opacity: .5; }
.bb-head { display: flex; align-items: flex-start; gap: .6rem; }
.bb-drag { cursor: grab; color: var(--text-muted); font-size: 1.1rem; line-height: 1; }
.bb-title { flex: 1; min-width: 0; }
.bb-kind {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); font-weight: 700;
}
.bb-title h3 { margin: .1rem 0 .1rem; font-size: 1.05rem; }
.bb-sub { margin: 0; font-size: .74rem; color: var(--text-muted); }
.bb-tools { display: flex; gap: .25rem; }
.bb-tools button {
  border: 1px solid var(--border); background: var(--bg); border-radius: 8px;
  width: 30px; height: 30px; cursor: pointer; color: var(--text); font-size: .85rem;
}
.bb-tools button:disabled { opacity: .35; cursor: default; }
.bb-kpis {
  display: grid; gap: .5rem; margin: .8rem 0;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}
.bb-kpi {
  border: 1px solid var(--border); border-radius: 10px; padding: .5rem .6rem;
  background: var(--bg);
}
.bb-kpi span { display: block; font-size: .68rem; color: var(--text-muted); }
.bb-kpi strong { font-size: 1rem; }
.bb-kpi.good strong { color: #047857; }
.bb-kpi.bad strong { color: #B91C1C; }
.bb-chart { height: 220px; margin-bottom: .8rem; }
.bb-table table { font-size: .78rem; }
.bb-table td.num, .bb-table th.num { text-align: right; }

.board-sticky {
  position: sticky; bottom: 0; z-index: 40; display: none;
  gap: .5rem; align-items: center; padding: .5rem .6rem; margin-top: .8rem;
  background: var(--surface); border-top: 1px solid var(--border);
}
.board-sticky-count { font-size: .75rem; color: var(--text-muted); margin-left: auto; }
@media (max-width: 720px) {
  .board-sticky:not([hidden]) { display: flex; }
  .board-actions [data-board-act] { display: none; }
  .board-hint { margin-left: 0; width: 100%; }
}

/* v12 Phase B — 6 tabs must still share one phone row (Home·Deep·Regions·Months·Insights·Board) */
@media (max-width: 430px) {
  .app-header .nav-tab,
  .sticky-bar .sticky-tabs .nav-tab {
    padding: 0.34rem 0.08rem;
    font-size: 0.68rem;
    letter-spacing: -0.02em;
  }
  .sticky-bar .sticky-tabs .nav-tab { font-size: 0.66rem; padding: 0.28rem 0.06rem; }
}
.bb-empty {
  margin: .7rem 0 0; font-size: .82rem; color: #92400E;
  background: #FFFBEB; border: 1px solid #FDE68A; border-radius: 8px; padding: .45rem .6rem;
}

/* ---------- v12C: channel scoping ---------- */
/* a classification with no sales in the selected channel is greyed out */
.cls-chip.is-off {
  opacity: 0.42;
  cursor: not-allowed;
  background: var(--surface-2, #f1f3f5);
  color: var(--text-muted, #7a8592);
  border-style: dashed;
}
.cls-chip.is-off:hover { transform: none; }
.kpi-card.is-muted { opacity: 0.68; }
.gh-scope {
  display: inline-block;
  margin-left: 0.4rem;
  font-size: 0.72rem;
  color: var(--text-muted, #7a8592);
}
td.muted, .num.muted { color: var(--text-muted, #9aa4b1); }
.empty-cell {
  text-align: center;
  color: var(--text-muted, #7a8592);
  font-size: 0.82rem;
  padding: 0.9rem 0.5rem;
}
.ch-tag { font-size: 0.68rem; opacity: 0.8; }

.scope-tag {
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--text-muted, #7a8592);
  background: var(--surface-2, #f1f3f5);
  border-radius: 999px;
  padding: 0.08rem 0.42rem;
  margin-left: 0.3rem;
  white-space: nowrap;
}

/* =====================================================================
   v12D — Insights: channel-pair comparison
   ===================================================================== */
.pair-panel .panel-body { padding-top: .7rem; }
.pair-pills {
  display: flex; flex-wrap: wrap; gap: .55rem;
}
.pair-pill {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .62rem .95rem; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: .9rem; color: var(--text); transition: all .16s ease;
}
.pair-pill strong { font-weight: 800; letter-spacing: -0.01em; }
.pair-pill em {
  font-style: normal; font-size: .68rem; font-weight: 700; text-transform: uppercase;
  color: var(--text-faint); letter-spacing: .06em;
}
.pair-pill:hover { border-color: var(--primary); background: var(--primary-soft); }
.pair-pill.active {
  background: var(--header-bg); border-color: var(--header-bg); color: #fff;
  box-shadow: 0 4px 14px rgba(18, 49, 47, .22);
}
.pair-pill.active em { color: rgba(255,255,255,.62); }
.pair-summary {
  margin: .9rem 0 .2rem; font-size: 1.02rem; line-height: 1.55; color: var(--text);
}
.pair-summary strong { font-weight: 800; }
.pair-scope { margin: .15rem 0 0; font-size: .74rem; color: var(--text-muted); }

.pair-sec { border-top: 3px solid var(--border); }
.pair-sec.is-working { border-top-color: var(--success); }
.pair-sec.is-action { border-top-color: var(--warning); }
.pair-sec .panel-header h3 { display: flex; align-items: center; gap: .4rem; }
.pair-sec .ps-tick { font-size: .78rem; }
.pair-sec.is-working .ps-tick { color: var(--success); }
.pair-sec.is-action .ps-tick { color: var(--warning); }
.pair-count {
  font-size: .7rem; font-weight: 700; color: var(--text-muted);
  background: var(--surface-alt); border-radius: 999px; padding: .1rem .45rem;
}
.pair-table { font-size: .84rem; }
.pair-table td { vertical-align: top; }
.pair-table .pair-why { color: var(--text-muted); font-size: .78rem; line-height: 1.45; min-width: 240px; }
.pair-table tbody tr.clickable { cursor: pointer; }
.pair-table tbody tr.clickable:hover { background: rgba(15, 118, 110, .07); }
.pair-minor {
  font-style: normal; font-size: .62rem; font-weight: 700; text-transform: uppercase;
  color: var(--warning); background: var(--warning-bg); border-radius: 999px; padding: .05rem .35rem;
}
.pt, .pg { font-weight: 700; white-space: nowrap; }
.pt.up, .pg.up { color: var(--success); }
.pt.down, .pg.down { color: var(--error); }
.pt-flat { color: var(--text-faint); font-size: .74rem; }
.pair-more {
  margin: .6rem auto 0; display: block; font-size: .8rem;
}
.btn-csv2 { font-size: .76rem; padding: .32rem .6rem; }
.pair-dl {
  grid-column: span 12; display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  padding: .2rem .2rem .4rem;
}
.pair-skel {
  height: 18px; border-radius: 6px; margin: .35rem 0;
  background: linear-gradient(90deg, #EFEDE7 25%, #F7F5F0 37%, #EFEDE7 63%);
  background-size: 400% 100%; animation: insShimmer 1.3s ease-in-out infinite;
}

/* =====================================================================
   v12D — Board: one search, whole story
   ===================================================================== */
.board-hero {
  background: linear-gradient(135deg, var(--header-bg) 0%, #0F766E 100%);
  color: #fff; border: none;
}
.board-hero-body { padding: 1.6rem 1.3rem 1.3rem; }
.board-h1 {
  margin: 0; font-size: 1.62rem; font-weight: 800; letter-spacing: -0.02em; color: #fff;
}
.board-sub { margin: .35rem 0 1rem; font-size: .9rem; color: rgba(255,255,255,.78); max-width: 62ch; }
.board-search-wrap.big { position: relative; max-width: 720px; }
.board-search-wrap.big .search-icon {
  position: absolute; left: 1rem; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; color: var(--text-muted); pointer-events: none;
}
.board-search-wrap.big input {
  width: 100%; padding: .95rem 1rem .95rem 2.9rem; font-size: 1rem;
  border-radius: 14px; border: none; background: #fff; color: var(--text);
  box-shadow: 0 8px 26px rgba(0,0,0,.18);
}
.board-search-wrap.big input:focus { outline: 3px solid rgba(255,255,255,.5); }
.board-results {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + .4rem);
  background: #fff; border-radius: 12px; box-shadow: 0 16px 40px rgba(0,0,0,.22);
  max-height: 340px; overflow: auto; padding: .3rem;
}
.br-item {
  display: flex; align-items: center; gap: .6rem; width: 100%; text-align: left;
  padding: .55rem .65rem; border: none; background: none; cursor: pointer;
  border-radius: 9px; font-size: .88rem; color: var(--text);
}
.br-item:hover, .br-item.sel { background: var(--primary-soft); }
.br-kind {
  font-size: .62rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em;
  color: var(--primary); background: var(--primary-soft); border-radius: 999px; padding: .1rem .4rem;
}
.br-sub { margin-left: auto; font-size: .74rem; color: var(--text-muted); }
.br-empty { padding: .7rem; font-size: .84rem; color: var(--text-muted); }
.board-recent { display: flex; flex-wrap: wrap; gap: .4rem; margin: .8rem 0 0; min-height: 1.4rem; }
.board-recent .rc-lbl { font-size: .72rem; color: rgba(255,255,255,.65); align-self: center; }
.rc-chip {
  border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.12); color: #fff;
  border-radius: 999px; padding: .22rem .6rem; font-size: .76rem; cursor: pointer;
}
.rc-chip:hover { background: rgba(255,255,255,.25); }
.board-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
.board-actions .btn { background: #fff; border-color: #fff; color: var(--header-bg); font-weight: 700; }
.board-actions .btn:disabled { opacity: .45; cursor: not-allowed; }
.board-actions .btn-ghost { background: transparent; border-color: rgba(255,255,255,.4); color: #fff; }
.board-hint { color: rgba(255,255,255,.7); }
.board-blocks { grid-column: span 12; display: grid; gap: 1rem; }
.bb {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.bb-head { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; margin-bottom: .8rem; }
.bb-head h3 { margin: 0; font-size: 1rem; font-weight: 800; letter-spacing: -0.01em; }
.bb-head .bb-note { font-size: .74rem; color: var(--text-muted); }
.bb-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .7rem; }
.bb-kpi {
  background: var(--surface-alt); border-radius: 12px; padding: .8rem .9rem;
  border: 1px solid var(--border-soft);
}
.bb-kpi .k-lbl { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.bb-kpi .k-val { font-size: 1.3rem; font-weight: 800; letter-spacing: -0.02em; margin-top: .2rem; }
.bb-kpi .k-sub { font-size: .72rem; color: var(--text-muted); margin-top: .15rem; }
.bb-insight {
  margin: .8rem 0 0; font-size: .84rem; line-height: 1.55; color: var(--text);
  background: var(--primary-soft); border-left: 3px solid var(--primary);
  border-radius: 0 8px 8px 0; padding: .55rem .7rem;
}
.bb-chart { height: 260px; position: relative; }
.bb-grid2 { display: grid; grid-template-columns: 1.1fr .9fr; gap: 1rem; align-items: start; }
.bb-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.bb-table th, .bb-table td { padding: .4rem .5rem; border-bottom: 1px solid var(--border-soft); text-align: right; }
.bb-table th:first-child, .bb-table td:first-child { text-align: left; }
.bb-table th { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.board-sticky {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 60; display: flex; gap: .45rem;
  align-items: center; background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: .4rem .6rem; box-shadow: 0 10px 30px rgba(0,0,0,.16);
}
.board-sticky-count { font-size: .74rem; color: var(--text-muted); }
@media (max-width: 760px) {
  .board-h1 { font-size: 1.28rem; }
  .bb-grid2 { grid-template-columns: 1fr; }
  .pair-table { font-size: .78rem; }
  .pair-table .pair-why { min-width: 180px; }
  .pair-pill { padding: .5rem .75rem; font-size: .82rem; }
  .board-sticky { bottom: 4.6rem; }
}

/* v12D board — extra pieces */
.bb-hero .bb-eyebrow {
  display: block; font-size: .68rem; font-weight: 800; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: .1rem;
}
.bb-hero .bb-head h3 { font-size: 1.5rem; letter-spacing: -0.02em; }
.bb-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .9rem; }
.bb-chip {
  font-size: .76rem; border: 1px solid var(--border); border-radius: 999px;
  padding: .22rem .6rem; background: var(--surface-alt); font-weight: 600;
}
.bb-chip em { font-style: normal; color: var(--text-muted); font-weight: 500; }
.bb-chip.muted { color: var(--text-muted); }
.bb-bars { display: grid; gap: .5rem; }
.bb-bar-row { display: grid; grid-template-columns: 92px 1fr auto; gap: .6rem; align-items: center; font-size: .82rem; }
.bb-bar-row .bbr-lbl { font-weight: 700; }
.bb-bar-row .bbr-lbl em { font-style: normal; font-size: .62rem; color: var(--text-muted); }
.bbr-track { height: 12px; background: var(--surface-alt); border-radius: 999px; overflow: hidden; }
.bbr-track i { display: block; height: 100%; border-radius: 999px; }
.bbr-val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bbr-val em { font-style: normal; color: var(--text-muted); font-size: .74rem; margin-left: .25rem; }
.bb-sub-table + .bb-sub-table { margin-top: 1.1rem; }
.bb-sub-table .bb-head h3 { font-size: .88rem; }
@media (max-width: 760px) {
  .bb-bar-row { grid-template-columns: 62px 1fr; grid-template-areas: "l t" "v v"; }
  .bb-bar-row .bbr-val { grid-area: v; font-size: .76rem; }
  .bb-hero .bb-head h3 { font-size: 1.2rem; }
}

/* ============ v12F — cleaner Board & Insights tabs ============
   Board: show ONLY the search-driven board (hide crumbs, title, KPI strip,
   top-4 cards, channel comparison, share panel, vendor mapping, vendor strip).
   Insights: hide crumbs, title, KPI strip, top-4 cards and vendor mapping —
   keep Channel comparison and the pair tables. */
body[data-view="board"] #flowCrumbs,
body[data-view="board"] .page-title-row,
body[data-view="board"] #vendorStrip,
body[data-view="board"] .kpi-grid,
body[data-view="board"] .insights-strip,
body[data-view="board"] #channelComparePanel,
body[data-view="board"] #sharePanel,
body[data-view="board"] #vendorPanel,
body[data-view="insights"] #flowCrumbs,
body[data-view="insights"] .page-title-row,
body[data-view="insights"] .kpi-grid,
body[data-view="insights"] .insights-strip,
body[data-view="insights"] #vendorPanel,
body[data-view="ask"] #flowCrumbs,
body[data-view="ask"] .page-title-row,
body[data-view="ask"] #vendorStrip,
body[data-view="ask"] .kpi-grid,
body[data-view="ask"] .insights-strip,
body[data-view="ask"] #channelComparePanel,
body[data-view="ask"] #sharePanel,
body[data-view="ask"] #vendorPanel,
/* The temporary growth view must not reuse the Overview furniture, or it
   reads as the Overview page and the user cannot tell they moved. */
body[data-view="momdetail"] #flowCrumbs,
body[data-view="momdetail"] .page-title-row,
body[data-view="momdetail"] #vendorStrip,
body[data-view="momdetail"] .kpi-grid:not(#view-momdetail .kpi-grid),
body[data-view="momdetail"] .insights-strip,
body[data-view="momdetail"] #channelComparePanel,
body[data-view="momdetail"] #sharePanel,
body[data-view="momdetail"] #vendorPanel {
  display: none !important;
}
/* keep the detail view's own KPI row visible */
body[data-view="momdetail"] #view-momdetail .kpi-grid { display: grid !important; }

/* v12I: total row for summary tables */
.data-table tr.total-row td{border-top:2px solid var(--border-strong,#cbd5e1);background:var(--surface-2,#f8fafc);font-weight:600}
.data-table .cell-sub.delta.pos{color:#15803d}
.data-table .cell-sub.delta.neg{color:#b91c1c}


/* ===== v12I: Ask as a static tab ===== */
.ask-card {
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 6px 22px rgba(16, 42, 41, 0.07);
  max-width: 860px;
  margin: 0 auto;
}
.ask-card .ask-sheet-body {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem 0.9rem 0.9rem;
}
.ask-card .ask-log {
  flex: 1 1 auto;
  min-height: 260px;
  max-height: calc(100dvh - 380px);
  overflow-y: auto;
}
@media (max-width: 720px) {
  /* chat doesn't use the filter bar — reclaim the space so the whole tab
     (log + input + Send) fits one phone screen */
  body[data-view="ask"] .filters-bar { display: none !important; }
  .ask-card {
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    height: calc(100dvh - 200px);
    min-height: 320px;
  }
  .ask-card .ask-sheet-body { flex: 1 1 auto; min-height: 0; }
  .ask-card .ask-log { flex: 1 1 auto; min-height: 0; max-height: none; }
  /* iPhone: 16px stops Safari from auto-zooming into the input, which was
     pushing the Send button off-screen when the keyboard opened. */
  .ask-form input { font-size: 16px; height: 44px; }
  .ask-form .btn { height: 44px; min-width: 64px; }
}
.nav-tab-ask .t-full::after, .nav-tab-ask .t-short::after {
  content: "\2726";
  font-size: 0.62em;
  margin-left: 4px;
  vertical-align: super;
  opacity: 0.75;
}


/* ===== v12I: filters slide away smoothly when the page is scrolled ===== */
.filters-collapse.open.hiding {
  animation: filtersHide 0.22s ease forwards;
  overflow: hidden;
  pointer-events: none;
}
@keyframes filtersHide {
  from { opacity: 1; transform: translateY(0); max-height: 640px; }
  to { opacity: 0; transform: translateY(-8px); max-height: 0; margin-top: 0; margin-bottom: 0; padding-top: 0; padding-bottom: 0; }
}


/* ===== v12I R3a7: MoM growth flags ===== */
.mom-flag {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.4;
  padding: 1px 7px;
  border-radius: 999px;
  vertical-align: middle;
  white-space: nowrap;
}
.mom-flag small { font-size: 0.82em; font-weight: 600; opacity: 0.75; }
.mom-flag.up { background: #dcfce7; color: #15803d; }
.mom-flag.down { background: #fee2e2; color: #b91c1c; }
.kpi-value .mom-flag { font-size: 0.62rem; position: relative; top: -2px; }


/* ===== v12I R3a8: floating quick downloads ===== */
.quick-dl {
  position: fixed;
  right: 14px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 390; /* above content & sticky bars, below modals (500) */
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(19, 78, 74, 0.92);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: quickDlIn 0.25s ease;
}
@keyframes quickDlIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.quick-dl-cap {
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0 2px 0 6px;
}
.quick-dl-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  background: #ffffff;
  color: #134e4a;
  line-height: 1;
  min-height: 32px;
}
.quick-dl-btn:active { transform: scale(0.96); }
@media (max-width: 720px) {
  .quick-dl { right: 10px; bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); padding: 5px 7px; }
  .quick-dl-cap { display: none; }
  .quick-dl-btn { min-height: 40px; padding: 9px 13px; font-size: 0.8rem; }
}


/* ===== v12I R3a9: period chip — which months the numbers cover ===== */
.period-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  vertical-align: middle;
  margin-left: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #ccfbf1;
  color: #134e4a;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
  line-height: 1.5;
}
.period-chip::before { content: "\1F4C5"; font-size: 0.75rem; }
@media (max-width: 720px) {
  .period-chip { margin-left: 6px; font-size: 0.66rem; padding: 2px 8px; }
}

/* ---------- Region comparison: impact strip + matrix (added) ---------- */
.impact-strip { margin: 0 0 0.75rem; }
.impact-lead {
  font-size: 0.78rem;
  color: var(--text-soft);
  margin-bottom: 0.5rem;
}
.impact-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.6rem;
}
.impact-card {
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  background: var(--surface);
}
.impact-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.86rem;
  margin-bottom: 0.4rem;
}
.impact-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--border-soft);
  overflow: hidden;
  margin-bottom: 0.4rem;
}
.impact-fill { display: block; height: 100%; border-radius: 999px; background: var(--ch-hm, #0F766E); }
.impact-fill.up { background: #15803D; }
.impact-fill.down { background: #B91C1C; }
.impact-meta { font-size: 0.72rem; color: var(--text-soft); line-height: 1.35; }
.impact-meta.muted { color: var(--text-muted); }

.level-switch { margin-left: 0.5rem; }

.lead-chip {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--border-soft);
  color: var(--text-soft);
}

.btn-more {
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  margin-left: 0.35rem;
}
.btn-more:hover { border-color: var(--ch-hm); color: var(--text); }
.btn-more[hidden] { display: none; }

/* =====================================================================
 * MODERN THEME + DARK MODE  (appended: these override the base tokens)
 * Channel hues were re-picked and machine-validated for colour-blind
 * separation — the old Trendyol purple and Online indigo were nearly
 * identical to deuteranopes. Dark mode is a selected set of steps for the
 * dark surface, not an automatic inversion.
 * ===================================================================== */
:root {
  color-scheme: light;
  --bg: #F5F7F8;
  --surface: #FFFFFF;
  --surface-alt: #EFF2F4;
  --border: #DCE2E7;
  --border-soft: #E9EDF0;
  --text: #14181B;
  --text-muted: #5A6672;
  --text-faint: #97A1AB;
  --primary: #0D9488;
  --primary-hover: #0B7C71;
  --primary-soft: #E2F4F1;
  --header-bg: #0E2B2A;
  --header-text: #F2F7F6;

  --error: #B42318;   --error-bg: #FDECEA;
  --warning: #B45309; --warning-bg: #FDF3E3;
  --success: #15803D; --success-bg: #EAF6EE;

  /* Channel hues — validated categorical set */
  --ch-ecom: #0D9488;
  --ch-hs: #EA580C;
  --ch-ty: #DB2777;
  --ch-combo: #2563EB;
  --ch-hm: #475569;          /* Hypermarket = the total, shown as a neutral benchmark */

  --region-akb: #0D9488;
  --region-jed: #EA580C;
  --region-ruh: #2563EB;

  --chart-grid: #E4E9ED;
  --chart-axis: #5A6672;

  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(16, 24, 32, 0.04), 0 8px 20px rgba(16, 24, 32, 0.05);
  --shadow-lg: 0 12px 40px rgba(16, 24, 32, 0.16);
}

/* Dark values are declared twice on purpose: the media query follows the OS,
   the [data-theme] scope follows the user's toggle and must win either way. */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0F1315;
    --surface: #171C1F;
    --surface-alt: #1E2429;
    --border: #2B333A;
    --border-soft: #232A30;
    --text: #EEF3F5;
    --text-muted: #A4AEB8;
    --text-faint: #737E89;
    --primary: #2DD4BF;
    --primary-hover: #5EEAD4;
    --primary-soft: #14312F;
    --header-bg: #0A1214;
    --header-text: #EAF2F1;

    --error: #F87171;   --error-bg: #2A1616;
    --warning: #FBBF24; --warning-bg: #2A2011;
    --success: #4ADE80; --success-bg: #12271A;

    --ch-ecom: #0FA79A;
    --ch-hs: #E06A17;
    --ch-ty: #E0508C;
    --ch-combo: #3F82E8;
    --ch-hm: #94A3B8;

    --region-akb: #0FA79A;
    --region-jed: #E06A17;
    --region-ruh: #3F82E8;

    --chart-grid: #262E35;
    --chart-axis: #A4AEB8;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 22px rgba(0, 0, 0, 0.32);
    --shadow-lg: 0 14px 44px rgba(0, 0, 0, 0.55);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0F1315;
  --surface: #171C1F;
  --surface-alt: #1E2429;
  --border: #2B333A;
  --border-soft: #232A30;
  --text: #EEF3F5;
  --text-muted: #A4AEB8;
  --text-faint: #737E89;
  --primary: #2DD4BF;
  --primary-hover: #5EEAD4;
  --primary-soft: #14312F;
  --header-bg: #0A1214;
  --header-text: #EAF2F1;

  --error: #F87171;   --error-bg: #2A1616;
  --warning: #FBBF24; --warning-bg: #2A2011;
  --success: #4ADE80; --success-bg: #12271A;

  --ch-ecom: #0FA79A;
  --ch-hs: #E06A17;
  --ch-ty: #E0508C;
  --ch-combo: #3F82E8;
  --ch-hm: #94A3B8;

  --region-akb: #0FA79A;
  --region-jed: #E06A17;
  --region-ruh: #3F82E8;

  --chart-grid: #262E35;
  --chart-axis: #A4AEB8;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 22px rgba(0, 0, 0, 0.32);
  --shadow-lg: 0 14px 44px rgba(0, 0, 0, 0.55);
}

/* Surfaces that were hardcoded white in the base sheet */
:root[data-theme="dark"] body,
:root:where(:not([data-theme="light"])) body { background: var(--bg); color: var(--text); }

/* ---- theme toggle ---- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  height: 34px;
  padding: 0 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: transparent;
  color: var(--header-text);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.1); }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .tt-label { font-weight: 600; }
@media (max-width: 720px) { .theme-toggle .tt-label { display: none; } }

/* ---- mobile pass for the newer components ---- */
@media (max-width: 720px) {
  .impact-cards { grid-template-columns: 1fr; }
  .impact-card { padding: 0.55rem 0.6rem; }
  .level-switch { margin-left: 0; width: 100%; }
  .level-switch .cls-chip { flex: 1 1 auto; }
  .btn-more { margin-left: 0; }
  .panel-header { flex-wrap: wrap; row-gap: 0.4rem; }
  .ms-foot-actions { display: flex; gap: 0.3rem; flex-wrap: wrap; }
  #tblRegionMatrix { font-size: 0.76rem; }
  #tblRegionMatrix .cell-sub { font-size: 0.66rem; }
  .modal { width: 100% !important; max-height: 92vh; }
  .modal-body .table-wrap { max-height: 60vh !important; }
  #tblDetail { font-size: 0.76rem; }
  .mom-flag { font-size: 0.62rem; }
}
.ms-foot-actions { display: inline-flex; gap: 0.35rem; align-items: center; }
.ms-all, .ms-none {
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.ms-all:hover { border-color: var(--primary); color: var(--primary); }
.ms-none:hover { border-color: var(--error); color: var(--error); }

/* ---------- Insights: priority attention banner ---------- */
.priority-banner {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 0.6rem;
  margin-bottom: 0.25rem;
}
.pb-card {
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
}
.pb-bad {
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--error) 14%, var(--surface)) 0%,
    color-mix(in srgb, var(--warning) 12%, var(--surface)) 100%);
  border: 1px solid color-mix(in srgb, var(--error) 38%, transparent);
}
.pb-good {
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--success) 13%, var(--surface)) 0%,
    color-mix(in srgb, var(--primary) 10%, var(--surface)) 100%);
  border: 1px solid color-mix(in srgb, var(--success) 36%, transparent);
}
.pb-flag.good { background: var(--success); }
.pb-amount.good { color: var(--success); }
.pb-good .pb-foot { border-top-color: color-mix(in srgb, var(--success) 22%, transparent); }
.win { color: var(--success); }
.priority-banner[hidden] { display: none; }
.pb-flag {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #fff;
  background: var(--error);
  padding: 0.16rem 0.5rem;
  border-radius: 999px;
  margin-bottom: 0.5rem;
}
.pb-main {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.pb-name { font-size: 1.28rem; font-weight: 800; color: var(--text); display: block; line-height: 1.2; }
.pb-sub { font-size: 0.74rem; color: var(--text-muted); }
.pb-figure { text-align: right; }
.pb-amount { display: block; font-size: 1.55rem; font-weight: 800; color: var(--error); line-height: 1.1; }
.pb-amount-label { font-size: 0.7rem; color: var(--text-muted); }
.pb-explain { margin: 0.55rem 0 0; font-size: 0.86rem; line-height: 1.5; color: var(--text); }
.pb-explain strong { font-weight: 700; }
.pb-foot {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid color-mix(in srgb, var(--error) 22%, transparent);
  font-size: 0.74rem;
  color: var(--text-muted);
}
.pb-total { font-weight: 700; color: var(--text); }
.uplift { color: var(--error); }
@media (max-width: 720px) {
  .pb-figure { text-align: left; }
  .pb-amount { font-size: 1.3rem; }
  .pb-name { font-size: 1.08rem; }
  .priority-banner { padding: 0.75rem 0.8rem; }
}

/* =====================================================================
 * MOBILE DENSITY PASS  (appended — wins over the earlier rules)
 * The phone view was showing desktop-sized cards, every filter chip and a
 * floating export bar on top of the content. This tightens the whole
 * hierarchy: one screen should answer one question.
 * ===================================================================== */
@media (max-width: 720px) {

  /* --- Board: the export buttons must be real, tappable and in the flow --- */
  .board-actions [data-board-act] {
    display: inline-flex !important;
    flex: 1 1 46%;
    justify-content: center;
    min-height: 46px;
    font-weight: 700;
    font-size: 0.86rem;
  }
  .board-actions { gap: 0.5rem; margin-top: 0.85rem; }
  .board-actions #btnBoardClear { flex: 1 1 100%; min-height: 40px; justify-content: center; }
  .board-hint { font-size: 0.72rem; }
  /* the floating duplicate just covers content on a phone */
  .board-sticky { display: none !important; }

  /* --- Header: one compact row --- */
  .app-header { padding: 0.4rem 0.6rem; }
  .brand-sub, .app-header .brand p { display: none; }
  .app-header .btn { min-height: 38px; }

  /* --- Filters: collapse the noise --- */
  .filter-bar { padding: 0.4rem 0.6rem; gap: 0.35rem; }
  .chip-row, .cls-chips { gap: 0.28rem; }
  .cls-chip { height: 26px; font-size: 0.7rem; padding: 0 0.5rem; }
  .ch-chip { font-size: 0.72rem; }
  .filter-note { font-size: 0.68rem; }

  /* --- KPI cards: two per row, tighter --- */
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
  .kpi-card { padding: 0.6rem 0.65rem; border-radius: 12px; }
  .kpi-label { font-size: 0.62rem; letter-spacing: 0.05em; }
  .kpi-value { font-size: 1.12rem; line-height: 1.2; }
  .kpi-sub { font-size: 0.66rem; line-height: 1.35; }
  .kpi-card .mom-flag { font-size: 0.6rem; }

  /* the headline card stays full width so the big number reads first */
  .kpi-grid > .kpi-card:first-child { grid-column: 1 / -1; }
  .kpi-grid > .kpi-card:first-child .kpi-value { font-size: 1.6rem; }

  /* --- Panels: less chrome, more content --- */
  .panel { border-radius: 12px; }
  .panel-header { padding: 0.55rem 0.7rem; gap: 0.35rem; }
  .panel-header h3 { font-size: 0.92rem; }
  .panel-header .hint, .panel-header .note-chip { font-size: 0.66rem; }
  .panel-body { padding: 0.6rem 0.7rem; }
  .panel-body.tight { padding: 0.45rem 0.5rem; }
  .chart-wrap.lg { height: 210px; }

  /* --- Tables: readable without pinching --- */
  .data-table { font-size: 0.75rem; }
  .data-table th, .data-table td { padding: 0.4rem 0.45rem; }
  .cell-sub { font-size: 0.64rem; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  /* columns that only add noise on a phone */
  .data-table .hyper-col, .data-table .hyper-col2 { display: none; }

  /* --- Leader / summary cards --- */
  .leader-grid { grid-template-columns: 1fr; gap: 0.5rem; }
  .bb-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 0.5rem; }
  .bb, .bb-sub-table { border-radius: 12px; }
  .bb-head { flex-wrap: wrap; gap: 0.3rem; }
  .bb-head h3 { font-size: 0.95rem; }

  /* --- Quick download pill shouldn't sit on the content --- */
  .quick-dl { bottom: calc(env(safe-area-inset-bottom, 0px) + 62px); }
}

/* Very small phones */
@media (max-width: 380px) {
  .kpi-value { font-size: 1rem; }
  .kpi-grid > .kpi-card:first-child .kpi-value { font-size: 1.4rem; }
  .data-table { font-size: 0.71rem; }
}

@media (max-width: 720px) {
  .priority-banner { grid-template-columns: 1fr; gap: 0.5rem; }
  .pb-card { padding: 0.7rem 0.75rem; }
  .pb-main { align-items: flex-start; }
}

/* The floating export pill was sitting on top of the KPI numbers on a phone.
   Compact it to icons and tuck it clear of the bottom nav. */
@media (max-width: 720px) {
  .quick-dl {
    right: 0.5rem;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 68px);
    gap: 0.3rem;
    padding: 0.25rem;
    opacity: 0.96;
  }
  .quick-dl-cap { display: none; }
  .quick-dl-btn { padding: 0 0.65rem; min-height: 38px; font-size: 0.76rem; }
}

/* =====================================================================
 * DARK MODE READABILITY FIXES
 * The base stylesheet hardcodes light surfaces and light-mode ink in many
 * places; overriding the tokens alone left those washed out. Each rule
 * below was derived from a measured contrast failure, not guessed.
 * ===================================================================== */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    /* Tokens the base sheet references with a light fallback */
    --surface-2: #1E2429;
    --border-strong: #39424A;
    --text-faint: #8B95A0;
  }
}
:root[data-theme="dark"] {
    /* Tokens the base sheet references with a light fallback */
    --surface-2: #1E2429;
    --border-strong: #39424A;
    --text-faint: #8B95A0;
  }
@media (prefers-color-scheme: dark) {
  /* --- surfaces that were hardcoded light --- */
  :root:where(:not([data-theme="light"])) table.data-table tr:hover td { background: var(--surface-alt) !important; }
  :root:where(:not([data-theme="light"])) .data-table tr.total-row td { background: var(--surface-alt) !important; border-top-color: var(--border-strong) !important; }
  :root:where(:not([data-theme="light"])) .ch-chip { background: var(--surface) !important; }
  :root:where(:not([data-theme="light"])) .ch-chip[aria-pressed="false"] { color: var(--text-muted) !important; }
  :root:where(:not([data-theme="light"])) .scope-tag { background: var(--surface-alt) !important; color: var(--text-muted) !important; }
  :root:where(:not([data-theme="light"])) .modal, :root:where(:not([data-theme="light"])) .modal-body, :root:where(:not([data-theme="light"])) .bb, :root:where(:not([data-theme="light"])) .bb-sub-table, :root:where(:not([data-theme="light"])) .panel, :root:where(:not([data-theme="light"])) .kpi-card { background-color: var(--surface); }
  :root:where(:not([data-theme="light"])) .res-type, :root:where(:not([data-theme="light"])) .ic-ch { background: var(--surface-alt) !important; border-color: var(--border) !important; }
  
  /* --- channel text must use the dark-stepped hues --- */
  :root:where(:not([data-theme="light"])) .ch-toggle-label.ecom, :root:where(:not([data-theme="light"])) .ch-chip.ecom[aria-pressed="true"], :root:where(:not([data-theme="light"])) .ic-ch.ch-ecom { color: var(--ch-ecom) !important; }
  :root:where(:not([data-theme="light"])) .ch-toggle-label.hs, :root:where(:not([data-theme="light"])) .ch-chip.hs[aria-pressed="true"], :root:where(:not([data-theme="light"])) .ic-ch.ch-hs, :root:where(:not([data-theme="light"])) .res-type.category { color: var(--ch-hs) !important; }
  :root:where(:not([data-theme="light"])) .ch-toggle-label.ty, :root:where(:not([data-theme="light"])) .ch-chip.ty[aria-pressed="true"], :root:where(:not([data-theme="light"])) .ic-ch.ch-ty, :root:where(:not([data-theme="light"])) .natl-row td:first-child strong { color: var(--ch-ty) !important; }
  :root:where(:not([data-theme="light"])) .ch-toggle-label.combo, :root:where(:not([data-theme="light"])) .ch-chip.combo[aria-pressed="true"], :root:where(:not([data-theme="light"])) .ic-ch.ch-combo { color: var(--ch-combo) !important; }
  :root:where(:not([data-theme="light"])) .ch-toggle-label.hm, :root:where(:not([data-theme="light"])) .ch-chip.hm[aria-pressed="true"] { color: var(--ch-hm) !important; }
  :root:where(:not([data-theme="light"])) .ch-name { color: var(--text) !important; }
  :root:where(:not([data-theme="light"])) .note-chip { color: var(--ch-ty) !important; background: color-mix(in srgb, var(--ch-ty) 16%, transparent) !important; border-color: color-mix(in srgb, var(--ch-ty) 40%, transparent) !important; }
  
  /* --- up / down indicators --- */
  :root:where(:not([data-theme="light"])) .mom-flag.up { background: color-mix(in srgb, var(--success) 20%, transparent) !important; color: var(--success) !important; }
  :root:where(:not([data-theme="light"])) .mom-flag.down { background: color-mix(in srgb, var(--error) 20%, transparent) !important; color: var(--error) !important; }
  :root:where(:not([data-theme="light"])) .data-table .cell-sub.delta.pos, :root:where(:not([data-theme="light"])) .vmetric b.pos, :root:where(:not([data-theme="light"])) .bb-kpi.good strong { color: var(--success) !important; }
  :root:where(:not([data-theme="light"])) .data-table .cell-sub.delta.neg, :root:where(:not([data-theme="light"])) .vmetric b.neg, :root:where(:not([data-theme="light"])) .bb-kpi.bad strong { color: var(--error) !important; }
  
  /* --- filled pills need dark ink, not white, on light accent fills --- */
  :root:where(:not([data-theme="light"])) .pb-flag, :root:where(:not([data-theme="light"])) .pb-flag.good { color: #0B1416 !important; }
  :root:where(:not([data-theme="light"])) .cls-chip[aria-pressed="true"], :root:where(:not([data-theme="light"])) .cls-chip.all[aria-pressed="true"] { color: #0B1416 !important; }
  :root:where(:not([data-theme="light"])) .btn-primary, :root:where(:not([data-theme="light"])) .app-header .btn-primary { color: #0B1416 !important; }
  :root:where(:not([data-theme="light"])) .priority-banner .btn-more { color: var(--text) !important; border-color: var(--border-strong) !important; }
  
  /* --- misc dim text --- */
  :root:where(:not([data-theme="light"])) td.rank, :root:where(:not([data-theme="light"])) .pt-flat, :root:where(:not([data-theme="light"])) .cell-sub, :root:where(:not([data-theme="light"])) em { color: var(--text-muted) !important; }
  :root:where(:not([data-theme="light"])) .empty-cell, :root:where(:not([data-theme="light"])) .hint, :root:where(:not([data-theme="light"])) .bb-note, :root:where(:not([data-theme="light"])) .pair-scope { color: var(--text-muted) !important; }
}
/* --- surfaces that were hardcoded light --- */
:root[data-theme="dark"] table.data-table tr:hover td { background: var(--surface-alt) !important; }
:root[data-theme="dark"] .data-table tr.total-row td { background: var(--surface-alt) !important; border-top-color: var(--border-strong) !important; }
:root[data-theme="dark"] .ch-chip { background: var(--surface) !important; }
:root[data-theme="dark"] .ch-chip[aria-pressed="false"] { color: var(--text-muted) !important; }
:root[data-theme="dark"] .scope-tag { background: var(--surface-alt) !important; color: var(--text-muted) !important; }
:root[data-theme="dark"] .modal, :root[data-theme="dark"] .modal-body, :root[data-theme="dark"] .bb, :root[data-theme="dark"] .bb-sub-table, :root[data-theme="dark"] .panel, :root[data-theme="dark"] .kpi-card { background-color: var(--surface); }
:root[data-theme="dark"] .res-type, :root[data-theme="dark"] .ic-ch { background: var(--surface-alt) !important; border-color: var(--border) !important; }

/* --- channel text must use the dark-stepped hues --- */
:root[data-theme="dark"] .ch-toggle-label.ecom, :root[data-theme="dark"] .ch-chip.ecom[aria-pressed="true"], :root[data-theme="dark"] .ic-ch.ch-ecom { color: var(--ch-ecom) !important; }
:root[data-theme="dark"] .ch-toggle-label.hs, :root[data-theme="dark"] .ch-chip.hs[aria-pressed="true"], :root[data-theme="dark"] .ic-ch.ch-hs, :root[data-theme="dark"] .res-type.category { color: var(--ch-hs) !important; }
:root[data-theme="dark"] .ch-toggle-label.ty, :root[data-theme="dark"] .ch-chip.ty[aria-pressed="true"], :root[data-theme="dark"] .ic-ch.ch-ty, :root[data-theme="dark"] .natl-row td:first-child strong { color: var(--ch-ty) !important; }
:root[data-theme="dark"] .ch-toggle-label.combo, :root[data-theme="dark"] .ch-chip.combo[aria-pressed="true"], :root[data-theme="dark"] .ic-ch.ch-combo { color: var(--ch-combo) !important; }
:root[data-theme="dark"] .ch-toggle-label.hm, :root[data-theme="dark"] .ch-chip.hm[aria-pressed="true"] { color: var(--ch-hm) !important; }
:root[data-theme="dark"] .ch-name { color: var(--text) !important; }
:root[data-theme="dark"] .note-chip { color: var(--ch-ty) !important; background: color-mix(in srgb, var(--ch-ty) 16%, transparent) !important; border-color: color-mix(in srgb, var(--ch-ty) 40%, transparent) !important; }

/* --- up / down indicators --- */
:root[data-theme="dark"] .mom-flag.up { background: color-mix(in srgb, var(--success) 20%, transparent) !important; color: var(--success) !important; }
:root[data-theme="dark"] .mom-flag.down { background: color-mix(in srgb, var(--error) 20%, transparent) !important; color: var(--error) !important; }
:root[data-theme="dark"] .data-table .cell-sub.delta.pos, :root[data-theme="dark"] .vmetric b.pos, :root[data-theme="dark"] .bb-kpi.good strong { color: var(--success) !important; }
:root[data-theme="dark"] .data-table .cell-sub.delta.neg, :root[data-theme="dark"] .vmetric b.neg, :root[data-theme="dark"] .bb-kpi.bad strong { color: var(--error) !important; }

/* --- filled pills need dark ink, not white, on light accent fills --- */
:root[data-theme="dark"] .pb-flag, :root[data-theme="dark"] .pb-flag.good { color: #0B1416 !important; }
:root[data-theme="dark"] .cls-chip[aria-pressed="true"], :root[data-theme="dark"] .cls-chip.all[aria-pressed="true"] { color: #0B1416 !important; }
:root[data-theme="dark"] .btn-primary, :root[data-theme="dark"] .app-header .btn-primary { color: #0B1416 !important; }
:root[data-theme="dark"] .priority-banner .btn-more { color: var(--text) !important; border-color: var(--border-strong) !important; }

/* --- misc dim text --- */
:root[data-theme="dark"] td.rank, :root[data-theme="dark"] .pt-flat, :root[data-theme="dark"] .cell-sub, :root[data-theme="dark"] em { color: var(--text-muted) !important; }
:root[data-theme="dark"] .empty-cell, :root[data-theme="dark"] .hint, :root[data-theme="dark"] .bb-note, :root[data-theme="dark"] .pair-scope { color: var(--text-muted) !important; }

/* ---------------------------------------------------------------------
 * Channel toggles: the label text now wears normal ink and the channel
 * colour moves to the checkbox and border. Colour-on-white failed contrast
 * at every size in both themes, and identity is safer on a mark than on
 * the word itself.
 * ------------------------------------------------------------------- */
.ch-toggle-label { color: var(--text) !important; background: var(--surface) !important; }
.ch-toggle-label input { accent-color: var(--chip-hue, var(--primary)); }
.ch-toggle-label.ecom  { --chip-hue: var(--ch-ecom); }
.ch-toggle-label.hs    { --chip-hue: var(--ch-hs); }
.ch-toggle-label.ty    { --chip-hue: var(--ch-ty); }
.ch-toggle-label.combo { --chip-hue: var(--ch-combo); }
.ch-toggle-label.hm    { --chip-hue: var(--ch-hm); }
.ch-toggle-label { border-left: 3px solid var(--chip-hue, var(--border-soft)); }
.ch-toggle-label:hover { border-color: var(--border); border-left-color: var(--chip-hue, var(--border)); }
:root[data-theme="dark"] .ch-toggle-label,
:root:where(:not([data-theme="light"])) .ch-toggle-label { background: var(--surface) !important; }

/* ---------- Monthly: two-month comparison ---------- */
.cmp-controls { display: flex; align-items: flex-end; gap: .6rem; flex-wrap: wrap; margin-bottom: .8rem; }
.cmp-field { display: flex; flex-direction: column; gap: .2rem; font-size: .72rem; color: var(--text-muted); font-weight: 600; }
.cmp-select {
  font: inherit; font-size: .86rem; padding: .4rem .6rem; min-height: 38px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.cmp-arrow { color: var(--text-muted); padding-bottom: .55rem; }
.cmp-summary { margin-bottom: .7rem; }
.cmp-head { margin: 0 0 .25rem; font-size: .95rem; color: var(--text); }
.cmp-sub { margin: 0 0 .5rem; font-size: .78rem; color: var(--text-muted); }
.cmp-delta { font-weight: 700; margin-left: .35rem; }
.cmp-delta.pos { color: var(--success); }
.cmp-delta.neg { color: var(--error); }
.cmp-regions { display: flex; gap: .4rem; flex-wrap: wrap; }
.cmp-chip {
  font-size: .74rem; padding: .22rem .55rem; border-radius: 999px;
  border: 1px solid var(--border-soft); background: var(--surface-alt); color: var(--text);
}
.cmp-chip em { font-style: normal; color: var(--text-muted); margin-left: .25rem; }
@media (max-width: 720px) {
  .cmp-controls { gap: .45rem; }
  .cmp-field { flex: 1 1 42%; }
  .cmp-select { width: 100%; }
  .cmp-arrow { display: none; }
  #btnCompareMonths { flex: 1 1 100%; min-height: 42px; }
  #tblMonthRegion, #tblMonthCompare { font-size: .74rem; }
}

/* ---------- Clickable MoM chips ---------- */
.mom-flag.is-clickable {
  font: inherit;
  border: 0;
  cursor: pointer;
  appearance: none;
  transition: filter .12s, transform .12s;
}
.mom-flag.is-clickable:hover { filter: brightness(0.94); transform: translateY(-1px); }
.mom-flag.is-clickable:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Temporary "Growth detail" tab ---------- */
.nav-tab-temp { position: relative; padding-right: 1.6rem !important; }
.nav-tab-temp[hidden] { display: none !important; }
.nav-tab-temp .temp-x {
  position: absolute;
  right: .45rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  line-height: 1;
  opacity: .65;
}
.nav-tab-temp .temp-x:hover { opacity: 1; }
.temp-bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .7rem;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warning) 13%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warning) 40%, transparent);
  border-left-width: 4px;
}
.temp-back {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font: inherit;
  font-size: .82rem;
  font-weight: 700;
  padding: .42rem .75rem;
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex: none;
}
.temp-back:hover { border-color: var(--primary); color: var(--primary); }
.temp-back svg { width: 15px; height: 15px; }
.temp-bar-text { display: flex; flex-direction: column; gap: .1rem; min-width: 0; flex: 1 1 auto; }
.temp-bar-title {
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--warning);
}
.temp-bar-sub { font-size: .76rem; color: var(--text-muted); line-height: 1.35; }

/* the temp view itself is visibly not one of the normal pages */
#view-momdetail.active { position: relative; }
#view-momdetail.active::before {
  content: "";
  position: absolute;
  inset: -6px -8px;
  border: 2px dashed color-mix(in srgb, var(--warning) 45%, transparent);
  border-radius: var(--radius);
  pointer-events: none;
}
.nav-tab-temp {
  border: 1px dashed color-mix(in srgb, var(--warning) 65%, transparent) !important;
}

@media (max-width: 720px) {
  .temp-bar { font-size: .72rem; }
  .nav-tab-temp { padding-right: 1.4rem !important; }
}

@media (max-width: 720px) {
  .temp-bar { flex-wrap: wrap; gap: .5rem; padding: .5rem .6rem; }
  .temp-back { flex: 1 1 100%; justify-content: center; }
  .temp-bar-text { flex: 1 1 100%; }
  .temp-bar-sub { font-size: .72rem; }
  #btnMomClose { flex: none; }
}

/* =====================================================================
 * PHONE ACCESSIBILITY PASS
 * Derived from a measured audit at 360 / 390 / 430 px in both themes:
 * every rule below fixes a specific finding — text under 11px, tap
 * targets under 32px, or a row wider than the screen.
 * ===================================================================== */
@media (max-width: 720px) {

  /* ---- readable minimums (nothing below ~11.5px) ---- */
  .kpi-label { font-size: 0.72rem !important; letter-spacing: 0.045em; }
  .kpi-sub,
  .period-chip,
  .hint,
  .cell-sub,
  .bb-note,
  .impact-meta,
  .cmp-sub,
  .temp-bar-sub,
  .pair-scope,
  .leader-meta,
  .leader-note { font-size: 0.74rem !important; line-height: 1.4; }
  .pb-flag, .pb-flag.good, .temp-bar-title { font-size: 0.72rem !important; }
  .nav-tab .t-short { font-size: 0.76rem !important; }
  .lead-chip, .cmp-chip { font-size: 0.74rem !important; }
  .mom-flag { font-size: 0.7rem !important; }
  .mom-flag small { font-size: 0.62rem; }

  /* ---- tap targets: 32px floor, 40px+ for primary navigation ---- */
  .nav-tab {
    min-height: 42px !important;
    padding-top: .35rem !important;
    padding-bottom: .35rem !important;
  }
  .nav-tab-temp { min-height: 42px !important; }
  .cls-chip {
    height: 34px !important;
    padding: 0 .7rem !important;
    font-size: 0.74rem !important;
  }
  .ch-toggle-label { min-height: 34px; padding: .3rem .55rem .3rem .4rem; }
  .btn-csv,
  .btn-more,
  .ms-all,
  .ms-none,
  .ms-clear {
    min-height: 34px !important;
    padding: .4rem .7rem !important;
    display: inline-flex !important;
    align-items: center;
  }
  .qmark {
    width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    font-size: .9rem !important;
  }
  /* growth chips are now a primary interaction — make them properly tappable */
  .mom-flag.is-clickable {
    min-height: 30px;
    padding: .3rem .5rem !important;
    display: inline-flex;
    align-items: center;
    gap: .18rem;
  }
  .data-table .mom-flag.is-clickable { min-height: 28px; }

  /* ---- rows that were wider than the screen ---- */
  .ch-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    max-width: 100%;
    overflow-x: visible;
  }
  .ch-toggles > * { flex: 0 1 auto; }
  .chip-row, .cls-chips {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .chip-row::-webkit-scrollbar, .cls-chips::-webkit-scrollbar { display: none; }

  /* keep long headings and values from pushing the layout out */
  .panel-header h3, .bb-head h3, .kpi-value, .pb-name { min-width: 0; overflow-wrap: anywhere; }
  .panel, .bb, .kpi-card, .impact-card { min-width: 0; }
}

/* Smallest phones still in common use */
@media (max-width: 380px) {
  .nav-tab { padding-left: .5rem !important; padding-right: .5rem !important; }
  .cls-chip { padding: 0 .55rem !important; }
  .kpi-label { font-size: 0.7rem !important; }
}

/* =====================================================================
 * PHONE PASS 2 — remaining audit findings
 * ===================================================================== */
@media (max-width: 720px) {

  /* the channel row was set to nowrap at a higher specificity, so it ran
     329px wide inside a 320px column on a 360px phone */
  .ch-row .ch-toggles {
    flex-wrap: wrap !important;
    height: auto !important;
    overflow-x: visible !important;
  }
  .ch-toggles { height: auto !important; }

  /* table headers and micro-labels lifted to a readable floor */
  .data-table th,
  .bb-table th,
  .pair-table th,
  .monthly-table th { font-size: 0.72rem !important; letter-spacing: .02em; }
  .scope-tag,
  .leader-label,
  .lc-k,
  .bb-eyebrow,
  .badge,
  .rank-badge,
  .note-chip,
  .sig-kicker,
  .vmetric,
  .pt-flat,
  .pair-minor { font-size: 0.72rem !important; }
  .mom-flag small { font-size: 0.66rem !important; }
  .btn-csv, .btn-more { font-size: 0.74rem !important; }
  .data-table em, .pair-why em, .bb em { font-size: 0.72rem !important; }
  .data-table small, .bb small, .leader-card small { font-size: 0.72rem !important; }

  /* segmented level pickers in Insights */
  .seg-btn {
    min-height: 34px !important;
    padding: .4rem .7rem !important;
    font-size: 0.75rem !important;
  }

  /* growth chips: give the finger something to hit */
  .mom-flag.is-clickable { min-height: 32px !important; }
  .kpi-card .mom-flag.is-clickable { min-height: 34px !important; }
}

/* A scroll container that adds no visual box of its own — used for tables
   that sit directly inside a card. */
.table-wrap.flush { max-height: none; overflow-x: auto; overflow-y: visible; }

@media (max-width: 720px) {
  /* last resort: no data table may push the page sideways */
  .data-table { max-width: 100%; }
  .modal .table-wrap { overflow-x: auto !important; }
  .bb-kpi { min-width: 0; overflow-wrap: anywhere; }
  .mom-flag small { font-size: 0.7rem !important; }
  .pair-table em, .data-table em, em { font-size: 0.72rem !important; }
}
