:root {
  --bg: #0b0f17;
  --panel: #141b29;
  --panel-2: #1b2435;
  --line: #232e44;
  --text: #e6ecf5;
  --muted: #93a1b8;
  --accent: #4f9dff;
  --ok: #3ddc97;
  --bad: #ff6b6b;
  --warn: #f0b429;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: radial-gradient(1200px 600px at 80% -10%, #16203a, var(--bg) 55%); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 0.2rem 0; }
.brand { margin: 0; letter-spacing: 0.08em; font-size: 0.78rem; color: var(--muted); }
.brand span { color: var(--accent); }

.login {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.5rem;
}
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.75rem;
}
.login-card h1 { margin: 0; font-size: 1.8rem; }
.account-layer { position: fixed; inset: 0; z-index: 40; background: rgba(15, 16, 24, 0.72); }
.qr { width: 180px; height: 180px; background: #fff; border-radius: 8px; }
.secret { font-family: ui-monospace, monospace; word-break: break-all; }
.login-card label, .field { display: grid; gap: 0.3rem; font-size: 0.86rem; color: var(--muted); }
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}
textarea { min-height: 140px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(122, 162, 247, 0.45); border-color: var(--accent); }

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #0b0f17; border-color: transparent; font-weight: 650; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: default; }

.app { min-height: 100%; display: flex; flex-direction: column; }
.top {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 23, 0.92);
  position: sticky;
  top: 0;
  z-index: 20;
}
.top-brand { display: flex; align-items: center; gap: 0.6rem; flex: 0 0 auto; }
.top-brand .brand { white-space: nowrap; }
.top-brand strong { display: block; font-size: 1.05rem; white-space: nowrap; }
.top-logo { width: 36px; height: 36px; border-radius: 8px; object-fit: contain; background: #0b0f17; flex: 0 0 auto; }
.logo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.7rem; }
.logo-preview { width: 64px; height: 64px; border-radius: 12px; object-fit: contain; background: #0b0f17; border: 1px solid var(--line); }
.tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; flex: 1; }
.tabs button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  color: var(--muted);
}
.tabs button.active { color: var(--text); border-color: rgba(79, 157, 255, 0.55); background: rgba(79, 157, 255, 0.2); }
.top-user { display: flex; align-items: center; gap: 0.45rem; flex: 0 0 auto; color: var(--muted); font-size: 0.88rem; }
.who {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 18rem;
  padding: 0.18rem 0.28rem 0.18rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  white-space: nowrap;
}
.who-name {
  min-width: 0;
  color: var(--text);
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
}
.who-role {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
  line-height: 1.2;
  padding: 0.16rem 0.5rem;
  border-radius: 999px;
  background: rgba(11, 15, 23, 0.72);
  border: 1px solid var(--line);
}

#main { padding: 0.75rem 1rem 1rem; display: grid; gap: 0.75rem; align-content: start; }
.api-entry { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.8rem; }
.api-url {
  border: 1px solid rgba(79, 157, 255, 0.45);
  background: rgba(79, 157, 255, 0.1);
  color: var(--accent);
  border-radius: 8px;
  padding: 0.35rem 0.65rem;
  font-family: ui-monospace, monospace;
  font-size: 0.84rem;
}
.api-page { display: grid; gap: 0.75rem; }
.api-head { display: flex; justify-content: space-between; gap: 0.8rem; align-items: flex-start; }
.api-head .btn { flex: 0 0 auto; white-space: nowrap; }
.api-head h2 { margin-top: 0; }
.api-base { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; margin: 0.2rem 0 0.6rem; }
.api-base code, .api-ep code {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.82rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.12rem 0.4rem;
}
.api-ep { display: grid; gap: 0.4rem; padding: 0.8rem 0 0.15rem; border-top: 1px solid var(--line); }
.api-ep p { margin: 0; }
.api-ep-line { display: flex; flex-wrap: wrap; gap: 0.4rem 0.55rem; align-items: center; }
.api-method {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.42rem;
  border-radius: 4px;
}
.api-method.get { color: var(--ok); background: rgba(61, 220, 151, 0.14); }
.api-method.post { color: var(--accent); background: rgba(79, 157, 255, 0.14); }
.api-method.put, .api-method.patch { color: var(--warn); background: rgba(240, 180, 41, 0.14); }
.api-method.delete { color: #ff8b8b; background: rgba(255, 107, 107, 0.14); }
.api-access { color: var(--muted); font-size: 0.78rem; }
.api-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.api-grid .api-block:only-child { grid-column: 1 / -1; }
.api-block {
  min-width: 0;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: rgba(11, 15, 23, 0.55);
  border: 1px solid var(--line);
}
.api-block h3 { margin: 0 0 0.3rem; font-size: 0.7rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.api-block pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: ui-monospace, monospace; font-size: 0.78rem; line-height: 1.45; }
.api-page > .panel > .api-block { margin-top: 0.5rem; }
@media (max-width: 860px) {
  .api-grid { grid-template-columns: 1fr; }
  .api-head { flex-wrap: wrap; }
}
.card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem 1rem;
}
.row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: end; }
.stats-layout { display: grid; grid-template-columns: minmax(12rem, 16rem) minmax(0, 1fr); gap: 0.8rem; align-items: start; }
.stats-list { display: grid; gap: 0.35rem; align-content: start; }
.stats-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel, rgba(20, 27, 41, 0.96));
  color: inherit;
  cursor: pointer;
}
.stats-item.is-on { border-color: rgba(79, 157, 255, 0.7); background: rgba(79, 157, 255, 0.14); }
.stats-item .dash-dot.is-on { background: var(--ok); }
.stats-item .dash-dot.is-off { background: var(--bad); }
.stats-body { display: grid; gap: 0.75rem; min-width: 0; }
@media (max-width: 800px) {
  .stats-layout { grid-template-columns: 1fr; }
}
.stats-bar { align-items: center; }
.stats-bar select {
  width: auto;
  min-width: 14rem;
  height: 2.4rem;
  margin: 0;
  padding: 0.35rem 2rem 0.35rem 0.75rem;
  background-color: var(--panel);
  color: var(--text);
  color-scheme: dark;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%2393a1b8' d='M1 1.2 6 6.8 11 1.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 0.7rem;
}
.stats-bar select:disabled { opacity: 0.75; }
.vpn-card { display: grid; gap: 0.75rem; }
.vpn-card.vpn-service-collapsed > *:not(.vpn-section-head) { display: none; }
.vpn-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
}
.vpn-section-head > h3 {
  margin: 0;
  flex: 1 1 100%;
  order: 3;
  font-size: 1.15rem;
}
.vpn-section-head .vpn-service-toggle { order: 1; margin: 0; }
.vpn-section-head .vpn-service-toggle.is-locked { opacity: 0.55; cursor: not-allowed; }
.vpn-section-head .vpn-service-status { order: 2; font-size: 0.82rem; color: var(--muted); white-space: nowrap; }
.vpn-svc-on { color: var(--ok); }
.vpn-svc-off { color: var(--muted); font-weight: 600; }
.vpn-status { margin: 0; font-size: 0.92rem; color: var(--muted); }
.vpn-status-ok { color: var(--ok); }
.vpn-status-wait { color: var(--accent); }
.vpn-busy-bar { display: grid; gap: 0.35rem; max-width: 28rem; }
.vpn-busy-track {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: #363b54;
  overflow: hidden;
}
.vpn-busy-fill {
  position: absolute;
  height: 100%;
  width: 38%;
  border-radius: 999px;
  background: var(--accent);
  animation: update-indet 1.15s ease-in-out infinite;
}
.vpn-busy-label { margin: 0; color: var(--muted); font-size: 0.84rem; }
.vpn-card.is-busy .btn,
.vpn-card.is-busy .gamepad-toggle-input { pointer-events: none; opacity: 0.65; }
.vpn-status-idle { color: var(--muted); }
.vpn-status-bad { color: #f7768e; }
.vpn-peers { display: flex; flex-direction: column; gap: 0.55rem; }
.vpn-peers-title { margin: 0.2rem 0 0; font-size: 1rem; }
.vpn-peer-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}
.vpn-peer-host { font-size: 0.84rem; font-weight: 650; margin: 0; word-break: break-all; }
.vpn-peer-fields { display: flex; flex-direction: column; gap: 0.3rem; width: 100%; }
.vpn-peer-row {
  display: grid;
  grid-template-columns: minmax(8rem, max-content) minmax(0, 1fr);
  align-items: baseline;
  gap: 0.75rem;
  font-size: 0.82rem;
}
.vpn-peer-row .k { color: var(--muted); font-weight: 500; }
.vpn-peer-row .v {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: right;
  word-break: break-word;
}
.vpn-peer-card > .btn { align-self: flex-start; margin: 0.1rem 0 0; }
.vpn-peers-table-wrap { overflow-x: auto; }
.vpn-peers-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.vpn-peers-table th, .vpn-peers-table td {
  padding: 0.45rem 0.55rem;
  text-align: left;
  border: 1px solid var(--line);
  vertical-align: middle;
}
.vpn-peers-table th { background: var(--panel-2); color: var(--accent); font-weight: 650; }
.vpn-key-cell, .vpn-val-info { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.vpn-val-ok { color: var(--ok); font-weight: 650; }
.vpn-val-info { color: #7dcfff; }
.vpn-meta { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; margin: 0; color: var(--muted); font-size: 0.84rem; }
.vpn-key {
  margin: 0;
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  word-break: break-all;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}
.vpn-form { display: grid; gap: 0.65rem; }
.allow-form {
  display: grid;
  grid-template-columns: minmax(8rem, 1.4fr) minmax(8rem, 1fr) 6.5rem auto;
  gap: 0.65rem;
  align-items: end;
  margin-top: 0.85rem;
}
.allow-form .vpn-actions { grid-column: 1 / -1; }
.allow-days { width: 100%; }
.allow-expired { color: var(--bad); }
@media (max-width: 800px) {
  .allow-form { grid-template-columns: 1fr; }
}
.vpn-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; }
.vpn-fields.one { grid-template-columns: minmax(0, 28rem); }
.vpn-fields .field { min-width: 0; }
.vpn-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.vpn-form textarea { width: 100%; font-family: ui-monospace, monospace; font-size: 0.82rem; line-height: 1.45; }
.vpn-form a.btn, .vpn-peers-table a.btn { text-decoration: none; display: inline-flex; width: fit-content; margin-right: 0.35rem; }
.wg-server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0.75rem 1rem;
  align-items: end;
}
.wg-server-form { display: grid; gap: 0.75rem; }
.wg-server .vpn-status { display: grid; gap: 0.2rem; }
.wg-status-detail { color: var(--muted); font-size: 0.82rem; }
.wg-toggle { margin: 0; }
.wg-lan-hint { margin: 0; font-size: 0.82rem; }
.wg-peer-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}
.wg-peer-form label { flex: 1 1 14rem; }
.wg-peer-form .btn { margin-bottom: 0.05rem; }
.wg-advanced { justify-self: start; }
.wg-advanced-block { display: grid; gap: 0.35rem; }
.wg-server input[readonly] { opacity: 0.85; }
.grow { flex: 1; min-width: 180px; }
.stats { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.stat {
  background: var(--panel-2);
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  min-width: 88px;
}
.stat b { display: block; font-size: 1.25rem; }
.stat span { color: var(--muted); font-size: 0.75rem; }

.list { display: grid; gap: 0.55rem; }
.board {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
}
.board .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.board .dot.on { background: var(--ok); }
.board .dot.bad { background: var(--bad); }
.board .dot.warn { background: var(--warn); }
.board h3 { margin: 0 0 0.15rem; font-size: 1rem; }
.board-full {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.75rem;
  align-items: stretch;
}
.board-top {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  gap: 0.65rem 0.9rem;
  align-items: center;
}
.board-top h3 { margin: 0; }
.board-top .meta { margin: 0.1rem 0 0; }
.board-top .actions { align-items: center; }
.edit-form { align-items: center; margin: 0; }
.edit-form input,
.edit-form select,
.edit-form .btn,
.edit-form .pill {
  height: 2.35rem;
  margin: 0;
  box-sizing: border-box;
}
.edit-form .pill {
  display: inline-flex;
  align-items: center;
  padding: 0 0.2rem;
  white-space: nowrap;
}
.edit-form input[name="port"] { width: 5.5rem; }
.edit-form input[name="name"] { width: 9rem; }
.edit-form input[name="host"] { width: 11rem; }
.edit-form select { width: auto; min-width: 7.5rem; }
.access-panel { display: flex; flex-direction: column; gap: 1.15rem; }
.access-panel > h2,
.access-panel > p { margin: 0; }
.user-row {
  align-items: center;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  gap: 0.85rem 1rem;
  padding: 1rem 1.1rem;
}
.user-row > div:nth-child(2) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem 1rem;
}
.user-row h3 { margin: 0; min-width: 6rem; flex: 0 0 auto; }
.user-row > div:nth-child(2) > select {
  width: 11.5rem;
  min-width: 11.5rem;
  flex: 0 0 11.5rem;
  margin: 0;
  padding: 0.4rem 2rem 0.4rem 0.7rem;
  background-color: var(--panel);
  color: var(--text);
  color-scheme: dark;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%2393a1b8' d='M1 1.2 6 6.8 11 1.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 0.7rem;
}
.user-pass {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}
.user-pass input { width: 9.5rem; flex: 0 0 auto; background-color: var(--panel); }
.user-pass .btn { white-space: nowrap; flex: 0 0 auto; }
.user-row .muted,
.user-row .user-groups {
  flex: 1 1 100%;
  margin: 0.15rem 0 0;
  padding-top: 0.15rem;
}
#access-group-form { align-items: end; gap: 0.85rem; margin: 0; }
#access-group-form .btn { white-space: nowrap; margin-bottom: 0.05rem; }
.role-matrix { display: grid; gap: 0.55rem; }
.role-matrix h3, .role-builder h3 { margin: 0.4rem 0 0; font-size: 1rem; }
.role-matrix > .role-save, .role-create > .btn, .role-card .btn { justify-self: start; width: auto; }
.role-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.role-table th, .role-table td {
  border: 1px solid var(--line);
  padding: 0.4rem 0.55rem;
  text-align: left;
  vertical-align: middle;
}
.role-table th { color: var(--accent); background: var(--bg); }
.role-table select, .role-mini select, .role-card select, #user-form select {
  width: 100%;
  min-width: 0;
  padding: 0.4rem 1.8rem 0.4rem 0.65rem;
  background-color: var(--panel);
  color: var(--text);
  color-scheme: dark;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%2393a1b8' d='M1 1.2 6 6.8 11 1.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  background-size: 0.7rem;
}
.role-builder, .role-create, .role-card { display: grid; gap: 0.55rem; }
.role-mini {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.5rem;
}
.role-card {
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}
.role-card.is-default { border-color: rgba(79, 157, 255, 0.35); }
.role-default-name { margin: 0; display: flex; align-items: center; gap: 0.45rem; }
.role-card select:disabled { opacity: 0.7; }
.user-groups { align-items: center; gap: 0.55rem 0.75rem; }
.role-table select:disabled { opacity: 0.7; }
.meta { color: var(--muted); font-size: 0.82rem; display: flex; flex-wrap: wrap; gap: 0.45rem 0.8rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.35rem; justify-content: flex-end; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--text);
  font-size: 0.88rem;
}
.pill input { width: 1rem; height: 1rem; accent-color: var(--accent); }

.grid-wall {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.7rem;
}
.vcard { display: grid; gap: 0.65rem; }
.vcard header { display: flex; justify-content: space-between; gap: 0.5rem; align-items: center; }
.vcard > strong { font-size: 0.95rem; }
.stat-list { display: grid; gap: 0.35rem; }
.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.38rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
.stat-row > span { color: var(--muted); font-size: 0.8rem; }
.pill-status {
  font-size: 0.74rem;
  font-weight: 650;
  line-height: 1.2;
  padding: 0.16rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: transparent;
}
.pill-status.ok { color: var(--ok); border-color: rgba(61, 220, 151, 0.45); background: rgba(61, 220, 151, 0.12); }
.pill-status.bad { color: #ff8b8b; border-color: rgba(255, 107, 107, 0.5); background: rgba(255, 107, 107, 0.12); }
.pill-status.info { color: var(--accent); border-color: rgba(79, 157, 255, 0.45); background: rgba(79, 157, 255, 0.12); }
.badge {
  font-size: 0.72rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  color: var(--muted);
}
.kv, .state-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 0.45rem; }
.state-cell {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(11, 15, 23, 0.45);
}
.state-cell span { color: var(--muted); font-size: 0.78rem; }
.state-cell b { font-size: 0.92rem; text-align: right; }
.state-cell b.ok { color: var(--ok); }
.state-cell b.bad { color: #ff8b8b; }
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.chart-card { position: relative; }
.chart-card canvas.chart-plot {
  display: block;
  width: 100%;
  height: 188px;
  border-radius: 6px;
  cursor: crosshair;
  background: #0d1018;
}
.chart-overlay {
  position: absolute;
  pointer-events: none;
  border-radius: 6px;
}
.chart-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  min-width: 8rem;
  max-width: 16rem;
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  background: rgba(13, 16, 24, 0.95);
  border: 1px solid rgba(86, 95, 137, 0.55);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  font-size: 0.72rem;
  line-height: 1.35;
  color: #c0caf5;
}
.chart-tooltip-time { margin-bottom: 0.25rem; font-weight: 700; color: #a9b1d6; }
.chart-tooltip-row { display: flex; align-items: center; gap: 0.35rem; }
.chart-tooltip-dot { width: 8px; height: 8px; border-radius: 2px; flex: 0 0 auto; }
.chart-tooltip-name { flex: 1; color: #a9b1d6; }
.chart-tooltip-val { font-weight: 700; color: #e8ecff; }
.event-log { max-height: 280px; overflow: auto; display: grid; gap: 0.35rem; }
@media (max-width: 860px) { .charts { grid-template-columns: 1fr; } }
.kv span, .state-cell span { color: var(--muted); }

.dash { display: grid; gap: 0.55rem; }
.dash-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.8rem;
  padding: 0.4rem 0.55rem;
  background: rgba(11, 15, 23, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.dash-views { display: flex; gap: 0.3rem; }
.dash-views .btn.is-on { border-color: rgba(79, 157, 255, 0.55); background: rgba(79, 157, 255, 0.2); color: var(--text); }
.dash-stats { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.dash-stats .stat { min-width: 64px; padding: 0.28rem 0.5rem; }
.dash-stats .stat b { font-size: 1rem; }
.dash-hint { margin-left: auto; font-size: 0.78rem; }
.map-wrap { position: relative; min-height: 520px; height: 100%; }
.map-layers-wrap { position: absolute; top: 10px; right: 10px; z-index: 1000; }
.map-draw {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-width: calc(100% - 20px);
  padding: 0.4rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(11, 15, 23, 0.92);
}
.map-draw input { width: 9rem; }
.map-draw .btn.is-on { border-color: rgba(79, 157, 255, 0.55); background: rgba(79, 157, 255, 0.2); }
.scene-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
.scene-row span { flex: 1; min-width: 4rem; font-size: 0.84rem; }
.scene-kind {
  flex: 0 0 auto;
  min-width: 0;
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  color: var(--accent);
  border: 1px solid rgba(79, 157, 255, 0.4);
  border-radius: 999px;
  padding: 0.08rem 0.45rem;
  background: rgba(79, 157, 255, 0.12);
}
.scene-row .btn { flex: 0 0 auto; padding: 0.28rem 0.55rem; }
.scene-row select { max-width: 8rem; height: 2rem; }
.route-num { background: transparent; border: 0; box-shadow: none; color: #e6ecf5; font-weight: 700; }
.map-layers-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  min-width: 11.5rem;
  padding: 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(11, 15, 23, 0.98);
  box-shadow: var(--shadow);
}
.map-layers-menu[hidden] { display: none !important; }
.map-layers-title {
  margin: 0.15rem 0.35rem 0.3rem;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #7a879c;
}
.map-layers-item {
  display: block;
  width: 100%;
  margin: 0 0 0.15rem;
  padding: 0.38rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 650;
  text-align: left;
}
.map-layers-item:hover { background: rgba(79, 157, 255, 0.12); }
.map-layers-item.is-active { border-color: rgba(79, 157, 255, 0.55); background: rgba(79, 157, 255, 0.2); }
.map-layers-hint { margin: 0.4rem 0.35rem 0.15rem; font-size: 0.68rem; line-height: 1.35; color: #7a879c; }
.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 0.7rem;
  min-height: calc(100vh - 168px);
}
.layout.map-only, .layout.is-map, .layout.is-wall, .layout.is-video { grid-template-columns: 1fr; }
.layout.is-wall .dash-stage { display: none; }
.layout.is-video .dash-stage { display: flex; }
.dash-chips { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; justify-content: flex-end; }
.video-wall { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 0.75rem; align-content: start; }
.video-wall[hidden] { display: none; }
.video-bar { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; grid-column: 1 / -1; }
.video-bar select,
.video-cam {
  width: auto;
  min-width: 14rem;
  max-width: 18rem;
  height: 2.4rem;
  margin: 0;
  padding: 0.35rem 2rem 0.35rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: var(--panel);
  color: var(--text);
  color-scheme: dark;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%2393a1b8' d='M1 1.2 6 6.8 11 1.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 0.7rem;
}
.video-cam { min-width: 8rem; height: 2rem; }
.video-note { font-size: 0.75rem; }
.video-tile {
  display: grid;
  gap: 0.4rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(20, 27, 41, 0.96);
}
.video-tile-head { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.video-tile-head strong { flex: 1 1 8rem; }
.video-stream { width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 8px; object-fit: contain; }
.video-status.is-bad { color: var(--bad); }
.video-q.is-on { border-color: var(--accent); color: var(--accent); }
.layout.is-wall .side { max-height: none; }
.dash-stage { display: flex; flex-direction: column; gap: 0.55rem; min-width: 0; min-height: calc(100vh - 180px); }
.layout .side { overflow: auto; max-height: calc(100vh - 92px); display: grid; gap: 0.7rem; align-content: start; }
.dash-group { display: grid; gap: 0.55rem; }
.dash-group-head { display: flex; align-items: center; gap: 0.5rem; }
.dash-group-head h3 { margin: 0; font-size: 0.95rem; }
.dash-count {
  min-width: 1.4rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: rgba(79, 157, 255, 0.16);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
}
.dash-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(520px, 1fr)); gap: 0.75rem; }
.dash-card, .dash-strip-card {
  display: grid;
  gap: 0.7rem;
  padding: 0.9rem 1rem 0.85rem;
  border-radius: 10px;
  background: rgba(20, 27, 41, 0.96);
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px transparent;
}
.dash-card.is-selected { border-color: rgba(79, 157, 255, 0.55); box-shadow: 0 0 0 1px rgba(79, 157, 255, 0.35); }
.dash-card.is-critical, .dash-strip-card.is-critical {
  border-color: rgba(255, 107, 107, 0.72);
  box-shadow: 0 0 0 1px rgba(255, 107, 107, 0.28), 0 0 22px rgba(255, 80, 80, 0.22);
}
.dash-card.is-warn, .dash-strip-card.is-warn { border-color: rgba(240, 180, 41, 0.55); box-shadow: inset 3px 0 0 var(--warn); }
.dash-card.is-offline, .dash-strip-card.is-offline { opacity: 0.82; }
.dash-card-head, .dash-strip-head { display: flex; justify-content: space-between; gap: 0.75rem 1rem; align-items: flex-start; flex-wrap: wrap; }
.dash-card-name { flex: 1 1 12rem; min-width: 8rem; }
.dash-card-title, .dash-strip-name { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.5rem; }
.dash-card-title strong, .dash-strip-name strong { font-size: 1.05rem; letter-spacing: 0.01em; }
.dash-host { display: block; margin-top: 0.15rem; color: var(--muted); font-size: 0.75rem; font-family: ui-monospace, monospace; }
.dash-type {
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--accent);
  border: 1px solid rgba(79, 157, 255, 0.4);
  border-radius: 999px;
  padding: 0.08rem 0.45rem;
  background: rgba(79, 157, 255, 0.12);
}
.dash-card-tools, .dash-strip-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.35rem; }
.dash-card-tools { flex: 0 1 15rem; flex-direction: column; align-items: stretch; width: min(15rem, 100%); margin-left: auto; }
.dash-card-tools .btn { white-space: normal; text-align: center; line-height: 1.25; }
.dash-card-tools .dash-chip, .dash-card-tools .dash-chips { align-self: flex-end; }
.dash-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.18rem 0.5rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}
.dash-strip-card .dash-chip { text-transform: uppercase; letter-spacing: 0.03em; }
.dash-dot { width: 0.42rem; height: 0.42rem; border-radius: 50%; background: currentColor; }
.dash-chip-on { color: var(--ok); background: rgba(61, 220, 151, 0.15); }
.dash-chip-warn { color: var(--warn); background: rgba(240, 180, 41, 0.15); }
.dash-chip-off { color: var(--bad); background: rgba(255, 107, 107, 0.12); }
.dash-alerts { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.dash-alert {
  padding: 0.16rem 0.45rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 650;
  border: 1px solid transparent;
}
.dash-alert.is-bad { color: #ff8b8b; background: rgba(255, 107, 107, 0.12); border-color: rgba(255, 107, 107, 0.35); }
.dash-alert.is-warn { color: var(--warn); background: rgba(240, 180, 41, 0.12); border-color: rgba(240, 180, 41, 0.35); }
.dash-alert.is-muted { color: var(--muted); background: rgba(147, 161, 184, 0.1); border-color: var(--line); }
.dash-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
.dash-metric, .dash-cell, .dash-mini-chip {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  min-width: 0;
  padding: 0.42rem 0.5rem;
  border-radius: 8px;
  background: rgba(11, 15, 23, 0.55);
  border: 1px solid rgba(35, 46, 68, 0.75);
}
.dash-metric.is-wide { grid-column: 1 / -1; }
.dash-metric span, .dash-cell span, .dash-mini-chip span {
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.dash-metric b, .dash-cell b, .dash-mini-chip b {
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.25;
  white-space: normal;
  overflow-wrap: anywhere;
}
#dash-strip { width: 100%; }
#dash-strip[hidden] { display: none !important; }
.dash-cells { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 0.4rem; }
.dash-mini { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.dash-mini-chip { min-width: 7rem; }
.dash-card-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
.dash-card-foot .btn, .dash-strip-tools .btn, .dash-graphs { text-align: center; text-decoration: none; }
.dash-graphs { justify-self: start; }
.dash-ok { color: var(--ok); }
.dash-warn { color: var(--warn); }
.dash-bad { color: #ff8b8b; }
.dash-info { color: #bb9af7; }
.dash-muted { color: var(--muted); }
.dash-pick {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(11, 15, 23, 0.45);
  text-align: left;
}
.dash-pick.is-selected { border-color: rgba(79, 157, 255, 0.55); background: rgba(79, 157, 255, 0.12); }
.dash-pick.is-critical { border-color: rgba(255, 107, 107, 0.55); }
.dash-pick.is-warn { border-color: rgba(240, 180, 41, 0.5); }
.dash-pick-name { display: grid; gap: 0.05rem; min-width: 0; }
.dash-pick-name small { color: var(--muted); font-size: 0.72rem; }
@media (max-width: 1200px) { .dash-cells { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 720px) {
  .dash-cells, .dash-metrics, .dash-card-foot { grid-template-columns: 1fr 1fr; }
  .dash-card-tools { flex-direction: row; }
}
#map { height: 100%; min-height: 520px; border-radius: 8px; border: 1px solid var(--line); background: #0a0e16; }
.leaflet-div-icon.board-pin { background: transparent; border: 0; }
.board-pin-dot {
  width: 32px; height: 32px; margin: 0 auto;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #0b0f17; font-size: 0.68rem; font-weight: 800;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.55);
}
.board-pin-dot.off { color: #fff; filter: grayscale(0.35); }
.board-pin-dot.armed { box-shadow: 0 0 0 3px rgba(61, 220, 151, 0.85), 0 2px 8px rgba(0,0,0,.55); }
.board-pin-name {
  margin-top: 2px;
  text-align: center;
  font-size: 11px;
  font-weight: 750;
  line-height: 1.15;
  color: #e6ecf5;
  text-shadow: 0 1px 2px #000, 0 0 6px #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast {
  position: fixed; bottom: 1rem; right: 1rem;
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 0.7rem 0.9rem; border-radius: 10px; box-shadow: var(--shadow);
}
.update-progress { display: grid; gap: 0.45rem; max-width: 36rem; }
.update-progress-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: #363b54;
  overflow: hidden;
}
.update-progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.25s ease;
}
.update-progress-fill.indeterminate {
  position: absolute;
  width: 38%;
  transition: none;
  animation: update-indet 1.15s ease-in-out infinite;
}
.update-progress-fill.done { background: var(--ok); }
.update-progress-fill.failed { background: var(--bad); }
@keyframes update-indet {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(280%); }
}
.vpn-body[hidden], .vpn-self[hidden] { display: none !important; }
.gamepad-enable.gamepad-toggle-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
  cursor: pointer;
}
.gamepad-toggle-input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.gamepad-toggle-track {
  position: relative;
  flex-shrink: 0;
  width: 2.5rem;
  height: 1.35rem;
  background: #363b54;
  border-radius: 999px;
  pointer-events: none;
}
.gamepad-enable .gamepad-toggle-input:checked + .gamepad-toggle-track { background: var(--ok); }
.gamepad-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.1rem;
  height: 1.1rem;
  background: #e6ecf5;
  border-radius: 50%;
  transition: transform 0.2s ease;
  pointer-events: none;
}
.gamepad-enable .gamepad-toggle-input:checked + .gamepad-toggle-track .gamepad-toggle-thumb { transform: translateX(1.15rem); }
.gamepad-enable-label { pointer-events: none; user-select: none; }

@media (max-width: 860px) {
  .vpn-fields { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; }
  .layout { grid-template-columns: 1fr; }
  .layout .side { max-height: none; }
  #map { min-height: 320px; }
}
