:root {
  --bg: #EEEEEE; --surface: #FFFFFF; --surface-2: #F7F7F7; --text: #151515; --muted: #5C5C5C;
  --border: #DADADA; --accent: #E70000; --accent-text: #C10000; --accent-deep: #750117;
  --ok: #0E7A3E; --ok-bg: #E3F4EA; --warn: #8A5200; --warn-bg: #FFF1D6; --danger: #B00000; --danger-bg: #FDE3E3;
  --info: #1D4E89; --info-bg: #E2ECF8; --muted-bg: #ECECEC;
  --radius: 12px; --radius-sm: 8px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 1px 1px rgba(0,0,0,.04);
  --font: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111; --surface: #1B1B1B; --surface-2: #222222; --text: #F2F2F2; --muted: #ABABAB;
    --border: #2F2F2F; --accent-text: #FF5C5C; --ok: #5BD08D; --ok-bg: #12301F; --warn: #F2B65A; --warn-bg: #33270F;
    --danger: #FF7A7A; --danger-bg: #3A1414; --info: #8DB8F0; --info-bg: #14253A; --muted-bg: #262626;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 var(--font); background: var(--bg); color: var(--text); }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }

/* каркас */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 20px 14px; position: sticky;
  top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; font-weight: 700; letter-spacing: .01em; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  display: grid; place-items: center; color: #fff; font-size: 13px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text); font-weight: 500; min-height: 40px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--danger-bg); color: var(--accent-text); }
.nav .count { margin-left: auto; background: var(--accent); color: #fff; border-radius: 99px; font-size: 12px;
  padding: 0 7px; font-weight: 600; }
.side-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 8px; }
.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 12px 28px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.content { padding: 24px 28px 48px; max-width: 1280px; }
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 4px; font-weight: 700; }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 600; }
.lead { color: var(--muted); margin: 0 0 20px; max-width: 75ch; }

/* картки й сітки */
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: 2fr 1fr; }
.g-alerts { grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 16px; }
.grid .card + .card { margin-top: 0; }
.kpi .v { font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 13px; margin-top: 4px; }
.kpi.alert { border-color: var(--accent); }
.kpi.alert .v { color: var(--accent-text); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }

/* кнопки й поля */
.btn { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 8px 16px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 600 14px var(--font);
  cursor: pointer; transition: background .15s, border-color .15s, transform .1s; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #B80010); border-color: transparent; color: #fff; }
.btn.primary:hover { background: linear-gradient(135deg, #D10000, var(--accent-deep)); }
.btn.stop { background: var(--accent-deep); border-color: transparent; color: #fff; }
.btn.go { background: var(--ok); border-color: transparent; color: #fff; }
.btn.sm { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
label { font-weight: 500; font-size: 14px; display: block; margin-bottom: 6px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=time], input[type=datetime-local], select, textarea {
  width: 100%; font: 15px var(--font); color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 11px; min-height: 40px; }
textarea { min-height: 120px; resize: vertical; line-height: 1.45; }
.field { margin-bottom: 14px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; min-height: 32px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.seg button { border: 0; background: transparent; font: 600 13px var(--font); padding: 8px 14px; cursor: pointer;
  color: var(--text); min-height: 36px; }
.seg button.on { background: var(--text); color: var(--surface); }

/* чіпи статусів */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; font-size: 12px;
  font-weight: 600; white-space: nowrap; background: var(--muted-bg); color: var(--muted); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.danger { background: var(--danger-bg); color: var(--danger); }
.chip.info { background: var(--info-bg); color: var(--info); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.live .dot { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .live .dot { animation: none; } * { transition: none !important; } }

/* таблиці */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td .btn.sm { white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* дерево */
details.node { border-top: 1px solid var(--border); }
details.node > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 10px 4px; min-height: 44px; }
details.node > summary::-webkit-details-marker { display: none; }
details.node > summary::before { content: ""; width: 7px; height: 7px; border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; margin: 0 4px; }
details.node[open] > summary::before { transform: rotate(45deg); }
details.node .inner { padding: 0 0 8px 22px; }
.city > summary { font-weight: 700; font-size: 16px; }
.loc > summary { font-weight: 600; }
.dir-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600;
  margin: 10px 0 4px; display: flex; align-items: center; gap: 8px; }
.meter { width: 90px; height: 6px; background: var(--muted-bg); border-radius: 99px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--ok); }

/* інше */
.banner { border-radius: var(--radius); padding: 12px 16px; display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
.banner.danger { background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.info { background: var(--info-bg); color: var(--info); }
.feed { list-style: none; padding: 0; margin: 0; }
.feed li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; display: flex; gap: 10px; }
.feed li:last-child { border-bottom: 0; }
.feed time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; width: 46px; }
.msg { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 14px; }
.vars { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.vars button { border: 1px dashed var(--border); background: transparent; border-radius: 99px; padding: 2px 10px;
  font: 13px var(--font); color: var(--text); cursor: pointer; min-height: 28px; }
.picker { max-height: 520px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 4px 12px; background: var(--surface); }
.picker .grp { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 14px; }
.copy { display: flex; gap: 8px; }
.copy input { font-size: 13px; }
.login { max-width: 380px; margin: 12vh auto; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3, .g-alerts { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px 12px; }
  .brand { padding: 0 8px 0 0; } .side-foot { display: none; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; } .nav a span.t { display: none; }
  .top, .content { padding-left: 16px; padding-right: 16px; }
  .g2 { grid-template-columns: 1fr; }
}
@media (max-width: 520px) { .g4 { grid-template-columns: 1fr 1fr; } .kpi .v { font-size: 22px; } }

/* вхід */
body.auth { display: grid; grid-template-columns: minmax(320px, 44%) 1fr; min-height: 100vh; background: var(--surface); }
.logo { display: block; aspect-ratio: 3463 / 560; background: currentColor;
  -webkit-mask: url(/static/logo.svg) center / contain no-repeat; mask: url(/static/logo.svg) center / contain no-repeat; }
.auth-brand { background: linear-gradient(150deg, var(--accent) 0%, #A8000F 48%, var(--accent-deep) 100%); color: #fff;
  padding: 48px; display: flex; flex-direction: column; justify-content: space-between; gap: 32px; }
.logo-light { width: 190px; color: #fff; }
.auth-title { font-size: 34px; line-height: 1.15; font-weight: 700; margin: 0 0 12px; letter-spacing: -.01em; text-wrap: balance; }
.auth-sub { font-size: 17px; margin: 0; max-width: 34ch; color: #fff; opacity: .92; }
.auth-main { display: grid; place-items: center; padding: 32px 24px; }
.auth-card { width: 100%; max-width: 380px; }
.logo-mobile { display: none; width: 160px; color: var(--accent-text); margin-bottom: 28px; }
.pw { position: relative; }
.pw input { padding-right: 48px; }
.pw-toggle { position: absolute; right: 2px; top: 2px; width: 44px; height: calc(100% - 4px); min-height: 36px; border: 0;
  background: transparent; color: var(--muted); cursor: pointer; border-radius: var(--radius-sm); display: grid; place-items: center; }
.pw-toggle:hover { color: var(--text); }
.pw-toggle[aria-pressed="true"] { color: var(--accent-text); }
.btn.block { width: 100%; justify-content: center; min-height: 46px; font-size: 15px; }
.form-error { color: var(--danger); background: var(--danger-bg); border-radius: var(--radius-sm); padding: 9px 12px; margin: 0 0 14px; font-size: 14px; font-weight: 500; }
input[aria-invalid="true"] { border-color: var(--danger); }
.auth-help { margin-top: 18px; }
@media (max-width: 760px) {
  body.auth { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .logo-mobile { display: block; }
  .auth-main { place-items: start center; padding-top: 12vh; }
}

/* бічна панель, форми */
.brand-mark { background: none; width: 30px; height: 30px; border-radius: 0; }
.who { display: block; font-weight: 600; color: var(--text); }
.linkish { border: 0; background: none; padding: 0; font: inherit; color: var(--accent-text); cursor: pointer; }
.linkish:hover { text-decoration: underline; }
.narrow { max-width: 460px; }
.sim-time { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); max-width: 340px; }
.banner .icon { flex: none; }
.seg button[disabled] { opacity: .45; cursor: not-allowed; }
