/* ============================================================
   PULSE — Design System
   ============================================================ */

:root {
  /* Surface */
  --bg: #FAFAF7;            /* warm off-white */
  --bg-2: #F2F2EC;          /* sunken */
  --surface: #FFFFFF;       /* card */
  --surface-2: #F7F7F2;
  --ink: #0F0F0E;           /* near-black */
  --ink-2: #2A2A26;
  --muted: #6B6B63;
  --muted-2: #9A9A90;
  --line: #E6E6DD;
  --line-2: #D5D5C8;

  /* Accent — electric lime */
  --accent: #C6F24E;
  --accent-ink: #0F0F0E;     /* text on accent */
  --accent-soft: #EDF9C2;

  /* Semantic */
  --success: #2F7D3B;
  --warning: #B45309;
  --danger:  #9F1239;
  --info:    #1E4FBF;

  /* Geometry */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-pill: 999px;

  /* Density */
  --gap-1: 4px;
  --gap-2: 8px;
  --gap-3: 12px;
  --gap-4: 16px;
  --gap-5: 24px;
  --gap-6: 32px;
  --gap-7: 48px;
  --gap-8: 64px;

  /* Type — overridden at end of file */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-serif: "Newsreader", "Instrument Serif", Charter, serif;

  /* Shadow — used SPARINGLY */
  --shadow-1: 0 1px 0 rgba(15,15,14,0.04), 0 1px 2px rgba(15,15,14,0.04);
  --shadow-2: 0 2px 0 rgba(15,15,14,0.03), 0 8px 24px -8px rgba(15,15,14,0.10);
  --shadow-pop: 0 24px 64px -24px rgba(15,15,14,0.30), 0 2px 8px rgba(15,15,14,0.06);

  /* Easing */
  --ease: cubic-bezier(.2, .8, .2, 1);
}

[data-theme="dark"] {
  --bg: #0E0E0C;
  --bg-2: #161613;
  --surface: #1A1A16;
  --surface-2: #222220;
  --ink: #F4F4EE;
  --ink-2: #DEDED5;
  --muted: #9A9A90;
  --muted-2: #6B6B63;
  --line: #2A2A26;
  --line-2: #3B3B36;
  --accent: #C6F24E;
  --accent-ink: #0F0F0E;
  --accent-soft: #2C3A14;
}

/* ============================================================
   Reset / base
   ============================================================ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-feature-settings: "ss01", "cv11", "cv09";
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button { font-family: inherit; }
a { color: inherit; }
code, pre, .mono { font-family: var(--font-mono); font-feature-settings: "ss01"; }
.serif { font-family: var(--font-serif); font-weight: 400; letter-spacing: -0.01em; }

/* ============================================================
   Type scale
   ============================================================ */
.t-display {
  font-family: var(--font-serif);
  font-size: 56px;
  line-height: 1;
  letter-spacing: -0.02em;
  font-weight: 400;
}
.t-h1 { font-size: 28px; line-height: 1.2; letter-spacing: -0.02em; font-weight: 600; margin: 0; }
.t-h2 { font-size: 20px; line-height: 1.3; letter-spacing: -0.01em; font-weight: 600; margin: 0; }
.t-h3 { font-size: 16px; line-height: 1.35; font-weight: 600; margin: 0; }
.t-body { font-size: 14px; line-height: 1.5; }
.t-small { font-size: 13px; line-height: 1.5; }
.t-caption {
  font-size: 11px;
  line-height: 1.4;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--muted);
  font-family: var(--font-mono);
}
.muted { color: var(--muted); }
.ink-2 { color: var(--ink-2); }

/* ============================================================
   App shell
   ============================================================ */
.app, .app-shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
  background: var(--bg);
}
.app.is-builder, .app.is-public { grid-template-columns: 1fr; }

/* ------- Survey Detail Header ------- */
.survey-detail-header {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "title back";
  gap: 12px;
  align-items: start;
}
.survey-detail-title { grid-area: title; min-width: 0; }
.survey-detail-back { grid-area: back; justify-self: end; flex-shrink: 0; }

/* ------- Tabs ------- */
.tab-bar-wrap { position: relative; }
.tab-bar-hint { display: none; }
.tab-bar {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
  margin-top: 8px;
}
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: transparent;
  border: 0;
  border-bottom: 1.5px solid transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  margin-bottom: -1px;
  transition: color .12s, border-color .12s;
}
.tab:hover { color: var(--ink-2); }
.tab.is-on {
  color: var(--ink);
  border-bottom-color: var(--ink);
  font-weight: 600;
}
.tab-count {
  background: var(--bg-2);
  color: var(--muted);
  padding: 1px 6px;
  border-radius: var(--r-pill);
  font-size: 10.5px;
  font-weight: 600;
}
.tab.is-on .tab-count { background: var(--ink); color: var(--accent); }

/* ------- Chip ------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all .12s;
}
.chip:hover { color: var(--ink); border-color: var(--line-2); }
.chip.is-on {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

/* ------- NPS score pill ------- */
.score-pill {
  display: inline-grid; place-items: center;
  width: 28px; height: 22px;
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-2);
  color: var(--ink);
}
.score-pill.is-promoter  { background: rgba(198,242,78,0.30); color: #2F4F0E; }
.score-pill.is-passive   { background: var(--bg-2); color: var(--muted); }
.score-pill.is-detractor { background: rgba(159,18,57,0.10); color: #9F1239; }

.split-1-1 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* Tweak scale */
:root { --ui-scale: 1; }
.app-shell, body > #root > div { zoom: var(--ui-scale); }

/* Dark mode toggle (via tweak) */
html.is-dark {
  --bg: #0E0E0C;
  --bg-2: #161613;
  --surface: #1A1A16;
  --surface-2: #222220;
  --ink: #F4F4EE;
  --ink-2: #DEDED5;
  --muted: #9A9A90;
  --muted-2: #6B6B63;
  --line: #2A2A26;
  --line-2: #3B3B36;
  --accent-soft: #2C3A14;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--bg);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 6px;
}
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--accent);
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.02em;
  position: relative;
}
.brand-mark::after {
  /* heartbeat dot */
  content: "";
  position: absolute;
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  bottom: 4px; right: 4px;
  box-shadow: 0 0 0 0 var(--accent);
  animation: pulse 2s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(.85); }
}
.brand-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--font-mono);
}

.workspace-switch {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  transition: border-color .15s var(--ease);
}
.workspace-switch:hover { border-color: var(--line-2); }
.workspace-switch .avatar {
  width: 22px; height: 22px; border-radius: var(--r-sm);
  background: var(--ink); color: var(--accent);
  display: grid; place-items: center; font-size: 11px; font-weight: 600;
}
.workspace-switch .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-switch .arrow { color: var(--muted); }

.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-2);
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  cursor: pointer;
  font-size: 15px;
  transition: background .12s var(--ease), color .12s var(--ease);
  text-decoration: none;
  border: 1px solid transparent;
}
.nav-item:hover { background: var(--bg-2); color: var(--ink); }
.nav-item.is-active {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  font-weight: 500;
}
.nav-item .nav-icon { width: 16px; flex: 0 0 16px; opacity: .8; }
.nav-item .nav-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--font-mono);
}

.sidebar-foot {
  margin-top: auto;
  display: flex; flex-direction: column; gap: 6px;
}

/* ============================================================
   Main
   ============================================================ */
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky; top: 0; z-index: 5;
  backdrop-filter: blur(8px);
}
.topbar-inner {
  display: flex; align-items: center; gap: 20px;
  padding: 20px 32px;
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
}
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--ink); }
.crumbs .sep { color: var(--line-2); }
.crumbs .current { color: var(--ink); font-weight: 500; font-size: 16px; }

.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar-actions .btn-icon { width: 36px; height: 36px; padding: 8px; }

.search {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  min-width: 240px;
  color: var(--muted);
  font-size: 13px;
  cursor: text;
}
.search kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg-2);
  color: var(--muted);
}

.content {
  padding: 32px;
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}
.content.wide { max-width: none; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  transition: background .12s var(--ease), border-color .12s var(--ease), transform .12s var(--ease);
  white-space: nowrap;
  font-family: inherit;
  line-height: 1;
  text-decoration: none;
}
.btn:hover { border-color: var(--line-2); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.btn-primary:hover { background: var(--ink-2); border-color: var(--ink-2); color: var(--bg); }
.btn-accent {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-accent:hover { background: #B5E13D; border-color: #B5E13D; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-2); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #FBE4EA; border-color: #F2C5CF; }

.btn-sm { padding: 5px 9px; font-size: 12.5px; }
.btn-lg { padding: 10px 16px; font-size: 14px; }
.btn-icon { padding: 6px; width: 28px; height: 28px; justify-content: center; }
.btn-block { width: 100%; justify-content: center; }

/* ============================================================
   Inputs
   ============================================================ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
}
.field-help { font-size: 12px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 80px; }

.input-group {
  display: flex; align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
}
.input-group:focus-within { border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-group .input { border: 0; box-shadow: none !important; }
.input-group .btn { border-radius: 0; border: 0; border-left: 1px solid var(--line); }

.checkbox {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.checkbox input { display: none; }
.checkbox .box {
  width: 16px; height: 16px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: var(--surface);
  display: grid; place-items: center;
  transition: all .12s var(--ease);
}
.checkbox input:checked + .box {
  background: var(--ink);
  border-color: var(--ink);
}
.checkbox input:checked + .box::after {
  content: "";
  width: 9px; height: 5px;
  border-left: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg) translate(1px, -1px);
}

.radio {
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer;
}
.radio input { display: none; }
.radio .dot {
  width: 16px; height: 16px;
  border: 1px solid var(--line-2);
  border-radius: 50%;
  background: var(--surface);
  display: grid; place-items: center;
  transition: all .12s var(--ease);
}
.radio input:checked + .dot {
  border-color: var(--ink);
  border-width: 1.5px;
}
.radio input:checked + .dot::after {
  content: "";
  width: 8px; height: 8px;
  background: var(--ink);
  border-radius: 50%;
}

.toggle {
  width: 30px; height: 18px;
  background: var(--line-2);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background .15s var(--ease);
  flex: 0 0 30px;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: white;
  border-radius: 50%;
  transition: left .18s var(--ease);
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.toggle.on { background: var(--ink); }
.toggle.on::after { left: 14px; }

/* ============================================================
   Cards & Surfaces
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.card-pad { padding: 20px; }
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.card-head .t-h3 { flex: 1; }

/* ============================================================
   Badges
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 7px;
  border-radius: var(--r-sm);
  font-size: 11.5px;
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-family: var(--font-mono);
  letter-spacing: -0.01em;
}
.badge .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted);
}
.badge.is-active .dot { background: var(--success); }
.badge.is-draft .dot { background: var(--muted); }
.badge.is-paused .dot { background: var(--warning); }
.badge.is-archived .dot { background: var(--muted-2); }
.badge.is-success { background: #ECF6EE; color: var(--success); border-color: #C9E5CE; }
.badge.is-warning { background: #FBF1DE; color: var(--warning); border-color: #F2DDB1; }
.badge.is-info    { background: #E5EBFA; color: var(--info); border-color: #C4D1F1; }

/* ============================================================
   Tables
   ============================================================ */
.table-wrap { overflow-x: auto; }
table.t {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.t thead th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-family: var(--font-mono);
  background: var(--surface-2);
  position: sticky; top: 0;
}
table.t tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.t tbody tr { transition: background .1s var(--ease); }
table.t tbody tr:hover { background: var(--surface-2); }
table.t tbody tr:last-child td { border-bottom: 0; }
table.t .num { font-family: var(--font-mono); font-feature-settings: "tnum"; }

/* ============================================================
   Empty state
   ============================================================ */
.empty {
  border: 1px dashed var(--line-2);
  border-radius: var(--r-lg);
  padding: 56px 24px;
  text-align: center;
  background: var(--surface-2);
}
.empty-mark {
  width: 44px; height: 44px;
  margin: 0 auto 16px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  color: var(--muted);
}

/* ============================================================
   Misc utilities
   ============================================================ */
.row { display: flex; align-items: center; gap: 12px; }
.col { display: flex; flex-direction: column; gap: 12px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.grow { flex: 1; min-width: 0; }
.flex { display: flex; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-5 { gap: 24px; } .gap-6 { gap: 32px; }
.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-baseline { align-items: baseline; }
.justify-end { justify-content: flex-end; }
.col-1 { display: grid; grid-template-columns: 1fr; gap: 16px; }
.col-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.col-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.col-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.split-7-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; }
.split-3-7 { display: grid; grid-template-columns: 1fr 2fr; gap: 24px; }

.divider { height: 1px; background: var(--line); margin: 0; border: 0; }

.kpi-num {
  font-family: var(--font-serif);
  font-size: 44px;
  line-height: 1;
  letter-spacing: -0.02em;
  font-weight: 400;
}
.kpi-num-mono {
  font-family: var(--font-mono);
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.03em;
  font-weight: 500;
  font-feature-settings: "tnum";
}
.kpi-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--font-mono);
  margin-top: 8px;
}
.kpi-delta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px;
  color: var(--success);
  font-family: var(--font-mono);
  margin-top: 4px;
}
.kpi-delta.neg { color: var(--danger); }

/* ============================================================
   Density
   ============================================================ */
[data-density="compact"] {
  --gap-3: 8px;
  --gap-4: 12px;
  --gap-5: 18px;
  --gap-6: 24px;
}
[data-density="compact"] .content { padding: 22px; }
[data-density="compact"] table.t tbody td { padding: 8px 14px; }
[data-density="compact"] table.t thead th { padding: 7px 14px; }
[data-density="compact"] .card-pad { padding: 14px; }
[data-density="compact"] .card-head { padding: 11px 14px; }
[data-density="compact"] .topbar-inner { padding: 14px 22px; }

/* ============================================================
   Radius variants (Tweak)
   ============================================================ */
[data-radius="sharp"] {
  --r-xs: 0px; --r-sm: 0px; --r-md: 2px; --r-lg: 4px; --r-xl: 6px;
}
[data-radius="soft"] {
  --r-xs: 6px; --r-sm: 8px; --r-md: 10px; --r-lg: 14px; --r-xl: 18px;
}
[data-radius="round"] {
  --r-xs: 10px; --r-sm: 12px; --r-md: 14px; --r-lg: 18px; --r-xl: 22px;
}

/* ============================================================
   Animations
   ============================================================ */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fade-in .35s var(--ease); }
@keyframes scale-in {
  from { opacity: 0; transform: scale(.96); }
  to { opacity: 1; transform: scale(1); }
}

/* ============================================================
   Logo asset
   ============================================================ */
.logo-stamp {
  display: inline-flex; align-items: center; gap: 8px;
}
.logo-stamp svg { display: block; }

/* ============================================================
   Scrollbars
   ============================================================ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

/* ============================================================
   Bootstrap Icons compatibility
   ============================================================ */
.bi { font-size: inherit; color: inherit; }

/* Mono utility */
.mono { font-family: var(--font-mono); }

/* Alert notifications */
.alert-pulse {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px;
  margin: 0;
  font-size: 13.5px;
  border-bottom: 1px solid var(--line);
}
.alert-pulse button {
  margin-left: auto; background: none; border: none; cursor: pointer;
  font-size: 16px; color: var(--muted); padding: 0 4px;
}
.alert-success { background: #ECF6EE; color: var(--success); }
.alert-error { background: #FDE8EF; color: var(--danger); }

/* Form validation */
.field-validation-error { font-size: 12px; color: var(--danger); margin-top: 4px; display: block; }
.validation-summary-errors ul { margin: 0; padding: 0 0 0 16px; font-size: 13px; color: var(--danger); }
.input.is-error, .select.is-error, .textarea.is-error { border-color: var(--danger); }

/* Plan usage widget in sidebar */
.plan-usage {
  padding: 10px;
  font-size: 12px;
}
.plan-bar {
  height: 4px; background: var(--bg-2); border-radius: 999px; overflow: hidden; margin: 8px 0;
}
.plan-bar-fill { height: 100%; background: var(--ink); }

/* Builder full-screen override */
body.is-builder { overflow: hidden; }
body.is-builder .topbar-wrap { display: none; }

/* Card footer */
.card-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px;
}

/* Sidebar foot logout */
.nav-item form button {
  all: unset;
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  transition: background .12s var(--ease), color .12s var(--ease);
}
.nav-item form button:hover { background: var(--bg-2); color: var(--ink); }

/* Progress bar for completion */
.progress-bar-wrap {
  width: 80px; height: 6px; background: var(--bg-2); border-radius: 999px; overflow: hidden;
}
.progress-bar-fill { height: 100%; background: var(--ink); }

/* Tabs with anchor behavior */
.tab-pane { display: none; }
.tab-pane.is-active { display: block; }

/* Toast */
.toast-pulse {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  background: var(--ink); color: var(--bg);
  padding: 12px 18px; border-radius: var(--r-md);
  font-size: 13.5px; display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-pop);
  animation: fade-in .2s var(--ease);
}
.toast-pulse.is-success { background: var(--success); }
.toast-pulse.is-error { background: var(--danger); }

/* ============================================================
   Topbar dropdowns (notifications + user menu)
   ============================================================ */
.topbar-dropdown { position: relative; display: inline-flex; }

.notif-trigger { position: relative; }
.notif-badge {
  position: absolute; top: 0; right: 0;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px;
  background: var(--danger, #DC2626); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg);
}

.user-avatar-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--ink); color: var(--accent);
  display: grid; place-items: center;
  font-size: 14px; font-weight: 600;
  border: none; cursor: pointer; padding: 0; margin-left: 4px;
  font-family: inherit;
  transition: transform .12s var(--ease), filter .12s var(--ease);
}
.user-avatar-btn:hover { filter: brightness(1.1); transform: scale(1.05); }
.user-avatar-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar-menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  min-width: 240px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 50;
  overflow: hidden;
}
.notif-menu { width: 320px; max-width: calc(100vw - 32px); }
.topbar-menu[hidden] { display: none; }

.topbar-menu-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px; color: var(--ink);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.btn-link-sm {
  background: none; border: none; padding: 0;
  color: var(--muted); font-size: 11.5px; cursor: pointer;
  font-family: inherit;
}
.btn-link-sm:hover { color: var(--ink); text-decoration: underline; }

.topbar-menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  font-size: 13px; color: var(--ink);
  text-decoration: none; cursor: pointer;
  background: none; border: none; width: 100%;
  font-family: inherit; text-align: left;
}
.topbar-menu-item:hover { background: var(--bg-2); }
.topbar-menu-item i { font-size: 14px; color: var(--muted); }
.topbar-menu-form { margin: 0; padding: 0; }

.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  text-decoration: none; color: var(--ink);
  font-size: 13px;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg-2); }
.notif-item .notif-title { font-weight: 500; }
.notif-item .notif-meta { font-size: 11.5px; color: var(--muted); }
.notif-empty {
  padding: 24px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
}

/* ============================================================
   Font override (final)
   ============================================================ */
:root {
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-serif: "Newsreader", "Instrument Serif", Charter, serif;
}

/* ============================================================
   Auth split (Login/Register)
   ============================================================ */
.auth-split {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
}
.auth-split-form {
  display: flex; flex-direction: column;
  padding: 32px 56px; gap: 32px;
}
.auth-split-side {
  background: var(--ink);
  color: var(--bg);
  padding: 32px 56px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* ============================================================
   Sidebar drawer toggle (hidden desktop)
   ============================================================ */
.sidebar-toggle { display: none; }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 99;
}
.sidebar-backdrop.is-show { display: block; }

/* ============================================================
   RESPONSIVE — tablets and below
   ============================================================ */
@media (max-width: 1199px) {
  .topbar-inner, .content { padding-left: 24px; padding-right: 24px; }
  .split-1-1 { grid-template-columns: 1fr; }
  .split-7-3 { grid-template-columns: 1fr; gap: 16px; }
  .col-3 { grid-template-columns: repeat(2, 1fr); }
  .col-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 700px) {
  .col-3 { grid-template-columns: 1fr; }
  .col-4 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .col-4 { grid-template-columns: 1fr; }
}

/* Tables on small screens — wrap in scroll, shrink padding */
@media (max-width: 767px) {
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.t { font-size: 12.5px; }
  table.t thead th, table.t tbody td { padding: 8px 10px; white-space: nowrap; }
  .between { flex-wrap: wrap; gap: 10px; }
  .card-head { flex-wrap: wrap; gap: 8px; }
}

@media (max-width: 991px) {
  /* App shell collapses to single column */
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0;
    width: 280px; max-width: 86vw;
    height: 100vh; height: 100dvh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.2,.8,.2,1);
    box-shadow: 0 12px 40px rgba(0,0,0,0.18);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-toggle { display: inline-flex; }
  .topbar-inner { padding: 14px 18px; gap: 12px; }
  .crumbs { font-size: 13px; min-width: 0; overflow: hidden; }
  .crumbs .current { font-size: 14px; }
  .crumbs a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90px; }
  .content { padding: 20px 18px; }

  /* Auth split → stacked */
  .auth-split { grid-template-columns: 1fr; }
  .auth-split-side { display: none; }
  .auth-split-form { padding: 28px 24px; gap: 24px; min-height: 100vh; }

  /* Dashboard grid — fewer effective cols */
  .dash-grid { grid-template-columns: repeat(4, 1fr) !important; }
  .dash-card { grid-column: 1 / -1 !important; grid-row: span 10 !important; }
}

@media (max-width: 767px) {
  .topbar-inner { padding: 12px 14px; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .btn-icon { width: 34px; height: 34px; }
  .content { padding: 16px 14px; }

  /* Auth */
  .auth-split-form { padding: 24px 18px; }
  .auth-split-form .brand { padding: 0; }
  .auth-split-form h1 { font-size: 28px !important; }
  .auth-split-form h2 { font-size: 22px !important; }

  /* Common 2-col patterns */
  .col-2 { grid-template-columns: 1fr !important; }

  /* Buttons take more comfortable touch targets */
  .btn { padding: 9px 14px; font-size: 13px; }
  .btn-sm { padding: 7px 11px; font-size: 12.5px; }

  /* Tables: allow horizontal scroll wrappers */
  .table-wrap, .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Tables with t-cards: stack rows as cards */
  .t-cards thead { display: none; }
  .t-cards, .t-cards tbody { display: block; width: 100%; }
  .t-cards tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 12px 14px;
    margin-bottom: 8px;
    background: var(--surface);
    position: relative;
  }
  .t-cards td {
    display: block;
    padding: 4px 0 !important;
    border: 0 !important;
  }
  .t-cards td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 10.5px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 2px;
    font-weight: 600;
  }
  .t-cards .t-cards-chev {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 0 !important;
  }
  .t-cards .t-cards-action {
    margin-top: 8px;
    padding-top: 8px !important;
    border-top: 1px dashed var(--line) !important;
  }

  /* Tab bar: horizontal scroll on mobile */
  .tab-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-right: 32px;
  }
  .tab-bar::-webkit-scrollbar { display: none; }
  .tab {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 10px 12px;
    font-size: 13px;
  }
  .tab-bar-hint {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 1px;
    width: 44px;
    padding-right: 6px;
    background: linear-gradient(to right, rgba(255,255,255,0), var(--bg) 60%);
    color: var(--muted);
    pointer-events: none;
    font-size: 14px;
    animation: tabHintBounce 1.4s ease-in-out infinite;
  }
  @keyframes tabHintBounce {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(-5px); }
  }

  /* Survey detail header: keep back button top-right on mobile */
  .survey-detail-header {
    grid-template-columns: 1fr auto;
  }
  .survey-detail-back {
    padding: 6px 10px;
    font-size: 12.5px;
  }

  /* Hide secondary topbar items by default; keep essentials */
  .topbar-spacer { flex: 1; }

  /* Modals: reduce padding */
  .dash-modal { max-width: calc(100vw - 28px) !important; padding: 18px !important; }

  /* Notifications: full-width sheet */
  .notif-menu {
    position: fixed;
    top: 60px;
    left: 12px;
    right: 12px;
    width: auto;
    max-width: none;
    max-height: calc(100vh - 76px);
    display: flex;
    flex-direction: column;
  }
  .notif-list {
    max-height: none;
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .notif-item .notif-title {
    white-space: normal;
    word-break: break-word;
    line-height: 1.35;
  }
}

@media (max-width: 480px) {
  html { font-size: 14.5px; }
  .topbar-inner { padding: 10px 12px; gap: 8px; }
  .crumbs a { max-width: 60px; }
  .content { padding: 14px 12px; }

  /* Topbar dropdown menus: full-width fixed sheet */
  .notif-menu {
    position: fixed;
    top: 64px;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    max-height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
  }
  .notif-list {
    max-height: none;
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .notif-item { padding: 12px 14px; }
  .notif-item .notif-title {
    white-space: normal;
    word-break: break-word;
    line-height: 1.35;
  }
  .notif-empty { padding: 28px 14px; }
  .notif-badge {
    min-width: 16px;
    height: 16px;
    font-size: 10px;
    line-height: 16px;
    border-width: 1.5px;
  }

  .topbar-menu.user-menu {
    right: -8px;
    left: auto;
    min-width: 220px;
  }

  /* Cards spacing */
  .card { padding: 16px; }

  /* Folder bar wrap */
  .dash-folder-bar { gap: 6px; }
  .dash-folder-chip { padding: 5px 10px; font-size: 12px; }

  /* Auth side hidden, footer wraps */
  .auth-split-form .row { flex-wrap: wrap; gap: 10px; }
}

/* ============================================================
   Builder-specific responsive (3-col layout)
   ============================================================ */
@media (max-width: 1100px) {
  .builder-container {
    grid-template-columns: 200px 1fr 240px !important;
  }
}
@media (max-width: 900px) {
  body { overflow: auto !important; }
  .builder-topbar {
    padding-left: 12px !important;
    padding-right: 12px !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  .builder-topbar .row { min-width: 0; flex: 1 1 auto; }
  .builder-topbar .topbar-spacer { display: none; }
  .builder-topbar .topbar-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px !important;
  }
  .builder-topbar .topbar-actions .btn {
    padding: 7px 10px !important;
    font-size: 12.5px !important;
  }
  .builder-topbar .topbar-actions .btn span,
  .builder-topbar .topbar-actions .btn { white-space: nowrap; }
  .builder-wrapper {
    padding: 8px 0 12px !important;
    height: auto !important;
    overflow: visible !important;
  }
  .builder-container {
    display: block !important;
    height: auto !important;
    max-width: 100% !important;
    border-radius: 0 !important;
    border-left: none !important;
    border-right: none !important;
  }
  .question-toolbox, .builder-canvas-area, .builder-config-panel,
  .canvas-area, .config-panel {
    border-right: none !important;
    border-left: none !important;
    border-bottom: 1px solid var(--line) !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }
  .question-toolbox { padding: 12px !important; }
  .canvas-area { padding: 16px !important; }
  .config-panel { padding: 16px !important; }
  .question-card {
    flex-direction: column;
    align-items: stretch !important;
  }
  .preview-widget { display: none !important; }
}

@media (max-width: 600px) {
  .builder-topbar .topbar-actions .btn i + * { display: none; }
  .builder-topbar .topbar-actions .btn { gap: 0 !important; }
  .builder-topbar .row > div:nth-of-type(1) .t-caption { display: none; }
}

/* ============================================================
   Generic fluid-grid helpers — opt-in via class
   ============================================================ */
.grid-fluid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

/* Large landscape phones / small tablets */
@media (max-width: 640px) {
  .grid-fluid { grid-template-columns: 1fr; gap: 12px; }
}
