/* ==========================================================================
   Мост — панель управления.
   Светлая тема, системные шрифты, без внешних ресурсов и сборки.
   ========================================================================== */

:root {
  --bg: #eef2f6;
  --bg-glow-1: rgba(15, 118, 110, 0.10);
  --bg-glow-2: rgba(59, 130, 246, 0.08);
  --surface: #ffffff;
  --surface-2: #f5f9fa;
  --surface-3: #ecf3f4;
  --border: #dde6ea;
  --border-strong: #c4d2d9;
  --text: #13232e;
  --text-soft: #2f4353;
  --muted: #607485;
  --accent: #0f766e;
  --accent-strong: #0b5c56;
  --accent-soft: #e2f3f0;
  --accent-border: #a9d9d2;
  --ok: #127347;
  --ok-soft: #dcf4e5;
  --ok-border: #a5dcc0;
  --warn: #91570a;
  --warn-soft: #fbefd5;
  --warn-border: #eccf95;
  --danger: #ad2718;
  --danger-soft: #fbe5e2;
  --danger-border: #efb9b2;
  --focus: #0e7490;
  --shadow-sm: 0 1px 2px rgba(16, 33, 45, 0.06);
  --shadow-md: 0 12px 26px -16px rgba(16, 33, 45, 0.35);
  --shadow-lg: 0 30px 70px -28px rgba(16, 33, 45, 0.45);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  --topbar-h: 64px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(900px 500px at 8% -10%, var(--bg-glow-1), transparent 65%),
    radial-gradient(800px 500px at 100% 0%, var(--bg-glow-2), transparent 60%);
  background-attachment: fixed;
}

body.modal-open {
  overflow: hidden;
}

h1, h2, h3, h4, p {
  margin: 0;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

svg {
  display: block;
}

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

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -60px;
  left: 16px;
  z-index: 500;
  padding: 10px 16px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 0;
  color: #fff;
}

/* ---------- Общий каркас ---------- */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main {
  flex: 1 1 auto;
  width: 100%;
}

.view {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 26px 22px 56px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
}

.topbar__inner {
  display: flex;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 10px 22px;
  min-height: var(--topbar-h);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  flex: 0 0 auto;
  color: var(--accent);
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
}

.brand__logo {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
}

.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand__name {
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand__sub {
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px;
}

.main-nav::-webkit-scrollbar {
  display: none;
}

.main-nav__link {
  flex: 0 0 auto;
  padding: 8px 13px;
  border-radius: 999px;
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.main-nav__link:hover {
  background: var(--surface-3);
  color: var(--text);
  text-decoration: none;
}

.main-nav__link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.topbar__aside {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.session-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.session-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
}

.footer {
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.6);
}

.footer__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 14px 22px;
  color: var(--muted);
  font-size: 12.5px;
}

.footer__meta {
  font-variant-numeric: tabular-nums;
}

.noscript {
  max-width: 640px;
  margin: 40px auto;
  padding: 18px 20px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------- Загрузка ---------- */

.boot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 52vh;
  color: var(--muted);
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 44px 18px;
  color: var(--muted);
  text-align: center;
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  border: 2.5px solid var(--accent-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn[aria-busy="true"]::after {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  opacity: 0.8;
}

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn--secondary {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text-soft);
}

.btn--secondary:hover:not(:disabled) {
  border-color: var(--accent-border);
  background: var(--surface-2);
  color: var(--text);
}

.btn--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
}

.btn--danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.btn--danger:hover:not(:disabled) {
  background: #8f1f13;
  border-color: #8f1f13;
}

.btn--sm {
  padding: 6px 11px;
  font-size: 13px;
  border-radius: var(--radius-xs);
}

.btn--block {
  width: 100%;
}

.btn--icon {
  padding: 6px;
  width: 32px;
  height: 32px;
}

/* ---------- Поля формы ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field--full {
  grid-column: 1 / -1;
}

.field__label {
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
}

.req {
  color: var(--danger);
}

.input,
.select,
.textarea {
  width: 100%;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder,
.textarea::placeholder {
  color: #93a4b1;
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: #a9bcc7;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.textarea {
  min-height: 88px;
  resize: vertical;
}

.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(173, 39, 24, 0.12);
}

.field__hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.field__error {
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.4;
}

.field-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 13px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-xs);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 500;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.form-section + .form-section {
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.form-actions__hint {
  margin-right: auto;
  color: var(--muted);
  font-size: 12.5px;
}

.checkbox {
  display: inline-flex;
  align-items: flex-start;
  gap: 9px;
  cursor: pointer;
  font-size: 14px;
}

.checkbox input {
  width: 17px;
  height: 17px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.checkbox__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.checkbox__hint {
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Сегментированный переключатель ---------- */

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  max-width: 100%;
  overflow-x: auto;
}

.segmented__option {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  border-radius: var(--radius-xs);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.segmented__input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.segmented__option:hover {
  color: var(--text);
}

.segmented__option:has(.segmented__input:checked) {
  background: var(--surface);
  color: var(--accent-strong);
  box-shadow: var(--shadow-sm);
}

.segmented__option:has(.segmented__input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

/* ---------- Карточки и страницы ---------- */

.page {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.page__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 18px;
}

.page__heading {
  flex: 1 1 260px;
  min-width: 0;
}

.page__title {
  font-size: clamp(21px, 2.4vw, 27px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.page__subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.page__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.page__content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
}

.back-link:hover {
  color: var(--accent);
  text-decoration: none;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.card__title {
  font-size: 15px;
  font-weight: 700;
}

.card__body {
  padding: 18px;
}

.card__foot {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.card--flush .card__body {
  padding: 0;
}

/* ---------- Статистика / обзор ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.stat__label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.stat__value {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.stat__meta {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.stat--ok {
  border-color: var(--ok-border);
  background: linear-gradient(180deg, var(--ok-soft), var(--surface) 70%);
}

.stat--bad {
  border-color: var(--danger-border);
  background: linear-gradient(180deg, var(--danger-soft), var(--surface) 70%);
}

.stat--warn {
  border-color: var(--warn-border);
  background: linear-gradient(180deg, var(--warn-soft), var(--surface) 70%);
}

.quick-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.quick-link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.quick-link:hover {
  border-color: var(--accent-border);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  text-decoration: none;
}

.quick-link__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
}

.quick-link__arrow {
  color: var(--accent);
}

.quick-link__text {
  color: var(--muted);
  font-size: 13px;
}

.hints {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.hints__title {
  font-size: 14px;
  font-weight: 700;
}

.hints__list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
  color: var(--text-soft);
  font-size: 13.5px;
}

.hints__list li::marker {
  color: var(--accent);
}

/* ---------- Панель инструментов списка ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.toolbar__field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 150px;
}

.toolbar__field--grow {
  flex: 1 1 260px;
}

.toolbar__label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.toolbar__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.selection-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  background: var(--accent-soft);
}

.selection-bar__text {
  color: var(--accent-strong);
  font-size: 13.5px;
  font-weight: 600;
}

.selection-bar .toolbar__actions {
  margin-left: auto;
}

/* ---------- Таблицы ---------- */

.list-region {
  min-height: 120px;
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr:hover {
  background: var(--surface-2);
}

.table th.num,
.table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table .cell-check {
  width: 40px;
  padding-right: 0;
}

.table .cell-actions {
  text-align: right;
  white-space: nowrap;
}

.cell-title {
  color: var(--text);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.cell-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.cell-money {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.name-link {
  color: var(--accent-strong);
  font-weight: 600;
  text-decoration: none;
}

.name-link:hover {
  text-decoration: underline;
}

.mono {
  font-family: var(--mono);
  font-size: 12.5px;
}

.muted {
  color: var(--muted);
}

.nowrap {
  white-space: nowrap;
}

.skeleton-table {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px 18px;
}

.skeleton-line {
  height: 12px;
  margin: 14px 0;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-3) 25%, #f9fbfc 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

.skeleton-line--title {
  width: 40%;
  margin-top: 4px;
}

.skeleton-line--short {
  width: 60%;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Пагинация ---------- */

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 4px 2px;
}

.pager__info {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.pager__buttons {
  display: flex;
  gap: 8px;
}

/* ---------- Бейджи ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge--accent {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.badge--ok {
  border-color: var(--ok-border);
  background: var(--ok-soft);
  color: var(--ok);
}

.badge--warn {
  border-color: var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
}

.badge--danger {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.badge--muted {
  background: var(--surface-3);
  color: var(--muted);
}

.badge--state {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text-soft);
}

.badge--state::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--state-color, var(--muted));
  flex: 0 0 auto;
}

/* ---------- Пустое состояние, ошибки, уведомления ---------- */

.empty,
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 44px 22px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.empty__icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 4px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 19px;
  font-weight: 700;
}

.empty__title,
.error-state__title {
  font-size: 16px;
  font-weight: 700;
}

.empty__text,
.error-state__text {
  max-width: 520px;
  color: var(--muted);
  font-size: 13.5px;
}

.empty__action,
.error-state__action {
  margin-top: 8px;
}

.alert {
  padding: 12px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 13.5px;
}

.alert--error {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.alert--info {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.alert--warn {
  border-color: var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
}

/* ---------- Тосты ---------- */

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(390px, calc(100vw - 24px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}

.toast--error {
  border-left-color: var(--danger);
}

.toast--success {
  border-left-color: var(--ok);
}

.toast--info {
  border-left-color: var(--accent);
}

.toast--leaving {
  animation: toast-out 0.16s ease-in forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(6px); }
}

.toast__body {
  flex: 1 1 auto;
  min-width: 0;
}

.toast__msg {
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.toast__details {
  margin: 7px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12.5px;
  display: grid;
  gap: 3px;
}

.toast__close {
  flex: 0 0 auto;
  padding: 2px 5px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.toast__close:hover {
  background: var(--surface-3);
  color: var(--text);
}

/* ---------- Модальные окна ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(14, 27, 38, 0.5);
  animation: fade-in 0.15s ease-out;
  overflow-y: auto;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  display: flex;
  flex-direction: column;
  width: min(600px, 100%);
  max-height: calc(100vh - 40px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.18s ease-out;
}

.modal--sm {
  width: min(440px, 100%);
}

.modal--lg {
  width: min(880px, 100%);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
}

.modal__title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.modal__close {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.modal__close:hover {
  background: var(--surface-3);
  color: var(--text);
}

.modal__body {
  flex: 1 1 auto;
  padding: 18px;
  overflow-y: auto;
}

.modal__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}

.modal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-left: auto;
}

.modal__foot .form-actions {
  margin: 0;
  padding: 0;
  border: 0;
  width: 100%;
}

.modal__text {
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.55;
}

.modal__text + .modal__text {
  margin-top: 10px;
}

.modal__list {
  margin: 12px 0 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
  color: var(--text-soft);
  font-size: 13.5px;
}

/* ---------- Комбобокс ---------- */

.combobox {
  position: relative;
  min-width: 0;
}

.combobox__input {
  padding-right: 32px;
}

.combobox::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 12px;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
  opacity: 0.7;
}

.combobox__list {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  z-index: 40;
  max-height: 250px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.combobox__option {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.combobox__option:hover,
.combobox__option.is-active {
  background: var(--accent-soft);
}

.combobox__title {
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.combobox__meta {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.combobox__hint {
  padding: 11px 12px;
  color: var(--muted);
  font-size: 12.5px;
}

.picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.picker__row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.picker__row .combobox {
  flex: 1 1 auto;
}

/* ---------- Позиции ---------- */

.positions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.positions__head {
  display: grid;
  grid-template-columns: minmax(170px, 2fr) 86px 118px 86px 86px 112px 34px;
  gap: 8px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.positions__rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.positions__row {
  display: grid;
  grid-template-columns: minmax(170px, 2fr) 86px 118px 86px 86px 112px 34px;
  gap: 8px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.positions__cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.positions__cell-label {
  display: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.positions__sum {
  display: flex;
  align-items: center;
  min-height: 38px;
  color: var(--text-soft);
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.positions__error {
  color: var(--danger);
  font-size: 12px;
  line-height: 1.35;
}

.positions__row-error {
  grid-column: 1 / -1;
  margin: 0;
}

.positions__remove {
  align-self: start;
  margin-top: 1px;
  width: 34px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--danger);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.positions__remove:hover {
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

.positions__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 4px;
}

.positions__total {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.positions__total-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

/* ---------- Детальные карточки ---------- */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 22px;
}

.detail-item {
  min-width: 0;
}

.detail-item--full {
  grid-column: 1 / -1;
}

.detail-item__label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.detail-item__value {
  margin-top: 3px;
  color: var(--text);
  font-size: 14.5px;
  overflow-wrap: anywhere;
}

.detail-item__value--money {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  align-items: start;
}

.related-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.related-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface-2);
}

.related-item__sum {
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.related-empty {
  color: var(--muted);
  font-size: 13px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.detail-actions .field {
  min-width: 190px;
}

.detail-actions__spacer {
  flex: 1 1 auto;
}

/* ---------- Экран входа ---------- */

.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-height: 100vh;
  padding: 28px 18px;
}

.login-card {
  width: min(420px, 100%);
  padding: 28px 26px 24px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 20px;
  color: var(--accent);
}

.login-brand__logo {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
}

.login-brand__name {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.login-brand__sub {
  color: var(--muted);
  font-size: 12px;
}

.login-card__title {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.login-card__text {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.5;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 20px;
}

.login-key-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.login-key-row .input {
  flex: 1 1 auto;
}

.login-error {
  display: flex;
  gap: 8px;
  padding: 10px 13px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-xs);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 500;
}

.login-hint {
  display: grid;
  gap: 6px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.login-hint strong {
  color: var(--text-soft);
}

.login-footer {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* ---------- Аудит ---------- */

.toolbar--audit {
  align-items: flex-end;
}

.audit-table {
  min-width: 1060px;
}

.audit-table .cell-expand {
  width: 46px;
  padding-right: 0;
}

.audit-expand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.audit-expand:hover {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.audit-row {
  cursor: pointer;
}

.audit-row.is-open {
  background: var(--surface-2);
}

.audit-method {
  display: inline-block;
  min-width: 48px;
  margin-right: 7px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text-soft);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  vertical-align: 1px;
}

.audit-method--write {
  background: var(--warn-soft);
  color: var(--warn);
}

.audit-request {
  min-width: 160px;
}

.audit-path {
  font-size: 12px;
  overflow-wrap: anywhere;
}

.audit-message-cell {
  max-width: 320px;
  overflow-wrap: anywhere;
}

.audit-duration {
  font-variant-numeric: tabular-nums;
}

.audit-duration--warn {
  color: var(--warn);
  font-weight: 600;
}

.audit-duration--slow {
  color: var(--danger);
  font-weight: 700;
}

.audit-details-row td {
  padding: 0 12px 12px;
  border-bottom: 1px solid var(--border);
}

.audit-details-row:hover {
  background: transparent;
}

.audit-details-cell {
  background: transparent;
}

.audit-details-meta {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.audit-details {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface-3);
  color: var(--text-soft);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 320px;
  overflow: auto;
}

.audit-auto {
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
  padding: 2px 0;
}

.audit-auto .checkbox__text {
  gap: 0;
}

.audit-updated {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Адаптивность ---------- */

@media (max-width: 960px) {
  .topbar__inner {
    flex-wrap: wrap;
    gap: 8px 16px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .brand {
    margin-right: auto;
  }

  .topbar__aside {
    order: 2;
  }

  .main-nav {
    order: 3;
    flex-basis: 100%;
    padding-bottom: 2px;
  }

  .positions__head {
    display: none;
  }

  .positions__row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
  }

  .positions__cell--product {
    grid-column: 1 / -1;
  }

  .positions__cell--sum {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
  }

  .positions__cell-label {
    display: block;
  }

  .positions__cell--sum .positions__cell-label {
    display: inline;
    margin-right: 6px;
  }

  .positions__remove {
    width: 100%;
    height: 38px;
  }
}

@media (max-width: 760px) {
  .view {
    padding: 18px 14px 44px;
  }

  .topbar__inner {
    padding-left: 14px;
    padding-right: 14px;
  }

  .footer__inner {
    padding: 12px 14px;
  }

  .page__actions {
    width: 100%;
    margin-left: 0;
  }

  .toolbar {
    padding: 12px;
    gap: 10px;
  }

  .toolbar__actions {
    width: 100%;
    margin-left: 0;
  }

  .toolbar__actions .btn {
    flex: 0 0 auto;
  }

  .toolbar__field {
    flex: 1 1 100%;
  }

  .selection-bar {
    align-items: flex-start;
  }

  .selection-bar .toolbar__actions {
    width: 100%;
  }

  /* Таблицы превращаются в карточки */
  .table--cards thead {
    display: none;
  }

  .table--cards,
  .table--cards tbody,
  .table--cards tr,
  .table--cards td {
    display: block;
    width: 100%;
  }

  .table--cards tbody tr {
    display: block;
    margin: 10px;
    padding: 6px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
  }

  .table--cards tbody tr:hover {
    background: var(--surface);
  }

  .table--cards tbody tr:last-child {
    margin-bottom: 10px;
  }

  .table--cards td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 12px;
    border-bottom: 0;
    text-align: right;
  }

  .table--cards td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-align: left;
  }

  .table--cards td[data-label=""]::before,
  .table--cards td:not([data-label])::before {
    display: none;
  }

  .table--cards td.cell-check {
    justify-content: flex-start;
    padding: 8px 12px 2px;
  }

  .table--cards td.cell-actions {
    justify-content: flex-end;
    padding-top: 10px;
  }

  .table--cards td.cell-actions::before {
    margin-right: auto;
  }

  .table--cards .cell-title,
  .table--cards .cell-sub {
    text-align: right;
  }

  .table--cards td[data-label="Наименование"] {
    display: block;
    text-align: left;
    padding-top: 8px;
  }

  .table--cards td[data-label="Наименование"]::before {
    display: none;
  }

  .table--cards td[data-label="Наименование"] .cell-title,
  .table--cards td[data-label="Наименование"] .cell-sub {
    text-align: left;
  }

  .pager {
    justify-content: center;
  }

  .page__head {
    gap: 10px;
  }

  .detail-actions {
    align-items: stretch;
  }

  .detail-actions .btn,
  .detail-actions .field {
    flex: 1 1 auto;
  }

  .modal-overlay {
    padding: 12px;
    align-items: flex-end;
  }

  .modal {
    max-height: calc(100vh - 24px);
  }

  .form-actions {
    justify-content: stretch;
  }

  .form-actions .btn {
    flex: 1 1 auto;
  }

  .form-actions__hint {
    flex-basis: 100%;
  }

  .toast-region {
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
  }

  .login-card {
    padding: 22px 18px 20px;
  }
}

@media (max-width: 480px) {
  .brand__sub {
    display: none;
  }

  .page__title {
    font-size: 20px;
  }

  .table--cards tbody tr {
    margin: 8px;
  }

  .positions__row {
    grid-template-columns: minmax(0, 1fr);
  }

  .positions__cell--product {
    grid-column: auto;
  }

  .detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Аудит: раскрытые детали как отдельная карточка под строкой */
@media (max-width: 760px) {
  .audit-table {
    min-width: 0;
  }

  .table--cards .audit-details-row {
    margin: 0 10px 10px;
    padding: 0;
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    background: var(--surface);
    box-shadow: none;
  }

  .table--cards .audit-details-row td {
    display: block;
    padding: 10px 12px;
    border: 0;
    text-align: left;
  }

  .table--cards .audit-details-row td::before {
    display: none;
  }

  .table--cards .audit-details {
    max-height: 240px;
  }

  .table--cards .cell-expand {
    width: auto;
    padding: 8px 12px 2px;
  }

  .audit-request {
    min-width: 0;
  }

  .audit-message-cell {
    max-width: none;
  }

  .toolbar--audit .audit-updated {
    white-space: normal;
  }
}

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