/* First-line support assistant.
   Organised as: tokens, base, typography, layout, controls, then per screen,
   with the responsive rules last. */

:root {
  /* Palette, unchanged. */
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #1b2430;
  --ink-muted: #5b6572;
  --border: #dde2e7;
  --accent: #2f6f6b;
  --accent-ink: #ffffff;
  --success-bg: #e3f2ee;
  --success-ink: #1d6f5f;
  --danger-bg: #fbeaea;
  --danger-ink: #a13a3a;
  /* Cooled from amber so no surface in the app reads warm. */
  --warning-bg: #e8ecf2;
  --warning-ink: #465166;

  /* Derived, so tints stay in the same family as the palette above. */
  --surface-sunken: #eef1f4;
  --accent-dark: #245853;
  --accent-tint: #eaf2f1;

  --radius: 10px;
  --radius-sm: 7px;

  /* One type scale, so nothing is sized by eye. */
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 15px;
  --text-lg: 17px;
  --text-xl: 21px;
  --text-2xl: 26px;

  /* One spacing scale, for the same reason. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 44px;
  --space-8: 64px;

  --shadow-sm: 0 1px 2px rgba(27, 36, 48, 0.05);
  --shadow-md: 0 2px 10px rgba(27, 36, 48, 0.07), 0 1px 2px rgba(27, 36, 48, 0.04);
}

/* --- Base ---------------------------------------------------------------- */

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* --- Typography ---------------------------------------------------------- */

/* Three distinct weights of voice: heading, body, and quiet supporting text. */

h1 {
  font-size: var(--text-2xl);
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.012em;
  margin: 0 0 var(--space-2);
  /* Headings choose their own line breaks; nothing forces one. */
  text-wrap: balance;
}

h2 { font-size: var(--text-lg); font-weight: 650; line-height: 1.3; margin: 0; text-wrap: balance; }

.lede {
  color: var(--ink-muted);
  font-size: var(--text-base);
  margin: 0 0 var(--space-6);
  max-width: 54ch;
}

/* Section rule and label, the main tool for breaking a long form into parts. */
.section-head {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: var(--space-7) 0 var(--space-4);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border);
}

.section-head.flush { margin-top: 0; padding-top: 0; border-top: none; }

.eyebrow {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 var(--space-4);
}

.muted { color: var(--ink-muted); }
.muted.small, .small { font-size: var(--text-sm); }
.muted.small.tight, .tight { margin: 0 0 var(--space-4); }

.field-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 var(--space-2);
}

.hint {
  font-weight: 400;
  font-size: var(--text-xs);
  color: var(--ink-muted);
  letter-spacing: 0;
  text-transform: none;
}

/* --- Layout -------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { font-weight: 650; font-size: var(--text-base); letter-spacing: -0.01em; }

.tag { font-size: var(--text-sm); color: var(--ink-muted); }

.nav { display: flex; align-items: center; gap: var(--space-2); }
.nav .btn { margin-top: 0; }

.app-shell {
  max-width: 620px;
  margin: var(--space-7) auto var(--space-8);
  padding: 0 var(--space-5);
}

.screen { display: none; }
.screen.active { display: block; }

/* --- Controls ------------------------------------------------------------ */

textarea,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: var(--text-base);
  font-family: inherit;
  line-height: 1.5;
  color: var(--ink);
  background: var(--surface);
  resize: vertical;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

textarea::placeholder, input::placeholder { color: #9aa3ad; }

textarea:focus,
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

input[readonly] {
  background: var(--surface-sunken);
  color: var(--ink-muted);
  cursor: not-allowed;
}

input[type="file"] {
  display: block;
  font: inherit;
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

input[type="file"]::file-selector-button {
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  margin-right: var(--space-3);
  cursor: pointer;
}

input[type="file"]:disabled::file-selector-button { opacity: 0.5; cursor: default; }

/* Explicit clear buttons are provided where they matter. */
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* --- Buttons -------------------------------------------------------------
   Three tiers. One filled primary per screen, a bordered secondary for real
   alternatives, and a quiet tier for anything that should not compete. */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 40px;
  border-radius: var(--radius);
  padding: 9px 18px;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  margin-top: var(--space-3);
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn:hover { border-color: #c6ced6; }

/* Links that present as buttons, on the 404 page. */
a.btn { text-decoration: none; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  padding: 11px 22px;
  font-size: var(--text-base);
  min-height: 44px;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

/* Secondary: a genuine alternative, but plainly not the main action. */
.btn-ghost { background: var(--surface); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-sunken); }

/* Quiet: available, deliberately unemphatic. */
.btn-quiet {
  background: none;
  border-color: transparent;
  color: var(--ink-muted);
  font-weight: 600;
}

.btn-quiet:hover { background: var(--surface-sunken); border-color: transparent; color: var(--ink); }

.btn-small { padding: 6px 12px; font-size: var(--text-sm); min-height: 34px; }

.btn-icon { padding: 6px 10px; font-size: var(--text-sm); min-height: 34px; line-height: 1.2; }

.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:hover { background: var(--surface); border-color: var(--border); }
.btn-primary:disabled:hover { background: var(--accent); border-color: var(--accent); }

.btn-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* --- Badges -------------------------------------------------------------- */

.badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.01em;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-success { background: var(--success-bg); color: var(--success-ink); }
.badge-danger { background: var(--danger-bg); color: var(--danger-ink); }
.badge-warning { background: var(--warning-bg); color: var(--warning-ink); }
.badge-muted { background: var(--surface-sunken); color: var(--ink-muted); }

/* --- Messages ------------------------------------------------------------
   Inline, next to whatever caused them. Nothing here uses a browser dialog. */

.message,
.errors,
.notice {
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin: 0 0 var(--space-5);
  font-size: var(--text-sm);
  line-height: 1.55;
  border: 1px solid;
}

.message-problem,
.errors {
  border-color: #efc9c9;
  background: var(--danger-bg);
  color: var(--danger-ink);
}

.message-notice,
.notice {
  border-color: #bfded4;
  background: var(--success-bg);
  color: var(--success-ink);
}

.message-plain {
  border-color: var(--border);
  background: var(--surface);
  color: var(--ink-muted);
}

.message-text { margin: 0 0 var(--space-3); }
.message .btn { margin-top: 0; }

.errors ul, .message ul { margin: 0; padding-left: var(--space-4); }
.errors li, .message li { margin-bottom: var(--space-1); }
.errors li:last-child, .message li:last-child { margin-bottom: 0; }

/* --- Empty and loading states -------------------------------------------- */

.empty-state {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: var(--space-7) var(--space-5);
  text-align: center;
}

.empty-state h1,
.empty-state h2 { font-size: var(--text-lg); font-weight: 650; margin: 0 0 var(--space-2); }
.empty-state p { color: var(--ink-muted); margin: 0 auto; max-width: 42ch; font-size: var(--text-sm); }
.empty-state .btn { margin-top: var(--space-5); }

#app-failed-reason {
  margin: var(--space-3) auto 0;
  max-width: 46ch;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--text-xs);
  color: var(--ink-muted);
  overflow-wrap: anywhere;
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-5);
  color: var(--ink-muted);
  font-size: var(--text-sm);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: none;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* A thin bar rather than a blocking dialog, so a slow save is visible without
   taking the screen away. */
#busy-bar {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  overflow: hidden;
  pointer-events: none;
  z-index: 40;
}

#busy-bar::after {
  content: "";
  display: block;
  height: 100%;
  width: 40%;
  background: var(--accent);
  transform: translateX(-100%);
  opacity: 0;
}

body.is-busy #busy-bar::after {
  opacity: 1;
  animation: sweep 1.1s ease-in-out infinite;
}

@keyframes sweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

@media (prefers-reduced-motion: reduce) {
  .spinner, body.is-busy #busy-bar::after { animation: none; }
  .spinner { border-top-color: var(--border); }
}

/* --- Cards --------------------------------------------------------------- */

.match-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-3);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.match-card.top { border-color: var(--accent); box-shadow: var(--shadow-md); }

.match-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.match-title { font-weight: 650; margin: 0; font-size: var(--text-base); line-height: 1.35; }
.match-title.small { font-size: var(--text-base); }

.match-sub {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xs);
  color: var(--ink-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
}

.row-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.row-actions .btn { margin-top: 0; }

/* --- Intake -------------------------------------------------------------- */

.match-results { margin-top: var(--space-5); }
#search-results { margin-top: var(--space-4); }
#kba-search { margin-bottom: var(--space-2); }

#search-results .match-card,
#kba-list .match-card { margin-bottom: var(--space-2); }

#search-results .match-head { margin-bottom: 0; }

/* --- Call flow -----------------------------------------------------------
   The step in hand is the loudest thing on the screen; what is already done
   sits back out of the way. */

.flow-log {
  margin-bottom: var(--space-5);
  padding-left: var(--space-3);
  border-left: 2px solid var(--border);
}

.log-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--text-xs);
  line-height: 1.55;
  color: var(--ink-muted);
  padding: 2px 0;
}

.log-item i { color: #9aa8a6; margin-top: 3px; font-size: 11px; flex: none; }

.flow-step {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-6);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.step-text {
  font-size: var(--text-xl);
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-5);
  text-wrap: pretty;
}

.step-image {
  margin: 0 0 var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-sunken);
}

.step-image img { display: block; width: 100%; height: auto; }

.option-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.option-row .btn { margin-top: 0; }

/* --- Review -------------------------------------------------------------- */

.review-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.review-head h1 { margin: 0; flex: 1 1 auto; min-width: 0; }

.review-fields { margin-bottom: var(--space-5); }

.field-row { margin-bottom: var(--space-3); }

.description-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--text-sm);
  line-height: 1.7;
  white-space: pre;
}

.review-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.review-actions .btn { margin-top: 0; }

/* --- Manage -------------------------------------------------------------- */

#manage-readonly { margin: var(--space-4) 0; }

.filter-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin: var(--space-5) 0 var(--space-4);
}

.filter-row input { margin-bottom: 0; }
.filter-row .btn { margin-top: 0; flex: none; }

.branching-note {
  border-left: 2px solid var(--border);
  padding-left: var(--space-3);
  margin: var(--space-3) 0 0;
  color: var(--ink-muted);
  font-size: var(--text-sm);
}

/* --- Editor --------------------------------------------------------------
   Sections are separated by the rules on .section-head; the steps below read
   as numbered cards rather than a run of inputs. */

.editor-layout { display: block; }

#app-shell.wide { max-width: 1180px; }

#app-shell.wide .editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 560px) minmax(0, 1fr);
  gap: var(--space-7);
  align-items: start;
}

#screen-editor input[type="text"],
#screen-editor input[type="search"],
#screen-editor textarea { margin-bottom: var(--space-5); }

#screen-editor .field-label { margin-top: 0; }

#pdf-file { margin-bottom: var(--space-4); }
#pdf-status { margin: 0 0 var(--space-5); }

#action-steps { margin-bottom: var(--space-4); }

.step-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.step-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 var(--space-2);
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent-dark);
  font-size: var(--text-xs);
  font-weight: 700;
}

#screen-editor .step-row input[type="text"]:last-child,
.step-row input[type="file"] { margin-bottom: 0; }

.step-row textarea { margin-bottom: var(--space-4); }

.step-row input[type="file"] { font-size: var(--text-xs); }
.step-row input[type="file"]::file-selector-button { font-size: var(--text-xs); padding: 6px 12px; }

.image-preview {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}

.image-preview img {
  width: 128px;
  height: 96px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}

.image-preview .btn { margin-top: 0; }

.step-image-error { margin: var(--space-3) 0 0; }

/* --- Source panel -------------------------------------------------------- */

.source-panel { position: sticky; top: 84px; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.panel-head .btn { margin-top: 0; }

.source-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--text-xs);
  line-height: 1.7;
  white-space: pre-wrap;
  height: 66vh;
  min-height: 320px;
}

/* --- Sign in ------------------------------------------------------------- */

#app-loading { margin-top: var(--space-7); }

#screen-auth { max-width: 420px; }
#screen-auth input { margin-bottom: var(--space-5); }
#screen-auth .btn-primary { width: 100%; margin-top: var(--space-2); }
#screen-auth .muted.small { margin-top: var(--space-5); }

#signup-fields { margin: 0; }

#signed-in-as {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Team ---------------------------------------------------------------- */

.team-block { margin-bottom: var(--space-6); }
.team-block .btn { width: 100%; }

.join-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--text-2xl);
  font-weight: 650;
  letter-spacing: 0.18em;
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  margin: 0 0 var(--space-2);
  user-select: all;
  overflow-wrap: anywhere;
}

/* --- Tablet -------------------------------------------------------------- */

@media (max-width: 1080px) {
  #app-shell.wide .editor-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-6); }
}

@media (max-width: 900px) {
  #app-shell.wide { max-width: 720px; }
  #app-shell.wide .editor-layout { display: block; }
  .source-panel { position: static; margin-top: var(--space-7); }
  .source-box { height: auto; min-height: 260px; }
}

/* --- Phone and small tablet ---------------------------------------------- */

@media (max-width: 700px) {
  .topbar {
    flex-wrap: wrap;
    padding: var(--space-3) var(--space-4);
    row-gap: var(--space-2);
  }

  .brand { flex: 1 1 100%; }

  /* The nav scrolls sideways rather than stacking into a tall block. */
  .nav {
    flex: 1 1 100%;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar { display: none; }
  .nav .btn { flex: none; }

  /* Not worth a line of its own on a phone, and it truncates to noise if it
     rides along at the end of the scrolling nav. */
  #signed-in-as { display: none; }

  .app-shell { margin: var(--space-5) auto var(--space-7); padding: 0 var(--space-4); }
  #app-shell.wide { max-width: none; }

  h1 { font-size: 22px; }
  .step-text { font-size: var(--text-lg); }

  .flow-step { padding: var(--space-5) var(--space-4); }
  .match-card { padding: var(--space-4); }
  .step-row { padding: var(--space-4); }

  .section-head { margin-top: var(--space-6); padding-top: var(--space-5); }

  /* Comfortable to hit with a thumb. */
  .btn { min-height: 44px; }
  .btn-primary { min-height: 48px; width: 100%; }
  .btn-small, .btn-icon { min-height: 38px; width: auto; }

  .option-row { flex-direction: column; align-items: stretch; }
  .option-row .btn { width: 100%; }

  .review-actions { flex-direction: column-reverse; align-items: stretch; }
  .review-actions .btn { width: 100%; }

  .filter-row { flex-wrap: wrap; }
  .filter-row input { flex: 1 1 100%; }
  .filter-row .btn { width: auto; min-height: 40px; }

  .match-head { flex-wrap: wrap; }
  .row-actions .btn { width: auto; }

  .team-block .btn { width: 100%; }
  .empty-state { padding: var(--space-6) var(--space-4); }
  .empty-state .btn { width: 100%; }

  .description-box { white-space: pre-wrap; font-size: var(--text-xs); }
  .join-code { font-size: var(--text-xl); letter-spacing: 0.12em; }

  .image-preview img { width: 96px; height: 72px; }
}

@media (max-width: 420px) {
  .app-shell { padding: 0 var(--space-3); }
  .flow-step { padding: var(--space-4) var(--space-3); }
  .step-row-head { gap: var(--space-2); }
}

/* --- Drafting from a document -------------------------------------------- */

.pdf-actions { margin-bottom: var(--space-4); }
.pdf-actions .btn { margin-top: 0; }

/* Something the model was not sure of, sitting against the field it affects. */
.uncertain-note {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin: calc(var(--space-5) * -1 + var(--space-2)) 0 var(--space-5);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--ink-muted);
}

.step-row .uncertain-note { margin: calc(var(--space-4) * -1 + var(--space-2)) 0 var(--space-4); }

.uncertain-tag {
  flex: none;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--warning-ink);
  background: var(--warning-bg);
  border-radius: var(--radius-sm);
  padding: 2px 7px;
  margin-top: 1px;
}

#draft-uncertain { margin: 0 0 var(--space-5); }
#draft-uncertain ul { margin: var(--space-2) 0 0; padding-left: var(--space-4); }

/* --- Modal ---------------------------------------------------------------
   Used when a step cannot be carried out and the call has to end there. */

.modal-backdrop {
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  inset: 0;
  z-index: 60;
  padding: var(--space-5);
  background: rgba(27, 36, 48, 0.42);
}

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-6);
  box-shadow: 0 12px 40px rgba(27, 36, 48, 0.18);
}

.modal h2 { font-size: var(--text-xl); margin: 0 0 var(--space-2); letter-spacing: -0.01em; }
.modal .field-label { margin-top: var(--space-4); }
.modal textarea { margin-bottom: var(--space-3); }
.modal input { margin-bottom: 0; }
.modal .errors { margin: var(--space-3) 0 0; }

#blocked-modal-step { color: var(--ink); font-weight: 600; }

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

/* Both endings name what they do, and a label that breaks across two lines
   reads as two options rather than one. */
.modal-actions .btn { margin-top: 0; white-space: nowrap; }

/* Cancel sits away from the two that end the call, so it is not picked by
   accident when reaching for the nearest button. */
#blocked-cancel { margin-right: auto; }

@media (max-width: 700px) {
  .modal-backdrop { padding: var(--space-3); align-items: flex-end; }
  .modal { padding: var(--space-5) var(--space-4); max-height: 92vh; }
  .modal-actions { flex-direction: column-reverse; align-items: stretch; }
  .modal-actions .btn { width: 100%; }
}

/* --- Record steps --------------------------------------------------------- */

/* The value a record step asks for, on the call screen. */
#flow-record { margin-bottom: var(--space-4); }
#flow-record-error { margin: calc(var(--space-4) * -1 + var(--space-2)) 0 var(--space-4); }

/* A capture field already answered earlier in the call. */
.field-row .prefilled { margin: var(--space-2) 0 0; }

/* Optional per-step note, always visible on action/record/question steps. */
.step-comment { margin: 0 0 var(--space-4); }
.step-comment input { margin-bottom: 0; }

/* Step type, in the KBA form. */
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: var(--text-base);
  font-family: inherit;
  line-height: 1.5;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.step-row select { margin-bottom: var(--space-4); }

/* --- Flagging a step ------------------------------------------------------
   Icon-sized on purpose: this sits alongside "mark done" and "issue
   resolved" without reading as a third thing of equal weight to choose
   between. */

.flag-control { margin-left: auto; }
.flag-control .btn { margin-top: 0; }

.flag-toggle-sent { color: var(--success-ink); }

.flag-popover {
  flex: 1 1 100%;
  margin-top: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-sunken);
}

.flag-popover-row { display: flex; align-items: center; gap: var(--space-2); }
.flag-popover-row input { margin-bottom: 0; flex: 1 1 auto; min-width: 0; }
.flag-popover-row .btn { margin-top: 0; flex: none; }

.flag-popover .errors,
.flag-popover .muted.small.tight { margin: var(--space-2) 0 0; }

/* --- The manage screen's flag backlog ------------------------------------- */

.flags-section { margin-bottom: var(--space-5); }

.flags-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  margin-top: 0;
}

.flags-toggle:hover { background: var(--surface-sunken); }

.flags-chevron {
  margin-left: auto;
  color: var(--ink-muted);
  font-size: var(--text-xs);
  transition: transform 0.12s ease;
}

.flags-toggle[aria-expanded="true"] .flags-chevron { transform: rotate(90deg); }

.flags-panel {
  margin-top: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: var(--space-4);
}

.flags-group { margin-bottom: var(--space-4); }
.flags-group:last-child { margin-bottom: 0; }

.flags-group-title {
  font-weight: 600;
  font-size: var(--text-sm);
  margin: 0 0 var(--space-2);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

.flag-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
}

.flag-row + .flag-row { border-top: 1px solid var(--border); }

.flag-row-body { min-width: 0; }
.flag-row-step { font-weight: 600; font-size: var(--text-sm); margin: 0; }
.flag-row-reason { margin: var(--space-1) 0 0; color: var(--ink-muted); font-size: var(--text-sm); }
.flag-row-meta { margin: var(--space-1) 0 0; color: var(--ink-muted); font-size: var(--text-xs); }

.flag-row .btn { margin-top: 0; flex: none; }
.flag-row .errors { flex: 1 1 100%; margin: var(--space-2) 0 0; }

@media (max-width: 700px) {
  /* The rest of .option-row goes full width and stacks; the flag control
     stays put so it does not suddenly read as a fourth big button. */
  .flag-control { align-self: flex-end; width: auto; }
  .flag-control .btn { width: auto; }

  .flag-row { flex-direction: column; align-items: stretch; }
  .flag-row .btn { width: auto; align-self: flex-start; }
}

/* --- Open / Resolved tabs in the flags panel ------------------------------ */

.flags-tabs {
  display: flex;
  gap: var(--space-4);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-3);
}

.flags-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: var(--space-2) 0;
  margin-top: 0;
  margin-bottom: -1px;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
}

.flags-tab:hover { color: var(--ink); }
.flags-tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

/* The optional note beside "Mark resolved", and the button itself once a row
   is showing the Reopen action instead. */
.flag-row-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
}

.flag-row-actions input { margin-bottom: 0; width: 180px; }
.flag-row-actions .btn { margin-top: 0; }

@media (max-width: 700px) {
  .flag-row-actions { width: 100%; flex-wrap: wrap; }
  .flag-row-actions input { flex: 1 1 auto; width: auto; }
}

/* --- Previewing a KBA ------------------------------------------------------
   Reuses the call flow exactly as a real call runs it, so the only thing
   this needs of its own is a way to say, unmistakably, that it is not one. */

.preview-banner {
  background: var(--warning-bg);
  color: var(--warning-ink);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
  font-weight: 600;
}

.preview-banner strong { font-weight: 700; }

/* --- Recovering from a session or connection problem mid-call ------------- */

/* The small sign-in prompt reused inside the flag popover or a step's image
   slot. Its own scoped spacing, the same way the main sign-in screen tunes
   its inputs, since the base input styling carries none of its own. */
[data-reauth-form] input {
  margin-bottom: var(--space-3);
}

[data-reauth-form] .btn { margin-top: var(--space-1); }

[data-recovery-message] { margin-bottom: 0; }

.step-image-slot:empty { display: none; }
