/* ── Location modal (read-only card) ──────────────────────────────────── */
.loc-modal-sub {
  margin: 16px 0 8px; font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 1px; text-transform: uppercase; color: var(--muted-2);
}
.loc-modal-people { list-style: none; padding: 0; margin: 0;
  max-height: 220px; overflow-y: auto; }
.loc-modal-people li { padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.loc-modal-people li:last-child { border-bottom: none; }
.loc-modal-people a { color: var(--text); text-decoration: none; }
.loc-modal-people a:hover { color: var(--accent-2); }

/* ── Window size ladder ───────────────────────────────────────────────────
   The standard set of window sizes, applied as a `win-*` class on the
   `.modal-backdrop`. Every window (form, picker, confirm) picks one tier so
   sizes stop drifting per-modal. `win-full` is the near-fullscreen browser
   (~10% margins) for search/pickers; the rest step down to `win-xs` confirms.
   `.win-* .modal` is (0,2,0) so it overrides the legacy .panel-md/lg (0,1,0)
   without touching them — existing modals keep working until they migrate. */
.win-full { padding: 6vh 8vw 8vh; align-items: stretch; }
.win-full .modal { max-width: none; width: 100%; max-height: none; height: 100%; }
.win-lg .modal { max-width: 900px; }
.win-md .modal { max-width: 720px; }
.win-sm .modal { max-width: 520px; }
.win-xs .modal { max-width: 420px; }
/* The subdivision picker keeps a comfortable md width in every context, even when
   pushed into a full-width window (nested in the person picker) — its dashboard-
   style rows sprawl at full width. Beats `.win-full .modal` (0,2,0) on specificity. */
.modal-backdrop > .modal.sub-picker {
  max-width: 720px; width: 100%; height: auto; max-height: 88vh; align-self: flex-start;
}

/* Standardized picker window frame (person / location / responsible pickers):
   the *same width as the main form window* (`.panel-lg`, 900px) and a stable, tall
   height so a thousand-row list has vertical room and the frame doesn't jump as
   results filter. Works identically standalone or as a drill-down screen pushed
   into a form window. (0,3,0) beats the `.win-* .modal` size ladder (0,2,0), so the
   opener's `data-window-size` only steers the backdrop padding, not the box. */
.modal-backdrop > .modal.win-picker {
  max-width: 900px; width: 100%; height: 84vh; max-height: 84vh; align-self: flex-start;
}

/* A window whose body scrolls independently of a pinned head/toolbar/footer
   (the picker layout). Head, toolbar and actions stay put; `.win-results`
   takes the remaining height and scrolls. Used by every picker modal. */
.win-body { display: flex; flex-direction: column; }
.win-body > .modal-head,
.win-body > .win-toolbar,
.win-body > .actions { flex: none; }
.win-results { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }

/* ── In-window screen navigation ──────────────────────────────────────────
   A window (one .modal-backdrop) can hold several .modal "screens" — the form,
   then a picker pushed in front of it, then a deeper picker. Only the last is
   shown; earlier ones stay in the DOM but hidden, so a half-filled form is intact
   when you step «← Назад». Picker screens match the form's width so the window
   frame doesn't jump as you navigate. */
.modal-backdrop > .modal.win-behind { display: none; }
.win-screen { max-width: 900px; }

/* Smooth reveal of a pushed picker screen. While its fragment loads, the top
   screen is kept invisible (`.win-loading` on the backdrop) so the window never
   flashes an empty box; once rendered, `.win-revealing` fades + lifts it in. The
   `:last-child` selector survives the outerHTML swap that replaces the loading
   placeholder with the fragment's own .modal, so no per-node class juggling. */
.modal-backdrop.win-loading > .modal:last-child { opacity: 0; }
/* A freshly-opened window fades its whole backdrop (dim + box) in; a picker screen
   pushed into an already-open window fades only its box (the dim is already there). */
.modal-backdrop.win-revealing,
.modal-backdrop > .modal.win-revealing { animation: winScreenIn .2s ease both; }
@keyframes winScreenIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .modal-backdrop.win-revealing,
  .modal-backdrop > .modal.win-revealing { animation: none; }
}
/* Right-aligned head controls for a picker window: «← Назад» (shown by js/windows/screens.js only
   when the picker sits over another screen) sitting next to ✕. The title is the
   head's other child, so `.modal-head`'s space-between keeps it on the left. */
.win-head-actions { flex: none; display: flex; align-items: center; gap: 8px; }
.win-back {
  flex: none; cursor: pointer; line-height: 1; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); border-radius: var(--radius-sm);
  padding: 5px 10px; font: inherit; font-size: 12px;
}
.win-back svg { width: 13px; height: 13px; }
.win-back:hover { color: var(--text); border-color: var(--border-bright); background: var(--panel-2); }

/* Picker toolbar: search field + inline drill-down filters on one row. */
.win-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.win-toolbar > input[type="text"] { flex: 1 1 240px; }

/* Location picker: search on its own row, kind-filter chips wrapping below.
   In this column layout the shared `.win-toolbar > input { flex: 1 1 240px }` would
   read 240px as a *height* and grow the field vertically — pin it back to auto. */
.loc-picker-toolbar { flex-direction: column; align-items: stretch; }
.loc-picker-toolbar > input[type="text"] { flex: none; width: 100%; }
.loc-kind-chips .badge {
  background: var(--panel-2); border-color: var(--border); color: var(--text); text-transform: none;
}

/* Specialization picker: search and category select share one row, 50/50. */
.spec-picker-toolbar > input[type="text"],
.spec-picker-toolbar > select { flex: 1 1 0; min-width: 0; width: auto; }

/* Picker result row — a full-width selectable button. */
.picker-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 10px 12px; margin-bottom: 6px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 3px;
  color: var(--text);
}
.picker-row:hover { border-color: var(--border-bright); background: var(--panel-3); }
.picker-row .picker-row-main { flex: 1; min-width: 0; }
.picker-row .picker-row-name { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.picker-row .picker-row-name .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--tag, var(--accent)); flex: none;
}
.picker-row .picker-row-sub { color: var(--muted); font-size: 12px; }
.picker-row .badge { flex: none; }
.picker-more { color: var(--muted); text-align: center; margin: 8px 0 0; }

/* Person picker rows carry a rectangular portrait + a two-column identification
   readout (subdivision, birth date/age, gender, current location) so a person is
   recognisable, not name-only. The row grows taller, so pin photo/badge to top. */
.picker-row-person { align-items: flex-start; gap: 14px; padding: 12px; }
/* Shared document portrait — a flat-panel 3:4 frame with a cover-cropped photo
   and an initials fallback. Used by the person-detail hero (.pk-photo) and every
   list/roster/search portrait (.list-portrait); each caller supplies its size. */
.pk-photo, .list-portrait {
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--panel);
}
.pk-photo img, .list-portrait img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center top; }
.pk-initials, .list-portrait .list-initials {
  font-family: var(--font-display); font-weight: 700; letter-spacing: 1px; color: var(--muted-2);
}
.pk-photo { flex: none; width: 84px; height: 112px; }
.pk-initials { font-size: 20px; }
/* Compact 3:4 portrait for list-table rows — small, same frame/rounding as everywhere. */
.list-portrait { flex: none; width: 33px; height: 44px; }
.list-portrait .list-initials { font-size: 12px; }
.col-portrait { width: 33px; }
.pk-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.pk-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.pk-id { min-width: 0; }
.pk-name {
  font-weight: 600; color: var(--text-strong); line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis;
}
.pk-cs { color: var(--accent-2); font-weight: 600; margin-left: 6px; white-space: nowrap; }
.pk-rank {
  margin-top: 3px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 1px;
  text-transform: uppercase; color: var(--signal);
}
/* Two-column readout — spreads the facts across the free width instead of a
   cramped single stack. */
.pk-readout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px;
  padding-top: 10px; border-top: 1px solid var(--border);
}
.pk-readout .ro { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.pk-readout .ro-v { font-size: 13px; }

/* Multi-select state for the specialization picker: chosen rows carry a check +
   accent border (tags/picker.js), and the create row leads with a ＋. */
.picker-row .picker-row-check { flex: none; opacity: 0; color: var(--accent-2); font-weight: 700; }
.picker-row.is-selected .picker-row-check { opacity: 1; }
.picker-row.is-selected {
  border-color: var(--accent-2);
  background: color-mix(in srgb, var(--accent-2) 10%, var(--panel-2));
}
.picker-row.spec-create .spec-plus { color: var(--accent-2); font-weight: 700; }

/* ── Combobox (picker-backed field) ───────────────────────────────────────
   Replaces a would-be <select> for entities too numerous to list: a hidden
   input holds the pk, the button opens the picker window, JS writes the chosen
   value + label back (see [data-window-open] in js/windows/controls.js). */
.combobox { display: inline-flex; align-items: stretch; gap: 6px; width: 100%; }
/* The trigger is styled to be indistinguishable from a native <select> (same fill,
   border, radius, padding, font and focus ring as `input, select, textarea` above)
   — a picker-backed field must not look different from the plain fields around it.
   The caret stands in for the select's dropdown arrow. */
.combobox-btn {
  flex: 1; min-width: 0; display: inline-flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 9px 11px; cursor: pointer; text-align: left;
  background: var(--bg); border: 1px solid var(--border-bright); border-radius: var(--radius);
  color: var(--text); font-size: 14px; font-family: inherit;
}
.combobox-btn:focus-visible {
  outline: none; border-color: var(--accent-2);
}
/* Keep the label to one line — a long subdivision path ellipsises instead of
   wrapping the button to two lines. min-width:0 lets the flex child shrink. */
.combobox-btn [data-combobox-label],
.combobox-btn .combobox-label {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Same down-chevron as a native <select> (shared `--field-arrow`); the ▾ glyph in
   the markup is hidden (font-size:0) and the SVG painted in its place. */
.combobox-btn .combobox-caret {
  flex: none; width: 12px; height: 12px; font-size: 0;
  background: var(--field-arrow) center / 12px 12px no-repeat;
}
.combobox-btn [data-combobox-label].muted { color: var(--muted); }
/* Optional clear affordance (shown only once a value is chosen); matches the field
   fill/border/radius so it reads as part of the same control. */
.combobox-clear {
  flex: none; width: 38px; cursor: pointer; line-height: 1;
  background: var(--bg); border: 1px solid var(--border-bright); border-radius: var(--radius);
  color: var(--muted); font-size: 15px;
}
.combobox-clear:hover { color: var(--text); border-color: var(--accent-2); }

/* ── Modal (HTMX-loaded create/edit forms) ────────────────────────────── */
/* z-index defaults to 100 (the base #modal-root modal). Stacked overlays opened
   via js/windows/layers.js get a higher `--layer-z` so each sits above the last. */
.modal-backdrop {
  position: fixed; inset: 0; z-index: var(--layer-z, 100);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 24px;
  background: var(--backdrop);
  /* No `backdrop-filter: blur()` — blurring the whole viewport is GPU-heavy on
     weak machines. The semi-transparent `--backdrop` colour dims fine on its own. */
}
.modal {
  width: 100%; max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin: 0 0 18px; padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 {
  margin: 0; border: 0; padding: 0;
  font-family: var(--font-display); font-weight: 700; font-size: 17px;
}
.modal-x {
  flex: none; cursor: pointer; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); border-radius: var(--radius-sm);
  width: 30px; height: 30px; font-size: 14px;
}
.modal-x svg { width: 15px; height: 15px; }
.modal-x:hover { color: var(--text); border-color: var(--border-bright); }
.modal-intro { margin-top: 0; }

/* A window in the middle of something that cannot be taken back — today only the
   import modal, while its run is creating records (js/windows/busy.js). The controls
   stay clickable on purpose: each one answers with the reason instead of closing, and
   a control with `pointer-events: none` could not say anything at all. */
.modal-backdrop.is-busy [data-modal-close] { cursor: not-allowed; opacity: .45; }
