:root {
  --bg: #f4f5f7; --card: #fff; --text: #171c26; --muted: #5f6b7c; --line: #e3e6eb; --soft: #f0f2f5;
  --red: #c4320a; --red-bg: #fff1ec; --red-line: #f9c2b0;
  --amber: #a15c07; --amber-bg: #fff8e6; --amber-line: #f6d79b;
  --green: #08744a; --green-bg: #eafaf1; --green-line: #a6e4c4;
  --blue: #1757c2; --blue-bg: #edf4ff; --blue-line: #b6d0fb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --primary: #c4320a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1016; --card: #161a22; --text: #e8eaee; --muted: #9aa4b2; --line: #272d38; --soft: #1f242e;
    --red: #ff8a66; --red-bg: #2c1610; --red-line: #6b2a17;
    --amber: #f5b544; --amber-bg: #2a2010; --amber-line: #5e4515;
    --green: #4bd394; --green-bg: #0f2a1e; --green-line: #1d5a3c;
    --blue: #8ab8ff; --blue-bg: #13233d; --blue-line: #2a4a7d;
    --shadow: none;
    --primary: #d43d1a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); min-height: 1.2em; margin: 0; }
h1, h2, h3, p { margin: 0; }

/* ---------- header and navigation ---------- */
.header { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line); }
.header-inner { max-width: 1120px; margin: 0 auto; display: flex; align-items: center; gap: 20px; padding: 8px 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; }
.nav a { position: relative; display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.nav a:hover { text-decoration: none; color: var(--text); background: var(--soft); }
.nav a.active { color: var(--text); background: var(--soft); }
.nav svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-badge { position: absolute; top: 4px; left: 24px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--primary); color: #fff; font: 700 11px/18px system-ui, sans-serif; font-style: normal; text-align: center; }
.user { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); }

main { max-width: 1120px; margin: 0 auto; padding: 16px 16px 48px; }

@media (max-width: 760px) {
  .header-inner { padding: 10px 16px; }
  .user { display: none; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; justify-content: space-around; gap: 0;
    background: var(--card); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .nav a { flex: 1; flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 11px; border-radius: 10px; }
  .nav a.active { background: none; color: var(--red); }
  .nav svg { width: 24px; height: 24px; }
  .nav-badge { top: 2px; left: calc(50% + 6px); }
  main { padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); }
}

/* ---------- page structure ---------- */
.page-title { font-size: 22px; font-weight: 700; margin: 4px 0 4px; }
.lead { margin-bottom: 8px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 24px 2px 8px; font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.section-title a, .section-title .link { font-size: 14px; letter-spacing: 0; text-transform: none; font-weight: 600; }
.home-grid { display: grid; gap: 0 20px; }
@media (min-width: 920px) { .home-grid { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; } }
.stack > * + * { margin-top: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.empty { color: var(--muted); }
.back { display: inline-block; margin: 2px 0 12px; font-weight: 600; }

/* ---------- status banner and notices ---------- */
.banner { display: flex; align-items: center; gap: 14px; padding: 16px 18px; border-radius: 16px; border: 1px solid; margin-bottom: 4px; }
.banner .icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; font-weight: 800; font-size: 20px; color: #fff; }
.banner .big { font-size: 19px; font-weight: 700; line-height: 1.3; }
.banner.green { background: var(--green-bg); border-color: var(--green-line); } .banner.green .icon { background: var(--green); }
.banner.amber { background: var(--amber-bg); border-color: var(--amber-line); } .banner.amber .icon { background: var(--amber); }
.banner.red { background: var(--red-bg); border-color: var(--red-line); } .banner.red .icon { background: var(--red); }
.notice { padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--soft); margin-bottom: 10px; }
.notice.red { background: var(--red-bg); border-color: var(--red-line); }
.notice.amber { background: var(--amber-bg); border-color: var(--amber-line); }

/* ---------- chips and dots ---------- */
.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--soft); color: var(--muted); }
.chip.red { background: var(--red-bg); color: var(--red); }
.chip.amber { background: var(--amber-bg); color: var(--amber); }
.chip.green { background: var(--green-bg); color: var(--green); }
.chip.blue { background: var(--blue-bg); color: var(--blue); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; background: var(--muted); }
.dot.red { background: var(--red); } .dot.green { background: var(--green); } .dot.amber { background: var(--amber); } .dot.blue { background: var(--blue); }

/* ---------- alert card ---------- */
.alert { border-left: 5px solid var(--line); }
.alert.red { border-left-color: var(--red); }
.alert.amber { border-left-color: var(--amber); }
.alert.blue { border-left-color: var(--blue); }
.alert.green { border-left-color: var(--green); }
.alert-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.alert h3 { font-size: 18px; margin-top: 8px; line-height: 1.3; }
.title-link { color: inherit; display: block; }
.title-link:hover { text-decoration: none; }
.title-link:hover h3 { text-decoration: underline; }
.chev { color: var(--muted); font-weight: 400; }
.status-text { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--soft); font-weight: 500; }
.devices { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.devices li { display: flex; align-items: baseline; gap: 8px; }
.devices .dot { position: relative; top: 1px; }
.dev-name { overflow-wrap: anywhere; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-align: center; }
.btn:hover { background: var(--soft); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(.95); }
.btn.dark { background: var(--text); border-color: var(--text); color: var(--card); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { border: 0; background: none; padding: 0; color: var(--blue); font: inherit; font-weight: 600; cursor: pointer; }
.link.danger { color: var(--red); }
.buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
@media (max-width: 760px) { .alert .buttons .btn { flex: 1 1 140px; } }

/* ---------- lists ---------- */
.list { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); color: inherit; }
.item:last-child { border-bottom: none; }
a.item:hover { background: var(--soft); text-decoration: none; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 650; overflow-wrap: anywhere; }
.item-sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; text-align: right; }
.item .buttons { margin-top: 8px; }
.item > form { flex: 1; }
details.item { display: block; }
details.item > summary { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; list-style: none; }
details.item > summary::-webkit-details-marker { display: none; }
pre.body { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--soft); padding: 10px 12px; border-radius: 10px; margin: 10px 0 6px; font: 12px/1.5 ui-monospace, Consolas, monospace; }

/* ---------- call order ---------- */
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; gap: 12px; }
.steps li + li { margin-top: 2px; }
.step-num { width: 28px; height: 28px; border-radius: 50%; background: var(--soft); border: 1px solid var(--line); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.step-names { font-weight: 650; padding-top: 3px; }
.step-wait { color: var(--muted); font-size: 13px; padding-bottom: 10px; }
.step-edit { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.step-head .link { margin-left: auto; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.pill { position: relative; }
.pill input { position: absolute; left: 0; top: 0; width: 1px; height: 1px; min-height: 0; opacity: 0; pointer-events: none; }
.pill span { display: inline-flex; align-items: center; min-height: 38px; padding: 6px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); font-weight: 600; cursor: pointer; }
.pill input:checked + span { background: var(--text); border-color: var(--text); color: var(--card); }
.pill input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- system and stats ---------- */
.checks { display: grid; gap: 12px; }
.check-row { display: flex; gap: 10px; align-items: flex-start; }
.check-row .dot { margin-top: 6px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.stats b { display: block; font-size: 24px; line-height: 1.2; }
.stats span { color: var(--muted); font-size: 13px; }

/* ---------- timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 88px 12px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: none; }
.tl-time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.tl-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: var(--muted); }
.tl-dot.red { background: var(--red); } .tl-dot.green { background: var(--green); } .tl-dot.blue { background: var(--blue); } .tl-dot.amber { background: var(--amber); }

/* ---------- forms ---------- */
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 11px; width: 100%; min-height: 42px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-line); border-color: var(--blue); }
textarea { min-height: 140px; font: 13px/1.5 ui-monospace, Consolas, monospace; }
.field { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
.form-grid { display: grid; gap: 12px; }
@media (min-width: 640px) { .form-grid.two { grid-template-columns: 1fr 1fr; } }
.form-grid .wide, .form-grid .buttons, .form-grid details { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text); }
.check input { width: 20px; height: 20px; min-height: 0; }
.with-unit { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.with-unit input { width: 84px; }
.phone-row { display: flex; gap: 8px; }
.phone-row select { width: auto; flex: none; }
details > summary { cursor: pointer; font-weight: 600; }
.card > details > summary { color: var(--blue); }
.card > details[open] > summary { margin-bottom: 12px; }
.inset { background: var(--soft); border-radius: 12px; padding: 12px; }

/* ---------- segmented tabs and filters ---------- */
.segmented { display: flex; gap: 2px; padding: 3px; margin: 10px 0 12px; background: var(--soft); border: 1px solid var(--line); border-radius: 12px; }
.segmented button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: none; color: var(--muted); font: inherit; font-weight: 650; cursor: pointer; }
.segmented button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.filters button { min-height: 34px; padding: 4px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--muted); font: inherit; font-size: 13px; font-weight: 650; cursor: pointer; }
.filters button.on { background: var(--text); border-color: var(--text); color: var(--card); }

/* ---------- login and toast ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; padding: 24px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30; max-width: calc(100vw - 32px); padding: 11px 18px; border-radius: 12px; background: var(--text); color: var(--card); font-weight: 600; box-shadow: 0 6px 24px rgba(0, 0, 0, .2); }
.toast.err { background: var(--primary); color: #fff; }
@media (max-width: 760px) { .toast { bottom: calc(88px + env(safe-area-inset-bottom)); } }
.signout { margin-top: 28px; }

/* ---------- yes/no box ---------- */
.ask { width: min(420px, calc(100vw - 32px)); padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--text); box-shadow: 0 12px 40px rgba(0, 0, 0, .3); }
.ask::backdrop { background: rgba(0, 0, 0, .45); }
.ask p { font-size: 16px; }
.ask .buttons { margin-top: 18px; }
.ask .btn { flex: 1; }
