:root {
  color-scheme: dark;
  --page: #101319;
  --sidebar: #14181f;
  --surface: #181d26;
  --raised: #1d2430;
  --line: #2a3342;
  --text: #f1f4fa;
  --muted: #9caac0;
  --accent: #7aaaff;
  --good: #64dfb6;
  --warning: #ffc481;
  --bad: #ffaaa6;
  font: 15px/1.5 Inter, 'Segoe UI', system-ui, sans-serif;
  background: var(--page);
  color: var(--text);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: 24px; }
body { margin: 0; min-width: 280px; }
button, input, textarea { font: inherit; }
button, a, summary { -webkit-tap-highlight-color: transparent; }
button, summary { cursor: pointer; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
button:focus-visible, a:focus-visible, summary:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }
.skip { position: fixed; top: 8px; left: 8px; z-index: 5; transform: translateY(-140%); padding: 10px; background: var(--surface); }
.skip:focus { transform: none; }

.sidebar { position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; width: 224px; padding: 27px 17px 20px; border-right: 1px solid var(--line); background: var(--sidebar); }
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 6px; font-weight: 680; letter-spacing: -.02em; }
.brand small { display: block; margin-top: 1px; color: var(--muted); font-size: 11px; font-weight: 520; letter-spacing: .05em; }
.brand-mark { display: flex; flex: none; align-items: flex-end; justify-content: center; gap: 3px; width: 40px; height: 40px; padding-bottom: 10px; border-radius: 12px; color: #c6dbff; background: #233d66; }
.brand-mark i { display: block; width: 4px; height: 8px; border-radius: 2px; background: currentColor; }
.brand-mark i:nth-child(2) { height: 13px; }
.brand-mark i:nth-child(3) { height: 18px; }
.nav { display: grid; gap: 5px; margin-top: 42px; }
.nav a { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 9px 10px; border-radius: 9px; color: var(--muted); font-size: 14px; font-weight: 560; white-space: nowrap; }
.nav a span { width: 19px; font-size: 18px; line-height: 1; text-align: center; }
.nav a:hover { color: var(--text); background: var(--surface); }
.nav a[aria-current] { color: #bbd4ff; background: #202f48; }
.logout { margin-top: auto; }
.logout .button { width: 100%; }

.workspace { width: min(calc(100% - 224px), 1576px); margin-left: 224px; padding: 36px clamp(24px, 3.2vw, 56px) 48px; }
.heading, .heading-actions, .panel-head, .plot-controls, .chart-foot, .balance, .command-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.heading { margin-bottom: 27px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(29px, 3.5vw, 45px); font-weight: 725; letter-spacing: -.045em; line-height: 1.12; }
.heading p { margin-top: 8px; color: var(--muted); }
.connection { white-space: nowrap; display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 6px 11px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); background: var(--surface); font-size: 13px; font-weight: 650; }
.connection i, .chart-foot i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.connection[data-state='online'] { background: #17352f; color: var(--good); border-color: #2b5449; }
.connection[data-state='offline'], .connection[data-state='error'] { color: var(--warning); }
.button { display: inline-grid; place-items: center; min-height: 42px; padding: 8px 13px; border: 1px solid transparent; border-radius: 9px; color: var(--text); background: var(--raised); font-size: 13px; font-weight: 650; text-align: center; }
.button:hover:not(:disabled) { filter: brightness(1.18); }
.button:disabled { opacity: .46; }
.quiet { border-color: var(--line); }
.refresh { min-width: 42px; padding: 0; font-size: 23px; line-height: 1; }
.danger { border-color: #5e3c41; background: #302228; color: #ffc1bd; }
.primary { background: #8bb5ff; color: #101c31; }
.banner { margin: 0 0 17px; padding: 11px 14px; border: 1px solid #6b533b; border-radius: 10px; color: var(--warning); background: #30291f; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin-bottom: 18px; }
.metric, .panel { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.metric { min-width: 0; padding: 15px 17px; }
.metric p { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 630; color: #c2cbda; }
.metric-icon, .panel-icon, .relay-icon { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 8px; background: #24334c; color: #a7c8ff; font-weight: 640; }
.metric-icon.warm { background: #3c2c33; color: #ffb49b; }
.network-icon { display: flex; align-items: flex-end; justify-content: center; gap: 2px; padding-bottom: 6px; }
.network-icon i { width: 3px; height: 5px; border-radius: 1px; background: currentColor; }
.network-icon i:nth-child(2) { height: 8px; }
.network-icon i:nth-child(3) { height: 11px; }
.metric-value { margin-top: 12px; font-size: clamp(20px, 2.5vw, 34px); line-height: 1.12; letter-spacing: -.045em; font-weight: 690; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric small, .relay small, .balance small { display: block; margin-top: 5px; font-size: 12px; color: var(--muted); }
.metric-signal { display: flex; align-items: baseline; gap: 11px; }
.signal { display: inline-flex; align-items: flex-end; gap: 3px; }
.signal i { width: 4px; height: 5px; background: #3b4659; border-radius: 2px; }
.signal i:nth-child(2) { height: 8px; }
.signal i:nth-child(3) { height: 11px; }
.signal i:nth-child(4) { height: 14px; }
.signal i:nth-child(5) { height: 17px; }
.signal i.active { background: var(--good); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(295px, 1fr); gap: 18px; align-items: start; }
.panel { min-width: 0; padding: 19px 20px; }
.chart-panel, .control-panel { align-self: stretch; }
.panel-head { align-items: flex-start; margin-bottom: 16px; }
.panel-head h2 { font-size: 20px; font-weight: 690; letter-spacing: -.025em; }
.panel-head p { margin-top: 2px; color: var(--muted); font-size: 13px; }
.panel-icon { width: 35px; height: 35px; font-size: 19px; }
.history-dates { margin: -8px 0 12px; }
.history-dates .tool-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.history-dates .tool-form input { min-width: 0; }
.history-dates .tool-form button { justify-self: start; }
.plot-controls { flex-wrap: wrap; margin-bottom: 14px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; background: #141922; }
.segmented button { border: 0; min-height: 32px; padding: 3px 9px; background: transparent; color: var(--muted); border-radius: 7px; white-space: nowrap; font-size: 12px; font-weight: 620; }
.segmented button:hover, .segmented button[aria-pressed='true'] { background: #273750; color: #e0ebff; }
.plot { position: relative; width: 100%; height: clamp(192px, 20vw, 244px); }
.plot canvas { display: block; width: 100%; height: 100%; }
.plot-empty { position: absolute; inset: 0 0 20px 35px; display: grid; place-items: center; margin: 0; padding: 12px; text-align: center; color: var(--muted); }
.plot-tip { position: absolute; top: 8px; right: 8px; pointer-events: none; padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--sidebar); color: var(--text); font-size: 12px; }
.chart-foot { flex-wrap: wrap; margin-top: 11px; font-size: 12px; color: var(--muted); }
.chart-foot i { color: var(--accent); margin-right: 5px; }
.chart-foot b { font-weight: 560; }

.relays { display: grid; gap: 7px; }
.relay { display: grid; grid-template-columns: 34px minmax(0, 1fr) 36px; align-items: center; text-align: left; gap: 10px; width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; min-height: 53px; background: #171c25; color: var(--text); font-size: 14px; font-weight: 640; }
.relay:hover:not(:disabled) { border-color: #526886; background: var(--raised); }
.relay-icon { width: 33px; height: 33px; color: #a0b4d1; background: #242b38; font-size: 20px; }
.relay small { margin-top: 0; font-weight: 500; }
.switch { display: inline-flex; align-items: center; padding: 3px; width: 36px; height: 21px; border-radius: 99px; background: #364253; }
.switch::before { content: ''; display: block; width: 15px; height: 15px; border-radius: 50%; background: #aab8cd; }
.relay[aria-pressed='true'] .switch { justify-content: flex-end; background: #245647; }
.relay[aria-pressed='true'] .switch::before, .relay[aria-pressed='true'] .relay-icon { color: var(--good); }
.relay[aria-pressed='true'] .switch::before { background: var(--good); }
.relay[data-pending] .switch { outline: 1px dashed var(--warning); outline-offset: 2px; }
.command-row { margin-top: 12px; }
.command-row > button { margin-left: auto; }
.feedback, .muted { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.feedback[data-tone='good'] { color: var(--good); }
.feedback[data-tone='bad'] { color: var(--bad); }
.feedback[data-tone='pending'] { color: var(--warning); }

.events { margin: 0; padding: 0; list-style: none; max-height: 284px; overflow: auto; scrollbar-color: #485a73 transparent; }
.events li { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 53px; padding: 7px 3px; border-top: 1px solid var(--line); }
.events li:first-child { border-top: 0; }
.event-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: #222f43; color: #a7c8ff; }
.event-text { min-width: 0; overflow-wrap: anywhere; }
.event-text strong, .event-text small { display: block; }
.event-text strong { font-size: 13px; }
.event-text small, .events time { color: var(--muted); font-size: 12px; }
.events time { text-align: right; }
.balance { padding: 10px 11px; border: 1px solid var(--line); border-radius: 10px; background: #171c25; }
.balance span, .balance strong { display: block; overflow-wrap: anywhere; }
.balance span { color: var(--muted); font-size: 12px; }
.balance strong { font-size: 17px; }
.balance small { margin-top: 0; }
#balance-feedback, .tool .feedback { margin: 6px 0; }
.tool { border-bottom: 1px solid var(--line); }
.tool:last-child { border-bottom: 0; }
.tool summary { padding: 10px 0; min-height: 43px; color: #d4ddec; font-size: 13px; font-weight: 620; }
.tool-form { display: grid; gap: 9px; margin: 0 0 10px; }
.tool-form label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.tool-form input, .tool-form textarea, .tool-form select { width: 100%; min-width: 0; min-height: 41px; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: #121720; color: var(--text); font: inherit; font-size: 16px; }
.tool-form textarea { resize: vertical; }
.diagnostics dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px; margin: 0 0 9px; font-size: 13px; }
.diagnostics dt { color: var(--muted); }
.diagnostics dd { margin: 0; overflow-wrap: anywhere; }
.terminal-output { max-height: 19rem; overflow: auto; margin: 10px 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--page); color: var(--text); font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.position-panel #position-detail { margin: -6px 0 10px; }

.position-panel { margin-top: 18px; }
.position-panel .panel-head { align-items: center; }
.position-map { z-index: 0; height: clamp(230px, 45vh, 440px); border: 1px solid var(--line); border-radius: 10px; background: #283343; }
.position-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.position-actions select { min-height: 38px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); color: var(--text); font: inherit; font-size: 13px; }
#position-yandex { display: block; width: 100%; }
.position-external { margin-top: 10px; }
.leaflet-attribution-flag { display: none !important; }
#service-start { margin: 6px 0 8px; }
.position-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; padding-top: 10px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.position-meta span:first-child { color: var(--text); }
.position-panel .muted { margin-top: 8px; }
.login-page { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 20px; }
.login-panel { width: min(100%, 390px); padding: clamp(20px, 5vw, 32px); }
.login-panel .brand { padding: 0; }
.login-panel h1 { margin: 22px 0 18px; font-size: 29px; }
.login-panel form { display: grid; gap: 7px; }
.login-panel label { color: var(--muted); font-size: 13px; }
.login-panel input { min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--page); color: var(--text); }
.login-panel .button { margin-top: 10px; background: #8bb5ff; color: #101c31; }

dialog { width: min(420px, calc(100% - 32px)); max-width: none; padding: 0; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
dialog::backdrop { background: #080b12b8; }
.confirm-form { display: grid; gap: 13px; padding: 20px; }
.confirm-form h2 { font-size: 21px; }
.confirm-form p { color: var(--muted); overflow-wrap: anywhere; }
.confirm-form > div { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

@media (max-width: 1120px) {
  .sidebar { width: 180px; padding-inline: 12px; }
  .workspace { margin-left: 180px; width: calc(100% - 180px); padding-inline: 22px; }
  .dashboard-grid { grid-template-columns: minmax(0, 1.35fr) minmax(275px, 1fr); }
}
@media (max-width: 890px) {
  .sidebar { position: static; width: auto; padding: max(12px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left)); display: grid; grid-template-columns: minmax(0, 1fr) auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0; }
  .nav { grid-column: 1 / -1; display: flex; overflow-x: auto; margin: 10px -5px 6px; }
  .logout { grid-row: 1; grid-column: 2; }
  .logout .button { min-height: 36px; }
  .workspace { width: auto; margin: 0; padding: 24px max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }
}
@media (max-width: 660px) {
  .heading { flex-wrap: wrap; margin-bottom: 18px; }
  .heading p { margin-top: 4px; font-size: 14px; }
  .heading-actions { width: 100%; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-bottom: 12px; }
  .metric { padding: 11px; }
  .metric-value { font-size: 25px; margin-top: 8px; }
  .metric-icon { width: 23px; height: 23px; }
  .dashboard-grid { display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
  .control-panel { order: -1; }
  .panel { padding: 14px; }
  .segmented button { min-height: 38px; }
  .nav { gap: 2px; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { font-size: 12px; padding-inline: 6px; gap: 4px; }
  .nav a span { width: 15px; font-size: 15px; }
}
