/* ── Font imports ─────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=IBM+Plex+Sans:wght@300;400;500;600;700&family=Sora:wght@400;600;700&display=swap');

/* ── CSS Variables — Light theme ─────────────────────────────────────────── */
:root {
  /* Brand */
  --brand-primary:   #1a56db;
  --brand-secondary: #0e4fbe;
  --brand-accent:    #f59e0b;
  --brand-success:   #059669;
  --brand-danger:    #dc2626;
  --brand-warning:   #d97706;
  --brand-info:      #0891b2;

  /* Surface */
  --bg-page:         #f3f4f6;
  --bg-card:         #ffffff;
  --bg-card-alt:     #f9fafb;
  --bg-sidebar:      #0f172a;
  --bg-sidebar-hover:#1e293b;
  --bg-sidebar-active:#1d4ed8;
  --bg-header:       #ffffff;
  --bg-input:        #ffffff;
  --bg-input-focus:  #eff6ff;

  /* Text */
  --text-primary:    #111827;
  --text-secondary:  #6b7280;
  --text-muted:      #9ca3af;
  --text-sidebar:    #cbd5e1;
  --text-sidebar-active: #ffffff;
  --text-inverse:    #ffffff;
  --text-link:       #1a56db;

  /* Border */
  --border:          #e5e7eb;
  --border-focus:    #1a56db;
  --border-strong:   #d1d5db;

  /* Shadow */
  --shadow-sm:       0 1px 2px rgba(0,0,0,.05);
  --shadow-md:       0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.06);
  --shadow-lg:       0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -2px rgba(0,0,0,.04);
  --shadow-xl:       0 20px 25px -5px rgba(0,0,0,.08), 0 10px 10px -5px rgba(0,0,0,.03);

  /* Radius */
  --radius-sm:       6px;
  --radius:          10px;
  --radius-lg:       14px;
  --radius-xl:       20px;
  --radius-full:     9999px;

  /* Spacing */
  --sidebar-width:   240px;
  --header-height:   60px;

  /* Map markers */
  --marker-buyer:    #059669;
  --marker-low:      #f59e0b;
  --marker-non:      #dc2626;
  --marker-high:     #1a56db;
  --marker-inactive: #9ca3af;

  /* Font — set via JS theme switcher */
  --font-body:    'Inter', 'IBM Plex Sans', sans-serif;
  --font-heading: 'Inter', sans-serif;
  --font-mono:    'JetBrains Mono', 'Courier New', monospace;
  --font-tabular-nums: tabular-nums;
}

/* ── Dark mode ───────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg-page:         #0f172a;
  --bg-card:         #1e293b;
  --bg-card-alt:     #263248;
  --bg-sidebar:      #080f1d;
  --bg-sidebar-hover:#111827;
  --bg-header:       #1e293b;
  --bg-input:        #1e293b;
  --bg-input-focus:  #1d3461;

  --text-primary:    #f1f5f9;
  --text-secondary:  #94a3b8;
  --text-muted:      #64748b;
  --text-sidebar:    #94a3b8;

  --border:          #334155;
  --border-strong:   #475569;

  --shadow-sm:       0 1px 2px rgba(0,0,0,.3);
  --shadow-md:       0 4px 6px rgba(0,0,0,.4);
  --shadow-lg:       0 10px 15px rgba(0,0,0,.5);
}

/* ── Font themes ──────────────────────────────────────────────────────────── */
[data-font="inter"]         { --font-body: 'Inter', sans-serif;           --font-heading: 'Inter', sans-serif; }
[data-font="ibm-plex-sans"] { --font-body: 'IBM Plex Sans', sans-serif;   --font-heading: 'IBM Plex Sans', sans-serif; }
[data-font="sora-inter"]    { --font-body: 'Inter', sans-serif;           --font-heading: 'Sora', sans-serif; }

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--bg-page);
  line-height: 1.5;
  min-height: 100vh;
  transition: background .2s, color .2s;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea, button { font-family: inherit; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  height: 100vh;
  position: fixed;
  top: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width .2s;
}
.sidebar-logo {
  padding: 20px 20px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-logo-mark {
  width: 32px; height: 32px;
  background: var(--brand-primary);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff;
  flex-shrink: 0;
}
.sidebar-logo-text { color: #fff; font-weight: 600; font-size: 15px; line-height: 1.2; }
.sidebar-logo-sub  { color: var(--text-sidebar); font-size: 11px; }

.sidebar-section { padding: 16px 12px 4px; }
.sidebar-section-label {
  color: #475569;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 0 8px;
  margin-bottom: 4px;
}
.sidebar-nav { list-style: none; }
.sidebar-nav li a, .sidebar-nav li button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-sidebar);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 450;
  line-height: 1.25;
  cursor: pointer;
  width: 100%;
  border: none;
  background: none;
  transition: background .12s, color .12s;
  text-decoration: none;
}
.sidebar-nav li a:hover, .sidebar-nav li button:hover {
  background: var(--bg-sidebar-hover);
  color: #e2e8f0;
  text-decoration: none;
}
.sidebar-nav li a.active, .sidebar-nav li button.active {
  background: var(--bg-sidebar-active);
  color: var(--text-sidebar-active);
  font-weight: 500;
}
.sidebar-nav li a .nav-icon, .sidebar-nav li button .nav-icon {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  opacity: .8; flex-shrink: 0;
}
/* Force a single icon size for every nav item (parent + child), regardless of
   the size attribute be_icon() emits, so labels and icons stay aligned. */
.sidebar-nav .nav-icon svg { width: 18px; height: 18px; }
.sidebar-bottom {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.sidebar-user-avatar {
  width: 32px; height: 32px;
  background: #1d4ed8;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: #fff; font-size: 13px; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; overflow: hidden; }
.sidebar-user-name { color: #e2e8f0; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { color: #64748b; font-size: 11px; }

/* ── Main content ─────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--header-height);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.topbar-title { font-size: 16px; font-weight: 600; font-family: var(--font-heading); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ── Page content ─────────────────────────────────────────────────────────── */
.page-content { padding: 24px; flex: 1; }
.page-header { margin-bottom: 20px; }
.page-header h1 { font-family: var(--font-heading); font-size: 22px; font-weight: 700; }
.page-header p  { color: var(--text-secondary); font-size: 14px; margin-top: 2px; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title { font-size: 14px; font-weight: 600; font-family: var(--font-heading); }
.card-body { padding: 20px; }

/* ── KPI Row ──────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: box-shadow .15s;
}
.kpi-card:hover { box-shadow: var(--shadow-md); }
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--kpi-accent, var(--brand-primary));
}
.kpi-label  { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-secondary); margin-bottom: 8px; }
.kpi-value  { font-size: 24px; font-weight: 700; font-variant-numeric: var(--font-tabular-nums); line-height: 1; color: var(--text-primary); }
.kpi-sub    { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.kpi-trend  { font-size: 11px; font-weight: 600; }
.kpi-trend.up   { color: var(--brand-success); }
.kpi-trend.down { color: var(--brand-danger); }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: var(--bg-card-alt);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary);
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th.num { text-align: right; }
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-card-alt); }
tbody td { padding: 10px 14px; color: var(--text-primary); vertical-align: middle; }
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody td.muted { color: var(--text-secondary); }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
}
.badge-green   { background: #d1fae5; color: #065f46; }
.badge-red     { background: #fee2e2; color: #991b1b; }
.badge-yellow  { background: #fef3c7; color: #92400e; }
.badge-blue    { background: #dbeafe; color: #1e40af; }
.badge-gray    { background: #f3f4f6; color: #374151; }
.badge-purple  { background: #ede9fe; color: #5b21b6; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  cursor: pointer; border: none;
  transition: background .12s, box-shadow .12s, transform .08s;
  text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn-primary   { background: var(--brand-primary); color: #fff; }
.btn-primary:hover { background: var(--brand-secondary); color: #fff; text-decoration: none; }
.btn-secondary { background: var(--bg-card); border: 1px solid var(--border); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-card-alt); text-decoration: none; }
.btn-danger    { background: var(--brand-danger); color: #fff; }
.btn-success   { background: var(--brand-success); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-xs { padding: 3px 9px; font-size: 11px; }
.btn-icon { padding: 8px; }
.btn-ghost { background: transparent; border: none; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-card-alt); text-decoration: none; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 5px; }
.form-input, .form-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  transition: border-color .12s, box-shadow .12s;
  outline: none;
}
.form-input:focus, .form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
  background: var(--bg-input-focus);
}
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Filter bar ───────────────────────────────────────────────────────────── */
.filter-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 20px;
}
.filter-bar .form-group { margin-bottom: 0; flex: 1; min-width: 140px; max-width: 200px; }
.filter-bar .form-label { font-size: 11px; }
.filter-bar .form-input,
.filter-bar .form-select { font-size: 12.5px; padding: 6px 10px; }

/* Filter controls (.filter-form/.filter-group/.filter-input/.filter-select) used by
   products, brand-sales, opportunities and reports — styled to match the form system. */
.filter-form { display: flex; flex-wrap: wrap; gap: 12px 14px; align-items: flex-end; width: 100%; }
.filter-group { display: flex; flex-direction: column; gap: 5px; min-width: 150px; }
.filter-group > label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); }
.filter-input, .filter-select {
  height: 36px; padding: 7px 10px; font-size: 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-input); color: var(--text-primary);
}
.filter-select { cursor: pointer; }
.filter-input:focus, .filter-select:focus { outline: none; border-color: var(--border-focus); background: var(--bg-input-focus); }
.filter-actions { display: flex; gap: 8px; align-items: flex-end; margin-left: auto; }

/* .kpi-row — same responsive auto-grid as .kpi-grid (used by products, brand-sales,
   opportunities, billing, api-sync) so KPI cards sit in a row, not stacked. */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }

/* ── Map ──────────────────────────────────────────────────────────────────── */
#map {
  width: 100%;
  height: 540px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  z-index: 1;
}
.map-legend {
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.map-legend-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-secondary);
}
.map-legend-dot {
  width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0;
}

/* Leaflet popup customise */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-lg) !important;
  font-family: var(--font-body) !important;
  font-size: 13px !important;
  padding: 0 !important;
  min-width: 230px;
}
.leaflet-popup-content { margin: 0 !important; padding: 0 !important; }
.popup-header {
  background: var(--brand-primary);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius) var(--radius) 0 0;
  font-weight: 600;
  font-size: 13px;
}
.popup-body { padding: 12px 14px; }
.popup-row { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; font-size: 12.5px; }
.popup-label { color: var(--text-secondary); }
.popup-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.popup-footer { padding: 8px 14px; border-top: 1px solid var(--border); }

/* ── Drilldown drawer ─────────────────────────────────────────────────────── */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.drawer-overlay.open { opacity: 1; pointer-events: all; }
.drawer {
  position: fixed;
  top: 0; right: 0;
  width: 460px;
  max-width: 95vw;
  height: 100vh;
  background: var(--bg-card);
  z-index: 501;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  box-shadow: var(--shadow-xl);
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.drawer-title { font-size: 15px; font-weight: 700; font-family: var(--font-heading); }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-footer { padding: 14px 20px; border-top: 1px solid var(--border); flex-shrink: 0; }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-btn {
  padding: 8px 16px;
  font-size: 13px; font-weight: 500;
  color: var(--text-secondary);
  background: none; border: none; cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .12s, border-color .12s;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Progress / scores ────────────────────────────────────────────────────── */
.score-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.score-fill { height: 100%; border-radius: 3px; background: var(--brand-primary); transition: width .5s; }
.score-fill.high   { background: var(--brand-danger); }
.score-fill.medium { background: var(--brand-warning); }
.score-fill.low    { background: var(--brand-success); }

/* ── Opportunity tier ─────────────────────────────────────────────────────── */
.tier-high   { color: #dc2626; font-weight: 700; }
.tier-medium { color: #d97706; font-weight: 700; }
.tier-low    { color: #059669; font-weight: 700; }

/* ── Notification / Alert ─────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 13px;
  display: flex; align-items: flex-start; gap: 10px;
  margin-bottom: 16px;
}
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.demo-banner {
  background: linear-gradient(90deg, #fef3c7 0%, #fffbeb 100%);
  border: 1px solid #fbbf24;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 12.5px;
  color: #92400e;
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 16px;
}

/* ── Sync / API status ────────────────────────────────────────────────────── */
.sync-status { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.green  { background: var(--brand-success); box-shadow: 0 0 0 2px rgba(5,150,105,.2); }
.status-dot.red    { background: var(--brand-danger);  box-shadow: 0 0 0 2px rgba(220,38,38,.2); }
.status-dot.yellow { background: var(--brand-warning); box-shadow: 0 0 0 2px rgba(217,119,6,.2); }
.status-dot.gray   { background: var(--text-muted); }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0b1220 0%, #16294a 55%, #1e3a5f 100%);
  padding: 24px;
}
.login-shell {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  width: 100%;
  max-width: 940px;
  min-height: 560px;
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-xl);
}
/* Brand panel */
.login-brand {
  background: linear-gradient(160deg, var(--brand-primary) 0%, #163fa3 60%, #0f2d78 100%);
  color: #fff;
  padding: 44px 40px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
}
.login-brand::after {
  content: "";
  position: absolute; right: -80px; bottom: -80px;
  width: 240px; height: 240px; border-radius: 50%;
  background: rgba(255,255,255,.06);
}
.login-brand-logo { display: flex; align-items: center; gap: 12px; }
.login-brand-mark {
  width: 44px; height: 44px; border-radius: var(--radius);
  background: rgba(255,255,255,.14);
  display: inline-flex; align-items: center; justify-content: center;
}
.login-brand-name { font-size: 24px; font-weight: 700; letter-spacing: -.3px; }
.login-brand-tagline { margin-top: 14px; font-size: 14px; line-height: 1.55; color: rgba(255,255,255,.82); max-width: 30ch; }
.login-features { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.login-features li { display: flex; align-items: flex-start; gap: 11px; font-size: 13.5px; color: rgba(255,255,255,.9); }
.login-features li .icon { margin-top: 1px; color: #bfdbff; flex: 0 0 auto; }
.login-brand-foot { font-size: 11.5px; color: rgba(255,255,255,.6); }

/* Form panel */
.login-form-wrap { display: flex; align-items: center; justify-content: center; padding: 44px 48px; }
.login-form { width: 100%; max-width: 360px; }
.login-form-logo { display: none; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-logo-mark {
  width: 36px; height: 36px;
  background: var(--brand-primary);
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
}
.login-logo-text { font-size: 19px; font-weight: 700; font-family: var(--font-heading); }
.login-title { font-size: 22px; font-weight: 700; margin-bottom: 6px; color: var(--text-primary); }
.login-sub   { font-size: 13.5px; color: var(--text-secondary); margin-bottom: 24px; }
.login-alert { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; }
.login-row { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 20px; }
.login-remember { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); cursor: pointer; user-select: none; }
.login-remember input { width: 15px; height: 15px; accent-color: var(--brand-primary); cursor: pointer; }
.login-forgot { font-size: 13px; color: var(--text-link); font-weight: 500; text-decoration: none; }
.login-forgot:hover { text-decoration: underline; }
.login-forgot-note[hidden] { display: none; }
.login-forgot-note { display: flex; align-items: flex-start; gap: 7px; font-size: 12.5px; color: var(--text-secondary); background: var(--bg-card-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 12px; margin: -8px 0 18px; }
.login-submit { width: 100%; justify-content: center; gap: 8px; padding: 11px; font-size: 14.5px; }
.login-demo { margin-top: 26px; border-top: 1px solid var(--border); padding-top: 16px; }
.login-demo > summary { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); list-style: none; }
.login-demo > summary::-webkit-details-marker { display: none; }
.login-demo-grid { display: grid; gap: 7px; margin-top: 12px; }
.login-demo-grid > div { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--text-secondary); }
.login-demo-grid code { font-size: 11.5px; color: var(--text-primary); background: var(--bg-card-alt); padding: 2px 7px; border-radius: 5px; border: 1px solid var(--border); }
@media (max-width: 780px) {
  .login-page { padding: 14px; }
  .login-shell { grid-template-columns: 1fr; max-width: 100%; width: 100%; min-height: 0; }
  .login-brand { display: none; }
  .login-form-wrap { padding: 30px 22px; }
  .login-form { max-width: 100%; }
  .login-form-logo { display: flex; }
}

/* ── Sidebar nav wrapper — transparent block; the sidebar itself scrolls
   (original, known-good behaviour). Logo stays at top, user block at bottom. */
.sidebar-scroll { display: block; }

/* ── Admin About tab ────────────────────────────────────────────────────────── */
.admin-about-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
@media (max-width: 820px) { .admin-about-grid { grid-template-columns: 1fr; } }
.tab-link { display: inline-flex; align-items: center; gap: 6px; }
/* Info grid (label over value) — used by Admin → About and Settings → App Info. */
.info-grid  { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.info-item  { display: flex; flex-direction: column; gap: 4px; }
.info-label { font-size: 12px; color: var(--text-muted); }
.info-value { font-size: 14px; font-weight: 600; color: var(--text-primary); word-break: break-word; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.flex     { display: flex; }
.flex-1   { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2    { gap: 8px; }
.gap-3    { gap: 12px; }
.gap-4    { gap: 16px; }
.grid-2   { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3   { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.mb-3     { margin-bottom: 12px; }
.mb-4     { margin-bottom: 16px; }
.mb-5     { margin-bottom: 20px; }
.mt-3     { margin-top: 12px; }
.mt-4     { margin-top: 16px; }
.text-sm  { font-size: 12px; }
.text-muted { color: var(--text-secondary); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.text-right { text-align: right; }
.tabnum   { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full   { width: 100%; }
.sr-only  { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ── Section layout ───────────────────────────────────────────────────────── */
.section-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  margin-bottom: 20px;
}
@media (max-width: 1100px) { .section-grid { grid-template-columns: 1fr; } }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; max-width: 100%; overflow-x: hidden; }
  .kpi-grid, .kpi-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .kpi-card { min-width: 0; }
  .filter-form, .filter-bar { flex-wrap: wrap; }
  .filter-group { min-width: 0; }
  .page-content { padding: 16px; }
}
@media (max-width: 480px) {
  .kpi-grid, .kpi-row { grid-template-columns: 1fr; }
}

/* ── Flat icons (be_icon) ───────────────────────────────────────────────────
   One consistent inline-SVG family. Icons inherit text colour and align to
   the text baseline; they never shift layout or get distorted. */
.icon {
  display: inline-block;
  vertical-align: -0.18em;
  flex-shrink: 0;
  stroke-width: 2;
  pointer-events: none;
}
button .icon, a .icon, .btn .icon { vertical-align: -0.18em; }
/* Icon + label spacing inside buttons/links that hold both. */
.btn .icon + *, a .icon + *, .ic-label > .icon { margin-right: 0; }
.btn > .icon:first-child:not(:only-child) { margin-right: 7px; }
.kpi-icon .icon, .stat-icon .icon { vertical-align: middle; }
/* Sidebar/topbar icons sit centred in their slot. */
.nav-icon { display: inline-flex; align-items: center; justify-content: center; }
.nav-icon .icon { vertical-align: middle; opacity: .9; }
/* Spinning sync icon. */
.icon.spin { animation: be-spin 1s linear infinite; }
@keyframes be-spin { to { transform: rotate(360deg); } }
/* Inline password reveal toggle. */
.input-affix { position: relative; }
.input-affix .form-input, .input-affix .form-control { padding-right: 40px; }
.pw-toggle {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0; border: none; background: none;
  color: var(--text-muted); cursor: pointer; border-radius: var(--radius-sm);
}
.pw-toggle:hover { color: var(--text-primary); background: var(--bg-card-alt); }

/* ── Print ────────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .filter-bar, .btn, .drawer { display: none !important; }
  .main-content { margin-left: 0; }
  .page-content { padding: 0; }
  table { font-size: 11px; }
}

/* ── Variable aliases (views use these names) ──────────────────────────────── */
:root {
  --border-color:        var(--border);
  --bg-subtle:           var(--bg-card-alt);
  --border-light:        var(--border);
  --color-primary:       var(--brand-primary);
  --color-primary-light: #EEF2FF;
}

/* ── Badge aliases ─────────────────────────────────────────────────────────── */
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-neutral { background: #f3f4f6; color: #374151; }
.badge-info    { background: #e0f2fe; color: #0369a1; }
.badge-secondary { background: #f3f4f6; color: #374151; }
.badge-amber     { background: #fef3c7; color: #92400e; }
.badge-primary   { background: #dbeafe; color: #1e40af; }
[data-theme="dark"] .badge-neutral   { background: #1e293b; color: #94a3b8; }
[data-theme="dark"] .badge-secondary { background: #1e293b; color: #94a3b8; }

/* ── Page header layout ─────────────────────────────────────────────────────── */
.page-title    { font-size: 22px; font-weight: 700; font-family: var(--font-heading); }
.page-subtitle { font-size: 13.5px; color: var(--text-secondary); margin-top: 3px; }
.page-header   { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ── Charts layout ──────────────────────────────────────────────────────────── */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.chart-card { overflow: hidden; }
.chart-card canvas { display: block; width: 100% !important; height: 240px !important; }
@media (max-width: 900px) { .charts-row { grid-template-columns: 1fr; } }

/* ── Percentage bar ─────────────────────────────────────────────────────────── */
.pct-bar-wrap { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.pct-bar      { height: 4px; border-radius: 2px; background: var(--brand-primary); min-width: 4px; }

/* ── Drawer sub-elements (view-specific drawers) ────────────────────────────── */
.drawer-panel  { display: flex; flex-direction: column; height: 100%; }
.drawer-close  {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  border: none; background: var(--bg-card-alt); cursor: pointer;
  color: var(--text-secondary); font-size: 20px; line-height: 1;
  transition: background .12s; flex-shrink: 0;
}
.drawer-close:hover { background: var(--border); color: var(--text-primary); }
.drawer-section { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.drawer-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.drawer-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 12px; }

/* ── Detail grid (used inside drawers) ──────────────────────────────────────── */
.detail-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.detail-item  { display: flex; flex-direction: column; gap: 3px; }
.detail-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.detail-value { font-size: 13.5px; color: var(--text-primary); word-break: break-word; }

/* ── Clickable rows ─────────────────────────────────────────────────────────── */
.clickable-row { cursor: pointer; }

/* ── KPI card colour variants ───────────────────────────────────────────────── */
.kpi-card--danger  { --kpi-accent: var(--brand-danger); }
.kpi-card--warning { --kpi-accent: var(--brand-warning); }
.kpi-card--success { --kpi-accent: var(--brand-success); }
.kpi-card--info    { --kpi-accent: var(--brand-info); }

/* ── form-control alias ─────────────────────────────────────────────────────── */
.form-control {
  width: 100%; padding: 8px 12px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 13px; color: var(--text-primary);
  transition: border-color .12s, box-shadow .12s; outline: none;
  font-family: inherit;
}
.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
  background: var(--bg-input-focus);
}
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ── Code block ─────────────────────────────────────────────────────────────── */
.code-block {
  background: var(--bg-card-alt); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px;
  font-family: var(--font-mono); font-size: 12.5px; word-break: break-all;
  color: var(--text-primary); line-height: 1.6;
}

/* ── Log viewer ─────────────────────────────────────────────────────────────── */
.log-viewer {
  background: var(--bg-card-alt); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px;
  max-height: 360px; overflow-y: auto; font-family: var(--font-mono);
  font-size: 12px; line-height: 1.7; margin-top: 12px;
}
.log-line { border-bottom: 1px solid var(--border); padding: 2px 0; color: var(--text-secondary); }
.log-line:last-child { border-bottom: none; }
.log-error { color: var(--brand-danger) !important; }

/* ── Text color utilities ───────────────────────────────────────────────────── */
.text-danger  { color: var(--brand-danger)  !important; }
.text-warning { color: var(--brand-warning) !important; }
.text-success { color: var(--brand-success) !important; }
.text-info    { color: var(--brand-info)    !important; }

/* ── Bulk action bar ─────────────────────────────────────────────────────────── */
.bulk-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: #eff6ff; border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm); margin-bottom: 12px; font-size: 13px;
}
.bulk-bar .bulk-count { font-weight: 600; color: var(--brand-primary); flex: 1; }
[data-theme="dark"] .bulk-bar { background: #1e3461; border-color: #1d4ed8; }

/* ── Checkbox column ─────────────────────────────────────────────────────────── */
th.cb-col, td.cb-col { width: 40px; text-align: center; padding: 10px 8px; }
input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--brand-primary); cursor: pointer; }

/* ── Row action buttons ──────────────────────────────────────────────────────── */
.row-actions { display: flex; gap: 4px; align-items: center; justify-content: flex-end; white-space: nowrap; }
.btn-row-edit   { color: var(--brand-primary); }
.btn-row-delete { color: var(--brand-danger); }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-panel { background: var(--bg-card); border-radius: var(--radius-lg); width: 100%; max-width: 480px; box-shadow: var(--shadow-xl); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 17px; font-weight: 700; margin: 0; }
.modal-body { padding: 24px; }
.modal-footer { display: flex; gap: 12px; justify-content: flex-end; padding-top: 16px; border-top: 1px solid var(--border); margin-top: 16px; }

/* ── Report picker ───────────────────────────────────────────────────────────── */
.report-picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-top: 8px; }
.report-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px 20px;
  text-decoration: none; color: var(--text-primary);
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  transition: all .2s;
}
.report-card:hover { border-color: var(--brand-primary); box-shadow: 0 4px 12px rgba(26,86,219,.12); transform: translateY(-2px); text-decoration: none; color: var(--text-primary); }
.report-card-icon  { color: var(--brand-primary); }
.report-card-label { font-weight: 600; font-size: 15px; }
.report-card-arrow { color: var(--text-muted); margin-top: auto; }

/* ── API Sync specific ───────────────────────────────────────────────────────── */
.api-status-row   { display: flex; gap: 32px; flex-wrap: wrap; }
.api-status-item  { display: flex; align-items: flex-start; gap: 12px; }
.api-status-dot   { width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; flex-shrink: 0; }
.dot-green { background: var(--brand-success); box-shadow: 0 0 0 3px rgba(5,150,105,.2); }
.dot-amber { background: var(--brand-warning); box-shadow: 0 0 0 3px rgba(217,119,6,.2); }
.dot-grey  { background: var(--text-muted); }
.api-status-label { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.api-status-value { font-size: 14px; font-weight: 500; }
.sync-summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px 24px; }
.ss-item  { display: flex; flex-direction: column; gap: 2px; }
.ss-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.ss-value { font-size: 14px; font-weight: 600; color: var(--text-primary); }
@media (max-width: 760px) { .sync-summary-grid { grid-template-columns: repeat(2, minmax(0,1fr)); } }

/* ── Settings font picker ─────────────────────────────────────────────────────── */
.font-option-inner { border: 2px solid var(--border) !important; border-radius: var(--radius) !important; padding: 20px !important; transition: all .2s !important; }
.font-option:hover .font-option-inner { border-color: var(--brand-primary) !important; }
.font-option.selected .font-option-inner { border-color: var(--brand-primary) !important; background: rgba(26,86,219,.04) !important; }
.font-option-check { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 2px; transition: all .2s; }
.font-option.selected .font-option-check { border-color: var(--brand-primary); background: var(--brand-primary); }
.font-preview-block { background: var(--bg-card-alt) !important; }
.fp-num { color: var(--brand-primary) !important; }

/* ── Hint text ────────────────────────────────────────────────────────────────── */
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Settings btn-lg ─────────────────────────────────────────────────────────── */
.btn-lg { padding: 12px 28px; font-size: 15px; }

/* ── Misc fixes ───────────────────────────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.card-body { padding: 20px; }

/* ═══════════════════════════════════════════════════════════════════════════
   Pricing & Sales page  (migrated from views/pricing_sales.php inline <style>)
   All selectors are page-namespaced (.ps-*, .psd-*, #ps-drawer, tr.pv-*).
   ═════════════════════════════════════════════════════════════════════════ */
/* ── Command bar ──────────────────────────────────────────────────────────── */
.ps-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 10px 14px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
}
.ps-period-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--bg-sidebar);
    color: #93c5fd;
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
}
.ps-period-pill .ps-month-badge {
    background: rgba(147,197,253,.18);
    color: #93c5fd;
    font-size: 10px;
    font-weight: 600;
    border-radius: 4px;
    padding: 2px 6px;
    letter-spacing: .03em;
}
.ps-divider {
    width: 1px;
    height: 26px;
    background: var(--border);
    flex-shrink: 0;
    margin: 0 2px;
}
/* Filter chips */
.ps-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--bg-card-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 10px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: border-color .12s, color .12s;
}
.ps-chip:hover { border-color: var(--brand-primary); color: var(--text-primary); }
.ps-chip.active { border-color: var(--brand-primary); background: #eff6ff; color: var(--brand-primary); }
.ps-chip svg { flex-shrink: 0; opacity: .7; }
.ps-chip select, .ps-chip input[type="text"] {
    position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.ps-chip input[type="text"] { font-size: 12px; }
.ps-date-chip {
    display: inline-flex; align-items: center; gap: 5px;
    background: var(--bg-card-alt); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 5px 10px;
    font-size: 12px; color: var(--text-secondary);
    white-space: nowrap;
}
.ps-date-chip input[type="date"] {
    border: none; background: transparent; font-size: 12px;
    color: var(--text-primary); outline: none; cursor: pointer;
    font-family: var(--font-body); width: 110px;
}
.ps-date-chip .ps-date-sep { color: var(--text-muted); font-size: 11px; margin: 0 2px; }
.ps-spacer { flex: 1; min-width: 8px; }
/* Action buttons in bar */
.ps-action-dl {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 14px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--bg-card-alt);
    color: var(--text-primary); font-size: 12.5px; font-weight: 500;
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background .12s, border-color .12s;
}
.ps-action-dl:hover { background: var(--bg-card); border-color: var(--border-strong); text-decoration: none; color: var(--text-primary); }
.ps-action-up {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 14px; border-radius: var(--radius-sm);
    border: none; background: var(--brand-primary);
    color: #fff; font-size: 12.5px; font-weight: 500;
    cursor: pointer; white-space: nowrap;
    transition: background .12s;
}
.ps-action-up:hover { background: var(--brand-secondary); }
/* Reset link */
.ps-reset-link {
    font-size: 11.5px; color: var(--brand-primary); cursor: pointer;
    text-decoration: none; white-space: nowrap; padding: 4px 6px;
    border-radius: 4px; transition: background .1s;
}
.ps-reset-link:hover { background: #eff6ff; }

/* ── KPI strip ────────────────────────────────────────────────────────────── */
.ps-kpi-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}
.ps-kpi {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    position: relative;
    overflow: hidden;
    transition: box-shadow .15s;
}
.ps-kpi:hover { box-shadow: var(--shadow-md); }
.ps-kpi::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: var(--kpi-accent-color, var(--brand-primary));
}
.ps-kpi.accent-blue   { --kpi-accent-color: #1a56db; }
.ps-kpi.accent-green  { --kpi-accent-color: #059669; }
.ps-kpi.accent-amber  { --kpi-accent-color: #d97706; }
.ps-kpi.accent-purple { --kpi-accent-color: #7c3aed; }
.ps-kpi-label {
    font-size: 10.5px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .06em; color: var(--text-secondary); margin-bottom: 8px;
}
.ps-kpi-value {
    font-size: 26px; font-weight: 700; line-height: 1;
    color: var(--text-primary); font-variant-numeric: tabular-nums;
}
.ps-kpi-value.compact { font-size: 20px; }
.ps-kpi-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }
.ps-kpi-bar {
    margin-top: 10px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}
.ps-kpi-bar-fill {
    height: 100%; border-radius: 2px;
    background: var(--kpi-accent-color, var(--brand-primary));
    transition: width .6s ease;
}

/* ── Table ────────────────────────────────────────────────────────────────── */
.ps-table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.ps-table-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px 12px;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}
.ps-table-title { font-size: 14px; font-weight: 600; font-family: var(--font-heading); }
.ps-table-meta { display: flex; align-items: center; gap: 8px; }
.ps-count-badge {
    display: inline-flex; align-items: center;
    background: var(--bg-card-alt); border: 1px solid var(--border);
    border-radius: var(--radius-full);
    padding: 3px 10px; font-size: 11px; color: var(--text-secondary);
}
table.ps-table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: auto; }
table.ps-table thead th {
    background: var(--bg-card-alt);
    font-size: 10.5px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-secondary);
    padding: 9px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.ps-table thead th.r { text-align: right; }
table.ps-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background .08s;
    cursor: pointer;
}
table.ps-table tbody tr:last-child { border-bottom: none; }
table.ps-table tbody tr:hover { background: var(--bg-card-alt); }
table.ps-table tbody td {
    padding: 10px 14px; color: var(--text-primary); vertical-align: middle;
}
table.ps-table tbody td.r { text-align: right; font-variant-numeric: tabular-nums; }
table.ps-table tbody td.muted { color: var(--text-muted); }

/* Product cell: name + meta on two lines */
.ps-prod-name { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; display: block; }
.ps-prod-meta { font-size: 11px; color: var(--text-muted); white-space: nowrap; margin-top: 1px; }
.ps-barcode   { font-family: var(--font-mono); font-size: 11.5px; letter-spacing: .02em; }
.ps-sku       { font-family: var(--font-mono); font-size: 11.5px; }

/* RSP chip */
.ps-rsp-set {
    display: inline-flex; align-items: center;
    background: #eff6ff; color: #1e40af;
    border-radius: 5px; padding: 3px 8px;
    font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.ps-rsp-unset {
    display: inline-flex; align-items: center;
    background: var(--bg-card-alt); color: var(--text-muted);
    border-radius: 5px; padding: 3px 8px;
    font-size: 11px; border: 1px dashed var(--border-strong);
}

/* Status dot */
.ps-status { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; }
.ps-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.ps-dot.on  { background: #059669; }
.ps-dot.off { background: var(--text-muted); }

/* Empty state */
.ps-empty {
    text-align: center; padding: 60px 24px;
    color: var(--text-muted); font-size: 13px;
}
.ps-empty-icon { font-size: 36px; margin-bottom: 12px; opacity: .4; }

/* ── Upload card ──────────────────────────────────────────────────────────── */
.ps-upload-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-top: 24px;
    overflow: hidden;
}
.ps-upload-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px 12px;
    border-bottom: 1px solid var(--border);
}
.ps-upload-body { padding: 22px 24px; }
.ps-steps {
    display: flex; gap: 0; margin-bottom: 24px;
    border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden;
}
.ps-step {
    flex: 1; display: flex; align-items: flex-start; gap: 12px;
    padding: 14px 16px;
    border-right: 1px solid var(--border);
    background: var(--bg-card-alt);
}
.ps-step:last-child { border-right: none; }
.ps-step-num {
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--brand-primary); color: #fff;
    font-size: 11px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; margin-top: 1px;
}
.ps-step-text { font-size: 12.5px; color: var(--text-secondary); line-height: 1.5; }
.ps-step-text strong { color: var(--text-primary); font-weight: 600; display: block; margin-bottom: 2px; }

/* Drop zone */
.ps-drop {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 32px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.ps-drop:hover, .ps-drop.over {
    border-color: var(--brand-primary);
    background: #eff6ff;
}
.ps-drop-icon { font-size: 30px; opacity: .45; margin-bottom: 10px; }
.ps-drop-label { font-size: 14px; color: var(--text-primary); margin-bottom: 4px; }
.ps-drop-label a { color: var(--brand-primary); text-decoration: underline; cursor: pointer; }
.ps-drop-hint  { font-size: 12px; color: var(--text-muted); }
.ps-filename   { margin-top: 10px; font-size: 13px; color: var(--brand-primary); font-weight: 500; }

/* Preview table row states */
tr.pv-ok  td { background: rgba(5, 150, 105, .04); }
tr.pv-err td { background: rgba(220, 38,  38, .04); }

/* ── Drawer ───────────────────────────────────────────────────────────────── */
#ps-drawer {
    position: fixed; top: 0; right: 0;
    width: 480px; max-width: 96vw; height: 100vh;
    background: var(--bg-card);
    box-shadow: var(--shadow-xl);
    z-index: 600;
    display: flex; flex-direction: column;
    transform: translateX(110%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
}
#ps-drawer.open { transform: translateX(0); }
#ps-drawer-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.38);
    z-index: 599; opacity: 0; pointer-events: none;
    transition: opacity .2s;
}
#ps-drawer-overlay.open { opacity: 1; pointer-events: all; }
.psd-head {
    padding: 16px 20px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.psd-head h3 { font-size: 15px; font-weight: 700; line-height: 1.3; margin: 0; }
.psd-close {
    width: 30px; height: 30px; border-radius: 50%;
    border: none; background: var(--bg-card-alt); cursor: pointer;
    font-size: 16px; color: var(--text-secondary);
    display: flex; align-items: center; justify-content: center;
    transition: background .1s;
}
.psd-close:hover { background: var(--border); color: var(--text-primary); }
.psd-body { flex: 1; overflow-y: auto; padding: 20px; }
.psd-section { margin-bottom: 22px; }
.psd-section-title {
    font-size: 10.5px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .07em; color: var(--text-muted);
    margin-bottom: 10px; padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.psd-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px;
}
.psd-field { display: flex; flex-direction: column; gap: 3px; }
.psd-field-label { font-size: 11px; color: var(--text-muted); }
.psd-field-value { font-size: 13px; color: var(--text-primary); font-weight: 500; }
.psd-field-value code { font-family: var(--font-mono); font-size: 12px; font-weight: 400; }
.psd-rsp-block {
    background: #eff6ff; border: 1px solid #bfdbfe;
    border-radius: var(--radius); padding: 14px 16px;
    display: flex; align-items: center; justify-content: space-between;
}
.psd-rsp-block.unset { background: var(--bg-card-alt); border-color: var(--border); }
.psd-rsp-label { font-size: 11px; color: #1e40af; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.psd-rsp-label.unset { color: var(--text-muted); }
.psd-rsp-value { font-size: 22px; font-weight: 700; color: #1e40af; font-variant-numeric: tabular-nums; }
.psd-rsp-value.unset { font-size: 14px; color: var(--text-muted); font-weight: 500; }
.psd-unit-price { font-size: 13px; color: var(--text-secondary); }

/* ── Flash alerts (page-level) ────────────────────────────────────────────── */
.ps-alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 16px; border-radius: var(--radius-sm);
    border: 1px solid; font-size: 13px; margin-bottom: 16px;
}
.ps-alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.ps-alert-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 1200px) {
    .ps-kpi-strip { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
    .ps-steps { flex-direction: column; }
    .ps-step { border-right: none; border-bottom: 1px solid var(--border); }
    .ps-step:last-child { border-bottom: none; }
}

.ps-rsp-input {
    width: 86px; text-align: right; font-variant-numeric: tabular-nums;
    font-size: 12.5px; padding: 4px 7px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--bg-card); color: var(--text-primary);
    outline: none; transition: border-color .12s, box-shadow .12s;
}
.ps-rsp-input:hover  { border-color: var(--border-strong); }
.ps-rsp-input:focus  { border-color: var(--brand-primary); box-shadow: 0 0 0 2px rgba(26,86,219,.12); }
.ps-rsp-input.unset  { border-style: dashed; background: transparent; }
.ps-rsp-input.unset::placeholder { color: var(--text-muted); }

/* Pricing & Sales — chip/search helpers (migrated from inline styles) */
a.ps-chip { text-decoration: none; }
.ps-chip--search { cursor: default; }
.ps-search-field { position: static; opacity: 1; width: 160px; height: auto; border: none; background: transparent; outline: none; font-size: 12px; color: var(--text-primary); }
/* Pricing & Sales — upload-preview table (non-clickable rows + accent cells) */
.ps-table--static tbody tr { cursor: default; }
.ps-prod-strong { font-weight: 500; }
.ps-new-rsp { font-weight: 600; color: #1e40af; }

/* ── Shared text/state utilities (consolidated from repeated inline styles) ── */
.req           { color: var(--brand-danger); }
.cell-empty    { text-align: center; padding: 20px; }
.text-overline { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.text-meta     { font-size: 11px; color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════════════════════
   Page-scoped view styles  (migrated from per-view inline <style> blocks)
   Scoped via [data-page="…"] on .page-content so they only apply on their own
   page — identical to the old inline behavior, but centralized here.
   ═════════════════════════════════════════════════════════════════════════ */

/* Shared: pagination bar (suppliers + merchant_detail) */
.pagination-bar  { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); }
.pagination-info { font-size: 13px; color: var(--text-muted); margin: 0 auto; }

/* Shared print extras (from reports view) */
@media print {
  .page-header-actions { display: none !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; }
}

/* ── Admin ─────────────────────────────────────────────────────────────── */
[data-page="admin"] .tab-nav { display:flex; gap:4px; border-bottom:2px solid var(--border-color); }
[data-page="admin"] .tab-link { padding:10px 18px; font-size:14px; font-weight:500; color:var(--text-secondary); text-decoration:none; border-bottom:2px solid transparent; margin-bottom:-2px; transition:all .2s; }
[data-page="admin"] .tab-link:hover { color:var(--text-primary); }
[data-page="admin"] .tab-link.active { color:var(--color-primary); border-bottom-color:var(--color-primary); }
[data-page="admin"] .form-row { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
[data-page="admin"] .log-viewer { background:var(--bg-subtle); border:1px solid var(--border-color); border-radius:8px; padding:12px 16px; max-height:500px; overflow-y:auto; font-family:monospace; font-size:12px; line-height:1.7; }
[data-page="admin"] .log-line { border-bottom:1px solid var(--border-light); padding:2px 0; }

/* ── Opportunities ─────────────────────────────────────────────────────── */
[data-page="opportunities"] .score-pill { display:inline-flex; align-items:center; justify-content:center; width:44px; height:24px; border-radius:12px; font-weight:700; font-size:13px; font-variant-numeric:tabular-nums; }
[data-page="opportunities"] .score-high { background:#FEE2E2; color:#DC2626; }
[data-page="opportunities"] .score-mid  { background:#FEF3C7; color:#D97706; }
[data-page="opportunities"] .score-low  { background:#D1FAE5; color:#059669; }
[data-page="opportunities"] .kpi-card--danger  { border-left:4px solid #EF4444; }
[data-page="opportunities"] .kpi-card--warning { border-left:4px solid #F59E0B; }
[data-page="opportunities"] .kpi-card--success { border-left:4px solid #10B981; }

/* ── Reports (report picker cards) ─────────────────────────────────────── */
[data-page="reports"] .report-picker-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(220px,1fr)); gap:16px; margin-top:8px; }
[data-page="reports"] .report-card { background:var(--bg-card); border:1px solid var(--border); border-radius:12px; padding:24px 20px; text-decoration:none; color:var(--text-primary); display:flex; flex-direction:column; align-items:flex-start; gap:10px; transition:all .2s; cursor:pointer; }
[data-page="reports"] .report-card:hover { border-color:var(--brand-primary); box-shadow:0 4px 12px rgba(79,110,247,0.12); transform:translateY(-2px); }
[data-page="reports"] .report-card-icon { color:var(--brand-primary); }
[data-page="reports"] .report-card-label { font-weight:600; font-size:15px; }
[data-page="reports"] .report-card-arrow { color:var(--text-muted); margin-top:auto; }

/* ── Suppliers (row highlight) ─────────────────────────────────────────── */
[data-page="suppliers"] .supplier-row:hover td { background: var(--bg-input-focus); }
[data-page="suppliers"] .supplier-row-active td { background: rgba(79,110,247,.06); }

/* ── Settings ──────────────────────────────────────────────────────────── */
[data-page="settings"] .settings-card { margin-bottom: 20px; }
[data-page="settings"] .settings-body { padding: 24px; }
[data-page="settings"] .settings-description { color: var(--text-secondary); font-size: 14px; margin: 0 0 20px; }
[data-page="settings"] .settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; }
[data-page="settings"] .font-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
[data-page="settings"] .font-option  { cursor: pointer; display: block; }
[data-page="settings"] .font-radio   { display: none; }
[data-page="settings"] .font-option-inner  { border: 2px solid var(--border); border-radius: 12px; padding: 20px; transition: all .2s; }
[data-page="settings"] .font-option:hover .font-option-inner { border-color: var(--brand-primary); }
[data-page="settings"] .font-option.selected .font-option-inner { border-color: var(--brand-primary); background: rgba(79,110,247,0.04); }
[data-page="settings"] .font-option-header { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
[data-page="settings"] .font-option-check  { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 2px; transition: all .2s; }
[data-page="settings"] .font-option.selected .font-option-check { border-color: var(--brand-primary); background: var(--brand-primary); }
[data-page="settings"] .check-dot { width: 8px; height: 8px; border-radius: 50%; background: white; display: none; }
[data-page="settings"] .font-option.selected .check-dot { display: block; }
[data-page="settings"] .font-option-name    { font-size: 17px; font-weight: 700; color: var(--text-primary); }
[data-page="settings"] .font-option-tagline { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
[data-page="settings"] .font-option-detail  { font-size: 12px; color: var(--text-muted); margin: 0; line-height: 1.5; }
[data-page="settings"] .font-preview-block  { background: var(--bg-card-alt); border-radius: 8px; padding: 14px; margin-bottom: 12px; }
[data-page="settings"] .fp-heading { font-size: 15px; font-weight: 700; color: var(--text-primary); margin-bottom: 6px; }
[data-page="settings"] .fp-body    { font-size: 13px; color: var(--text-secondary); margin-bottom: 3px; }
[data-page="settings"] .fp-num     { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--brand-primary); }
[data-page="settings"] .font-preview-inter { font-family: 'Inter', sans-serif !important; }
[data-page="settings"] .font-preview-ibm   { font-family: 'IBM Plex Sans', sans-serif !important; }
[data-page="settings"] .font-preview-sora .fp-heading { font-family: 'Sora', sans-serif !important; }
[data-page="settings"] .font-preview-sora .fp-body    { font-family: 'Inter', sans-serif !important; }
[data-page="settings"] .info-grid  { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
[data-page="settings"] .info-item  { display: flex; flex-direction: column; gap: 4px; }
[data-page="settings"] .info-label { font-size: 12px; color: var(--text-muted); }
[data-page="settings"] .info-value { font-size: 14px; font-weight: 500; }

/* ── TradeRewards Campaigns ────────────────────────────────────────────── */
[data-page="trade-rewards-campaigns"] .modal-overlay { display:none; position:fixed; inset:0; background:rgba(0,0,0,.45); z-index:1000; align-items:center; justify-content:center; }
[data-page="trade-rewards-campaigns"] .modal-overlay.open { display:flex; }
[data-page="trade-rewards-campaigns"] .modal-header { display:flex; align-items:center; justify-content:space-between; padding:16px 20px; border-bottom:1px solid var(--border); }
[data-page="trade-rewards-campaigns"] .modal-title { font-weight:600; font-size:15px; }
[data-page="trade-rewards-campaigns"] .btn-danger { background:#dc2626; color:#fff; border-color:#dc2626; }
[data-page="trade-rewards-campaigns"] .btn-danger:hover { background:#b91c1c; }
[data-page="trade-rewards-campaigns"] .empty-state { text-align:center; padding:60px 20px; color:var(--text-muted); }
[data-page="trade-rewards-campaigns"] .empty-state svg { opacity:.3; margin-bottom:16px; }
[data-page="trade-rewards-campaigns"] .empty-title { font-size:16px; font-weight:600; color:var(--text-base); margin-bottom:8px; }
[data-page="trade-rewards-campaigns"] .empty-sub { font-size:13px; margin-bottom:20px; }
[data-page="trade-rewards-campaigns"] .alert-info-panel { display:flex; align-items:flex-start; gap:10px; }
[data-page="trade-rewards-campaigns"] .bulk-bar { display:flex; align-items:center; gap:10px; padding:8px 12px; background:var(--surface-2,#f3f4f6); border-radius:8px; margin-bottom:8px; }

/* ── Merchants (row highlight) ─────────────────────────────────────────── */
[data-page="merchants"] .merchant-row:hover td { background: var(--bg-input-focus); }
