/* ============ CRM «Таблица Реестра» — фрахтовый журнал ============ */
:root {
  --paper: #f4f1e9;
  --paper-deep: #ece7db;
  --surface: #fffdf8;
  --ink: #1b2532;
  --ink-soft: #4a5568;
  --muted: #8b8f98;
  --line: #ddd6c6;
  --line-strong: #c9c0ab;
  --accent: #ff7300;
  --accent-soft: #ffe9d5;
  --navy: #16202e;
  --navy-2: #1d2a3b;
  --green: #1e7d4f;
  --green-soft: #e3f2e9;
  --amber: #b97c10;
  --amber-soft: #fdf3dd;
  --red: #c0392b;
  /* Яркие цвета для отметок о выплате (стемпы, чекбоксы «выплачено») — заметнее, чем общий --green/--amber */
  --paid: #0da259;
  --paid-soft: #c9f6dd;
  --advance: #ee8b00;
  --advance-soft: #ffe8b8;
  --radius: 10px;
  --mono: 'IBM Plex Mono', 'SF Mono', Menlo, monospace;
  --sans: 'Golos Text', -apple-system, 'Segoe UI', sans-serif;
  --display: 'Unbounded', 'Golos Text', sans-serif;
  --shadow: 0 8px 30px rgba(27, 37, 50, .10);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(255, 115, 0, .06), transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 34px, rgba(27, 37, 50, .022) 34px 35px),
    var(--paper);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Вход ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* явная колонка: иначе max-width:100% карточки не работает на узких экранах */
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 400px; max-width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  padding: 38px 34px 30px;
  position: relative;
  box-shadow: 6px 6px 0 rgba(27, 37, 50, .12);
  animation: card-in .5s cubic-bezier(.2, .9, .3, 1.2) both;
}
@keyframes card-in { from { opacity: 0; transform: translateY(18px) } to { opacity: 1; transform: none } }
.brand-logo { display: block; width: 250px; max-width: 88%; margin: 4px auto 16px; position: relative; z-index: 1; }
.logo .brand-logo-side { display: block; width: 158px; margin: 4px 0 8px 0; }
.login-card::before {
  content: '';
  position: absolute; inset: 8px;
  border: 1px dashed var(--line-strong);
  border-radius: 2px;
  pointer-events: none;
}
.login-kicker {
  text-align: center;
  font-family: var(--mono); font-size: 11px; letter-spacing: .22em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 10px;
}
.login-title {
  font-family: var(--display); font-weight: 900; font-size: 30px;
  letter-spacing: .01em; line-height: 1.1;
}
.login-sub { color: var(--ink-soft); margin: 10px 0 24px; font-size: 13px; }
.route-line {
  display: flex; align-items: center; gap: 6px; margin: 18px 0 22px;
  color: var(--muted); font-family: var(--mono); font-size: 11px;
}
.route-line .dash { flex: 1; border-top: 2px dashed var(--line-strong); }
.field { margin-bottom: 14px; position: relative; z-index: 1; }
.field label {
  display: block; font-size: 11px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-soft); margin-bottom: 5px;
}
.field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: 6px;
  background: #fff; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:not([type="checkbox"]):not([type="radio"]):focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 115, 0, .14);
}
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1.5px solid var(--ink); border-radius: 6px;
  background: var(--ink); color: var(--paper);
  padding: 9px 16px; font-weight: 600; font-size: 13.5px;
  transition: transform .12s, box-shadow .12s, background .15s;
  position: relative; z-index: 1;
}
.btn:hover { transform: translateY(-1px); box-shadow: 3px 3px 0 rgba(27, 37, 50, .18); }
.btn:active { transform: none; box-shadow: none; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: rgba(27, 37, 50, .05); }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-width: 1px; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.wide { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.login-hint {
  margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--muted); line-height: 1.6; position: relative; z-index: 1;
}
.login-hint code { font-family: var(--mono); color: var(--ink-soft); background: var(--paper-deep); padding: 1px 5px; border-radius: 4px; }
.login-error { color: var(--red); font-size: 13px; margin-bottom: 12px; min-height: 0; }

/* Поле пароля с «глазком» */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 40px !important; }
.pw-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: none; font-size: 16px; opacity: .5; padding: 6px 8px;
}
.pw-eye:hover { opacity: 1; }

/* ---------- Каркас ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--navy), var(--navy-2));
  color: #e9e4d8;
  padding: 26px 0 18px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.logo { padding: 0 22px 20px; border-bottom: 1px solid rgba(233, 228, 216, .12); }
.logo .kicker { font-family: var(--mono); font-size: 10px; letter-spacing: .28em; color: var(--accent); text-transform: uppercase; }
.logo .name { font-family: var(--display); font-weight: 700; font-size: 19px; margin-top: 4px; color: #fff; }
.logo .tag { font-size: 11px; color: rgba(233, 228, 216, .5); margin-top: 3px; }
.nav { padding: 14px 12px; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  color: rgba(233, 228, 216, .78); text-decoration: none;
  padding: 9px 12px; border-radius: 7px; font-size: 13.5px; font-weight: 500;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s;
  animation: nav-in .4s ease both;
}
.nav a:nth-child(1) { animation-delay: .03s } .nav a:nth-child(2) { animation-delay: .07s }
.nav a:nth-child(3) { animation-delay: .11s } .nav a:nth-child(4) { animation-delay: .15s }
.nav a:nth-child(5) { animation-delay: .19s } .nav a:nth-child(6) { animation-delay: .23s }
@keyframes nav-in { from { opacity: 0; transform: translateX(-8px) } to { opacity: 1; transform: none } }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: rgba(255, 115, 0, .16); color: #fff; border-left-color: var(--accent); }
.nav .icon { width: 18px; text-align: center; }
.nav .badge {
  margin-left: auto; background: var(--accent); color: #fff;
  font-size: 10.5px; font-weight: 700; font-family: var(--mono);
  padding: 1px 7px; border-radius: 20px;
}
.side-user { padding: 14px 18px 0; border-top: 1px solid rgba(233, 228, 216, .12); }
.side-user .u-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.side-user .avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #b53d12);
  color: #fff; font-weight: 700; font-size: 13px;
  display: grid; place-items: center; letter-spacing: .02em;
  box-shadow: 0 2px 8px rgba(255, 115, 0, .4);
}
.side-user .u-name { font-weight: 600; color: #fff; font-size: 13.5px; }
.side-user .u-role { font-size: 11px; color: rgba(233, 228, 216, .5); margin-top: 1px; }
.side-user .u-actions { display: flex; gap: 6px; }
.side-user button {
  background: none; border: 1px solid rgba(233, 228, 216, .25); color: rgba(233, 228, 216, .8);
  border-radius: 6px; padding: 5px 12px; font-size: 12px; cursor: pointer;
}
.side-user button:hover { border-color: var(--accent); color: #fff; }
.side-user #logout-btn { flex: 1; }

.main { padding: 26px 30px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { font-family: var(--display); font-weight: 700; font-size: 22px; }
.page-title .count { font-family: var(--mono); font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 10px; }
.page-sub { color: var(--ink-soft); font-size: 13px; margin-top: 5px; max-width: 640px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search], .toolbar select {
  padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface);
}
.toolbar input[type=search] { width: 240px; }
.toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--accent); }

/* ---------- Таблицы ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: auto;
  max-height: calc(100vh - 210px);
  box-shadow: var(--shadow);
}
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.grid th {
  position: sticky; top: 0; z-index: 2;
  background: var(--navy); color: #e9e4d8;
  font-size: 10.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase;
  padding: 9px 10px; text-align: left; white-space: nowrap;
  border-bottom: 2px solid var(--accent);
}
table.grid td {
  padding: 8px 10px; border-bottom: 1px solid var(--line);
  white-space: nowrap; max-width: 250px; overflow: hidden; text-overflow: ellipsis;
  vertical-align: middle;
}
table.grid tbody tr { cursor: pointer; transition: background .1s; }
table.grid tbody tr:hover { background: var(--accent-soft); }
table.grid td.num { font-family: var(--mono); font-size: 12.5px; text-align: right; }
table.grid td.total { font-weight: 600; color: var(--ink); background: rgba(255, 115, 0, .05); }
table.grid td.idx { color: var(--muted); font-family: var(--mono); font-size: 11.5px; }
tr.paid-full td { background: rgba(13, 162, 89, .12); }
tr.paid-full:hover td { background: rgba(13, 162, 89, .19) !important; }
/* Авто выгружено, CMR не прикреплён — строка горит красным */
tr.no-cmr td { background: rgba(192, 57, 43, .10); }
tr.no-cmr:hover td { background: rgba(192, 57, 43, .17) !important; }
.chip.blink { animation: cmr-blink 1.6s ease-in-out infinite; }
@keyframes cmr-blink { 0%, 100% { opacity: 1 } 50% { opacity: .45 } }
.cmr-alert {
  background: #fbe5e2; border: 1.5px solid var(--red); color: var(--red);
  border-radius: 7px; padding: 9px 13px; font-size: 13px; font-weight: 600; margin-bottom: 10px;
}

.stamp {
  display: inline-block; font-family: var(--mono); font-size: 9.5px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  border: 1.5px solid; border-radius: 3px; padding: 2px 7px;
  transform: rotate(-2deg);
}
.stamp.paid { color: var(--paid); border-color: var(--paid); background: var(--paid-soft); }
.stamp.advance { color: var(--advance); border-color: var(--advance); background: var(--advance-soft); }
.stamp.pending { color: var(--muted); border-color: var(--line-strong); background: none; transform: none; font-weight: 500; }
.stamp.pop { animation: stamp-pop .35s cubic-bezier(.2, 2.2, .4, 1) both; }
@keyframes stamp-pop { from { transform: scale(1.6) rotate(-8deg); opacity: 0 } to { transform: scale(1) rotate(-2deg); opacity: 1 } }

.stars { color: #d9a90c; letter-spacing: 1px; font-size: 13px; }
.stars .off { color: var(--line-strong); }
.stars.click span { cursor: pointer; font-size: 22px; transition: transform .1s; }
.stars.click span:hover { transform: scale(1.2); }

.chip {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 9px;
  border-radius: 20px; background: var(--paper-deep); color: var(--ink-soft);
}
.chip.blue { background: #e3ecf7; color: #2a5788; }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.red { background: #fbe5e2; color: var(--red); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.doc-ind { font-family: var(--mono); font-size: 11px; color: var(--ink-soft); }

/* ---------- Панель строки (drawer) ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(22, 32, 46, .45);
  z-index: 40; animation: fade .2s both;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 480px; max-width: 94vw;
  background: var(--surface); z-index: 41;
  border-left: 2px solid var(--ink);
  box-shadow: -18px 0 50px rgba(22, 32, 46, .25);
  display: flex; flex-direction: column;
  animation: slide-in .28s cubic-bezier(.2, .9, .3, 1) both;
}
@keyframes slide-in { from { transform: translateX(60px); opacity: 0 } to { transform: none; opacity: 1 } }
.drawer-head {
  padding: 20px 24px 14px; border-bottom: 1px dashed var(--line-strong);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
}
.drawer-head .t { font-family: var(--display); font-weight: 700; font-size: 16px; line-height: 1.3; }
.drawer-head .s { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 4px; }
.drawer-close { background: none; border: none; font-size: 22px; color: var(--muted); line-height: 1; }
.drawer-close:hover { color: var(--ink); }
.drawer-body { padding: 18px 24px; overflow-y: auto; flex: 1; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); font-size: 12px; padding-top: 1px; }
.kv dd { font-weight: 500; overflow-wrap: anywhere; }
.kv dd.num { font-family: var(--mono); }
.kv dd.hero { font-size: 16px; font-weight: 700; color: var(--accent); font-family: var(--mono); }
.sect { margin-top: 22px; padding-top: 16px; border-top: 1px dashed var(--line-strong); }
.sect > h4 {
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-soft); margin-bottom: 12px; font-weight: 700;
}
.pay-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-weight: 500; }
.switch input { accent-color: var(--paid); width: 16px; height: 16px; cursor: pointer; }
.doc-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 7px; margin-bottom: 7px; font-size: 13px;
  background: #fff;
}
.doc-item a { color: var(--ink); font-weight: 500; text-decoration: none; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-item a:hover { color: var(--accent); }
.doc-item .meta { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.drawer-foot { padding: 14px 24px; border-top: 1px solid var(--line); display: flex; gap: 10px; flex-wrap: wrap; background: var(--paper); }

/* ---------- Модальные окна ---------- */
.modal-card {
  position: fixed; z-index: 42; inset: 0; margin: auto;
  width: 680px; max-width: 94vw; height: fit-content; max-height: 90vh; overflow-y: auto;
  background: var(--surface); border: 2px solid var(--ink); border-radius: 8px;
  box-shadow: 10px 10px 0 rgba(27, 37, 50, .15);
  padding: 26px 28px;
  animation: modal-in .3s cubic-bezier(.2, .9, .3, 1.1) both;
}
@keyframes modal-in { from { opacity: 0 } to { opacity: 1 } }
.modal-card h3 { font-family: var(--display); font-size: 18px; margin-bottom: 4px; }
.modal-card .m-sub { color: var(--ink-soft); font-size: 12.5px; margin-bottom: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.calc-strip {
  grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center;
  background: var(--navy); color: #e9e4d8; border-radius: 7px; padding: 10px 16px; margin-top: 4px;
}
.calc-strip .lbl { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: rgba(233, 228, 216, .6); }
.calc-strip .val { font-family: var(--mono); font-size: 19px; font-weight: 600; color: #fff; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.lock-note {
  grid-column: 1 / -1; font-size: 12px; color: var(--amber); background: var(--amber-soft);
  border: 1px solid rgba(185, 124, 16, .3); border-radius: 6px; padding: 8px 12px;
}

/* ---------- Карточки заявок ---------- */
.req-card {
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 12px; box-shadow: var(--shadow);
  border-left: 4px solid var(--amber);
}
.req-card.approved { border-left-color: var(--green); opacity: .75; }
.req-card.rejected { border-left-color: var(--red); opacity: .75; }
.req-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.req-title { font-weight: 600; font-size: 13.5px; }
.req-meta { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.req-diff { font-size: 13px; margin: 4px 0; }
.req-diff table { border-collapse: collapse; }
.req-diff td { padding: 3px 12px 3px 0; }
.req-diff .old { color: var(--muted); text-decoration: line-through; font-family: var(--mono); font-size: 12px; }
.req-diff .new { color: var(--green); font-weight: 600; font-family: var(--mono); font-size: 12px; }
.req-diff .fld { color: var(--ink-soft); }
.req-comment { font-size: 12.5px; color: var(--ink-soft); font-style: italic; margin-top: 6px; }
.req-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- Справочники / пользователи ---------- */
.dir-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.dir-card { background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.dir-card h4 { font-family: var(--display); font-size: 14px; margin-bottom: 12px; }
.dir-item { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.dir-item button { background: none; border: none; color: var(--muted); font-size: 15px; }
.dir-item button:hover { color: var(--red); }
.dir-add { display: flex; gap: 8px; margin-top: 12px; }
.dir-add input { flex: 1; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 6px; }

.empty {
  text-align: center; color: var(--muted); padding: 60px 20px; font-size: 14px;
  background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius);
}
.empty .big { font-size: 34px; margin-bottom: 10px; }

/* ---------- Тосты ---------- */
#toasts { position: fixed; bottom: 22px; right: 22px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--navy); color: #fff; border-left: 4px solid var(--accent);
  padding: 11px 18px; border-radius: 7px; font-size: 13.5px; max-width: 380px;
  box-shadow: 0 10px 30px rgba(22, 32, 46, .35);
  animation: toast-in .25s cubic-bezier(.2, .9, .3, 1.2) both;
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) } to { opacity: 1; transform: none } }

/* ---------- Полировка ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 6px; border: 2px solid var(--surface); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.table-wrap { scrollbar-width: thin; }

table.grid tbody tr { border-left: 3px solid transparent; }
table.grid tbody tr:hover td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

.page-title .count {
  background: var(--paper-deep); padding: 3px 10px; border-radius: 20px;
}

.btn:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ============ Мобильная адаптация ============ */

/* Мобильная шапка и оверлей меню: на десктопе скрыты (display:none не участвует в grid .app) */
.topbar { display: none; }
.nav-overlay { display: none; }

/* ---------- ≤1024: сайдбар превращается в выезжающее бургер-меню ---------- */
@media (max-width: 1024px) {
  html, body { overflow-x: hidden; }

  .topbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 35;
    background: linear-gradient(180deg, var(--navy), var(--navy-2));
    padding: 8px 12px;
    border-bottom: 2px solid var(--accent);
  }
  .burger {
    width: 44px; height: 44px; flex-shrink: 0;
    display: grid; place-items: center;
    background: none; border: 1px solid rgba(233, 228, 216, .3);
    border-radius: 8px; color: #e9e4d8; font-size: 20px; line-height: 1;
    transition: background .15s;
  }
  .burger:hover, .burger:active { background: rgba(255, 255, 255, .08); }
  .topbar .brand-logo-top { height: 24px; width: auto; display: block; }

  .app { display: block; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 280px; max-width: 85vw;
    height: 100vh; height: 100dvh;
    overflow-y: auto;
    z-index: 60;
    transform: translateX(-105%);
    transition: transform .28s cubic-bezier(.2, .9, .3, 1);
  }
  body.menu-open .sidebar { transform: none; box-shadow: 18px 0 50px rgba(22, 32, 46, .35); }
  .nav-overlay { position: fixed; inset: 0; background: rgba(22, 32, 46, .45); z-index: 59; }
  body.menu-open .nav-overlay { display: block; animation: fade .2s both; }
  body.menu-open { overflow: hidden; }

  .main { padding: 18px 16px 60px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }

  /* iOS Safari: у input[type=date] своя минимальная ширина — распирает ячейку grid и вылезает за карточку */
  .form-grid .field { min-width: 0; }
  .field input[type="date"],
  .field input[type="month"],
  .field input[type="time"],
  .field input[type="datetime-local"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
  /* и центрирует значение даты — выравниваем влево, как остальные поля */
  input::-webkit-date-and-time-value { text-align: left; }
}

/* ---------- ≤768: формы в одну колонку, тач-цели, модалки/дровер на всю ширину ---------- */
@media (max-width: 768px) {
  /* 16px в полях ввода — иначе iOS Safari масштабирует страницу при фокусе */
  input, select, textarea { font-size: 16px; }
  .field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea {
    min-height: 44px; padding: 11px 12px;
  }
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; }
  .pw-eye { padding: 10px 12px; }

  .form-grid { grid-template-columns: 1fr; }
  .kv dd.hero { font-size: 18px; }

  .nav a { padding: 12px 14px; font-size: 15px; }
  .side-user button { min-height: 44px; }
  .side-user .u-actions { gap: 8px; }

  .toolbar input[type=search] { flex: 1 1 100%; width: auto; min-width: 0; min-height: 44px; }
  .toolbar select { flex: 1 1 40%; min-width: 0; max-width: 100%; min-height: 44px; }

  .page-head .btn { width: 100%; justify-content: center; }

  /* Таблицы: вертикально скроллит страница, горизонтально — сам .table-wrap */
  .table-wrap { max-height: none; }
  table.grid td { padding: 11px 10px; }
  table.grid th { padding: 10px; }
  .switch input { width: 20px; height: 20px; }
  .pay-row { min-height: 44px; }
  .dir-item { padding: 9px 0; }
  .dir-item button { font-size: 18px; padding: 8px 10px; }
  .dir-add input { min-height: 44px; }
  .stars.click span { font-size: 26px; }

  /* Модалки — на всю ширину, скролл внутри */
  .modal-card {
    width: 100%; max-width: 100%;
    max-height: 100vh; max-height: 100dvh;
    border-radius: 0; border-left: none; border-right: none;
    box-shadow: none;
    padding: 22px 18px;
  }

  /* Дровер — на весь экран */
  .drawer { width: 100%; max-width: 100%; border-left: none; }
  .drawer-head { padding: 16px 16px 12px; }
  .drawer-body { padding: 16px; }
  .drawer-foot { padding: 12px 16px; }
  .drawer-foot .btn { flex: 1 1 auto; justify-content: center; }
  .drawer-close { padding: 10px 12px; margin: -8px -10px 0 0; }

  .req-diff { overflow-x: auto; }
  .req-actions .btn { flex: 1 1 auto; justify-content: center; }
}

/* ---------- ≤480: телефоны ---------- */
@media (max-width: 480px) {
  .main { padding: 14px 12px 50px; }

  .login-wrap { padding: 16px; }
  .login-card { padding: 30px 22px 24px; }
  .login-title { font-size: 26px; }
  .login-sub { overflow-wrap: anywhere; }

  .page-title { font-size: 20px; }
  .page-sub { font-size: 12.5px; }

  .kv { grid-template-columns: 106px 1fr; gap: 8px 10px; }
  .drawer-head .t { font-size: 15px; }

  .modal-card { padding: 20px 14px; }
  .modal-card h3 { font-size: 16px; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1 1 auto; justify-content: center; }
  .calc-strip { flex-wrap: wrap; gap: 4px 10px; }
  .calc-strip .val { font-size: 17px; }

  .dir-grid { grid-template-columns: 1fr; }

  #toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
}

/* ---------- ≤360: самые узкие экраны ---------- */
@media (max-width: 360px) {
  .main { padding: 12px 10px 44px; }
  .login-card { padding: 26px 16px 20px; }
  .login-title { font-size: 22px; }
  .page-title { font-size: 18px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
  .kv dt:first-child { margin-top: 0; }
  .modal-card { padding: 18px 12px; }
}
