/* ============================================================================
   Meridian — Design System
   Warm paper canvas, near-black indigo ink, one electric-violet accent.
   Mobile-first responsive; sidebar becomes an overlay drawer under 1024px.
   ============================================================================ */

:root {
  --paper:       #f7f7f4;
  --surface:     #ffffff;
  --surface-2:   #fbfbf9;
  --ink:         #14152b;
  --ink-2:       #4a4c66;
  --ink-3:       #8a8ca3;
  --hairline:    #e8e8e2;

  --accent:      #5b34ff;
  --accent-soft: #efeaff;
  --accent-ink:  #3d1fd6;

  --up:          #0f9d63;
  --up-soft:     #e4f6ee;
  --down:        #d9463c;
  --down-soft:   #fdeceb;
  --warn:        #b7791f;
  --warn-soft:   #fdf4e3;

  --google:      #1a73e8;
  --facebook:    #f5a05a;
  --ga4:         #e8710a;
  --ahrefs:      #ff5b35;

  --radius:      14px;
  --radius-sm:   10px;
  --shadow-sm:   0 1px 2px rgba(20,21,43,.04), 0 1px 3px rgba(20,21,43,.06);
  --shadow-md:   0 4px 16px rgba(20,21,43,.06), 0 2px 4px rgba(20,21,43,.04);
  --shadow-lg:   0 12px 40px rgba(20,21,43,.10);

  --sidebar-w:   256px;
  --topbar-h:    64px;

  /* Surfaces that stay dark-on-light / light-on-dark (brand mark, primary
     button, avatars). Defined separately so dark mode can invert them. */
  --inverse-bg:    #14152b;
  --inverse-bg-h:  #23243f;
  --inverse-ink:   #ffffff;
  --topbar-bg:     rgba(247,247,244,.88);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'cv02','cv03','cv04','ss01';
}

img, svg, video { max-width: 100%; }

.font-display { font-family: 'Fraunces', Georgia, serif; font-optical-sizing: auto; letter-spacing: -.01em; }
.tnum { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }

/* Inputs must be able to shrink inside grids (prevents horizontal overflow). */
.input, .select, textarea.input, select, input { min-width: 0; max-width: 100%; }

/* ----------------------------------------------------------------------------
   Shell
   ---------------------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; max-width: 100%; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  /* Make room for the fixed sidebar. Removed at the drawer breakpoint. */
  margin-left: var(--sidebar-w);
}

.content {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 26px 32px 72px;
}

/* ----------------------------------------------------------------------------
   Sidebar
   ---------------------------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--hairline);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  /* Fixed (not sticky) so it always fills the viewport, no matter how long
     the page content is. .main is offset by the same width below. */
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  z-index: 60;
}

.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px 18px; }

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  background: var(--inverse-bg); color: var(--inverse-ink);
  display: grid; place-items: center;
  font-family: 'Fraunces', serif; font-weight: 600; font-size: 18px;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--ink-3); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Desktop: the close (X) button collapses the sidebar entirely. */
.sidebar-close { display: grid; }

body.sidebar-collapsed .sidebar { display: none; }
body.sidebar-collapsed .main { margin-left: 0; }

.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-3); padding: 14px 10px 6px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 11px; border-radius: 9px;
  color: var(--ink-2); text-decoration: none;
  font-size: 14px; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.nav-item.active svg { color: var(--accent); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--ink-3); }

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--hairline); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 6px 10px; min-width: 0; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 650; font-size: 13px;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-name, .user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-name { font-size: 13px; font-weight: 600; }
.user-email { font-size: 11px; color: var(--ink-3); }

.sidebar-overlay {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(20,21,43,.42);
  backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden;
  transition: opacity .2s, visibility .2s;
}
body.sidebar-open .sidebar-overlay { opacity: 1; visibility: visible; }

/* ----------------------------------------------------------------------------
   Topbar
   ---------------------------------------------------------------------------- */
.topbar {
  min-height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 12px 28px;
  border-bottom: 1px solid var(--hairline);
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 30;
  flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; }
.topbar-left h1 {
  font-size: 18px; font-weight: 650; letter-spacing: -.015em; margin: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

.icon-btn {
  display: grid; place-items: center;
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 10px; border: 1px solid var(--hairline);
  background: var(--surface); color: var(--ink-2); cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 19px; height: 19px; }
.menu-btn { display: none; }
/* When the desktop sidebar is collapsed, the hamburger reappears to reopen it. */
body.sidebar-collapsed .menu-btn { display: grid; }

/* ----------------------------------------------------------------------------
   Cards / stats
   ---------------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--hairline); flex-wrap: wrap; }
.card-title { font-size: 14.5px; font-weight: 650; letter-spacing: -.01em; }
.card-sub { font-size: 12.5px; color: var(--ink-3); margin: 2px 0 0; }

.stat {
  position: relative; min-width: 0;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm);
  transition: box-shadow .18s, transform .18s;
}
.stat:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-label { font-size: 11.5px; color: var(--ink-3); font-weight: 550; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 28px; line-height: 1.08; font-weight: 600; margin-top: 9px; letter-spacing: -.02em; word-break: break-word; }
.stat-value.font-display { font-weight: 550; }
.stat-foot { margin-top: 8px; display: flex; align-items: center; gap: 8px; font-size: 12.5px; flex-wrap: wrap; color: var(--ink-3); }
.stat-icon { position: absolute; top: 16px; right: 16px; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; }
.stat-icon svg { width: 17px; height: 17px; }
.stat-sm { padding: 14px 16px; }
.stat-sm .stat-label { font-size: 11px; }
.stat-sm .stat-value { font-size: 20px; font-weight: 650; margin-top: 6px; letter-spacing: -.01em; }

/* ----------------------------------------------------------------------------
   Chips / badges
   ---------------------------------------------------------------------------- */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.4; }
.chip svg { width: 13px; height: 13px; }
.chip-up { background: var(--up-soft); color: var(--up); }
.chip-down { background: var(--down-soft); color: var(--down); }
.chip-flat { background: var(--surface-2); color: var(--ink-3); }
.chip-new { background: var(--accent-soft); color: var(--accent-ink); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 7px; font-size: 11.5px; font-weight: 600; }
.badge-active, .badge-sent, .badge-live { background: var(--up-soft); color: var(--up); }
.badge-paused, .badge-draft { background: var(--surface-2); color: var(--ink-3); }
.badge-demo { background: var(--warn-soft); color: var(--warn); }
.badge-synced { background: var(--accent-soft); color: var(--accent-ink); }

.platform-tag { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; }
.platform-dot { width: 8px; height: 8px; border-radius: 3px; flex-shrink: 0; display: inline-block; }
.dot-google { background: var(--google); }
.dot-facebook { background: var(--facebook); }
.dot-ga4 { background: var(--ga4); }
.dot-ahrefs { background: var(--ahrefs); }

/* ----------------------------------------------------------------------------
   Buttons
   ---------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 15px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; font-family: inherit;
  cursor: pointer; border: 1px solid transparent; text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary { background: var(--inverse-bg); color: var(--inverse-ink); }
.btn-primary:hover { background: var(--inverse-bg-h); }
.btn-accent { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(91,52,255,.28); }
.btn-accent:hover { background: var(--accent-ink); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--hairline); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--down-soft); color: var(--down); }
.btn-danger:hover { background: var(--down-soft); filter: brightness(.95); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ----------------------------------------------------------------------------
   Tables
   ---------------------------------------------------------------------------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; min-width: 560px; }
.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); font-weight: 600; padding: 12px 20px;
  border-bottom: 1px solid var(--hairline); white-space: nowrap;
}
.tbl th.right, .tbl td.right { text-align: right; }
.tbl td { padding: 14px 20px; font-size: 13.5px; border-bottom: 1px solid var(--hairline); color: var(--ink-2); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .strong { color: var(--ink); font-weight: 600; }
.tbl a.row-link { color: inherit; text-decoration: none; }
.cell-title { display: block; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-sub { font-size: 11.5px; color: var(--ink-3); }

/* ----------------------------------------------------------------------------
   Forms
   ---------------------------------------------------------------------------- */
.field { margin-bottom: 16px; min-width: 0; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field .hint { font-size: 11.5px; color: var(--ink-3); font-weight: 400; margin-top: 5px; }
.field .error { font-size: 11.5px; color: var(--down); font-weight: 500; margin-top: 5px; }
.input, .select, textarea.input {
  width: 100%; padding: 10px 13px;
  border: 1px solid var(--hairline); border-radius: 10px;
  font-size: 14px; color: var(--ink); background: var(--surface);
  font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, textarea.input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.input.is-invalid { border-color: var(--down); }
textarea.input { resize: vertical; }
.input-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.field-set { color: var(--up); font-weight: 600; }

/* Responsive form grid — collapses to one column on small screens. */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid.cols-1 { grid-template-columns: minmax(0, 1fr); }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ----------------------------------------------------------------------------
   Layout helpers
   ---------------------------------------------------------------------------- */
.grid-kpi { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.split-even { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.split-wide { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; }
.split-narrow { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 16px; }
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); font-weight: 650; margin: 30px 0 12px; display: flex; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

/* ----------------------------------------------------------------------------
   Ribbon (report hero)
   ---------------------------------------------------------------------------- */
.ribbon {
  background: linear-gradient(135deg, #14152b 0%, #2a2456 55%, #3d2a8f 100%);
  border-radius: 18px; padding: 26px 28px; color: #fff;
  position: relative; overflow: hidden;
}
.ribbon::after {
  content: ''; position: absolute; right: -40px; top: -60px;
  width: 260px; height: 260px; border-radius: 50%;
  background: radial-gradient(circle, rgba(91,52,255,.55), transparent 70%);
}
.ribbon-inner { position: relative; z-index: 1; display: flex; justify-content: space-between; align-items: flex-end; gap: 22px; flex-wrap: wrap; }
.ribbon-eyebrow { font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; color: rgba(255,255,255,.62); font-weight: 600; }
.ribbon h2 { font-size: 26px; margin: 6px 0 0; font-weight: 600; letter-spacing: -.02em; }
.ribbon-sub { color: rgba(255,255,255,.7); font-size: 14px; margin-top: 5px; }
.ribbon-stats { display: flex; gap: 26px; flex-wrap: wrap; }
.ribbon-stat-label { font-size: 11.5px; color: rgba(255,255,255,.6); text-transform: uppercase; letter-spacing: .06em; }
.ribbon-stat-value { font-size: 26px; font-weight: 600; margin-top: 2px; }

/* ----------------------------------------------------------------------------
   Flash / empty / meter
   ---------------------------------------------------------------------------- */
.flash {
  padding: 12px 16px; border-radius: 11px; font-size: 13.5px; font-weight: 500;
  margin-bottom: 18px; display: flex; align-items: center; gap: 9px; border: 1px solid;
}
.flash svg { width: 17px; height: 17px; flex-shrink: 0; }
.flash-ok { background: var(--up-soft); border-color: var(--up); color: var(--up); }
.flash-error { background: var(--down-soft); border-color: var(--down); color: var(--down); }

.empty { text-align: center; padding: 46px 22px; color: var(--ink-3); }
.empty-icon { width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 14px; background: var(--surface-2); display: grid; place-items: center; }
.empty-icon svg { width: 24px; height: 24px; color: var(--ink-3); }
.empty-title { font-weight: 600; color: var(--ink-2); margin: 0 0 4px; }
.empty p { margin: 0 0 16px; }

.meter { height: 8px; border-radius: 999px; background: var(--hairline); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 999px; }

.chart-box { position: relative; width: 100%; }

/* ----------------------------------------------------------------------------
   Website switcher
   ---------------------------------------------------------------------------- */
.site-switch { position: relative; }
.site-switch-btn {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 8px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--hairline);
  font-size: 13.5px; font-weight: 600; font-family: inherit; color: var(--ink);
  cursor: pointer; min-width: 190px; transition: border-color .15s, box-shadow .15s;
}
.site-switch-btn:hover { border-color: #d8d8d0; }
.site-switch.open .site-switch-btn { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.site-switch-btn > svg { width: 14px; height: 14px; margin-left: auto; color: var(--ink-3); transition: transform .18s; }
.site-switch.open .site-switch-btn > svg { transform: rotate(180deg); }
.site-switch-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.site-switch-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--up); flex-shrink: 0; display: inline-block; }
.site-switch-dot.is-all { background: var(--accent); }
.site-switch-dot.is-paused { background: var(--ink-3); }

.site-switch-menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 288px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 13px; box-shadow: var(--shadow-lg); padding: 6px;
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: opacity .16s, transform .16s, visibility .16s; z-index: 50;
}
.site-switch.open .site-switch-menu { opacity: 1; visibility: visible; transform: none; }
.site-switch-scroll { max-height: 320px; overflow-y: auto; }
.site-switch-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; border: none; background: none; cursor: pointer;
  border-radius: 9px; font-size: 13.5px; font-weight: 500; font-family: inherit;
  color: var(--ink-2); text-align: left; transition: background .12s;
}
.site-switch-item:hover { background: var(--surface-2); color: var(--ink); }
.site-switch-item.is-active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.site-switch-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-switch-check { width: 15px; height: 15px; color: var(--accent); flex-shrink: 0; }
.site-switch-empty { padding: 14px 12px; margin: 0; font-size: 13px; color: var(--ink-3); text-align: center; }
.site-switch-add {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  margin-top: 6px; padding: 10px; border-top: 1px solid var(--hairline);
  color: var(--accent-ink); font-size: 13px; font-weight: 650;
  text-decoration: none; border-radius: 9px;
}
.site-switch-add:hover { background: var(--accent-soft); }
.site-switch-add svg { width: 15px; height: 15px; }

/* ----------------------------------------------------------------------------
   Login
   ---------------------------------------------------------------------------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 500px at 50% -20%, var(--accent-soft), transparent), var(--paper);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--hairline); border-radius: 18px;
  box-shadow: var(--shadow-lg); padding: 32px 30px;
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

/* Laptop: pull the fixed right rail into a single column. */
@media (max-width: 1180px) {
  .split { grid-template-columns: minmax(0, 1fr); }
}

/* Tablet: sidebar becomes an off-canvas drawer. */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    height: 100dvh; width: min(290px, 84vw);
    transform: translateX(-100%);
    transition: transform .24s cubic-bezier(.4,0,.2,1);
    box-shadow: var(--shadow-lg);
  }
  body.sidebar-open .sidebar { transform: none; }
  .sidebar-close { display: grid; }
  .menu-btn { display: grid; }

  /* Drawer overlays the page — no offset needed. */
  .main { margin-left: 0; }

  .split-even, .split-wide, .split-narrow { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }

  .content { padding: 22px 20px 64px; }
  .topbar { padding: 12px 20px; }

  /* Prevent background scroll while the drawer is open. */
  body.sidebar-open { overflow: hidden; }
}

/* Phone */
@media (max-width: 640px) {
  .content { padding: 18px 14px 56px; }
  .topbar { padding: 10px 14px; gap: 10px; }
  .topbar-left h1 { font-size: 16px; }

  .card-pad { padding: 16px; }
  .card-head { padding: 14px 16px; }
  .tbl th, .tbl td { padding: 12px 14px; }

  .grid-kpi { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
  .grid-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

  .stat { padding: 15px 16px; }
  .stat-value { font-size: 24px; }

  .ribbon { padding: 20px 18px; border-radius: 14px; }
  .ribbon h2 { font-size: 21px; }
  .ribbon-stats { gap: 18px; }
  .ribbon-stat-value { font-size: 21px; }

  .site-switch-btn { min-width: 0; padding: 8px 10px; }
  .site-switch-label { max-width: 88px; }

  /* Full-width buttons read better on narrow screens. */
  .form-actions .btn { flex: 1 1 auto; }
}

@media (max-width: 400px) {
  .grid-metrics { grid-template-columns: minmax(0, 1fr); }
  .site-switch-label { max-width: 62px; }
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ----------------------------------------------------------------------------
   Stat card alert states (portfolio dashboard)
   ---------------------------------------------------------------------------- */
.stat-alert {
  border-color: var(--down);
  background: var(--surface);
  box-shadow: inset 0 2px 0 0 var(--down-soft);
}
.stat-warn {
  border-color: var(--warn);
  background: var(--surface);
  box-shadow: inset 0 2px 0 0 var(--warn-soft);
}
.badge-alert { background: var(--down-soft); color: var(--down); }

/* ----------------------------------------------------------------------------
   Filter bar (websites list)
   ---------------------------------------------------------------------------- */
.filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-bottom: 18px;
}
.filter-search {
  position: relative; flex: 1 1 260px; min-width: 0;
}
.filter-search svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--ink-3); pointer-events: none;
}
.filter-search input {
  width: 100%; padding: 9px 13px 9px 36px;
  border: 1px solid var(--hairline); border-radius: 10px;
  font-size: 13.5px; font-family: inherit; color: var(--ink);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.filter-search input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.filter-select {
  width: auto; min-width: 150px; padding: 9px 12px;
  font-size: 13.5px; border-radius: 10px;
}

/* Pagination */
.pagination-wrap {
  padding: 14px 20px; border-top: 1px solid var(--hairline);
  font-size: 13px;
}
.pagination-wrap nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pagination-wrap svg { width: 16px; height: 16px; }
.pagination-wrap a, .pagination-wrap span[aria-current] > span, .pagination-wrap span > span {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 9px; margin: 0 2px;
  border-radius: 8px; text-decoration: none; font-weight: 600;
  color: var(--ink-2); border: 1px solid var(--hairline); background: var(--surface);
}
.pagination-wrap a:hover { background: var(--surface-2); color: var(--ink); }
.pagination-wrap [aria-current="page"] > span {
  background: var(--accent-soft); color: var(--accent-ink); border-color: transparent;
}
.pagination-wrap .cursor-not-allowed > span,
.pagination-wrap [aria-disabled="true"] > span {
  opacity: .45;
}
.pagination-wrap p { color: var(--ink-3); margin: 0; }

@media (max-width: 640px) {
  .filter-select { flex: 1 1 100%; min-width: 0; }
  .filter-bar .btn { flex: 1 1 auto; }
}

/* ----------------------------------------------------------------------------
   Report comparison bar
   ---------------------------------------------------------------------------- */
.compare-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius);
}
.compare-label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.compare-bar .select { width: auto; min-width: 180px; }
.compare-hint { font-size: 12.5px; color: var(--ink-3); margin-left: auto; }
.compare-prev { color: var(--ink-3); font-size: 12px; }

@media (max-width: 640px) {
  .compare-bar .select { flex: 1 1 100%; }
  .compare-hint { margin-left: 0; width: 100%; }
}

/* Delta chip inside small metric cards */
.stat-delta { margin-top: 6px; }
.stat-sm .stat-delta .chip { font-size: 11px; padding: 1px 6px; }

/* ----------------------------------------------------------------------------
   Permission matrix (user form)
   ---------------------------------------------------------------------------- */
.perm-row {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px; border-radius: 9px; font-size: 13px;
  border: 1px solid var(--hairline); background: var(--surface-2);
  color: var(--ink-3); transition: all .15s;
}
.perm-check {
  width: 16px; height: 16px; border-radius: 5px; flex-shrink: 0;
  border: 1.5px solid var(--ink-3); position: relative;
}
.perm-row.perm-on { border-color: #c4ead8; background: var(--up-soft); color: var(--up); font-weight: 600; }
.perm-row.perm-on .perm-check { border-color: var(--up); background: var(--up); }
.perm-row.perm-on .perm-check::after {
  content: ''; position: absolute; left: 4px; top: 1px;
  width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.perm-row.perm-off { opacity: .6; }

/* Year-grouped compare dropdown */
.compare-bar select optgroup {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-3); font-weight: 650; background: var(--surface-2);
}
.compare-bar select option {
  font-size: 13.5px; text-transform: none; letter-spacing: 0;
  color: var(--ink); font-weight: 400; padding: 4px 0;
}

/* ----------------------------------------------------------------------------
   Comparison "from" value
   ---------------------------------------------------------------------------- */
.delta-from { font-size: 11px; color: var(--ink-3); margin-left: 6px; }

/* ----------------------------------------------------------------------------
   Dark theme
   ---------------------------------------------------------------------------- */
html[data-theme="dark"] {
  --paper:       #101018;
  --surface:     #181822;
  --surface-2:   #1f1f2b;
  --ink:         #ececf2;
  --ink-2:       #b4b4c4;
  --ink-3:       #7c7c90;
  --hairline:    #2a2a38;

  --accent:      #8b6bff;
  --accent-soft: #241d4a;
  --accent-ink:  #a892ff;

  --up:          #34d399;
  --up-soft:     #10291f;
  --down:        #f87171;
  --down-soft:   #2e1717;
  --warn:        #fbbf24;
  --warn-soft:   #2b2110;

  --google:      #6ba5f0;
  --facebook:    #f5a05a;
  --ga4:         #f5a05a;
  --ahrefs:      #ff8566;

  --shadow-sm:   0 1px 2px rgba(0,0,0,.3), 0 1px 3px rgba(0,0,0,.2);
  --shadow-md:   0 4px 16px rgba(0,0,0,.35), 0 2px 4px rgba(0,0,0,.25);
  --shadow-lg:   0 12px 40px rgba(0,0,0,.45);

  /* In dark mode these become light surfaces with dark text. */
  --inverse-bg:    #2f3050;
  --inverse-bg-h:  #3b3c63;
  --inverse-ink:   #f2f2f8;
  --topbar-bg:     rgba(16,16,24,.88);

  color-scheme: dark;
}

/* Colour transitions on theme change. */
body, .card, .stat, .sidebar, .topbar, .tbl, .input, .select, .btn, .badge {
  transition: background-color .35s ease, border-color .35s ease, color .35s ease;
}
@media (prefers-reduced-motion: reduce) {
  body, .card, .stat, .sidebar, .topbar, .tbl, .input, .select, .btn, .badge {
    transition: none;
  }
}

/* ----------------------------------------------------------------------------
   Theme toggle button (sun <-> moon morph)
   ---------------------------------------------------------------------------- */
.theme-toggle {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  border: 1px solid var(--hairline); background: var(--surface);
  color: var(--ink-2); cursor: pointer; display: grid; place-items: center;
  position: relative; overflow: hidden; padding: 0;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--ink); }
.theme-toggle svg { width: 19px; height: 19px; grid-area: 1 / 1; }

/* Sun: visible in light mode. Moon: visible in dark mode. */
.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  transition: transform .45s cubic-bezier(.4, 0, .2, 1), opacity .3s ease;
}
.theme-toggle .icon-sun  { transform: rotate(0deg) scale(1); opacity: 1; }
.theme-toggle .icon-moon { transform: rotate(-90deg) scale(.4); opacity: 0; }

html[data-theme="dark"] .theme-toggle .icon-sun  { transform: rotate(90deg) scale(.4); opacity: 0; }
html[data-theme="dark"] .theme-toggle .icon-moon { transform: rotate(0deg) scale(1); opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .theme-toggle .icon-sun, .theme-toggle .icon-moon { transition: opacity .15s ease; }
}

/* View Transition API: circular wipe from the toggle button. */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) { z-index: 2; }

/* ----------------------------------------------------------------------------
   Confirmation modal
   ---------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center; padding: 20px;
  background: rgba(10, 10, 18, .55);
  backdrop-filter: blur(3px);
  opacity: 0; visibility: hidden;
  transition: opacity .2s ease, visibility .2s ease;
}
.modal-backdrop.is-open { opacity: 1; visibility: visible; }

.modal {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 26px 24px 20px;
  text-align: center;
  transform: translateY(10px) scale(.97);
  transition: transform .22s cubic-bezier(.4, 0, .2, 1);
}
.modal-backdrop.is-open .modal { transform: translateY(0) scale(1); }

.modal-icon {
  width: 46px; height: 46px; border-radius: 50%;
  margin: 0 auto 14px;
  display: grid; place-items: center;
  background: var(--down-soft); color: var(--down);
}
.modal-icon svg { width: 23px; height: 23px; }

.modal-title {
  margin: 0 0 7px; font-size: 17px; font-weight: 650;
  color: var(--ink); letter-spacing: -.01em;
}
.modal-body {
  margin: 0 0 20px; font-size: 13.5px; line-height: 1.55; color: var(--ink-2);
}
.modal-actions {
  display: flex; gap: 9px; justify-content: center;
}
.modal-actions .btn { min-width: 104px; justify-content: center; }

body.modal-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  .modal-backdrop, .modal { transition: none; }
}
@media (max-width: 480px) {
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
}

/* ----------------------------------------------------------------------------
   Leads
   ---------------------------------------------------------------------------- */
.lead-tabs {
  display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px;
  border-bottom: 1px solid var(--hairline); padding-bottom: 0;
}
.lead-tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px; font-size: 13.5px; font-weight: 550;
  color: var(--ink-3); text-decoration: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}
.lead-tab:hover { color: var(--ink-2); }
.lead-tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.lead-tab-count {
  font-size: 11.5px; font-weight: 650; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-3);
}
.lead-tab.is-active .lead-tab-count { background: var(--accent-soft); color: var(--accent-ink); }

.lead-detail > td { background: var(--surface-2); padding: 0 !important; }
.lead-detail-inner {
  display: grid; grid-template-columns: 1fr 300px; gap: 24px;
  padding: 18px 20px; border-top: 1px solid var(--hairline);
}
.lead-form { border-left: 1px solid var(--hairline); padding-left: 20px; }
.lbl-sm {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-3); font-weight: 650; display: block; margin-bottom: 3px;
}
.lead-meta { display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; color: var(--ink-2); }
.lead-meta .lbl-sm { display: inline; margin-right: 6px; }

.webhook-row { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.webhook-url {
  flex: 1 1 300px; min-width: 0; overflow-x: auto; white-space: nowrap;
  padding: 9px 12px; border-radius: 9px;
  background: var(--surface-2); border: 1px solid var(--hairline);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px; color: var(--ink-2);
}

@media (max-width: 860px) {
  .lead-detail-inner { grid-template-columns: 1fr; }
  .lead-form { border-left: 0; border-top: 1px solid var(--hairline); padding-left: 0; padding-top: 16px; }
}

/* Dashboard leads summary card */
.lead-summary {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-bottom: 22px; text-decoration: none; color: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.lead-summary:hover { border-color: var(--accent); box-shadow: var(--shadow-md); }
.lead-summary-arrow {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.lead-summary-arrow svg { width: 18px; height: 18px; }

/* Divider between the Viewing and Compare-to selectors */
.compare-divider {
  width: 1px; height: 22px; background: var(--hairline); margin: 0 4px;
}
@media (max-width: 700px) {
  .compare-divider { display: none; }
}

/* Location assignment checkboxes (user form) */
.loc-check {
  display: flex; align-items: center; gap: 9px; cursor: pointer;
  padding: 9px 12px; border-radius: 9px; font-size: 13px;
  border: 1px solid var(--hairline); background: var(--surface-2);
  color: var(--ink-2); transition: all .15s;
}
.loc-check:hover { border-color: var(--accent); }
.loc-check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.loc-check:has(input:checked) {
  border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); font-weight: 600;
}

/* ----------------------------------------------------------------------------
   Report page
   ---------------------------------------------------------------------------- */
.back-link {
  font-size: 13px; color: var(--ink-3); text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; margin-bottom: 16px;
}
.back-link:hover { color: var(--ink-2); }

.ribbon-title { margin: 4px 0 2px; font-size: 26px; font-weight: 600; letter-spacing: -.02em; }

.health-score { font-size: 42px; font-weight: 600; margin: 8px 0 6px; }
.health-breakdown { display: flex; justify-content: space-around; margin-top: 16px; }
.health-count { font-weight: 650; font-size: 16px; }
.health-label { font-size: 11px; color: var(--ink-3); }

.test-send-form {
  display: flex; gap: 9px; flex-wrap: wrap; align-items: flex-start;
}

/* ----------------------------------------------------------------------------
   Mobile topbar — two tidy rows (mobile only, desktop untouched)

   .topbar-right has three direct children: the site switcher, the page action
   button(s) from @yield('topbar'), and the theme toggle. On narrow screens we
   lay them out as:
     Row 1: site switcher (full width — its label matters)
     Row 2: action button(s) + theme toggle, sharing the row
   ---------------------------------------------------------------------------- */
@media (max-width: 720px) {
  .topbar {
    align-items: center;
    flex-wrap: wrap;
    row-gap: 10px;
  }

  /* Row 1: Back · Home · title · (auto gap) · theme toggle · hamburger.
     Everything lives in .topbar-left, so they naturally share one line. */
  .topbar-left {
    flex: 1 1 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    order: 1;
  }
  .topbar-left .nav-back,
  .topbar-left .nav-home { flex: 0 0 auto; }
  .topbar-left h1 {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Show the mobile theme toggle and push it (plus the hamburger after it) to
     the far right of row 1. */
  .topbar-left .theme-toggle-left {
    display: grid;
    flex: 0 0 auto;
    margin-left: auto;   /* everything from here is shoved right */
  }
  .topbar-left .menu-btn {
    display: grid;
    flex: 0 0 auto;
  }

  /* Row 2+: the right container. Its own theme toggle is hidden on mobile. */
  .topbar-right {
    order: 2;
    flex: 1 1 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-start;
  }
  .topbar-right .theme-toggle-right { display: none; }

  /* Site switcher spans its own full row. */
  .topbar-right .site-switch {
    order: 1;
    flex: 1 1 100%;
  }
  .topbar-right .site-switch-btn { width: 100%; }
  .site-switch-label { max-width: none; }

  /* Page action buttons share the next row. */
  .topbar-right .btn {
    order: 2;
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
    padding: 10px 12px;
  }

  /* Theme toggle keeps its fixed square and sits at the end of row 2. */
  .topbar-right .theme-toggle {
    order: 3;
    flex: 0 0 auto;
  }
}

/* Dropdown becomes a screen-anchored panel so it never spills off-screen
   or crowds the cards behind it. */
@media (max-width: 720px) {
  .site-switch-menu {
    position: fixed;
    top: auto;
    left: 14px;
    right: 14px;
    width: auto;
    max-width: none;
    margin-top: 8px;
  }
  .site-switch-scroll { max-height: 60vh; }
}


.match-note { color: var(--ink-3); font-style: italic; }

.trend-note {
    display: block;
    font-size: 11px;
    line-height: 1.35;
    color: var(--ink-3);
    margin-top: 4px;
}
.trend-note.is-good { color: var(--up); }
.trend-note.is-bad  { color: var(--down); }
.trend-note.is-warn { color: var(--warn); }


/* Topbar Home + Back buttons */
.nav-back, .nav-home { display: grid; flex-shrink: 0; }
.nav-home svg, .nav-back svg { width: 18px; height: 18px; }
@media (max-width: 640px) { .nav-back, .nav-home { width: 36px; height: 36px; } }

.theme-toggle-left { display: none; }
