:root {
  --navy: #1c2b3a;
  --navy-dark: #101a24;
  --gold: #a9812f;
  --gold-light: #d8b968;
  --bg: #f5f4f1;
  --panel: #ffffff;
  --border: #dcd8d0;
  --text: #23262b;
  --text-muted: #6b6f76;
  --danger: #b3261e;
  --danger-bg: #fbeceb;
  --ok: #1e7d4b;
  --ok-bg: #e9f6ef;
  --pending: #8a5a00;
  --pending-bg: #fdf1dc;
  --radius: 6px;
  --focus: #2f6fed;
  --font-serif: Georgia, "Times New Roman", "Noto Serif", "PT Serif", serif;
  --shadow-card: 0 1px 2px rgba(16, 26, 36, 0.05), 0 10px 30px rgba(16, 26, 36, 0.09);

  /* Motion. Established here — the app had no easing/duration scale. Keep UI
     transitions on --ease-out and under ~200ms; extend this block rather than
     inventing parallel values. */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --dur-fast: 120ms;
  --dur-ui: 180ms;
  /* Section step change: incoming settles slower than the outgoing leaves, so
     the swap reads as a deliberate move rather than a flicker. Still < 300ms. */
  --dur-section-out: 140ms;
  --dur-section-in: 260ms;
  --dur-enter: 280ms;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: var(--navy);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  background: var(--gold);
  color: var(--navy-dark);
  font-weight: 700;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 16px; }
.brand-text span { font-size: 12px; color: #c9d2dc; }

.header-flag {
  font-size: 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  padding: 6px 10px;
  border-radius: 999px;
  color: #e4e8ee;
}

.account-bar {
  font-size: 13px;
  color: #e4e8ee;
  display: flex;
  align-items: center;
  gap: 12px;
}
.account-bar button {
  background: none;
  border: none;
  color: var(--gold);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}
.account-bar button:hover { color: #fff; }

/* Plain wrapper — still used for the "Loading…" and edit-profile takeover. */
.auth-shell {
  max-width: 480px;
  margin: 40px auto;
}
.auth-shell .section-card { margin: 0; }

/* Branded two-panel wrapper for sign in / sign up / reset / pending review.
   Left: navy credibility panel. Right: the form. Stacks on narrow screens. */
.auth-layout {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  max-width: 860px;
  margin: 48px auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-card);
  /* clip (not hidden): keeps the child backgrounds inside the 14px radius
     without making this a scroll container, which would disable the
     position:sticky on .auth-brand-inner. */
  overflow: clip;
}

.auth-brand {
  background: linear-gradient(157deg, var(--navy) 0%, var(--navy-dark) 100%);
  color: #fff;
  padding: 44px 40px;
  display: flex;
  flex-direction: column;
}

/* Sticky on wide screens so the reassurance copy stays in view while a long
   form (sign-up) scrolls past. Overridden back to static in the stacked
   mobile layout below. */
.auth-brand-inner {
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 24px;
}

.auth-brand-mark {
  background: var(--gold);
  color: var(--navy-dark);
  font-weight: 700;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  letter-spacing: 0.5px;
}

.auth-brand h1 {
  font-family: var(--font-serif);
  font-size: 25px;
  font-weight: 600;
  line-height: 1.25;
  margin: 0;
}

.auth-brand .auth-brand-sub {
  font-size: 13.5px;
  color: #c9d2dc;
  margin: -8px 0 0;
}

.auth-points {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 13px;
  color: #dce3ea;
}
.auth-points li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.45;
}
.auth-points li::before {
  content: "";
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  border-radius: 50%;
  background: rgba(216, 185, 104, 0.18);
  /* small check mark */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23d8b968' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 8.5l3 3 6-6.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
}

.auth-brand-foot {
  margin-top: auto;
  padding-top: 20px;
  font-size: 12px;
  color: #9fb0c0;
}

.auth-main {
  padding: 44px 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
/* Inside the branded layout the panel itself is the card — strip the
   nested .section-card chrome so it doesn't double up. */
.auth-main .section-card {
  background: none;
  border: none;
  border-radius: 0;
  padding: 0;
  margin: 0;
}
.auth-main .section-card h2 {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 600;
}
.auth-main .btn-row { margin-top: 22px; }
.auth-main .btn-row .nav-btn { width: 100%; }

.auth-switch {
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
}
.auth-switch button {
  background: none;
  border: none;
  color: var(--navy);
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 2px;
  font-size: 14px;
}
.auth-switch button:hover { color: var(--navy-dark); }

/* Password field + Show/Hide reveal toggle. */
.password-wrap {
  position: relative;
  max-width: 420px;
}
.password-wrap input { width: 100%; padding-right: 58px; }
.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 4px;
}
.password-toggle:hover { color: var(--text); }
.password-toggle:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

@media (max-width: 760px) {
  .auth-layout {
    grid-template-columns: 1fr;
    max-width: 460px;
    margin: 24px auto;
  }
  .auth-brand {
    padding: 24px 24px 22px;
  }
  .auth-brand-inner {
    gap: 14px;
    position: static;
    top: auto;
  }
  .auth-points,
  .auth-brand-foot { display: none; }
  .auth-brand h1 { font-size: 21px; }
  .auth-main { padding: 28px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .auth-switch button,
  .password-toggle,
  button.nav-btn,
  button.submit-btn,
  .radio-option,
  .pending-btn,
  .telegram-btn { transition: none; }

  button.nav-btn:active,
  button.submit-btn:active,
  .radio-option:active,
  .pending-btn:active,
  .telegram-btn:active { transform: none; }

  /* Keep the result panel fading in (aids comprehension) but drop the rise. */
  .result-panel:not(.hidden) { animation-name: result-panel-fade; }

  /* Submit progress bar: the width still updates (it carries the status), it
     just jumps to each value instead of gliding. */
  .submit-progress .fill { transition: none; }
}

.app-body {
  flex: 1;
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  align-items: start;
}

/* Screens with no section nav (sign in / sign up / pending review /
   edit profile / the post-submit confirmation) collapse the two-column
   grid to a single narrow column so the card sits centred, not shoved
   into the right-hand 1fr track with a dead 260px gutter beside it. */
.app-body.no-nav {
  grid-template-columns: 1fr;
  max-width: 920px;
}
.app-body.no-nav .result-panel,
.app-body.no-nav .auth-shell {
  max-width: 520px;
  margin: 40px auto;
}

@media (max-width: 860px) {
  .app-body { grid-template-columns: 1fr; }
  .section-nav { position: static !important; order: 2; }

}

.section-nav {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 20px;
  border-right: 1px solid var(--border);
  margin-right: 20px;
}

.nav-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  border: 1px solid transparent;
  background: none;
  text-align: left;
  width: 100%;
}

.nav-item .num { font-variant-numeric: tabular-nums; color: var(--gold); font-weight: 600; min-width: 20px; }

.nav-item:hover { background: rgba(0,0,0,0.03); }

.nav-item.active {
  background: var(--panel);
  border-color: var(--border);
  color: var(--text);
  font-weight: 600;
}

.nav-item.skipped { opacity: 0.4; text-decoration: line-through; }
.nav-item.done .num { color: var(--ok); }

.form-main { min-width: 0; }

.section-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 32px;
  margin-bottom: 20px;
}

.section-card h2 {
  margin: 0 0 4px;
  font-size: 19px;
  color: var(--navy);
}

.section-desc {
  color: var(--text-muted);
  font-size: 13.5px;
  margin: 0 0 22px;
}

.field {
  margin-bottom: 22px;
}

.field:last-child { margin-bottom: 0; }

.field label.field-label {
  display: block;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.req-mark { color: var(--danger); margin-left: 2px; }

.field-help {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0 0 8px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
select {
  width: 100%;
  max-width: 420px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: #fff;
  color: var(--text);
}

textarea {
  width: 100%;
  max-width: 560px;
  min-height: 90px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  resize: vertical;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.field.has-error input,
.field.has-error select {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.error-text {
  color: var(--danger);
  font-size: 12.5px;
  margin-top: 5px;
}

.radio-group, .yn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.radio-option {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 14px;
  cursor: pointer;
  font-size: 13.5px;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 7px;
  user-select: none;
}

.radio-option:hover { border-color: var(--gold-light); }

.radio-option.selected {
  border-color: var(--gold);
  background: #fbf4e6;
  font-weight: 600;
}

.radio-option input { margin: 0; }

.yn-group .radio-option { min-width: 64px; justify-content: center; }

.other-input-wrap { margin-top: 10px; max-width: 420px; }

.pending-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.pending-btn {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--pending);
  background: var(--pending-bg);
  color: var(--pending);
  cursor: pointer;
}

.pending-btn.active {
  background: var(--pending);
  color: #fff;
}

.upload-choice {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.upload-box {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: #fbfaf8;
}

.upload-box input[type="file"] { font-size: 13px; }

.file-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  font-size: 13px;
}

.file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 6px;
  background: #fff;
}

.file-remove {
  border: none;
  background: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
}

.upload-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

.btn-row {
  display: flex;
  justify-content: space-between;
  margin-top: 26px;
  gap: 10px;
}

button.nav-btn, button.submit-btn {
  padding: 11px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  transition: background-color 180ms ease, border-color 180ms ease, transform var(--dur-fast) var(--ease-out);
}

button.nav-btn.primary, button.submit-btn {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

button.nav-btn.primary:hover, button.submit-btn:hover { background: var(--navy-dark); }
button.nav-btn:focus-visible, button.submit-btn:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
button.nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.telegram-btn {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid #229ed9;
  background: #eaf7fd;
  color: #1789bd;
  font-size: 13px;
  cursor: pointer;
}

.telegram-btn[data-connected="true"] {
  background: var(--ok-bg);
  border-color: var(--ok);
  color: var(--ok);
}

/* Press feedback — a near-imperceptible dip so a tap registers, especially on
   touch where there is no hover state. transform only, ~120ms; reduced-motion
   opts out in the block near the top of this file. */
.radio-option, .pending-btn, .telegram-btn {
  transition: transform var(--dur-fast) var(--ease-out);
}
button.nav-btn:active,
button.submit-btn:active,
.radio-option:active,
.pending-btn:active,
.telegram-btn:active { transform: scale(0.98); }

/* Long-running submit: shown on its own full-page screen (see
   #submit-progress-panel / startSubmitProgress() in app.js) while the matter is
   being sent (~75s). The bar is a time estimate — the backend gives no real
   progress signal — so it eases to ~95% and holds, reaching 100% (green) only
   when the response lands. */
.submit-progress { margin-top: 22px; }
.submit-progress .track {
  height: 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}
.submit-progress .fill {
  height: 100%;
  width: 0%;
  background: var(--navy);
  transition: width 450ms var(--ease-out), background-color var(--dur-ui) ease;
}
.submit-progress .fill.is-done { background: var(--ok); }
.submit-progress .subline {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 10px;
}

.inline-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.banner {
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13.5px;
}

.banner.warn { background: var(--pending-bg); border: 1px solid var(--pending); color: var(--pending); }
.banner.error { background: var(--danger-bg); border: 1px solid var(--danger); color: var(--danger); }
.banner.info { background: #eef2f8; border: 1px solid var(--navy); color: var(--navy); }

.result-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 32px;
}

.result-panel.hidden, .hidden { display: none !important; }

/* Submit-result entrance — the one rare, high-emotion moment (matter filed), so
   the delight budget applies. A single gesture: the panel rises 8px and fades in
   as it replaces the form. transform/opacity only. */
.result-panel:not(.hidden) {
  animation: result-panel-in var(--dur-enter) var(--ease-out) both;
}
/* The rise reads as an uplifting gesture — right for a confirmed submission,
   tonally wrong under an error. The failure panel fades in without travel. */
.result-panel.is-error:not(.hidden) {
  animation-name: result-panel-fade;
}
@keyframes result-panel-in {
  from { opacity: 0; transform: translateY(8px); }
}
@keyframes result-panel-fade {
  from { opacity: 0; }
}

/* The submitting screen fades out in place before the result panel fades/rises
   into the same spot — a quick opacity handoff, no movement. */
#submit-progress-panel { transition: opacity 150ms var(--ease-out); }
#submit-progress-panel.is-leaving { animation: none; opacity: 0; }

.result-panel h2 { margin-top: 0; color: var(--navy); }

.result-status {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 14px;
}

.result-status.ok { background: var(--ok-bg); color: var(--ok); }
.result-status.stub-fail { background: var(--danger-bg); color: var(--danger); }

.result-actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}

.result-summary-line { color: var(--text-muted); font-size: 14px; margin: 4px 0 18px; }

.result-next-steps { margin: 0 0 4px; padding-left: 20px; color: var(--text); }
.result-next-steps li { margin-bottom: 6px; }

.section-progress {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.app-footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 16px;
}

.fieldset-title {
  font-size: 14px;
  font-weight: 700;
  margin: 26px 0 4px;
  color: var(--navy);
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.fieldset-title:first-child { border-top: none; padding-top: 0; margin-top: 0; }


/* ---------------------------------------------------------------------------
   Mobile control sizing. Deliberately at the END of the stylesheet: these
   override the base input rules above, and at equal specificity the later
   block wins. Moving this higher silently breaks the font-size rule.
   --------------------------------------------------------------------------- */
@media (max-width: 860px) {
  /* iOS Safari auto-zooms into any field whose text is under 16px and never
     zooms back out, leaving the agent panning a magnified page. */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  select,
  textarea {
    font-size: 16px;
    min-height: 44px;
  }

  /* Thumb-sized controls: 44px is Apple's minimum, 48px Android's. The stock
     36-38px is reachable but invites mis-taps on the longer option lists. */
  .radio-option,
  .pending-btn,
  .telegram-btn,
  button.nav-btn,
  button.submit-btn { min-height: 44px; }

  .upload-box input[type="file"] { font-size: 15px; }
}

/* --- Follow-up-doc page (?ft= link) ----------------------------------------
   Rendered outside the wizard (nav hidden, .app-body.no-nav centres it). Reuses
   .section-card / .field / .file-list / .result-* styling; only the matter
   context strip is new. */
.followup-card .followup-context {
  margin: 16px 0 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  background: var(--bg);
}
.followup-context-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 5px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.followup-context-row:last-child { border-bottom: none; }
.followup-context-row span { color: var(--text-muted); flex: 0 0 auto; }
.followup-context-row strong { text-align: right; font-weight: 600; }

/* --- Section transition (wizard step change) ------------------------------
   renderCurrentSection() wraps the panel swap in document.startViewTransition().
   These rules style that cross-fade: the outgoing section fades, the incoming
   one fades up 6px. transform/opacity only. With no View Transitions support,
   or under reduced motion (the JS skips the wrap), the swap is instant — the
   ::view-transition pseudo-elements simply never get created. */
#sections-container { view-transition-name: section-panel; }

::view-transition-group(section-panel) { animation-timing-function: var(--ease-out); }
::view-transition-old(section-panel) { animation: vt-section-out var(--dur-section-out) var(--ease-out) both; }
::view-transition-new(section-panel) { animation: vt-section-in var(--dur-section-in) var(--ease-out) both; }

@keyframes vt-section-out { to { opacity: 0; } }
@keyframes vt-section-in { from { opacity: 0; transform: translateY(6px); } }

/* Ordered step list on the "Almost there." screen — lower-roman with a
   closing bracket, i) ii), rather than the browser default "i." */
.step-list {
  list-style: none;
  padding-left: 1.6rem;
  margin: 0.6rem 0;
  counter-reset: step;
}

.step-list li {
  counter-increment: step;
  position: relative;
  margin-bottom: 0.4rem;
}

.step-list li::before {
  content: counter(step, lower-roman) ")";
  position: absolute;
  left: -1.6rem;
  width: 1.3rem;
  text-align: right;
}
