:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #7a7f87;
  --line: #e7e8ec;
  --accent: #6c47ff;
  --accent-2: #9b7bff;
  --accent-soft: #efeaff;
  --accent-text: #ffffff;
  --green: #2dbe64;
  --red: #f33a3a;
  --orange: #ff9a1f;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
}
:root[data-theme="dark"] {
  --accent: #8b6bff;
  --accent-2: #a98fff;
  --accent-soft: #2a2340;
  --bg: #121212;
  --card: #1e1e1f;
  --text: #f2f2f2;
  --muted: #9a9ea6;
  --line: #2c2c2e;
  --shadow: none;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "YS Text", "Segoe UI", Roboto, Arial, sans-serif;
  padding: 12px 16px 96px;
  min-height: 100vh;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, select { font: inherit; color: var(--text); }

.top { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 14px; }
.title { display: flex; align-items: center; gap: 12px; }
.logo { width: 40px; height: 40px; border-radius: 12px; display: block; box-shadow: 0 4px 12px rgba(108,71,255,.3); }
h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.3px; }
.title p { margin: 0; color: var(--muted); font-size: 13px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; background: var(--card); font-size: 20px; box-shadow: var(--shadow); }

.tabs { display: flex; gap: 4px; background: var(--card); padding: 4px; border-radius: 14px; box-shadow: var(--shadow); margin-bottom: 14px; }
.tab { flex: 1; padding: 9px 0; border-radius: 10px; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--accent); color: var(--accent-text); }

.view { display: none; }
.view.active { display: block; }

.filters { margin-bottom: 10px; }
#search {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 0; background: var(--card); box-shadow: var(--shadow); outline: none;
}
.chips { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.chip { padding: 7px 13px; border-radius: 999px; background: var(--card); color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; box-shadow: var(--shadow); }
.chip.active { background: var(--accent); color: var(--accent-text); }

.group-title { margin: 18px 4px 8px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; display: flex; justify-content: space-between; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; text-align: left; }
.row + .row { border-top: 1px solid var(--line); }
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--line); display: grid; place-items: center;
  font-weight: 700; position: relative;
}
.avatar.on::after {
  content: ""; position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border-radius: 50%;
  background: var(--green); border: 2px solid var(--card);
}
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .side { text-align: right; font-size: 12px; color: var(--muted); flex: none; }
.row .side b { display: block; color: var(--text); font-weight: 600; font-size: 13px; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 6px; background: var(--bg); font-size: 11px; font-weight: 600; margin-left: 4px; vertical-align: 1px; }
.tag.y { background: var(--accent-soft); color: var(--accent); }

.note { color: var(--muted); font-size: 13px; margin: 0 4px 12px; }
.route { padding: 14px; }
.route + .route { border-top: 1px solid var(--line); }
.route .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.route .fqdn { font-weight: 700; }
.route .ip { color: var(--muted); font-size: 13px; }
.route .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pill { padding: 8px 12px; border-radius: 12px; background: var(--bg); font-weight: 600; font-size: 13px; }
.pill.current { background: var(--accent); color: var(--accent-text); }
.pill:not(.current):not(.danger) { color: var(--accent); }
.pill.danger { color: var(--red); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tile .k { color: var(--muted); font-size: 12px; }
.tile .v { font-size: 20px; font-weight: 800; margin-top: 4px; }
.tile .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile.wide { grid-column: 1 / -1; }
.ok { color: var(--green); } .bad { color: var(--red); } .warn { color: var(--orange); }

.btn { padding: 14px 16px; border-radius: 14px; font-weight: 700; background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: var(--accent-text); }
.btn.secondary { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.btn.danger { background: transparent; color: var(--red); }
.btn.wide { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .5; }
.fab {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); padding: 16px;
  border-radius: 16px; background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: var(--accent-text);
  font-weight: 800; font-size: 16px; box-shadow: 0 8px 24px rgba(108,71,255,.35);
}

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .2s; }
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; background: var(--card);
  border-radius: 22px 22px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .25s ease;
}
.sheet.open { transform: translateY(0); }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin: 4px 0 4px; font-size: 20px; }
.sheet .muted { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 2px; }
.field input:focus, .field select:focus, #search:focus { box-shadow: 0 0 0 2px var(--accent); }
.field input, .field select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); outline: none;
}
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { padding: 10px 14px; border-radius: 12px; background: var(--bg); font-weight: 600; }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.qr { display: block; width: 100%; max-width: 320px; margin: 6px auto 12px; border-radius: 14px; background: #fff; padding: 8px; image-rendering: pixelated; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; margin: 6px 0 12px; }
.kv span:nth-child(odd) { color: var(--muted); }
.kv span:nth-child(even) { word-break: break-all; }
.stack { display: grid; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  transition: all .2s; pointer-events: none; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }
.skeleton { height: 64px; border-radius: var(--radius); background: var(--card); margin-bottom: 10px; opacity: .6; }

.head-actions { display: flex; gap: 8px; }
.sheet.tall { height: 92vh; max-height: 92vh; }
.person-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.person-head h2 { margin: 0; }
.person-head .muted { margin: 2px 0 0; }
.avatar.big { width: 56px; height: 56px; font-size: 22px; background: var(--accent-soft); color: var(--accent); }
.live { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 16px; background: var(--bg); margin-bottom: 12px; }
.live.on { background: var(--accent-soft); }
.live-icon, .loc-icon { font-size: 22px; width: 32px; text-align: center; flex: none; }
.live .name { font-weight: 700; }
.live .sub { color: var(--muted); font-size: 13px; }
.muted-inline { color: var(--muted); font-weight: 500; font-size: 13px; }
.period { margin-bottom: 4px; }
.period button { flex: 1; }
.stats { margin: 10px 0 4px; }
.stats .tile { background: var(--bg); box-shadow: none; }
.tile .v.small { font-size: 16px; }
.row.static { cursor: default; }
.svc .bar { height: 6px; border-radius: 3px; background: var(--bg); margin-top: 7px; overflow: hidden; }
.svc .bar i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.fold { margin-top: 16px; }
.fold summary { cursor: pointer; font-weight: 700; padding: 10px 4px; color: var(--accent); list-style: none; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: " ›"; }
.fold[open] summary::after { content: " ⌄"; }
.sites { padding: 6px 0; }
.site { display: flex; justify-content: space-between; gap: 10px; padding: 7px 14px; font-size: 13px; }
.site span { word-break: break-all; }
.site b { color: var(--muted); font-weight: 600; flex: none; }
.small { font-size: 12px; }
#sheet .card { background: var(--card); border: 1px solid var(--line); box-shadow: none; }
