/* ---------- tokens ---------- */
:root {
  --bg:            #f7f6f3;
  --surface:       #ffffff;
  --surface-2:     #fbfaf8;
  --sunken:        #f1efea;
  --line:          #e3e0d8;
  --line-strong:   #d2cec3;
  --ink:           #1c1b18;
  --ink-2:         #55524a;
  --ink-3:         #858175;
  --accent:        #1f5f5b;
  --accent-ink:    #ffffff;
  --accent-soft:   #e6efee;
  --accent-line:   #bcd6d3;
  --amber:         #9a6b12;
  --amber-soft:    #fbf2df;
  --danger:        #a33228;
  --danger-soft:   #fbeceb;
  --radius:        10px;
  --radius-lg:     14px;
  --shadow-sm:     0 1px 2px rgba(28,27,24,.06), 0 1px 1px rgba(28,27,24,.04);
  --shadow-md:     0 4px 16px rgba(28,27,24,.08), 0 1px 3px rgba(28,27,24,.05);
  --shadow-lg:     0 18px 48px rgba(28,27,24,.14), 0 2px 8px rgba(28,27,24,.06);
  --sans:          'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif:         'Source Serif 4', Georgia, 'Times New Roman', serif;
  --topbar-h:      58px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #16161a;
    --surface:     #1e1e23;
    --surface-2:   #23232a;
    --sunken:      #191920;
    --line:        #32323b;
    --line-strong: #43434f;
    --ink:         #eceae6;
    --ink-2:       #b3b0a9;
    --ink-3:       #85827b;
    --accent:      #6fc0b8;
    --accent-ink:  #10201f;
    --accent-soft: #1d2f2e;
    --accent-line: #2f4f4c;
    --amber:       #d9a441;
    --amber-soft:  #2c2415;
    --danger:      #e08a80;
    --danger-soft: #33201e;
    --shadow-sm:   0 1px 2px rgba(0,0,0,.4);
    --shadow-md:   0 4px 16px rgba(0,0,0,.45);
    --shadow-lg:   0 18px 48px rgba(0,0,0,.55);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- boot ---------- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 20px; height: 20px; border-radius: 5px; flex: none;
  background: var(--accent);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 5px 5px auto auto;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent-ink);
}
.brand-name { font-weight: 700; letter-spacing: -.015em; font-size: 16px; }
.brand-sm .brand-name { font-size: 15px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 9px 16px;
  font-size: 14px; font-weight: 550; cursor: pointer; background: none;
  transition: background .13s, border-color .13s, color .13s, opacity .13s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { border-color: var(--line-strong); color: var(--ink-2); background: var(--surface); }
.btn-ghost:hover:not(:disabled) { border-color: var(--ink-3); color: var(--ink); }
.btn-quiet { color: var(--ink-3); padding: 6px 10px; }
.btn-quiet:hover { color: var(--ink); background: var(--sunken); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }

.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px;
  border: none; background: none; border-radius: 8px; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
.icon-btn svg { width: 19px; height: 19px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.field > span { font-size: 13px; font-weight: 550; color: var(--ink-2); }
.field small { font-size: 12px; color: var(--ink-3); }
.field input, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong);
  border-radius: 8px; background: var(--surface); transition: border-color .13s, box-shadow .13s;
}
.field input:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error {
  margin: 0 0 13px; padding: 9px 12px; border-radius: 8px;
  background: var(--danger-soft); color: var(--danger); font-size: 13px;
  border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent);
}

/* ---------- auth / setup ---------- */
.auth-view { min-height: 100vh; display: grid; place-items: center; padding: 28px 20px 56px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 30px 30px 32px; box-shadow: var(--shadow-md);
}
.auth-card-wide { max-width: 560px; }
.auth-lede { color: var(--ink-2); font-size: 14px; margin: 14px 0 20px; }

.tabs { display: flex; gap: 3px; background: var(--sunken); padding: 3px; border-radius: 9px; margin-bottom: 22px; }
.tab {
  flex: 1; border: none; background: none; padding: 8px; border-radius: 7px;
  font-size: 14px; font-weight: 550; color: var(--ink-3); cursor: pointer;
}
.tab.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.setup-title { font-family: var(--serif); font-size: 25px; font-weight: 600; margin: 16px 0 0; letter-spacing: -.01em; }
.choice-set { border: none; padding: 0; margin: 0 0 22px; }
.choice-set legend { font-size: 13px; font-weight: 600; color: var(--ink-2); padding: 0; margin-bottom: 10px; }
.choice {
  display: flex; gap: 11px; align-items: flex-start; padding: 13px 14px; cursor: pointer;
  border: 1px solid var(--line-strong); border-radius: 10px; margin-bottom: 8px;
  background: var(--surface); transition: border-color .13s, background .13s;
}
.choice:hover { border-color: var(--ink-3); }
.choice input { margin: 3px 0 0; accent-color: var(--accent); flex: none; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice-body { display: flex; flex-direction: column; gap: 2px; }
.choice-body strong { font-size: 14px; font-weight: 600; }
.choice-body em { font-style: normal; font-size: 13px; color: var(--ink-2); }
.setup-actions { display: flex; justify-content: space-between; gap: 12px; }

/* ---------- topbar ---------- */
.app-view, .admin-view { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 13px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-context {
  font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; flex: 1; min-width: 0;
}
.topbar-context b { color: var(--ink); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex: none; }
.nav-toggle { display: none; }

.save-state { font-size: 12px; color: var(--ink-3); min-width: 52px; text-align: right; }
.save-state.is-saving { color: var(--amber); }
.save-state.is-saved { color: var(--accent); }

.menu { position: relative; }
.avatar-btn { border: none; background: none; padding: 0; cursor: pointer; border-radius: 50%; }
.avatar {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 650;
  letter-spacing: .02em;
}
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 210px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px;
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 30;
}
.menu-head { padding: 9px 11px 11px; border-bottom: 1px solid var(--line); margin-bottom: 5px; display: grid; gap: 1px; }
.menu-head strong { font-size: 14px; }
.menu-head span { font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; }
.menu-item {
  display: block; width: 100%; text-align: left; border: none; background: none;
  padding: 8px 11px; border-radius: 7px; font-size: 14px; cursor: pointer; color: var(--ink-2);
}
.menu-item:hover { background: var(--sunken); color: var(--ink); }

/* ---------- layout ---------- */
.layout { flex: 1; display: grid; grid-template-columns: 324px 1fr; min-height: 0; }

.sidebar {
  border-right: 1px solid var(--line); background: var(--surface-2);
  display: flex; flex-direction: column; min-height: 0;
  height: calc(100vh - var(--topbar-h)); position: sticky; top: var(--topbar-h);
}

/* ---------- progress ---------- */
.progress-block { padding: 17px 18px 15px; border-bottom: 1px solid var(--line); flex: none; }
.progress-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 9px; }
.progress-count { font-size: 13px; color: var(--ink-2); }
.progress-count b { color: var(--ink); font-weight: 650; font-size: 15px; }
.progress-pct { font-size: 12px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.progress-track { height: 5px; background: var(--sunken); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .3s ease; }
.progress-meta { font-size: 12px; color: var(--ink-3); margin-top: 9px; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 4px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex: none; }
.chip {
  flex: 1 1 auto; text-align: center;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  padding: 4px 8px; border-radius: 20px; font-size: 12px; font-weight: 500; cursor: pointer;
  white-space: nowrap;
  transition: background .13s, border-color .13s, color .13s;
}
.chip:hover { border-color: var(--ink-3); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- question list ---------- */
.qlist { overflow-y: auto; flex: 1; padding: 8px 0 32px; scrollbar-width: thin; }
.qgroup-head {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2);
  padding: 11px 18px 7px; font-size: 11px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--ink-3);
  display: flex; justify-content: space-between; gap: 8px; align-items: baseline;
  border-bottom: 1px solid var(--line);
}
.qgroup-head span { letter-spacing: 0; text-transform: none; font-weight: 500; font-variant-numeric: tabular-nums; }

.qrow {
  display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left;
  padding: 8px 18px; border: none; background: none; cursor: pointer;
  border-left: 2px solid transparent; transition: background .1s;
}
.qrow:hover { background: var(--sunken); }
.qrow.is-current { background: var(--accent-soft); border-left-color: var(--accent); }
.qdot {
  width: 8px; height: 8px; border-radius: 50%; flex: none; margin-top: 7px;
  border: 1.5px solid var(--line-strong); background: transparent;
}
.qrow.is-done .qdot { background: var(--accent); border-color: var(--accent); }
.qrow.is-na .qdot { background: var(--ink-3); border-color: var(--ink-3); }
.qtext { min-width: 0; flex: 1; }
.qid { font-size: 11px; font-weight: 650; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.qrow.is-current .qid { color: var(--accent); }
.qsnippet {
  font-size: 12.5px; color: var(--ink-2); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.qrow.is-current .qsnippet { color: var(--ink); }
.qclip { flex: none; margin-top: 5px; color: var(--accent); }
.qclip svg { width: 13px; height: 13px; display: block; }
.qlist-empty { padding: 30px 18px; text-align: center; color: var(--ink-3); font-size: 13px; }

/* ---------- main / question card ---------- */
.main { min-width: 0; overflow-y: auto; height: calc(100vh - var(--topbar-h)); }
.qcard { max-width: 720px; margin: 0 auto; padding: 34px 28px 88px; }

.qcrumb {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 12px; color: var(--ink-3); margin-bottom: 16px;
}
.qcrumb b { color: var(--ink-2); font-weight: 600; }
.qcrumb .sep { color: var(--line-strong); }

.badge {
  display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: .01em;
  background: var(--sunken); color: var(--ink-2); border: 1px solid var(--line);
}
.badge-doc { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

.qposition { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; margin-left: auto; }

.qtitle {
  font-family: var(--serif); font-size: 25px; line-height: 1.35; font-weight: 600;
  letter-spacing: -.011em; margin: 0 0 14px;
}
.qcontext {
  font-size: 13.5px; color: var(--ink-2); padding: 11px 14px; background: var(--surface-2);
  border: 1px solid var(--line); border-left: 2px solid var(--line-strong);
  border-radius: 0 8px 8px 0; margin-bottom: 22px;
}
.qcontext b { color: var(--ink); font-weight: 600; }

.answer-label { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 7px; gap: 12px; }
.answer-label span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.answer-hint { font-size: 12px; color: var(--ink-3); }
.answer-box {
  width: 100%; min-height: 168px; resize: vertical; padding: 13px 15px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface);
  font-size: 15px; line-height: 1.6; transition: border-color .13s, box-shadow .13s;
}
.answer-box:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.answer-box:disabled { background: var(--sunken); color: var(--ink-2); }

.na-row { display: flex; align-items: center; gap: 8px; margin-top: 11px; font-size: 13px; color: var(--ink-2); }
.na-row input { accent-color: var(--accent); width: 15px; height: 15px; }

/* ---------- evidence ---------- */
.evidence { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 22px; }
.evidence-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.evidence-head h3 { font-size: 14px; font-weight: 650; margin: 0; }
.evidence-sub { font-size: 12.5px; color: var(--ink-3); margin: 0 0 13px; }

.doc-hint {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: 9px;
  background: var(--amber-soft); border: 1px solid color-mix(in srgb, var(--amber) 26%, transparent);
  margin-bottom: 14px; font-size: 13px; color: var(--ink-2);
}
.doc-hint svg { width: 15px; height: 15px; flex: none; margin-top: 2px; color: var(--amber); }
.doc-hint b { color: var(--ink); font-weight: 600; display: block; margin-bottom: 2px; }

.dropzone {
  border: 1.5px dashed var(--line-strong); border-radius: 10px; padding: 20px;
  text-align: center; cursor: pointer; transition: border-color .13s, background .13s;
  background: var(--surface-2);
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone p { margin: 0; font-size: 13.5px; color: var(--ink-2); }
.dropzone p b { color: var(--accent); font-weight: 600; }
.dropzone small { display: block; margin-top: 3px; font-size: 12px; color: var(--ink-3); }

.filelist { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 7px; }
.fileitem {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
}
.fileicon { width: 15px; height: 15px; flex: none; color: var(--ink-3); }
.filemeta { min-width: 0; flex: 1; }
.filemeta a { color: var(--ink); font-size: 13.5px; font-weight: 500; text-decoration: none; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filemeta a:hover { color: var(--accent); text-decoration: underline; }
.filemeta small { font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.fileitem.is-uploading { opacity: .6; }

/* ---------- footer nav ---------- */
.qnav { display: flex; justify-content: space-between; gap: 12px; margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--line); }
.qnav-right { display: flex; gap: 9px; }

.finish-card {
  margin-top: 30px; padding: 22px; border-radius: 12px;
  border: 1px solid var(--accent-line); background: var(--accent-soft); text-align: center;
}
.finish-card h3 { font-family: var(--serif); font-size: 19px; margin: 0 0 6px; font-weight: 600; }
.finish-card p { font-size: 13.5px; color: var(--ink-2); margin: 0 0 15px; }

.submitted-banner {
  display: flex; gap: 10px; align-items: center; padding: 12px 15px; border-radius: 10px;
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  font-size: 13.5px; color: var(--ink-2); margin-bottom: 22px;
}
.submitted-banner b { color: var(--ink); }

/* ---------- admin ---------- */
.admin-wrap { flex: 1; padding: 26px 22px 60px; max-width: 1180px; margin: 0 auto; width: 100%; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 860px; }
.admin-table th {
  text-align: left; padding: 12px 15px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-3); border-bottom: 1px solid var(--line); font-weight: 700;
}
.admin-table td { padding: 13px 15px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table .who strong { display: block; font-weight: 600; }
.admin-table .who span { font-size: 12px; color: var(--ink-3); }
.mini-track { width: 110px; height: 5px; background: var(--sunken); border-radius: 3px; overflow: hidden; margin-bottom: 4px; }
.mini-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.mini-label { font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.pill-open { background: var(--amber-soft); color: var(--amber); }
.pill-done { background: var(--accent-soft); color: var(--accent); }
.admin-empty { padding: 40px; text-align: center; color: var(--ink-3); }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 9px;
  font-size: 13.5px; box-shadow: var(--shadow-lg); z-index: 60; max-width: 90vw;
}
.toast.is-error { background: var(--danger); color: #fff; }

/* ---------- responsive ---------- */
.sidebar-scrim { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .nav-toggle { display: grid; }
  .sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: min(324px, 86vw);
    z-index: 25; transform: translateX(-100%); transition: transform .2s ease;
    height: auto; box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-scrim {
    display: block; position: fixed; inset: var(--topbar-h) 0 0 0;
    background: rgba(0,0,0,.32); z-index: 24;
  }
  .main { height: auto; }
  .qcard { padding: 26px 20px 80px; }
  .qtitle { font-size: 21px; }
  .topbar-context { display: none; }
}

@media (max-width: 520px) {
  .field-row { grid-template-columns: 1fr; }
  .auth-card { padding: 24px 20px 26px; }
  .qnav { flex-direction: column-reverse; }
  .qnav-right { flex-direction: column; }
  .qnav .btn { width: 100%; }
}
