@font-face {
  font-family: "PT Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/PTSans-400-cyr.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: "PT Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/PTSans-400-lat.woff2") format("woff2");
  unicode-range: U+0000-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "PT Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/PTSans-700-cyr.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: "PT Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/PTSans-700-lat.woff2") format("woff2");
  unicode-range: U+0000-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "PT Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/PTMono-400-cyr.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: "PT Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/PTMono-400-lat.woff2") format("woff2");
  unicode-range: U+0000-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "PT Serif";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/PTSerif-700-cyr.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: "PT Serif";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/PTSerif-700-lat.woff2") format("woff2");
  unicode-range: U+0000-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --a-bg: #F4F7F7;
  --a-surface: #FFFFFF;
  --a-ink: #1C2528;
  --a-muted: #5C6C71;
  --a-faint: #8A989C;
  --a-border: #D8E0E1;
  --a-border-soft: #E8EEEE;
  --a-accent: #1F6F78;
  --a-accent-hover: #17575E;
  --a-accent-wash: #E7F0F1;
  --a-st-auto-bg: #FEF3C7;
  --a-st-auto-fg: #92400E;
  --a-st-confirmed-bg: #DCFCE7;
  --a-st-confirmed-fg: #166534;
  --a-st-manual-bg: #DBEAFE;
  --a-st-manual-fg: #1E40AF;
  --a-st-unmatched-bg: #FEE2E2;
  --a-st-unmatched-fg: #991B1B;
  --a-danger: #B42318;
  --a-danger-wash: #FEF3F2;
  --a-danger-border: #FDA29B;
  --a-row-hover: #FAFCFC;
  --a-radius: 6px;
  --a-shadow-panel: -10px 0 32px rgb(28 37 40 / 16%);
  --a-shadow-toast: 0 12px 28px rgb(28 37 40 / 20%);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  color: var(--a-ink);
  background: var(--a-bg);
  font-family: "PT Sans", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--a-ink);
  background: var(--a-bg);
}

button,
input,
select {
  color: inherit;
  font: inherit;
}

button,
a,
label,
input,
select {
  touch-action: manipulation;
}

a {
  color: var(--a-accent);
}

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.75;
}

h1,
h2,
h3,
h4,
p,
dl,
dd {
  margin-top: 0;
}

h1,
h2,
h3,
h4 {
  color: var(--a-ink);
  line-height: 1.2;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(1.75rem, 3vw, 2.25rem);
}

h2 {
  margin-bottom: 4px;
  font-size: 1.25rem;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--a-accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  border-radius: var(--a-radius);
  color: var(--a-surface);
  background: var(--a-accent);
  font-weight: 700;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-header {
  border-bottom: 1px solid var(--a-border);
  background: var(--a-surface);
}

.app-header__inner,
.app-main {
  width: min(100% - 48px, 1280px);
  margin-inline: auto;
}

.app-header__inner {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 12px;
  color: var(--a-ink);
  text-decoration: none;
}

.brand__name {
  font-family: "PT Serif", Georgia, serif;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand__tagline {
  color: var(--a-muted);
  font-size: 0.875rem;
}

.database-count {
  margin: 0;
  color: var(--a-muted);
  font-size: 0.875rem;
  white-space: nowrap;
}

.database-count__number {
  color: var(--a-ink);
  font-family: "PT Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.app-main {
  padding-block: 28px 56px;
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.page-heading--calculation {
  align-items: center;
  margin-bottom: 20px;
}

.page-heading__copy {
  min-width: 0;
}

.page-heading__description,
.section-heading p {
  margin: 0;
  color: var(--a-muted);
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--a-accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.page-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.inline-form {
  margin: 0;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--a-radius);
  cursor: pointer;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
}

.button:hover {
  text-decoration: none;
}

.button:active:not(:disabled) {
  filter: brightness(0.94);
}

.button:disabled,
.button.htmx-request {
  cursor: not-allowed;
  opacity: 0.55;
}

.button--primary {
  color: var(--a-surface);
  background: var(--a-accent);
}

.button--primary:hover:not(:disabled) {
  background: var(--a-accent-hover);
}

.button--secondary {
  border-color: var(--a-border);
  color: var(--a-ink);
  background: var(--a-surface);
}

.button--secondary:hover {
  border-color: var(--a-accent);
  color: var(--a-accent-hover);
}

.button--ghost {
  border-color: transparent;
  color: var(--a-muted);
  background: transparent;
}

.button--ghost:hover {
  color: var(--a-st-unmatched-fg);
  background: var(--a-st-unmatched-bg);
}

.button--wide {
  width: 100%;
}

.button__icon {
  width: 19px;
  height: 19px;
  flex: 0 0 19px;
  stroke-width: 2;
}

.button__count {
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 999px;
  color: var(--a-accent);
  background: rgb(255 255 255 / 82%);
  font-size: 0.75rem;
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--a-radius);
  color: var(--a-muted);
  background: transparent;
  cursor: pointer;
}

.icon-button:hover {
  color: var(--a-ink);
  background: var(--a-bg);
}

.icon-button svg {
  width: 22px;
  height: 22px;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
  padding: 13px 15px;
  border: 1px solid var(--a-danger-border);
  border-radius: var(--a-radius);
  color: var(--a-st-unmatched-fg);
  background: var(--a-danger-wash);
}

.alert .icon {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
}

.alert p {
  margin: 2px 0 0;
}

.alert--panel {
  margin: 0 0 16px;
  font-size: 0.875rem;
}

.upload-card {
  margin-bottom: 34px;
  padding: 20px;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  background: var(--a-surface);
}

.dropzone {
  display: flex;
  min-height: 190px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 24px;
  border: 1.5px dashed var(--a-border);
  border-radius: var(--a-radius);
  color: var(--a-muted);
  background: var(--a-bg);
  cursor: pointer;
  text-align: center;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--a-accent);
  color: var(--a-accent-hover);
  background: var(--a-accent-wash);
}

.dropzone.is-invalid {
  border-color: var(--a-danger);
  background: var(--a-danger-wash);
}

.dropzone__icon {
  width: 46px;
  height: 46px;
  margin-bottom: 14px;
  color: var(--a-accent);
  stroke-width: 1.5;
}

.dropzone__title {
  color: var(--a-ink);
  font-size: 1.0625rem;
  font-weight: 700;
}

.dropzone__hint {
  margin-top: 5px;
  color: var(--a-faint);
  font-size: 0.8125rem;
}

.upload-card__fields {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-top: 16px;
}

.upload-card__submit {
  flex: 0 0 auto;
}

.field {
  display: grid;
  gap: 6px;
}

.field--grow {
  flex: 1 1 auto;
}

.field label,
.candidate-search > label {
  color: var(--a-ink);
  font-size: 0.875rem;
  font-weight: 700;
}

input[type="text"],
input[type="search"],
input[type="number"],
select {
  width: 100%;
  min-height: 42px;
  padding: 8px 11px;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  color: var(--a-ink);
  background: var(--a-surface);
}

input::placeholder {
  color: var(--a-faint);
  opacity: 1;
}

input:hover,
select:hover {
  border-color: var(--a-faint);
}

input:focus,
select:focus {
  border-color: var(--a-accent);
}

.field-hint,
.field-error {
  margin: 0;
  font-size: 0.8125rem;
}

.field-hint {
  color: var(--a-muted);
}

.field-error,
.inline-error {
  color: var(--a-danger);
}

.field-error:not([hidden]) {
  margin-top: 9px;
}

.inline-error {
  margin: 0 0 10px;
  padding: 9px 10px;
  border-radius: var(--a-radius);
  background: var(--a-danger-wash);
  font-size: 0.875rem;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-heading--compact {
  align-items: center;
}

.record-count {
  padding: 3px 8px;
  border: 1px solid var(--a-border);
  border-radius: 999px;
  color: var(--a-muted);
  background: var(--a-surface);
  font-size: 0.75rem;
  white-space: nowrap;
}

.table-frame {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  background: var(--a-surface);
  scrollbar-color: var(--a-border) transparent;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--a-ink);
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--a-border-soft);
  vertical-align: middle;
}

.data-table th {
  color: var(--a-muted);
  background: var(--a-bg);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: left;
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:not(.is-selected):hover td {
  background: var(--a-row-hover);
}

.calculations-table {
  min-width: 960px;
}

.lines-table {
  min-width: 1080px;
  table-layout: fixed;
}

.lines-table thead th {
  position: sticky;
  z-index: 2;
  top: 0;
}

.table-frame--lines {
  max-height: min(66vh, 720px);
}

.line-row {
  cursor: pointer;
}

.line-row.is-selected td {
  background: var(--a-accent-wash);
}

.line-row.is-selected td:first-child {
  background-image: linear-gradient(to right, var(--a-accent) 0 3px, transparent 3px);
}

.row-number-cell {
  width: 58px;
  text-align: center !important;
}

.row-open-button {
  display: inline-grid;
  min-width: 38px;
  min-height: 38px;
  place-items: center;
  padding: 4px;
  border: 0;
  border-radius: var(--a-radius);
  color: var(--a-accent);
  background: transparent;
  cursor: pointer;
}

.row-open-button:hover {
  color: var(--a-surface);
  background: var(--a-accent);
}

.work-cell {
  display: table-cell;
  width: 34%;
}

.work-cell__equipment,
.work-cell__work {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.work-cell__equipment {
  font-weight: 700;
}

.work-cell__work {
  margin-top: 2px;
  color: var(--a-muted);
}

.col-param {
  width: 14%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-qty,
.col-grade {
  width: 8%;
}

.col-base,
.col-total {
  width: 11%;
}

.status-cell {
  width: 112px;
}

.numeric {
  font-variant-numeric: tabular-nums;
  text-align: right !important;
}

.mono {
  font-family: "PT Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.emphasis {
  font-weight: 700;
}

.muted {
  color: var(--a-muted);
}

.nowrap {
  white-space: nowrap;
}

.file-name {
  display: inline-block;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

.badge-group {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.status-badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
}

.status-badge__dot {
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge__count {
  padding-left: 1px;
  font-family: "PT Mono", monospace;
}

.status-badge--auto {
  color: var(--a-st-auto-fg);
  background: var(--a-st-auto-bg);
}

.status-badge--confirmed {
  color: var(--a-st-confirmed-fg);
  background: var(--a-st-confirmed-bg);
}

.status-badge--manual {
  color: var(--a-st-manual-fg);
  background: var(--a-st-manual-bg);
}

.status-badge--unmatched {
  color: var(--a-st-unmatched-fg);
  background: var(--a-st-unmatched-bg);
}

.actions-column {
  width: 220px;
}

.actions-cell {
  white-space: nowrap;
}

.text-link {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  padding: 4px 5px;
  font-weight: 700;
  text-decoration: none;
}

.text-link:hover {
  text-decoration: underline;
}

.text-link--secondary {
  margin-left: 5px;
  color: var(--a-muted);
  font-weight: 400;
}

.empty-state {
  padding: 50px 20px !important;
  color: var(--a-muted);
  text-align: center;
}

.empty-state > * {
  display: block;
  margin-inline: auto;
}

.empty-state strong {
  color: var(--a-ink);
}

.empty-state__icon {
  width: 44px;
  height: 44px;
  margin-bottom: 12px;
  color: var(--a-faint);
  stroke-width: 1.5;
}

.empty-state--compact {
  padding-block: 28px !important;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 18px;
  color: var(--a-muted);
  font-size: 0.875rem;
}

.breadcrumbs a {
  min-height: 30px;
  padding-block: 4px;
  text-decoration: none;
}

.breadcrumbs a:hover {
  text-decoration: underline;
}

.breadcrumbs__separator {
  width: 15px;
  height: 15px;
  color: var(--a-faint);
}

.breadcrumbs span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr)) minmax(180px, 1.35fr);
  gap: 10px;
  margin-bottom: 28px;
}

.stat-card {
  display: flex;
  min-height: 114px;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px 15px;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  background: var(--a-surface);
}

.stat-card .status-badge {
  align-self: flex-start;
}

.stat-card__label {
  color: var(--a-muted);
  font-size: 0.8125rem;
  font-weight: 700;
}

.stat-card__value {
  margin-top: 4px;
  font-size: 1.65rem;
  font-weight: 400;
  line-height: 1;
}

.stat-card__value--total {
  font-size: clamp(1.65rem, 3vw, 2.15rem);
  font-weight: 700;
}

.stat-card__note {
  color: var(--a-faint);
  font-size: 0.75rem;
}

.stat-card--auto {
  border-top: 3px solid var(--a-st-auto-fg);
}

.stat-card--confirmed {
  border-top: 3px solid var(--a-st-confirmed-fg);
}

.stat-card--unmatched {
  border-top: 3px solid var(--a-st-unmatched-fg);
}

.stat-card--total {
  color: var(--a-surface);
  border-color: var(--a-accent);
  background: var(--a-accent);
}

.stat-card--total .stat-card__label,
.stat-card--total .stat-card__value,
.stat-card--total .stat-card__note {
  color: var(--a-surface);
}

.stat-card--total .stat-card__note {
  opacity: 0.78;
}

.drawer-backdrop {
  position: fixed;
  z-index: 90;
  inset: 0;
  background: rgb(28 37 40 / 28%);
}

.panel-is-open {
  overflow: hidden;
}

.line-panel {
  position: fixed;
  z-index: 100;
  top: 0;
  right: 0;
  display: flex;
  width: min(420px, 100vw);
  height: 100vh;
  height: 100dvh;
  flex-direction: column;
  border-left: 1px solid var(--a-border);
  background: var(--a-surface);
  box-shadow: var(--a-shadow-panel);
  animation: panel-in 120ms ease-out both;
}

.line-panel__header {
  display: flex;
  min-height: 76px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--a-border);
  background: var(--a-surface);
}

.line-panel__header .eyebrow {
  margin-bottom: 2px;
}

.line-panel__header h2 {
  margin: 0;
}

.line-panel__scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 18px 20px;
  scroll-padding: 88px 0 120px;
}

.panel-section {
  padding-block: 18px;
  border-bottom: 1px solid var(--a-border-soft);
}

.panel-section__heading {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 13px;
}

.panel-section__number {
  color: var(--a-faint);
  font-size: 0.6875rem;
}

.source-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 0;
}

.source-grid__item {
  display: grid;
  grid-template-columns: minmax(92px, 0.75fr) minmax(0, 1.5fr);
  gap: 10px;
  padding: 8px 9px;
  border-radius: var(--a-radius);
  background: var(--a-bg);
}

.source-grid dt {
  color: var(--a-faint);
  font-size: 0.75rem;
}

.source-grid dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--a-muted);
  font-size: 0.8125rem;
}

.panel-form {
  margin: 0;
}

.matched-card {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  background: var(--a-bg);
}

.matched-card__label {
  display: block;
  margin-bottom: 10px;
  overflow-wrap: anywhere;
  font-family: "PT Mono", monospace;
  font-size: 0.8125rem;
  line-height: 1.35;
}

.matched-card__facts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 0;
}

.matched-card__facts > div {
  min-width: 0;
  padding: 7px;
  border-radius: 4px;
  background: var(--a-surface);
}

.matched-card__facts dt {
  color: var(--a-faint);
  font-size: 0.6875rem;
}

.matched-card__facts dd {
  margin: 2px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.75rem;
  white-space: nowrap;
}

.matched-card__note {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 10px 0 0;
  color: var(--a-st-auto-fg);
  font-size: 0.8125rem;
}

.inline-icon {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  margin-top: 1px;
}

.panel-empty,
.candidate-empty {
  margin: 0;
  padding: 11px 12px;
  border-radius: var(--a-radius);
  color: var(--a-muted);
  background: var(--a-bg);
  font-size: 0.8125rem;
}

.panel-empty {
  margin-bottom: 13px;
}

.panel-empty--compact {
  margin-top: 12px;
  margin-bottom: 0;
}

.candidate-list {
  display: grid;
  gap: 7px;
}

.candidate-option {
  position: relative;
  display: grid;
  min-height: 52px;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--a-border-soft);
  border-radius: var(--a-radius);
  background: var(--a-surface);
  cursor: pointer;
}

.candidate-option:hover {
  border-color: var(--a-accent);
  background: var(--a-accent-wash);
}

.candidate-option.is-selected,
.candidate-option:has(input:checked) {
  border-color: var(--a-accent);
  background: linear-gradient(to right, var(--a-accent) 0 3px, var(--a-accent-wash) 3px);
}

.candidate-option:has(input:focus-visible) {
  outline: 2px solid var(--a-accent);
  outline-offset: 2px;
}

.candidate-option input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--a-accent);
}

.candidate-option__body,
.candidate-option__label,
.candidate-option__meta {
  min-width: 0;
}

.candidate-option__body,
.candidate-option__label {
  display: block;
}

.candidate-option__label {
  overflow-wrap: anywhere;
  color: var(--a-ink);
  font-family: "PT Mono", monospace;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.35;
}

.candidate-option__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 5px;
  color: var(--a-faint);
  font-size: 0.6875rem;
}

.candidate-option__score {
  flex: 0 0 auto;
  color: var(--a-muted);
}

.candidate-search {
  display: grid;
  gap: 6px;
  margin-top: 16px;
}

.search-input {
  position: relative;
}

.search-input svg {
  position: absolute;
  top: 50%;
  left: 11px;
  width: 18px;
  height: 18px;
  color: var(--a-faint);
  pointer-events: none;
  transform: translateY(-50%);
}

.search-input input {
  padding-left: 37px;
}

.search-results {
  margin-top: 7px;
}

.search-results.htmx-request {
  min-height: 58px;
  opacity: 0.62;
}

.reference-coefficients {
  margin-top: 14px;
}

.reference-coefficients h4 {
  margin-bottom: 7px;
  color: var(--a-muted);
  font-size: 0.8125rem;
}

.reference-coefficients ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.reference-coefficients li {
  display: grid;
  gap: 2px;
  padding: 8px 9px;
  border-radius: var(--a-radius);
  color: var(--a-muted);
  background: var(--a-bg);
  font-size: 0.75rem;
}

.reference-coefficients__value {
  color: var(--a-ink);
}

.field-group {
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}

.field-group legend {
  padding: 0 0 7px;
  color: var(--a-ink);
  font-size: 0.875rem;
  font-weight: 700;
}

.radio-group {
  display: grid;
  gap: 7px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--a-muted);
  font-size: 0.8125rem;
}

.radio-option input {
  width: 16px;
  height: 16px;
  accent-color: var(--a-accent);
}

.applied-coefficients-grid {
  display: grid;
  gap: 8px;
}

.applied-coefficient-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  border: 1px solid var(--a-border-soft);
  border-radius: var(--a-radius);
  background: var(--a-bg);
}

.checkbox-label {
  display: flex;
  flex: 1 1 180px;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--a-ink);
  font-size: 0.8125rem;
}

.checkbox-label input {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  accent-color: var(--a-accent);
}

.applied-coefficient-item select,
.applied-coefficient-item input[type="number"] {
  width: auto;
  min-width: 96px;
  min-height: 36px;
  flex: 0 0 auto;
}

.coefficient-breakdown {
  margin-top: 14px;
}

.coefficient-breakdown h4 {
  margin-bottom: 7px;
  color: var(--a-muted);
  font-size: 0.8125rem;
}

.coefficient-breakdown ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.coefficient-breakdown li {
  padding: 8px 9px;
  border-radius: var(--a-radius);
  color: var(--a-muted);
  background: var(--a-bg);
  font-size: 0.75rem;
}

.line-panel__actions {
  padding-top: 18px;
}

.reset-form {
  margin: 8px 0 0;
}

.action-result {
  position: fixed;
  z-index: 150;
  right: 20px;
  bottom: 20px;
  pointer-events: none;
}

.toast {
  display: flex;
  max-width: min(360px, calc(100vw - 32px));
  min-height: 48px;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  color: var(--a-ink);
  background: var(--a-surface);
  box-shadow: var(--a-shadow-toast);
  font-weight: 700;
  pointer-events: auto;
  animation: toast-in 160ms ease-out both;
}

.toast__icon {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  color: var(--a-st-confirmed-fg);
  stroke-width: 2;
}

@keyframes panel-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1040px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

  .stat-card--total {
    grid-column: span 2;
  }
}

@media (max-width: 780px) {
  .app-header__inner,
  .app-main {
    width: min(100% - 32px, 1280px);
  }

  .app-header__inner {
    min-height: 64px;
  }

  .brand__tagline {
    display: none;
  }

  .page-heading--calculation {
    align-items: stretch;
    flex-direction: column;
  }

  .page-actions {
    justify-content: flex-start;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

  .stat-card--total {
    grid-column: span 2;
  }
}

@media (max-width: 580px) {
  .app-header__inner,
  .app-main {
    width: min(100% - 24px, 1280px);
  }

  .app-main {
    padding-block: 20px 40px;
  }

  .database-count {
    max-width: 120px;
    white-space: normal;
    text-align: right;
  }

  .page-heading {
    margin-bottom: 16px;
  }

  .upload-card {
    padding: 12px;
  }

  .dropzone {
    min-height: 168px;
    padding: 18px 12px;
  }

  .upload-card__fields {
    align-items: stretch;
    flex-direction: column;
  }

  .upload-card__submit {
    width: 100%;
  }

  .page-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .page-actions .button,
  .page-actions .inline-form,
  .page-actions .inline-form .button {
    width: 100%;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .action-result {
    right: 12px;
    bottom: 12px;
    left: 12px;
  }

  .toast {
    max-width: none;
  }
}

@media (max-width: 420px) {
  .line-panel {
    width: 100vw;
    border-left: 0;
  }

  .line-panel__header {
    padding-inline: 14px;
  }

  .line-panel__scroll {
    padding-inline: 14px;
  }

  .source-grid__item {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .candidate-option__meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .matched-card__facts {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .app-header,
  .page-actions,
  .drawer-backdrop,
  .line-panel,
  .action-result {
    display: none !important;
  }

  body,
  .app-main {
    background: #fff;
  }

  .app-main {
    width: 100%;
  }

  .table-frame {
    overflow: visible;
  }
}

/* Редактор продолжает экран сверки: отдельный блок сохраняет читаемость PDF и истории. */
.editor-section {
  margin-top: 28px;
  padding: 20px;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  background: var(--a-surface);
}

.editor-heading {
  align-items: flex-end;
  margin-bottom: 16px;
}

.editor-heading .eyebrow,
.editor-heading h2,
.editor-heading p,
.editor-proof h3,
.editor-proof p,
.editor-history h3 {
  margin-bottom: 0;
}

.editor-heading p,
.editor-proof p {
  color: var(--a-muted);
}

.editor-feedback,
.editor-empty {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: var(--a-radius);
  color: var(--a-st-confirmed-fg);
  background: var(--a-st-confirmed-bg);
}

.editor-empty {
  color: var(--a-muted);
  background: var(--a-bg);
}

.editor-error {
  margin-bottom: 16px;
}

.editor-error strong,
.editor-error p {
  display: block;
}

.editor-form,
.editor-import-form {
  display: grid;
  gap: 16px;
}

.editor-table-frame {
  max-height: min(70vh, 760px);
}

.editor-table {
  min-width: 860px;
}

.editor-table thead {
  position: sticky;
  z-index: 2;
  top: 0;
}

.editor-table th,
.editor-table td {
  min-width: 128px;
  padding: 8px;
  vertical-align: top;
}

.editor-table input,
.editor-table select {
  min-width: 112px;
  min-height: 38px;
  padding: 7px 8px;
  background: var(--a-surface);
}

.editor-code-column,
.editor-row-code {
  min-width: 112px !important;
}

.editor-code-column,
.editor-row-code {
  position: sticky;
  left: 0;
}

.editor-code-column {
  z-index: 3;
}

.editor-row-code {
  z-index: 1;
  background: var(--a-surface);
}

.editor-param-column {
  min-width: 180px !important;
}

.editor-value-column {
  min-width: 154px !important;
}

.editor-field-code,
.editor-axis-key,
.editor-history-meta,
.editor-exact-value {
  display: block;
  margin-top: 4px;
  color: var(--a-muted);
  font-size: 0.75rem;
  font-weight: 400;
}

.editor-exact-value {
  white-space: nowrap;
}

.editor-column-settings th,
.editor-column-settings td {
  color: var(--a-muted);
  background: var(--a-bg);
  font-size: 0.75rem;
}

.editor-proof {
  display: grid;
  grid-template-columns: minmax(190px, 0.8fr) minmax(160px, 0.45fr) minmax(260px, 1.4fr);
  align-items: start;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--a-border-soft);
  border-radius: var(--a-radius);
  background: var(--a-bg);
}

.editor-comment-field textarea,
.editor-undo textarea {
  width: 100%;
  min-height: 78px;
  resize: vertical;
  padding: 9px 11px;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  color: var(--a-ink);
  background: var(--a-surface);
  font: inherit;
  line-height: 1.5;
}

.editor-comment-field textarea:focus,
.editor-undo textarea:focus {
  border-color: var(--a-accent);
  outline: 2px solid var(--a-accent);
  outline-offset: 2px;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.editor-history {
  margin-top: 20px;
}

.editor-history__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.editor-history-table,
.editor-preview-table {
  min-width: 920px;
}

.editor-history-table td,
.editor-preview-table td {
  vertical-align: top;
  overflow-wrap: anywhere;
}

.editor-current,
.editor-reverted {
  color: var(--a-st-confirmed-fg);
  font-size: 0.8125rem;
  font-weight: 700;
}

.editor-reverted {
  color: var(--a-muted);
}

.editor-undo {
  min-width: 220px;
}

.editor-undo > summary {
  width: max-content;
  list-style: none;
}

.editor-undo > summary::-webkit-details-marker {
  display: none;
}

.editor-undo[open] > summary {
  margin-bottom: 10px;
}

.editor-undo form {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--a-border-soft);
  border-radius: var(--a-radius);
  background: var(--a-bg);
}

.editor-source {
  margin-bottom: 28px;
}

.editor-import-form {
  grid-template-columns: minmax(260px, 1fr) minmax(160px, 0.35fr) minmax(280px, 1fr);
  align-items: flex-end;
}

.editor-file-field input[type="file"] {
  width: 100%;
  min-height: 42px;
  padding: 7px;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  background: var(--a-surface);
}

.editor-import-form > .editor-actions,
.editor-import-preview {
  grid-column: 1 / -1;
}

.editor-import-preview:empty {
  display: none;
}

.editor-preview-actions {
  margin-top: 12px;
}

@media (max-width: 900px) {
  .editor-proof,
  .editor-import-form {
    grid-template-columns: 1fr;
  }

  .editor-import-form > .editor-actions,
  .editor-import-preview {
    grid-column: auto;
  }
}

@media (max-width: 620px) {
  .editor-section {
    padding: 16px 12px;
  }

  .editor-heading,
  .editor-history__heading {
    align-items: stretch;
    flex-direction: column;
  }

  .editor-heading .button,
  .editor-actions .button {
    width: 100%;
  }
}

@media print {
  .editor-form,
  .editor-source,
  .editor-undo {
    display: none !important;
  }
}

/* --- волна 6: навигация разделов (оркестратор) --- */
.app-nav { display: flex; gap: 18px; margin-left: 40px; margin-right: auto; }
.app-nav__link {
  color: var(--a-muted); text-decoration: none; font-size: 14px;
  padding: 4px 2px; border-bottom: 2px solid transparent;
}
.app-nav__link:hover { color: var(--a-ink); }
.app-nav__link[aria-current="page"], .app-nav__link.is-active {
  color: var(--a-accent); border-bottom-color: var(--a-accent);
}
