/* Anketa page — the app's tokens and form primitives copied from the app's
   global stylesheet (one dark theme, yellow accent, Tektur). Radii are zeroed
   in :root: the app ships with «Sharp UI» on by default (its UI store turns
   the flag on out of the box).

   Everything is grouped by CONTROL TYPE, not by field: one rule per kind —
   single-line control, auto-growing text, date, select, chips, multi-value
   row, segmented switch — so the form stays uniform by construction. */

@font-face {
  font-family: 'Tactic Sans Exd';
  font-style: normal;
  font-weight: 1000;
  font-display: swap;
  src: url('./fonts/TacticSansExd-Ult.otf') format('opentype');
}
/* Tektur (variable font, weights 400-900) — self-hosted, two subsets. */
@font-face {
  font-family: 'Tektur';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url('./fonts/XoH62YHtS7q969kXCjzlV0aSkS_o8Oacsz-cvGHE.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Tektur';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url('./fonts/XoH62YHtS7q969kXCjzlV0aSkS_o8OacszucvA.woff2') format('woff2');
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: dark;
  --bg-primary: #0d0d0d;
  --bg-secondary: #1a1a1a;
  --bg-card: #1a1a1a;
  --bg-sidebar: #111111;
  --bg-input: #222222;
  --bg-tertiary: #2a2a2a;
  --dropdown-bg: #262626;
  --text-primary: #ffffff;
  --text-secondary: #cccccc;
  --text-muted: #888888;
  --border-color: #333333;
  --accent-color: #f2d244;
  --accent-hover: #d4b820;
  --accent-glow: rgba(var(--accent-color-rgb), 0.15);
  --accent-color-rgb: 242, 210, 68;
  --accent-secondary: #0057b7;
  --color-danger: #dc3545;
  --color-danger-hover: #c82333;
  --color-danger-rgb: 220, 53, 69;
  --color-success: #28a745;
  --color-success-rgb: 40, 167, 69;
  --header-height: 56px;
  --space-4: 4px;
  --space-8: 8px;
  --space-12: 12px;
  --space-16: 16px;
  --space-20: 20px;
  --space-32: 32px;
  --motion-fast: 150ms;
  --motion-medium: 250ms;
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --card-shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
  --card-radius: 0;
  --radius-sm: 0;
  --radius-md: 0;
  --radius-lg: 0;
  --radius-pill: 0;
  /* One control height for every single-line control: a select, a date and a
     text input are the same box, and only auto-growing text is taller. */
  --control-height: 42px;
  /* THE spacing system of the form — one scale, four levels, applied by the
     stack rules below (never by ad-hoc margins):
       cluster  cards of one block touch
       heading  a white group heading to its first block
       block    category → category (a visible break)
       group    before a white group heading (the biggest break) */
  --gap-cluster: 8px;
  --gap-heading: 16px;
  --gap-block: 24px;
  --gap-group: 40px;
  --font-heading: 'Tactic Sans Exd', 'Tektur', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  min-width: 0;
}

html {
  /* Rotation must not resize text (mobile font boosting). */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family:
    'Tektur',
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  /* Vertical scrolling only: every wide child carries its own min-width: 0
     and the page never pans sideways. */
  overflow-x: hidden;
}

::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* === Unified form primitives (main.css) === */
.field-input {
  padding: 9px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background-color: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  outline: none;
  transition:
    border-color var(--motion-fast),
    box-shadow var(--motion-fast);
  width: 100%;
  min-width: 0;
  min-height: var(--control-height);
  box-sizing: border-box;
}
.field-input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.field-input::placeholder {
  color: var(--text-muted);
  font-style: italic;
}
.field-input.error,
.field-input[aria-invalid='true'] {
  border-color: var(--color-danger);
}
.field-input.error:focus {
  box-shadow: 0 0 0 3px rgba(var(--color-danger-rgb), 0.15);
}
.field-input:-webkit-autofill,
.field-input:-webkit-autofill:hover,
.field-input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text-primary);
  box-shadow: 0 0 0 1000px var(--bg-input) inset;
  caret-color: var(--text-primary);
}
select.field-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 36px;
  cursor: pointer;
  text-overflow: ellipsis;
}
/* Auto-growing text: the same box as every other control, but it wraps words
   and grows vertically instead of pushing the layout sideways. */
textarea.field-input {
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
textarea.field-input.auto {
  height: var(--control-height);
}
/* The generated text is read, not typed: monospace, its own scroll. */
textarea.result-text {
  resize: vertical;
  overflow: auto;
  min-height: 220px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}
.field-input:disabled {
  color: var(--text-muted);
  cursor: default;
}
.field-error {
  font-size: 13px;
  color: var(--color-danger);
  margin-top: 4px;
}
.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* === Unified buttons (main.css) === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  transition:
    background-color var(--motion-fast),
    border-color var(--motion-fast),
    color var(--motion-fast);
}
.btn:hover:not(:disabled) {
  background-color: var(--bg-primary);
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.btn:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}
.btn-submit {
  background-color: var(--accent-color);
  color: #000;
  border-color: var(--accent-color);
}
.btn-submit:hover:not(:disabled) {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn-danger {
  background-color: transparent;
  color: var(--color-danger);
  border-color: var(--color-danger);
}
.btn-danger:hover:not(:disabled) {
  background-color: rgba(var(--color-danger-rgb), 0.1);
}
.icon-btn {
  width: 32px;
  height: 32px;
  flex: none;
  border: none;
  background: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  transition:
    background-color var(--motion-fast),
    color var(--motion-fast);
}
.icon-btn:hover:not(:disabled) {
  background-color: var(--bg-primary);
  color: var(--accent-color);
}
.field-hint-btn {
  width: 20px;
  height: 20px;
  flex: none;
  border: 1px solid var(--accent-color);
  border-radius: var(--radius-pill);
  background: none;
  color: var(--accent-color);
  font-size: 12px;
  font-style: italic;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.field-hint-btn:hover {
  color: var(--accent-color);
  border-color: var(--accent-color);
}
/* The icon-sized «add» button of the value rows: a grey square with a dashed
   yellow frame and a yellow plus. */
.plus-btn {
  width: var(--control-height);
  height: var(--control-height);
  flex: none;
  border: 1px dashed var(--accent-color);
  border-radius: var(--radius-lg);
  background-color: var(--bg-secondary);
  color: var(--accent-color);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.plus-btn:hover:not(:disabled) {
  background-color: var(--bg-tertiary);
}
.plus-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
/* The tag picker stands before the value input. */
.tag-btn {
  width: var(--control-height);
  height: var(--control-height);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background-color: var(--bg-secondary);
  color: var(--accent-color);
  font-size: 18px;
}

/* === Labels and headings === */
/* White BLOCK heading inside a group — always larger than a field label. */
.block-title {
  display: block;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 700;
  text-wrap: balance;
}
/* A field's own caption: small, muted, uppercase — never competes with a
   block heading. */
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.field-label-row {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

/* === Page layout === */
.anketa-header {
  display: flex;
  align-items: center;
  gap: var(--space-12);
  min-height: var(--header-height);
  padding: var(--space-8) var(--space-16);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 10;
}
.anketa-header img {
  height: 40px;
  width: auto;
  flex: none;
}
.anketa-header h1 {
  font-family: var(--font-heading);
  font-size: clamp(20px, 5vmin, 32px);
  font-weight: 1000;
  color: var(--accent-color);
  line-height: 1.05;
}
.header-actions {
  margin-left: auto;
  display: flex;
  gap: var(--space-8);
  align-items: center;
}
.anketa-note {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
}
.anketa-note--privacy {
  color: var(--accent-color);
}
.anketa-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-16) var(--space-16) var(--space-32);
  display: flex;
  flex-direction: column;
  /* Page chrome (notes, lists, the form, the actions, the result panel). */
  gap: var(--space-16);
}
/* THE card stack. The spacing is carried by margins of the stack children, so
   every block's distance is decided by its ROLE, not by the neighbour's guts. */
.anketa-form {
  display: flex;
  flex-direction: column;
}
/* The form opens with the same air a white group heading gets. */
.anketa-wrap > .anketa-form {
  margin-top: calc(var(--gap-group) - var(--space-16));
}
.anketa-form > * + * {
  margin-top: var(--gap-block);
}
.anketa-form > .group-title {
  margin-top: var(--gap-group);
}
.anketa-form > .group-title:first-child {
  margin-top: 0;
}
.anketa-form > .group-title + * {
  margin-top: var(--gap-heading);
}
/* A tight cluster (the service axes, appointments, the medical cards, the
   driver's licence with the vehicle): one block, its cards touching. */
.anketa-group {
  display: flex;
  flex-direction: column;
  gap: var(--gap-cluster);
}
/* White group heading: the biggest caption on the page. */
.group-title {
  display: block;
  color: var(--text-primary);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  text-wrap: balance;
}
/* Category heading inside a group: yellow. */
.category-title {
  display: block;
  color: var(--accent-color);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-wrap: balance;
}
.anketa-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: var(--space-16);
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
  min-width: 0;
}
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}
.field[hidden] {
  display: none;
}
.repeat-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
  min-width: 0;
}
.repeat-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-12);
  min-width: 0;
}
.repeat-row-head {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}
.repeat-row-index {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}
.repeat-row-head .btn {
  margin-left: auto;
}

/* === Chips (multi-choice) === */
.chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4) var(--space-8);
}
.chips.error {
  outline: 1px solid var(--color-danger);
  outline-offset: 2px;
}
.chip {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--bg-input);
  cursor: pointer;
  font-size: 13px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.chip input {
  accent-color: var(--accent-color);
  flex: none;
}

/* === Date control: the native picker, with an italic «дд.мм.рррр» where empty === */
.date-wrap {
  position: relative;
  display: flex;
  min-width: 0;
}
.date-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-style: italic;
  font-size: 14px;
  color: var(--text-muted);
}
.date-wrap.has-value .date-placeholder,
.date-wrap:focus-within .date-placeholder {
  display: none;
}
/* The empty native control prints its own dd.mm.yyyy hint — hidden while the
   format overlay is on screen; the calendar icon is a pseudo-element and stays. */
.date-wrap:not(.has-value):not(:focus-within) input[type='date']::-webkit-datetime-edit {
  color: transparent;
}
/* Firefox paints the same hint with the control's own colour and has no
   ::-webkit-datetime-edit, so hide it the same way while the overlay carries
   the format. The rule is scoped to an empty, unfocused control: a real value
   and the focused native editor both keep their normal colour. */
.date-wrap:not(.has-value):not(:focus-within) input[type='date'] {
  color: transparent;
}

/* === Multi-value control (the app's tag rows) === */
.multi {
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
  min-width: 0;
}
.multi-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.multi-row {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--bg-input);
  font-size: 14px;
  min-width: 0;
}
.multi-row .multi-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}
.multi-add {
  display: flex;
  align-items: stretch;
  gap: var(--space-8);
  min-width: 0;
}
.multi-add .field-input {
  flex: 1;
}
.tag-picker {
  position: relative;
  flex: none;
}
.tag-menu {
  position: absolute;
  left: 0;
  top: calc(100% + 4px);
  z-index: 30;
  min-width: 200px;
  max-width: min(260px, calc(100vw - 48px));
  background-color: var(--dropdown-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow-hover);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
}
.tag-menu[hidden] {
  display: none;
}
.tag-menu button {
  text-align: left;
  padding: 8px;
  border: none;
  background: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.tag-menu button:hover {
  background-color: var(--bg-primary);
  color: var(--accent-color);
}
.hint-wrap {
  position: relative;
}
.field-hint-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  background-color: var(--dropdown-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow-hover);
  padding: var(--space-12);
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.45;
}
.field-hint-panel[hidden] {
  display: none;
}
.field-hint-title {
  color: var(--accent-color);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.field-hint-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.field-hint-service {
  color: var(--text-primary);
  font-weight: 600;
}
.field-hint-close {
  align-self: flex-end;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.field-hint-close:hover {
  color: var(--accent-color);
}

/* === Segmented switch (single-choice document slots) === */
.segmented {
  display: flex;
  gap: var(--space-8);
  flex-wrap: wrap;
}
.segmented-btn {
  flex: 1 1 auto;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.segmented-btn.is-active {
  border-color: var(--accent-color);
  color: var(--accent-color);
  box-shadow: inset 0 0 0 1px var(--accent-color);
}

/* === Checkbox row === */
.check-row {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  font-size: 14px;
  cursor: pointer;
}
.check-row input {
  accent-color: var(--accent-color);
  width: 18px;
  height: 18px;
  flex: none;
}

/* === Issues and result === */
.issue-list,
.warning-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  font-size: 13px;
}
/* An empty list must not leave a hole in the page rhythm. */
.issue-list:empty,
.warning-list:empty {
  display: none;
}
.issue-list li {
  color: var(--color-danger);
}
.warning-list li {
  color: var(--text-secondary);
}
.issue-list li::before,
.warning-list li::before {
  content: '• ';
}
.result-panel {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: var(--space-16);
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}
.result-panel[hidden] {
  display: none;
}
.result-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}
.result-row {
  display: flex;
  gap: var(--space-8);
}
.result-row .btn {
  flex: 1;
}
.result-row--end {
  justify-content: flex-end;
}
.result-row--end .btn {
  flex: 0 0 calc(50% - var(--space-4));
}
.actions-block {
  display: flex;
}
.actions-block .btn {
  width: 100%;
}

/* === Down arrow (jump to the generate button) === */
.fab-down {
  position: fixed;
  left: var(--space-16);
  bottom: var(--space-16);
  z-index: 25;
  width: 44px;
  height: 44px;
  border: 1px solid var(--accent-color);
  border-radius: var(--radius-pill);
  background-color: var(--accent-color);
  color: #000;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--card-shadow-hover);
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab-down[hidden] {
  display: none;
}

/* === Confirm dialog === */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-16);
}
.modal-overlay[hidden] {
  display: none;
}
.modal-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow-hover);
  padding: var(--space-20);
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}
.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}
.modal-message {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.45;
}
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

.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;
}

@media (max-width: 640px) {
  .anketa-wrap {
    padding: var(--space-12) var(--space-12) var(--space-32);
  }
  .anketa-card {
    padding: var(--space-12);
  }
  /* 16px keeps iOS from zooming into a focused field. */
  .field-input,
  .chip,
  .segmented-btn,
  .check-row {
    font-size: 16px;
  }
  .result-row--end .btn {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
