:root {
  color-scheme: light;
  --fg: #16181d;
  --bg: #ffffff;
  --muted: #5b6270;
  --border: #d8dbe2;
  --accent: #1f5eff;
  --danger: #b3261e;
  --warning: #8a5300;
  --radius: 8px;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
}

main {
  max-width: 72rem;
  margin: 0 auto;
  padding: var(--space-4);
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 var(--space-4);
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 var(--space-2);
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

input[type="text"],
input[type="password"],
input[type="file"] {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--bg);
  color: var(--fg);
}

button {
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 120ms ease-out, filter 120ms ease-out;
}

button:hover {
  filter: brightness(0.92);
}

button:active {
  transform: scale(0.97);
}

a {
  color: var(--accent);
}

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

form > div,
.review-card__form {
  margin-bottom: var(--space-3);
}

[role="alert"] {
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-4);
}

.review-list {
  display: grid;
  gap: var(--space-4);
}

.review-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.review-card__unit {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.9rem;
}

.review-card__supplied {
  margin: 0 0 var(--space-2);
}

.review-card__status {
  font-weight: 600;
  margin: 0 0 var(--space-2);
}

.review-card__evidence {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: var(--space-2) var(--space-4);
  margin: 0 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--border) 35%, transparent);
  font-size: 0.9rem;
}

.review-card__evidence div {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.review-card__evidence dt {
  color: var(--muted);
  font-weight: 600;
}

.review-card__evidence dd {
  margin: 0;
}

.review-card__candidate-evidence {
  margin: 0.15rem 0 var(--space-2);
  color: var(--muted);
  font-size: 0.85rem;
}

.review-card__status--no-target {
  color: var(--danger);
}

.review-card__status--warning {
  color: var(--warning);
}

.review-card__form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-2);
}

.review-card__form label {
  margin-bottom: 0.25rem;
}

.review-card__form input[type="text"] {
  width: auto;
  min-width: 8rem;
}

.review-card__checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 400;
}

.review-card__checkbox input {
  width: auto;
}

/* App shell: brand link, step indicator, logout -- present on every
   authenticated page (upload/review/result), never on login. */
.app-shell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
  max-width: 72rem;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.app-shell__brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--fg);
  white-space: nowrap;
  flex-shrink: 0;
}

.app-shell__steps {
  display: flex;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
  color: var(--muted);
  flex: 1 1 auto;
}

.app-shell__step--current {
  color: var(--fg);
  font-weight: 600;
}

.app-shell__logout {
  margin: 0;
}

/* Custom accessible file picker: the real <input type="file"> stays in the
   layout (focusable, keyboard-operable, works with setInputFiles) but is
   made visually transparent and stretched over the styled control, so the
   browser's native locale-dependent chrome ("Choose File"/"No file
   chosen") is never what the user sees -- only the Russian label/status. */
.file-field__control {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.6rem;
}

.file-field__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.file-field__button {
  padding: 0.3rem 0.7rem;
  border-radius: calc(var(--radius) - 2px);
  background: var(--border);
  color: var(--fg);
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
}

.file-field__status {
  color: var(--muted);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-field__control:focus-within {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Candidate list keeps real <ul>/<li> semantics (screen-reader list
   navigation) without the visual bullet -- the checkbox itself is the
   marker the eye needs. */
.review-card__candidate-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-3);
}

.review-card__candidate {
  padding: var(--space-2) 0;
}

.review-card__candidate + .review-card__candidate {
  border-top: 1px solid var(--border);
}

.distribution-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 var(--space-3);
  font-size: 0.9rem;
}

.distribution-table th,
.distribution-table td {
  text-align: left;
  padding: 0.35rem var(--space-2);
  border-bottom: 1px solid var(--border);
}

.distribution-table th {
  color: var(--muted);
  font-weight: 600;
}

@media (min-width: 60rem) {
  .review-list {
    grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr));
    align-items: start;
  }
}

@media (max-width: 40rem) {
  main {
    padding: var(--space-3);
  }

  .app-shell {
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
  }

  /* Force a deterministic two-row stack -- brand + steps on row one, logout
     on its own row two -- regardless of how much the steps list's width
     varies between states (the bold current-step label differs per page:
     "Загрузка"/"Проверка"/"Результат"), so which row each item lands on
     never depends on a per-state pixel-width coincidence. */
  .app-shell__brand {
    order: 1;
  }

  .app-shell__steps {
    order: 2;
    gap: var(--space-2);
    font-size: 0.82rem;
  }

  .app-shell__logout {
    order: 3;
    flex-basis: 100%;
  }

  .review-card {
    padding: var(--space-3);
  }

  .review-card__form {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
