:root {
  --cream: #FBF6EC;
  --paper: #FFFDF8;
  --ink: #1F2A26;
  --muted: #6B736E;
  --line: #E4DCCB;
  --palm: #2F7D5B;
  --palm-deep: #1F5C43;
  --palm-soft: #EAF4EE;
  --taro: #6B4C9A;
  --ocean: #1E6F8C;
  --hibiscus: #C94C6A;
  --sand: #EFE4CC;
  --curve: 2px 14px;
}

* { box-sizing: border-box; }

html { scrollbar-width: thin; scrollbar-color: var(--palm) var(--cream); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--cream); }
::-webkit-scrollbar-thumb { background: var(--palm); border-radius: 10px; border: 2px solid var(--cream); }
::-webkit-scrollbar-thumb:hover { background: var(--palm-deep); }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background:
    radial-gradient(900px 400px at 100% -10%, #F3E9D2 0%, transparent 60%),
    radial-gradient(700px 360px at -10% 110%, #DDEFE6 0%, transparent 60%),
    var(--cream);
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.req { color: var(--hibiscus); font-weight: 600; }

/* Header */
.top {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.top::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 3px;
  background: linear-gradient(90deg, var(--palm), var(--ocean), var(--taro), var(--hibiscus));
}
.brand {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--palm-deep);
}
.tag { color: var(--muted); font-size: 13px; }
.actions { margin-left: auto; display: flex; gap: 10px; }

/* Layout */
main { max-width: 760px; margin: 0 auto; padding: 48px 24px 80px; }

h1, h2, h3 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 12px;
}
h1 { font-size: 40px; color: var(--palm-deep); }
h2 { font-size: 22px; }
h3 { font-size: 18px; }

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 12px;
  color: var(--taro);
  margin: 0 0 8px;
  font-weight: 500;
}

.hero { padding-bottom: 28px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.hero p { margin: 0 0 12px; max-width: 60ch; }

/* Respondent details */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--palm-deep); }
.field input {
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  padding: 11px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--curve);
}
.field input:focus { outline: none; border-color: var(--ocean); box-shadow: 0 0 0 3px rgba(30, 111, 140, 0.15); }
.respondent legend { font-size: 20px; }
@media (max-width: 640px) { .field-row { grid-template-columns: 1fr; } }

/* Sections */
.section {
  border: 0;
  border-top: 1px solid var(--line);
  padding: 32px 0 12px;
  margin: 0;
}
.section legend {
  font-family: "Fraunces", Georgia, serif;
  font-size: 22px;
  font-weight: 700;
  padding: 0;
  margin-bottom: 4px;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.num {
  font-family: "Inter", sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--paper);
  background: var(--taro);
  padding: 2px 8px;
  border-radius: var(--curve);
}
.section-desc { color: var(--muted); margin: 0 0 20px; }

/* Questions */
.q { margin-bottom: 26px; }
.q-text { font-weight: 600; margin: 0 0 12px; }
.q-num { color: var(--taro); margin-right: 4px; }

.choice,
.pill,
textarea {
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: var(--curve);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  margin-bottom: 8px;
  cursor: pointer;
}
.choice:hover { border-color: var(--palm); }
.choice:has(input:checked) {
  border-color: var(--palm);
  background: var(--palm-soft);
  box-shadow: inset 3px 0 0 var(--palm);
}
.choice input { accent-color: var(--palm); width: 16px; height: 16px; margin: 0; }

/* 1–5 scale */
.scale { display: flex; gap: 8px; }
.pill {
  flex: 1;
  position: relative;
  text-align: center;
  cursor: pointer;
  padding: 12px 0;
}
.pill input { position: absolute; opacity: 0; pointer-events: none; }
.pill span { font-weight: 600; color: var(--muted); }
.pill:hover { border-color: var(--palm); }
.pill:has(input:checked) {
  background: var(--palm);
  border-color: var(--palm);
  box-shadow: 0 6px 14px -8px var(--palm-deep);
}
.pill:has(input:checked) span { color: var(--paper); }

.scale-ends {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

/* Grid (Q4) */
.grid-wrap { overflow-x: auto; }
.grid {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 14px;
  min-width: 520px;
}
.grid th, .grid td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}
.grid th { font-size: 12px; color: var(--muted); font-weight: 600; }
.grid td:first-child, .grid th:first-child { text-align: left; width: 42%; }
.grid tbody tr:hover { background: var(--palm-soft); }
.grid input { accent-color: var(--palm); width: 16px; height: 16px; cursor: pointer; }

textarea {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  color: var(--ink);
  resize: vertical;
}
textarea:focus, .choice:focus-within, .pill:focus-within {
  outline: none;
  border-color: var(--ocean);
  box-shadow: 0 0 0 3px rgba(30, 111, 140, 0.15);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 12px 28px;
  border: 1px solid var(--palm);
  background: var(--palm);
  color: var(--paper);
  border-radius: var(--curve);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, color 0.15s;
}
.btn:hover { background: var(--palm-deep); border-color: var(--palm-deep); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn.ghost {
  background: transparent;
  color: var(--palm-deep);
  border-color: var(--palm-deep);
}
.btn.ghost:hover { background: var(--palm-soft); }
.btn.small { padding: 8px 16px; font-size: 13px; }

.footer {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  margin-top: 8px;
}
.error {
  margin: 0;
  color: var(--hibiscus);
  background: #FBEAEE;
  border-left: 3px solid var(--hibiscus);
  padding: 10px 14px;
  border-radius: 0 var(--curve);
  font-weight: 500;
}

/* Thanks */
.thanks {
  text-align: center;
  padding: 64px 24px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--curve);
  box-shadow: 0 24px 48px -36px var(--palm-deep);
}
.thanks p { max-width: 52ch; margin: 0 auto 12px; }
.thanks .btn { margin-top: 18px; }

/* ===== Admin: one-screen layout, scroll only inside the table ===== */
body.admin {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.admin main {
  max-width: clamp(320px, 96vw, 1800px);
  width: 100%;
  margin: 0 auto;
  padding: 16px 24px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Stats: quiet cards */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  flex-shrink: 0;
}
.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--curve);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.stat .value { font-family: "Fraunces", Georgia, serif; font-size: 22px; font-weight: 600; color: var(--ink); }
.stat .hint { font-size: 12px; color: var(--muted); }

/* Panel fills remaining height */
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--curve);
  padding: 16px 20px 8px;
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 10px;
  flex-shrink: 0;
}
.panel-head h2 { margin: 0; font-size: 18px; }

/* Scroll container: fixed to the panel, hidden scrollbar until scrolling */
.table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
  transition: scrollbar-color 0.3s ease;
}
.table-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
.table-wrap::-webkit-scrollbar-thumb { background: transparent; border-radius: 8px; transition: background 0.3s ease; }
.table-wrap.is-scrolling { scrollbar-color: var(--palm) transparent; }
.table-wrap.is-scrolling::-webkit-scrollbar-thumb { background: var(--palm); }

/* Table */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th, .table td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  vertical-align: top;
}
.table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 600;
  background: var(--cream);
  position: sticky;
  top: 0;
  z-index: 1;
}
.table tbody tr.row { cursor: pointer; transition: background 0.12s; }
.table tbody tr.row:hover { background: var(--palm-soft); }
.table tr.active { background: var(--palm-soft); }
.table .empty { text-align: center; color: var(--muted); padding: 32px; cursor: default; }

/* Expanded answers */
.table .expand { display: none; }
.table .expand.open { display: table-row; }
.table .expand td { white-space: normal; padding: 8px 0 24px; background: transparent; }
.qa-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px 0; width: 100%; }
.qa { display: flex; flex-direction: column; gap: 4px; min-width: 0; padding: 0 10px 14px; border-bottom: 1px solid var(--line); }
.qa-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--taro); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.qa textarea {
  width: 100%; resize: vertical; min-height: 44px;
  font: inherit; font-size: 13px; line-height: 1.5; color: var(--ink);
  padding: 0; margin: 0; background: transparent;
  border: 0; outline: none;
}

/* Detail dialog */
dialog {
  border: 0;
  border-radius: var(--curve);
  padding: 0;
  width: min(680px, calc(100vw - 32px));
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 30px 60px -30px rgba(31, 42, 38, 0.45);
}
dialog::backdrop { background: rgba(31, 42, 38, 0.4); }
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--cream);
}
.dialog-head h3 { margin: 0; font-size: 17px; }
.detail { margin: 0; padding: 8px 22px 22px; max-height: 70vh; overflow-y: auto; }
.detail-row { padding: 12px 0; border-bottom: 1px dashed var(--line); }
.detail-row:last-child { border-bottom: 0; }
.detail dt { font-weight: 600; color: var(--palm-deep); margin-bottom: 4px; }
.detail dd { margin: 0; white-space: pre-wrap; }

/* Back to top */
.fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  font-size: 20px;
  background: var(--palm);
  color: var(--paper);
  border: 0;
  border-radius: var(--curve);
  box-shadow: 0 12px 24px -12px var(--palm-deep);
  cursor: pointer;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s, background 0.15s;
}
.fab.visible { opacity: 1; transform: none; pointer-events: auto; }
.fab:hover { background: var(--palm-deep); }

/* Small screens */
@media (max-width: 640px) {
  .top { padding: 14px 18px; }
  .actions { margin-left: 0; width: 100%; }
  .actions .btn { flex: 1; }
  main { padding: 32px 16px 60px; }
  h1 { font-size: 32px; }
  .scale { gap: 6px; }
  .pill { padding: 10px 0; }
}
.other-input {
  margin: 4px 0 8px 28px;
  padding: 10px 14px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: var(--curve);
  background: var(--paper);
  width: calc(100% - 28px);
}