:root {
  color-scheme: dark;
  --bg: #070a0c;
  --surface: #0c1115;
  --surface-2: #11171c;
  --surface-3: #151d22;
  --line: #263039;
  --line-soft: #1b242b;
  --text: #f6f7f8;
  --muted: #929ca6;
  --accent: #a8ff3e;
  --accent-soft: rgba(168, 255, 62, .12);
  --accent-ink: #071006;
  --danger: #ff6b6b;
  --demo: #ffcc4d;
  --radius-sm: 8px;
  --radius-md: 12px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; min-height: 100vh; color: var(--text); background: var(--bg); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }
a { color: inherit; text-decoration: none; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: clamp(1.9rem, 3vw, 2.5rem); line-height: 1; letter-spacing: -.055em; }
h2 { margin: 0; font-size: 1rem; letter-spacing: -.02em; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }
.eyebrow { margin-bottom: 7px; color: var(--accent); font: 750 .62rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .16em; }
.hidden { display: none !important; }

.brand { display: inline-flex; align-items: center; gap: 11px; font-size: .92rem; font-weight: 750; letter-spacing: -.02em; }
.brand b { color: var(--accent); }
.brand-symbol { width: 32px; height: 32px; padding: 5px; color: var(--accent-ink); background: var(--accent); border-radius: 7px; fill: currentColor; }

.app-shell { display: grid; grid-template-columns: 212px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; padding: 25px 17px 18px; border-right: 1px solid var(--line-soft); background: #080c0f; z-index: 4; }
.sidebar > .brand { padding: 0 9px 31px; }
.sidebar nav { display: grid; gap: 4px; }
.nav-link { display: flex; width: 100%; min-height: 43px; align-items: center; gap: 13px; padding: 0 12px; color: #8b969f; background: transparent; border-radius: var(--radius-sm); text-align: left; font-size: .79rem; }
.nav-link svg { flex: 0 0 auto; width: 18px; height: 18px; fill: currentColor; }
.nav-link:hover, .nav-link:focus-visible { color: var(--text); background: var(--surface-2); outline: none; }
.nav-link.active { color: var(--text); background: var(--accent-soft); box-shadow: inset 2px 0 var(--accent); }
.nav-link.active svg { color: var(--accent); }
.sidebar-foot { display: grid; gap: 4px; margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.sidebar-foot form { margin: 0; }

.workspace { width: 100%; max-width: 1600px; margin: 0 auto; padding: 25px clamp(22px, 2.8vw, 42px) 44px; overflow: hidden; }
.workspace-head { display: flex; min-height: 76px; align-items: flex-start; justify-content: space-between; gap: 24px; padding-bottom: 22px; border-bottom: 1px solid var(--line-soft); }
.head-note { margin: 10px 0 0; color: var(--muted); font: .72rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.head-actions { display: flex; align-items: center; gap: 14px; }
.mode-switch { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #090d10; }
.mode-switch button { min-height: 34px; padding: 0 11px; color: #74808a; background: transparent; border-radius: 5px; font-size: .65rem; font-weight: 700; white-space: nowrap; }
.mode-switch button:hover, .mode-switch button:focus-visible { color: var(--text); outline: none; }
.mode-switch button.active { color: var(--accent-ink); background: var(--accent); }
.demo-mode .mode-switch button.active { color: #211900; background: var(--demo); }
.demo-banner { display: flex; min-height: 43px; align-items: center; gap: 12px; margin: 14px 0 -5px; padding: 0 14px; color: #ddc47a; background: rgba(255, 204, 77, .07); border: 1px solid rgba(255, 204, 77, .25); border-radius: var(--radius-sm); font-size: .66rem; }
.demo-banner strong { padding: 4px 7px; color: #211900; background: var(--demo); border-radius: 4px; font: 850 .58rem ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; }
.demo-banner i { width: 3px; height: 3px; border-radius: 50%; background: #8c783e; }
.demo-mode .eyebrow { color: var(--demo); }
.demo-mode .button:disabled, .demo-mode .restart-button:disabled { cursor: not-allowed; opacity: .46; }
.live-state { display: inline-flex; align-items: center; gap: 8px; color: #bac2c8; font-size: .75rem; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 4px rgba(255, 107, 107, .09); }
.status-dot.online { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; padding: 0 17px; border-radius: var(--radius-sm); font-weight: 750; font-size: .76rem; }
.button-primary { color: var(--accent-ink); background: var(--accent); }
.button-primary:hover { background: #b7ff60; }
.button-secondary { color: var(--text); background: var(--surface-3); border: 1px solid var(--line); }
.button-danger { color: #fff; background: #b74343; }
.button-block { width: 100%; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; margin: 19px 0; padding: 1px; background: var(--line-soft); border: 1px solid var(--line-soft); border-radius: var(--radius-md); overflow: hidden; }
.kpi { min-height: 107px; padding: 18px 19px; background: var(--surface); }
.kpi > span { display: block; color: var(--muted); font-size: .7rem; }
.kpi > strong { display: block; margin: 10px 0 5px; font-size: 1.75rem; line-height: 1; letter-spacing: -.045em; }
.kpi > strong b { color: inherit; }
.kpi > small { color: #66737c; font-size: .65rem; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 268px; gap: 19px; }
.primary-column, .ops-column { display: grid; align-content: start; gap: 19px; min-width: 0; }
.panel { min-width: 0; border: 1px solid var(--line-soft); border-radius: var(--radius-md); background: var(--surface); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 19px; border-bottom: 1px solid var(--line-soft); }
.chart-head { align-items: flex-start; }
.range-control { display: flex; padding: 3px; background: #080c0f; border: 1px solid var(--line-soft); border-radius: 8px; }
.range-control button { min-height: 30px; padding: 0 9px; color: #74808a; background: transparent; border-radius: 5px; font-size: .64rem; white-space: nowrap; }
.range-control button:hover, .range-control button:focus-visible { color: var(--text); outline: none; }
.range-control button.active { color: var(--accent-ink); background: var(--accent); font-weight: 750; }
.traffic-summary { display: flex; align-items: flex-end; gap: 27px; padding: 15px 19px 0; }
.traffic-summary div > span { display: block; color: var(--muted); font-size: .63rem; }
.traffic-summary strong { display: block; margin-top: 4px; font-size: 1rem; }
.chart-legend { display: flex; gap: 14px; margin-left: auto; padding-bottom: 2px; }
.chart-legend > span { display: flex !important; align-items: center; gap: 6px; }
.chart-legend i { width: 13px; height: 2px; background: var(--accent); }
.chart-legend i.tx { background: #6f7e88; }
.chart-wrap { position: relative; height: 222px; margin: 0 12px; }
#traffic-chart { width: 100%; height: 100%; overflow: visible; }
.chart-grid line { stroke: #1b252b; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-line { fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chart-line.rx { stroke: var(--accent); filter: drop-shadow(0 0 5px rgba(168, 255, 62, .18)); }
.chart-line.tx { stroke: #6f7e88; stroke-width: 1.6; }
.chart-area { fill: url(#chart-fill); opacity: .25; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: #637079; font-size: .72rem; text-align: center; }
.chart-axis { display: flex; justify-content: space-between; padding: 0 19px 15px; color: #59656d; font: .59rem ui-monospace, SFMono-Regular, Menlo, monospace; }

.last-update { color: #66727b; font-size: .62rem; }
.device-table-wrap { max-height: 520px; overflow: auto; }
.device-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.device-table th { position: sticky; z-index: 2; top: 0; height: 31px; padding: 0 12px; color: #637079; background: #090d10; font-size: .58rem; font-weight: 600; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
.demo-mode .device-glyph { color: var(--demo); background: rgba(255,204,77,.1); }
.demo-mode .device-status.online i { background: var(--demo); }
.demo-mode .device-traffic span { color: var(--demo); }
.demo-mode .switch input:checked + .slider { background: var(--demo); }
.demo-mode progress::-webkit-progress-value { background: var(--demo); }
.demo-mode progress::-moz-progress-bar { background: var(--demo); }
.device-table th:first-child, .device-table td:first-child { width: 31%; padding-left: 19px; }
.device-table th:nth-child(2) { width: 17%; }
.device-table th:nth-child(3) { width: 20%; }
.device-table th:nth-child(4) { width: 23%; }
.device-table th:last-child, .device-table td:last-child { width: 9%; text-align: center; }
.device-table td { height: 49px; padding: 6px 12px; border-top: 1px solid var(--line-soft); color: #b7c0c6; font-size: .67rem; vertical-align: middle; }
.device-table tr.disabled td { opacity: .5; }
.device-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.device-glyph { display: grid; flex: 0 0 auto; width: 27px; height: 27px; place-items: center; color: var(--accent); background: var(--accent-soft); border-radius: 7px; }
.device-glyph svg { width: 14px; height: 14px; fill: currentColor; }
.device-title { min-width: 0; }
.device-title strong, .device-title span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-title strong { color: #e8ebed; font-size: .7rem; font-weight: 650; }
.device-title span { margin-top: 2px; color: #5f6b74; font: .57rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.device-status { display: inline-flex; align-items: center; gap: 5px; color: #76828b; }
.device-status i { width: 6px; height: 6px; border-radius: 50%; background: #4c5962; }
.device-status.online { color: #c9d2d7; }
.device-status.online i { background: var(--accent); }
.device-traffic { white-space: nowrap; font: .59rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.device-traffic span { color: var(--accent); }
.switch { position: relative; display: inline-block; width: 34px; height: 20px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.slider { position: absolute; inset: 0; border-radius: 20px; background: #303a42; transition: .18s; }
.slider::before { content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; border-radius: 50%; background: #d8dde0; transition: .18s; }
.switch input:focus-visible + .slider { outline: 2px solid var(--text); outline-offset: 2px; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(14px); background: var(--accent-ink); }
.empty { padding: 30px !important; color: var(--muted) !important; text-align: center !important; }

.health-chip { padding: 4px 6px; color: var(--accent); background: var(--accent-soft); border-radius: 4px; font: .55rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.resource { padding: 15px 18px 0; }
.resource > div { display: flex; justify-content: space-between; color: var(--muted); font-size: .65rem; }
.resource b { color: #d5dade; font-weight: 600; }
progress { width: 100%; height: 4px; margin-top: 9px; border: 0; border-radius: 4px; overflow: hidden; background: #1a2329; }
progress::-webkit-progress-bar { background: #1a2329; }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }
.server-facts { margin: 17px 18px 18px; padding-top: 11px; border-top: 1px solid var(--line-soft); }
.server-facts > div { display: flex; justify-content: space-between; gap: 10px; padding-top: 8px; font-size: .61rem; }
.server-facts dt { color: #65717a; }
.server-facts dd { margin: 0; color: #a9b2b8; text-align: right; }
.audit-list { max-height: 257px; overflow: auto; margin: 0; padding: 5px 18px 12px; list-style: none; }
.audit-list li { position: relative; padding: 11px 0 10px 16px; border-bottom: 1px solid var(--line-soft); }
.audit-list li::before { content: ""; position: absolute; left: 0; top: 16px; width: 6px; height: 6px; border-radius: 50%; background: #53616a; }
.audit-list li.success::before { background: var(--accent); }
.audit-list li strong { display: block; color: #d7dcdf; font-size: .65rem; font-weight: 600; }
.audit-list li span { display: block; margin-top: 4px; color: #606d75; font: .55rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.privacy-panel { display: flex; gap: 12px; padding: 16px; background: var(--accent-soft); border-color: rgba(168, 255, 62, .18); }
.privacy-panel svg { flex: 0 0 auto; width: 21px; height: 21px; fill: var(--accent); }
.privacy-panel strong { font-size: .68rem; }
.privacy-panel p { margin: 5px 0 0; color: #91a083; font-size: .6rem; line-height: 1.45; }
.restart-button { min-height: 40px; color: #9da7ad; background: transparent; border: 1px solid #3d2b2d; border-radius: var(--radius-sm); font-size: .66rem; }
.restart-button:hover { color: #ffbaba; border-color: #754246; background: rgba(255,107,107,.05); }

dialog { width: min(460px, calc(100% - 30px)); padding: 0; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 30px 100px rgba(0,0,0,.72); }
dialog::backdrop { background: rgba(2, 5, 7, .78); backdrop-filter: blur(5px); }
dialog form { position: relative; padding: 30px; }
dialog h2 { margin-bottom: 11px; font-size: 1.4rem; }
.dialog-close { position: absolute; right: 18px; top: 15px; width: 36px; height: 36px; color: var(--muted); background: transparent; font-size: 1.5rem; }
label { display: block; margin: 22px 0; color: #aab3b9; font-size: .72rem; }
input { width: 100%; min-height: 45px; margin-top: 8px; padding: 0 13px; color: var(--text); background: #090d10; border: 1px solid var(--line); border-radius: var(--radius-sm); outline: 0; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 23px; }
.danger-text { color: var(--danger); }
.alert { margin: 13px 0 0; padding: 10px; color: #ffc1c1; background: rgba(255, 107, 107, .08); border: 1px solid rgba(255, 107, 107, .25); border-radius: 7px; font-size: .7rem; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 10; max-width: min(390px, calc(100% - 44px)); padding: 13px 16px; color: var(--accent-ink); background: var(--accent); border-radius: 8px; font-size: .72rem; font-weight: 700; box-shadow: 0 14px 45px rgba(0,0,0,.45); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s; }
.toast.visible { opacity: 1; transform: none; }
.toast.error { color: #fff; background: #b74343; }

.login-shell { display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 15% 10%, rgba(168,255,62,.075), transparent 28rem), var(--bg); }
.login-card { width: min(440px, 100%); padding: 34px; background: rgba(12,17,21,.94); border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 28px 80px rgba(0,0,0,.5); }
.login-copy { padding: 47px 0 7px; }
.login-copy h1 { margin-bottom: 14px; font-size: 2.55rem; }
.login-copy > p:last-child { margin-bottom: 0; color: var(--muted); font-size: .78rem; line-height: 1.55; }
.login-card form { margin-top: 17px; }
.security-proof { display: flex; justify-content: center; gap: 17px; padding-top: 23px; color: #5e6b73; font: .57rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.security-proof span { display: flex; align-items: center; gap: 5px; }
.security-proof i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }

@media (max-width: 1120px) {
  .dashboard-grid { grid-template-columns: minmax(0, 1fr) 240px; }
  .workspace { padding-inline: 22px; }
  .device-table th:nth-child(3), .device-table td:nth-child(3) { display: none; }
  .mode-switch button { max-width: 42px; overflow: hidden; padding-inline: 9px; }
  .mode-switch button::first-letter { text-transform: uppercase; }
}

@media (max-width: 980px) {
  .app-shell { display: block; }
  .sidebar { position: sticky; height: 62px; flex-direction: row; align-items: center; padding: 9px 16px; border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .sidebar > .brand { padding: 0 18px 0 0; }
  .sidebar nav { display: flex; }
  .nav-link { min-width: 43px; padding: 0 12px; }
  .nav-link span { display: none; }
  .sidebar-foot { display: flex; margin: 0 0 0 auto; padding: 0 0 0 8px; border: 0; border-left: 1px solid var(--line-soft); }
  .workspace { scroll-margin-top: 70px; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .ops-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .privacy-panel, .restart-button { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  .workspace { padding: 20px 13px 36px; }
  .workspace-head { align-items: stretch; flex-direction: column; }
  .head-actions { justify-content: space-between; }
  .mode-switch { order: 3; width: 100%; }
  .mode-switch button { max-width: none; flex: 1; }
  .demo-banner { align-items: flex-start; flex-wrap: wrap; padding-block: 10px; }
  .demo-banner i { margin-top: 7px; }
  .head-actions .button { min-height: 44px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-head { flex-direction: column; }
  .range-control { width: 100%; overflow-x: auto; }
  .range-control button { flex: 1 0 auto; min-height: 36px; }
  .traffic-summary { flex-wrap: wrap; gap: 13px 22px; }
  .chart-legend { margin-left: 0; }
  .device-table, .device-table tbody, .device-table tr, .device-table td { display: block; width: 100% !important; }
  .device-table thead { display: none; }
  .device-table tr { position: relative; padding: 13px 64px 13px 13px; border-top: 1px solid var(--line-soft); }
  .device-table td { height: auto; padding: 4px 0 !important; border: 0; text-align: left !important; }
  .device-table td::before { content: attr(data-label); display: inline-block; min-width: 92px; color: #5f6b74; font-size: .56rem; text-transform: uppercase; }
  .device-table td:first-child::before, .device-table td:last-child::before { display: none; }
  .device-table td:last-child { position: absolute; top: 22px; right: 14px; width: 40px !important; }
  .device-table td:nth-child(3) { display: block; }
  .ops-column { grid-template-columns: 1fr; }
  .privacy-panel, .restart-button { grid-column: auto; }
}

@media (max-width: 470px) {
  .sidebar > .brand span { display: none; }
  .sidebar nav .nav-link:nth-child(n+3) { display: none; }
  .kpi { min-height: 96px; padding: 15px; }
  .kpi > strong { font-size: 1.45rem; }
  .head-actions { align-items: stretch; flex-direction: column; }
  .chart-wrap { height: 185px; }
  .login-card { padding: 27px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
