:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-alt: #f8f9fb;
  --border: #e4e7ec;
  --border-strong: #cfd4dc;
  --text: #14171c;
  --text-secondary: #4b5566;
  --muted: #8a919e;

  --accent: #2f5fdb;
  --accent-hover: #2650bd;
  --accent-light: #eaf0ff;
  --accent-contrast: #ffffff;

  --green: #17874a;
  --green-light: #e7f7ee;
  --amber: #b5650a;
  --amber-light: #fdf1e3;
  --red: #c8281f;
  --red-light: #fdecec;
  --grey: #9aa1ab;
  --grey-light: #eef0f3;

  --radius-sm: 7px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, 0.16);

  --sidebar-w: 236px;
  --topbar-h: 58px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
button { font-family: inherit; }

/* ---------------------------------------------------------------------- */
/* App shell — sidebar + main column                                      */
/* ---------------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #5c7cf0);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.brand-title { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; line-height: 1.2; }
.brand-subtitle { font-size: 11px; color: var(--muted); margin-top: 1px; }

.tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 12px;
  flex: 1;
  overflow-y: auto;
  align-items: stretch;
}
.tab {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
  border-bottom: none;
  transition: background 0.12s, color 0.12s;
}
.tab:hover { background: var(--grey-light); color: var(--text); }
.tab.active { background: var(--accent-light); color: var(--accent); }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 23, 0.45);
  z-index: 19;
}
.sidebar-backdrop.show { display: block; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 22px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar-title { font-weight: 700; font-size: 16px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.topbar-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }

.sidebar-toggle {
  display: none;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--grey-light); }

#app { padding: 24px; max-width: 1200px; margin: 0 auto; width: 100%; }
.screen { display: none; }
.screen.active { display: block; }
.screen-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 16px;
}
.screen-header-row {
  position: sticky;
  top: var(--topbar-h);
  z-index: 5;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 6px 0;
  margin: -6px 0 10px;
}
.screen-header-row .screen-title { margin: 0; }
.selection-sum {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  white-space: nowrap;
}
.selection-sum-label { font-size: 12px; color: var(--accent); font-weight: 600; }
.selection-sum-value { font-size: 15px; font-weight: 700; color: var(--accent); }

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: inline-flex; }
  #app { padding: 16px; }
  .topbar { padding: 0 14px; }
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                 */
/* ---------------------------------------------------------------------- */
.btn-primary, .btn-secondary, .btn-danger, .btn-refresh, .btn-logout {
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s, color 0.12s;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-refresh { background: var(--accent); color: #fff; border: 1px solid var(--accent); }
.btn-refresh:hover { background: var(--accent-hover); }
.btn-refresh:disabled { opacity: 0.6; cursor: default; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.btn-secondary:hover { background: var(--grey-light); }
.btn-danger { background: var(--surface); color: var(--red); border: 1px solid #f0c6c3; padding: 7px 12px; font-size: 12.5px; }
.btn-danger:hover { background: var(--red-light); }
.btn-link { background: none; border: none; color: var(--accent); font-size: 12.5px; font-weight: 600; cursor: pointer; padding: 5px 7px; border-radius: 6px; text-decoration: none; }
.btn-link:hover { background: var(--accent-light); }
.btn-logout {
  width: 100%;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-logout:hover { color: var(--red); border-color: #f0c6c3; background: var(--red-light); }

/* ---------------------------------------------------------------------- */
/* KPI summary row + object cards                                         */
/* ---------------------------------------------------------------------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.kpi-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 8px;
}
.kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.kpi-card.accent .kpi-value { color: var(--accent); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
}
.obj-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.1s;
}
.obj-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); transform: translateY(-1px); }
.obj-card:active { background: var(--accent-light); transform: translateY(0); }
.obj-card h3 { margin: 4px 0 2px; font-size: 15.5px; font-weight: 700; letter-spacing: -0.005em; }
.obj-card-inactive { opacity: 0.6; }
.obj-rename {
  font-size: 13px;
  padding: 2px 5px;
  vertical-align: middle;
  opacity: 0.55;
}
.obj-rename:hover { opacity: 1; }
.inactive-tag {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted, #888);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
  vertical-align: middle;
}
.obj-total-cost {
  margin: 0 0 14px;
  font-size: 18px;
  font-weight: 800;
  color: var(--accent, var(--text));
  font-variant-numeric: tabular-nums;
}
.obj-card .badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  background: var(--grey-light);
  color: var(--text-secondary);
}
.obj-fields { display: grid; grid-template-columns: 1fr auto; gap: 7px 10px; font-size: 13px; }
.obj-fields .label { color: var(--muted); }
.obj-fields .value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.obj-fields .value.paid { font-weight: 700; color: var(--text); font-size: 14.5px; }

.other-summary {
  margin-top: 18px;
  padding: 14px 16px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}
.other-summary strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* Skeleton loading placeholders */
.skeleton {
  background: linear-gradient(90deg, var(--grey-light) 25%, #e4e6ea 37%, var(--grey-light) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  pointer-events: none;
}
.skeleton-card { height: 190px; }
@keyframes skeleton-loading {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ---------------------------------------------------------------------- */
/* Filters / toolbars                                                     */
/* ---------------------------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters select, .filters input, #ref-search {
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}
.filters select { flex: 1 1 140px; }
.filters input { flex: 2 1 200px; }
.filters .date-sort-toggle { flex: 0 0 auto; }
.filters .date-range-filter { flex: 2 1 260px; }
#ref-search { width: 100%; margin-bottom: 10px; }
.ref-object-filter {
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  flex: 0 0 auto;
}

.date-range-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.date-range-filter label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.date-range-filter input[type="date"] {
  padding: 8px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}
.date-preset-group { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-preset {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-preset:hover { color: var(--accent); border-color: var(--accent); }

.ref-toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.ref-toolbar input {
  flex: 1;
  min-width: 120px;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
}

@media (max-width: 480px) {
  .filters > * { flex: 1 1 100%; }
  .ref-toolbar input { flex: 1 1 100%; }
  .ref-toolbar button { flex: 1 1 100%; }
  .date-range-filter { width: 100%; }
  .date-range-filter label { flex: 1 1 auto; }
  .date-range-filter input[type="date"] { flex: 1 1 auto; min-width: 0; }
  .date-preset-group { width: 100%; }
  .btn-preset { flex: 1 1 30%; text-align: center; }
  .ref-sort-bar { flex-direction: column; align-items: stretch; }
  .ref-sort-bar .date-sort-toggle { width: 100%; justify-content: center; }
}

/* ---------------------------------------------------------------------- */
/* Tables                                                                  */
/* ---------------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 640px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
/* Платежи has 10 columns (дата/№/плательщик/получатель/сумма/объект/откуда
   деньги/кто отчитывается/вид затрат/действие) — the generic 640px min-width
   let the browser squeeze them all into one screen width, clipping/cramming
   text even with white-space:nowrap. Force a wide enough table so every
   column gets breathing room and .table-wrap's overflow-x:auto kicks in
   instead of the browser silently compressing columns. */
#registry-table { min-width: 1320px; }
#registry-table th:nth-child(1), #registry-table td:nth-child(1) { min-width: 100px; }
#registry-table th:nth-child(2), #registry-table td:nth-child(2) { min-width: 110px; }
#registry-table th:nth-child(3), #registry-table td:nth-child(3) { min-width: 150px; }
#registry-table th:nth-child(4), #registry-table td:nth-child(4) { min-width: 150px; }
#registry-table th:nth-child(5), #registry-table td:nth-child(5) { min-width: 110px; }
#registry-table th:nth-child(6), #registry-table td:nth-child(6) { min-width: 200px; }
#registry-table th:nth-child(7), #registry-table td:nth-child(7) { min-width: 120px; }
#registry-table th:nth-child(8), #registry-table td:nth-child(8) { min-width: 140px; }
#registry-table th:nth-child(9), #registry-table td:nth-child(9) { min-width: 170px; }
#registry-table th:nth-child(10), #registry-table td:nth-child(10) { min-width: 90px; }
th {
  background: var(--surface-alt);
  color: var(--muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
}
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--surface-alt); }
tbody tr:last-child td { border-bottom: none; }
td.amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; }
th.sortable-th { cursor: pointer; user-select: none; }
th.sortable-th:hover { color: var(--accent); }
th.sortable-th .sort-arrow { font-size: 9px; margin-left: 2px; color: var(--accent); }

.ref-sort-bar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.date-sort-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}
.date-sort-toggle:hover { color: var(--accent); border-color: var(--accent); }
.date-sort-toggle .sort-arrow { font-size: 9px; }

.name-sort-group { display: flex; gap: 6px; }
.btn-preset.active { background: var(--accent); color: #fff; border-color: var(--accent); }

@media (max-width: 700px) {
  .table-wrap { border: none; background: none; box-shadow: none; }
  /* table kept min-width:640px from the desktop rule above — reset it here,
     otherwise the "card mode" table below is still 640px wide inside its
     overflow-x:auto wrapper and each row-card gets clipped/scrollable. */
  table { min-width: 0; }
  /* Same reset for the Платежи per-column min-widths above — in card mode
     each td is a stacked block, not a table cell, so a min-width there would
     just force pointless horizontal overflow inside every card. */
  #registry-table, #registry-table th, #registry-table td { min-width: 0; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tbody tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    padding: 10px 12px;
    box-shadow: var(--shadow-sm);
  }
  tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    border-bottom: none;
    padding: 6px 0;
    white-space: normal;
    text-align: right;
  }
  tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    text-align: left;
    padding-right: 8px;
    flex-shrink: 0;
  }

  /* Touch targets + no-zoom-on-focus for phones */
  .tab { padding: 12px 14px; min-height: 44px; }
  .subtab { padding: 10px 15px; min-height: 40px; display: inline-flex; align-items: center; }
  .btn-danger { padding: 10px 14px; min-height: 40px; }
  .btn-link { padding: 10px 12px; min-height: 40px; display: inline-flex; align-items: center; }
  .modal-close { width: 40px; height: 40px; font-size: 22px; }
  .sidebar-toggle { width: 40px; height: 40px; }
  .ref-row .ref-actions { gap: 8px; }
  .topbar-meta { display: none; }

  .form-field input[type="text"],
  .form-field input[type="number"],
  .form-field input[type="date"],
  .form-field select,
  .form-field textarea,
  .filters select,
  .filters input,
  #ref-search,
  .ref-toolbar input,
  .date-range-filter input[type="date"],
  .alloc-row select,
  .alloc-row input {
    font-size: 16px; /* prevents iOS Safari auto-zoom on focus */
  }
}

/* ---------------------------------------------------------------------- */
/* Sub-tabs (pill nav inside a screen) + reference/operation lists         */
/* ---------------------------------------------------------------------- */
.subtabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.subtab {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.subtab:hover { border-color: var(--border-strong); }
.subtab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.ref-list { display: flex; flex-direction: column; gap: 7px; }
.ref-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.12s;
}
.ref-row:hover { border-color: var(--border-strong); }
.ref-row .ref-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ref-row .ref-main strong { font-weight: 600; }
.ref-row .meta { color: var(--muted); font-size: 12px; }
.ref-row .ref-actions { display: flex; gap: 6px; flex-shrink: 0; }
.ref-row.inactive { opacity: 0.55; }

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 28px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.gaps-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm); }
.gaps-box h2 { margin-top: 0; font-size: 17px; }
.gaps-box .chain { font-weight: 600; color: var(--accent); font-size: 13px; line-height: 1.7; }
.legend { display: flex; flex-direction: column; gap: 7px; margin: 14px 0; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot.зелёный { background: var(--green); }
.dot.оранжевый { background: var(--amber); }
.dot.красный { background: var(--red); }
.dot.серый { background: var(--grey); }

/* ---------------------------------------------------------------------- */
/* Toast                                                                   */
/* ---------------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1d222b;
  color: #fff;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--grey);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-success { border-left-color: var(--green); }
.toast.toast-error { border-left-color: var(--red); }

/* ---------------------------------------------------------------------- */
/* Modal                                                                   */
/* ---------------------------------------------------------------------- */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 23, 0.5);
  z-index: 50;
}
.modal-backdrop.show { display: block; }
.modal {
  display: none;
  position: fixed;
  z-index: 51;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: min(560px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal.show { display: block; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 15px;
  position: sticky;
  top: 0;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: var(--grey-light); color: var(--text); }
.modal-body { padding: 20px; }

/* ---------------------------------------------------------------------- */
/* Forms                                                                   */
/* ---------------------------------------------------------------------- */
.form-field { margin-bottom: 14px; }
.form-field label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 5px; font-weight: 600; }
.form-field input[type="text"],
.form-field input[type="number"],
.form-field input[type="date"],
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.form-field input:disabled { background: var(--surface-alt); color: var(--muted); }
.form-field textarea { min-height: 64px; resize: vertical; }
.form-field.checkbox { display: flex; align-items: center; gap: 8px; }
.form-field.checkbox label { margin: 0; }
.form-field.checkbox input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

.alloc-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.alloc-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.alloc-row select { flex: 2; min-width: 140px; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 13px; }
.alloc-row input { flex: 1; min-width: 90px; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 13px; }
.alloc-row .alloc-remove { flex-shrink: 0; }

@media (max-width: 480px) {
  .alloc-row select { flex: 1 1 100%; }
  .alloc-row .alloc-remove { width: 40px; height: 40px; padding: 0; font-size: 18px; display: flex; align-items: center; justify-content: center; }
}
.alloc-sum-hint { font-size: 12.5px; font-weight: 600; margin: 6px 0 14px; padding: 9px 11px; border-radius: var(--radius-sm); background: var(--grey-light); }
.alloc-sum-hint.ok { background: var(--green-light); color: var(--green); }
.alloc-sum-hint.bad { background: var(--red-light); color: var(--red); }

.form-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.form-actions-right { display: flex; gap: 8px; }

/* Mobile modal: full-screen sheet (avoids centered-box + keyboard-overlap
   issues) with an always-visible sticky action footer. */
@media (max-width: 560px) {
  .modal {
    left: 0;
    top: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
  }
  .modal-header { border-radius: 0; }
  .modal-body { padding-bottom: 24px; }
  .form-actions {
    position: sticky;
    bottom: 0;
    margin: 18px -20px -20px;
    padding: 14px 20px calc(14px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 12px rgba(16, 24, 40, 0.08);
    flex-wrap: wrap;
  }
  .form-actions-right { flex: 1 1 100%; }
  .form-actions-right .btn-primary,
  .form-actions-right .btn-secondary {
    flex: 1;
  }
}

/* ---------------------------------------------------------------------- */
/* Login page                                                              */
/* ---------------------------------------------------------------------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(180deg, #eef1f6 0%, var(--bg) 100%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 38px 34px;
  width: min(380px, 100%);
  box-shadow: var(--shadow-lg);
}
.login-brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #5c7cf0);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 22px;
  margin: 0 auto 18px;
}
.login-title { font-weight: 700; font-size: 22px; text-align: center; letter-spacing: -0.01em; }
.login-subtitle { font-size: 13px; color: var(--muted); text-align: center; margin: 6px 0 28px; line-height: 1.5; }
.login-error {
  font-size: 13px;
  color: var(--red);
  min-height: 0;
  margin: 0 0 0;
}
.login-error:not(:empty) {
  background: var(--red-light);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  margin: -2px 0 14px;
}
.login-submit { width: 100%; padding: 12px 14px; font-size: 14.5px; margin-top: 4px; }

/* ---------------------------------------------------------------------- */
/* Top navigation actions                                                  */
/* ---------------------------------------------------------------------- */
.nav-group-label {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  padding: 10px 12px 4px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--grey);
  white-space: nowrap;
}

/* ---------------------------------------------------------------------- */
/* Импорт счетов по материалам (Excel)                                     */
/* ---------------------------------------------------------------------- */
.modal.modal-wide { width: min(1080px, 96vw); }

.import-summary {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 13.5px;
  margin-bottom: 16px;
  line-height: 1.6;
}

.import-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 8px;
  white-space: nowrap;
}
.import-badge-ok { background: var(--green-light); color: var(--green); }
.import-badge-warn { background: var(--amber-light); color: var(--amber); }
.import-badge-muted { background: var(--grey-light); color: var(--grey); }

.import-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 14px;
}
.import-group-dup { border-color: #f0d9b5; background: var(--amber-light); }
.import-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.import-group-header .meta { font-size: 12px; color: var(--muted); }
.import-dup-choice {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--amber);
  margin-bottom: 8px;
}
.import-row-flagged { background: var(--red-light); }
.import-row-warn { font-size: 11px; color: var(--red); margin-top: 3px; }

/* --------- Загрузка документов (PDF/фото) с распознаванием --------- */
.doc-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 18px;
}
.doc-card-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.doc-card-header .meta { font-size: 12px; color: var(--muted); }
.doc-body { display: grid; grid-template-columns: minmax(220px, 320px) 1fr; gap: 16px; }
@media (max-width: 860px) { .doc-body { grid-template-columns: 1fr; } }
.doc-original { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-alt); }
.doc-original iframe, .doc-original img { width: 100%; height: 420px; border: none; display: block; object-fit: contain; background: #fff; }
.doc-header-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; margin-bottom: 10px; }
.doc-header-fields .form-field { margin-bottom: 10px; }
.doc-note-banner { font-size: 12.5px; padding: 8px 10px; border-radius: var(--radius-sm); margin-bottom: 10px; }
.doc-note-banner.warn { background: var(--amber-light); color: var(--amber); }
.doc-note-banner.error { background: var(--red-light); color: var(--red); }
.doc-note-banner.ok { background: var(--accent-light); color: var(--accent); }
.doc-lines-table input, .doc-lines-table select { width: 100%; padding: 5px 6px; font-size: 12.5px; border: 1px solid var(--border); border-radius: 6px; }
.doc-lines-table td { vertical-align: top; padding: 4px; }
.doc-bulk-object { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 12.5px; }
.doc-bulk-object select { min-width: 220px; }
.doc-totals { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; margin: 10px 0; }
.doc-totals strong { color: var(--text); }
.doc-object-candidates { font-size: 11px; color: var(--muted); margin-top: 2px; }
