/* Адмінка власника Kerum. Дизайн-контекст — .impeccable.md у корені репозиторію.
   Образ: щиток сигнальних ламп і вахтовий журнал. Колір — лише за справжнім станом. */

/* ---------- шрифт: лежить тут же, сторонніх серверів немає ---------- */
@font-face { font-family: "Sofia Sans"; src: url("/assets/fonts/sofia-sans-cyr.woff2") format("woff2"); font-weight: 1 1000; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Sofia Sans"; src: url("/assets/fonts/sofia-sans-lat.woff2") format("woff2"); font-weight: 1 1000; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Sofia Sans Condensed"; src: url("/assets/fonts/sofia-sans-cond-cyr.woff2") format("woff2"); font-weight: 1 1000; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Sofia Sans Condensed"; src: url("/assets/fonts/sofia-sans-cond-lat.woff2") format("woff2"); font-weight: 1 1000; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ---------- жетони ---------- */
:root {
  color-scheme: dark;
  --bg: oklch(15.5% 0.008 152);
  --surface: oklch(19% 0.01 152);
  --raised: oklch(23.5% 0.012 152);
  --line: oklch(28.5% 0.012 152);
  --line-strong: oklch(40% 0.014 152);
  --text: oklch(93.5% 0.01 152);
  --text-2: oklch(75% 0.012 152);
  --text-3: oklch(61% 0.012 152);
  --ok: oklch(77% 0.17 152);     --ok-bg: oklch(25% 0.045 152);
  --warn: oklch(83% 0.14 86);    --warn-bg: oklch(27% 0.05 86);
  --alarm: oklch(71% 0.19 27);   --alarm-bg: oklch(27% 0.075 27);
  --calm: oklch(77% 0.06 236);   --calm-bg: oklch(26% 0.03 236);
  --focus: oklch(82% 0.13 152);
  --scrim: oklch(8% 0.01 152 / 0.72);

  --font: "Sofia Sans", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-tight: "Sofia Sans Condensed", "Sofia Sans", "Arial Narrow", Arial, sans-serif;
  --font-code: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --t-xs: 0.8125rem; --t-sm: 0.9375rem; --t-md: 1.0625rem; --t-lg: 1.375rem; --t-xl: 1.8125rem; --t-2xl: 2.5rem;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --radius: 10px;
  --nav-h: 60px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: oklch(96.8% 0.006 152);
    --surface: oklch(99% 0.004 152);
    --raised: oklch(99.6% 0.002 152);
    --line: oklch(88.5% 0.008 152);
    --line-strong: oklch(74% 0.012 152);
    --text: oklch(23% 0.02 152);
    --text-2: oklch(42% 0.018 152);
    --text-3: oklch(54% 0.015 152);
    --ok: oklch(48% 0.14 152);     --ok-bg: oklch(93% 0.05 152);
    --warn: oklch(50% 0.115 72);   --warn-bg: oklch(93.5% 0.065 88);
    --alarm: oklch(50% 0.2 27);    --alarm-bg: oklch(93.5% 0.04 27);
    --calm: oklch(46% 0.075 240);  --calm-bg: oklch(93.5% 0.022 240);
    --focus: oklch(52% 0.15 152);
    --scrim: oklch(30% 0.02 152 / 0.45);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: oklch(96.8% 0.006 152);
  --surface: oklch(99% 0.004 152);
  --raised: oklch(99.6% 0.002 152);
  --line: oklch(88.5% 0.008 152);
  --line-strong: oklch(74% 0.012 152);
  --text: oklch(23% 0.02 152);
  --text-2: oklch(42% 0.018 152);
  --text-3: oklch(54% 0.015 152);
  --ok: oklch(48% 0.14 152);     --ok-bg: oklch(93% 0.05 152);
  --warn: oklch(50% 0.115 72);   --warn-bg: oklch(93.5% 0.065 88);
  --alarm: oklch(50% 0.2 27);    --alarm-bg: oklch(93.5% 0.04 27);
  --calm: oklch(46% 0.075 240);  --calm-bg: oklch(93.5% 0.022 240);
  --focus: oklch(52% 0.15 152);
  --scrim: oklch(30% 0.02 152 / 0.45);
}

/* ---------- основа ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh;
  background: var(--bg); color: var(--text);
  font: 400 var(--t-md)/1.5 var(--font);
  font-kerning: normal; font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
svg { display: block; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.tight { font-family: var(--font-tight); }
.label {
  font: 600 var(--t-xs)/1.2 var(--font-tight);
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-3);
}
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.code { font-family: var(--font-code); font-size: 0.86em; overflow-wrap: anywhere; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 46px; padding: 0 var(--s5);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: transparent; color: var(--text);
  font: 600 var(--t-md)/1.2 var(--font-tight); letter-spacing: 0.015em;
  text-decoration: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.btn:hover { background: var(--raised); }
.btn:active { transform: scale(0.985); }
.btn[disabled] { opacity: 0.5; cursor: default; transform: none; }
.btn-primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn-primary:hover { background: var(--text-2); border-color: var(--text-2); }
.btn-danger { border-color: var(--alarm); color: var(--alarm); }
.btn-danger:hover { background: var(--alarm-bg); }
.btn-danger.is-solid { background: var(--alarm); color: var(--bg); }
.btn-danger.is-solid:hover { background: var(--alarm); filter: brightness(1.08); }
.btn-small { min-height: 38px; padding: 0 var(--s4); font-size: var(--t-sm); }
.btn-wide { width: 100%; }
.btn-text {
  min-height: 44px; padding: 0 var(--s2); border: 0; background: none; color: var(--text-2);
  font: 600 var(--t-sm)/1 var(--font-tight); letter-spacing: 0.02em; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong);
}
.btn-text:hover { color: var(--text); }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: var(--radius); background: none; color: var(--text-2);
}
.icon-btn:hover { background: var(--raised); color: var(--text); }

/* ---------- поля ---------- */
.field { display: grid; gap: var(--s2); }
.field > span { font: 600 var(--t-sm)/1.2 var(--font-tight); color: var(--text-2); letter-spacing: 0.02em; }
.input {
  width: 100%; min-height: 46px; padding: var(--s2) var(--s3);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: 1rem;
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
.seg { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  min-height: 38px; padding: 0 var(--s3);
  border: 1px solid var(--line); border-radius: 999px; background: none; color: var(--text-2);
  font: 600 var(--t-sm)/1 var(--font-tight); letter-spacing: 0.02em;
}
.chip:hover { border-color: var(--line-strong); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }

/* ---------- лампи стану: колір, форма і слово разом ---------- */
.lamp { width: 1em; height: 1em; color: var(--text-3); }
.is-ok { --tone: var(--ok); --tone-bg: var(--ok-bg); }
.is-warn { --tone: var(--warn); --tone-bg: var(--warn-bg); }
.is-alarm { --tone: var(--alarm); --tone-bg: var(--alarm-bg); }
.is-calm { --tone: var(--calm); --tone-bg: var(--calm-bg); }
.is-off { --tone: var(--text-3); --tone-bg: var(--raised); }
.is-ok .lamp, .is-warn .lamp, .is-alarm .lamp, .is-calm .lamp, .is-off .lamp { color: var(--tone); }
@keyframes pulse { 50% { opacity: 0.35; } }
.is-alarm.is-live .lamp { animation: pulse 1.5s ease-in-out infinite; }

/* ---------- сторінки входу й прив'язки ---------- */
.gate { display: grid; place-items: center; padding: var(--s5) var(--s5) calc(var(--s7) + env(safe-area-inset-bottom, 0px)); }
.gate-box { width: 100%; max-width: 23rem; display: grid; gap: var(--s5); }
.gate-mark { display: flex; align-items: center; gap: var(--s3); }
.gate-mark svg { width: 44px; height: 44px; }
.gate-mark b { font: 700 var(--t-xl)/1 var(--font-tight); letter-spacing: 0.01em; }
.gate-mark span { display: block; margin-top: 3px; font: 500 var(--t-sm)/1.2 var(--font-tight); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); }
.gate h1 { font: 700 var(--t-xl)/1.15 var(--font-tight); letter-spacing: 0.005em; text-wrap: balance; }
.gate-text { color: var(--text-2); max-width: 34ch; }
.gate-actions { display: grid; gap: var(--s3); }
.gate-msg { min-height: 3em; color: var(--text-2); font-size: var(--t-sm); }
.gate-msg.is-bad { color: var(--alarm); }
.gate-msg.is-good { color: var(--ok); }
.gate-foot { color: var(--text-3); font-size: var(--t-xs); }

/* ---------- каркас застосунку ---------- */
.app { display: grid; grid-template-rows: auto 1fr; min-height: 100dvh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px)); }
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s3);
  padding: calc(var(--s2) + env(safe-area-inset-top, 0px)) var(--s4) var(--s2);
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.top-mark { display: flex; align-items: center; gap: var(--s2); margin-right: auto; min-width: 0; }
.top-mark svg { width: 28px; height: 28px; }
.top-mark b { font: 700 var(--t-lg)/1 var(--font-tight); }
.top-mark span { font: 600 var(--t-xs)/1 var(--font-tight); letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-3); padding-left: var(--s2); border-left: 1px solid var(--line-strong); margin-left: var(--s1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-idle { font: 500 var(--t-xs)/1 var(--font-tight); color: var(--text-3); letter-spacing: 0.04em; white-space: nowrap; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface); border-top: 1px solid var(--line);
}
.nav a {
  position: relative; display: grid; place-content: center; justify-items: center; gap: 3px;
  color: var(--text-3); text-decoration: none;
  font: 600 0.6875rem/1 var(--font-tight); letter-spacing: 0.05em; text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
}
.nav a svg { width: 24px; height: 24px; }
.nav a[aria-current="page"] { color: var(--text); }
.nav a[aria-current="page"]::before { content: ""; position: absolute; top: -1px; left: 22%; right: 22%; height: 2px; background: var(--text); border-radius: 0 0 2px 2px; }
.nav .badge { position: absolute; top: 9px; left: calc(50% + 7px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--alarm); color: var(--bg); font: 700 0.6875rem/17px var(--font); text-align: center; letter-spacing: 0; }

.main { width: 100%; max-width: 46rem; margin: 0 auto; padding: var(--s5) var(--s4) var(--s7); display: grid; gap: var(--s6); align-content: start; }
.view { display: grid; gap: var(--s6); align-content: start; min-width: 0; }
.view > h1 { font: 700 var(--t-xl)/1.1 var(--font-tight); }

/* ---------- рядок стану ---------- */
.status { display: grid; gap: var(--s3); padding: var(--s5); border-radius: var(--radius); background: var(--tone-bg, var(--surface)); }
.status-line { display: grid; grid-template-columns: auto 1fr; gap: var(--s3); align-items: start; }
.status-line .lamp { width: 1.5rem; height: 1.5rem; margin-top: 0.3rem; }
.status-line p { font: 700 var(--t-xl)/1.14 var(--font-tight); letter-spacing: 0.003em; text-wrap: balance; }
.status-more { color: var(--text-2); font-size: var(--t-sm); padding-left: calc(1.5rem + var(--s3)); display: grid; gap: var(--s1); }
.status-more li { color: var(--text); }
.status-actions { display: flex; flex-wrap: wrap; gap: var(--s2); padding-left: calc(1.5rem + var(--s3)); }

/* ---------- розділ, рядки, пари ---------- */
.sec { display: grid; gap: var(--s3); min-width: 0; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); min-height: 28px; }
.sec-note { color: var(--text-2); font-size: var(--t-sm); max-width: 62ch; }
.rows { border-top: 1px solid var(--line); }
.rows > li, .rows > a, .rows > button { border-bottom: 1px solid var(--line); }
.row {
  display: grid; grid-template-columns: auto 1fr auto; gap: var(--s3); align-items: center;
  width: 100%; min-height: 56px; padding: var(--s3) 0;
  background: none; border-width: 0 0 1px; border-style: solid; border-color: var(--line); text-align: left; text-decoration: none; color: inherit;
}
button.row:hover, a.row:hover { background: var(--surface); }
.row .lamp { width: 0.8125rem; height: 0.8125rem; }
.row-main { min-width: 0; display: grid; gap: 2px; }
.row-title { font-weight: 600; line-height: 1.3; }
.row-sub { color: var(--text-2); font-size: var(--t-sm); line-height: 1.35; }
.row-side { color: var(--text-3); font-size: var(--t-sm); text-align: right; white-space: nowrap; }
.row-chev { color: var(--text-3); width: 18px; height: 18px; }
.row.is-new .row-title::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 8px; border-radius: 50%; background: var(--tone, var(--alarm)); vertical-align: 0.12em; }
.kv { display: grid; grid-template-columns: minmax(8.5rem, 34%) 1fr; column-gap: var(--s4); border-top: 1px solid var(--line); }
.kv > dt, .kv > dd { padding: var(--s3) 0; border-bottom: 1px solid var(--line); min-width: 0; }
.kv > dt { color: var(--text-2); font-size: var(--t-sm); }
.kv > dd { font-weight: 500; }
.figs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4) var(--s5); }
.fig b { display: block; font: 700 var(--t-xl)/1 var(--font-tight); }
.fig span { display: block; margin-top: var(--s1); color: var(--text-2); font-size: var(--t-sm); line-height: 1.3; }
.empty { padding: var(--s5) 0; color: var(--text-2); max-width: 46ch; }
.pre { white-space: pre-wrap; font-size: var(--t-md); line-height: 1.5; max-width: 68ch; }

/* ---------- блок керування ---------- */
.plate { display: grid; gap: var(--s4); padding: var(--s4); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.acts { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: var(--s2); }

/* ---------- вікно підтвердження: знизу на телефоні, по центру на широкому ---------- */
.sheet { width: 100%; max-width: 30rem; margin: auto auto 0; padding: 0; border: 0; background: none; color: var(--text); max-height: 92dvh; }
.sheet::backdrop { background: var(--scrim); }
.sheet-box { display: grid; gap: var(--s4); padding: var(--s5) var(--s5) calc(var(--s5) + env(safe-area-inset-bottom, 0px)); background: var(--raised); border: 1px solid var(--line-strong); border-bottom: 0; border-radius: 16px 16px 0 0; overflow-y: auto; max-height: 92dvh; }
.sheet[open] .sheet-box { animation: rise 0.22s var(--ease); }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet h2 { font: 700 var(--t-lg)/1.2 var(--font-tight); text-wrap: balance; }
.sheet-detail { color: var(--text-2); }
.sheet-acts { display: grid; gap: var(--s2); }
.sheet-msg { min-height: 1.5em; font-size: var(--t-sm); color: var(--text-2); }
.sheet-msg.is-bad { color: var(--alarm); }
.sheet-msg.is-good { color: var(--ok); }

.toast { position: fixed; left: var(--s4); right: var(--s4); bottom: calc(var(--nav-h) + var(--s4) + env(safe-area-inset-bottom, 0px)); z-index: 40; margin: 0 auto; max-width: 28rem; padding: var(--s3) var(--s4); border-radius: var(--radius); background: var(--text); color: var(--bg); font-weight: 500; animation: rise 0.2s var(--ease); }

/* ---------- замок ---------- */
.lock { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: var(--s5); background: var(--bg); }

/* ---------- таблиця (на вузькому — картки-рядки) ---------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.table th { text-align: left; padding: var(--s2) var(--s3) var(--s2) 0; font: 600 var(--t-xs)/1.2 var(--font-tight); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); border-bottom: 1px solid var(--line-strong); }
.table td { padding: var(--s3) var(--s3) var(--s3) 0; border-bottom: 1px solid var(--line); vertical-align: top; }
@media (max-width: 639px) {
  .table thead { display: none; }
  .table tr { display: grid; gap: 2px; padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
  .table td { padding: 0; border: 0; }
  .table td[data-h]::before { content: attr(data-h) ": "; color: var(--text-3); }
  .table td:first-child { font-weight: 600; font-size: var(--t-md); }
}

/* ---------- широкий екран: навігація збоку, вміст у дві колонки там, де це має сенс ---------- */
@media (min-width: 960px) {
  .app { grid-template-columns: 13.5rem 1fr; grid-template-rows: auto 1fr; padding-bottom: 0; }
  .top { grid-column: 1 / -1; padding-left: var(--s5); padding-right: var(--s5); }
  .nav { position: sticky; top: 61px; left: auto; right: auto; bottom: auto; align-self: start; height: auto; grid-auto-flow: row; gap: 2px; padding: var(--s5) var(--s3); background: none; border: 0; }
  .nav a { grid-template-columns: 24px 1fr; justify-items: start; place-content: center start; gap: var(--s3); min-height: 46px; padding: 0 var(--s3); border-radius: var(--radius); font-size: var(--t-sm); letter-spacing: 0.06em; }
  .nav a:hover { background: var(--surface); color: var(--text); }
  .nav a[aria-current="page"] { background: var(--raised); }
  .nav a[aria-current="page"]::before { display: none; }
  .nav .badge { position: static; justify-self: end; grid-column: 3; }
  .nav a { grid-template-columns: 24px 1fr auto; }
  .main { max-width: 70rem; margin: 0; padding: var(--s6) var(--s7) var(--s8) var(--s5); }
  .split { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: var(--s7); align-items: start; }
  .status { padding: var(--s6); }
  .status-line p { font-size: var(--t-2xl); line-height: 1.08; }
  .status-line .lamp { width: 1.75rem; height: 1.75rem; margin-top: 0.45rem; }
  .status-more, .status-actions { padding-left: calc(1.75rem + var(--s3)); }
  .sheet { margin: auto; }
  .sheet-box { border-bottom: 1px solid var(--line-strong); border-radius: 16px; }
  .toast { bottom: var(--s5); }
  .figs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media print {
  .top, .nav, .toast, .no-print { display: none !important; }
  .app { display: block; padding: 0; }
  body { background: #fff; color: #000; }
}
