/* Шрифт Golos Text распространяется по SIL OFL 1.1; лицензия лежит в fonts/. */
@font-face {
  font-family: 'Golos Text';
  src: url('fonts/GolosText-Variable.ttf') format('truetype');
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
}

/* Визуальные токены и адаптивная компоновка калькулятора. */
:root {
  color-scheme: light;
  --md-sys-color-primary: #c90820;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #fff2f3;
  --md-sys-color-on-primary-container: #a50019;
  --md-sys-color-secondary: #087e5b;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #e4f7ef;
  --md-sys-color-on-secondary-container: #075d44;
  --md-sys-color-tertiary: #97620b;
  --md-sys-color-on-tertiary: #ffffff;
  --md-sys-color-tertiary-container: #fff5d9;
  --md-sys-color-on-tertiary-container: #714708;
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #410002;
  --md-sys-color-surface: #eaf3fb;
  --md-sys-color-surface-dim: #dbe8f4;
  --md-sys-color-surface-bright: #ffffff;
  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #ffffff;
  --md-sys-color-surface-container: #f2f6fa;
  --md-sys-color-surface-container-high: #edf3f9;
  --md-sys-color-surface-container-highest: #e4edf6;
  --md-sys-color-on-surface: #101d42;
  --md-sys-color-on-surface-variant: #637595;
  --md-sys-color-outline: #a9bed4;
  --md-sys-color-outline-variant: #d9e3ef;
  --md-sys-color-inverse-surface: #101d42;
  --md-sys-color-inverse-on-surface: #ffffff;
  --md-sys-shape-corner-xs: 5px;
  --md-sys-shape-corner-sm: 8px;
  --md-sys-shape-corner-md: 14px;
  --md-sys-shape-corner-lg: 16px;
  --md-sys-shape-corner-xl: 18px;
  --md-sys-elevation-1: 0 2px 10px rgba(38, 67, 104, .06);
  --md-sys-elevation-2: 0 6px 18px rgba(38, 67, 104, .12);
  --app-background-overlay: rgba(234, 243, 251, .77);
  --app-panel: rgba(255, 255, 255, .96);
  --app-table-alt: #f2f6fa;
  --app-ktu-good: #e4f7ef;
  --app-ktu-good-text: #087e5b;
  --app-ktu-good-border: #62c99e;
  --app-ktu-low: #fff5d9;
  --app-ktu-low-text: #97620b;
  --app-ktu-low-border: #eab84e;
}

[data-theme="dark"] {
  color-scheme: dark;
  --md-sys-color-primary: #ff8e9c;
  --md-sys-color-on-primary: #39000a;
  --md-sys-color-primary-container: #59202d;
  --md-sys-color-on-primary-container: #ffd9de;
  --md-sys-color-secondary: #85dbb3;
  --md-sys-color-on-secondary: #003825;
  --md-sys-color-secondary-container: #174d3d;
  --md-sys-color-on-secondary-container: #bcecd5;
  --md-sys-color-tertiary: #efc67a;
  --md-sys-color-on-tertiary: #382300;
  --md-sys-color-tertiary-container: #59411d;
  --md-sys-color-on-tertiary-container: #ffdfaa;
  --md-sys-color-error: #ffb4ab;
  --md-sys-color-on-error: #690005;
  --md-sys-color-error-container: #70232a;
  --md-sys-color-on-error-container: #ffdad6;
  --md-sys-color-surface: #101826;
  --md-sys-color-surface-dim: #101826;
  --md-sys-color-surface-bright: #303c4d;
  --md-sys-color-surface-container-lowest: #182333;
  --md-sys-color-surface-container-low: #1c2839;
  --md-sys-color-surface-container: #243244;
  --md-sys-color-surface-container-high: #2a3a4e;
  --md-sys-color-surface-container-highest: #35465a;
  --md-sys-color-on-surface: #e9f0fb;
  --md-sys-color-on-surface-variant: #b4c3d7;
  --md-sys-color-outline: #8296af;
  --md-sys-color-outline-variant: #40546b;
  --md-sys-color-inverse-surface: #e9f0fb;
  --md-sys-color-inverse-on-surface: #101d42;
  --app-background-overlay: rgba(9, 18, 31, .89);
  --app-panel: rgba(28, 40, 57, .97);
  --app-table-alt: #243244;
  --app-ktu-good: #174d3d;
  --app-ktu-good-text: #bcecd5;
  --app-ktu-good-border: #62c99e;
  --app-ktu-low: #59411d;
  --app-ktu-low-text: #ffdfaa;
  --app-ktu-low-border: #eab84e;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  min-width: 0;
  color: var(--md-sys-color-on-surface);
  background-color: var(--md-sys-color-surface);
  background-image: linear-gradient(var(--app-background-overlay), var(--app-background-overlay)), url("img/bg-img.png");
  background-position: center top;
  background-size: cover;
  background-attachment: fixed;
  font-family: "Golos Text", "Google Sans Text", "Roboto", Arial, sans-serif;
}
.mono { font-family: inherit; font-variant-numeric: tabular-nums; }
button, input, select, textarea { font: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}
svg { flex: none; }
.app-icon { width: 18px; height: 18px; stroke-width: 1; flex: none; }
.section-icon { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; flex: none; border-radius: 50%; color: var(--md-sys-color-primary); background: var(--md-sys-color-primary-container); font-size: 17px; }
.model-icon { color: var(--md-sys-color-on-surface-variant); font-size: 18px; flex: none; }
.selected .model-icon { color: var(--md-sys-color-primary); }

/* Общий каркас: карточки равной визуальной плотности и непрерывный поток. */
.app-header, .app-shell { width: min(100% - 4rem, 1536px); margin-inline: auto; }
.app-header { margin-top: 28px; border-radius: 14px; background: var(--app-panel) !important; border: 0 !important; }
.app-header-inner { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 16px 22px; }
.app-brand { display: flex; align-items: center; gap: 24px; min-width: 0; }
.app-brand-logo { display: flex; align-items: center; gap: 8px; flex: none; color: var(--md-sys-color-on-surface); }
.app-brand-logo img { display: block; width: 103px; height: auto; }
.app-brand-logo span { max-width: 80px; padding-left: 8px; border-left: 1px solid #9a0a32; font-size: 10px; font-weight: 700; line-height: 1.1; text-transform: uppercase; }
[data-theme="dark"] .app-brand-logo img { background: #fff; border-radius: 5px; padding: 4px; }
.app-brand h1 { font-size: clamp(20px, 1.6vw, 26px); line-height: 1.2; letter-spacing: -.025em; }
.app-header-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.app-shell { padding-block: 20px 48px; max-width: 1536px; display: flex; flex-direction: column; gap: 16px; }
.app-top-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.app-top-grid > *, .app-shell > *, .app-shell section, .app-shell article { min-width: 0; }
.app-presets, .app-model, .app-summary, .app-operators, .app-nalad-section, .app-detail { min-width: 0; }
.app-presets, .app-model, .app-summary, .app-operators, .app-nalad-section, .app-detail { padding: 16px 22px; }
.app-summary { background: var(--app-panel); border: 1px solid var(--md-sys-color-outline-variant); border-radius: 14px; }
.app-summary h2, .app-shell h2 { font-size: 19px; line-height: 1.25; font-weight: 700; letter-spacing: -.015em; }
.app-summary .summary-kicker, .app-summary .app-summary-label { color: var(--md-sys-color-on-surface-variant); font-size: 12px; }
.app-summary .summary-main, .app-summary .app-summary-total { color: var(--md-sys-color-primary); font-size: clamp(24px, 2vw, 30px); line-height: 1.2; font-weight: 700; }
.app-summary dl, .app-summary .summary-list { display: grid; gap: 12px; margin-top: 20px; }
.app-summary dl > div, .app-summary .summary-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.app-summary dt { color: var(--md-sys-color-on-surface-variant); }
.app-summary dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.app-summary-content { display: grid; grid-template-columns: minmax(0, 1fr) minmax(130px, .9fr); align-items: center; gap: 16px; min-width: 0; }
.app-summary-data, .app-summary-chart { min-width: 0; }
.app-summary-chart { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; }
.app-summary-chart svg { display: block; width: min(100%, 220px); height: auto; }
.m3-card { background: var(--app-panel); border-color: var(--md-sys-color-outline-variant); border-radius: 14px; box-shadow: var(--md-sys-elevation-1); }
.m3-selection-card { border-width: 1px; border-radius: 9px; background: var(--md-sys-color-surface-container); min-width: 0; }
.m3-selection-card.selected { border-color: var(--md-sys-color-primary) !important; background: var(--md-sys-color-primary-container) !important; box-shadow: none; }
.m3-selection-card.selected .card-title { color: var(--md-sys-color-primary) !important; }
.m3-selection-card.selected .card-desc { color: var(--md-sys-color-on-surface-variant) !important; opacity: 1; }
#boxPoolModeModel, #boxPoolModeAnchor { background: var(--md-sys-color-surface-container) !important; border-color: var(--md-sys-color-outline-variant) !important; }
#presetButtonsContainer { display: flex; flex-wrap: wrap; gap: 8px; }
#presetButtonsContainer .m3-chip { flex: 0 1 auto; min-height: 44px; padding: 8px 10px; border-color: var(--md-sys-color-outline-variant); background: var(--md-sys-color-surface-container); }
#presetButtonsContainer .m3-chip.active { color: var(--md-sys-color-primary) !important; border-color: var(--md-sys-color-primary) !important; background: var(--md-sys-color-primary-container) !important; box-shadow: none; }
#presetBadge { white-space: normal; flex-shrink: 1; min-width: 0; overflow-wrap: anywhere; }

/* Кнопки и поля рассчитываются по содержимому, с достаточной зоной нажатия. */
.m3-btn { height: auto; min-height: 40px; width: auto; padding: 9px 12px; border-radius: 8px; font-weight: 600; font-family: inherit; line-height: 20px; }
.m3-btn-sm { min-height: 36px; padding: 7px 12px; }
.m3-btn-filled { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); box-shadow: none; }
.m3-btn-tonal, .m3-btn-outlined { color: var(--md-sys-color-on-surface); background: var(--md-sys-color-surface-container-lowest); border: 1px solid var(--md-sys-color-outline-variant); }
.m3-icon-btn { width: 40px; height: 40px; border: 1px solid var(--md-sys-color-outline-variant); border-radius: 8px; background: var(--md-sys-color-surface-container-lowest); }
.m3-input, .op-input { border-color: var(--md-sys-color-outline-variant); background: var(--md-sys-color-surface-container-lowest); border-radius: 6px; }
.m3-input:disabled, .op-input:disabled { opacity: 1; }
.app-shell input[type="number"] { text-align: center !important; font-variant-numeric: tabular-nums; }
.app-shell input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
.app-shell input[type="number"]::-webkit-inner-spin-button, .app-shell input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.app-shell input[type="text"] { text-align: left; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--md-sys-color-primary); }

/* У таблиц одинаковые строки, внутренние поля и единое выравнивание. */
#tableViewContainer, .app-nalad-section .table-scroll, .app-table-scroll { position: relative; overflow-x: auto; overscroll-behavior-x: contain; border: 1px solid var(--md-sys-color-outline-variant); border-radius: 9px; }
.app-nalad-section > .overflow-x-auto { position: relative; }
.app-card-schedule { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; color: var(--md-sys-color-on-surface-variant); font-size: 12px; }
.app-card-schedule label { display: grid; gap: 5px; }
.app-card-schedule input { width: 80px; min-height: 38px; padding: 6px; }
.app-card-schedule .slash { padding-bottom: 9px; }
#tableViewContainer table, .app-nalad-section table { width: 100%; min-width: 1050px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.app-nalad-section table, table.nal-table { min-width: 720px; }
.app-nalad-section.is-empty table.nal-table { min-width: 0; }
.app-nalad-section.is-empty thead { display: none; }
#operatorsTableHead th, .app-nalad-section thead th { height: 65px; padding: 8px 6px; text-align: center; font-size: 10px; line-height: 1.25; background: var(--md-sys-color-surface-container-high); }
#operatorsTableBody td, .app-nalad-section tbody td { height: 58px; padding: 8px 6px; vertical-align: middle; text-align: center; border-bottom: 1px solid var(--md-sys-color-outline-variant); }
#operatorsTableBody td:first-child, .app-nalad-section tbody td:first-child { text-align: left; }
#operatorsTableBody tr:nth-child(even), .app-nalad-section tbody tr:nth-child(even) { background: var(--app-table-alt); }
#operatorsTableFoot td, .app-nalad-section tfoot td, .app-nalad-section tfoot th { height: 52px; padding: 8px 6px; vertical-align: middle; background: var(--md-sys-color-surface-container-high); text-align: center; }
#operatorsTableFoot td:first-child, .app-nalad-section tfoot td:first-child, .app-nalad-section tfoot th:first-child { text-align: left; }
#operatorsTableBody .op-input, .app-nalad-section tbody input { min-height: 34px; max-width: 100%; }
#operatorsTableBody input[data-field="name"] { min-width: 150px; width: 100%; }
#operatorsTableBody input[data-field="d"], #operatorsTableBody input[data-field="ktu"] { min-width: 48px; }
#operatorsTableBody input[data-field="H_fakt"], #operatorsTableBody input[data-field="H_share"] { min-width: 60px; }
#operatorsTableBody input[data-field="N"], #operatorsTableBody input[data-field="D"] { min-width: 80px; }
#inpTariffRate { min-width: 86px; }
#operatorsTableHead input[type="number"] { min-height: 30px; padding-inline: 4px; }
#operatorsTableBody .operators-empty, .app-nalad-section .nal-empty { text-align: left; color: var(--md-sys-color-on-surface-variant); padding: 20px 12px; }
.operators-empty > *, .nal-empty > * { position: sticky; left: 0; max-width: min(100%, calc(100vw - 72px)); }
.nal-name-input { width: 100%; min-width: 150px; padding: 6px 8px; }
.nal-hour-input { width: 68px; padding: 6px; }
.nal-premium { font-weight: 700; color: var(--md-sys-color-primary); }
.nal-delete-btn { display: inline-flex; justify-content: center; align-items: center; width: 36px; height: 36px; border: 0; border-radius: 8px; color: var(--md-sys-color-on-surface-variant); background: transparent; cursor: pointer; }
.nal-delete-btn:hover { color: var(--md-sys-color-primary); background: var(--md-sys-color-primary-container); }
.m3-btn:disabled, .nal-delete-btn:disabled { opacity: .55; cursor: not-allowed; }
.ktu-high, [data-ktu-state="high"] { color: var(--app-ktu-good-text) !important; background: var(--app-ktu-good) !important; border-color: var(--app-ktu-good-border) !important; }
.ktu-low, [data-ktu-state="low"] { color: var(--app-ktu-low-text) !important; background: var(--app-ktu-low) !important; border-color: var(--app-ktu-low-border) !important; }
#mobileCardsList > * { min-width: 0; background: var(--md-sys-color-surface-container); border-color: var(--md-sys-color-outline-variant); }
#mobileCardsList input { min-width: 0; }
.app-detail { overflow-wrap: anywhere; }
.app-detail-subtitle { font-size: 12px; color: var(--md-sys-color-on-surface-variant); margin: 3px 0 14px; }
.app-detail-values { display: grid; gap: 8px; margin-bottom: 14px; color: var(--md-sys-color-on-surface-variant); font-size: 12px; }
.app-detail-values strong { color: var(--md-sys-color-on-surface); font-variant-numeric: tabular-nums; }
.app-detail #exactFractionBanner { padding: 12px; }

@media (min-width: 1200px) {
  .app-top-grid { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: stretch; }
  .app-top-grid > .app-presets { grid-column: 1; grid-row: 1; }
  .app-top-grid > .app-model { grid-column: 1; grid-row: 2; }
  .app-top-grid > .app-summary { grid-column: 2; grid-row: 1 / span 2; }
}
@media (max-width: 1199px) {
  .app-top-grid { display: contents; }
  .app-presets { order: 1; }
  .app-model { order: 2; }
  .app-operators { order: 3; }
  .app-nalad-section { order: 4; }
  .app-summary { order: 5; }
  .app-detail { order: 6; }
  .app-header, .app-shell { width: min(100% - 2rem, 1536px); }
  .app-header-inner { align-items: flex-start; flex-wrap: wrap; }
  .app-header-actions { justify-content: flex-start; }
}
@media (max-width: 639px) {
  body { background-attachment: scroll; }
  .app-header, .app-shell { width: calc(100% - 24px); }
  .app-header { margin-top: 12px; }
  .app-header-inner { padding: 16px; gap: 14px; }
  .app-brand { flex-wrap: wrap; gap: 12px; }
  .app-brand-logo img { width: 87px; }
  .app-brand h1 { font-size: 20px; }
  .app-header-actions { width: 100%; }
  .app-shell { padding-top: 12px; }
  .app-top-grid { gap: 12px; }
  .app-shell h2, .app-summary h2 { font-size: 18px; }
  .app-presets, .app-model, .app-summary, .app-operators, .app-nalad-section, .app-detail { padding: 16px; }
  #presetButtonsContainer .m3-chip { min-height: 40px; }
  .m3-btn { min-height: 44px; }
  #mobileCardsList { grid-template-columns: minmax(0, 1fr); }
  #tableViewContainer table { min-width: 1050px; }
  .app-nalad-section table, table.nal-table { min-width: 720px; }
  .app-nalad-section.is-empty table.nal-table { min-width: 0; }
}

@media (max-width: 380px) {
  .app-summary-content { grid-template-columns: minmax(0, 1fr); }
  .app-summary-chart svg { width: min(180px, 100%); }
}

/* Классы добавляются только по действиям пользователя, а не при каждом пересчёте. */
@keyframes app-row-enter {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.app-enter { animation: app-row-enter 200ms ease-out both; }
tr.app-enter { animation: none; }
tr.app-enter > td, tr.app-enter > th { animation: app-row-enter 200ms ease-out both; }
.theme-transition body, .theme-transition body * {
  transition-property: color, background-color, border-color, box-shadow, fill, stroke;
  transition-duration: 220ms;
  transition-timing-function: ease;
}
@media (prefers-reduced-motion: reduce) {
  .app-enter, tr.app-enter > td, tr.app-enter > th { animation: none !important; }
  .theme-transition body, .theme-transition body *, .app-header *, .app-shell * { transition-duration: 0s !important; }
}
