/* Migrant check form — calm off-white / navy / teal palette, system fonts only. */

:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #fbfaf7;
  --ink: #16233a;
  --ink-2: #3a465d;
  --muted: #586274;
  --line: #d9dce2;
  --line-strong: #aeb5c1;
  --navy: #1b2d4f;
  --navy-hover: #24396a;
  --teal: #1b6a67;
  --teal-weak: #e3f0ee;
  --warn: #7a4900;
  --warn-weak: #fbf0dc;
  --alert: #93281f;
  --alert-weak: #f8e6e3;
  --progress: #2b4877;
  --progress-weak: #e8eef8;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(22, 35, 58, .06), 0 6px 18px rgba(22, 35, 58, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
}

h1, h2, h3 { line-height: 1.25; margin: 0; color: var(--navy); }
h1 { font-size: 1.6rem; font-weight: 650; }
h2 { font-size: 1.2rem; font-weight: 650; }
h3 { font-size: 1.02rem; font-weight: 650; }
p { margin: 0; }
code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 .3em; }

:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
h1:focus, h2:focus, h3:focus { outline: none; }
h1:focus-visible, h2:focus-visible, h3:focus-visible { outline: 3px solid var(--teal); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 50;
  background: var(--navy); color: #fff; padding: 8px 14px; border-radius: var(--radius-sm);
  text-decoration: none;
}
.skip-link:focus { top: 12px; }
.noscript { padding: 24px; }
.muted { color: var(--muted); }

/* ---------- top bar ---------- */
.topbar { background: var(--navy); color: #fff; }
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, #2b8a85, #1b6a67);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .18);
}
.brand-title { font-weight: 650; font-size: 1.05rem; }
.brand-sub { font-size: .82rem; color: #c6d0e2; }
.topbar-side { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .88rem; }
.health { color: #dfe6f2; max-width: 520px; }
.health-warn { color: #ffd9a3; }
.user { color: #c6d0e2; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  padding: 10px 16px; min-height: 44px; line-height: 1.2;
}
.btn:disabled { cursor: not-allowed; opacity: .55; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #155a57; }
.btn-secondary { background: var(--surface); color: var(--navy); border-color: var(--line-strong); }
.btn-secondary:hover:not(:disabled) { border-color: var(--navy); }
.btn-quiet { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .35); padding: 6px 12px; min-height: 36px; }
.btn-quiet:hover { border-color: #fff; }
.btn-wide { width: 100%; }
.link-btn {
  font: inherit; font-size: .9rem; color: var(--teal); background: none; border: 0;
  padding: 4px 0; cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.link-btn:disabled { color: var(--muted); text-decoration: none; cursor: not-allowed; }
.chip-btn {
  font: inherit; font-size: .85rem; color: var(--navy); background: var(--surface-2);
  border: 1px solid var(--line-strong); border-radius: 999px; padding: 1px 9px; margin: 2px 4px 2px 0;
  cursor: pointer;
}
.chip-btn:hover { border-color: var(--navy); }

/* ---------- page layout ---------- */
.page { max-width: 1240px; margin: 0 auto; padding: 24px 20px 96px; }
.intro { margin-bottom: 20px; max-width: 760px; }
.intro p { color: var(--ink-2); margin-top: 6px; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start; }
.side-col { position: sticky; top: 16px; }
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side-col { position: static; }
}

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- form sections ---------- */
.section { padding: 20px; margin-bottom: 16px; }
.section > summary {
  list-style: none; cursor: pointer; display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin: -20px; padding: 20px; border-radius: var(--radius);
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::after { content: "Показать"; color: var(--teal); font-size: .9rem; font-weight: 600; }
.section[open] > summary::after { content: "Скрыть"; }
.section[open] > summary { margin-bottom: 0; }
.section-title { font-size: 1.15rem; font-weight: 650; color: var(--navy); }
.section-tag { font-size: .82rem; color: var(--muted); font-weight: 500; margin-left: 8px; }
.section-body { margin-top: 10px; }
.section[open] .section-body { margin-top: 26px; }
.section-desc { color: var(--muted); font-size: .92rem; margin-bottom: 14px; }
.group-title { font-size: .95rem; color: var(--ink-2); margin: 18px 0 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.group-title:first-child { border-top: 0; padding-top: 0; margin-top: 0; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
@media (max-width: 640px) { .grid { grid-template-columns: minmax(0, 1fr); } }
.field { min-width: 0; margin: 0; padding: 0; border: 0; }

/* Normal input fields: label above the control, hint and messages below.
   Fallback (and ≤640px): a natural vertical stack. */
.field-input { display: flex; flex-direction: column; }
.field-input > .hint { margin: 6px 0 0; }

/* Two-column grids: paired fields share four row tracks (label, control,
   hint, messages), so controls line up whatever the label or hint length.
   Spacing between pairs comes from the messages track. */
@media (min-width: 641px) {
  @supports (grid-template-rows: subgrid) {
    .grid { row-gap: 0; }
    .grid > .field-input { display: grid; grid-template-rows: subgrid; grid-row: span 4; row-gap: 0; }
    .grid > .field-input > .label { grid-row: 1; align-self: end; }
    .grid > .field-input > .input { grid-row: 2; align-self: start; }
    .grid > .field-input > .hint { grid-row: 3; }
    .grid > .field-input > .field-msgs { grid-row: 4; padding-bottom: 14px; }
    .grid > .field-wide { margin-bottom: 14px; }
  }
}
.field-wide { grid-column: 1 / -1; }
.label { display: block; font-weight: 600; font-size: .95rem; margin-bottom: 4px; color: var(--ink); }
.hint { color: var(--muted); font-size: .84rem; margin: 0 0 6px; }
.input, .textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 10px 12px; min-height: 44px;
}
.textarea { min-height: 140px; resize: vertical; font-family: var(--mono); font-size: .88rem; }
.input:focus, .textarea:focus { border-color: var(--teal); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--alert); background: #fffafa; }
.need { color: var(--teal); font-size: .82rem; margin-top: 4px; font-weight: 600; }
.need:empty, .error:empty, .warning:empty { display: none; }
.error { color: var(--alert); font-size: .86rem; margin-top: 4px; }
.warning { color: var(--warn); font-size: .86rem; margin-top: 4px; }

.tri legend { padding: 0; margin-bottom: 4px; }
.tri-options { display: flex; flex-wrap: wrap; gap: 6px; }
.tri-opt {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--line-strong); border-radius: 999px; padding: 6px 12px; min-height: 40px;
  background: var(--surface); font-size: .93rem;
}
.tri-opt input { margin: 0; accent-color: var(--teal); }
.tri-opt:has(input:checked) { border-color: var(--teal); background: var(--teal-weak); }
.tri-opt:has(input:focus-visible) { outline: 3px solid var(--teal); outline-offset: 2px; }

.attach { margin-top: 12px; padding: 12px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-2); }
.attach-note { font-size: .84rem; color: var(--muted); margin: 4px 0 8px; }
.file-input { font: inherit; font-size: .9rem; max-width: 100%; }
.file-status { font-size: .88rem; margin-top: 6px; }

.notice {
  border-left: 4px solid var(--progress); background: var(--progress-weak);
  padding: 10px 12px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: .9rem; margin-bottom: 12px;
}
.radio-row { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 6px 0 10px; }
.radio-row label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; min-height: 32px; }
.radio-row input { accent-color: var(--teal); }

.form-actions { display: flex; justify-content: flex-end; margin-top: 4px; }

/* ---------- document upload / OCR ---------- */
.ocr-head { display: flex; align-items: baseline; gap: 8px; }
.ocr-drop {
  border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 16px; background: var(--surface-2);
  display: grid; gap: 6px; transition: border-color .15s, background .15s;
}
.ocr-drop-over { border-color: var(--teal); background: var(--teal-weak); }
.ocr-drop .label { margin: 0; }
.ocr-files { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 10px; }
.ocr-file {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 12px; align-items: start;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
.ocr-file-error { border-color: #e8bdb7; background: #fffafa; }
.ocr-file-warn { border-color: #ecd6aa; }
.ocr-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: var(--surface-2); }
.ocr-thumb-doc { display: grid; place-items: center; font-size: .75rem; font-weight: 700; color: var(--navy); }
.ocr-file-name { font-weight: 600; overflow-wrap: anywhere; }
.ocr-file-meta { font-size: .82rem; color: var(--muted); }
.ocr-file-status { font-size: .88rem; color: var(--ink-2); margin-top: 2px; }
.ocr-file-side { display: grid; gap: 4px; justify-items: end; min-width: 170px; }
.ocr-file .ocr-text { grid-column: 1 / -1; }
.ocr-file .ocr-text summary { cursor: pointer; color: var(--teal); font-weight: 600; font-size: .9rem; }
.ocr-page-title { font-size: .82rem; color: var(--muted); margin-top: 6px; }
.ocr-progress { width: 100%; height: 8px; margin-top: 4px; accent-color: var(--teal); }
.input-sm { min-height: 36px; padding: 6px 8px; font-size: .88rem; }
.ocr-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.btn-quiet-dark { background: transparent; color: var(--navy); border-color: var(--line-strong); }
.notice-warn { border-left-color: #c9892a; background: var(--warn-weak); }
.notice-alert { border-left-color: var(--alert); background: var(--alert-weak); }
.ocr-identity { margin-top: 6px; display: flex; gap: 6px; align-items: center; font-weight: 600; }
.ocr-review { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 4px; }
.ocr-rows { display: grid; gap: 10px; margin-top: 10px; }
.ocr-row { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; margin: 0; min-width: 0; }
.ocr-row-conflict { border-color: #e7cf9f; background: #fffcf6; }
.ocr-row-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 0; }
.ocr-row-head input, .ocr-replace input, .ocr-identity input { width: 18px; height: 18px; accent-color: var(--teal); }
.ocr-current { font-size: .86rem; color: var(--muted); margin: 4px 0 6px; }
.ocr-sources { margin: 6px 0 0; padding-left: 18px; font-size: .82rem; color: var(--ink-2); }
.ocr-sources q { font-family: var(--mono); font-size: .8rem; }
.ocr-cands { display: grid; gap: 6px; margin-bottom: 6px; }
.ocr-cand { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.ocr-replace { margin-top: 6px; display: flex; gap: 6px; align-items: center; font-size: .9rem; color: var(--warn); }
@media (max-width: 640px) {
  .ocr-file { grid-template-columns: 48px minmax(0, 1fr); }
  .ocr-thumb { width: 48px; height: 48px; }
  .ocr-file-side { grid-column: 1 / -1; justify-items: start; min-width: 0; }
}

/* ---------- plan ---------- */
.plan { padding: 18px; }
.plan-summary { color: var(--muted); font-size: .9rem; margin: 4px 0 12px; }
.op-list { list-style: none; margin: 0 0 12px; padding: 0; border-top: 1px solid var(--line); }
.op-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.op-head { display: flex; align-items: flex-start; gap: 10px; }
.op-head input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--teal); }
.op-title { font-weight: 600; cursor: pointer; }
.op-meta { margin: 2px 0 0 30px; display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: .76rem; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; }
.chip-candidate { color: var(--warn); border-color: #e7cf9f; background: var(--warn-weak); }
.op-state { margin: 4px 0 0 30px; font-size: .88rem; color: var(--ink-2); }
.op-row .link-btn { margin-left: 30px; }
.op-row[data-state="ready"] .op-state { color: var(--teal); font-weight: 600; }
.op-row[data-state="unsupported"] .op-title, .op-row[data-state="unsupported"] .op-state { color: var(--muted); }
.op-row[data-state="invalid"] .op-state { color: var(--alert); }
.op-row[data-state="running"] .op-state { color: var(--progress); font-weight: 600; }
.op-extra { margin: 4px 0 0 30px; font-size: .82rem; color: var(--warn); }
.plan-foot { font-size: .82rem; color: var(--muted); margin-bottom: 12px; }

.consent {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px; margin-bottom: 8px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-2);
}
.consent input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--teal); }
.consent label { font-size: .88rem; cursor: pointer; }
.consent-note { font-size: .84rem; color: var(--warn); margin-bottom: 8px; }
.run-hint { font-size: .86rem; color: var(--ink-2); margin-top: 8px; }

/* ---------- results ---------- */
.results { margin-top: 32px; }
.results-summary {
  margin: 10px 0 16px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line); font-size: .92rem;
}
.results-summary .counts { display: flex; flex-wrap: wrap; gap: 6px 16px; font-weight: 600; color: var(--ink-2); }
.results-summary .disclaimer { color: var(--muted); font-size: .84rem; margin-top: 4px; }
.results-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 960px) { .results-list { grid-template-columns: minmax(0, 1fr); } }

.result {
  background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--line-strong);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.result.tone-ok { border-left-color: var(--teal); }
.result.tone-neutral { border-left-color: var(--navy); }
.result.tone-warn { border-left-color: #c9892a; }
.result.tone-alert, .result.tone-error { border-left-color: var(--alert); }
.result.tone-progress { border-left-color: var(--progress); }
.result.tone-muted { border-left-color: var(--line-strong); background: var(--surface-2); }

.result-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.result-kind { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.badge { font-size: .78rem; font-weight: 700; border-radius: 999px; padding: 2px 10px; white-space: nowrap; border: 1px solid; }
.badge-ok { color: var(--teal); background: var(--teal-weak); border-color: #b9dbd6; }
.badge-neutral { color: var(--navy); background: #eef1f6; border-color: #cdd4e1; }
.badge-warn { color: var(--warn); background: var(--warn-weak); border-color: #e7cf9f; }
.badge-alert, .badge-error { color: var(--alert); background: var(--alert-weak); border-color: #e8bdb7; }
.badge-progress { color: var(--progress); background: var(--progress-weak); border-color: #c5d3ea; }
.badge-muted { color: var(--muted); background: var(--surface); border-color: var(--line); }
.result-headline { font-weight: 600; margin-top: 10px; }
.result-code { font-size: .84rem; color: var(--muted); margin-top: 4px; }
.result-explain { font-size: .9rem; color: var(--ink-2); margin-top: 6px; }
.data ol { margin: 0; padding-left: 20px; }
.stale { font-size: .86rem; color: var(--warn); background: var(--warn-weak); border-radius: var(--radius-sm); padding: 6px 10px; margin-top: 8px; }

.notes { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.note { font-size: .87rem; padding: 6px 10px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); }
.note-warn { background: var(--warn-weak); border-color: #ecd6aa; color: #5c3800; }
.note-alert { background: var(--alert-weak); border-color: #e8c3be; color: #6e1d16; }
.note-info { color: var(--ink-2); }

.meta { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 3px 12px; margin: 12px 0 0; font-size: .86rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }

.err-block { margin-top: 10px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--alert-weak); font-size: .88rem; color: #6e1d16; }
.err-block p + p { margin-top: 4px; }

.result details { margin-top: 10px; }
.result summary { cursor: pointer; color: var(--teal); font-weight: 600; font-size: .9rem; padding: 4px 0; }
.data { margin: 6px 0 0; font-size: .88rem; display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); gap: 3px 12px; }
.data dt { color: var(--muted); overflow-wrap: anywhere; }
.data dd { margin: 0; overflow-wrap: anywhere; }
.data .data { grid-column: 1 / -1; margin-left: 12px; }
.data ul { margin: 0; padding-left: 18px; }
.unknown-val { color: var(--warn); font-style: italic; }
.raw {
  font-family: var(--mono); font-size: .78rem; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px; overflow: auto; max-height: 320px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.result-actions .btn { min-height: 38px; padding: 7px 12px; font-size: .9rem; }
.spinner {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%; vertical-align: -2px; margin-right: 6px;
  border: 2px solid #c5d3ea; border-top-color: var(--progress); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.page-foot { margin-top: 40px; color: var(--muted); font-size: .84rem; max-width: 820px; }

/* ---------- mobile action bar ---------- */
.mobile-bar { display: none; }
@media (max-width: 960px) {
  .mobile-bar:not([hidden]) {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: rgba(246, 245, 241, .96); border-top: 1px solid var(--line);
  }
}

/* ---------- dialogs ---------- */
.dialog {
  border: 0; border-radius: var(--radius); padding: 24px; width: min(440px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(22, 35, 58, .3); color: var(--ink);
}
.dialog::backdrop { background: rgba(22, 35, 58, .45); }
.login-form { display: grid; gap: 6px; }
.login-form h2 { margin-bottom: 2px; }
.login-form .muted { margin-bottom: 10px; font-size: .9rem; }
.login-form .label { margin-top: 6px; }
.login-form .btn { margin-top: 10px; }
.confirm-body { margin: 12px 0 18px; display: grid; gap: 8px; color: var(--ink-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  .topbar, .side-col, .form-actions, .mobile-bar, .result-actions { display: none !important; }
  .layout { grid-template-columns: 1fr; }
}
