/* ============================================================
   Облік ОС — дизайн-система. Тёмная по умолчанию, военно-утилитарная.
   ============================================================ */
:root {
  --bg: #0b0e14;
  --bg2: #111620;
  --surface: #151b27;
  --surface2: #1b2331;
  --line: #283142;
  --line2: #36425a;
  --text: #e6ebf2;
  --muted: #8a96aa;
  --muted2: #5d6677;
  --accent: #4f8cff;
  --accent-d: #2f6ae0;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --radius-s: 10px;
  --shadow: 0 8px 30px rgba(0,0,0,.45);
  --shadow-s: 0 2px 10px rgba(0,0,0,.3);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tap: 44px;
}
:root[data-theme="light"] {
  --bg: #eef1f6; --bg2: #e6eaf1; --surface: #ffffff; --surface2: #f4f6fa;
  --line: #dce1ea; --line2: #c6cdda; --text: #18202e; --muted: #5a6678; --muted2: #93a0b5;
  --shadow: 0 8px 30px rgba(20,30,50,.12); --shadow-s: 0 2px 10px rgba(20,30,50,.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Каркас ---------------------------------------- */
#app { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  background: linear-gradient(180deg, var(--bg2), var(--bg));
  border-bottom: 1px solid var(--line); position: relative; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; letter-spacing: .2px; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, #2a3550, #1a2235); border: 1px solid var(--line2);
  font-size: 16px;
}
.brand .mark.szch { box-shadow: inset 0 0 0 1.5px #2f6ae055; }
.brand small { display: block; color: var(--muted); font-weight: 600; font-size: 11px; }
.brand > div > span { white-space: nowrap; }
.hide-sm { display: inline; }
@media (max-width: 560px) {
  .brand small { display: none; }
  .topbar { gap: 8px; padding: calc(9px + var(--safe-t)) max(12px, env(safe-area-inset-right)) 9px max(12px, env(safe-area-inset-left)); }
  .seg button { padding: 7px 10px; }
}
.topbar .spacer { flex: 1; }

.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); padding: 7px 13px; border-radius: 8px;
  font-weight: 700; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; min-height: 34px;
}
.seg button .em { font-size: 14px; }
.seg button.on { background: var(--surface2); color: var(--text); box-shadow: var(--shadow-s); }
.seg.world button.on { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-d)); }

.idbtn { display:inline-flex; align-items:center; gap:7px; background: var(--surface); border:1px solid var(--line);
  border-radius: 999px; padding: 5px 12px 5px 6px; cursor: pointer; color: var(--text); font-weight:600; }
.idbtn .av { width: 26px; height: 26px; border-radius:50%; background: var(--accent-d); color:#fff; display:grid; place-items:center; font-size:12px; font-weight:800; }

.layout { flex: 1; display: flex; min-height: 0; }
.siderail { display: none; }
.content { flex: 1; min-width: 0; overflow: auto; overscroll-behavior: contain; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 16px 14px 90px; }

/* ---------- Нижняя навигация (моб) ----------------------- */
.bottomnav {
  display: flex; background: var(--bg2); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); position: relative; z-index: 30;
}
.bottomnav button {
  flex: 1; border: 0; background: transparent; color: var(--muted); padding: 8px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; font-size: 11px; font-weight: 600;
}
.bottomnav button svg { width: 23px; height: 23px; }
.bottomnav button.on { color: var(--accent); }
.bottomnav button.on svg { filter: drop-shadow(0 0 8px var(--accent)); }

/* ---------- Типовые элементы ----------------------------- */
.icon-btn { width: var(--tap); height: var(--tap); display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); border-radius: 10px; cursor: pointer; }
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }

.btn { border: 1px solid var(--line2); background: var(--surface2); color: var(--text); padding: 10px 16px; border-radius: 11px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); justify-content: center; }
.btn:hover { border-color: var(--accent); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-d)); border-color: transparent; color: #fff; }
.btn.danger { background: #2a1416; border-color: #5b2020; color: #ff8a8a; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 12px; min-height: 36px; font-size: 13px; border-radius: 9px; }

.fab { position: fixed; right: 16px; bottom: calc(74px + var(--safe-b)); width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-d)); color: #fff; border: 0; box-shadow: var(--shadow); cursor: pointer; display: grid; place-items: center; z-index: 25; }
.fab svg { width: 26px; height: 26px; }

.input, select.input, textarea.input {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 11px 13px; color: var(--text); outline: none;
}
.input:focus { border-color: var(--accent); }
label.fld { display: block; margin-bottom: 12px; }
label.fld > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }

.searchbar { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; }
.searchbar svg { width: 19px; height: 19px; color: var(--muted); flex: none; }
.searchbar input { flex: 1; border: 0; background: transparent; padding: 12px 0; outline: none; }

.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.wraprow { display:flex; flex-wrap: wrap; gap: 8px; }
.section-title { display:flex; align-items:center; gap:8px; margin: 18px 2px 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 800; }
.section-title .count { color: var(--text); background: var(--surface2); border:1px solid var(--line); padding: 1px 8px; border-radius: 999px; font-size: 12px; }

/* ---------- Статус-чип ----------------------------------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--c); border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); white-space: nowrap; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.dot-lg { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------- KPI плитки ----------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; position: relative; overflow: hidden; }
.kpi .v { font-size: 28px; font-weight: 800; line-height: 1.05; }
.kpi .l { color: var(--muted); font-size: 12.5px; font-weight: 600; margin-top: 3px; }
.kpi .accentbar { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c, var(--accent)); }

/* ---------- Карточка / список бойцов --------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.list { display: flex; flex-direction: column; gap: 8px; }
.prow { display: flex; align-items: center; gap: 12px; padding: 11px 13px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; min-width: 0; }
.prow:hover { border-color: var(--line2); background: var(--surface2); }
.prow .av { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; font-weight: 800; color: #fff; flex: none; font-size: 15px; position: relative; }
.prow .av .ring { position:absolute; inset:-3px; border-radius:13px; border:2px solid var(--c); opacity:.5; }
.prow .main { flex: 1; min-width: 0; }
.prow .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prow .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.prow .sub b { color: var(--text); font-weight: 600; }
.prow .end { text-align: right; flex: none; display:flex; flex-direction:column; align-items:flex-end; gap:4px; }
.flagdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.flagdot.warn { background: var(--warn); } .flagdot.info { background: var(--accent); }

/* ---------- Карточка-досье ------------------------------- */
.dossier-hero { display: flex; gap: 14px; align-items: center; padding: 16px; }
.dossier-hero .av { width: 66px; height: 66px; border-radius: 16px; display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 24px; flex: none; }
.dossier-hero h2 { margin: 0 0 4px; font-size: 20px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; padding: 4px 16px 16px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; font-weight: 600; }
.statgrid { display:flex; flex-wrap:wrap; gap:7px; }
.statgrid .opt { padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface2); cursor: pointer; font-weight: 700; font-size: 13px; color: var(--muted); }
.statgrid .opt.on { color: #fff; border-color: transparent; }
.equip-toggles { display:flex; gap:8px; flex-wrap: wrap; }
.toggle { display:flex; align-items:center; gap:8px; padding: 8px 12px; border:1px solid var(--line); border-radius: 10px; background: var(--surface2); cursor: pointer; font-weight:600; font-size: 13px; }
.toggle .box { width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--line2); display: grid; place-items: center; }
.toggle.on .box { background: var(--ok); border-color: var(--ok); color: #04130a; }
.toggle.on .box svg { width: 14px; height: 14px; }

.timeline { display: flex; flex-direction: column; gap: 2px; }
.tl-day { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid var(--line); }
.tl-day .d { width: 64px; color: var(--muted); font-size: 12.5px; flex: none; }
.tl-day .slots { display: flex; gap: 6px; flex: 1; }

.loghint { font-size: 12px; color: var(--muted2); }
.logrow { display:flex; gap:10px; padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: 13px; }
.logrow .t { color: var(--muted2); flex: none; width: 76px; font-size: 12px; }

/* ---------- Дашборд ------------------------------------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px; margin-bottom: 14px; }
.panel h3 { margin: 0 0 12px; font-size: 14px; }
.dash-grid { display: grid; gap: 14px; }
.donut-wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.legend { display: flex; flex-direction: column; gap: 7px; flex: 1; min-width: 160px; }
.legend .li { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.legend .li .nm { flex: 1; color: var(--muted); }
.legend .li b { font-variant-numeric: tabular-nums; }
.chart-donut { width: 168px; height: 168px; flex: none; }
.donut-num { fill: var(--text); font-size: 30px; font-weight: 800; }
.donut-sub { fill: var(--muted); font-size: 11px; font-weight: 600; }
.chart-bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 92px 1fr 34px; align-items: center; gap: 10px; font-size: 13px; }
.bar-label { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: var(--surface2); border-radius: 6px; height: 18px; overflow: hidden; border: 1px solid var(--line); }
.bar-fill { display: block; height: 100%; border-radius: 6px; transition: width .5s ease; }
.bar-val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-line { width: 100%; height: auto; }
.chart-line .axis { fill: var(--muted2); font-size: 10px; }

/* ---------- Табличный режим ----------------------------- */
.table-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.gridscroll { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); max-height: calc(100vh - 230px); }
table.grid { border-collapse: separate; border-spacing: 0; font-size: 12.5px; white-space: nowrap; }
table.grid th, table.grid td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; }
table.grid thead th { position: sticky; top: 0; background: var(--surface2); z-index: 3; padding: 6px 8px; font-weight: 700; color: var(--muted); text-align: center; }
table.grid .colpib { position: sticky; left: 0; z-index: 4; background: var(--surface2); text-align: left; min-width: 168px; padding: 6px 10px; }
table.grid thead .colpib { z-index: 6; }
table.grid tbody .colpib { background: var(--surface); font-weight: 600; }
table.grid .daygrp { border-left: 2px solid var(--line2); }
table.grid td.cell { width: 34px; height: 30px; text-align: center; cursor: pointer; }
table.grid td.cell .sq { width: 100%; height: 100%; display: grid; place-items: center; font-size: 10px; font-weight: 800; color: #0008; }
table.grid tfoot td, table.grid tfoot th { position: sticky; bottom: 0; background: var(--surface2); font-weight: 800; text-align: center; padding: 5px; z-index: 3; }
table.grid tfoot .colpib { z-index: 5; text-align: left; }

/* ---------- Модалка / шторка ----------------------------- */
.modal-back { position: fixed; inset: 0; background: rgba(4,7,12,.6); backdrop-filter: blur(3px); display: flex; align-items: flex-end; justify-content: center; opacity: 0; transition: opacity .2s; z-index: 100; }
.modal-back.show { opacity: 1; }
.modal-sheet { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; border-radius: 18px 18px 0 0; border: 1px solid var(--line); display: flex; flex-direction: column; transform: translateY(20px); transition: transform .22s; padding-bottom: var(--safe-b); }
.modal-back.show .modal-sheet { transform: translateY(0); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 8px 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 16px 18px; overflow: auto; }
.modal-foot { display: flex; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--line); }
.modal-foot .btn { flex: 1; }

#toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); translate: -50% 20px; background: #0d1320; border: 1px solid var(--line2); color: var(--text); padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, translate .2s; z-index: 200; font-weight: 600; max-width: 90vw; }
#toast.show { opacity: 1; translate: -50% 0; }
#toast.ok { border-color: #2c6b3f; } #toast.err { border-color: #6b2c2c; }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 10px; opacity: .5; }

.banner { background: color-mix(in srgb, var(--warn) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--line)); border-radius: 12px; padding: 11px 13px; font-size: 13px; display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; }
.banner svg { width: 18px; height: 18px; color: var(--warn); flex: none; margin-top: 1px; }

/* ---------- Десктоп -------------------------------------- */
@media (min-width: 860px) {
  .bottomnav { display: none; }
  .siderail { display: flex; flex-direction: column; gap: 4px; width: 210px; padding: 14px 10px; border-right: 1px solid var(--line); background: var(--bg2); flex: none; }
  .siderail button { display: flex; align-items: center; gap: 12px; border: 0; background: transparent; color: var(--muted); padding: 11px 13px; border-radius: 11px; cursor: pointer; font-weight: 700; font-size: 14px; }
  .siderail button svg { width: 21px; height: 21px; }
  .siderail button:hover { background: var(--surface); color: var(--text); }
  .siderail button.on { background: var(--surface2); color: var(--text); }
  .siderail button.on svg { color: var(--accent); }
  .siderail .rail-sec { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted2); padding: 12px 14px 6px; font-weight: 800; }
  .fab { display: none; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .dash-grid { grid-template-columns: 1fr 1fr; }
  .dash-grid .full { grid-column: 1 / -1; }
  .wrap { padding: 22px 24px 40px; }
  .modal-back { align-items: center; }
  .modal-sheet { border-radius: 18px; }
  .list.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
}
@media (min-width: 1200px) { .list.cols { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
