:root {
  color-scheme: dark;
  --bg: #0c1118;
  --panel: #141c27;
  --line: #263344;
  --text: #f0f5fa;
  --muted: #a2b0c1;
  --accent: #65e4c0;
  --hot: #ffb66f;
  --error: #ff9898;
  font: 16px/1.5 "Geist", "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
h1, h2, p, ol { margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .54; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }

.topbar { background: #101722; border-bottom: 1px solid var(--line); }
.topbar-inner, .layout { width: min(100% - 3rem, 1220px); margin-inline: auto; }
.topbar-inner { height: 65px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: .75rem; font-weight: 730; letter-spacing: -.025em; }
.brand-mark {
  width: 30px; height: 30px; border: 1px solid #306859; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  color: var(--accent); background: #13322f;
}
.brand-mark i { width: 2px; border-radius: 1px; background: currentColor; height: 8px; }
.brand-mark i:nth-child(2) { height: 14px; }
.brand-mark i:nth-child(3) { height: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 1rem; }
.service-address, .hint, footer { color: var(--muted); font-size: .875rem; }
.layout { padding: 2.25rem 0 1.25rem; display: grid; gap: 1.125rem; }
.overview { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: .25rem; }
h1 { font-size: clamp(1.8rem, 4vw, 2.65rem); line-height: 1.1; letter-spacing: -.047em; font-weight: 740; }
.server-details { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .75rem; color: var(--muted); margin-top: .65rem; font-size: .9rem; }
.server-details span + span { font-variant-numeric: tabular-nums; color: #c1cbda; }
.button {
  border: 1px solid transparent; border-radius: 8px; padding: .56rem .9rem; min-height: 40px;
  color: var(--text); font-size: .875rem; font-weight: 700; white-space: nowrap;
  transition: background-color .15s, border-color .15s;
}
.button.quiet { background: transparent; border-color: var(--line); }
.button.quiet:hover:not(:disabled) { background: #213045; }
.button.restart { background: #2e211c; color: #ffcb9d; border-color: #634529; }
.button.restart:hover:not(:disabled) { background: #4a3124; border-color: #947044; }
.button.primary { background: var(--accent); color: #0b2e26; }
.button.primary:hover { background: #89efd4; }
.notice {
  padding: .65rem 1rem; color: #aff4df; background: #142e2b;
  border: 1px solid #265348; border-radius: 8px; font-size: .9rem;
}
.notice.error { background: #331f26; border-color: #71404b; color: #ffb8bc; }

.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .875rem; }
.card { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.metric { padding: 1rem 1.125rem; }
.metric h2 { display: flex; align-items: center; gap: .45rem; color: var(--muted); font-weight: 620; font-size: .875rem; }
.metric-value { min-height: 1.6em; margin: .12rem 0 .1rem; font-size: clamp(1.12rem, 2.4vw, 1.58rem); font-weight: 740; letter-spacing: -.038em; }
.tabular { font-variant-numeric: tabular-nums; }
.tone-good { color: var(--accent); }
.tone-warn { color: var(--hot); }
.tone-down { color: var(--error); }
.swatch { display: inline-block; width: .52rem; height: .52rem; border-radius: 2px; flex-shrink: 0; }
.incoming { background: var(--accent); }
.outgoing { background: var(--hot); }

.traffic-grid { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr); gap: 1.125rem; }
.traffic, .protocols, .activity { padding: 1.2rem 1.25rem; }
.devices { padding: 1.2rem 0 0; }
.devices > .section-header { padding-inline: 1.25rem; }
.section-header { display: flex; align-items: flex-start; justify-content: space-between; gap: .65rem; }
.section-header h2 { font-size: 1.14rem; font-weight: 730; letter-spacing: -.03em; }
.section-header .hint { margin-top: .18rem; }
.segments { display: inline-flex; align-items: stretch; align-self: flex-start; flex-shrink: 0; gap: 3px; padding: 3px; background: #0e151f; border: 1px solid var(--line); border-radius: 8px; }
.segments button {
  color: var(--muted); background: transparent; border: 0; border-radius: 5px;
  padding: .27rem .64rem; min-height: 32px; font-size: .875rem; font-weight: 650;
}
.segments button[aria-pressed="true"] { color: var(--text); background: #2a3a4d; }
.segments button:hover { color: var(--text); }
.traffic-summary { display: flex; flex-wrap: wrap; gap: .4rem 1.3rem; margin-top: 1rem; }
.traffic-summary > div { display: flex; gap: .4rem; align-items: center; color: var(--muted); font-size: .875rem; }
.traffic-summary strong { color: var(--text); margin-left: .2rem; font-variant-numeric: tabular-nums; }
.chart { width: 100%; height: 235px; position: relative; margin-top: .7rem; }
.chart canvas { width: 100%; height: 100%; display: block; }
.chart-message { display: grid; place-items: center; color: var(--muted); position: absolute; inset: 0 0 20px 0; pointer-events: none; font-size: .875rem; }
.chart-tooltip {
  position: absolute; top: 4px; right: .75rem; padding: .45rem .65rem; border-radius: 6px; pointer-events: none;
  background: #0d141f; border: 1px solid #3a4b5d; white-space: pre-line; font-size: .8rem;
  box-shadow: 0 3px 12px #080d1799;
}
.protocol-list { display: grid; gap: .9rem; margin-top: 1.25rem; }
.protocol-label { display: flex; justify-content: space-between; gap: .5rem; font-size: .875rem; }
.protocol-label strong { font-weight: 650; font-variant-numeric: tabular-nums; }
progress { display: block; width: 100%; height: 7px; margin-top: .42rem; background: #243245; border: 0; border-radius: 10px; overflow: hidden; }
progress::-webkit-progress-bar { background: #243245; }
progress::-webkit-progress-value { background: #79aafb; border-radius: 10px; }
progress::-moz-progress-bar { background: #79aafb; border-radius: 10px; }
.protocol-row:nth-child(2) progress::-webkit-progress-value { background: #65e4c0; }
.protocol-row:nth-child(2) progress::-moz-progress-bar { background: #65e4c0; }
.protocol-row:nth-child(3) progress::-webkit-progress-value { background: #ffb66f; }
.protocol-row:nth-child(3) progress::-moz-progress-bar { background: #ffb66f; }
.protocol-row:nth-child(4) progress::-webkit-progress-value { background: #9c8bd4; }
.protocol-row:nth-child(4) progress::-moz-progress-bar { background: #9c8bd4; }
.protocol-hint { margin-top: 1.2rem; }

.table-scroll { overflow-x: auto; margin-top: .9rem; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: .875rem; white-space: nowrap; }
thead { color: var(--muted); background: #111923; }
th { font-weight: 620; }
th, td { padding: .72rem 1rem; border-top: 1px solid var(--line); }
th:first-child, td:first-child { padding-left: 1.25rem; }
th:last-child, td:last-child { padding-right: 1.25rem; }
td:first-child { font-weight: 700; }
td:nth-child(n + 2) { font-variant-numeric: tabular-nums; }
.device-state { display: block; color: var(--muted); font-size: .8rem; font-weight: 500; }
.device-state.active { color: var(--accent); }
td[colspan] { color: var(--muted); font-weight: 500; }
.event-list { list-style: none; padding: 0; margin-top: .75rem; }
.event-list li { display: flex; flex-wrap: wrap; gap: .1rem 1rem; padding: .52rem 0; border-top: 1px solid var(--line); font-size: .875rem; }
.event-list time { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem 1rem; }

dialog {
  width: min(100% - 2rem, 420px); color: var(--text); background: var(--panel); padding: 1.35rem;
  border: 1px solid #3d4d60; border-radius: 12px;
}
dialog::backdrop { background: #050911c9; }
dialog h2 { font-size: 1.23rem; }
dialog p { color: var(--muted); margin-top: .5rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.3rem; }

.login-body {
  min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: radial-gradient(ellipse at 48% 22%, #152b35, var(--bg) 63%);
}
.login-card {
  width: min(100%, 405px); border: 1px solid var(--line); border-radius: 16px; padding: clamp(1.3rem, 6vw, 2rem);
  background: var(--panel); box-shadow: 0 15px 55px #070c1566;
}
.login-card h1 { font-size: 1.75rem; margin: 1.4rem 0 1.05rem; }
.login-card form { display: grid; gap: .4rem; }
.login-card label { font-size: .9rem; font-weight: 600; color: #cfdae6; }
.login-card input {
  background: #0e151f; color: var(--text); border: 1px solid #37475a;
  border-radius: 8px; padding: .58rem .68rem; min-height: 44px; margin: 0 0 .55rem;
}
.login-card .primary { margin-top: .3rem; min-height: 44px; }
.form-error { color: var(--error); margin-bottom: .7rem; font-size: .9rem; }

@media (max-width: 850px) {
  .traffic-grid { grid-template-columns: minmax(0, 1fr); }
  .protocol-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1.25rem; }
}
@media (max-width: 650px) {
  .topbar-inner, .layout { width: calc(100% - 1.5rem); }
  .layout { padding-top: 1.35rem; gap: .9rem; }
  .overview { align-items: flex-start; flex-direction: column; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
  .metric { padding: .75rem; }
  .traffic-grid { gap: .9rem; }
  .chart { height: 200px; }
  .traffic, .protocols, .activity { padding: .9rem; }
  .devices { padding-top: .9rem; }
  .devices > .section-header { padding-inline: .9rem; }
  .service-address { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
