/* styles.css — shared design system.
   Palette: "fieldwork" — paper white, ink, deep pine accent. No external fonts
   or CDNs by design: participant page loads must not leak IPs to third parties. */

:root {
  --paper: #FAFAF7;
  --card: #FFFFFF;
  --ink: #1C2321;
  --ink-soft: #4A544F;
  --line: #DDDDD4;
  --pine: #175B4E;
  --pine-dark: #0E4038;
  --pine-tint: #E7F0ED;
  --amber: #B7791F;
  --amber-tint: #FBF3E4;
  --red: #B3382C;
  --red-tint: #F9ECEA;
  --blue: #2C5282;
  --chat-bot: #EFF2EF;
  --chat-user: #175B4E;
  --radius: 10px;
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Consolas", monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.55;
  font-size: 16px;
}

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0.6em 0; }
a { color: var(--pine); }

:focus-visible { outline: 3px solid var(--pine); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Buttons & inputs ---------- */
button, .btn {
  font: inherit; cursor: pointer;
  border: 1px solid var(--pine); background: var(--pine); color: #fff;
  padding: 10px 18px; border-radius: var(--radius);
  font-weight: 600; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { background: var(--pine-dark); border-color: var(--pine-dark); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary, .btn.secondary { background: transparent; color: var(--pine); }
button.secondary:hover { background: var(--pine-tint); }
button.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); padding: 6px 10px; }
button.ghost:hover { background: var(--pine-tint); color: var(--pine-dark); }
button.danger { background: transparent; border-color: var(--red); color: var(--red); }
button.danger:hover { background: var(--red-tint); }
button.small { padding: 5px 10px; font-size: 0.85rem; border-radius: 7px; }

label { display: block; font-weight: 600; margin: 14px 0 5px; }
label .req { color: var(--red); }
input[type="text"], input[type="email"], input[type="number"], input[type="url"],
textarea, select {
  font: inherit; width: 100%;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--ink);
}
input:focus, textarea:focus, select:focus { border-color: var(--pine); outline: 2px solid var(--pine); outline-offset: 0; }
textarea { min-height: 90px; resize: vertical; }
.hint { color: var(--ink-soft); font-size: 0.86rem; margin-top: 4px; }
.field-error { color: var(--red); font-size: 0.9rem; margin-top: 5px; font-weight: 600; }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--red); }

.code-chip { font-family: var(--mono); background: var(--pine-tint); color: var(--pine-dark); padding: 2px 7px; border-radius: 6px; font-size: 0.92em; letter-spacing: 0.04em; }

/* ---------- Notices ---------- */
.notice { padding: 12px 15px; border-radius: var(--radius); margin: 12px 0; border: 1px solid; }
.notice.error { background: var(--red-tint); border-color: var(--red); color: #7C2018; }
.notice.warn { background: var(--amber-tint); border-color: var(--amber); color: #7A5210; }
.notice.ok { background: var(--pine-tint); border-color: var(--pine); color: var(--pine-dark); }

.test-banner {
  background: var(--amber); color: #fff; text-align: center;
  padding: 7px 12px; font-weight: 700; font-size: 0.9rem; letter-spacing: 0.03em;
}

/* ================= PARTICIPANT ================= */
.p-shell { max-width: 700px; margin: 0 auto; padding: 20px 16px 60px; }
.p-header { padding: 18px 0 6px; }
.p-header h1 { margin: 0; font-size: 1.25rem; }

/* Signature: the progress rule — a measurement ruler with ticks. */
.progress-rule { margin: 14px 0 26px; }
.progress-rule .track {
  position: relative; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden;
}
.progress-rule .fill {
  position: absolute; inset: 0 auto 0 0; background: var(--pine);
  border-radius: 4px; transition: width 300ms ease;
}
.progress-rule .ticks { display: flex; justify-content: space-between; margin-top: 3px; }
.progress-rule .tick { width: 1px; height: 5px; background: var(--line); }
.progress-rule .label { font-size: 0.8rem; color: var(--ink-soft); text-align: right; margin-top: 2px; font-variant-numeric: tabular-nums; }

.page-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 26px 24px; }
@media (max-width: 480px) { .page-card { padding: 20px 15px; border-radius: 12px; } }
.page-card h2 { margin-top: 0; }
.page-body { white-space: pre-wrap; }
.page-media img { max-width: 100%; border-radius: var(--radius); margin: 10px 0; }
.page-media video, .page-media iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: var(--radius); margin: 10px 0; background: #000; }

.q-block { margin: 26px 0; padding-top: 18px; border-top: 1px solid var(--line); }
.q-block:first-of-type { border-top: 0; padding-top: 0; }
.q-prompt { font-weight: 600; margin-bottom: 10px; }
.choice-row { display: flex; align-items: flex-start; gap: 10px; padding: 9px 10px; border-radius: 8px; margin: 2px 0; }
.choice-row:hover { background: var(--pine-tint); }
.choice-row input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--pine); flex: none; }
.choice-row label { margin: 0; font-weight: 400; cursor: pointer; flex: 1; }

.likert { display: flex; gap: 4px; flex-wrap: wrap; }
.likert .choice-col {
  flex: 1; min-width: 74px; text-align: center; border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 5px; cursor: pointer; font-size: 0.86rem; background: var(--card);
}
.likert .choice-col:hover { border-color: var(--pine); }
.likert .choice-col.selected { background: var(--pine); color: #fff; border-color: var(--pine); font-weight: 600; }
.likert input { position: absolute; opacity: 0; }

.matrix-wrap { overflow-x: auto; }
table.matrix { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
table.matrix th, table.matrix td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--line); }
table.matrix th[scope="row"] { text-align: left; font-weight: 500; }
table.matrix input { width: 18px; height: 18px; accent-color: var(--pine); }

.slider-wrap { padding: 6px 2px; }
.slider-wrap input[type="range"] { width: 100%; accent-color: var(--pine); }
.slider-labels { display: flex; justify-content: space-between; font-size: 0.84rem; color: var(--ink-soft); }
.slider-value { text-align: center; font-weight: 700; color: var(--pine-dark); font-variant-numeric: tabular-nums; }

.rank-list { list-style: none; padding: 0; margin: 0; }
.rank-item {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; margin: 6px 0;
}
.rank-item .rank-num { font-weight: 700; color: var(--pine); min-width: 1.4em; font-variant-numeric: tabular-nums; }
.rank-item .rank-label { flex: 1; }
.rank-btns { display: flex; gap: 4px; }
.rank-btns button { padding: 3px 9px; font-size: 1rem; line-height: 1; }

.nav-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 28px; }
.nav-row .spacer { flex: 1; }

/* ---------- Chatbot ---------- */
.chat-frame {
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  display: flex; flex-direction: column; background: var(--card);
  height: min(520px, 62vh); margin: 14px 0;
}
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 11px 15px;
  border-bottom: 1px solid var(--line); background: #FDFDFB;
}
.chat-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 30% 30%, #2E8C77, var(--pine-dark));
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 0.9rem;
}
.chat-title { font-weight: 700; }
.chat-status { font-size: 0.78rem; color: var(--ink-soft); display: flex; align-items: center; gap: 5px; }
.chat-status .dot { width: 7px; height: 7px; border-radius: 50%; background: #3BA55D; }

.chat-log { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.bubble {
  max-width: 82%; padding: 10px 14px; border-radius: 16px;
  white-space: pre-wrap; overflow-wrap: break-word; font-size: 0.96rem;
}
.bubble.bot { background: var(--chat-bot); color: var(--ink); align-self: flex-start; border-bottom-left-radius: 5px; }
.bubble.user { background: var(--chat-user); color: #fff; align-self: flex-end; border-bottom-right-radius: 5px; }

.typing { display: inline-flex; gap: 4px; padding: 13px 16px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: #9AA5A0; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%, 70%, 100% { opacity: 0.3; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-3px); } }

.chat-input-row { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: #FDFDFB; }
.chat-input-row textarea { flex: 1; min-height: 44px; max-height: 110px; border-radius: 12px; }
.chat-input-row button { border-radius: 12px; align-self: flex-end; }
.chat-done { text-align: center; color: var(--ink-soft); font-size: 0.88rem; padding: 9px; border-top: 1px solid var(--line); background: #FDFDFB; }
.chat-counter { font-size: 0.78rem; color: var(--ink-soft); margin-left: auto; font-variant-numeric: tabular-nums; }

/* Entry screen */
.entry-card { max-width: 430px; margin: 9vh auto 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 30px 26px; }
.entry-card h1 { margin-top: 0; }
.entry-card input { font-family: var(--mono); letter-spacing: 0.06em; text-transform: uppercase; }
.done-screen { text-align: center; padding: 60px 20px; }
.done-screen .mark { font-size: 2.6rem; color: var(--pine); }

/* ================= ADMIN ================= */
.a-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
@media (max-width: 860px) { .a-shell { grid-template-columns: 1fr; } .a-side { position: static; border-right: 0; border-bottom: 1px solid var(--line); } }
.a-side { border-right: 1px solid var(--line); background: var(--card); padding: 18px 14px; }
.a-side .brand { font-weight: 800; letter-spacing: -0.02em; margin-bottom: 18px; display: block; color: var(--ink); text-decoration: none; }
.a-side .brand span { color: var(--pine); }
.a-nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink-soft); text-decoration: none; margin: 2px 0; font-weight: 500; }
.a-nav a:hover { background: var(--pine-tint); color: var(--pine-dark); }
.a-nav a.active { background: var(--pine); color: #fff; }
.a-main { padding: 24px 28px 80px; min-width: 0; }
@media (max-width: 640px) { .a-main { padding: 16px 12px 60px; } }

.a-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.a-head h1 { margin: 0; flex: 1; min-width: 200px; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; }
.badge.draft { background: #EDEDE6; color: var(--ink-soft); }
.badge.live { background: var(--pine-tint); color: var(--pine-dark); }
.badge.closed { background: var(--red-tint); color: var(--red); }
.badge.locked { background: var(--amber-tint); color: #7A5210; }
.badge.test { background: var(--amber); color: #fff; }
.badge.flag { background: var(--red); color: #fff; }

.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--line); margin: 18px 0; flex-wrap: wrap; }
.tabs a { padding: 9px 15px; text-decoration: none; color: var(--ink-soft); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs a.active { color: var(--pine-dark); border-bottom-color: var(--pine); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin: 14px 0; }
.card h3 { margin-top: 0; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 180px; }

table.data { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.data th { text-align: left; padding: 8px 10px; border-bottom: 2px solid var(--line); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:hover td { background: #FCFCF9; }
.table-scroll { overflow-x: auto; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin: 14px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat .n { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; color: var(--pine-dark); font-variant-numeric: tabular-nums; }
.stat .k { font-size: 0.8rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }

/* Builder */
.builder { display: grid; grid-template-columns: 290px 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .builder { grid-template-columns: 1fr; } }
.page-list { list-style: none; margin: 0; padding: 0; }
.page-item {
  display: flex; align-items: center; gap: 8px; background: var(--card);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; margin: 6px 0; cursor: pointer;
}
.page-item.selected { border-color: var(--pine); box-shadow: 0 0 0 1px var(--pine); }
.page-item[draggable="true"] { touch-action: none; }
.page-item .drag { cursor: grab; color: var(--ink-soft); user-select: none; }
.page-item.drag-over { border-top: 3px solid var(--pine); }
.page-item .pi-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 0.92rem; }
.page-item .pi-type { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
.vis-tag { font-size: 0.7rem; background: var(--blue); color: #fff; border-radius: 5px; padding: 1px 6px; }

.q-item { border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; margin: 8px 0; background: #FDFDFB; }
.q-item .q-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.q-item .q-head .qt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--pine-dark); background: var(--pine-tint); padding: 2px 7px; border-radius: 5px; }
.q-item .q-head .qp { flex: 1; font-weight: 600; min-width: 150px; }

.check-inline { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; margin: 6px 14px 6px 0; }
.check-inline input { width: 17px; height: 17px; accent-color: var(--pine); }

/* WoZ console */
.woz-grid { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .woz-grid { grid-template-columns: 1fr; } }
.woz-item { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; margin: 7px 0; cursor: pointer; background: var(--card); }
.woz-item.selected { border-color: var(--pine); box-shadow: 0 0 0 1px var(--pine); }
.woz-item.waiting { border-left: 5px solid var(--amber); }
.woz-meta { font-size: 0.8rem; color: var(--ink-soft); }

/* Chat review */
.convo { border: 1px solid var(--line); border-radius: 10px; margin: 10px 0; background: var(--card); }
.convo-head { padding: 10px 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; cursor: pointer; }
.convo-body { padding: 4px 14px 14px; border-top: 1px solid var(--line); }
.turn { padding: 8px 10px; border-radius: 8px; margin: 6px 0; }
.turn.participant { background: #F1F3F6; }
.turn.bot { background: var(--pine-tint); }
.turn .t-meta { font-size: 0.76rem; color: var(--ink-soft); display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 3px; }
.turn details { font-size: 0.8rem; margin-top: 6px; }
.turn pre { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 8px; overflow-x: auto; font-size: 0.75rem; max-height: 220px; }

.login-card { max-width: 400px; margin: 12vh auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 30px 26px; }
