/* ==========================================================
   RefractSurvey — design tokens
   Signature: concentric "target ring" brand mark, calm dark
   panels for building/reviewing, plain high-contrast forms for
   the anonymous respondent-facing pages.
   ========================================================== */
:root {
  --bg:            #14171F;
  --bg-grid:       #171B26;
  --panel:         #1B1F2C;
  --panel-raised:  #212739;
  --border:        #2A3040;
  --border-soft:   #232838;

  --text:          #EDEFF5;
  --text-muted:    #8B93A8;
  --text-faint:    #5C6478;

  --accent:        #5B8CFF;
  --accent-soft:   rgba(91, 140, 255, 0.14);
  --accent-border: rgba(91, 140, 255, 0.4);
  --accent-hover:  #6f9aff;

  --normal:        #34C1A0;
  --normal-soft:   rgba(52, 193, 160, 0.14);

  --draft:         #8B93A8;
  --draft-soft:    rgba(139, 147, 168, 0.16);
  --active:        #34C1A0;
  --active-soft:   rgba(52, 193, 160, 0.14);
  --closed:        #E8874B;
  --closed-soft:   rgba(232, 135, 75, 0.16);

  --danger:        #E8455C;

  --font-display: 'Rajdhani', 'Segoe UI', sans-serif;
  --font-body:    'Inter', 'Segoe UI', sans-serif;
  --font-mono:    'JetBrains Mono', 'Consolas', monospace;

  --radius: 8px;
  --radius-sm: 5px;
}

/* Alternate dark themes - same darkness family and semantic status
   colors (draft/active/closed never change with theme), just a
   different accent hue and background tint. Selected during install
   (or later from Manage > Application Config) and applied via
   <html data-theme="...">. */
[data-theme="slate"] {
  --bg: #16181D; --bg-grid: #1A1D24; --panel: #1E212A; --panel-raised: #262A35;
  --border: #313640; --border-soft: #262B34;
  --accent: #4FB5C9; --accent-soft: rgba(79, 181, 201, 0.14); --accent-border: rgba(79, 181, 201, 0.4); --accent-hover: #5FBCCE;
}
[data-theme="ember"] {
  --bg: #1A1613; --bg-grid: #1E1916; --panel: #24201B; --panel-raised: #2C2721;
  --border: #3A332A; --border-soft: #2E2822;
  --accent: #E8A14B; --accent-soft: rgba(232, 161, 75, 0.14); --accent-border: rgba(232, 161, 75, 0.4); --accent-hover: #EAAA5D;
}
[data-theme="violet"] {
  --bg: #1A1826; --bg-grid: #1E1B2A; --panel: #221F30; --panel-raised: #2A2740;
  --border: #363047; --border-soft: #2C2838;
  --accent: #8B7CF0; --accent-soft: rgba(139, 124, 240, 0.14); --accent-border: rgba(139, 124, 240, 0.4); --accent-hover: #9C8FF5;
}
[data-theme="rose"] {
  --bg: #1E161B; --bg-grid: #221A1F; --panel: #2A1F26; --panel-raised: #332530;
  --border: #402E3C; --border-soft: #332730;
  --accent: #E36BB0; --accent-soft: rgba(227, 107, 176, 0.14); --accent-border: rgba(227, 107, 176, 0.4); --accent-hover: #E87FBC;
}
[data-theme="moss"] {
  --bg: #151A16; --bg-grid: #191F1A; --panel: #1E251F; --panel-raised: #253027;
  --border: #313D33; --border-soft: #283229;
  --accent: #5FBF5A; --accent-soft: rgba(95, 191, 90, 0.14); --accent-border: rgba(95, 191, 90, 0.4); --accent-hover: #6FCB6A;
}
[data-theme="indigo"] {
  --bg: #14151F; --bg-grid: #181A26; --panel: #1E2030; --panel-raised: #262940;
  --border: #33374F; --border-soft: #2A2D40;
  --accent: #6E74E8; --accent-soft: rgba(110, 116, 232, 0.14); --accent-border: rgba(110, 116, 232, 0.4); --accent-hover: #7E84ED;
}
[data-theme="plum"] {
  --bg: #1B1420; --bg-grid: #201826; --panel: #271D2E; --panel-raised: #302438;
  --border: #3E2E48; --border-soft: #322639;
  --accent: #B565D8; --accent-soft: rgba(181, 101, 216, 0.14); --accent-border: rgba(181, 101, 216, 0.4); --accent-hover: #C078E0;
}
[data-theme="sky"] {
  --bg: #131A1F; --bg-grid: #171F25; --panel: #1D272E; --panel-raised: #253039;
  --border: #324049; --border-soft: #29333B;
  --accent: #5AC8E8; --accent-soft: rgba(90, 200, 232, 0.14); --accent-border: rgba(90, 200, 232, 0.4); --accent-hover: #6ED1EC;
}
[data-theme="lime"] {
  --bg: #171A13; --bg-grid: #1B1F17; --panel: #21261C; --panel-raised: #2A3122;
  --border: #38402C; --border-soft: #2D3324;
  --accent: #9ED65C; --accent-soft: rgba(158, 214, 92, 0.14); --accent-border: rgba(158, 214, 92, 0.4); --accent-hover: #ABDD70;
}
[data-theme="frost"] {
  --bg: #15181D; --bg-grid: #191D23; --panel: #1F242B; --panel-raised: #272E36;
  --border: #343C46; --border-soft: #2B3138;
  --accent: #A8C5E8; --accent-soft: rgba(168, 197, 232, 0.14); --accent-border: rgba(168, 197, 232, 0.4); --accent-hover: #B7D0EC;
}
[data-theme="mono"] {
  --bg: #121212; --bg-grid: #161616; --panel: #1C1C1C; --panel-raised: #242424;
  --border: #363636; --border-soft: #2A2A2A;
  --accent: #E8E8E8; --accent-soft: rgba(232, 232, 232, 0.14); --accent-border: rgba(232, 232, 232, 0.4); --accent-hover: #FFFFFF;
}
[data-theme="crimson"] {
  --bg: #1D1414; --bg-grid: #211717; --panel: #291B1B; --panel-raised: #332121;
  --border: #402B2B; --border-soft: #332424;
  --accent: #E14B4B; --accent-soft: rgba(225, 75, 75, 0.14); --accent-border: rgba(225, 75, 75, 0.4); --accent-hover: #E85F5F;
}
[data-theme="sun"] {
  --bg: #191710; --bg-grid: #1D1B13; --panel: #242018; --panel-raised: #2E291D;
  --border: #3D3625; --border-soft: #302B1E;
  --accent: #E8D94B; --accent-soft: rgba(232, 217, 75, 0.14); --accent-border: rgba(232, 217, 75, 0.4); --accent-hover: #EDDE5F;
}
@property --rainbow-hue {
  syntax: '<number>';
  inherits: true;
  initial-value: 0;
}
[data-theme="rainbow"] {
  --rainbow-hue: 0;
  --bg: #121212; --bg-grid: #161616; --panel: #1C1C1C; --panel-raised: #242424;
  --border: #363636; --border-soft: #2A2A2A;
  --accent: hsl(var(--rainbow-hue) 85% 65%);
  --accent-soft: hsl(var(--rainbow-hue) 85% 65% / 0.14);
  --accent-border: hsl(var(--rainbow-hue) 85% 65% / 0.4);
  --accent-hover: hsl(var(--rainbow-hue) 90% 75%);
  animation: rainbow-cycle 30s linear infinite;
}
@keyframes rainbow-cycle { from { --rainbow-hue: 0; } to { --rainbow-hue: 360; } }
@media (prefers-reduced-motion: reduce) {
  [data-theme="rainbow"] { animation: none; --rainbow-hue: 260; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

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

code {
  font-family: var(--font-mono);
  background: var(--panel-raised);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

.muted { color: var(--text-muted); }

/* Faint blueprint grid behind the whole app */
.app-shell {
  min-height: 100vh;
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 40px 40px;
  background-position: -1px -1px;
}

/* ---------------- Topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 28px;
  background: rgba(27, 31, 44, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.topbar__brand { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.brand-mark { color: var(--accent); font-size: 20px; line-height: 1; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 19px; letter-spacing: 0.02em; }
.project-switcher select {
  background: var(--panel-raised); border: 1px solid var(--border); color: var(--text);
  font-family: var(--font-mono); font-size: 13px; padding: 6px 10px; border-radius: var(--radius-sm);
  max-width: 220px;
}
.topbar__nav { display: flex; align-items: center; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar__nav a {
  color: var(--text-muted); font-size: 14px; font-weight: 500; padding: 8px 12px;
  border-radius: var(--radius-sm); text-decoration: none;
}
.topbar__nav a:hover { color: var(--text); background: var(--panel-raised); }
.topbar__nav a.is-active { color: var(--text); background: var(--panel-raised); }
.topbar__nav a.nav-cta { background: var(--accent); color: #0C0E14; font-weight: 600; }
.topbar__nav a.nav-cta:hover { background: var(--accent-hover); }
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar__user { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.user-chip { font-size: 13px; color: var(--text-muted); }
.logout-link { font-size: 13px; color: var(--text-faint); }

/* Below 900px, wrap onto extra rows rather than a horizontal
   scrollbar - see the reference project's own hard-won note on why
   overflow-x:auto here is the failure mode to avoid: it's easy to
   miss by touch and leaves whatever's off-screen unreachable. .topbar
   is position:sticky, not fixed, so letting it grow taller just
   pushes page content down. */
@media (max-width: 600px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .topbar__nav { justify-content: center; }
  .topbar__actions { margin-left: 0; justify-content: center; }
  .topbar__user { justify-content: center; }
}

/* ---------------- Layout ---------------- */
.app-main { padding: 28px; max-width: 1200px; margin: 0 auto; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-title { font-family: var(--font-display); font-weight: 700; font-size: 28px; margin: 0 0 4px; display: flex; align-items: center; gap: 10px; }
.breadcrumb-link { display: inline-block; font-size: 12.5px; color: var(--text-faint); margin-bottom: 6px; }
.breadcrumb-link:hover { color: var(--accent); text-decoration: none; }
.page-subtitle { margin: 0; color: var(--text-muted); font-size: 14px; }
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-head__actions .inline-form { display: inline-flex; }

.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-bar select { background: var(--panel-raised); border: 1px solid var(--border); color: var(--text); font-size: 13px; padding: 7px 10px; border-radius: var(--radius-sm); }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-body); font-weight: 600; font-size: 14px; padding: 9px 16px;
  border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer; text-decoration: none;
}
.btn--primary { background: var(--accent); color: #0C0E14; }
.btn--primary:hover { background: var(--accent-hover); text-decoration: none; }
.btn--secondary { background: var(--normal-soft); color: var(--normal); border-color: rgba(52,193,160,0.3); }
.btn--ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn--ghost:hover { color: var(--text); border-color: var(--text-faint); text-decoration: none; }
.btn--danger { background: transparent; color: var(--danger); border-color: rgba(232,69,92,0.35); }
.btn--danger:hover { background: rgba(232,69,92,0.12); text-decoration: none; }
.btn--block { width: 100%; }
.btn--small { padding: 6px 12px; font-size: 13px; }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.link-btn { background: none; border: none; padding: 0; color: var(--text-faint); font-size: 13px; cursor: pointer; text-decoration: underline; }
.link-btn:hover { color: var(--danger); }
.link-btn--danger { color: var(--danger); }
.link-btn--neutral:hover { color: var(--accent); }
.order-cell { display: flex; gap: 6px; }
.order-cell .link-btn { text-decoration: none; font-size: 11px; }

/* ---------------- Badges / status ---------------- */
.badge { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; padding: 3px 8px; border-radius: 999px; background: var(--panel-raised); color: var(--text-muted); }
.badge--draft  { background: var(--draft-soft); color: var(--draft); }
.badge--active { background: var(--active-soft); color: var(--active); }
.badge--closed { background: var(--closed-soft); color: var(--closed); }
.badge--template { background: var(--accent-soft); color: var(--accent); }
.badge--used   { background: var(--panel-raised); color: var(--text-faint); }
.badge--unused { background: var(--active-soft); color: var(--active); }

/* ---------------- Modal ---------------- */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(10,12,18,0.7); align-items: center; justify-content: center; z-index: 50; }
.modal-backdrop:not([hidden]) { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; width: 320px; }
.modal h2 { margin: 0 0 6px; font-family: var(--font-display); font-size: 19px; }
.modal p { margin: 0 0 14px; color: var(--text-muted); font-size: 13px; }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------------- Forms ---------------- */
.form-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; max-width: 720px; }
.form-card--flush { padding: 0; border: none; background: none; max-width: none; }
.form-row { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.form-row label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.form-hint { font-size: 12px; color: var(--text-faint); margin: -2px 0 0; }
.required-flag { color: var(--closed); font-weight: 500; }
input[type=text], input[type=password], input[type=date], input[type=email], input[type=number], input[type=url], input[type=file],
textarea, select {
  background: var(--panel-raised); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: var(--radius-sm); font-family: var(--font-body); font-size: 14px;
  width: 100%;
}
textarea { resize: vertical; font-family: var(--font-body); }
.static-field { background: var(--panel-raised); border: 1px solid var(--border); color: var(--text-muted); padding: 10px 12px; border-radius: var(--radius-sm); font-family: var(--font-body); font-size: 14px; line-height: normal; user-select: text; }
.radio-pair { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-pill, .checkbox-pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 7px 12px; font-size: 13px; cursor: pointer; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.checkbox-row input[type=checkbox] { width: auto; accent-color: var(--accent); }
.checkbox-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.form-actions--split { justify-content: space-between; }
.inline-form { display: inline; }

.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.alert ul { margin: 0; padding-left: 18px; }
.alert--error { background: rgba(232,69,92,0.12); color: #ff8b9b; border: 1px solid rgba(232,69,92,0.3); }
.alert--info { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-border); }
.alert--warning { background: var(--closed-soft); color: var(--closed); border: 1px solid rgba(232,135,75,0.35); }

/* ---------------- Table ---------------- */
.table-wrap { overflow-x: auto; }
.stat-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.stat-table tr { border-bottom: 1px solid var(--border-soft); }
.stat-table tr:last-child { border-bottom: none; }
.stat-table th, .stat-table td { padding: 9px 2px; text-align: left; font-size: 13.5px; font-weight: 400; }
.stat-table th { color: var(--text-muted); }
.stat-table td { text-align: right; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

.data-table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.data-table th, .data-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border-soft); font-size: 13.5px; }
.data-table th { color: var(--text-faint); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.03em; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--panel-raised); }
.data-table__title { font-weight: 600; }
.data-table__mono { font-family: var(--font-mono); color: var(--text-muted); }
.empty-cell { text-align: center; color: var(--text-muted); padding: 30px; }

/* ---------------- Panels / groups / manage tiles ---------------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.panel__title { font-family: var(--font-display); font-size: 16px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin: 0 0 14px; }

.group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.section-heading { font-family: var(--font-display); font-size: 14px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-faint); margin: 28px 0 12px; display: flex; align-items: center; gap: 8px; }
.section-heading:first-of-type { margin-top: 0; }
.section-heading__count { font-family: var(--font-body); font-size: 13px; font-weight: 500; color: var(--text-faint); }

.group-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.group-card__head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; justify-content: space-between; }
.group-card h3 { margin: 0; font-size: 16px; }
.group-card__desc { color: var(--text-muted); font-size: 13px; margin: 0 0 10px; }
.group-card__foot { display: flex; align-items: center; gap: 12px; font-size: 12.5px; color: var(--text-muted); flex-wrap: wrap; }
.group-card--inactive { opacity: 0.6; }

.manage-tile { display: block; text-decoration: none; transition: border-color 0.15s ease, transform 0.15s ease; }
.manage-tile:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.manage-tile .group-card__desc { margin-bottom: 0; }

/* ---------------- Survey builder ---------------- */
.builder-group { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 18px; }
.builder-group__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border-soft); flex-wrap: wrap; }
.builder-group__title { margin: 0; font-family: var(--font-display); font-size: 17px; }
.builder-group__desc { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }
.builder-group__actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.builder-questions { padding: 10px 18px 16px; display: flex; flex-direction: column; gap: 10px; }
.question-card { background: var(--panel-raised); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 12px 14px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.question-card__body { min-width: 0; flex: 1 1 320px; }
.question-card__text { margin: 0 0 6px; font-size: 14px; font-weight: 600; }
.question-card__meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.question-type-badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.question-card__actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.builder-empty { color: var(--text-muted); font-size: 13.5px; padding: 4px 0 8px; }
.locked-banner { display: flex; align-items: center; gap: 10px; }

/* Question config sub-fields (scale bounds, boolean labels, choice
   options) shown/hidden by question_form.php's tiny inline script
   based on the selected question type. */
.option-list { display: flex; flex-direction: column; gap: 8px; }
.option-row { display: flex; gap: 8px; align-items: center; }
.option-row input[type=text] { flex: 1; }
.option-row .option-row__label { flex: 1.3; }
.option-row .option-row__desc { flex: 1; }
.option-row .link-btn { flex-shrink: 0; }

/* ---------------- Codes ---------------- */
.code-chip { font-family: var(--font-mono); font-size: 15px; font-weight: 600; letter-spacing: 0.04em; background: var(--panel-raised); color: var(--text); padding: 3px 9px; border-radius: var(--radius-sm); }

.code-print-sheet { display: none; }
@media print {
  .app-shell > .topbar, .no-print { display: none !important; }
  .app-main { max-width: none; padding: 0; }
  body, html { background: #fff !important; }
  .code-print-sheet { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
  .code-print-card {
    border: 1px dashed #999;
    padding: 16px 10px;
    text-align: center;
    break-inside: avoid;
  }
  .code-print-card__survey { font-size: 11px; color: #555; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em; }
  .code-print-card__code { font-family: var(--font-mono); font-size: 22px; font-weight: 700; letter-spacing: 0.05em; color: #111; }
  .code-print-card__batch { font-size: 10px; color: #777; margin-top: 6px; }
}
.code-print-sheet.is-preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 18px; }
.code-print-sheet.is-preview .code-print-card { background: var(--panel); border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 16px 10px; text-align: center; }
.code-print-sheet.is-preview .code-print-card__survey { font-size: 11px; color: var(--text-faint); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em; }
.code-print-sheet.is-preview .code-print-card__code { font-family: var(--font-mono); font-size: 22px; font-weight: 700; letter-spacing: 0.05em; color: var(--text); }
.code-print-sheet.is-preview .code-print-card__batch { font-size: 10px; color: var(--text-faint); margin-top: 6px; }

/* ---------------- Response viewing ---------------- */
.answer-list { display: flex; flex-direction: column; gap: 18px; }
.answer-group__title { font-family: var(--font-display); font-size: 15px; margin: 0 0 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.02em; }
.answer-item { padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.answer-item:last-child { border-bottom: none; }
.answer-item__q { font-size: 13.5px; color: var(--text-muted); margin: 0 0 4px; }
.answer-item__a { font-size: 15px; white-space: pre-wrap; }
.answer-item__a--empty { color: var(--text-faint); font-style: italic; }

/* ---------------- Response analytics (survey_analytics.php) ------------- */
.analytics-group { margin-bottom: 20px; }
.analytics-group__title { font-family: var(--font-display); font-size: 15px; margin: 0 0 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.02em; }
.analytics-question { padding: 16px 0; border-bottom: 1px solid var(--border-soft); }
.analytics-question:last-child { border-bottom: none; }
.analytics-question__text { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.analytics-question__meta { font-size: 12.5px; color: var(--text-faint); margin: 0 0 12px; }
.analytics-question__note { font-size: 12.5px; color: var(--text-faint); font-style: italic; margin: 0 0 10px; }

.chart-bars { display: flex; flex-direction: column; gap: 10px; max-width: 640px; }
.chart-bar-row { display: flex; flex-direction: column; gap: 4px; }
.chart-bar-row__label { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 13.5px; color: var(--text); }
.chart-bar-row__count { color: var(--text-faint); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart-bar-track { background: var(--panel-raised); border: 1px solid var(--border-soft); border-radius: 999px; height: 10px; overflow: hidden; }
.chart-bar-fill { background: var(--accent); height: 100%; border-radius: 999px; min-width: 2px; }

.chart-toggle-wrap { position: relative; }
.chart-toggle-head { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.chart-pie { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.chart-pie__svg { width: 160px; height: 160px; flex-shrink: 0; }
.chart-pie__svg path, .chart-pie__svg circle { stroke: var(--panel); stroke-width: 1.5; }
.chart-pie__legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.chart-pie__legend li { display: flex; align-items: center; gap: 8px; }
.chart-pie__swatch { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.chart-pie__legend-count { color: var(--text-faint); font-size: 12px; margin-left: 2px; font-variant-numeric: tabular-nums; }

/* ---------------- Public-facing: code entry / survey-take / thank you --- */
.public-body {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg);
  background-image: linear-gradient(var(--bg-grid) 1px, transparent 1px), linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 40px 40px;
  padding: 24px;
}
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 24px; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px; width: 400px; max-width: 100%;
}
.login-card__brand { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; justify-content: center; }
.login-card__tagline { color: var(--text-muted); font-size: 13px; margin: 0 0 18px; text-align: center; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.login-card__hint { margin-top: 16px; font-size: 12px; color: var(--text-faint); text-align: center; }

.code-entry-input {
  text-align: center; font-family: var(--font-mono); font-size: 22px; letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Centers the single survey card. Flex (rather than plain block +
   margin:auto) so it inherits the same min-width:0 shrink behavior as
   every other direct child of .public-body - see the rule below. Each
   Large Text question's live markdown preview now renders inline,
   directly under its own field (.md-preview-inline, in the "Survey-
   taking: markdown preview" section below) instead of in a sidebar
   here, so this row only ever has the one child. */
.survey-take-layout { display: flex; justify-content: center; width: 100%; }

/* Every direct child of the centered public-facing body (survey card,
   login card, preview banner, ...) is a flex item of .public-body.
   Flex items default to min-width:auto, which refuses to shrink below
   the item's own min-content size - on a narrow phone screen that's
   what causes horizontal overflow even though each of these already
   has max-width:100%. min-width:0 lets max-width actually win. */
.public-body > * { min-width: 0; }

.survey-take-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: 640px; max-width: 100%; min-width: 0; }
.survey-take-card__title { font-family: var(--font-display); font-size: 26px; margin: 0 0 6px; overflow-wrap: anywhere; }
.survey-take-card__group-sep, .survey-take-card__group { color: var(--text-muted); }
.survey-take-card__desc { color: var(--text-muted); font-size: 14px; margin: 0 0 24px; white-space: pre-wrap; overflow-wrap: anywhere; }
.take-group { margin-bottom: 28px; }
.take-group__title { font-family: var(--font-display); font-size: 17px; margin: 0 0 4px; }
.js-paginated .take-group__title { display: none; }
.take-group__desc { color: var(--text-muted); font-size: 13px; margin: 0 0 14px; overflow-wrap: anywhere; }
.take-question { margin-bottom: 20px; }
.take-question label.take-question__label { display: block; font-size: 14.5px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.take-question__error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }
.scale-options { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.scale-options label { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--text-muted); cursor: pointer; }
.scale-options input[type=radio] { accent-color: var(--accent); width: auto; }
.scale-endpoints { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }
.choice-options { display: flex; flex-direction: column; gap: 8px; }
.choice-options label { display: flex; align-items: center; gap: 8px; font-size: 14.5px; font-weight: 400; cursor: pointer; overflow-wrap: anywhere; }
.choice-options input { width: auto; accent-color: var(--accent); flex-shrink: 0; }
.choice-options label .choice-option__desc { font-size: 12.5px; color: var(--text-muted); }
.boolean-options { display: flex; gap: 10px; flex-wrap: wrap; }
.boolean-options label { display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 8px 16px; cursor: pointer; font-size: 14px; overflow-wrap: anywhere; }
.boolean-options input { width: auto; accent-color: var(--accent); flex-shrink: 0; }

/* ---------------- Install / setup wizard ---------------- */
.install-card { width: 600px; max-width: calc(100vw - 40px); }
.install-steps { list-style: none; margin: 0 0 20px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; font-size: 11px; color: var(--text-faint); }
.install-steps li { padding: 4px 8px; border: 1px solid var(--border); border-radius: 999px; }
.install-steps li.is-active { color: var(--accent); border-color: var(--accent-border); background: var(--accent-soft); }
.check-list { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.check-list__item { display: flex; align-items: flex-start; gap: 10px; font-size: 13.5px; }
.check-list__icon {
  flex-shrink: 0; width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
}
.check-list__item.is-ok .check-list__icon { background: var(--normal-soft); color: var(--normal); }
.check-list__item.is-fail .check-list__icon { background: rgba(232,69,92,0.16); color: var(--danger); }
.check-list__item.is-unknown .check-list__icon { background: var(--closed-soft); color: var(--closed); }
.check-list__item.is-optional .check-list__icon { background: var(--closed-soft); color: var(--closed); }
.check-list__item.is-optional .check-list__body { color: var(--text-muted); }
.check-list__body { display: flex; flex-direction: column; gap: 6px; }
.check-list__fix { margin-top: 2px; }
.check-list__fix-label { font-size: 11.5px; color: var(--text-faint); margin: 0 0 4px; }
.requirements-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.requirements-actions .btn { flex: 1; }
.check-command {
  display: inline-block; font-family: var(--font-mono); font-size: 12px; background: var(--panel-raised);
  border: 1px solid var(--border); border-radius: 5px; padding: 4px 8px; width: fit-content;
}
.check-command::before { content: "$ "; color: var(--text-faint); }
.url-example { background: var(--panel-raised); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 10px; }
.url-example__row { display: flex; align-items: center; gap: 8px; }
.url-example__row code { white-space: nowrap; }

.theme-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin: 4px 0 18px; }
.theme-option { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; cursor: pointer; min-height: 62px; }
.theme-option:has(input:checked) { border-color: var(--accent-border); background: var(--accent-soft); }
.theme-option input[type=radio] { accent-color: var(--accent); width: auto; }
.theme-swatch { width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0; border: 1px solid rgba(255,255,255,0.15); }
.theme-swatch--rainbow { background: conic-gradient(red, orange, yellow, green, blue, violet, red); animation: swatch-spin 9s linear infinite; }
@keyframes swatch-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .theme-swatch--rainbow { animation: none; } }
.theme-option__label { display: flex; flex-direction: column; justify-content: center; gap: 1px; min-height: 2.4em; }
.theme-option__name { font-weight: 600; font-size: 13.5px; }
.theme-option__desc { font-size: 12px; color: var(--text-muted); }

/* ---- Drag-and-drop reordering (groups + questions) ---------------------
   Groups are dragged by a handle in their header; questions by a handle
   on the card. Both drop targets share the same "ghost" treatment: the
   place you dragged *from* becomes a dashed empty outline the size of
   the tile, and a thin accent line shows exactly where the drop will
   land. Questions can be dropped into a different group's list, not
   just reordered within their own. */
.drag-handle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; flex-shrink: 0; cursor: grab;
  color: var(--text-faint); border-radius: 4px; touch-action: none;
}
.drag-handle:hover { color: var(--text-muted); background: var(--panel-raised); }
.drag-handle:active { cursor: grabbing; }
.drag-handle svg { width: 14px; height: 14px; display: block; }

.question-card { cursor: default; }
.builder-group,
.question-card,
.option-row { position: relative; }
/* Hidden by default; only shown (in place of the item's normal
   content) while it's the one being dragged - see .is-dragging below. */
.drag-placeholder-label { display: none; }
.builder-group.is-dragging,
.question-card.is-dragging,
.option-row.is-dragging {
  border: 1px dashed var(--border-soft);
  border-radius: var(--radius-sm);
  background: transparent;
}
.builder-group.is-dragging > *:not(.drag-placeholder-label),
.question-card.is-dragging > *:not(.drag-placeholder-label),
.option-row.is-dragging > *:not(.drag-placeholder-label) {
  display: none;
}
.builder-group.is-dragging > .drag-placeholder-label,
.question-card.is-dragging > .drag-placeholder-label,
.option-row.is-dragging > .drag-placeholder-label {
  display: block;
  color: var(--text-faint);
  font-style: italic;
  padding: 14px 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.builder-group.is-dragging { min-height: 52px; margin-bottom: 18px; }
.question-card.is-dragging { min-height: 44px; }
.option-row.is-dragging { min-height: 38px; }

.drop-indicator {
  height: 2px; border-radius: 2px; background: var(--accent);
  margin: -1px 0; position: relative; flex-shrink: 0;
}
.drop-indicator::before {
  content: ""; position: absolute; left: -3px; top: 50%; transform: translateY(-50%);
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
}
.builder-questions.is-drop-target { background: var(--accent-soft); border-radius: var(--radius-sm); }
.builder-questions { transition: background 0.1s ease; }

/* ---- Info bubble / popover ------------------------------------------- */
.info-bubble {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--panel-raised); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 11.5px; font-weight: 700;
  cursor: pointer; flex-shrink: 0; line-height: 1; position: relative;
}
.info-bubble:hover { color: var(--accent); border-color: var(--accent-border); }
.info-popover {
  position: absolute; z-index: 40; top: calc(100% + 8px); left: 0;
  width: 480px; max-width: min(480px, calc(100vw - 48px));
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: 0 12px 32px rgba(0,0,0,0.4);
  font-size: 13px; color: var(--text-muted); text-align: left;
}
.info-popover[hidden] { display: none; }
.info-popover h4 { margin: 0 0 10px; font-family: var(--font-display); font-size: 14px; color: var(--text); }
.info-popover-wrap { position: relative; display: inline-block; }
.status-workflow-diagram { width: 100%; height: auto; margin-bottom: 10px; }
.status-workflow-lock-note {
  display: flex; align-items: flex-start; gap: 8px; margin: 0 0 12px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--active-soft); border: 1px solid var(--active);
  font-size: 12.5px; color: var(--text);
}
.status-workflow-lock-note .lock-icon { flex-shrink: 0; margin-top: 2px; }
.status-workflow-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.status-workflow-list li { display: flex; gap: 8px; align-items: flex-start; }
.status-workflow-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 4px; flex-shrink: 0; }
.status-workflow-list strong { color: var(--text); font-weight: 600; }

@media (max-width: 600px) {
  .info-popover { width: min(400px, calc(100vw - 32px)); }
}

/* ---- Media grid (media.php library + question_form.php picker) ------- */
.media-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.media-grid__item {
  display: flex; flex-direction: column; gap: 6px; text-align: left;
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px; cursor: pointer; font: inherit; color: inherit;
}
.media-grid__item:hover { border-color: var(--text-faint); }
.media-grid__item.is-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.media-grid__thumb {
  height: 110px; display: flex; align-items: center; justify-content: center;
  background: var(--bg-grid); border-radius: var(--radius-sm); overflow: hidden;
}
.media-grid__thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.media-grid__name {
  font-size: 12.5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.media-grid__meta { font-size: 11.5px; color: var(--text-faint); }

.media-manage-bar__row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}

/* ---- Chosen-image preview (question_form.php, "Image Only" type) ----- */
.media-chosen {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; min-height: 40px;
}
.media-chosen img {
  width: 48px; height: 48px; object-fit: contain; background: var(--bg-grid); border-radius: 4px; flex-shrink: 0;
}
.media-chosen span { font-size: 13px; color: var(--text); word-break: break-word; }

/* ---- Modal dialog (media picker) --------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(10,12,18,0.7);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: 100%; max-width: 720px; max-height: min(80vh, 720px);
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border-soft);
}
.modal__header h3 { margin: 0; font-family: var(--font-display); font-size: 16px; color: var(--text); }
.modal__close {
  background: none; border: none; color: var(--text-muted); font-size: 22px; line-height: 1;
  cursor: pointer; padding: 2px 6px;
}
.modal__close:hover { color: var(--text); }
.modal__body { padding: 18px; overflow-y: auto; }

/* ---- Media grid usage count (always its own line) --------------------- */
.media-grid__usage { display: block; font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

/* ---- Markdown-rendered content (question text, textarea answers) ------
   overflow-wrap:anywhere guards against a single long unbroken token
   (a URL, a long code/id string pasted into question text) forcing
   this element - and everything shrink-wrapped around it, like the
   survey card on a narrow phone - wider than the viewport. */
.markdown-body { line-height: 1.5; overflow-wrap: anywhere; }
.markdown-body .md-heading { font-family: var(--font-display); margin: 0.6em 0 0.3em; color: var(--text); }
.markdown-body h4.md-heading { font-size: 1.15em; }
.markdown-body h5.md-heading { font-size: 1.05em; }
.markdown-body .md-list { margin: 0.3em 0; padding-left: 1.4em; }
.markdown-body .md-list .md-list { margin: 0.15em 0; }

/* ---- Question text / large-text answer markdown editing --------------- */
.md-hint { font-size: 12px; color: var(--text-faint); margin: 6px 0 0; }
.md-help-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--text-faint);
  background: none; color: var(--text-faint); font-size: 10px; line-height: 1; cursor: pointer;
  padding: 0; vertical-align: middle;
}
.md-help-btn:hover { color: var(--text); border-color: var(--text-muted); }
.md-help-list { margin: 0; }
.md-help-list dt { font-family: var(--font-mono); font-size: 13px; color: var(--text); margin-top: 12px; }
.md-help-list dt:first-child { margin-top: 0; }
.md-help-list dd { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }

.form-with-preview { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.form-with-preview .form-card { flex: 1 1 480px; max-width: 600px; }
.md-preview-col { flex: 1 1 320px; min-width: 280px; position: sticky; top: 20px; }
.md-preview-panel {
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.md-preview-panel__title {
  font-family: var(--font-display); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--text-faint); margin: 0 0 8px;
}
.md-preview { font-size: 14px; min-height: 1.5em; }

/* ---- Survey-taking: markdown preview (Large Text questions) -----------
   A collapsible <details> sitting directly under its own textarea,
   inside the same .take-question/.take-group as the field - not a
   separate sidebar or column - so it stays right where the respondent
   is already looking/scrolling, on any screen width. Distinct from
   .md-preview-col/.md-preview-panel (the builder's question-editor
   sidebar in "Question text / large-text answer markdown editing"
   above) - that one's a different layout for a different, staff-only
   page and is untouched by this. */
.md-preview-inline { margin-top: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--panel-raised); }
.md-preview-inline__toggle {
  cursor: pointer; padding: 8px 12px; font-size: 12.5px; font-weight: 600;
  color: var(--text-muted); list-style: none; user-select: none;
}
.md-preview-inline__toggle::-webkit-details-marker { display: none; }
.md-preview-inline__toggle::before { content: "▸ "; }
.md-preview-inline[open] .md-preview-inline__toggle::before { content: "▾ "; }
.md-preview-inline[open] .md-preview-inline__toggle { border-bottom: 1px solid var(--border-soft); }
.md-preview-inline .md-preview { padding: 10px 12px 12px; }

/* ---- Survey-taking: group pagination ----------------------------------- */
.take-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.take-nav__progress { color: var(--text-faint); font-size: 12.5px; margin: 0; }
.take-nav__buttons { display: flex; gap: 10px; margin-left: auto; }

/* ---- Survey-taking: images centered, capped to the card's width ------- */
.take-image { text-align: center; }
.take-image img { max-width: 100%; height: auto; display: block; margin: 0 auto; border-radius: var(--radius-sm); }
.take-image__caption { color: var(--text-muted); font-size: 13px; margin-top: 8px; }

.take-link { margin-bottom: 20px; }
.take-link__desc { color: var(--text-muted); font-size: 14px; margin: 0 0 8px; overflow-wrap: anywhere; }
.take-link__anchor { color: var(--accent); font-size: 14.5px; font-weight: 600; word-break: break-word; overflow-wrap: anywhere; }

/* ---- Survey preview banner ---------------------------------------------- */
.preview-bar {
  width: 640px; max-width: 100%; margin: 0 auto 14px; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; background: rgba(122, 162, 255, 0.12); border: 1px solid rgba(122, 162, 255, 0.35);
  border-radius: var(--radius-sm); padding: 10px 16px; font-size: 13px; color: var(--text-muted); flex-wrap: wrap;
}
.preview-bar strong { color: var(--text); }
.preview-bar a { color: var(--accent); white-space: nowrap; }

@media (max-width: 700px) {
  .form-with-preview { flex-direction: column; }
  .md-preview-col { position: static; width: 100%; }
}

/* ---- Survey-taking: narrow-screen tightening ---------------------------
   The card and its containing padding already shrink via max-width:100%
   and min-width:0 (see .public-body > * above) at any width - this
   just reclaims some of that padding for content on small phones, and
   stops the Back/Next/Finish row from getting tight next to the
   progress text. */
@media (max-width: 480px) {
  .public-body { padding: 14px; }
  .survey-take-card { padding: 18px; }
  .survey-take-card__title { font-size: 21px; }
  .take-nav__buttons { width: 100%; margin-left: 0; justify-content: space-between; }
  .take-nav__buttons .btn { flex: 1 1 0; }
}
