/* Power VPN app shell — shared by the admin panel and the user dashboard.
   Layout: fixed sidebar with route links on the left, one page at a time on the right.
   On narrow screens the sidebar becomes a top bar with scrolling tabs. */
:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --fg: #0e1a15;
  --muted: #5b6a63;
  --line: #dde5e1;
  --brand: #1f9d6b;
  --brand-ink: #0d6b47;
  --brand-soft: #dcf3e8;
  --side: #0f1915;
  --side-fg: #c9d6d0;
  --side-active: #1b2a24;
  --warn: #b7791f;
  --warn-soft: #fbf1dc;
  --danger: #c2412d;
  --danger-soft: #fbe9e5;
  --on-brand: #ffffff;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1210;
    --surface: #131d19;
    --surface-2: #17221e;
    --fg: #e7efeb;
    --muted: #93a49c;
    --line: #24312c;
    --brand: #36c48a;
    --brand-ink: #7fe0b4;
    --brand-soft: #123226;
    --side: #080d0b;
    --side-fg: #b3c2bb;
    --side-active: #15211c;
    --warn: #e6b357;
    --warn-soft: #33270f;
    --danger: #f08a75;
    --danger-soft: #3a1f19;
    --on-brand: #06120d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
a { color: var(--brand-ink); }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100%; }

.side {
  background: var(--side); color: var(--side-fg);
  display: flex; flex-direction: column; gap: 22px;
  padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand b { color: var(--brand); }
.brand small { display: block; color: var(--side-fg); font-weight: 500; font-size: 11.5px; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.8; }
.mark { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; flex: none; }
.mark svg { width: 15px; height: 15px; fill: #fff; }

.nav { display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: 9px;
  color: var(--side-fg); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--side-active); color: #fff; }
.nav a[aria-current="page"] { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--brand); }
.nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav .count { margin-left: auto; font-size: 11.5px; padding: 0 7px; border-radius: 999px; background: var(--side-active); color: var(--side-fg); font-variant-numeric: tabular-nums; }
.nav a[aria-current="page"] .count { background: var(--brand); color: var(--on-brand); }

.side-foot { margin-top: auto; padding: 10px; border-radius: 10px; background: var(--side-active); font-size: 12.5px; display: grid; gap: 8px; }
.side-foot .me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.side-foot .me div { min-width: 0; }
.side-foot .me div b { display: block; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-foot .me div span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.8; }

.content { padding: 28px 32px 56px; display: grid; align-content: start; gap: 20px; min-width: 0; }
.page { display: grid; gap: 20px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; gap: 10px; padding: 10px 12px; overflow-x: auto; }
  .brand small, .side-foot { display: none; }
  .nav { display: flex; gap: 4px; }
  .nav a { white-space: nowrap; padding: 7px 10px; }
  .nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--brand); }
  .content { padding: 20px 16px 48px; }
}

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 12px 20px; }
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; text-wrap: balance; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 64ch; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 13px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap;
  text-decoration: none; color: inherit;
}
.btn:hover { border-color: var(--muted); }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; border-radius: 7px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.55; cursor: progress; }

/* ---------- Stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 2px; }
.tile .k { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.tile .v { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile .s { color: var(--muted); font-size: 12.5px; }
.tile.accent .v { color: var(--brand-ink); }

/* ---------- Panels ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-head a { font-size: 13px; font-weight: 600; text-decoration: none; }
.panel-body { padding: 14px 16px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--line); min-width: 0; }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .grow b, .list .grow span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .grow span { color: var(--muted); font-size: 12.5px; }
.list time { color: var(--muted); font-size: 12.5px; white-space: nowrap; }

/* ---------- Tabs / filters ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 8px 12px; color: var(--muted); font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--brand); }
.tabs .n { font-size: 11.5px; color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.search { padding: 8px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); min-width: 220px; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.filter-bar .search { min-width: 0; color: var(--fg); }
.filter-bar .search.grow { flex: 1 1 240px; }
.filter-bar select.search { flex: 0 1 auto; max-width: 200px; }
.pager { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-top: 12px; color: var(--muted); font-size: 13px; }
.pager .pages { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.pager .btn[aria-current="page"] { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.pager select { padding: 4px 6px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--fg); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.empty { color: var(--muted); text-align: center; padding: 36px 16px; }
.mono { font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
td select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); max-width: 220px; }

.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who > span > b { display: block; }
.who > span > span { display: block; color: var(--muted); font-size: 12.5px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; flex: none; }
.with-flag { display: flex; align-items: center; gap: 10px; min-width: 0; }
.with-flag b { display: block; }
.with-flag span span, .with-flag small { color: var(--muted); font-size: 12.5px; }

.flag { width: 24px; height: 16px; border-radius: 3px; flex: none; box-shadow: 0 0 0 1px rgb(0 0 0 / 0.12); }
.flag.sm { width: 18px; height: 12px; border-radius: 2px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; border: 0; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
button.pill { cursor: pointer; }
.pill.on, .pill.public { background: var(--brand-soft); color: var(--brand-ink); }
.pill.off { background: var(--danger-soft); color: var(--danger); }
.pill.private { background: var(--surface-2); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.chips { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; max-width: 280px; }
.chip { font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.star { color: #d29b0b; }

.test-ok { color: var(--brand-ink); font-weight: 600; }
.test-bad { color: var(--danger); font-size: 12.5px; }

/* ---------- Server cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 10px; min-width: 0; }
.card .with-flag b { font-size: 15px; }
.card .tag { justify-self: start; }

/* ---------- Forms & dialogs ---------- */
.form { display: grid; gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .span2 { grid-column: 1 / -1; }
label.field { display: grid; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
label.field input, label.field select, label.field textarea, .form textarea {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--fg); font-weight: 400; width: 100%;
}
textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
.help { margin: 0; color: var(--muted); font-size: 12.5px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

dialog {
  width: min(540px, calc(100vw - 32px)); padding: 0;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--fg);
  box-shadow: 0 30px 80px -30px rgb(0 0 0 / 0.5);
}
dialog::backdrop { background: rgb(5 12 9 / 0.45); }
.dialog-head { padding: 16px 18px 0; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.dialog-body { padding: 14px 18px; display: grid; gap: 12px; }
.dialog-foot { padding: 12px 18px 16px; border-top: 1px solid var(--line); }

.check-list { display: grid; gap: 2px; max-height: 50vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 6px; }
.check-list label { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 7px; cursor: pointer; }
.check-list label:hover { background: var(--surface-2); }
.check-list small { color: var(--muted); margin-left: auto; white-space: nowrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 50;
  right: calc(20px + env(safe-area-inset-right, 0px)); bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px; border-radius: 11px;
  background: var(--fg); color: var(--bg);
  box-shadow: 0 18px 40px -16px rgb(0 0 0 / 0.5);
  font-weight: 500;
}
.toast.bad { background: var(--danger); color: #fff; }

/* ---------- Empty / notice ---------- */
.notice { padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--fg); font-size: 13.5px; }
.notice b { color: var(--warn); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- Login screen ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; display: grid; gap: 14px; }
.auth-card .brand { color: var(--fg); padding: 0; }
.auth-card .brand small { color: var(--muted); }
.auth-card h1 { margin: 6px 0 0; font-size: 22px; letter-spacing: -0.02em; }
.auth-card p { margin: 0; color: var(--muted); }
.auth-card .btn { justify-content: center; }
.error-box { margin: 0; padding: 9px 11px; border-radius: 9px; background: var(--danger-soft); color: var(--danger); font-size: 13px; }
.side-foot .btn { justify-content: center; background: transparent; color: var(--side-fg); border-color: #2a3a33; }
.side-foot .btn:hover { color: #fff; border-color: var(--side-fg); }
.side-links { display: flex; gap: 6px; }
.side-links .btn { flex: 1; }

/* ---------- User app extras ---------- */
.connect-card { display: flex; flex-wrap: wrap; align-items: center; gap: 18px 24px; padding: 18px 20px; }
.connect-card .big { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); box-shadow: 0 10px 26px -10px var(--brand); flex: none; }
.connect-card .big svg { width: 28px; height: 28px; fill: none; stroke: var(--on-brand); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.connect-card .info { flex: 1; min-width: 200px; display: grid; gap: 4px; }
.connect-card .info b { font-size: 17px; }
.group-title { margin: 6px 0 -6px; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

/* ---------- Servers page: usage, bulk bar, checkboxes ---------- */
.usage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px 24px; align-items: start; }
.usage-grid .k { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.usage-grid .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; margin-top: 6px; }
.meter span { display: block; height: 100%; background: var(--brand); border-radius: inherit; }
.meter.warn span { background: var(--warn); }
.meter.full span { background: var(--danger); }
.errors { margin: 10px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.errors b { color: var(--fg); font-variant-numeric: tabular-nums; }

.bulk-bar {
  position: sticky; top: 8px; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 12px;
  background: var(--fg); color: var(--bg);
  box-shadow: 0 14px 30px -16px rgb(0 0 0 / 0.5);
}
.bulk-bar b { margin-right: 6px; }
.bulk-bar .btn { background: var(--surface); color: var(--fg); border-color: transparent; }
.bulk-bar .btn.primary { background: var(--brand); color: var(--on-brand); }
.bulk-bar .btn.ghost { background: transparent; color: var(--bg); }
.servers-table { min-width: 1080px; }
th.check, td.check { width: 36px; padding-right: 0; }
td.check input, th.check input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
tr.selected td { background: color-mix(in srgb, var(--brand) 7%, var(--surface)); }
.names { display: flex; flex-wrap: wrap; gap: 4px; max-width: 220px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; justify-self: start; }
.seg label { display: flex; align-items: center; gap: 6px; padding: 7px 12px; cursor: pointer; font-weight: 600; }
.seg label + label { border-left: 1px solid var(--line); }
.seg input { accent-color: var(--brand); }

.mark-img { flex: none; object-fit: contain; }
