/* Menon Survey — minimal black & white */

@view-transition { navigation: auto; }

:root {
  --bg: #ffffff;
  --bg-soft: #f6f6f5;
  --fg: #0a0a0a;
  --muted: #6b6b6b;
  --faint: #a3a3a3;
  --line: #e7e7e5;
  --line-strong: #cfcfcc;
  --inv-bg: #0a0a0a;
  --inv-fg: #ffffff;
  --ok: #1f7a4d;
  --err: #b42318;
  --radius: 14px;
  --ease: cubic-bezier(.2, .7, .1, 1);
  --font: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0a0a; --bg-soft: #141414; --fg: #f5f5f4; --muted: #9a9a98; --faint: #5c5c5a;
    --line: #232323; --line-strong: #353535; --inv-bg: #f5f5f4; --inv-fg: #0a0a0a;
    --ok: #4ade80; --err: #f87171; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0a0a; --bg-soft: #141414; --fg: #f5f5f4; --muted: #9a9a98; --faint: #5c5c5a;
  --line: #232323; --line-strong: #353535; --inv-bg: #f5f5f4; --inv-fg: #0a0a0a;
  --ok: #4ade80; --err: #f87171; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background-color .35s var(--ease), color .35s var(--ease);
}
a { color: inherit; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
a:hover { text-decoration-color: currentColor; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(26px, 4vw, 34px); }
h2 { font-size: 19px; }
h3 { font-size: 15px; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent;
  view-transition-name: topbar;
}
.brand { display: inline-flex; color: var(--fg); }
.logo { display: block; color: var(--fg); transition: color .35s var(--ease); }
.logo svg { height: 34px; width: auto; display: block; }
.nav { display: flex; align-items: center; gap: 6px; }
.nav a, .nav .linklike {
  padding: 7px 12px; border-radius: 999px; text-decoration: none; color: var(--muted);
  font-size: 14px; transition: color .2s, background-color .2s;
  background: none; border: 0; font: inherit; cursor: pointer;
}
.nav a:hover, .nav .linklike:hover { color: var(--fg); background: var(--bg-soft); }
.nav a.active { color: var(--fg); background: var(--bg-soft); }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--fg); cursor: pointer;
  transition: transform .4s var(--ease), border-color .2s;
}
.icon-btn:hover { border-color: var(--line-strong); }
.theme-toggle:active { transform: rotate(90deg) scale(.92); }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: block; }
}

/* thin working indicator at the very top */
.progress-line {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 50; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--fg), transparent);
  background-size: 40% 100%; background-repeat: no-repeat;
  opacity: 0; transition: opacity .3s;
}
body.busy .progress-line { opacity: 1; animation: sweep 1.3s var(--ease) infinite; }
@keyframes sweep { from { background-position: -40% 0; } to { background-position: 140% 0; } }

/* ---------- layout ---------- */
.container { max-width: 1040px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 40px) 96px; view-transition-name: page; }
.narrow { max-width: 440px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 12px 0 28px; }
.page-head p { margin: 0; }
.eyebrow { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; display: block; text-decoration: none; }
a.eyebrow:hover { color: var(--fg); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.stack > * + * { margin-top: 16px; }
.section { margin-top: 48px; }
.divider { height: 1px; background: var(--line); margin: 32px 0; border: 0; }

.card {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; background: var(--bg);
  transition: border-color .25s, transform .35s var(--ease), box-shadow .35s var(--ease);
}
a.card { display: block; text-decoration: none; }
a.card:hover { border-color: var(--line-strong); transform: translateY(-2px); box-shadow: 0 12px 30px -18px rgba(0,0,0,.25); }
.card h2 { margin-bottom: 6px; }

/* ---------- reveal animation ---------- */
.reveal { opacity: 0; transform: translateY(10px); animation: reveal .6s var(--ease) forwards; animation-delay: calc(var(--i, 0) * 45ms); }
@keyframes reveal { to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .reveal { animation: none; opacity: 1; transform: none; }
  @view-transition { navigation: none; }
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
::view-transition-old(page) { animation: .22s var(--ease) both fade-out; }
::view-transition-new(page) { animation: .38s var(--ease) both fade-up; }
@keyframes fade-out { to { opacity: 0; transform: translateY(-4px); } }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 18px; border-radius: 999px; border: 1px solid var(--fg);
  background: var(--inv-bg); color: var(--inv-fg); font: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .2s var(--ease), opacity .2s, background-color .2s, color .2s;
}
.btn:hover { opacity: .88; }
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .35; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--fg); border-color: var(--line-strong); }
.btn-ghost:hover { border-color: var(--fg); opacity: 1; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-danger { background: transparent; color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, transparent); }
.btn-danger:hover { border-color: var(--err); opacity: 1; }
form.inline { display: inline; }

label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%; font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 12px;
  transition: border-color .2s, box-shadow .2s;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--fg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fg) 10%, transparent); }
.field + .field { margin-top: 18px; }

/* ---------- flashes ---------- */
.flashes { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 40px)); }
.flash {
  padding: 12px 16px; border-radius: 12px; background: var(--inv-bg); color: var(--inv-fg);
  font-size: 14px; box-shadow: 0 16px 40px -16px rgba(0,0,0,.4);
  animation: toast-in .45s var(--ease) both, toast-out .5s var(--ease) 5.5s forwards;
}
.flash-error { background: var(--err); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); visibility: hidden; } }

/* ---------- badges, bars ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; border: 1px solid var(--line-strong); color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge-open, .badge-completed, .badge-done { color: var(--fg); border-color: var(--fg); }
.badge-started, .badge-running { color: var(--fg); }
.badge-running::before { animation: pulse 1s ease-in-out infinite; }
.badge-failed { color: var(--err); border-color: var(--err); }
@keyframes pulse { 50% { opacity: .15; transform: scale(.7); } }

.bar { height: 4px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 14px; }
.bar > span { display: block; height: 100%; width: 0; background: var(--fg); border-radius: inherit; animation: grow 1s var(--ease) .15s forwards; }
@keyframes grow { to { width: var(--w); } }
.stats { display: flex; gap: 18px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.stats strong { color: var(--fg); font-weight: 600; }

.dots { display: inline-flex; gap: 3px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--fg); opacity: .25; }
.score { display: inline-flex; gap: 3px; vertical-align: middle; }
.score i { width: 14px; height: 4px; border-radius: 2px; background: var(--line-strong); }
.score i.on { background: var(--fg); }

/* ---------- tables ---------- */
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; background: var(--bg-soft); }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background-color .2s; }
tbody tr:hover { background: var(--bg-soft); }
td.actions { text-align: right; white-space: nowrap; }
td.actions > * { margin-left: 4px; }
.linkcell { display: flex; align-items: center; gap: 6px; min-width: 220px; }
.linkcell code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; color: var(--muted); }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 64px 24px; border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--muted); }
.empty h2 { color: var(--fg); }

/* ---------- question editor ---------- */
.q-list { counter-reset: q; display: grid; gap: 12px; }
.q-item {
  position: relative; display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: start;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  animation: reveal .45s var(--ease) both; opacity: 0; transform: translateY(8px);
}
.q-item.removing { animation: collapse .3s var(--ease) forwards; }
@keyframes collapse { to { opacity: 0; transform: scale(.98); } }
.q-num { counter-increment: q; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line-strong); display: grid; place-items: center; font-size: 13px; font-weight: 600; }
.q-num::before { content: counter(q); }
.q-item textarea { min-height: 52px; }
.q-item .guidance { margin-top: 8px; font-size: 13.5px; min-height: 40px; }
.q-tools { display: flex; flex-direction: column; gap: 4px; }
.q-tools button { width: 30px; height: 30px; border-radius: 8px; border: 1px solid transparent; background: none; color: var(--muted); cursor: pointer; }
.q-tools button:hover { border-color: var(--line); color: var(--fg); }

/* ---------- login ---------- */
.auth { min-height: calc(100vh - 140px); display: grid; place-items: center; }
.auth .card { width: 100%; max-width: 400px; padding: 32px; }

/* ---------- transcript (admin) ---------- */
.transcript { display: grid; gap: 10px; }
.transcript .msg { max-width: 82%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; }
.transcript .msg.assistant { background: var(--bg-soft); border-bottom-left-radius: 4px; }
.transcript .msg.user { background: var(--inv-bg); color: var(--inv-fg); justify-self: end; border-bottom-right-radius: 4px; }
.answer { border-top: 1px solid var(--line); padding: 18px 0; }
.answer:first-child { border-top: 0; padding-top: 0; }
blockquote { margin: 8px 0; padding: 2px 0 2px 12px; border-left: 2px solid var(--fg); color: var(--muted); font-style: italic; }

/* ================= Respondent chat ================= */
body.chat-page { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
body.chat-page main { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; max-width: 760px; margin: 0 auto; padding: 0 clamp(12px, 4vw, 24px); }
.chat-intro { text-align: center; padding: 20px 8px 20px; }
.chat-intro h1 { font-size: clamp(22px, 3.5vw, 28px); }
.chat-intro p { color: var(--muted); max-width: 560px; margin: 0 auto; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 20px 4px 24px; scroll-behavior: smooth; mask-image: linear-gradient(to bottom, transparent 0, #000 24px); }
.chat { display: flex; flex-direction: column; gap: 14px; }
.bubble {
  max-width: 85%; padding: 12px 16px; border-radius: 20px; white-space: pre-wrap; word-wrap: break-word;
  animation: bubble-in .45s var(--ease) both;
}
.bubble.assistant { align-self: flex-start; background: var(--bg-soft); border-bottom-left-radius: 6px; }
.bubble.user { align-self: flex-end; background: var(--inv-bg); color: var(--inv-fg); border-bottom-right-radius: 6px; }
.bubble.streaming::after { content: ""; display: inline-block; width: 2px; height: 1em; background: currentColor; margin-left: 2px; vertical-align: -2px; animation: caret 1s steps(2) infinite; }
.bubble.error { background: transparent; border: 1px solid var(--err); color: var(--err); }
@keyframes caret { 50% { opacity: 0; } }
@keyframes bubble-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }

.typing { align-self: flex-start; display: inline-flex; gap: 5px; padding: 16px 18px; border-radius: 20px; border-bottom-left-radius: 6px; background: var(--bg-soft); animation: bubble-in .35s var(--ease) both; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--fg); animation: bounce 1.2s var(--ease) infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .25; } 30% { transform: translateY(-5px); opacity: 1; } }

.composer-wrap { padding: 12px 0 max(16px, env(safe-area-inset-bottom)); }
.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px 8px 18px;
  border: 1px solid var(--line-strong); border-radius: 26px; background: var(--bg);
  transition: border-color .2s, box-shadow .3s var(--ease);
}
.composer:focus-within { border-color: var(--fg); box-shadow: 0 10px 30px -18px rgba(0,0,0,.35); }
.composer textarea { border: 0; padding: 8px 0; min-height: 24px; max-height: 180px; resize: none; background: transparent; box-shadow: none !important; line-height: 1.5; }
.composer .send { width: 40px; height: 40px; border-radius: 50%; padding: 0; flex: none; }
.composer .send svg { transition: transform .3s var(--ease); }
.composer .send:not([disabled]):hover svg { transform: translateY(-2px); }
.composer-note { text-align: center; font-size: 12px; color: var(--faint); margin-top: 8px; }
body.busy .composer { opacity: .7; }

.done-card { text-align: center; padding: 28px 20px; margin: 12px 0 24px; border: 1px solid var(--line); border-radius: var(--radius); animation: bubble-in .6s var(--ease) both; }
.check { width: 44px; height: 44px; margin: 0 auto 10px; border-radius: 50%; display: grid; place-items: center; background: var(--inv-bg); color: var(--inv-fg); }
.check svg path { stroke-dasharray: 30; stroke-dashoffset: 30; animation: draw .6s var(--ease) .25s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* ---------- error page ---------- */
.error-page { min-height: calc(100vh - 160px); display: grid; place-items: center; text-align: center; }
.error-page .code { font-size: 64px; font-weight: 700; letter-spacing: -0.04em; line-height: 1; }

@media (max-width: 640px) {
  .hide-sm { display: none; }
  th, td { padding: 10px 12px; }
  .bubble { max-width: 92%; }
}
