/* ============================================================================
   Inter, served from this origin.
   Not Google Fonts: the public form page is the one strangers load, often on a
   phone, and it should not depend on a third party — nor hand one a log of who
   opened which form. Two latin subsets, with font-display: swap so text paints
   immediately in the fallback face and reflows once Inter arrives.
   Licence: SIL Open Font License 1.1 — see public/fonts/LICENSE.
   ========================================================================= */

@font-face {
  font-family: Inter;
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/inter-400.woff2") format("woff2");
}

@font-face {
  font-family: Inter;
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/inter-600.woff2") format("woff2");
}

/* ============================================================================
   Design tokens
   One accent colour. Radii vary by element rather than one value everywhere.
   Shadows are layered by elevation rather than one grey blur under everything.
   ========================================================================= */

:root {
  --paper: #ffffff;
  --wash: #f6f7f9;
  --sunk: #eff1f5;
  --ink: #10131a;
  --mid: #5a6475;
  --faint: #99a1b0;
  --rule: #e7eaf0;
  --rule-soft: #f0f2f6;

  --brand: #4f46e5;
  --brand-ink: #4338ca;
  --brand-soft: #eef0fe;

  /* The Sirnia wordmark/lockup. Deliberately not --ink: solid black reads
     too heavy at the top of every page. */
  --wordmark: #444444;

  --live: #0e9f6e;
  --live-soft: #e6f6f0;
  --amber: #b4790f;
  --amber-soft: #fdf4e3;
  --danger: #c62f2f;
  --danger-soft: #fdecec;

  --r-sm: 6px;
  --r-md: 9px;
  --r-lg: 13px;
  --r-xl: 16px;

  --sh1: 0 1px 2px rgba(16, 19, 26, 0.04), 0 1px 3px rgba(16, 19, 26, 0.05);
  --sh2: 0 4px 14px rgba(16, 19, 26, 0.06), 0 1px 3px rgba(16, 19, 26, 0.04);
  --pop: 0 16px 40px rgba(16, 19, 26, 0.14), 0 2px 8px rgba(16, 19, 26, 0.06);

  /* Inter if the reader has it or it is dropped into public/fonts/; otherwise
     the platform's own UI face. No third-party request on any page — the
     public form page is loaded by strangers, often on a phone. */
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;

  font-family: var(--font);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15181e;
    --wash: #111419;
    --sunk: #0c0e12;
    --ink: #e9eaee;
    --mid: #9aa0ab;
    --faint: #6d7480;
    --rule: #272a31;
    --rule-soft: #1e2127;

    --brand: #7c74ff;
    --brand-ink: #a09aff;
    --brand-soft: #1e1b3a;

    /* #444444 is invisible on a dark surface; keep the same 'softer than
       pure contrast' intent by backing off from --ink instead. */
    --wordmark: #c9ccd4;

    --live: #3ddc97;
    --live-soft: #10301f;
    --amber: #e0b155;
    --amber-soft: #2e2413;
    --danger: #ff8a80;
    --danger-soft: #3a1715;

    --sh1: 0 1px 2px rgba(0, 0, 0, 0.3);
    --sh2: 0 4px 14px rgba(0, 0, 0, 0.35);
    --pop: 0 16px 40px rgba(0, 0, 0, 0.5);
  }
}

/* ============================================================================
   Base
   ========================================================================= */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--wash);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; line-height: 1.25; }
p { margin: 0; }

/* Every interactive thing shows where the keyboard is. */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .card, .nav, .q, .form-list li, .pi { transition: background-color .14s ease, border-color .14s ease, box-shadow .14s ease; }
}

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 20px; }
.hidden { display: none !important; }
.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;
}

/* ============================================================================
   Controls
   ========================================================================= */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 550;
  padding: 8px 14px; border-radius: var(--r-md);
  cursor: pointer; text-decoration: none; box-shadow: var(--sh1);
}
.btn:hover { background: var(--wash); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.primary {
  background: var(--brand); color: #fff; border-color: transparent;
  box-shadow: 0 1px 2px rgba(79, 70, 229, .3), 0 4px 12px rgba(79, 70, 229, .2);
}
.btn.primary:hover { background: var(--brand-ink); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--mid); }
.btn.ghost:hover { background: var(--wash); color: var(--ink); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; }

/* `input:not([type])` matters: inputs built with createElement("input") carry
   no type attribute, so an attribute selector alone would skip every control
   the editor and the renderer create at runtime. */
input:not([type]), input[type="text"], input[type="email"], input[type="number"],
input[type="date"], input[type="url"], textarea, select {
  width: 100%; font: inherit; font-size: 15px;
  padding: 10px 12px; border: 1px solid var(--rule);
  border-radius: var(--r-md); background: var(--paper); color: var(--ink);
}
textarea { min-height: 96px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--faint); }
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
}
.pill i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill.live { background: var(--live-soft); color: var(--live); }
.pill.draft { background: var(--amber-soft); color: var(--amber); }
.pill.closed { background: var(--sunk); color: var(--mid); }

.av {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; color: #fff;
  font-size: 11px; font-weight: 650; background: var(--mid);
}

.sw {
  width: 34px; height: 20px; border-radius: 999px; background: var(--rule);
  position: relative; flex-shrink: 0; border: none; cursor: pointer; padding: 0;
}
.sw::after {
  content: ""; position: absolute; top: 2.5px; left: 2.5px;
  width: 15px; height: 15px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.sw[aria-checked="true"] { background: var(--brand); }
.sw[aria-checked="true"]::after { left: auto; right: 2.5px; }

.note { font-size: 14px; margin-top: 14px; padding: 11px 13px; border-radius: var(--r-md); }
.note.ok { background: var(--live-soft); color: var(--live); }
.note.err { background: var(--danger-soft); color: var(--danger); }

/* ============================================================================
   Top bar
   ========================================================================= */

header.top, .topbar {
  background: var(--paper); border-bottom: 1px solid var(--rule);
}
header.top .wrap, .topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; height: 58px;
}
.topbar-inner { padding: 0 20px; }
.brand, .logo {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 16px; letter-spacing: -0.02em;
  color: var(--ink); text-decoration: none;
}
.mark {
  width: 26px; height: 26px; border-radius: var(--r-sm);
  background: linear-gradient(145deg, #6d62ff, var(--brand));
  display: grid; place-items: center; flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(79, 70, 229, .3);
}
.search {
  flex: 1; max-width: 340px; display: flex; align-items: center; gap: 8px;
  background: var(--wash); border: 1px solid var(--rule);
  border-radius: var(--r-md); padding: 0 11px;
}
.search input { border: none; background: none; padding: 8px 0; box-shadow: none; }
/* The ring moves to the wrapper rather than vanishing — this was the one
   interactive control on the signed-in pages with no focus indicator. */
.search input:focus { outline: none; }
.search:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }
.bar-right { display: flex; align-items: center; gap: 10px; }

/* ============================================================================
   Landing page
   ========================================================================= */

.hero { text-align: center; padding: 78px 0 36px; }
.hero h1 { font-size: 42px; letter-spacing: -0.03em; margin-bottom: 14px; }
.hero p.sub { color: var(--mid); font-size: 18px; max-width: 48ch; margin: 0 auto 28px; }
.auth-card {
  max-width: 400px; margin: 0 auto; background: var(--paper);
  border: 1px solid var(--rule); border-radius: var(--r-xl);
  padding: 24px; text-align: left; box-shadow: var(--sh2);
}
.auth-card h2 { font-size: 20px; margin-bottom: 4px; }
.auth-card p { color: var(--mid); font-size: 14px; margin-bottom: 16px; }
.auth-card .btn.primary { width: 100%; justify-content: center; margin-top: 12px; }

/* ============================================================================
   App shell
   ========================================================================= */

.app-shell { display: grid; grid-template-columns: 200px 1fr; min-height: calc(100vh - 58px); }
.rail, .sidebar { border-right: 1px solid var(--rule); background: var(--paper); padding: 14px 11px; }
.nav {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-md);
  color: var(--mid); font-size: 14px; font-weight: 500;
  text-decoration: none; margin-bottom: 2px; cursor: pointer;
}
.nav:hover { background: var(--wash); color: var(--ink); }
.nav.on { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.rail-cap, .sidebar h3 {
  font-size: 12px; color: var(--faint); font-weight: 600;
  padding: 0 10px; margin: 14px 0 7px;
}
.main { padding: 26px 28px; min-width: 0; }

/* ============================================================================
   Dashboard
   ========================================================================= */

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { font-size: 26px; letter-spacing: -0.03em; }
.page-head p { color: var(--mid); font-size: 14px; margin-top: 3px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 22px; }
.stat { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: 14px 16px; box-shadow: var(--sh1); }
.stat .k { font-size: 13px; color: var(--mid); margin-bottom: 4px; }
.stat .v { font-size: 24px; font-weight: 700; letter-spacing: -0.03em; display: flex; align-items: baseline; gap: 8px; }
.trend { font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: var(--r-sm); background: var(--live-soft); color: var(--live); }
.trend.down { background: var(--danger-soft); color: var(--danger); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 13px; }
.card {
  background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--r-lg); padding: 16px; box-shadow: var(--sh1);
  text-align: left; font: inherit; color: inherit; cursor: pointer; display: block; width: 100%;
}
.card:hover { box-shadow: var(--sh2); border-color: #d8dce6; }
.card .top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card h3 { font-size: 15px; font-weight: 620; letter-spacing: -0.01em; }
.card h3 a { color: inherit; text-decoration: none; }
/* Reveal-on-hover, but only where hovering exists. A touch device has no
   hover and no :focus-visible, so an opacity:0 button would still accept taps
   — an invisible control one stray tap from deleting a form and its
   responses. */
@media (hover: hover) and (pointer: fine) {
  .card .foot .btn.ghost.sm { opacity: 0; padding: 3px 6px; }
  .card:hover .foot .btn.ghost.sm,
  .card .foot .btn.ghost.sm:focus-visible { opacity: 1; }
}
.count { font-size: 22px; font-weight: 700; letter-spacing: -0.03em; }
.count small { font-size: 13px; font-weight: 500; color: var(--faint); letter-spacing: 0; margin-left: 5px; }
.count.none { color: var(--faint); }
.spark { margin: 10px 0 12px; height: 34px; }
.card .foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 11px; border-top: 1px solid var(--rule-soft); }
.faces { display: flex; }
.faces .av { width: 24px; height: 24px; font-size: 10px; border: 2px solid var(--paper); margin-left: -7px; }
.faces .av:first-child { margin-left: 0; }
.faces .av.more { background: var(--sunk); color: var(--mid); }
.when { font-size: 12px; color: var(--faint); }
.card .empty-line { color: var(--faint); font-size: 13px; padding: 6px 0 12px; }

.newtile {
  border: 1.5px dashed var(--rule); border-radius: var(--r-lg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 9px; color: var(--mid); min-height: 170px; background: transparent;
  font: inherit; cursor: pointer;
}
.newtile:hover { border-color: var(--brand); color: var(--brand-ink); }
.newtile .plus { width: 36px; height: 36px; border-radius: var(--r-md); background: var(--brand-soft); display: grid; place-items: center; }
.newtile b { font-size: 14px; }
.newtile span { font-size: 13px; color: var(--faint); }

.blank-slate { text-align: center; padding: 70px 20px; max-width: 46ch; margin: 0 auto; }
.blank-slate h2 { font-size: 22px; margin-bottom: 8px; }
.blank-slate p { color: var(--mid); margin-bottom: 22px; }

/* ============================================================================
   Editor
   ========================================================================= */

.ebar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 11px 18px; background: var(--paper); border-bottom: 1px solid var(--rule); }
.ename { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ename input {
  font-size: 15px; font-weight: 620; letter-spacing: -0.015em;
  border: 1px solid transparent; background: transparent; padding: 5px 8px; width: 220px;
}
.ename input:hover { border-color: var(--rule); }
.saved { font-size: 12px; color: var(--faint); display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.tabs { display: flex; gap: 2px; background: var(--wash); padding: 3px; border-radius: var(--r-md); border: 1px solid var(--rule); }
.tabs a {
  padding: 5px 14px; border-radius: var(--r-sm); font-size: 14px;
  font-weight: 550; color: var(--mid); text-decoration: none;
}
.tabs a.on { background: var(--paper); color: var(--ink); font-weight: 600; box-shadow: var(--sh1); }

.ebody { display: flex; min-height: calc(100vh - 116px); }
.canvas { flex: 1; min-width: 0; padding: 30px 24px; }
.sheet {
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-xl);
  box-shadow: var(--sh2); padding: 28px 30px 24px; max-width: 640px; margin: 0 auto;
}
.sheet .f-title { font-size: 25px; font-weight: 700; letter-spacing: -0.03em; border: none; padding: 2px 0; background: none; }
.sheet .f-sub { color: var(--mid); font-size: 14px; border: none; padding: 2px 0; background: none; margin-bottom: 20px; }

.q { position: relative; padding: 13px 14px; border-radius: var(--r-lg); border: 1px solid transparent; margin-bottom: 6px; }
.q:hover { background: var(--wash); }
.q.sel { border-color: var(--brand); background: var(--paper); box-shadow: 0 0 0 3px rgba(79, 70, 229, .1); }
.q .num {
  position: absolute; left: -32px; top: 15px; width: 22px; text-align: right;
  font-size: 12px; font-weight: 600; color: var(--faint);
  font-variant-numeric: tabular-nums; cursor: grab; background: none; border: none;
}
.q .num:active { cursor: grabbing; }
.q.dragging { opacity: .45; }
.q.drop-target { box-shadow: 0 -2px 0 var(--brand); }
.q .qlabel { font-size: 15px; font-weight: 600; border: none; background: none; padding: 0 0 7px; }
.q .req { color: var(--danger); font-weight: 600; }
.q .tools { position: absolute; right: 10px; top: 10px; display: flex; gap: 4px; opacity: 0; }
.q:hover .tools, .q.sel .tools, .q:focus-within .tools { opacity: 1; }
.q .preview { color: var(--faint); font-size: 14px; }
.q .opt { display: flex; align-items: center; gap: 9px; padding: 4px 0; }
.q .opt input { border: none; background: none; padding: 2px 0; font-size: 14px; }
.ring { width: 15px; height: 15px; border-radius: 50%; border: 1.5px solid var(--rule); flex-shrink: 0; }
.ring.sq { border-radius: 4px; }

.addq { margin-top: 16px; position: relative; }
.addline { display: flex; align-items: center; gap: 10px; }
.addline hr { flex: 1; border: 0; border-top: 1px solid var(--rule); }
.palette {
  margin-top: 9px; background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--r-lg); box-shadow: var(--pop); padding: 9px; max-width: 430px;
}
.pcap { font-size: 12px; color: var(--faint); padding: 3px 7px 7px; font-weight: 550; }
.pgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.pi {
  display: flex; align-items: center; gap: 9px; padding: 8px;
  border-radius: var(--r-sm); font-size: 14px; color: var(--ink);
  background: none; border: none; font: inherit; cursor: pointer; text-align: left; width: 100%;
}
.pi:hover { background: var(--brand-soft); }
.pi .ic { width: 26px; height: 26px; border-radius: var(--r-sm); background: var(--wash); border: 1px solid var(--rule); display: grid; place-items: center; flex-shrink: 0; }

.side { width: 250px; flex-shrink: 0; border-left: 1px solid var(--rule); background: var(--paper); padding: 18px; }
.side .cap { font-size: 12px; color: var(--faint); font-weight: 600; margin-bottom: 12px; }
.kind { display: flex; align-items: center; gap: 9px; padding: 9px 10px; border: 1px solid var(--rule); border-radius: var(--r-md); margin-bottom: 14px; font-size: 14px; font-weight: 550; }
.set { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--rule-soft); font-size: 14px; color: var(--mid); }
.set:last-child { border-bottom: none; }
.set label { margin: 0; font-weight: 500; font-size: 14px; color: var(--mid); }
.frozen { font-size: 12px; color: var(--faint); padding: 8px 0 0; }

/* ============================================================================
   Responses table
   ========================================================================= */

.tbl { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-lg); box-shadow: var(--sh1); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; color: var(--mid); font-weight: 600; padding: 11px 15px; background: var(--wash); border-bottom: 1px solid var(--rule); white-space: nowrap; }
td { padding: 12px 15px; border-top: 1px solid var(--rule-soft); color: var(--mid); vertical-align: top; }
tbody tr:hover { background: var(--wash); }
td.when-cell { white-space: nowrap; color: var(--faint); font-size: 13px; }

/* ============================================================================
   Public form page
   ========================================================================= */

.form-page { max-width: 620px; margin: 0 auto; padding: 48px 20px 80px; }
.form-card { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-xl); box-shadow: var(--sh2); padding: 34px 32px; }
.form-card h1 { font-size: 27px; letter-spacing: -0.03em; margin-bottom: 8px; }
.form-card .intro { color: var(--mid); margin-bottom: 28px; }
.field { margin-bottom: 22px; border: none; padding: 0; }
.field legend, .field > label { font-size: 16px; font-weight: 600; color: var(--ink); margin-bottom: 4px; padding: 0; }
.field .help { color: var(--mid); font-size: 14px; margin-bottom: 9px; }
.field .err { color: var(--danger); font-size: 14px; margin-top: 6px; }
.field [aria-invalid="true"] { border-color: var(--danger); }
.choice { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border: 1px solid var(--rule); border-radius: var(--r-md); margin-bottom: 7px; cursor: pointer; font-weight: 400; font-size: 15px; }
.choice:hover { background: var(--wash); }
.choice input { width: auto; margin: 0; accent-color: var(--brand); }
.stars { display: flex; gap: 4px; }
.star { background: none; border: none; cursor: pointer; padding: 3px; line-height: 0; color: var(--rule); }
.star.on { color: #f0b429; }
.form-foot { margin-top: 30px; display: flex; align-items: center; gap: 14px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.done { text-align: center; padding: 30px 10px; }
.done .tick { width: 52px; height: 52px; border-radius: 50%; background: var(--live-soft); color: var(--live); display: grid; place-items: center; margin: 0 auto 18px; }
.done h2 { font-size: 21px; margin-bottom: 8px; }
.done p { color: var(--mid); }

/* ============================================================================
   Narrow screens
   ========================================================================= */

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .rail, .sidebar, .side { display: none; }
  .main { padding: 20px 16px; }
  .stats { grid-template-columns: 1fr; }
  .canvas { padding: 20px 16px; }
  .sheet { padding: 22px 18px; }
  .q .num { position: static; display: inline-block; text-align: left; margin-bottom: 4px; }
  .tabs a { padding: 5px 10px; font-size: 13px; }
  .ename input { width: 130px; }
  .hero { padding: 48px 0 28px; }
  .hero h1 { font-size: 32px; }
  .form-page { padding: 28px 16px 60px; }
  .form-card { padding: 24px 18px; }
}

/* ============================================================================
   Brand lockup + the sign in / sign up switch
   ========================================================================= */

.brand, .logo { color: var(--wordmark); }
.brandmark { height: 22px; width: auto; display: block; }

.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: var(--sunk); border-radius: var(--r-md);
  padding: 4px; margin-bottom: 18px;
}
.seg {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font: inherit; font-size: 14px; font-weight: 600; color: var(--mid);
  padding: 8px 10px; border-radius: var(--r-sm);
}
.seg:hover { color: var(--wordmark); }
.seg.is-on {
  background: var(--paper); color: var(--wordmark); box-shadow: var(--sh1);
}
.seg:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
