:root {
  --bg: #f7f4ed;
  /* Was the same value as --bg -- every "card" was the page's own color with
     only a 1px near-invisible border between them, which is exactly why the
     whole page read as one undifferentiated block. A crisp white surface
     against the cream page background, plus --shadow-card below, is what
     actually makes a card look like a raised panel instead of a faint
     outline. */
  --surface: #ffffff;
  --surface-alt: #fbf9f4;
  --text: #1c1c1c;
  --text-strong: rgba(28, 28, 28, 0.83);
  --text-muted: #5f5f5d;
  --border: #eceae4;
  --border-interactive: rgba(28, 28, 28, 0.4);
  --tint-04: rgba(28, 28, 28, 0.04);
  --tint-03: rgba(28, 28, 28, 0.03);
  --on-dark: #fcfbf8;
  --ring: rgba(59, 130, 246, 0.5);
  --focus-shadow: rgba(0, 0, 0, 0.1) 0px 4px 12px;
  --shadow-card: 0 1px 2px rgba(28, 28, 28, 0.04), 0 6px 20px rgba(28, 28, 28, 0.05);
  --btn-inset: rgba(255, 255, 255, 0.2) 0px 0.5px 0px 0px inset, rgba(0, 0, 0, 0.2) 0px 0px 0px 0.5px inset,
    rgba(0, 0, 0, 0.05) 0px 1px 2px 0px;

  /* Citation states are a correctness signal, not decoration, so they keep
     enough saturation to stay legible -- muted/earthy to sit inside the warm
     palette rather than the bright red/amber/green a dark-UI would use. */
  --success: #3f7d4f;
  --success-bg: rgba(63, 125, 79, 0.1);
  --success-border: rgba(63, 125, 79, 0.35);
  --warn: #a15c0a;
  --warn-bg: rgba(161, 92, 10, 0.1);
  --warn-border: rgba(161, 92, 10, 0.32);
  --danger: #a5402c;
  --danger-bg: rgba(165, 64, 44, 0.1);
  --danger-border: rgba(165, 64, 44, 0.32);

  /* A 4th, otherwise-unused hue reserved for "this is live/interactive"
     (the follow-up chat) -- everything else on the page is a static result
     card, so this is the one visual signal that doesn't double as a
     citation-validity color. */
  --accent: #3b6ea5;
  --accent-bg: rgba(59, 110, 165, 0.06);
  --accent-border: rgba(59, 110, 165, 0.3);

  --radius-sm: 4px;
  --radius: 6px;
  --radius-md: 8px;
  --radius-card: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;

  --font: "Camera Plain Variable", ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-weight: 400;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

.header {
  margin-bottom: 2rem;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
  position: relative;
}

.lang-switch {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 0.15rem;
  gap: 0.15rem;
}

.lang-btn {
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.78rem;
  padding: 0.25rem 0.7rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.lang-btn:hover {
  color: var(--text);
}

.lang-btn.active {
  background: var(--text);
  color: var(--on-dark);
}

.logo {
  font-size: 2.25rem;
  font-weight: 600;
  letter-spacing: -0.9px;
  color: var(--text);
}

.tag {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.subtitle {
  margin: 0.6rem 0 0;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.5;
  max-width: 640px;
}

.query-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 1.25rem 1.5rem;
}

/* --- vehicle selector: shown first, gates the query panel until confirmed --- */

#vehicle-select-card {
  margin-bottom: 1.25rem;
}

.vehicle-select-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
}

.vehicle-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.vehicle-field select {
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  min-width: 160px;
}

.vehicle-field select:focus {
  outline: none;
  border-color: var(--border-interactive);
  box-shadow: 0 0 0 2px var(--ring);
}

#vehicle-confirm {
  padding: 0.7rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--on-dark);
  font-family: var(--font);
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--btn-inset);
  min-height: 44px;
}

#vehicle-confirm:hover {
  opacity: 0.9;
}

.vehicle-current {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-size: 0.92rem;
  color: var(--text-strong);
}

.vehicle-current strong {
  color: var(--text);
}

.query-panel label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.query-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

#query-input {
  flex: 1;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
}

#query-input::placeholder {
  color: var(--text-muted);
}

#query-input:focus {
  outline: none;
  border-color: var(--border-interactive);
  box-shadow: 0 0 0 2px var(--ring);
}

#submit-btn {
  padding: 0.7rem 1.35rem;
  border: none;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--on-dark);
  font-family: var(--font);
  font-weight: 400;
  font-size: 1rem;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--btn-inset);
}

#submit-btn:hover:not(:disabled) {
  opacity: 0.9;
}

#submit-btn:active:not(:disabled) {
  opacity: 0.8;
}

#submit-btn:focus-visible {
  box-shadow: var(--btn-inset), var(--focus-shadow);
}

#submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.samples {
  margin-top: 0.9rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-pill);
  font-family: var(--font);
  font-size: 0.82rem;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--border-interactive);
}

.chip:active {
  opacity: 0.8;
}

.status {
  margin-top: 1rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text-strong);
  background: var(--tint-03);
}

.status.error {
  border-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.results {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-card);
}

.card h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card h2::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.55;
  flex-shrink: 0;
}

/* Each card's dot picks up that card's accent color, so scanning down the
   page tells the sections apart at a glance instead of needing to read
   every heading -- the same trick the citation chips already use elsewhere
   on this page. */
#causes-card h2::before {
  background: var(--text);
  opacity: 1;
}

#followup-card h2::before {
  background: var(--accent);
  opacity: 1;
}

/* The follow-up card is the one part of the page that's "live" (a running
   conversation) rather than a static result -- it gets the accent hue,
   a tinted surface instead of plain white, and its own border color so it
   doesn't read as just another card in the stack. */
#followup-card {
  background: var(--accent-bg);
  border-color: var(--accent-border);
}

/* De-emphasized on purpose: a developer/debug affordance, not part of the
   technician-facing result. Flat instead of raised so it doesn't compete
   with the actual cards above it for attention. */
#raw-card {
  box-shadow: none;
  background: transparent;
  border-style: dashed;
}

@keyframes card-flash {
  0% {
    box-shadow: 0 0 0 3px var(--ring);
  }
  100% {
    box-shadow: 0 0 0 3px transparent;
  }
}

.card-flash {
  animation: card-flash 1.4s ease-out;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text);
}

.hint {
  margin: -0.35rem 0 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.refusal-note {
  margin: 0;
  padding: 0.75rem 0.95rem;
  border-radius: var(--radius-md);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn);
  font-size: 0.9rem;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.media-item {
  background: var(--surface);
  border-radius: var(--radius-card);
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.media-thumb {
  aspect-ratio: 16 / 9;
  background: var(--tint-04);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-thumb .placeholder {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 1rem;
  text-align: center;
}

/* PDF page renders are portrait -- "cover" (used for 16:9 video keyframes)
   would crop most of a tall page's text away, so this gets its own fit. */
.media-thumb img.pdf-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: top;
  background: var(--tint-03);
}

.media-body {
  padding: 0.85rem 1rem 1.1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.media-title {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
}

.media-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.source-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.1rem;
  padding: 0.12rem 0.5rem;
  border-radius: var(--radius-pill);
  background: var(--tint-04);
  border: 1px solid var(--border);
  color: var(--text-strong);
  font-size: 0.76rem;
  font-weight: 600;
}

.time-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.12rem 0.5rem;
  border-radius: var(--radius-pill);
  background: var(--tint-04);
  border: 1px solid var(--border);
  color: var(--text-strong);
  font-size: 0.72rem;
}

.media-snippet {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.media-item video {
  width: 100%;
  max-height: 200px;
  background: #000;
}

.pdf-placeholder {
  font-weight: 600;
  color: var(--text-strong);
}

.pdf-preview {
  width: 100%;
  height: 220px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--tint-03);
  margin-top: 0.35rem;
}

.pdf-preview-img {
  width: 100%;
  max-height: 480px;
  object-fit: contain;
  object-position: top;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--tint-03);
}

.pdf-open-link {
  align-self: flex-start;
  font-size: 0.82rem;
  color: var(--text);
}

.cause {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}

.cause:last-child {
  margin-bottom: 0;
}

.cause h3 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.likelihood {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.16rem 0.5rem;
  border-radius: var(--radius-pill);
  margin-left: 0.5rem;
  vertical-align: middle;
  border: 1px solid transparent;
}

.likelihood.high {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}

.likelihood.medium {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn);
}

.likelihood.low {
  background: var(--tint-04);
  border-color: var(--border);
  color: var(--text-muted);
}

.cause p {
  margin: 0.4rem 0;
  font-size: 0.92rem;
  color: var(--text-strong);
}

.safety {
  color: var(--warn);
  font-size: 0.82rem;
}

/* --- step wizard: one repair step at a time, big Prev/Next + a checkbox to
   mark it done -- the default view for a cause's repair_steps. A hands-full,
   gloved-up reader scans one instruction (plus its media) at a time instead
   of a long scrolling list; "view all steps" switches to the flat list for
   anyone who wants the overview first. --- */

.step-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.step-mode-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.78rem;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
}

.step-mode-toggle:hover {
  border-color: var(--border-interactive);
  color: var(--text);
}

.step-wizard {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.step-wizard-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.step-progress {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.step-dots {
  display: flex;
  gap: 0.3rem;
  flex: 1;
  flex-wrap: wrap;
}

.step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tint-04);
  border: 1px solid var(--border);
}

.step-dot.active {
  background: var(--text);
  border-color: var(--text);
}

.step-dot.done {
  background: var(--success);
  border-color: var(--success);
}

.step-panel {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--tint-03);
}

.step-panel.step-done {
  opacity: 0.6;
}

.step-check {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding-top: 0.15rem;
}

.step-check input[type="checkbox"] {
  width: 22px;
  height: 22px;
  cursor: pointer;
  accent-color: var(--success);
}

.step-check-lg input[type="checkbox"] {
  width: 28px;
  height: 28px;
}

.step-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-start;
}

.step-wizard-nav {
  display: flex;
  gap: 0.75rem;
}

.wizard-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-interactive);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
}

.wizard-btn:hover:not(:disabled) {
  box-shadow: var(--focus-shadow);
}

.wizard-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.wizard-btn.primary {
  background: var(--text);
  color: var(--on-dark);
  border-color: var(--text);
  box-shadow: var(--btn-inset);
  flex: 2;
}

.wizard-btn.primary:hover:not(:disabled) {
  opacity: 0.9;
}

/* --- flat step list: the "view all steps" alternative to the wizard --- */

.step-list {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.step-list li {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.step-list li.step-done {
  opacity: 0.55;
}

.step-list .step-body {
  flex-wrap: wrap;
}

/* --- voice input (mic) and read-aloud (speak) buttons --- */

.mic-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.mic-btn:hover {
  border-color: var(--border-interactive);
}

.mic-hint {
  flex-basis: 100%;
  font-size: 0.78rem;
  color: var(--danger);
}

.mic-btn.mic-active {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--on-dark);
  animation: mic-pulse 1.2s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(165, 64, 44, 0.35);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(165, 64, 44, 0);
  }
}

.speak-btn {
  display: inline-flex;
  align-items: center;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  margin-left: 0.4rem;
  border-radius: var(--radius-sm);
}

.speak-btn:hover {
  color: var(--text);
  background: var(--tint-04);
}

.speak-btn.speak-active {
  color: var(--success);
}

/* --- inline step media: PDF page / video clip shown beside a repair step --- */

.step-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.step-text {
  flex: 1 1 220px;
  min-width: 180px;
}

.step-media {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.step-media-item {
  width: 240px;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--tint-03);
  padding: 0;
  margin: 0;
  font-family: var(--font);
  text-align: left;
}

button.step-media-item {
  cursor: pointer;
}

button.step-media-item:hover {
  box-shadow: var(--focus-shadow);
}

.step-media-item img,
.step-media-item video {
  width: 100%;
  display: block;
}

.step-media-item video {
  background: #000;
  aspect-ratio: 16 / 9;
}

.step-media-item img {
  height: 150px;
  object-fit: cover;
  background: var(--tint-04);
}

.step-media-pdf img {
  object-fit: contain;
  object-position: top;
  background: var(--tint-03);
}

.step-media-cap {
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 0.2rem 0.4rem;
}

/* --- follow-up chat --- */

.followup-thread {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

/* Actual speech-bubble layout (align-self + max-width, one squared-off
   corner pointing at the sender) instead of two identically-shaped boxes
   that only differed by a faint background tint -- that was the concrete
   thing making this card unreadable as a "conversation" versus just another
   list of boxes. */
.followup-turn {
  max-width: 82%;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.65rem 0.9rem;
  box-shadow: 0 1px 2px rgba(28, 28, 28, 0.05);
}

.followup-turn.role-user {
  align-self: flex-end;
  background: var(--accent);
  border-color: var(--accent);
  border-bottom-right-radius: var(--radius-sm);
}

.followup-turn.role-user .followup-role,
.followup-turn.role-user .followup-text {
  color: var(--on-dark);
}

.followup-turn.role-assistant {
  align-self: flex-start;
  background: var(--surface);
  border-bottom-left-radius: var(--radius-sm);
}

.followup-turn.followup-loading {
  color: var(--text-muted);
}

.followup-role {
  display: flex;
  align-items: center;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.followup-text {
  font-size: 0.92rem;
  color: var(--text-strong);
  white-space: pre-wrap;
}

.suggested-questions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.suggested-questions-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  flex-basis: 100%;
}

.suggested-q-chip {
  font-size: 0.8rem;
}

@media (max-width: 720px) {
  .followup-turn {
    max-width: 92%;
  }
}

.followup-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

#followup-input {
  flex: 1;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem; /* >=16px avoids iOS Safari auto-zooming the page on focus */
}

#followup-input::placeholder {
  color: var(--text-muted);
}

#followup-input:focus {
  outline: none;
  border-color: var(--border-interactive);
  box-shadow: 0 0 0 2px var(--ring);
}

#followup-submit {
  padding: 0.65rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--on-dark);
  font-family: var(--font);
  font-weight: 400;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--btn-inset);
}

#followup-submit:hover:not(:disabled) {
  opacity: 0.9;
}

#followup-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.evidence-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.evidence-row {
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.evidence-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
}

.evidence-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.evidence-row p {
  margin: 0.45rem 0 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.toggle {
  background: none;
  border: none;
  color: var(--text);
  text-decoration: underline;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.88rem;
  padding: 0;
}

.raw-json {
  margin-top: 0.75rem;
  padding: 1rem;
  background: var(--tint-03);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: auto;
  font-size: 0.75rem;
  max-height: 360px;
  color: var(--text-strong);
}

/* --- citation chips: functional 3-state signal, kept as pill "action" tags --- */

.cite-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: 0.05rem 0.55rem;
  margin: 0 0.15rem;
  font-size: 0.76rem;
  font-weight: 600;
  font-family: var(--font);
  line-height: 1.6;
  cursor: pointer;
  vertical-align: baseline;
}

.cite-chip.cite-green {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}

.cite-chip.cite-yellow {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn);
}

.cite-chip.cite-red {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
  text-decoration: line-through;
}

.cite-chip:hover {
  box-shadow: var(--focus-shadow);
}

.cite-popover {
  position: absolute;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.7rem;
  font-size: 0.78rem;
  color: var(--text-strong);
  box-shadow: var(--focus-shadow);
  z-index: 50;
  pointer-events: none;
}

/* --- validation bar --- */

.validation-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 0.9rem 0 1.1rem;
  padding: 0.65rem 0.95rem;
  border-radius: var(--radius-md);
  background: var(--tint-03);
  border: 1px solid var(--border);
  font-size: 0.82rem;
}

.vstat {
  color: var(--text-muted);
}

.vstat-ok {
  color: var(--success);
  font-weight: 600;
}

.vstat-warn {
  color: var(--danger);
  font-weight: 600;
}

.vstat-note {
  color: var(--warn);
}

/* --- evidence-focus: deduped-by-source cards (video / manual / procedure) --- */

.evidence-focus {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.focus-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.focus-card.focus-video {
  border-color: var(--border-interactive);
}

.focus-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.focus-title {
  font-weight: 600;
  color: var(--text);
}

.focus-tag {
  font-size: 0.72rem;
  padding: 0.14rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success);
}

.focus-tag.degraded {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn);
}

.focus-card video {
  width: 100%;
  max-height: 240px;
  background: #000;
  border-radius: var(--radius-md);
}

.evidence-bar {
  position: relative;
  height: 8px;
  border-radius: var(--radius-sm);
  background: var(--tint-04);
  overflow: hidden;
}

.evidence-seg {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(59, 130, 246, 0.3);
  border-radius: var(--radius-sm);
}

.evidence-seg.active {
  background: rgba(59, 130, 246, 0.85);
}

.focus-caption {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.replay-btn {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border-interactive);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.4rem 0.85rem;
  font-family: var(--font);
  font-size: 0.78rem;
  cursor: pointer;
}

.replay-btn:hover {
  box-shadow: var(--focus-shadow);
}

.replay-btn:active {
  opacity: 0.8;
}

.focus-degraded .placeholder {
  aspect-ratio: 16 / 9;
  background: var(--tint-04);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.focus-degraded .placeholder img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.focus-snippet-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.focus-snippet-highlight {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-strong);
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* --- responsive layout: phones/narrow tablets get a lighter, stacked shell
   (less padding, single-column grids, big thumb-reachable action buttons).
   Desktop/wide-tablet keeps the multi-column layout above. --- */

@media (max-width: 720px) {
  .app {
    padding: 1.25rem 0.85rem 3rem;
  }

  .logo {
    font-size: 1.7rem;
  }

  .card {
    padding: 1rem 1.1rem;
  }

  .query-row,
  .followup-form {
    flex-wrap: wrap;
  }

  #query-input,
  #followup-input {
    flex: 1 1 100%;
    order: -1; /* input first, mic + submit form a full-width button row under it */
  }

  .step-panel,
  .step-list li {
    flex-direction: column;
    /* .step-panel's base rule sets align-items: flex-start to top-align the
       checkbox with the text in the desktop ROW layout. In a COLUMN layout
       that same property switches meaning to "don't stretch children to the
       container's width" -- .step-body (and the fixed/percent-width media
       inside it) then sizes to its own unconstrained max-content width
       instead of the viewport, which is what was pushing the whole page
       into horizontal scroll on narrow screens. Explicit stretch restores
       normal block-like full-width children. */
    align-items: stretch;
  }

  /* .step-media has flex: 0 0 auto (shrink-to-fit) in the base rules above,
     so it never gets a definite width for step-media-item's `width: 100%`
     to resolve against -- it silently falls back to the image's tiny
     intrinsic size instead. Giving it flex-grow here (spanning the full row)
     is what makes the percentage below actually apply. */
  .step-media {
    flex: 1 1 100%;
    width: 100%;
  }

  .step-media-item {
    width: 100%;
    max-width: 360px;
  }

  .step-wizard-nav {
    flex-direction: column-reverse; /* primary "done, next" action closest to the thumb */
  }

  .wizard-btn,
  .wizard-btn.primary {
    flex: 1 1 auto;
  }

  .evidence-focus,
  .media-grid {
    grid-template-columns: 1fr;
  }

  .vehicle-select-row {
    flex-direction: column;
    align-items: stretch;
  }

  .vehicle-field select,
  #vehicle-confirm {
    width: 100%;
  }
}

/* --- coarse pointer (touch, incl. a gloved finger on a shop tablet/kiosk):
   enlarge the primary action targets regardless of viewport width -- a wide
   touchscreen kiosk needs this as much as a phone does. Inline elements like
   citation chips are deliberately excluded: blowing those up would break the
   reading flow of the surrounding paragraph for a target that's tapped with
   more care anyway. --- */

@media (pointer: coarse) {
  #submit-btn,
  #followup-submit,
  .wizard-btn,
  .step-mode-toggle,
  .chip,
  .lang-btn {
    min-height: 44px;
  }

  .mic-btn {
    width: 48px;
    height: 48px;
  }

  .step-check input[type="checkbox"] {
    width: 26px;
    height: 26px;
  }

  .step-check-lg input[type="checkbox"] {
    width: 30px;
    height: 30px;
  }
}


/* ---- login overlay, user chip, feedback ------------------------------------ */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(247, 244, 237, 0.92);
  backdrop-filter: blur(4px);
}
.login-overlay.hidden { display: none; }
.login-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 12px; }
.login-field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--text-muted); }
.login-field input {
  padding: 10px 12px;
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-md);
  background: var(--surface);
  font: inherit;
  color: var(--text);
}
.login-error {
  padding: 8px 10px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}
.user-chip { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; font-size: 13px; color: var(--text-muted); }
.user-chip.hidden { display: none; }
.user-name { font-weight: 600; color: var(--text-strong); }

.feedback-slot { margin-top: 12px; }
.feedback {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-muted);
}
.feedback-btn {
  padding: 4px 10px;
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-pill);
  background: var(--surface);
  cursor: pointer;
  font-size: 15px;
  line-height: 1.2;
}
.feedback-btn:hover { background: var(--tint-04); }
.feedback-thanks { color: var(--success); font-weight: 600; }
.feedback-comment {
  flex: 1 1 200px;
  min-width: 140px;
  padding: 6px 10px;
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-md);
  background: var(--surface);
  font: inherit;
}
.feedback-send {
  padding: 6px 12px;
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  font: inherit;
}

/* ---- intent answers: how-to guide, quick answer, clarify / friendly reply ------------------ */
.guide { display: flex; flex-direction: column; gap: 14px; }
.g-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.g-head h3 { margin: 0; font-size: 1.25rem; }
.g-diff { padding: 2px 10px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 600; border: 1px solid var(--border-interactive); color: var(--text-muted); }
.g-diff-easy { color: var(--success); border-color: var(--success-border); background: var(--success-bg); }
.g-diff-moderate { color: var(--warn); border-color: var(--warn-border); background: var(--warn-bg); }
.g-diff-advanced { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg); }
.g-summary { margin: 0; color: var(--text-strong); line-height: 1.55; }
.g-safety { padding: 10px 14px; border: 1px solid var(--warn-border); background: var(--warn-bg); border-radius: var(--radius-md); }
.g-safety-title { font-weight: 700; color: var(--warn); margin-bottom: 4px; }
.g-safety ul { margin: 0; padding-left: 20px; }
.g-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.g-list { padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-alt); }
.g-list h4, .g-steps-h { margin: 0 0 6px; font-size: 0.95rem; }
.g-list ul { margin: 0; padding-left: 18px; }
.g-item-name { font-weight: 600; }
.g-spec { display: inline-block; padding: 0 8px; border-radius: var(--radius-pill); background: var(--accent-bg); border: 1px solid var(--accent-border); color: var(--accent); font-size: 12px; font-weight: 600; }
.g-note, .g-empty { color: var(--text-muted); font-size: 13px; }
.g-empty { margin: 0; }
.g-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.g-step { display: flex; gap: 10px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); box-shadow: var(--shadow-card); }
.g-step.g-done { opacity: 0.55; }
.g-check { padding-top: 3px; }
.g-check input { width: 20px; height: 20px; cursor: pointer; }
.g-step-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.g-step-title { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.g-num { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; background: var(--text); color: var(--on-dark); font-size: 13px; }
.g-step-text { line-height: 1.55; }
.g-step-safety { color: var(--warn); font-size: 14px; }
.g-evidence { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(220px, 1.4fr); gap: 12px; align-items: start; }
.g-evidence > :only-child { grid-column: 1 / -1; }
.g-video { display: flex; flex-direction: column; gap: 6px; padding: 10px; border: 1px solid var(--accent-border); border-radius: var(--radius-md); background: var(--accent-bg); }
.g-vid-thumb { position: relative; padding: 0; border: 0; border-radius: var(--radius); overflow: hidden; background: #000; cursor: pointer; line-height: 0; }
.g-vid-thumb:disabled { cursor: default; }
.g-vid-thumb img { width: 100%; height: auto; display: block; }
.g-play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 34px; color: #fff; text-shadow: 0 2px 10px rgba(0,0,0,.6); background: rgba(0,0,0,.18); }
.g-vid-time { position: absolute; right: 6px; bottom: 6px; padding: 1px 7px; border-radius: var(--radius-pill); background: rgba(0,0,0,.72); color: #fff; font-size: 12px; line-height: 1.5; }
.g-vid-ph { padding: 28px; background: var(--tint-04); color: var(--text-muted); text-align: center; line-height: 1.4; }
.g-vid-label { font-weight: 700; color: var(--accent); }
.g-vid-title { font-size: 13px; color: var(--text-muted); }
.g-vid-watch { font-size: 14px; line-height: 1.45; }
.g-vid-player { width: 100%; border-radius: var(--radius); background: #000; }
.g-replay, .g-link { align-self: flex-start; padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; text-decoration: underline; }
.g-manual { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-alt); }
.g-manual-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.g-badge { padding: 1px 9px; border-radius: var(--radius-pill); background: var(--text); color: var(--on-dark); font-size: 12px; font-weight: 600; }
.g-section { color: var(--text-muted); font-size: 12px; }
.g-quote { margin: 0; padding: 4px 0 4px 12px; border-left: 3px solid var(--warn-border); font-size: 14px; line-height: 1.55; color: var(--text-strong); background: rgba(255, 240, 200, 0.35); }
.g-figs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.g-figs a { line-height: 0; }
.g-figs img { max-height: 190px; max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.g-escalate, .g-conf { font-size: 14px; color: var(--text-strong); }
.g-conf { color: var(--text-muted); }
.g-grounding { font-size: 12px; color: var(--success); }
.g-answer { font-size: 1.15rem; line-height: 1.55; font-weight: 600; }
.g-details { margin: 0; padding-left: 20px; line-height: 1.55; }
.g-reply { display: flex; flex-direction: column; gap: 12px; }
.g-reply-text { font-size: 1.05rem; line-height: 1.6; }
.g-clar-q { display: flex; flex-direction: column; gap: 6px; }
.g-clar-text { font-weight: 600; }
.g-clar-opts { display: flex; gap: 8px; flex-wrap: wrap; }
.g-opt-on { background: var(--text); color: var(--on-dark); border-color: var(--text); }
.g-continue { align-self: flex-start; }
.g-continue:disabled { opacity: 0.45; cursor: not-allowed; }
@media (max-width: 720px) {
  .g-lists, .g-evidence { grid-template-columns: 1fr; }
  .g-step { padding: 12px; }
}
