/* Rathole admin — dark, dense, dashboard-style. No external fonts (strict CSP). */
:root {
  --bg: #0a0c11;
  --bg-2: #0e1118;
  --surface: #121620;
  --surface-2: #171c28;
  --surface-3: #1d2331;
  --border: #232a3a;
  --border-2: #2d3548;
  --text: #e7eaf2;
  --text-2: #b7bfd1;
  --muted: #7f889e;
  --faint: #566078;
  --accent: #8aa4ff;
  --accent-2: #6d88f5;
  --accent-bg: rgba(138, 164, 255, .12);
  --down: #8aa4ff;   /* client download (server tx) */
  --up: #4fd1a5;     /* client upload (server rx) */
  --ok: #3ecf8e;
  --ok-bg: rgba(62, 207, 142, .12);
  --warn: #f2b84b;
  --warn-bg: rgba(242, 184, 75, .12);
  --bad: #ff6b72;
  --bad-bg: rgba(255, 107, 114, .12);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.25);
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar: 232px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: rgba(138,164,255,.35); }
.mono { font-family: var(--mono); font-size: 12.5px; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--bg-2); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px 12px; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 650; letter-spacing: .01em; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: radial-gradient(circle at 30% 30%, #b6c6ff, #5d77ea 60%, #3346a8); display: grid; place-items: center; box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset, 0 4px 14px rgba(93,119,234,.35); }
.brand-mark svg { width: 16px; height: 16px; color: #fff; }
.brand small { display: block; color: var(--muted); font-weight: 500; font-size: 11.5px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-bg); color: #dfe6ff; }
.nav a.active svg { color: var(--accent); }
.nav svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.sidebar .spacer { flex: 1; }
.sidebar-foot { padding: 10px 12px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12.5px; }

.main { min-width: 0; padding: 26px 32px 60px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.mobile-top, .tabbar { display: none; }

/* ---------- cards & grid ---------- */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: 2fr 1fr; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-pad { padding: 16px 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px 0; }
.card-head h2, .card-head h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text); }
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 14px 18px 18px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 26px 0 10px; font-weight: 600; }

.kpi { padding: 15px 16px; display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; }
.kpi .label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 7px; }
.kpi .label svg { width: 15px; height: 15px; }
.kpi .value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi .value small { font-size: 14px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.kpi .foot { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.kpi .foot .d { color: var(--down); }
.kpi .foot .u { color: var(--up); }

/* ---------- badges / dots ---------- */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--faint); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.dot.idle { background: #6b7ba3; }
.dot.pulse { animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 3px var(--ok-bg); } 50% { box-shadow: 0 0 0 6px rgba(62,207,142,.05); } }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 550; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border-2); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: #8ff0c4; border-color: rgba(62,207,142,.25); }
.badge.warn { background: var(--warn-bg); color: #ffd58a; border-color: rgba(242,184,75,.25); }
.badge.bad { background: var(--bad-bg); color: #ffb0b4; border-color: rgba(255,107,114,.25); }
.badge.accent { background: var(--accent-bg); color: #c9d4ff; border-color: rgba(138,164,255,.25); }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border-2); background: transparent; color: var(--text-2); cursor: pointer; font-size: 12.5px; }
.chip:hover { border-color: var(--faint); color: var(--text); }
.chip.on { background: var(--accent-bg); border-color: rgba(138,164,255,.4); color: #dfe6ff; }
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 7px; color: var(--muted); cursor: pointer; font-size: 12.5px; font-weight: 550; }
.seg button.on { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.3); }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text); font-weight: 550; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, transform .05s; }
.btn:hover { background: var(--surface-3); border-color: var(--faint); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: linear-gradient(180deg, #8ea8ff, #6d88f5); border-color: #7c97fb; color: #0b1030; }
.btn.primary:hover { background: linear-gradient(180deg, #a0b5ff, #7b94f7); }
.btn.danger { background: var(--bad-bg); border-color: rgba(255,107,114,.35); color: #ffb9bd; }
.btn.danger:hover { background: rgba(255,107,114,.2); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn.icon { width: 34px; padding: 0; }
.btn.sm.icon { width: 30px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; color: var(--text-2); font-weight: 550; }
.field .hint { font-size: 12px; color: var(--muted); }
.field .err { font-size: 12px; color: var(--bad); }
.input, select.input, textarea.input { height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border-2); background: var(--bg-2); color: var(--text); outline: none; width: 100%; transition: border-color .12s, box-shadow .12s; }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; min-height: 70px; }
.input:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(138,164,255,.18); }
.input.mono { font-family: var(--mono); }
.check { display: flex; gap: 9px; align-items: flex-start; color: var(--text-2); font-size: 13px; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search .input { padding-left: 34px; width: 260px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
.t td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr { transition: background .1s; }
.t tbody tr.click { cursor: pointer; }
.t tbody tr.click:hover { background: var(--surface-2); }
.t .r { text-align: right; }
.peer-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.peer-name .nm { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.peer-name .ext { font-size: 11px; color: var(--muted); }
.traffic-cell { display: flex; flex-direction: column; gap: 1px; font-size: 12.5px; }
.traffic-cell .d { color: var(--down); }
.traffic-cell .u { color: var(--up); }
.bar { height: 6px; border-radius: 4px; background: var(--surface-3); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.bar i.d { background: var(--down); }
.bar i.u { background: var(--up); }

.peer-cards { display: none; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; user-select: none; }
.chart svg { display: block; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--faint); font-size: 10.5px; font-family: var(--sans); }
.chart .tip { position: absolute; pointer-events: none; background: rgba(18,22,32,.96); border: 1px solid var(--border-2); border-radius: 10px; padding: 8px 10px; font-size: 12px; white-space: nowrap; box-shadow: 0 8px 24px rgba(0,0,0,.35); z-index: 2; }
.chart .tip .t { color: var(--muted); margin-bottom: 3px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); align-items: center; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.empty-chart { height: 100%; display: grid; place-items: center; color: var(--faint); font-size: 13px; }

/* ---------- route diagram ---------- */
.route { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr; align-items: center; gap: 10px; padding: 8px 0; }
.hop { background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.hop .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; display: flex; align-items: center; gap: 6px; }
.hop .v { font-family: var(--mono); font-size: 12.5px; margin-top: 4px; word-break: break-all; }
.hop.ok { border-color: rgba(62,207,142,.35); }
.hop.bad { border-color: rgba(255,107,114,.45); }
.hop-arrow { color: var(--faint); display: flex; flex-direction: column; align-items: center; font-size: 10.5px; gap: 2px; }
.hop-arrow svg { width: 20px; height: 20px; }

.checks { display: flex; flex-direction: column; }
.checks .row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.checks .row:last-child { border-bottom: 0; }
.checks .row .dot { margin-top: 6px; }
.checks .row b { font-weight: 560; display: block; }
.checks .row span { color: var(--muted); font-size: 12.5px; }

.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 8px 18px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; word-break: break-all; }

.alert { display: flex; gap: 12px; padding: 12px 14px; border-radius: 12px; border: 1px solid; font-size: 13px; align-items: flex-start; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.alert.warn { background: var(--warn-bg); border-color: rgba(242,184,75,.3); color: #ffe0a3; }
.alert.bad { background: var(--bad-bg); border-color: rgba(255,107,114,.3); color: #ffc4c7; }
.alert.info { background: var(--accent-bg); border-color: rgba(138,164,255,.3); color: #d5ddff; }
.alert.ok { background: var(--ok-bg); border-color: rgba(62,207,142,.3); color: #b6f5d8; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row-flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ---------- modal / drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(4,6,10,.62); backdrop-filter: blur(3px); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .12s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 40px); overflow: auto; background: var(--surface); border: 1px solid var(--border-2); border-radius: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.5); animation: pop .14s ease-out; }
.modal.wide { max-width: 760px; }
@keyframes pop { from { transform: translateY(6px) scale(.99); opacity: 0; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 6px; }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 650; }
.modal-body { padding: 12px 20px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 20px; flex-wrap: wrap; }

.drawer-overlay { justify-content: flex-end; align-items: stretch; padding: 0; }
.drawer { width: 100%; max-width: 560px; height: 100vh; overflow: auto; background: var(--surface); border-left: 1px solid var(--border-2); animation: slide .16s ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.drawer-head { position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--border); padding: 16px 20px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; z-index: 1; }
.drawer-head h3 { margin: 0; font-size: 18px; }
.drawer-body { padding: 18px 20px 40px; display: flex; flex-direction: column; gap: 16px; }

.config-box { position: relative; }
.config-box pre { margin: 0; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 14px; font: 12px/1.55 var(--mono); max-height: 320px; overflow: auto; white-space: pre-wrap; word-break: break-all; color: var(--text-2); }
.config-box pre.blur { filter: blur(6px); user-select: none; }
.config-box .reveal { position: absolute; inset: 0; display: grid; place-items: center; }
.qr { display: flex; justify-content: center; }
.qr img { width: 100%; max-width: 300px; aspect-ratio: 1; border-radius: 14px; background: #fff; padding: 10px; image-rendering: pixelated; }
.qr.blur img { filter: blur(10px); }

.toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--surface-3); border: 1px solid var(--border-2); border-radius: 12px; padding: 11px 14px; box-shadow: 0 12px 30px rgba(0,0,0,.4); font-size: 13px; max-width: 380px; display: flex; gap: 10px; align-items: flex-start; animation: pop .15s ease-out; }
.toast.err { border-color: rgba(255,107,114,.45); }
.toast.ok { border-color: rgba(62,207,142,.45); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background:
  radial-gradient(700px 400px at 15% 10%, rgba(109,136,245,.16), transparent 60%),
  radial-gradient(600px 400px at 90% 90%, rgba(79,209,165,.08), transparent 60%), var(--bg); }
.login { width: 100%; max-width: 380px; padding: 28px; }
.login .brand { padding: 0 0 22px; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login p { color: var(--muted); margin: 0 0 22px; }

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; }
@keyframes sk { to { background-position: -200% 0; } }
.spin { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.2); border-top-color: currentColor; border-radius: 50%; animation: rot .7s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

.countdown { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.top-list .item { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.top-list .item:last-child { border-bottom: 0; }
.top-list .item .bar { grid-column: 1 / -1; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 14px 16px 96px; }
  .mobile-top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); background: rgba(10,12,17,.85); backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 20; }
  .mobile-top .brand { padding: 0; }
  .tabbar { display: grid; grid-template-columns: repeat(6, 1fr); position: fixed; bottom: 0; left: 0; right: 0; background: rgba(14,17,24,.94); backdrop-filter: blur(12px); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 30; }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 5px 0; font-size: 10.5px; color: var(--muted); }
  .tabbar a svg { width: 21px; height: 21px; }
  .tabbar a.active { color: #dfe6ff; }
  .tabbar a.active svg { color: var(--accent); }
  .tabbar a:hover { text-decoration: none; }
  .cols-2 { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 19px; }
  .search .input { width: 100%; }
  .search { flex: 1; min-width: 160px; }
  .peer-table { display: none; }
  .peer-cards { display: flex; flex-direction: column; gap: 10px; }
  .peer-card { padding: 13px 14px; display: flex; flex-direction: column; gap: 8px; cursor: pointer; }
  .route { grid-template-columns: 1fr; }
  .hop-arrow { flex-direction: row; justify-content: center; }
  .hop-arrow svg { transform: rotate(90deg); }
  .toasts { left: 12px; right: 12px; bottom: 82px; }
  .toast { max-width: none; }
  .drawer { max-width: none; }
  .modal { border-radius: 16px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
}
@media (max-width: 420px) {
  .kpi .value { font-size: 20px; }
  .kpi { padding: 12px 13px; }
}
