:root { --blue:#1A2E6E; --amber:#F0A832; --bg:#F4F4F6; --line:#E3E3E8; --text:#1C1C22; --muted:#71717C; }
* { box-sizing:border-box; margin:0; }
body { font:14px/1.5 -apple-system,'Segoe UI',Roboto,sans-serif; background:var(--bg); color:var(--text); }
header { display:flex; align-items:center; gap:12px; padding:10px 18px; background:var(--blue); color:#fff; }
header .logo { font-weight:600; font-size:17px; }
header .sub { font-size:12px; opacity:.65; }
header .right { margin-left:auto; font-size:12px; color:var(--amber); }
header .hdr-user { font-size:12px; opacity:.85; white-space:nowrap; }
.layout { display:flex; min-height:calc(100vh - 46px); }
nav { width:170px; flex-shrink:0; background:#fff; border-right:1px solid var(--line); padding:10px 8px; }
nav a { display:block; padding:8px 12px; border-radius:8px; color:var(--muted); text-decoration:none; margin-bottom:2px; }
nav a.active { background:#E9EDFB; color:var(--blue); font-weight:600; }
nav a.disabled { opacity:.4; pointer-events:none; }
main { flex:1; min-width:0; padding:18px 22px; }
.row { display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin-bottom:16px; }
h2 { font-size:16px; font-weight:600; }
select, input, textarea, button { font:inherit; padding:7px 12px; border:1px solid var(--line); border-radius:8px; background:#fff; }
button { cursor:pointer; }
button.primary { background:var(--blue); color:#fff; border-color:var(--blue); }
button.ghost { background:transparent; }
.card { background:#fff; border:1px solid var(--line); border-radius:12px; margin-bottom:12px; overflow:hidden; }
.card-h { display:flex; align-items:center; gap:10px; padding:10px 14px; border-bottom:1px solid var(--line); font-weight:600; flex-wrap:wrap; }
.card-b { padding:10px 14px; }
table { width:100%; border-collapse:collapse; }
td, th { padding:7px 14px; text-align:left; font-size:13px; }
th { color:var(--muted); font-weight:400; font-size:12px; }
tr + tr td { border-top:1px solid var(--line); }
.pill { display:inline-block; font-size:11px; padding:2px 9px; border-radius:10px; background:#E9EDFB; color:var(--blue); }
.pill.warn { background:#FDF1DC; color:#8A5A0B; }
.pill.danger { background:#FCE9E9; color:#8E2424; }
.pill.ok { background:#E5F3EA; color:#1F6B3A; }
.muted { color:var(--muted); }
.num { text-align:right; font-variant-numeric:tabular-nums; }
.form-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); gap:8px; }
dialog { border:1px solid var(--line); border-radius:12px; padding:18px; width:min(560px,92vw); }
dialog::backdrop { background:rgba(20,25,50,.35); }
label { font-size:12px; color:var(--muted); display:block; margin-bottom:3px; }
.field input, .field select, .field textarea { width:100%; }

/* нижняя панель навигации — только мобильный */
.bottombar { display:none; }
.more-sheet { display:none; }

/* ====== мобильный (<768px): нижнее меню, таблицы-карточки, полноэкранные диалоги ====== */
@media (max-width:767px) {
  body { padding-bottom:calc(60px + env(safe-area-inset-bottom)); }
  header { padding:8px 12px; flex-wrap:wrap; }
  header .right { display:none; }                /* якорь цикла на телефоне не нужен */
  nav#sideNav { display:none; }
  main { padding:12px; }
  .layout { display:block; min-height:auto; }

  /* зоны нажатия ≥44px; шрифт полей 16px — iOS не зумит */
  button, select, input:not([type=checkbox]):not([type=radio]) { min-height:44px; font-size:16px; }
  input[type=checkbox], input[type=radio] { width:22px; height:22px; }

  .bottombar { display:flex; position:fixed; left:0; right:0; bottom:0; z-index:90;
    width:auto; border-right:none; background:#fff; border-top:1px solid var(--line);
    padding:0 0 env(safe-area-inset-bottom); }
  .bottombar a, .bottombar button.more { position:relative; flex:1; display:flex; flex-direction:column; align-items:center;
    justify-content:center; gap:1px; min-height:56px; font-size:11px; color:var(--muted);
    text-decoration:none; border:none; background:none; padding:6px 2px; border-radius:0; margin:0; }
  .bottombar .ic { font-size:20px; line-height:1; }
  .bottombar a.active, .bottombar button.more.active { color:var(--blue); font-weight:600; }
  .bottombar .navbadge { position:absolute; transform:translate(12px,-22px); }

  .more-sheet { position:fixed; left:0; right:0; bottom:calc(56px + env(safe-area-inset-bottom)); z-index:89;
    background:#fff; border-top:1px solid var(--line); box-shadow:0 -8px 30px rgba(20,25,50,.15);
    border-radius:14px 14px 0 0; padding:8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .more-sheet.open { display:block; }
  .more-sheet a { display:block; padding:13px 14px; color:var(--text); text-decoration:none;
    border-radius:10px; font-size:15px; }
  .more-sheet a.active { background:#E9EDFB; color:var(--blue); font-weight:600; }

  /* таблицы → карточки (nav.js раскладывает подписи в data-th) */
  table.m-card thead, table.m-card tr.m-head { display:none; }
  table.m-card, table.m-card tbody, table.m-card tr, table.m-card td { display:block; width:100%; }
  table.m-card tr { border:1px solid var(--line); border-radius:10px; margin:8px 0; padding:8px 12px; background:#fff; }
  table.m-card td { border:none !important; padding:3px 0; font-size:14px; text-align:left; }
  table.m-card td:empty { display:none; }
  table.m-card td[data-th]::before { content:attr(data-th) ': '; color:var(--muted); font-size:12px; }

  /* диалоги — во весь экран, поля в одну колонку, кнопки прижаты снизу */
  dialog { width:100vw !important; max-width:100vw !important; height:100dvh; max-height:100dvh !important;
    margin:0; border:none; border-radius:0; padding:16px; overflow:auto; }
  .form-grid { grid-template-columns:1fr !important; }
  dialog > .row:last-of-type { position:sticky; bottom:0; background:#fff; margin:14px -16px 0 !important;
    padding:10px 16px calc(10px + env(safe-area-inset-bottom)); border-top:1px solid var(--line); }
  dialog > .row:last-of-type button { flex:1; }
}
