/* Zone Analysis Debriefer - phone-first, glove-tolerant, high-contrast for
   outdoor daylight use (design doc S5). Light theme by default: this app
   is used standing outside, not in a dark tent - a dark theme would be
   *harder* to read in direct sun, so there is no dark-mode branch here on
   purpose. */

:root {
  --bg: #f5f4ee;
  --surface: #ffffff;
  --ink: #16160f;
  --ink-muted: #514f45;
  --border: #d9d5c7;
  --accent: #14140f;
  --record: #c81e1e;
  --record-ring: rgba(200, 30, 30, .30);
  --ok: #1c7a3c;
  --warn: #b05a00;
  --focus: #1a56c4;
  --radius: 14px;
  --tap-min: 48px;
  --appheader-h: 52px;
}

* { box-sizing: border-box; }

/* Defensive: several elements below toggle visibility via the `hidden`
   attribute (app.js) *and* carry their own `display:` declaration (e.g.
   .topbar's `display: flex`). Author rules of equal specificity beat the
   UA's `[hidden] { display: none }`, so without this, a component that
   sets its own `display` would ignore `hidden` entirely - confirmed live
   (the top bar stayed visible on the Join screen). This forces `hidden`
   to always win, regardless of what any component rule below declares. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 32px;
}

h1 { font-size: 1.5rem; margin: 20px 0 12px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- app header (map id + gear button - every screen) ---------------- */
/* Always present, never toggled by `hidden` (app.js) - the gear button
   must be reachable from setup/join/interview/closed alike (workflow
   ruling). Sticky above `.topbar` (below), which offsets its own `top` by
   --appheader-h so the two stack instead of overlapping when both are
   visible (interview screen). */

.appheader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: var(--appheader-h);
  padding: 0 4px 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 6;
}

.appheader-label { font-size: .85rem; font-weight: 600; color: var(--ink-muted); }

.gear-btn {
  width: var(--tap-min);
  height: var(--tap-min);
  flex: none;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.gear-btn:hover, .gear-btn:active { background: var(--bg); }
.gear-btn svg { width: 26px; height: 26px; }

/* Bug 3: a small, unobtrusive "sign out" affordance next to the gear
   button - shown only when a code is actually required (app.js's init()),
   text-only so it does not compete with the gear button for attention. */
.signout-btn {
  flex: none;
  min-height: var(--tap-min);
  padding: 0 10px;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.signout-btn:hover, .signout-btn:active { color: var(--ink); }

/* --- top bar (connection + progress) ------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--appheader-h);
  z-index: 5;
}

.conn-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ink-muted);
  flex: none;
}
.conn-dot.conn-green  { background: var(--ok); }
.conn-dot.conn-amber  { background: var(--warn); }
.conn-dot.conn-red    { background: var(--record); }

.topbar-label { font-size: .85rem; color: var(--ink-muted); flex: 1; }

.chip {
  font-size: .8rem;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

/* --- cards / forms --------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 4px; }
label:first-child { margin-top: 0; }

input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  font-size: 1rem;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  min-height: var(--tap-min);
}
textarea { min-height: 96px; resize: vertical; }

input[type="text"]:focus, input[type="password"]:focus, textarea:focus, select:focus,
button:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

fieldset.mode-toggle {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 14px 0;
}
fieldset.mode-toggle legend { font-weight: 600; font-size: .85rem; padding: 0 4px; }

/* --- join screen: assignment picker (replaces the free-text data-dir
   field - Phase 9b operator ruling: the searcher/debriefer never types a
   path, they pick from what the server discovered under --data-root) --- */

fieldset.assignment-picker {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px 2px;
  margin: 0 0 14px;
}
fieldset.assignment-picker legend { font-weight: 600; font-size: .85rem; padding: 0 4px; }

.assignment-list { list-style: none; margin: 0; padding: 0 0 8px; }
.assignment-list li.empty { color: var(--ink-muted); padding: 8px 0; }

/* Already-debriefed assignments fold into a collapsed <details> below the
   active list (operator ruling: "folded and lower in sorting") - the
   summary line is itself a tap target, so it needs the same min-height as
   every other row. */
.debriefed-details summary {
  cursor: pointer;
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  font-weight: 600;
  font-size: .9rem;
  color: var(--ink-muted);
}
.debriefed-details[open] summary { margin-bottom: 4px; }

.checkbox-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-weight: 400;
  min-height: var(--tap-min);
}
.checkbox-option input { width: 20px; height: 20px; flex: none; }
.checkbox-option small { color: var(--ink-muted); display: block; }

.assignment-row {
  display: block;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  min-height: var(--tap-min);
  cursor: pointer;
}
.assignment-row:last-child { margin-bottom: 0; }
.assignment-row.is-selected {
  border-color: var(--focus);
  background: #eaf1fb;
  box-shadow: inset 0 0 0 1px var(--focus);
}
.assignment-row-title { font-weight: 600; }
.assignment-row-name { font-weight: 400; color: var(--ink-muted); }
.assignment-row-badges { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
}
/* "already debriefed" is a warning badge, not a block - a re-debrief is
   legal (task brief) - so it uses --warn, never a color that reads as an
   error/disabled state. */
.badge-ok { background: #e4f3e9; color: var(--ok); border-color: #bfe3cb; }
.badge-warn { background: #fdf1e2; color: var(--warn); border-color: #f0d2a6; }

/* Phase 11: the "Reset" action on an already-debriefed row (archives the
   previous debrief so it can be re-run) - own line, away from the row's
   badges, since it is an action, not a status indicator. Keeps the shared
   .btn tap-target sizing (var(--tap-min)) - this remains a real button on
   a touch device, not a shrunken link. */
.assignment-reset-btn { display: block; margin-top: 10px; }

/* Enhancement 1: "View analysis" on a prepared row - same treatment as the
   Reset action above (own line, real tap-target button), just earlier in
   source order so it reads as "look at what's already there" before
   "start over". */
.assignment-view-btn { display: block; margin-top: 10px; text-decoration: none; text-align: center; }

.mode-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-weight: 400;
  min-height: var(--tap-min);
}
.mode-option input { width: 20px; height: 20px; flex: none; }
.mode-option small { color: var(--ink-muted); display: block; }

/* --- buttons ----------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap-min);
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; margin-top: 14px; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
/* Any inline SVG glyph inside a .btn - without this, a <svg> with no
   explicit width/height/CSS size falls back to the UA default replaced-
   element size (300x150 CSS px), ballooning the whole button. Confirmed
   live: the "Type instead" button's keyboard icon rendered ~225px tall
   before this rule existed. */
.btn svg { width: 20px; height: 20px; fill: currentColor; flex: none; }

.error-text {
  color: #7a1414;
  background: #fbe9e9;
  border: 1px solid #f0bcbc;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .9rem;
  margin-top: 10px;
}

.banner {
  background: #fff6df;
  border: 1px solid #e8d38f;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .9rem;
  margin: 10px 0;
}

/* --- join screen: session list ---------------------------------------- */

.session-list { list-style: none; margin: 0; padding: 0; }
.session-list li.empty { color: var(--ink-muted); padding: 8px 0; }

.session-row {
  display: block;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  min-height: var(--tap-min);
  cursor: pointer;
}
.session-row:last-child { margin-bottom: 0; }
.session-row-title { font-weight: 600; }
.session-row-meta { color: var(--ink-muted); font-size: .85rem; margin-top: 2px; }

/* --- preparing screen (POST /api/prepare polling) ----------------------- */

.preparing-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.spinner-dark {
  position: static;
  width: 28px;
  height: 28px;
  flex: none;
  border: 4px solid var(--border);
  border-top-color: var(--focus);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .spinner-dark { animation: spin 1.6s steps(8) infinite; }
}
.preparing-step { font-weight: 600; margin: 0; }
.preparing-hint { color: var(--ink-muted); font-size: .85rem; margin: 12px 0 0; }
.preparing-warnings {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: #fff6df;
  border: 1px solid #e8d38f;
  border-radius: 8px;
  font-size: .85rem;
}
.preparing-failed { margin-top: 14px; }

.help-note { font-size: .9rem; color: var(--ink-muted); margin-top: 4px; }
.help-note summary {
  cursor: pointer;
  padding: 10px 4px;
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  color: var(--ink);
  font-weight: 600;
}
.help-note p { line-height: 1.5; }

/* --- interview screen: question ---------------------------------------- */

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-top: 16px;
}

.question-text {
  font-size: 1.4rem;
  line-height: 1.35;
  font-weight: 600;
  margin: 0 0 12px;
}

/* --- gap picture (Phase 9e): shown above the question, tap to enlarge -- */

.question-image-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 12px;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.question-image {
  display: block;
  width: 100%;
  height: auto;
  max-height: 220px;
  object-fit: cover;
}

.image-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 24px 16px;
}
.image-overlay img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}
.image-overlay-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: var(--tap-min);
  height: var(--tap-min);
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.question-text.is-thinking { color: var(--ink-muted); font-weight: 400; font-style: italic; }

/* --- push-to-talk: the dominant element on the screen ------------------ */

.record-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 0 10px;
}

.record-btn {
  /* At least 40vw wide, capped so it does not become absurd on a wide
     desktop window (design doc S5 / task brief). */
  width: min(40vw, 300px);
  height: min(40vw, 300px);
  min-width: 150px;
  min-height: 150px;
  border-radius: 50%;
  border: none;
  background: var(--record);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  touch-action: none; /* the button owns press gestures - no scroll/zoom stealing them */
  box-shadow: 0 0 0 0 var(--record-ring);
}
.record-btn[disabled] { background: var(--ink-muted); cursor: not-allowed; }

.record-icon { width: 34%; height: 34%; fill: currentColor; }

.record-btn.is-recording {
  animation: record-pulse 1.6s ease-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  .record-btn.is-recording { animation: none; }
}
@keyframes record-pulse {
  0%   { box-shadow: 0 0 0 0 var(--record-ring); }
  70%  { box-shadow: 0 0 0 28px rgba(200, 30, 30, 0); }
  100% { box-shadow: 0 0 0 0 rgba(200, 30, 30, 0); }
}

.record-btn.is-busy .record-icon { visibility: hidden; }

.spinner {
  position: absolute;
  width: 30%;
  height: 30%;
  border: 4px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: spin 1.6s steps(8) infinite; }
}
@keyframes spin { to { transform: rotate(360deg); } }

.record-hint { color: var(--ink-muted); font-size: .95rem; text-align: center; margin: 0; }
.record-timer { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 0; }

/* --- compose / confirm-before-send -------------------------------------- */

.compose-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 12px;
}
.compose-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}
.compose-actions .btn { flex: 1; }

/* --- transcript ---------------------------------------------------------- */

.transcript-wrap { margin-top: 22px; }
.transcript-heading { font-size: .95rem; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .04em; }

.transcript {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 42vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.transcript-entry {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.transcript-entry:last-child { border-bottom: none; }
.transcript-speaker {
  display: block;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-muted);
  margin-bottom: 2px;
}
.transcript-agent .transcript-speaker { color: var(--focus); }
.transcript-searcher .transcript-speaker { color: var(--ok); }
.transcript-entry p { margin: 0; line-height: 1.4; }

/* --- closed / failed screen ---------------------------------------------- */

.closed-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin-top: 16px;
}
.file-list {
  list-style: none;
  margin: 12px 0;
  padding: 0;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .85rem;
}
.file-list li {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  word-break: break-all;
}

/* --- desktop layout (Enhancement 5) ---------------------------------- */
/*
   Tester: "Looks like the UI was built for a mobile phone... It would be
   great to have a desktop mode too, so the text box for typing input is
   wider." Everything above this point is the unchanged phone layout - this
   block ADDS a wide-screen treatment above ~900px, it never overrides
   anything below that breakpoint. Typing is the primary input on a laptop
   (a keyboard is right there), so the compose textarea gets the emphasis:
   a comfortable max content width (not full-bleed - long lines are
   unreadable), a genuinely wide multi-line answer box, and more vertical
   room for the transcript. The push-to-talk button stays available but
   drops to a small, secondary-looking control instead of competing with
   the text box for space - the existing min(40vw, 300px) mobile rule
   already caps it at 300px past a 750px-wide viewport, but 300px is still
   sized to be the dominant control on a phone; a laptop wants it visibly
   secondary, not merely capped.
*/
@media (min-width: 900px) {
  #app { max-width: 760px; }

  /* The join/setup screens' single-column forms stay comfortable at any
     width - only the interview screen (long transcript entries, a
     multi-line answer) actually benefits from the wider shell above. */
  .question-text { font-size: 1.55rem; }

  .transcript { max-height: 55vh; }

  .record-area { padding: 14px 0 10px; }
  .record-btn {
    width: 130px;
    height: 130px;
    min-width: 0;
    min-height: 0;
  }

  .compose-panel textarea {
    min-height: 220px;
    font-size: 1.05rem;
  }
}
