/* ============================================================
   SampleFlux — app.css  |  Production Design System v2
   Typefaces: DM Sans (body) · DM Mono (code/data)
   Google Fonts loaded via @import below.
   Audited & improved: layout, spacing, typography, responsive,
   sidebar, topbar, cards, tables, forms, buttons, loaders.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;0,9..40,800;1,9..40,400&family=DM+Mono:ital,wght@0,400;0,500;1,400&display=swap');


/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  /* Layout */
  --sidebar-expanded: 284px;
  --sidebar-collapsed: 72px;
  --shell-motion: 240ms cubic-bezier(.4, 0, .2, 1);
  --topbar-h: 68px;

  /* Surfaces */
  --bg: #F2F4F8;
  --panel: #FFFFFF;
  --panel-alt: #FAFBFF;
  --line: #E2E6F0;
  --line-soft: #EDF0F8;

  /* Text */
  --text: #141928;
  --text-2: #3C4462;
  --muted: #6E7898;
  --muted-2: #9AA3C0;

  /* Navigation */
  --nav: #141928;
  --nav-2: #1B2240;
  --navText: #BDC6E0;

  /* Brand */
  --brand: #4361EE;
  --brandHover: #3451D1;
  --brandActive: #2A41BE;
  --brandLight: rgba(67, 97, 238, .10);
  --brandLighter: rgba(67, 97, 238, .06);
  --focusRing: rgba(67, 97, 238, .22);

  /* Semantic */
  --success: #0EA472;
  --successLight: rgba(14, 164, 114, .10);
  --warning: #E8910A;
  --warningLight: rgba(232, 145, 10, .10);
  --danger: #D94638;
  --dangerLight: rgba(217, 70, 56, .10);
  --info: #7B6EE3;
  --infoLight: rgba(123, 110, 227, .10);

  /* Export */
  --export: #3A6EFC;
  --exportHover: #2D5FE8;

  /* Shadows */
  --shadow-xs: 0 1px 3px rgba(20, 25, 40, .07);
  --shadow-sm: 0 2px 8px rgba(20, 25, 40, .06), 0 1px 3px rgba(20, 25, 40, .04);
  --shadow-md: 0 6px 20px rgba(20, 25, 40, .07), 0 2px 6px rgba(20, 25, 40, .04);
  --shadow-lg: 0 16px 40px rgba(20, 25, 40, .10), 0 4px 12px rgba(20, 25, 40, .05);
  --panelShadow: var(--shadow-sm);

  /* Radii — differentiated for proper visual hierarchy */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 12px;

  /* Type scale */
  --text-xs: 0.72rem;
  --text-sm: 0.84rem;
  --text-base: 1rem;
  --text-md: 1.08rem;
  --text-lg: 1.2rem;
  --text-xl: 1.45rem;
  --text-2xl: 1.75rem;
  --text-3xl: 2.1rem;

  /* Soft buttons */
  --softButton: #FFFFFF;
  --softButtonHover: #F5F7FF;
  --softButtonText: #2C3454;

  /* Touch tap target minimum */
  --tap-min: 44px;
}


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

html {
  scroll-behavior: smooth;
  /* Prevent layout shift from scrollbar appearing/disappearing */
  overflow-y: scroll;
}

body {
  margin: 0;
  font-family: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Inherit font on all interactive elements */
body, button, input, select, textarea { font: inherit; }

a { text-decoration: none; color: inherit; }

/* Consolidated focus-visible — single rule, no browser outline */
a:focus-visible,
button:focus-visible,
summary:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
}

/* Images/media are responsive by default */
img, video, svg { max-width: 100%; display: block; }

/* Remove default list styles when used as nav */
ul, ol { list-style: none; margin: 0; padding: 0; }

/* ── App Shell ──────────────────────────────────────────────── */
.app-shell {
  position: relative;
  min-height: 100vh;
  background: var(--bg);
  /* FIX: removed overflow:hidden which can clip fixed elements incorrectly */
}


/* ═══════════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════════ */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 30;
  width: var(--sidebar-expanded);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 14px 24px;
  background: var(--nav);
  color: var(--navText);
  border-right: 1px solid rgba(255, 255, 255, .04);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .08) transparent;
  transition:
    width var(--shell-motion),
    padding var(--shell-motion),
    box-shadow var(--shell-motion);
  /* Prevent overscroll from propagating to body */
  overscroll-behavior: contain;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .08);
  border-radius: 999px;
}

/* Mobile backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  border: 0;
  padding: 0;
  margin: 0;
  background: rgba(10, 15, 30, .52);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--shell-motion), visibility 0s linear 240ms;
  z-index: 34;
}

body.sidebar-modal-open { overflow: hidden; }

/* Brand / Logo area */
.brand-home {
  display: block;
  position: sticky;
  top: 0;
  z-index: 3;
  background: linear-gradient(
    180deg,
    rgba(20, 25, 40, .99) 0%,
    rgba(20, 25, 40, .96) 70%,
    rgba(20, 25, 40, .88) 100%
  );
  padding: 8px 0 2px;
  transition: padding var(--shell-motion);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
  transition:
    padding var(--shell-motion),
    justify-content var(--shell-motion),
    gap var(--shell-motion);
}

.sidebar-brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.sidebar-brand-icon-shell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 6px;
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(67, 97, 238, .28) 0%, rgba(40, 55, 120, .32) 100%);
  border: 1px solid rgba(67, 97, 238, .30);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .06),
    0 0 0 1px rgba(67, 97, 238, .10),
    0 0 24px rgba(67, 97, 238, .18);
  flex-shrink: 0;
}

.sidebar-brand-icon-shell::before {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 8px;
  background: radial-gradient(circle, rgba(67, 97, 238, .20) 0%, transparent 70%);
  z-index: -1;
}

.sidebar-brand-logo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 6px;
}

.sidebar-brand-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  transition:
    opacity var(--shell-motion),
    max-width var(--shell-motion),
    transform var(--shell-motion);
}

.sidebar-brand-name {
  font-size: .98rem;
  font-weight: 800;
  color: #F0F4FF;
  line-height: 1.1;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-brand-subtitle {
  font-size: .72rem;
  font-weight: 500;
  color: #7D8DB8;
  line-height: 1.2;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Navigation ─────────────────────────────────────────────── */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 0 0;
  transition: padding var(--shell-motion);
}

.sidebar-section-label {
  padding: 16px 12px 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .10em;
  text-transform: uppercase;
  color: #4E5F88;
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: anywhere;
  transition:
    opacity var(--shell-motion),
    max-height var(--shell-motion),
    margin var(--shell-motion),
    padding var(--shell-motion);
}

.sidebar-divider {
  height: 1px;
  background: rgba(255, 255, 255, .06);
  margin: 6px 0;
  transition: margin var(--shell-motion), opacity var(--shell-motion);
}

/* Nav group (details/summary accordion) */
.nav-group { overflow: hidden; }

/* Shared base for nav links and summary */
.nav-link,
.nav-group summary,
.nav-group a {
  display: flex;
  font-size: 13.5px;
  font-weight: 500;
  color: #8898C4;
  border-left: 2px solid transparent;
  background: transparent;
  text-decoration: none;
  /* Ensure consistent tap target */
  min-height: 42px;
  transition:
    background .14s ease,
    color .14s ease,
    border-color .14s ease,
    box-shadow .14s ease;
}

.nav-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  list-style: none;
  cursor: pointer;
  margin: 0 2px;
}

/* Remove default summary marker in all browsers */
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::marker { content: none; display: none; }

.nav-parent-main {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  /* Prevent text overflow in collapsed state */
  overflow: hidden;
  transition:
    gap var(--shell-motion),
    justify-content var(--shell-motion),
    width var(--shell-motion);
}

.nav-parent-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
  transition:
    opacity var(--shell-motion),
    max-width var(--shell-motion),
    transform var(--shell-motion);
}

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  color: currentColor;
}

.nav-icon svg,
.nav-chevron svg,
.sidebar-brand-icon svg { display: block; }

.nav-text {
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition:
    opacity var(--shell-motion),
    max-width var(--shell-motion),
    transform var(--shell-motion);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  margin: 0 2px;
  transition:
    background .14s ease,
    color .14s ease,
    border-color .14s ease,
    box-shadow .14s ease,
    padding var(--shell-motion),
    justify-content var(--shell-motion);
}

.nav-link .nav-parent-main { width: 100%; }

/* Hover states */
.nav-link:hover,
.nav-group summary:hover {
  color: #D8E2FF;
  background: rgba(255, 255, 255, .07);
  border-left-color: var(--brand);
}

/* Active/current states */
.nav-group.is-current summary,
.nav-link.active {
  color: #EEF2FF;
  background: rgba(67, 97, 238, .18);
  border-left-color: var(--brand);
  font-weight: 600;
}

/* Focus-visible states */
.nav-link:focus-visible,
.nav-group summary:focus-visible,
.nav-group a:focus-visible {
  color: #D8E2FF;
  background: rgba(255, 255, 255, .08);
  border-left-color: var(--brand);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
}

/* Chevron */
.nav-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
  flex-shrink: 0;
  transition:
    transform .2s ease,
    opacity var(--shell-motion),
    max-width var(--shell-motion);
}

.nav-group[open] > .nav-parent .nav-chevron { transform: rotate(180deg); }

/* Nav badge */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 17px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(67, 97, 238, .20);
  color: #C4D0FF;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: .01em;
  flex-shrink: 0;
  transition:
    opacity var(--shell-motion),
    max-width var(--shell-motion),
    margin var(--shell-motion),
    padding var(--shell-motion);
}

/* Submenu accordion */
.nav-submenu {
  display: grid;
  /* FIX: use grid rows trick instead of max-height for smoother animation */
  grid-template-rows: 0fr;
  overflow: hidden;
  transition: grid-template-rows .22s ease, padding var(--shell-motion);
  padding: 0;
}

.nav-submenu > * { min-height: 0; overflow: hidden; }

.nav-group[open] > .nav-submenu {
  grid-template-rows: 1fr;
  padding: 2px 0 6px;
}

/* Submenu links */
.nav-group a {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 2px;
  margin-right: 2px;
  padding: 7px 12px 7px 44px;
  min-height: 38px;
  font-size: 12.5px;
  color: #6D80B0;
  border-radius: var(--r-sm);
  border-left-color: transparent !important;
  position: relative;
}

.nav-group a:hover {
  color: #D8E2FF;
  background: rgba(255, 255, 255, .07);
}

.nav-group a.active {
  background: rgba(67, 97, 238, .14);
  color: #C8D5FF;
  font-weight: 600;
}

/* Submenu bullet dot */
.nav-group a::before {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: .75;
  flex: 0 0 auto;
}

.nav-group a.active::before,
.nav-group a:hover::before { opacity: 1; }


/* ── Collapsed Sidebar ──────────────────────────────────────── */
html.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed);
  padding-left: 8px;
  padding-right: 8px;
  overflow-x: hidden;
}

html.sidebar-collapsed .main-shell {
  margin-left: var(--sidebar-collapsed);
  width: calc(100% - var(--sidebar-collapsed));
}

html.sidebar-collapsed .brand-home { padding-top: 8px; }

html.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  gap: 0;
  padding-left: 8px;
  padding-right: 8px;
}

html.sidebar-collapsed .sidebar-brand-icon-shell {
  width: 38px;
  height: 38px;
  padding: 6px;
  border-radius: 8px;
}

html.sidebar-collapsed .sidebar-brand-copy,
html.sidebar-collapsed .sidebar-section-label,
html.sidebar-collapsed .nav-text,
html.sidebar-collapsed .nav-chevron,
html.sidebar-collapsed .nav-badge {
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  pointer-events: none;
  transform: translateX(-5px);
}

html.sidebar-collapsed .sidebar-section-label {
  max-height: 0;
  margin: 0;
  padding-top: 0;
  padding-bottom: 0;
}

html.sidebar-collapsed .sidebar-divider { margin: 5px 6px; opacity: .5; }

html.sidebar-collapsed .nav-parent-main {
  width: 100%;
  justify-content: center;
  gap: 0;
}

html.sidebar-collapsed .nav-parent-meta {
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  transform: translateX(5px);
  pointer-events: none;
}

html.sidebar-collapsed .nav-group summary,
html.sidebar-collapsed .nav-link {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

/* FIX: collapse submenu with same grid-rows trick */
html.sidebar-collapsed .nav-group > .nav-submenu {
  grid-template-rows: 0fr !important;
  padding: 0 !important;
}

html.sidebar-collapsed .nav-group a { display: none; }


/* ── Reduced Motion ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .sidebar, .brand-home, .sidebar-brand, .sidebar-brand-copy,
  .sidebar-nav, .sidebar-section-label, .sidebar-divider,
  .nav-parent-main, .nav-parent-meta, .nav-text, .nav-link,
  .nav-chevron, .nav-badge, .nav-submenu, .main-shell,
  .sidebar-toggle, .survey-terminate-option,
  .page-loading-overlay, .page-loading-spinner {
    transition: none !important;
    animation-duration: 1ms !important;
  }

  .page-loading-spinner { animation-duration: 1.4s !important; }
}


/* ═══════════════════════════════════════════════════════════════
   MAIN SHELL & TOPBAR
   ═══════════════════════════════════════════════════════════════ */
.main-shell {
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
  margin-left: var(--sidebar-expanded);
  width: calc(100% - var(--sidebar-expanded));
  height: 100vh;
  /* FIX: use dvh for mobile viewport accuracy */
  height: 100dvh;
  overflow: hidden;
  transition:
    margin-left var(--shell-motion),
    width var(--shell-motion);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: var(--topbar-h);
  min-width: 0;
  padding: 12px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 0 var(--line-soft);
  /* Prevent shrinking below its content */
  flex-shrink: 0;
}

.topbar-main {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1 1 auto;
}

.topbar-title {
  min-width: 0;
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0;
  /* FIX: prevent title overflow on narrow screens */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar toggle button */
.sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text-2);
  cursor: pointer;
  flex: 0 0 auto;
  transition:
    background-color .18s ease,
    border-color .18s ease,
    color .18s ease,
    box-shadow .18s ease,
    transform .14s ease;
}

.sidebar-toggle:hover {
  background: var(--softButtonHover);
  border-color: #C6CEEA;
  color: var(--text);
}

.sidebar-toggle:focus-visible {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--focusRing);
}

.sidebar-toggle:active { transform: translateY(1px); }
.sidebar-toggle-icon { display: block; }

/* User area */
.topbar-user {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
  /* FIX: no-wrap to keep user area compact and aligned */
  flex-wrap: nowrap;
  min-width: 0;
  flex-shrink: 0;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-2);
  font-weight: 600;
  min-width: 0;
}

.user-chip > span:last-child {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--brand) 0%, #7B6EE3 100%);
  color: #fff;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .02em;
  box-shadow: 0 2px 6px rgba(67, 97, 238, .28);
  flex-shrink: 0;
}

.topbar-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 16px;
  background: var(--bg);
  color: var(--text-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  white-space: nowrap;
  font-weight: 600;
  font-size: var(--text-sm);
  letter-spacing: .01em;
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  transition:
    background-color .15s ease,
    color .15s ease,
    border-color .15s ease,
    box-shadow .15s ease,
    transform .14s ease;
}

.topbar-logout:hover {
  background: #E8ECF7;
  border-color: #C6CEEA;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.topbar-logout:active {
  transform: translateY(0);
  box-shadow: var(--shadow-xs);
}

.topbar-logout:focus-visible {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--focusRing);
}


/* ═══════════════════════════════════════════════════════════════
   CONTENT SHELL & PAGE STRUCTURE
   ═══════════════════════════════════════════════════════════════ */
.content-shell {
  position: relative;
  flex: 1 1 auto;
  padding: 20px 24px 32px;
  overflow: auto;
  min-height: 0;
  min-width: 0;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  /* FIX: removed scrollbar-gutter:stable both-edges — 'both-edges' not widely supported */
  scrollbar-gutter: stable;
}

.page-head {
  margin-bottom: 16px;
  display: flex;
  /* FIX: align-items should default to center, not justify-content flush-end */
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.page-head.is-empty { display: none; margin-bottom: 0; }

.page-head-tools {
  margin-left: auto;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  flex: 1 1 640px;
  min-width: 0;
}

.page-body { display: block; min-width: 0; }

/* Screen-reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}


/* ═══════════════════════════════════════════════════════════════
   CARDS & PANELS
   ═══════════════════════════════════════════════════════════════ */
.card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.stat-card,
.panel-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--panelShadow);
}

.stat-card { text-align: center; }

.section-block {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.section-block > h3 {
  margin: 0;
  font-size: var(--text-md);
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
}

/* Stat card typography */
.stat-card h3,
.stat-card > span {
  display: block;
  margin: 0;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: .09em;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  text-align: center;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--text);
}

.stat-card small,
.stat-card > .muted {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1.45;
}

.panel-card h3 {
  margin: 0 0 14px;
  font-size: var(--text-md);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0;
  color: var(--text);
}

.panel-card > p:last-child,
.panel-card > .help-text:last-child { margin-bottom: 0; }


/* ── Analytics Scope ─────────────────────────────────────────── */
.analytics-scope-panel {
  margin-top: 20px;
  display: grid;
  gap: 14px;
  min-width: 0;
}

.analytics-scope-panel-primary {
  padding-left: 14px;
  border-left: 3px solid var(--brand);
}

.analytics-scope-head { margin-bottom: 0; align-items: flex-start; }
.analytics-scope-head-filter-only { justify-content: flex-end; margin-bottom: 12px; }
.analytics-scope-head-split {
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.analytics-scope-selected {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding-top: 2px;
}

.analytics-scope-selected span {
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.analytics-scope-selected strong {
  color: var(--text);
  font-size: .96rem;
  font-weight: 700;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.analytics-chart-card-head { align-items: flex-start; margin-bottom: 14px; }
.analytics-scope-head h3 { margin: 2px 0 4px; }

.analytics-section-eyebrow {
  display: inline-flex;
  align-items: center;
  color: var(--brand);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.analytics-scope-filter {
  min-width: 260px;
  max-width: 360px;
  flex: 0 1 320px;
  margin-left: auto;
}

.analytics-scope-filter-auto {
  min-width: 0;
  max-width: 100%;
  width: auto;
  flex: 0 0 auto;
}

.analytics-scope-filter-auto select { width: auto; min-width: 0; max-width: 100%; }

.analytics-scope-grid { margin-top: 14px; }
.analytics-scope-grid > .panel-card { min-width: 0; }
.analytics-scope-grid-1 { grid-template-columns: 1fr; }
.analytics-scope-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.analytics-overview-grid {
  margin-top: 20px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}


/* ═══════════════════════════════════════════════════════════════
   TABLES
   ═══════════════════════════════════════════════════════════════ */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel);
  width: 100%;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  touch-action: pan-x pan-y;
  scrollbar-gutter: stable;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  background: var(--panel);
}

th, td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  /* FIX: left-align is better default for data tables than center */
  text-align: center;
  white-space: nowrap;
  vertical-align: middle;
}

th {
  background: #F0F2FA;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--brand);
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1.5px solid var(--line);
}

tbody tr { transition: background .12s ease; }
tbody tr:hover td { background: #F5F7FF; }
tbody tr:last-child td { border-bottom: none; }

/* Sticky columns */
.data-table th.is-sticky-col,
.data-table td.is-sticky-col {
  position: sticky;
  background: var(--panel);
  z-index: 2;
  background-clip: padding-box;
}

.data-table thead th.is-sticky-col {
  background: #F0F2FA;
  z-index: 4;
}

.data-table .sticky-shadow {
  box-shadow: 8px 0 14px -12px rgba(13, 27, 42, .30);
}

.data-table th.col-internal_rid,
.data-table td.col-internal_rid,
.data-table th.col-supplier_rid,
.data-table td.col-supplier_rid {
  width: 1%;
  min-width: max-content;
  max-width: none;
}

.data-table td.col-internal_rid,
.data-table td.col-supplier_rid {
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}


/* ═══════════════════════════════════════════════════════════════
   PAGE LOADING OVERLAY & SPINNER
   ═══════════════════════════════════════════════════════════════ */
.page-loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(242, 244, 248, .56);
  backdrop-filter: blur(2.5px);
  -webkit-backdrop-filter: blur(2.5px);
  z-index: 60;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity .22s ease-out, visibility 0s linear .22s;
  will-change: opacity;
  contain: layout paint style;
}

/* FIX: shell variant should be absolute within the content area */
.page-loading-overlay-shell {
  position: absolute;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 60;
}

.page-loading-overlay.is-active,
html.page-loader-pending .page-loading-overlay-shell {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity .16s ease-out, visibility 0s linear 0s;
}

.page-loading-spinner {
  position: relative;
  width: 58px;
  height: 58px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  pointer-events: none;
  box-sizing: border-box;
  border-radius: 50%;
  border: 4px solid rgba(67, 97, 238, .16);
  border-top-color: var(--brand);
  border-right-color: var(--brand);
  animation: sms-loader-spin .78s linear infinite;
  animation-play-state: paused;
  transform-origin: 50% 50%;
  will-change: transform;
  backface-visibility: hidden;
  transform: translateZ(0);
  contain: layout paint style;
  isolation: isolate;
}

.page-loading-spinner::before,
.page-loading-spinner::after { content: none; }

.page-loading-spinner > svg { display: none !important; }

.page-loading-overlay.is-active .page-loading-spinner,
html.page-loader-pending .page-loading-overlay-shell .page-loading-spinner {
  animation-play-state: running;
}


/* ═══════════════════════════════════════════════════════════════
   TOOLBAR & FILTERS
   ═══════════════════════════════════════════════════════════════ */
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.toolbar select,
.toolbar input {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--text);
  font-size: var(--text-sm);
  /* FIX: consistent height with buttons */
  min-height: 40px;
  transition: border-color .14s ease, box-shadow .14s ease;
}

.toolbar button,
.toolbar a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  border: none;
  border-radius: var(--r-sm);
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  transition:
    background-color .14s ease,
    box-shadow .14s ease,
    transform .12s ease;
}

.toolbar button:hover,
.toolbar a:hover {
  background: var(--brandHover);
  box-shadow: 0 4px 12px rgba(67, 97, 238, .22);
  transform: translateY(-1px);
}

.toolbar button:active,
.toolbar a:active { transform: translateY(0); }

/* View Filters */
.view-filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.view-filter-row {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
}

.view-filter-row select,
.view-filter-row input {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--text);
  min-width: 130px;
  height: 38px;
  font-size: var(--text-sm);
  transition: border-color .14s ease, box-shadow .14s ease;
}

.view-filter-row .filter-wide { min-width: 170px; }
.view-filter-row .filter-date { min-width: 145px; }

.view-filter-row .btn-primary,
.view-filter-row .btn-secondary {
  padding: 8px 14px;
  height: 38px;
}

/* Shared hover/focus for all inputs */
.form-field input:hover,
.form-field select:hover,
.form-field textarea:hover,
.toolbar select:hover,
.toolbar input:hover,
.view-filter-row select:hover,
.view-filter-row input:hover { border-color: #B4BFDD; }

.form-field input:focus-visible,
.form-field select:focus-visible,
.form-field textarea:focus-visible,
.toolbar select:focus-visible,
.toolbar input:focus-visible,
.view-filter-row select:focus-visible,
.view-filter-row input:focus-visible {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--focusRing);
}


/* ═══════════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════════ */
.btn-primary, .btn-secondary, .btn-export {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 16px;
  border-radius: var(--r-md);
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: var(--text-sm);
  letter-spacing: .01em;
  transition:
    background-color .16s ease,
    border-color .16s ease,
    color .16s ease,
    box-shadow .16s ease,
    opacity .16s ease,
    transform .12s ease;
}

/* Primary */
.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(67, 97, 238, .24);
}

.btn-primary:hover {
  background: var(--brandHover);
  box-shadow: 0 4px 14px rgba(67, 97, 238, .32);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(67, 97, 238, .18);
}

.btn-primary:focus-visible { box-shadow: 0 0 0 3px var(--focusRing); }

.btn-primary:disabled {
  opacity: .55;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* Secondary */
.btn-secondary {
  background: var(--softButton);
  border: 1px solid var(--line);
  color: var(--softButtonText);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
  background: var(--softButtonHover);
  border-color: #C6CEEA;
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.btn-secondary:active {
  transform: translateY(0);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:focus-visible {
  box-shadow: 0 0 0 3px rgba(107, 120, 168, .25);
}

.btn-secondary:disabled {
  opacity: .60;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* Export */
.btn-export {
  background: var(--export);
  border: 1px solid var(--export);
  color: #fff;
  box-shadow: 0 2px 8px rgba(58, 110, 252, .22);
}

.btn-export:hover {
  background: var(--exportHover);
  border-color: var(--exportHover);
  box-shadow: 0 4px 14px rgba(58, 110, 252, .30);
  transform: translateY(-1px);
}

.btn-export:active { transform: translateY(0); }

.btn-export:focus-visible {
  box-shadow: 0 0 0 3px rgba(58, 110, 252, .28);
}

.btn-export:disabled {
  opacity: .60;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* Export CSV id-specific (inherits btn-export styles) */
#exportCsvBtn { background: var(--export); border: 1px solid var(--export); color: #fff; }
#exportCsvBtn:hover { background: var(--exportHover); border-color: var(--exportHover); color: #fff; }
#exportCsvBtn:focus-visible {
  background: var(--export);
  border-color: #7EA8FF;
  box-shadow: 0 0 0 3px rgba(58, 110, 252, .28);
  color: #fff;
}

/* Small variant */
.btn-small {
  padding: 6px 10px;
  font-size: var(--text-xs);
  border-radius: var(--r-sm);
  min-height: 32px;
}

/* Table action link */
.table-action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 5px 12px;
  border-radius: var(--r-sm);
  background: var(--brandLighter);
  border: 1px solid rgba(67, 97, 238, .18);
  color: var(--brand);
  font-weight: 600;
  font-size: var(--text-xs);
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(67, 97, 238, .08);
  transition:
    background-color .16s ease,
    color .16s ease,
    border-color .16s ease,
    box-shadow .16s ease,
    transform .12s ease;
}

.table-action-link:hover {
  background: var(--brandLight);
  color: var(--brandHover);
  border-color: rgba(67, 97, 238, .28);
  box-shadow: 0 4px 12px rgba(67, 97, 238, .18);
  transform: translateY(-1px);
}

.table-action-link:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(67, 97, 238, .08);
}

.table-action-link:focus-visible { box-shadow: 0 0 0 3px var(--focusRing); }


/* ═══════════════════════════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════════════════════════ */
.module-stack { display: grid; gap: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.form-field label {
  font-weight: 600;
  font-size: var(--text-sm);
  line-height: 1.35;
  color: var(--text-2);
}

.field-required { color: var(--danger); }

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--text);
  font-size: var(--text-sm);
  transition:
    border-color .14s ease,
    box-shadow .14s ease,
    background-color .14s ease;
}

.form-field input::placeholder,
.form-field textarea::placeholder { color: var(--muted-2); }

/* FIX: unified disabled/readonly state */
.form-field input[readonly],
.form-field input:disabled,
.form-field select:disabled,
.form-field textarea:disabled {
  background: #F6F8FC;
  color: var(--muted);
  border-color: var(--line-soft);
  cursor: not-allowed;
  /* Prevent browser dimming on top of our styling */
  opacity: 1;
}

.form-field textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.6;
}

.textarea-compact { min-height: 55px !important; }

.form-full { grid-column: 1 / -1; }

.form-error {
  font-size: var(--text-sm);
  color: var(--danger);
  line-height: 1.35;
}

.form-field small {
  font-size: var(--text-xs);
  color: var(--muted);
  line-height: 1.45;
}

/* Validation state */
#userManagementForm input[aria-invalid="true"],
#userManagementForm select[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(217, 70, 56, .12);
}

/* Input with action button inside */
.input-action-shell { position: relative; display: flex; align-items: center; }
.input-action-shell input { padding-right: 52px; }

.field-action-button {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--brand);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: var(--r-xs);
  cursor: pointer;
  transition: background-color .14s ease;
}

.field-action-button svg { width: 18px; height: 18px; display: block; }
.field-action-button:hover { background: var(--brandLighter); }
.field-action-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focusRing);
}

/* Password strength */
.password-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}

.password-strength-cluster {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
}

.password-strength-bar {
  width: 120px;
  height: 5px;
  border-radius: 999px;
  background: rgba(148, 163, 184, .22);
  overflow: hidden;
}

.password-strength-fill {
  display: block;
  height: 100%;
  width: 34%;
  border-radius: inherit;
  transition: width .18s ease, background-color .18s ease;
}

.password-strength-fill.strength-weak { width: 34%; background: var(--danger); }
.password-strength-fill.strength-medium { width: 67%; background: var(--warning); }
.password-strength-fill.strength-strong { width: 100%; background: var(--success); }

.password-strength-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-2);
}

/* Inline checkboxes */
.inline-checkboxes { display: flex; gap: 12px; flex-wrap: wrap; }

.inline-checkboxes label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--text);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: border-color .14s ease, background-color .14s ease;
}

.inline-checkboxes label:hover {
  border-color: #C6CEEA;
  background: var(--softButtonHover);
}

.inline-checkboxes input[type="checkbox"] { margin: 0; accent-color: var(--brand); }


/* ═══════════════════════════════════════════════════════════════
   ALERTS & FEEDBACK
   ═══════════════════════════════════════════════════════════════ */
.alert {
  padding: 12px 16px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-size: var(--text-sm);
  line-height: 1.55;
}

.alert-success {
  background: var(--successLight);
  border-color: rgba(14, 164, 114, .22);
  color: #0A6B4A;
}

.alert-error {
  background: var(--dangerLight);
  border-color: rgba(217, 70, 56, .22);
  color: #9E2B1E;
}

.alert-info {
  background: var(--infoLight);
  border-color: rgba(67, 97, 238, .20);
  color: #2D42A8;
}

/* FIX: added missing warning alert variant */
.alert-warning {
  background: var(--warningLight);
  border-color: rgba(232, 145, 10, .22);
  color: #8A5200;
}

.page-action-feedback { width: 100%; margin-bottom: 12px; }
.page-action-feedback-copy { display: grid; gap: 4px; }
.page-action-feedback-copy strong { font-size: var(--text-sm); line-height: 1.35; }
.page-action-feedback-copy span { font-size: var(--text-xs); line-height: 1.48; }

.module-load-feedback {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.module-load-feedback-inline { margin-bottom: 14px; }
.module-load-feedback-card { min-height: 160px; }
.module-load-feedback-copy { display: grid; gap: 6px; min-width: 0; }
.module-load-feedback-copy strong { font-size: var(--text-sm); line-height: 1.35; }
.module-load-feedback-copy span { color: inherit; line-height: 1.5; }

.module-load-feedback-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}


/* ═══════════════════════════════════════════════════════════════
   PAGINATION
   ═══════════════════════════════════════════════════════════════ */
.pagination-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.pagination-meta { color: var(--muted); font-size: var(--text-sm); }
.pagination-actions { display: flex; align-items: center; gap: 8px; }

.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  background: var(--brand);
  color: #fff;
  border: 1px solid var(--brand);
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  transition:
    background-color .14s ease,
    border-color .14s ease,
    box-shadow .14s ease,
    transform .12s ease;
}

.page-btn:hover {
  background: var(--brandHover);
  border-color: var(--brandHover);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(67, 97, 238, .20);
}

.page-btn:active { transform: translateY(0); }

.page-btn:focus-visible { box-shadow: 0 0 0 3px var(--focusRing); }

.page-btn.is-disabled {
  pointer-events: none;
  opacity: .45;
  transform: none;
}

.page-status {
  color: var(--text);
  font-weight: 600;
  font-size: var(--text-sm);
}


/* ═══════════════════════════════════════════════════════════════
   MISC UI COMPONENTS
   ═══════════════════════════════════════════════════════════════ */
.muted { color: var(--muted); }

.empty {
  padding: 28px;
  background: var(--panel);
  border: 1.5px dashed var(--line);
  border-radius: var(--r-lg);
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
}

.button-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 6px;
  min-width: 0;
}

.button-row > * { min-width: 0; max-width: 100%; }

.entity-form-actions { align-items: center; }

.inline-toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  min-width: 0;
}

.inline-toolbar .form-field { min-width: 220px; max-width: 100%; }

.inline-copy { display: flex; gap: 10px; align-items: center; min-width: 0; }
.inline-copy input { flex: 1 1 auto; min-width: 0; }

/* Copy icon button */
.copy-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text-2);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition:
    background-color .14s ease,
    color .14s ease,
    border-color .14s ease;
}

.copy-icon svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 1.8; }

.copy-icon:hover {
  background: var(--brandLighter);
  color: var(--brand);
  border-color: rgba(67, 97, 238, .24);
}

.copy-icon:focus-visible { box-shadow: 0 0 0 3px var(--focusRing); }

/* Cell truncation helpers */
.cell-truncate-20, .cell-truncate-30, .country-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}

.cell-truncate-20 .text {
  display: inline-block;
  max-width: 20ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-truncate-30 .text {
  display: inline-block;
  max-width: 30ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Country flag */
.country-flag {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 12px;
  flex: 0 0 18px;
  overflow: hidden;
  border-radius: 3px;
  background: linear-gradient(180deg, #FFF 0%, #F8FAFC 100%);
  box-shadow: inset 0 0 0 1px rgba(20, 25, 40, .12);
}

.country-flag-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  transform: translateZ(0);
}

.country-flag-fallback { display: none; width: 100%; height: 100%; }
.country-flag.is-fallback { background: linear-gradient(180deg, #F8FAFC 0%, #E2E8F0 100%); }
.country-flag.is-fallback .country-flag-fallback { display: block; }

.country-flag.is-fallback::before {
  content: "";
  position: absolute;
  inset: 2px 4px;
  border-radius: 999px;
  border: 1.2px solid #64748B;
  opacity: .65;
}

.country-flag.is-fallback::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  top: 50%;
  height: 1px;
  background: #64748B;
  opacity: .65;
  transform: translateY(-50%);
}


/* ═══════════════════════════════════════════════════════════════
   DASHBOARD
   ═══════════════════════════════════════════════════════════════ */
.dashboard-stack { display: grid; gap: 22px; }

.dashboard-kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.dashboard-kpi-card {
  background: linear-gradient(160deg, #fff 0%, #f8faff 100%);
  box-shadow: 0 4px 18px rgba(20, 25, 40, .05);
}

.dashboard-kpi-metric {
  font-size: 2.35rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  margin: 8px 0 10px;
  color: var(--text);
}

.dashboard-mini-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.dashboard-mini-grid div {
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  background: var(--panel-alt);
  transition: box-shadow .14s ease, border-color .14s ease;
}

.dashboard-mini-grid div:hover {
  border-color: var(--line);
  box-shadow: var(--shadow-xs);
}

.dashboard-mini-grid strong {
  display: block;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0;
  margin-bottom: 4px;
}

.dashboard-mini-grid span {
  display: block;
  font-size: var(--text-xs);
  color: var(--muted);
}

.dashboard-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

/* FIX: consolidate height rule */
.dashboard-grid-2 > .panel-card,
.dashboard-grid-3 > .panel-card {
  min-width: 0;
  height: 100%;
}

.dashboard-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
}

.dashboard-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.dashboard-panel-head p {
  max-width: 64ch;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.6;
}

/* Charts */
.chart-frame { position: relative; width: 100%; min-width: 0; }
.chart-frame-lg { height: 320px; }
.chart-frame-md { height: 260px; }
.chart-frame-sm { height: 220px; }
.chart-frame-country { height: 260px; }
.chart-frame-stats { height: 260px; }
.panel-card canvas { width: 100% !important; height: 100% !important; max-width: 100%; }


/* ═══════════════════════════════════════════════════════════════
   COUNTRY MAP
   ═══════════════════════════════════════════════════════════════ */
.country-volume-grid {
  display: grid;
  grid-template-columns: 1.05fr 1.25fr;
  gap: 18px;
  align-items: stretch;
}

.country-map-shell {
  display: grid;
  grid-template-rows: minmax(220px, 1fr) auto;
  gap: 14px;
}

.country-map-stage {
  position: relative;
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: linear-gradient(160deg, #f6f9ff 0%, #EDF2FF 100%);
  overflow: hidden;
}

.map-blob {
  position: absolute;
  background: rgba(67, 97, 238, .07);
  border: 1px solid rgba(67, 97, 238, .10);
  filter: drop-shadow(0 14px 18px rgba(67, 97, 238, .06));
}

.map-blob-americas { left: 8%; top: 18%; width: 28%; height: 46%; border-radius: 42% 58% 53% 47% / 36% 41% 59% 64%; }
.map-blob-europe { left: 42%; top: 20%; width: 16%; height: 18%; border-radius: 56% 44% 51% 49% / 45% 41% 59% 55%; }
.map-blob-asia { left: 54%; top: 26%; width: 28%; height: 34%; border-radius: 47% 53% 42% 58% / 48% 37% 63% 52%; }
.map-blob-oceania { left: 77%; top: 67%; width: 12%; height: 14%; border-radius: 52% 48% 60% 40% / 45% 49% 51% 55%; }

.map-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  border: none;
  background: transparent;
  padding: 0;
  cursor: default;
}

.map-marker-dot {
  display: block;
  border-radius: 999px;
  border: 2px solid transparent;
  box-shadow: 0 6px 16px rgba(20, 25, 40, .12);
}

.map-marker-flag {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: .95rem;
  line-height: 1;
}

.country-map-legend { display: grid; gap: 8px; }

.country-map-legend-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  background: var(--panel-alt);
  transition: border-color .12s ease;
}

.country-map-legend-item:hover { border-color: var(--line); }
.legend-swatch { width: 9px; height: 9px; border-radius: 999px; }
.legend-label { font-size: var(--text-sm); color: var(--text-2); }


/* ═══════════════════════════════════════════════════════════════
   RECONCILIATION
   ═══════════════════════════════════════════════════════════════ */
.reconciliation-view-layout,
.reconciliation-history-layout,
.reconciliation-workspace-layout { min-width: 0; }

.reconciliation-workspace-panel { min-width: 0; overflow: hidden; }

.reconciliation-kpi-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
}

.reconciliation-source-grid,
.reconciliation-rule-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  min-width: 0;
}

.reconciliation-source-grid > .panel-card,
.reconciliation-rule-grid > .panel-card,
.reconciliation-source-card { min-width: 0; }

.recon-source-textarea { min-height: 180px; resize: vertical; }
.recon-run-feedback:empty { display: none; }

.reconciliation-summary-panel,
.reconciliation-result-panel,
.reconciliation-history-panel { min-width: 0; overflow: hidden; }

.reconciliation-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  min-width: 0;
}

.reconciliation-summary-grid > .panel-card { min-width: 0; }
.reconciliation-summary-grid ul { margin: 0; padding-left: 18px; }
.reconciliation-summary-grid li { overflow-wrap: anywhere; }
.reconciliation-summary-grid li .table-action-link { margin-left: 8px; vertical-align: middle; }
.reconciliation-summary-grid li .help-text { margin: 4px 0 0; }

.reconciliation-result-panel .table-wrap,
.reconciliation-history-panel .table-wrap { max-width: 100%; overflow: auto; }

.reconciliation-history-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.reconciliation-result-table,
.reconciliation-history-table { width: max-content; min-width: 100%; }

.reconciliation-result-table th.col-source-value,
.reconciliation-result-table td.col-source-value,
.reconciliation-result-table th.col-internal-rid,
.reconciliation-result-table td.col-internal-rid,
.reconciliation-result-table th.col-supplier-rid,
.reconciliation-result-table td.col-supplier-rid {
  width: 1%;
  min-width: max-content;
  max-width: none;
}

.reconciliation-result-table td.col-source-value,
.reconciliation-result-table td.col-internal-rid,
.reconciliation-result-table td.col-supplier-rid {
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

.reconciliation-result-table td:nth-child(10) { max-width: 320px; white-space: normal; }

.reconciliation-history-table td:nth-child(3),
.reconciliation-history-table td:nth-child(4) { white-space: nowrap; }


/* ═══════════════════════════════════════════════════════════════
   SURVEY
   ═══════════════════════════════════════════════════════════════ */
.survey-panel {
  box-shadow: 0 8px 24px rgba(20, 25, 40, .05);
  background: linear-gradient(170deg, #fff 0%, #fafbff 100%);
}

.survey-section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.survey-section-head > div { width: 100%; }
.survey-section-head h3 { margin: 0; }

.survey-section-head p {
  margin: 6px 0 0;
  color: var(--muted);
  max-width: none;
  line-height: 1.65;
  font-size: var(--text-sm);
}

.survey-toolbar { justify-content: space-between; }
.survey-toolbar-field { min-width: 420px; flex: 1 1 420px; }

.survey-meta-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.survey-meta-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.survey-link-grid { margin-top: 20px; align-items: start; }
.survey-link-grid-equal { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.survey-form-grid .form-field label,
.survey-prescreener-grid .form-field label { color: var(--text); }

.survey-validation-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

.survey-rule-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: linear-gradient(170deg, #fff 0%, #f8fbff 100%);
  min-height: 100%;
  box-shadow: var(--shadow-xs);
}

/* Survey terminate options */
.survey-terminate-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  width: 100%;
}

.survey-terminate-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition:
    border-color .16s ease,
    box-shadow .16s ease,
    background-color .16s ease,
    transform .14s ease;
}

.survey-terminate-option:hover {
  border-color: #C6CEEA;
  background: var(--softButtonHover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.survey-terminate-option:has(input:checked) {
  border-color: rgba(67, 97, 238, .50);
  background: var(--brandLighter);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, .10);
  transform: translateY(0);
}

.survey-terminate-option input[type="checkbox"] {
  width: 16px !important;
  min-width: 16px;
  max-width: 16px;
  height: 16px;
  margin: 0;
  padding: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  display: block;
  appearance: auto;
  -webkit-appearance: checkbox;
  flex: 0 0 16px;
  accent-color: var(--brand);
}

/* FIX: remove duplicate rules — combined into one */
.survey-terminate-option input[type="checkbox"]:hover,
.survey-terminate-option input[type="checkbox"]:focus-visible,
.survey-terminate-option input[type="checkbox"]:disabled {
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
}

.survey-terminate-option-text {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  font-size: var(--text-sm);
  line-height: 1.45;
  word-break: normal;
  overflow-wrap: break-word;
}

.survey-checkbox-row {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  margin-top: 2px;
  color: var(--text);
  font-weight: 500;
  line-height: 1.45;
  cursor: pointer;
}

.survey-checkbox-row input[type="checkbox"] {
  margin: 0;
  order: 0;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
}

.survey-checkbox-row span { order: 1; display: inline-block; }

.survey-prescreener-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.survey-quota-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }


/* ═══════════════════════════════════════════════════════════════
   USER MANAGEMENT
   ═══════════════════════════════════════════════════════════════ */
.user-management-layout,
.user-management-panel,
.user-management-table-panel,
.user-management-table-card { min-width: 0; }

.user-management-panel,
.user-management-table-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.user-management-alert:empty { display: none; }

.user-management-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.user-management-head h3 { margin-bottom: 8px; }

.user-management-role-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--brandLighter);
  border: 1px solid rgba(67, 97, 238, .16);
  color: var(--brand);
  font-weight: 700;
  font-size: var(--text-sm);
  letter-spacing: .02em;
  white-space: nowrap;
}

.user-management-form-grid { align-items: start; }
.user-management-actions { margin-top: 14px; justify-content: flex-start; }
.user-management-table-card { width: 100%; max-width: 100%; overflow: hidden; }

.user-management-table-card .table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.user-management-table-card .data-table {
  width: max-content;
  min-width: 100%;
}


/* ═══════════════════════════════════════════════════════════════
   SUPPORT
   ═══════════════════════════════════════════════════════════════ */
.support-help-card { padding: 22px; }
.support-help-layout { display: grid; gap: 18px; }

.support-help-kicker {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--brandLighter);
  border: 1px solid rgba(67, 97, 238, .16);
  color: var(--brand);
  font-weight: 700;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: .07em;
}

.support-help-copy h2 {
  margin: 14px 0 10px;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: 0;
}

.support-help-copy p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.75;
  max-width: 58ch;
}

.support-help-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.support-help-contact {
  display: grid;
  gap: 6px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--panel-alt);
  min-width: 0;
}

.support-help-contact span {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}

.support-help-contact strong,
.support-help-contact a {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
}

.support-help-note {
  margin-top: 16px;
  color: var(--muted);
  line-height: 1.75;
  max-width: 56ch;
  font-size: var(--text-sm);
}


/* ═══════════════════════════════════════════════════════════════
   UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════ */
.help-text { font-size: var(--text-sm); color: var(--muted); line-height: 1.55; }
.is-hidden { display: none !important; }
.form-stack-spaced { margin-top: 16px; }
.filter-block-spaced { margin: 12px 0 16px; }
.filter-row-start { justify-content: flex-start; }
.panel-card-spaced { margin-top: 22px; }

/* Code/monospace block */
.setup-code-block {
  display: block;
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid rgba(217, 70, 56, .15);
  border-radius: var(--r-sm);
  background: #fff;
  overflow: auto;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: var(--text-sm);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

#loadRespondentForm { margin-bottom: 16px; }


/* ═══════════════════════════════════════════════════════════════
   KEYFRAMES
   ═══════════════════════════════════════════════════════════════ */
@keyframes sms-spin { to { transform: rotate(360deg); } }

@keyframes sms-loader-spin {
  from { transform: translateZ(0) rotate(0turn); }
  to   { transform: translateZ(0) rotate(1turn); }
}


/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   Hierarchy: 1600 → 1366 → 1100 (sidebar overlay) → 900 → 760 → 700
   ═══════════════════════════════════════════════════════════════ */

/* ── 1600px ──────────────────────────────────────────────────── */
@media (max-width: 1600px) {
  :root {
    --sidebar-expanded: 258px;
    --sidebar-collapsed: 72px;
    --topbar-h: 62px;
  }

  body { font-size: 14px; }

  .sidebar { padding: 18px 12px; }
  .topbar { padding: 10px 18px; min-height: 62px; }
  .topbar-title { font-size: 1.22rem; }
  .content-shell { padding: 14px 16px 20px; }
  .page-head { margin-bottom: 12px; gap: 12px; }
  .page-head-tools { flex-basis: 520px; min-width: 280px; }
  .card-grid { gap: 12px; }
  .section-block { gap: 12px; }
  .stat-card, .panel-card { padding: 16px; }
  .stat-card h3, .stat-card > span { font-size: .70rem; }
  .stat-card strong { font-size: 1.65rem; margin-top: 8px; }
  .analytics-scope-panel { margin-top: 16px; }
  .analytics-scope-head { margin-bottom: 0; }
  .analytics-scope-grid { margin-top: 10px; }
  .dashboard-kpi-metric { font-size: 1.90rem; }
  .dashboard-mini-grid { gap: 10px; margin-top: 12px; }
  .dashboard-mini-grid div { padding: 10px; }
  .dashboard-mini-grid strong { font-size: .96rem; }
  .dashboard-panel-head { margin-bottom: 10px; }
  .chart-frame-lg { height: 280px; }
  .chart-frame-md, .chart-frame-country, .chart-frame-stats { height: 222px; }
  .chart-frame-sm { height: 190px; }
  .toolbar { margin-bottom: 12px; }
  .toolbar select, .toolbar input { padding: 8px 10px; font-size: .88rem; }
  .toolbar button, .toolbar a { padding: 8px 11px; font-size: .88rem; }
  .view-filter-row { gap: 8px; }
  .view-filter-row select, .view-filter-row input {
    min-width: 118px; height: 34px; padding: 7px 9px; font-size: .84rem;
  }
  .view-filter-row .filter-wide { min-width: 148px; }
  .view-filter-row .filter-date { min-width: 130px; }
  .view-filter-row .btn-primary, .view-filter-row .btn-secondary { height: 34px; padding: 7px 11px; }
  .form-grid { gap: 12px; }
  .form-field input, .form-field select, .form-field textarea { padding: 9px 10px; font-size: .88rem; }
  .button-row { gap: 10px; }
  .btn-primary, .btn-secondary, .btn-export { padding: 8px 13px; font-size: .88rem; }
  .inline-toolbar .form-field { min-width: 180px; }
  .survey-toolbar-field { min-width: 332px; flex-basis: 332px; }
  .support-help-card { padding: 20px; }
  .support-help-layout { gap: 20px; }
  .support-help-copy h2 { font-size: 1.34rem; }
  .table-wrap { border-radius: var(--r-md); }
  .table-wrap table { width: max-content; min-width: 100%; table-layout: auto; }
  .data-table th, .data-table td { white-space: nowrap; }
  .data-table th { padding: 9px 10px; font-size: .70rem; letter-spacing: normal; }
  .data-table td { padding: 9px 10px; font-size: .84rem; }
  .data-table th.col-internal_rid, .data-table td.col-internal_rid,
  .data-table th.col-supplier_rid, .data-table td.col-supplier_rid {
    width: 1%; min-width: max-content; max-width: none;
  }
  .table-action-link { padding: 4px 8px; font-size: .74rem; }
  .pagination-bar { margin-top: 10px; }
  .page-btn { padding: 7px 11px; font-size: .84rem; }
}


/* ── 1366px ──────────────────────────────────────────────────── */
@media (max-width: 1366px) {
  :root {
    --sidebar-expanded: 232px;
    --sidebar-collapsed: 68px;
    --topbar-h: 58px;
  }

  body { font-size: 13px; }

  .sidebar { padding: 16px 10px; }
  .topbar { padding: 10px 14px; min-height: 58px; }
  .topbar-title { font-size: 1.12rem; }
  .user-avatar { width: 30px; height: 30px; font-size: .76rem; }
  .topbar-logout { min-height: 34px; padding: 6px 12px; font-size: .84rem; }
  .content-shell { padding: 10px 12px 16px; }
  .page-head { margin-bottom: 9px; gap: 10px; }
  .page-head-tools { min-width: 250px; }
  .card-grid { gap: 10px; }
  .section-block { gap: 10px; }
  .stat-card, .panel-card { padding: 12px; border-radius: var(--r-md); }
  .stat-card h3, .stat-card > span { font-size: .66rem; }
  .stat-card strong { font-size: 1.45rem; margin-top: 6px; }
  .analytics-scope-panel { margin-top: 12px; }
  .analytics-scope-head { margin-bottom: 0; }
  .analytics-section-eyebrow { font-size: .60rem; }
  .analytics-scope-filter { min-width: 220px; max-width: 320px; }
  .analytics-scope-filter-auto { min-width: 0; max-width: 100%; }
  .analytics-scope-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dashboard-kpi-metric { font-size: 1.72rem; margin: 5px 0 7px; }
  .dashboard-stack, .dashboard-kpi-grid, .module-stack { gap: 12px; }
  .dashboard-mini-grid { gap: 8px; margin-top: 10px; }
  .dashboard-mini-grid div { padding: 8px; border-radius: var(--r-sm); }
  .dashboard-mini-grid strong { font-size: .88rem; }
  .dashboard-mini-grid span { font-size: .70rem; }
  .dashboard-panel-head { gap: 10px; margin-bottom: 8px; }
  .chart-frame-lg { height: 252px; }
  .chart-frame-md, .chart-frame-country, .chart-frame-stats { height: 202px; }
  .chart-frame-sm { height: 172px; }
  .toolbar { gap: 7px; margin-bottom: 10px; }
  .toolbar select, .toolbar input, .toolbar button, .toolbar a { padding: 7px 9px; font-size: .84rem; }
  .view-filters { gap: 5px; }
  .view-filter-row { gap: 7px; }
  .view-filter-row select, .view-filter-row input {
    min-width: 108px; height: 30px; padding: 5px 8px; font-size: .80rem;
  }
  .view-filter-row .filter-wide { min-width: 136px; }
  .view-filter-row .filter-date { min-width: 122px; }
  .view-filter-row .btn-primary, .view-filter-row .btn-secondary { height: 30px; padding: 5px 9px; font-size: .80rem; }
  .form-grid { gap: 10px; }
  .form-field { gap: 5px; }
  .form-field label { font-size: .80rem; }
  .form-field input, .form-field select, .form-field textarea { padding: 8px 9px; font-size: .84rem; }
  .form-field textarea { min-height: 76px; }
  .button-row { gap: 8px; }
  .btn-primary, .btn-secondary, .btn-export { padding: 7px 11px; font-size: .84rem; }
  .btn-small { padding: 4px 8px; font-size: .74rem; }
  .inline-toolbar { gap: 8px; }
  .inline-toolbar .form-field { min-width: 162px; }
  .survey-section-head { gap: 10px; margin-bottom: 10px; }
  .survey-section-head p { margin-top: 3px; font-size: .84rem; line-height: 1.40; }
  .survey-toolbar-field { min-width: 298px; flex-basis: 298px; }
  .survey-rule-card { padding: 11px; border-radius: var(--r-md); }
  .survey-link-grid { margin-top: 12px; }
  .support-help-card { padding: 16px; }
  .support-help-layout { gap: 16px; }
  .support-help-copy h2 { font-size: 1.28rem; }
  .support-help-copy p, .support-help-note { font-size: .86rem; line-height: 1.52; }
  .support-help-contact { padding: 12px 14px; }
  .support-help-contact a { font-size: .96rem; }
  .survey-terminate-options { grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 10px; }
  .survey-terminate-option { min-height: 52px; padding: 10px 12px; }
  .table-wrap { border-radius: var(--r-sm); overflow: auto; }
  .table-wrap table { width: max-content; min-width: 100%; table-layout: auto; }
  th, td { padding: 7px 8px; font-size: .74rem; line-height: 1.22; white-space: nowrap; }
  .data-table th {
    white-space: normal; word-break: keep-all; overflow-wrap: normal;
    line-height: 1.18; min-width: 88px; font-size: .66rem;
  }
  .data-table td { max-width: 190px; overflow: hidden; text-overflow: ellipsis; font-size: .78rem; }
  .data-table th.col-internal_rid, .data-table td.col-internal_rid,
  .data-table th.col-supplier_rid, .data-table td.col-supplier_rid {
    width: 1%; min-width: max-content; max-width: none;
  }
  .data-table td.col-internal_rid, .data-table td.col-supplier_rid { overflow: visible; text-overflow: clip; }
  .data-table td.is-sticky-col, .data-table th.is-sticky-col { background-clip: padding-box; }
  .cell-truncate-20, .cell-truncate-30, .country-cell { justify-content: center; flex-wrap: nowrap; }
  .cell-truncate-20 .text { max-width: 14ch; white-space: nowrap; }
  .cell-truncate-30 .text { max-width: 20ch; white-space: nowrap; }
  .copy-icon { width: 18px; height: 18px; flex: 0 0 auto; }
  .table-action-link { padding: 4px 7px; font-size: .70rem; white-space: nowrap; }
  .pagination-bar { gap: 8px; margin-top: 8px; }
  .pagination-meta, .page-status { font-size: .76rem; }
  .page-btn { padding: 5px 9px; font-size: .78rem; }
  .dashboard-kpi-grid > .panel-card,
  .dashboard-grid-2 > .panel-card,
  .dashboard-grid-3 > .panel-card { min-width: 0; }
  .dashboard-grid-2, .dashboard-grid-3 { gap: 10px; }
}


/* ── 1100px — sidebar becomes overlay drawer ─────────────────── */
@media (max-width: 1100px) {
  /* Reset sidebar to overlay drawer mode */
  .sidebar,
  html.sidebar-collapsed .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 36;
    width: min(86vw, 320px);
    max-width: calc(100vw - 28px);
    padding: 0 16px 18px;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    transform: translateX(-100%);
    visibility: hidden;
    pointer-events: none;
    box-shadow: 0 24px 60px rgba(10, 15, 30, .28);
    will-change: transform;
    transition: transform var(--shell-motion), visibility 0s linear 240ms;
  }

  html.sidebar-mobile-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
    transition: transform var(--shell-motion), visibility 0s linear 0ms;
  }

  .sidebar-backdrop { display: block; }

  html.sidebar-mobile-open .sidebar-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity var(--shell-motion), visibility 0s linear 0ms;
  }

  /* Main shell takes full width */
  .main-shell,
  html.sidebar-collapsed .main-shell {
    margin-left: 0;
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
  }

  .page-loading-overlay-shell { top: var(--topbar-h); }

  /* FIX: sidebar-collapsed overrides are undone at this breakpoint */
  html.sidebar-collapsed .brand-home { padding-top: 8px; }

  html.sidebar-collapsed .sidebar-brand {
    justify-content: flex-start;
    gap: 10px;
    padding-left: 16px;
    padding-right: 16px;
  }

  html.sidebar-collapsed .sidebar-brand-icon-shell {
    width: 40px; height: 40px; padding: 6px; border-radius: 8px;
  }

  html.sidebar-collapsed .sidebar-brand-copy,
  html.sidebar-collapsed .sidebar-section-label,
  html.sidebar-collapsed .nav-text,
  html.sidebar-collapsed .nav-chevron,
  html.sidebar-collapsed .nav-badge,
  html.sidebar-collapsed .nav-parent-meta {
    opacity: 1;
    max-width: none;
    overflow: visible;
    pointer-events: auto;
    transform: none;
  }

  html.sidebar-collapsed .sidebar-section-label {
    max-height: none;
    margin: 0;
    padding: 14px 12px 4px;
  }

  html.sidebar-collapsed .sidebar-divider { margin: 6px 0; opacity: 1; }
  html.sidebar-collapsed .nav-parent-main { width: auto; justify-content: flex-start; gap: 10px; }

  html.sidebar-collapsed .nav-group summary,
  html.sidebar-collapsed .nav-link {
    justify-content: flex-start;
    padding-left: 12px;
    padding-right: 12px;
  }

  html.sidebar-collapsed .nav-group > .nav-submenu {
    grid-template-rows: 0fr !important;
    padding: 0 !important;
  }

  html.sidebar-collapsed .nav-group[open] > .nav-submenu {
    grid-template-rows: 1fr !important;
    padding: 2px 0 6px !important;
  }

  html.sidebar-collapsed .nav-group a { display: flex; }

  /* Grids */
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-kpi-grid, .dashboard-grid-2, .dashboard-grid-3,
  .country-volume-grid, .survey-validation-grid,
  .survey-prescreener-grid, .survey-quota-grid,
  .support-help-layout { grid-template-columns: 1fr; }
  .support-help-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-mini-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .survey-terminate-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .page-head { flex-direction: column; }
  .page-head-tools { margin-left: 0; min-width: 100%; width: 100%; }
  .view-filter-row { justify-content: flex-start; }

  .survey-meta-grid,
  .survey-meta-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .survey-toolbar { justify-content: flex-start; }
  .survey-toolbar-field { min-width: 100%; }

  .analytics-scope-head,
  .analytics-chart-card-head { flex-direction: column; }

  .analytics-scope-filter { min-width: 100%; max-width: none; width: 100%; margin-left: 0; }
  .analytics-scope-filter-auto { width: auto; min-width: 0; max-width: 100%; }
  .analytics-scope-filter-auto select { width: auto; max-width: 100%; }

  .analytics-scope-grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
  .analytics-scope-grid.dashboard-grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

  .inline-copy { flex-direction: column; align-items: stretch; }
  .support-help-copy h2 { font-size: 1.24rem; }
  .module-load-feedback { flex-direction: column; align-items: flex-start; }

  .nav-group summary, .nav-link { min-height: 46px; }
  .nav-group a { min-height: 42px; padding-top: 10px; padding-bottom: 10px; }

  .reconciliation-source-grid,
  .reconciliation-rule-grid { grid-template-columns: 1fr; }

  .reconciliation-kpi-row {
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .reconciliation-summary-grid { grid-template-columns: 1fr; }

  .user-management-head,
  .user-management-table-panel .dashboard-panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .user-management-role-chip { align-self: flex-start; }
}


/* ── 900px ───────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .content-shell { padding: 12px 12px 20px; }

  .dashboard-panel-head,
  .analytics-scope-head,
  .analytics-chart-card-head { flex-direction: column; align-items: stretch; }

  .page-head-tools,
  .page-head-tools .view-filters { width: 100%; min-width: 0; }

  .toolbar,
  .view-filter-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: 8px;
  }

  .toolbar > *,
  .view-filter-row > * { width: 100%; min-width: 0; }

  .form-field input, .form-field select,
  .toolbar select, .toolbar input,
  .view-filter-row select, .view-filter-row input {
    min-height: 40px;
    height: auto;
  }

  .btn-primary, .btn-secondary, .btn-export,
  .page-btn, .topbar-logout, .sidebar-toggle, .table-action-link { min-height: 40px; }

  .button-row { align-items: stretch; }
  .button-row > * { flex: 1 1 calc(50% - 6px); min-width: 140px; justify-content: center; }

  .inline-toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
  }

  .inline-toolbar .form-field { min-width: 0; width: 100%; }
}


/* ── 760px ───────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .main-shell { height: 100dvh; min-height: 100dvh; }

  .sidebar-brand { gap: 12px; padding: 16px 12px; }
  .sidebar-brand-icon-shell { width: 38px; height: 38px; padding: 6px; border-radius: 8px; }
  .sidebar-brand-name { font-size: .94rem; }
  .sidebar-brand-subtitle { font-size: .72rem; }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
  }

  .topbar-main { width: 100%; min-width: 0; }
  .topbar-title { font-size: 1.02rem; }

  .topbar-user {
    width: auto;
    min-width: 0;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    justify-self: end;
  }

  .user-chip { max-width: 100%; min-width: 0; gap: 8px; font-size: .86rem; }
  .user-chip > span:last-child { max-width: 84px; }
  .user-avatar { width: 30px; height: 30px; font-size: .76rem; }

  .topbar-logout {
    width: auto;
    min-height: 34px;
    padding: 6px 11px;
    border-radius: var(--r-sm);
    font-size: .82rem;
    flex: 0 0 auto;
  }

  .page-head { align-items: stretch; margin-bottom: 8px; }
  .page-head.is-empty { margin-bottom: 0; }
  .content-shell { padding: 8px 10px 18px; overflow-x: hidden; }

  .page-loading-spinner { width: 52px; height: 52px; }

  .page-body, .module-stack, .panel-card { min-width: 0; max-width: 100%; }
  .module-stack { gap: 12px; }
  .panel-card, .stat-card { padding: 12px; border-radius: var(--r-md); }

  .table-wrap { overflow-x: auto; overflow-y: hidden; }
  .table-wrap table { width: max-content; min-width: 100%; }
  th, td { padding: 8px 9px; }

  .chart-frame-lg { height: 244px; }
  .chart-frame-md, .chart-frame-country, .chart-frame-stats { height: 204px; }
  .chart-frame-sm { height: 180px; }

  /* Stack all grids to single column on mobile */
  .card-grid:not(.reconciliation-kpi-row),
  .dashboard-kpi-grid, .dashboard-grid-2, .dashboard-grid-3,
  .analytics-scope-grid-1, .analytics-scope-grid-3,
  .analytics-scope-grid.dashboard-grid-2,
  .country-volume-grid, .survey-meta-grid, .survey-meta-grid-3,
  .survey-link-grid, .support-help-layout {
    grid-template-columns: 1fr !important;
  }

  .reconciliation-kpi-row {
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .reconciliation-kpi-row > .stat-card { min-width: 180px; }
  .reconciliation-summary-grid { grid-template-columns: 1fr; }

  .toolbar, .view-filter-row { grid-template-columns: 1fr; }
  .inline-toolbar { grid-template-columns: 1fr; }

  .toolbar button, .toolbar a,
  .view-filter-row .btn-primary,
  .view-filter-row .btn-secondary,
  .view-filter-row .btn-export { width: 100%; }

  .analytics-scope-filter, .analytics-scope-filter-auto {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .analytics-scope-filter-auto select { width: 100% !important; max-width: none; }
  .analytics-scope-selected strong { white-space: normal; }

  .support-help-grid { grid-template-columns: 1fr; }

  .button-row { flex-direction: column; gap: 10px; }
  .button-row > * { width: 100%; min-width: 0; }

  .entity-form-actions {
    flex-direction: row;
    align-items: stretch;
    justify-content: flex-start;
    gap: 10px;
  }

  .entity-form-actions > * { flex: 1 1 calc(50% - 5px); min-width: 140px; width: auto; }
  .entity-form-actions > a:last-child { flex-basis: 100%; }

  .user-management-head { flex-direction: column; align-items: stretch; }
  .user-management-role-chip { align-self: flex-start; }

  .pagination-bar { justify-content: stretch; }
  .pagination-actions { width: 100%; justify-content: space-between; }
}


/* ── 700px ───────────────────────────────────────────────────── */
@media (max-width: 700px) {
  :root { --sidebar-collapsed: 64px; }

  .survey-terminate-options { grid-template-columns: 1fr; }
  .survey-terminate-option { min-height: auto; padding: 10px 12px; }

  .card-grid,
  .analytics-scope-grid-1,
  .analytics-scope-grid-3,
  .survey-meta-grid,
  .survey-meta-grid-3 { grid-template-columns: 1fr; }

  .reconciliation-kpi-row {
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .analytics-scope-grid.dashboard-grid-2 { grid-template-columns: 1fr; }
  .dashboard-mini-grid { grid-template-columns: 1fr; }

  .inline-copy { flex-direction: column; align-items: stretch; }
  .support-help-copy h2 { font-size: 1.14rem; }
}
