:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --border: #e4e3df;
  --border-strong: #d4d3ce;
  --text: #161615;
  --text-2: #55544f;
  --text-3: #85847d;
  --accent: #2a78d6;
  --accent-soft: #e8f0fb;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #1f8a4c;
  --good-soft: #e5f4ea;
  --warn: #b26b00;
  --warn-soft: #fbf0dc;
  --bad: #c93b3a;
  --bad-soft: #fbe9e8;
  --shadow: 0 1px 2px rgba(20, 20, 18, .04), 0 4px 16px rgba(20, 20, 18, .04);
  --radius: 14px;
  --radius-sm: 9px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121212;
    --surface: #1b1b1a;
    --surface-2: #232322;
    --border: #2c2c2a;
    --border-strong: #3a3a37;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8d8c84;
    --accent: #5a9cec;
    --accent-soft: #1d2a3b;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #4cc27a;
    --good-soft: #17291e;
    --warn: #e0a33a;
    --warn-soft: #2e2414;
    --bad: #ef6b6a;
    --bad-soft: #351a1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212;
  --surface: #1b1b1a;
  --surface-2: #232322;
  --border: #2c2c2a;
  --border-strong: #3a3a37;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #8d8c84;
  --accent: #5a9cec;
  --accent-soft: #1d2a3b;
  --series-1: #3987e5;
  --series-2: #d95926;
  --good: #4cc27a;
  --good-soft: #17291e;
  --warn: #e0a33a;
  --warn-soft: #2e2414;
  --bad: #ef6b6a;
  --bad-soft: #351a1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 24px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 600; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.tnum { font-variant-numeric: tabular-nums; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 12px max(16px, env(safe-area-inset-left)) 12px max(16px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; font-size: 16px; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  display: flex; align-items: center; gap: 7px; white-space: nowrap;
  padding: 7px 12px; border-radius: 999px; color: var(--text-2); font-size: 14px; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.nav a.soon { color: var(--text-3); pointer-events: none; }
.topbar-actions { display: flex; gap: 4px; margin-left: auto; }
.topbar-actions form { margin: 0; }
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.view { max-width: 1180px; margin: 0 auto; padding: 28px 16px 64px; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { margin: 4px 0 0; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.mt { margin-top: 16px; }
@media (max-width: 960px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3-1, .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 10px 12px; }
  .nav { order: 3; flex-basis: 100%; }
  .view { padding-top: 20px; }
  h1 { font-size: 21px; }
}

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head .muted { font-size: 13px; }

/* ---------- KPI ---------- */
.kpi .label { color: var(--text-2); font-size: 13px; }
.kpi .value { font-size: 30px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi .sub { color: var(--text-3); font-size: 13px; margin-top: 4px; }

/* ---------- Buttons & Inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-primary:hover { background: var(--text); opacity: .88; }
.btn-good { color: var(--good); }
.btn-bad { color: var(--bad); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
input, select {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, .btn:focus-visible, .icon-btn:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: grid; gap: 6px; font-size: 13px; color: var(--text-2); font-weight: 500; }

/* ---------- Status ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px 4px 9px; border-radius: 999px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.idle { background: var(--surface-2); color: var(--text-3); }

.protect {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.protect-text { display: flex; align-items: center; gap: 12px; }
.protect-text strong { display: block; font-size: 15px; }

/* ---------- Listen ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border);
  min-height: 44px;
}
.list li:first-child { border-top: 0; }
.list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.list .count { color: var(--text-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.list .actions { display: flex; gap: 6px; opacity: .0; transition: opacity .15s; }
.list li:hover .actions, .list li:focus-within .actions { opacity: 1; }
@media (hover: none) { .list .actions { opacity: 1; } }
.bar-bg { position: relative; flex: 1; min-width: 0; }
.bar-bg .bar { position: absolute; left: 0; bottom: -7px; height: 2px; border-radius: 2px; background: var(--series-1); opacity: .55; }
.bar-bg .bar.blocked { background: var(--series-2); }
.empty { color: var(--text-3); font-size: 14px; padding: 12px 0; }

.device { display: flex; align-items: center; gap: 12px; }
.device-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); flex: none; }
.device-meta { flex: 1; min-width: 0; }
.device-meta strong { display: block; font-size: 14px; font-weight: 600; }
.device-meta span { color: var(--text-3); font-size: 13px; }

.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 6px; }
.tag.allow { background: var(--good-soft); color: var(--good); }
.tag.block { background: var(--bad-soft); color: var(--bad); }
.tag.custom { background: var(--surface-2); color: var(--text-2); }

.domain-tool { display: flex; gap: 8px; flex-wrap: wrap; }
.domain-tool input { flex: 1 1 100%; }
.domain-tool .btn { flex: 1 1 0; }
.check-result { margin-top: 12px; font-size: 14px; color: var(--text-2); }
.check-result:empty { display: none; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; color: var(--text-3); font-weight: 600; padding: 0 10px 8px 0; }
td { padding: 9px 10px 9px 0; border-top: 1px solid var(--border); vertical-align: middle; }
td.domain { max-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) { .col-device { display: none; } }
td.right, th.right { text-align: right; padding-right: 0; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: 13px; padding: 4px 10px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- Chart ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--text-3); font-size: 11px; }
.chart .hit { fill: transparent; cursor: default; }
.chart .col.dim { opacity: .45; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.12); min-width: 150px;
  opacity: 0; transition: opacity .1s;
}
.tooltip.show { opacity: 1; }
.tooltip .t-head { font-weight: 600; margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 14px; color: var(--text-2); }
.tooltip .t-row b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip .t-row i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 6px; }

/* ---------- Übersicht ---------- */
.tiles { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.tile { display: flex; flex-direction: column; gap: 14px; color: var(--text); transition: border-color .15s; }
.tile:hover { text-decoration: none; border-color: var(--border-strong); }
.tile-head { display: flex; align-items: center; gap: 10px; }
.tile-head .device-icon { width: 34px; height: 34px; }
.tile-stats { display: flex; gap: 22px; }
.tile-stats .value { font-size: 24px; }
.tile.placeholder { border-style: dashed; box-shadow: none; background: transparent; color: var(--text-3); justify-content: center; align-items: center; min-height: 150px; }

/* ---------- Diverses ---------- */
.alert { background: var(--bad-soft); color: var(--bad); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.4s infinite; border-radius: 8px; height: 16px; }
@keyframes sk { to { background-position: -200% 0; } }
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .2s; max-width: calc(100% - 32px); z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--bad); color: #fff; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 650; font-size: 18px; margin-bottom: 20px; }
.login-card { display: grid; gap: 14px; padding: 26px; }
.login-card h1 { font-size: 20px; }
.login-card p { margin: -8px 0 4px; font-size: 14px; }
.login-card .btn { height: 42px; margin-top: 4px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
