/* New Age Media dashboard — Scandinavian fintech, light edition.
 *
 * Near-white page, pure-white cards, hairline borders, soft shadows and
 * one confident accent — the Stripe/Linear school. Country colors are
 * applied via `body.country-<code>` and cascade through `--accent` so
 * the UI shifts per view. Chart colors are read from the --chart-* and
 * country tokens by the JS, so theme and charts stay in step; the
 * palette is CVD-validated for the light surface (dataviz validator,
 * 2026-11-13) — keep the hue ORDER of --chart-1..8 if you edit it.
 */

@import url('https://rsms.me/inter/inter.css');

:root {
  color-scheme: light;

  /* Surfaces — near-white page, white cards, cool gray steps. */
  --bg:           #f6f7f9;
  --bg-soft:      #f1f3f6;
  --surface:      #ffffff;       /* cards */
  --surface-2:    #f3f4f7;       /* elevated elements, hovers, inputs */
  --surface-3:    #e8eaef;
  --border:       rgba(16, 24, 40, 0.08);
  --border-strong:rgba(16, 24, 40, 0.14);

  /* Typography — slate ink, three steps of recession. */
  --text:         #101828;
  --text-2:       #344054;
  --muted:        #667085;
  --muted-2:      #98a2b3;

  /* Semantic colors — deep enough to read on white. */
  --positive:     #12934f;
  --positive-soft: rgba(18, 147, 79, 0.10);
  --negative:     #d92d20;
  --negative-soft: rgba(217, 45, 32, 0.08);
  --warning:      #d97706;

  /* Brand / accents */
  --violet:       #7857e0;       /* primary accent: all-countries view */
  --violet-soft:  rgba(120, 87, 224, 0.10);
  --violet-ring:  rgba(120, 87, 224, 0.28);

  --dk:           #e5484d;       /* Danish red */
  --dk-soft:      rgba(229, 72, 77, 0.10);
  --dk-ring:      rgba(229, 72, 77, 0.28);

  --fi:           #2f7ce8;       /* Finnish blue */
  --fi-soft:      rgba(47, 124, 232, 0.10);
  --fi-ring:      rgba(47, 124, 232, 0.28);

  --se:           #d97706;       /* Swedish gold */
  --se-soft:      rgba(217, 119, 6, 0.10);
  --se-ring:      rgba(217, 119, 6, 0.28);

  --no:           #0e8a6d;       /* Norwegian fjord teal */
  --no-soft:      rgba(14, 138, 109, 0.10);
  --no-ring:      rgba(14, 138, 109, 0.28);

  /* Active accent (swapped per country) */
  --accent:       var(--violet);
  --accent-soft:  var(--violet-soft);
  --accent-ring:  var(--violet-ring);

  /* Charts — consumed by dashboard/costs/leads JS via getComputedStyle.
     --chart-1..8 is the categorical palette in its validated order. */
  --chart-grid:   rgba(16, 24, 40, 0.06);
  --chart-tick:   #667085;
  --chart-1: #7857e0;
  --chart-2: #d97706;
  --chart-3: #2f7ce8;
  --chart-4: #e5484d;
  --chart-5: #0e9bb5;
  --chart-6: #65a30d;
  --chart-7: #d6409f;
  --chart-8: #12934f;

  /* Type */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --font-display: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Display", Inter, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Shape & motion */
  --radius-sm: 8px;
  --radius:    14px;
  --radius-lg: 18px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow:    0 4px 16px rgba(16, 24, 40, 0.08), 0 1px 3px rgba(16, 24, 40, 0.05);
  --ease:      cubic-bezier(0.22, 0.61, 0.36, 1);
  --t-fast:    .15s var(--ease);
  --t-med:     .25s var(--ease);
}

/* Country-scoped accent overrides. JS toggles these on body. */
body.country-all { --accent: var(--violet); --accent-soft: var(--violet-soft); --accent-ring: var(--violet-ring); }
body.country-dk  { --accent: var(--dk);     --accent-soft: var(--dk-soft);     --accent-ring: var(--dk-ring); }
body.country-fi  { --accent: var(--fi);     --accent-soft: var(--fi-soft);     --accent-ring: var(--fi-ring); }
body.country-se  { --accent: var(--se);     --accent-soft: var(--se-soft);     --accent-ring: var(--se-ring); }
body.country-no  { --accent: var(--no);     --accent-soft: var(--no-soft);     --accent-ring: var(--no-ring); }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  background-image:
    radial-gradient(1200px 800px at 85% -10%, rgba(120, 87, 224, 0.045), transparent 60%),
    radial-gradient(900px 600px at 10% 100%, rgba(47, 124, 232, 0.035), transparent 60%);
  background-attachment: fixed;
  color: var(--text);
  font: 400 15px/1.5 var(--font-sans);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

h1, h2, h3, h4 { margin: 0; font-family: var(--font-display); font-weight: 600; letter-spacing: -0.015em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; color: var(--text); }
h4 { font-size: 13px; color: var(--muted); font-weight: 500; }
p  { margin: 0; }

code {
  font-family: var(--font-mono); background: var(--surface-2);
  padding: 2px 7px; border-radius: 6px; font-size: 12.5px; color: var(--text-2);
}

.muted { color: var(--muted); }
.inline { display: inline; }
.num { text-align: right; font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.up, .pos { color: var(--positive); }
.down, .neg { color: var(--negative); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  font: 500 13.5px var(--font-sans);
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover     { background: var(--surface-3); }
.btn:active    { transform: translateY(1px); }
.btn-primary   { background: var(--accent); color: #fff; font-weight: 600; border-color: transparent; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost     { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(16,24,40,.05); color: var(--text); }
.btn-sm        { padding: 6px 12px; font-size: 12.5px; }
.btn + .btn    { margin-left: 8px; }

/* ============================================================
   Auth page
   ============================================================ */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 32px; }
.auth-card  {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: block; object-fit: contain;
  box-shadow: 0 6px 20px rgba(120, 87, 224, 0.22);
  transition: transform .2s var(--ease), box-shadow .2s var(--ease);
}
.brand-mark:hover { transform: scale(1.04) rotate(-1.5deg); }
.brand-mark.small { width: 30px; height: 30px; border-radius: 9px; box-shadow: 0 3px 10px rgba(120, 87, 224, 0.18); }
.brand-text h1 { font-size: 17px; letter-spacing: -0.02em; }
.brand-text p  { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.auth-form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 500; }
.auth-form input, .auth-form select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 14px; border-radius: var(--radius-sm); font: inherit;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.auth-form input:focus, .auth-form select:focus {
  outline: none; border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.auth-form button { padding: 13px; font-size: 14px; margin-top: 4px; }

.alert       { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px; }
.alert-error { background: var(--negative-soft); color: #b42318; border: 1px solid rgba(217,45,32,0.25); }
.alert-info  { background: var(--violet-soft); color: #5a3fc4; border: 1px solid rgba(120,87,224,0.25); }

.auth-links {
  margin-top: 14px; font-size: 13px; text-align: center; color: var(--muted);
}
.auth-links a { color: var(--accent); text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }
.auth-links .sep { margin: 0 10px; opacity: 0.5; }

/* Role / status pills used in topbar + settings user table */
.role-pill {
  display: inline-block; margin-left: 8px; padding: 2px 8px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; border-radius: 4px; vertical-align: middle;
  background: var(--violet-soft); color: #5a3fc4;
  border: 1px solid rgba(120,87,224,0.28);
}
.role-pill.role-viewer { background: rgba(102,112,133,0.10); color: #475467; border-color: rgba(102,112,133,0.25); }
.status-pill {
  display: inline-block; padding: 2px 8px; font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; border-radius: 4px;
}
.status-pill.status-active   { background: var(--positive-soft); color: #0e7a41; border: 1px solid rgba(18,147,79,0.28); }
.status-pill.status-disabled { background: var(--negative-soft); color: #b42318; border: 1px solid rgba(217,45,32,0.28); }
.status-pill.status-pending  { background: rgba(217,119,6,0.10); color: #b45309; border: 1px solid rgba(217,119,6,0.28); }

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 32px;
  position: sticky; top: 0; z-index: 10;
  background: rgba(252, 252, 253, 0.8);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 20px; }
.nav { display: flex; gap: 2px; }
.nav-link {
  padding: 8px 14px; border-radius: var(--radius-sm);
  text-decoration: none; color: var(--muted);
  font: 500 13.5px var(--font-sans); letter-spacing: -0.005em;
  transition: color var(--t-fast), background var(--t-fast);
}
.nav-link:hover { color: var(--text); background: rgba(16,24,40,.05); text-decoration: none; }
.nav-link.active {
  color: var(--text);
  background: var(--accent-soft);
}

/* ============================================================
   Dashboard shell
   ============================================================ */
.dashboard {
  max-width: 1280px; margin: 0 auto; padding: 32px 32px 64px;
  display: flex; flex-direction: column; gap: 28px;
}

/* ============================================================
   Controls row
   ============================================================ */
.controls {
  display: flex; gap: 28px; flex-wrap: wrap; align-items: flex-end;
  padding: 18px 20px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.control-group { display: flex; flex-direction: column; gap: 6px; }
.control-group label {
  font-size: 11px; color: var(--muted-2); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.control-group select {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 14px; font: 500 13.5px var(--font-sans);
  transition: border-color var(--t-fast), background var(--t-fast);
  min-width: 160px;
}
.control-group select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft);
}
.window-label { margin-left: auto; }
.window-label span { font-family: var(--font-mono); font-size: 13px; color: var(--muted); }

/* ============================================================
   NAM range picker (custom popover) — Linear / Stripe / Mixpanel aesthetic
   ============================================================ */
.rp-trigger {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); padding: 9px 14px 9px 14px;
  border-radius: var(--radius-pill); cursor: pointer;
  font: 500 13.5px var(--font-sans); min-height: 40px;
  transition: border-color var(--t-fast), background var(--t-fast);
  -webkit-tap-highlight-color: transparent;
}
.rp-trigger:hover { border-color: var(--border-strong); }
.rp-trigger[aria-expanded="true"] {
  border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft);
}
.rp-trigger::before {
  content: "";
  width: 14px; height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4M8 2v4M3 10h18'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4M8 2v4M3 10h18'/%3E%3C/svg%3E") center/contain no-repeat;
  color: var(--muted); flex-shrink: 0;
}
.rp-trigger[aria-expanded="true"]::before { color: var(--accent); }

.rp-popover {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(16,24,40,0.14), 0 2px 8px rgba(16,24,40,0.08);
  padding: 14px;
  z-index: 50;
  min-width: 560px;
  max-width: calc(100vw - 32px);
  font: 400 13px var(--font-sans);
  animation: rpFadeIn .12s ease-out;
}
@keyframes rpFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.rp-body { display: flex; gap: 16px; align-items: flex-start; }

.rp-presets {
  display: flex; flex-direction: column; gap: 2px;
  padding-right: 12px; border-right: 1px solid var(--border);
  min-width: 140px;
}
.rp-preset {
  background: transparent; border: 0;
  color: var(--text-2); font: 500 13px var(--font-sans);
  padding: 8px 12px; border-radius: var(--radius-sm);
  cursor: pointer; text-align: left;
  transition: background var(--t-fast), color var(--t-fast);
}
.rp-preset:hover { background: var(--surface-2); color: var(--text); }
.rp-preset.active {
  background: var(--accent-soft); color: var(--text);
  box-shadow: inset 0 0 0 1px var(--accent-ring);
}

.rp-cals-wrap { flex: 1; min-width: 0; }
.rp-cals-head { display: flex; justify-content: space-between; margin-bottom: 4px; }
.rp-nav {
  width: 28px; height: 28px; border-radius: 6px;
  background: transparent; border: 0; cursor: pointer;
  color: var(--muted); font-size: 18px; line-height: 1;
  transition: background var(--t-fast), color var(--t-fast);
}
.rp-nav:hover { background: var(--surface-2); color: var(--text); }

.rp-cals { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.rp-month-head {
  font: 600 13px var(--font-sans); color: var(--text);
  text-align: center; padding: 4px 0 10px;
}
.rp-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px;
}
.rp-weekday {
  text-align: center; font: 500 10.5px var(--font-sans);
  color: var(--muted-2); text-transform: uppercase;
  letter-spacing: 0.06em; padding: 4px 0;
}
.rp-day {
  height: 32px; border: 0; background: transparent;
  color: var(--text); font: 500 12.5px var(--font-sans);
  border-radius: 6px; cursor: pointer; padding: 0;
  transition: background var(--t-fast), color var(--t-fast);
}
.rp-day:hover:not(:disabled) { background: var(--surface-2); }
.rp-day.rp-today { font-weight: 700; color: var(--accent); }
.rp-day.rp-in-range {
  background: var(--accent-soft); border-radius: 0;
  color: var(--text);
}
.rp-day.rp-range-start {
  background: var(--accent); color: #fff; border-radius: 6px 0 0 6px;
}
.rp-day.rp-range-end {
  background: var(--accent); color: #fff; border-radius: 0 6px 6px 0;
}
.rp-day.rp-range-start.rp-range-end { border-radius: 6px; }
.rp-day.rp-empty { visibility: hidden; }

.rp-footer {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
  gap: 12px;
}
.rp-summary {
  font: 400 12px var(--font-sans); color: var(--muted);
  font-variant-numeric: tabular-nums;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rp-actions { display: flex; gap: 8px; }
.rp-btn {
  padding: 7px 14px; border-radius: var(--radius-sm);
  border: 0; font: 500 13px var(--font-sans); cursor: pointer;
  transition: background var(--t-fast), filter var(--t-fast);
}
.rp-btn.rp-clear { background: transparent; color: var(--muted); }
.rp-btn.rp-clear:hover { color: var(--text); background: var(--surface-2); }
.rp-btn.rp-apply { background: var(--accent); color: #fff; font-weight: 600; }
.rp-btn.rp-apply:hover:not(:disabled) { filter: brightness(1.08); }
.rp-btn.rp-apply:disabled { background: var(--surface-3); color: var(--muted-2); cursor: not-allowed; }

@media (max-width: 640px) {
  .rp-popover { min-width: 0; width: calc(100vw - 32px); padding: 10px; }
  .rp-body { flex-direction: column; }
  .rp-presets {
    border-right: 0; border-bottom: 1px solid var(--border);
    padding: 0 0 10px; flex-direction: row; flex-wrap: wrap;
    min-width: 0; gap: 4px;
  }
  .rp-preset { flex: 1 0 auto; padding: 7px 10px; font-size: 12.5px; }
  .rp-cals { grid-template-columns: 1fr; gap: 4px; }
  .rp-day { height: 36px; font-size: 13px; }
}

/* Custom date-range picker — a single integrated pill.
   Uses native OS date UI (best on mobile) styled to match our theme. */
.date-range {
  display: inline-flex; align-items: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-pill); padding: 2px 2px 2px 14px;
  gap: 0; min-width: 0;
  transition: border-color var(--t-fast);
}
.date-range:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.date-range::before {
  content: "";
  display: inline-block;
  width: 14px; height: 14px;
  margin-right: 8px;
  background-color: var(--muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4M8 2v4M3 10h18'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4M8 2v4M3 10h18'/%3E%3C/svg%3E") center/contain no-repeat;
  flex-shrink: 0;
}
.date-range input[type="date"] {
  background: transparent; border: 0; color: var(--text);
  font: 500 13.5px var(--font-sans); padding: 8px 2px;
  color-scheme: light;
  min-width: 130px;
  /* iOS: 16px prevents auto-zoom on focus. We'll override per media below. */
}
.date-range input[type="date"]:focus { outline: none; }
.date-range input[type="date"]::placeholder { color: var(--muted-2); }
.date-range input[type="date"]::-webkit-calendar-picker-indicator {
  filter: none;
  cursor: pointer;
  padding: 2px;
  opacity: 0.7;
  transition: opacity var(--t-fast);
}
.date-range input[type="date"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }
.date-range .date-sep { color: var(--muted-2); padding: 0 4px; user-select: none; font-size: 13px; }
.date-range .date-apply {
  background: var(--accent); color: #fff; border: 0;
  padding: 7px 16px; border-radius: var(--radius-pill);
  font: 600 12.5px var(--font-sans); cursor: pointer;
  margin-left: 6px;
  transition: filter var(--t-fast), opacity var(--t-fast);
}
.date-range .date-apply:hover:not(:disabled) { filter: brightness(1.08); }
.date-range .date-apply:disabled { background: var(--surface-3); color: var(--muted-2); cursor: not-allowed; }
.date-range .date-clear {
  background: transparent; border: 0;
  width: 32px; height: 32px; margin-left: 2px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 17px; line-height: 1; color: var(--muted-2);
  cursor: pointer; border-radius: 50%;
  transition: background var(--t-fast), color var(--t-fast);
}
.date-range .date-clear:hover { background: rgba(16,24,40,.06); color: var(--text); }

/* Segmented — pill style, Lunar/Revolut feel */
.segmented {
  display: inline-flex; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}
.segmented button {
  background: transparent; border: 0; color: var(--muted);
  padding: 7px 16px; font: 500 13px var(--font-sans);
  border-radius: var(--radius-pill); cursor: pointer;
  transition: color var(--t-fast), background var(--t-fast);
  min-width: 42px;
}
.segmented button:hover { color: var(--text); }
.segmented button.active {
  color: #fff; background: var(--accent);
  box-shadow: 0 2px 10px var(--accent-ring);
}

/* ============================================================
   KPI tiles — generous spacing, subtle separators
   ============================================================ */
.kpi-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}
.kpi-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  transition: border-color var(--t-fast), transform var(--t-fast);
  box-shadow: var(--shadow-sm);
}
.kpi-card:hover { border-color: var(--border-strong); }

.kpi-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi-value {
  font: 600 30px/1.1 var(--font-display);
  margin-top: 10px;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.kpi-delta {
  color: var(--muted); font-size: 12.5px; margin-top: 8px; font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.kpi-delta.up   { color: var(--positive); }
.kpi-delta.down { color: var(--negative); }

/* Muted / unallocated card — dashed border, translucent */
.kpi-card-muted {
  background: transparent;
  border-style: dashed;
  border-color: var(--border-strong);
}
.kpi-card-muted .kpi-value { color: var(--muted); }

/* ============================================================
   Insights
   ============================================================ */
.insights {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.insights > h3 {
  margin-bottom: 14px; font-size: 12px; color: var(--muted-2); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
}
.insight-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}
.insight {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.insight-title  { font: 600 13.5px/1.3 var(--font-sans); margin-bottom: 5px; color: var(--text); letter-spacing: -0.005em; }
.insight-detail { font-size: 12.5px; color: var(--muted); line-height: 1.55; }
.insight.severity-positive { border-left-color: var(--positive); }
.insight.severity-warning  { border-left-color: var(--warning); }
.insight.severity-critical { border-left-color: var(--negative); }
.insight.severity-neutral  { border-left-color: var(--accent); }
/* Health-check severities (error/warning/info match the health.py keys). */
.insight.severity-error    { border-left-color: var(--negative); }
.insight.severity-info     { border-left-color: var(--accent); }

/* ============================================================
   Charts & cards
   ============================================================ */
.chart-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  min-width: 0;           /* let grid/flex children shrink to their slot */
  box-shadow: var(--shadow-sm);
}
/* Cards that hold wide data tables (leads, costs, etc.) clip anything that
   can't fit; the tables themselves get a horizontal scrollbar so wide content
   is still reachable without spilling past the card border. */
.table-grid > .card { overflow: hidden; }
.table-grid > .card > .data-table {
  display: block;
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}
.card header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.card header h3 {
  font: 600 14px var(--font-display); color: var(--text-2);
  text-transform: none; letter-spacing: -0.005em;
}
.chart-card-wide { grid-column: 1 / -1; }
.chart-wrap { position: relative; height: 280px; }
.chart-card-wide .chart-wrap { height: 340px; }

/* ============================================================
   Tables
   ============================================================ */
.table-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 16px;
}
.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.data-table th, .data-table td {
  padding: 10px 12px; text-align: left;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table th {
  color: var(--muted-2); font-weight: 500; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.06em; background: transparent;
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.data-table tbody tr { transition: background var(--t-fast); }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table tbody tr.total-row td {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.06em;
}
.data-table tbody tr.total-row:hover td { background: var(--surface-2); }

.chip {
  display: inline-block; padding: 3px 10px; background: var(--surface-2);
  border-radius: var(--radius-pill);
  font: 500 11px var(--font-sans); color: var(--muted);
  font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
}

/* Sortable table headers (click to sort, marked by class .sortable-col) */
.sortable-col { user-select: none; transition: color var(--t-fast); }
.sortable-col:hover { color: var(--text); }
.sortable-col::after {
  content: "";
  display: inline-block;
  margin-left: 6px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted-2);
  opacity: 0.35;
  transition: opacity var(--t-fast), transform var(--t-fast);
  vertical-align: middle;
}
.sortable-col[aria-sort="ascending"]::after { opacity: 1; transform: rotate(180deg); }
.sortable-col[aria-sort="descending"]::after { opacity: 1; }

/* Global notice banner (site-wide reminders) */
#notice-bar {
  position: sticky;
  top: 0; z-index: 15;
  display: flex; flex-direction: column; gap: 1px;
  /* Many simultaneous notices must never swallow the viewport: cap the
     bar and let it scroll internally. */
  max-height: 34vh;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
}
.notice {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: #fdf5e7;
  border-bottom: 1px solid rgba(217, 119, 6, 0.25);
  color: var(--text);
  font: 400 13px/1.5 var(--font-sans);
}
.notice-warning { background: #fdf5e7; border-bottom-color: rgba(217, 119, 6, 0.25); }
.notice-critical { background: #fdefed; border-bottom-color: rgba(217, 45, 32, 0.28); }
.notice-info { background: #f2effc; border-bottom-color: rgba(120, 87, 224, 0.25); }
.notice-body { flex: 1; min-width: 0; }
.notice-title { font-weight: 600; font-size: 13.5px; margin-bottom: 2px; }
.notice-detail { color: var(--muted); font-size: 12.5px; }
.notice-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.notice-dismiss {
  background: none; border: 0; color: var(--muted); font-size: 18px;
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
}
.notice-dismiss:hover { background: rgba(16,24,40,.06); color: var(--text); }
@media (max-width: 640px) {
  .notice { flex-direction: column; align-items: flex-start; padding: 12px 16px; }
  .notice-actions { align-self: stretch; justify-content: space-between; }
}

/* Modal shell (used on /costs for add/edit recurring) */
.modal-shell {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(16, 24, 40, 0.42);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; padding-top: calc(24px + env(safe-area-inset-top));
}
.modal-shell[hidden] { display: none !important; }
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 28px; width: 100%; max-width: 640px;
  max-height: calc(100vh - 48px); overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-card > header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.modal-card h3 { font-size: 16px; }

/* Inline info-dot tooltip.
   The tooltip anchors to the dot itself (position: relative on .info-dot)
   rather than the enclosing row/card, so it appears right next to the icon. */
.tooltip-wrap { position: relative; }   /* legacy selector, still works for table headers */
.info-dot {
  position: relative;                    /* anchors the tooltip to the dot */
  display: inline-block; margin-left: 4px;
  color: var(--muted-2); cursor: help; font-size: 11px;
  vertical-align: middle; font-style: normal; font-weight: 500;
  transition: color var(--t-fast);
}
.info-dot:hover { color: var(--text); }
.info-dot::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px); left: 50%;
  transform: translateX(-50%) translateY(-2px);
  background: var(--surface-3);
  color: var(--text);
  font: 400 12px/1.45 var(--font-sans);
  letter-spacing: 0; text-transform: none;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  width: max-content; max-width: 280px;
  white-space: normal; text-align: left;
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-fast), transform var(--t-fast);
  box-shadow: var(--shadow);
  z-index: 20;
}
.info-dot:hover::after, .info-dot:focus::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
/* Tooltips near the right edge of the viewport get pulled inward to avoid
   being clipped off-screen. */
@media (max-width: 640px) {
  .info-dot::after { max-width: calc(100vw - 48px); }
}

/* Costs page: category cards show a compact vendor list with a "Show all"
   toggle. Marketing card groups vendors by country using a subhead row.
   Using table-layout: auto (the default) + width: 1% on numeric columns is
   the classic "shrink-to-content" trick — numeric columns keep their amounts
   fully visible while the vendor column absorbs remaining width and wraps. */
.vendor-mini { width: 100%; }
.vendor-mini td:first-child, .vendor-mini th:first-child {
  word-break: break-word;  /* long vendor names wrap instead of pushing the card wider */
  white-space: normal;
}
.vendor-mini td.num, .vendor-mini th.num {
  width: 1%;               /* collapses to content size under auto layout */
  white-space: nowrap;     /* keep the amount on one line */
}

.vendor-mini tbody tr.country-subhead th {
  font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted); background: rgba(16,24,40,0.02);
  padding-top: 10px; border-top: 1px solid var(--border);
}
.vendor-mini tbody tr.country-subhead:first-child th { border-top: 0; padding-top: 4px; }
.vendor-mini tbody tr.country-subhead.country-dk th { color: var(--dk); }
.vendor-mini tbody tr.country-subhead.country-fi th { color: var(--fi); }
.vendor-mini tbody tr.country-subhead.country-se th { color: var(--se); }
.vendor-mini tbody tr.country-subhead.country-no th { color: var(--no); }
.vendor-expand-toggle {
  margin-top: 10px; width: 100%; justify-content: center;
  font-size: 11px; letter-spacing: 0.02em;
}
/* Keep cards from being wider than their flex/grid slot — enforces overflow
   clipping inside cost cards so nothing spills beyond the border. */
#category-cards .card { min-width: 0; overflow: hidden; }

/* Leads page: CPL table country/brand subtotal rows. Subtotals visually
   separate groups while the sortable helper still works on leaf rows. */
#cpl-table tbody tr.cpl-subtotal td {
  font-size: 11px; letter-spacing: 0.03em;
  background: rgba(16,24,40,0.025);
  border-top: 1px solid var(--border);
}
#cpl-table tbody tr.cpl-subtotal.country-head td {
  text-transform: uppercase;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  background: rgba(16,24,40,0.045);
}
#cpl-table tbody tr.cpl-subtotal.country-head.country-dk td { color: var(--dk); }
#cpl-table tbody tr.cpl-subtotal.country-head.country-fi td { color: var(--fi); }
#cpl-table tbody tr.cpl-subtotal.country-head.country-se td { color: var(--se); }
#cpl-table tbody tr.cpl-subtotal.country-head.country-no td { color: var(--no); }
#cpl-table tbody tr.cpl-subtotal.brand-head td { color: var(--muted); }

/* ============================================================
   Data entry page
   ============================================================ */
.entry-page {
  max-width: 1200px; margin: 0 auto; padding: 32px 32px 64px;
  display: flex; flex-direction: column; gap: 20px;
}
.tabs {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-pill); align-self: flex-start;
  overflow-x: auto; scrollbar-width: none; flex-wrap: wrap;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: 0; color: var(--muted);
  padding: 9px 18px; cursor: pointer;
  font: 500 13.5px var(--font-sans);
  border-radius: var(--radius-pill);
  transition: color var(--t-fast), background var(--t-fast);
  flex-shrink: 0;
}
.tab:hover { color: var(--text); }
.tab.active { color: #fff; background: var(--accent); box-shadow: 0 2px 10px var(--accent-ring); }

.tab-panel { display: none; flex-direction: column; gap: 18px; }
.tab-panel.active { display: flex; }

.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px; align-items: end;
}
.form-grid label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; color: var(--muted); font-weight: 500;
}
.form-grid .span-2 { grid-column: span 2; }
.form-grid input, .form-grid select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 14px; border-radius: var(--radius-sm); font: inherit;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.form-grid input:focus, .form-grid select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft);
}
.form-grid button { justify-self: start; }

.import-form { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-top: 12px; }
.import-form.form-grid { display: grid; }
.import-form input[type="file"] { color: var(--muted); font: 500 12.5px var(--font-sans); }
.import-form input[type="file"]::file-selector-button {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: var(--radius-sm); margin-right: 12px;
  font: 500 12.5px var(--font-sans); cursor: pointer;
  transition: background var(--t-fast);
}
.import-form input[type="file"]::file-selector-button:hover { background: var(--surface-3); }

.result {
  margin-top: 12px; background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px; font-family: var(--font-mono);
  font-size: 12px; line-height: 1.55; max-height: 280px; overflow: auto;
  white-space: pre-wrap; color: var(--muted);
}
.result.success {
  border-color: rgba(18, 147, 79, 0.45);
  background: rgba(18, 147, 79, 0.06);
  color: var(--text);
}
.result.error {
  border-color: rgba(217, 45, 32, 0.45);
  background: rgba(217, 45, 32, 0.05);
  color: var(--text);
}

/* ============================================================
   iOS safe-area insets (notch / home-bar)
   ============================================================ */
.topbar {
  padding-top: calc(16px + env(safe-area-inset-top));
  padding-left: calc(32px + env(safe-area-inset-left));
  padding-right: calc(32px + env(safe-area-inset-right));
}
.dashboard, .entry-page {
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  padding-left: calc(32px + env(safe-area-inset-left));
  padding-right: calc(32px + env(safe-area-inset-right));
}

/* ============================================================
   Tablet (≤ 960 px)
   ============================================================ */
@media (max-width: 960px) {
  .dashboard, .entry-page { padding-left: 20px; padding-right: 20px; }
  .topbar { padding-left: 20px; padding-right: 20px; }
  .controls { gap: 16px; }
  .window-label { margin-left: 0; width: 100%; }
  .chart-wrap { height: 240px; }
  .chart-card-wide .chart-wrap { height: 280px; }
}

/* ============================================================
   Phone (≤ 640 px)
   ============================================================ */
@media (max-width: 640px) {
  :root {
    --radius: 12px;
    --radius-lg: 14px;
  }

  /* Prevent iOS auto-zoom on focus: inputs must be ≥ 16 px font-size. */
  input, select, textarea,
  .form-grid input, .form-grid select,
  .auth-form input, .auth-form select,
  .date-range input[type="date"] {
    font-size: 16px !important;
  }

  html, body { font-size: 14.5px; }

  /* Topbar compacts to two-line layout so brand+nav fits on one row,
     user info can wrap. */
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom,0)) 16px;
    padding-top: calc(12px + env(safe-area-inset-top));
  }
  .topbar-left, .topbar-right {
    width: 100%;
    gap: 10px;
  }
  .topbar-right { justify-content: space-between; }
  .nav { flex: 1; overflow-x: auto; scrollbar-width: none; gap: 0; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-link {
    padding: 7px 12px;
    font-size: 13px;
    flex-shrink: 0;
    min-height: 36px;
    display: inline-flex; align-items: center;
  }

  /* Dashboard layout */
  .dashboard, .entry-page {
    padding: 16px 14px calc(40px + env(safe-area-inset-bottom)) 14px;
    gap: 16px;
  }

  /* Controls: each group on its own row, full width */
  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding: 14px;
    border-radius: var(--radius);
  }
  .control-group { width: 100%; }
  .control-group select { width: 100%; min-width: 0; padding: 12px 14px; min-height: 44px; }

  /* Segmented period pills should span full width with flexible widths */
  .segmented { width: 100%; display: flex; }
  .segmented button { flex: 1; padding: 10px 0; min-height: 40px; }

  /* Date range pill on its own line */
  .date-range {
    width: 100%;
    border-radius: var(--radius);
    padding: 6px 8px 6px 14px;
    flex-wrap: wrap;
    gap: 4px;
  }
  .date-range input[type="date"] {
    flex: 1 1 auto;
    min-width: 0;
    padding: 10px 6px;
    min-height: 40px;
  }
  .date-range .date-apply {
    flex-shrink: 0;
    min-height: 36px;
    padding: 8px 16px;
  }

  .window-label span { font-size: 12px; }

  /* KPI grid: 2 columns on phones, not 1 */
  .kpi-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .kpi-card { padding: 14px 14px; }
  .kpi-label { font-size: 11.5px; }
  .kpi-value { font-size: 22px; margin-top: 4px; }
  .kpi-delta { font-size: 11.5px; margin-top: 4px; }

  /* Chart heights */
  .chart-wrap { height: 220px; }
  .chart-card-wide .chart-wrap { height: 260px; }
  .chart-grid, .table-grid { gap: 10px; }
  .card { padding: 14px 16px; border-radius: var(--radius); }
  .card header h3 { font-size: 13px; }

  /* Insights */
  .insights { padding: 14px; }
  .insight { padding: 12px 14px; }
  .insight-title { font-size: 13px; }
  .insight-detail { font-size: 12px; }

  /* Tables — horizontal scroll instead of squeezing */
  .data-table { font-size: 12.5px; }
  .card > .data-table,
  .card .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .data-table th, .data-table td { padding: 9px 10px; }

  /* Entry page: tab pill row scrolls horizontally, larger touch targets */
  .tabs {
    width: 100%;
    overflow-x: auto; scrollbar-width: none;
    flex-wrap: nowrap;
    padding: 4px;
  }
  .tab {
    padding: 10px 16px;
    font-size: 13.5px;
    min-height: 40px;
    flex-shrink: 0;
  }

  /* Forms full-width, 1 column */
  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .form-grid .span-2 { grid-column: span 1; }
  .form-grid input, .form-grid select { padding: 12px 14px; min-height: 44px; border-radius: var(--radius-sm); }
  .form-grid button { width: 100%; justify-self: stretch; padding: 13px; }

  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; }

  /* Auth page */
  .auth-card { padding: 24px 22px; }
  .auth-form input { padding: 13px 14px; min-height: 46px; }
  .auth-form button { padding: 14px; min-height: 48px; }
}

/* ============================================================
   Small phone (≤ 380 px) — tighten further
   ============================================================ */
@media (max-width: 380px) {
  .kpi-row { grid-template-columns: 1fr; }
  .kpi-value { font-size: 24px; }
  .nav-link { padding: 6px 9px; font-size: 12px; }
  .control-group label { font-size: 10px; }
}
