:root {
  --bg: #F2F4F7;
  --card: #FFFFFF;
  --line: #E1E6EC;
  --line-strong: #C5D3E8;
  --text: #1B2430;
  --text-2: #3E4957;
  --muted: #5B6675;
  --accent: #1F5FBF;
  --accent-hover: #174A94;
  --accent-soft: #F3F7FD;
  --ok-bg: #E3F2E8;
  --ok: #1E6B3A;
  --warn-bg: #FDF1E3;
  --warn: #8A3B12;
  --chip: #EEF1F4;
  --side: #1B2430;
  --side-text: #C7CED8;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1 { font-size: 20px; margin: 0 0 12px; font-weight: 600; }
h2 { font-size: 13px; margin: 20px 0 8px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.splash { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* Каркас: на телефоне и в мини-приложении — нижние вкладки, на компьютере — меню слева */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar .title { font-weight: 600; }
.main { flex: 1; padding: 16px 16px calc(80px + env(safe-area-inset-bottom)); width: 100%; max-width: 760px; margin: 0 auto; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1 1 0; min-width: 0; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 500; color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer;
}
.tab svg { width: 22px; height: 22px; flex-shrink: 0; }
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10.5px; }
.tab.on { color: var(--accent); }
.side { display: none; }

@media (min-width: 900px) {
  .shell:not(.miniapp) { flex-direction: row; }
  .shell:not(.miniapp) .side {
    display: flex; flex-direction: column; width: 240px; flex-shrink: 0;
    background: var(--side); color: var(--side-text); padding: 20px 12px; position: sticky; top: 0; height: 100vh;
  }
  .shell:not(.miniapp) .side .brand { color: #fff; font-weight: 600; padding: 0 12px 20px; }
  .shell:not(.miniapp) .side a {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
    color: var(--side-text); text-decoration: none;
  }
  .shell:not(.miniapp) .side a svg { width: 20px; height: 20px; }
  .shell:not(.miniapp) .side a:hover { background: rgba(255,255,255,.06); color: #fff; }
  .shell:not(.miniapp) .side a.on { background: rgba(255,255,255,.1); color: #fff; }
  .shell:not(.miniapp) .side .who { margin-top: auto; padding: 12px; font-size: 13px; }
  .shell:not(.miniapp) .side .who button { margin-top: 8px; }
  .shell:not(.miniapp) .col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .shell:not(.miniapp) .tabs { display: none; }
  .shell:not(.miniapp) .main { padding: 28px 32px 40px; max-width: 980px; margin: 0; }
  .shell:not(.miniapp) .topbar { display: none; }
  .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
}
.col { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.row > div { min-width: 0; }
.row .grow { flex: 1; }

/* Элементы */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.stat .v { font-size: 22px; font-weight: 600; }
.stat .l { font-size: 12px; color: var(--muted); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 44px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .sub { font-size: 12px; color: var(--muted); }
.chip { display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--text-2); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar div { height: 100%; background: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--card); color: var(--accent);
  font: 500 15px system-ui, sans-serif; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--accent-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { border: 0; background: none; min-height: 32px; padding: 0 8px; color: var(--side-text); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

input[type=text], input[type=search], select {
  margin-bottom: 12px;
  width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 10px;
  font: 15px system-ui, sans-serif; background: var(--card); color: var(--text);
}
input.code { margin-bottom: 0; font-size: 20px; letter-spacing: .12em; text-transform: uppercase; text-align: center; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters button { border: 1px solid var(--line-strong); background: var(--card); border-radius: 999px; padding: 6px 12px; font: 13px system-ui, sans-serif; cursor: pointer; color: var(--text-2); }
.filters button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

details.region { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; }
details.region summary { padding: 12px 14px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
details.region label { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); cursor: pointer; }
details.region label .grow { flex: 1; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; accent-color: var(--accent); }
.choices { display: grid; gap: 8px; }
.choices label { display: flex; gap: 10px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; cursor: pointer; }
.total { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); }
@media (min-width: 900px) { .shell:not(.miniapp) .total { bottom: 12px; } }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { max-width: 420px; width: 100%; padding: 24px; }
.login ol { padding-left: 20px; margin: 0 0 16px; }
.err { color: var(--warn); font-size: 14px; min-height: 20px; margin: 8px 0; }
.topbar .btn.ghost { color: var(--accent); }
