:root {
  --bg: #f5f4f1;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --sidebar: #efede8;
  --border: #e3e0da;
  --border-strong: #d2cec6;
  --text: #1f1e1c;
  --muted: #6d6a64;
  --faint: #9a968f;
  --accent: #d97757;
  --accent-strong: #c2613f;
  --accent-soft: rgba(217, 119, 87, 0.14);
  --green: #2e9d5b;
  --orange: #d48a1a;
  --red: #d2453d;
  --track: #e9e6e0;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.04);
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a19;
    --surface: #242322;
    --surface-2: #2a2927;
    --sidebar: #201f1e;
    --border: #353331;
    --border-strong: #45423f;
    --text: #edebe7;
    --muted: #a7a39c;
    --faint: #7b7771;
    --accent-soft: rgba(217, 119, 87, 0.2);
    --green: #4cc27d;
    --orange: #e8a23c;
    --red: #f06a61;
    --track: #3a3835;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-strong); }
svg { width: 16px; height: 16px; flex: none; }
svg.inline { width: 14px; height: 14px; vertical-align: -2px; }
.server-icon svg { width: 100%; height: 100%; }
code, .mono { font-family: var(--mono); font-size: 0.92em; overflow-wrap: anywhere; }
input[type=range], input[type=checkbox] { accent-color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.error-text { color: var(--red); }
.warn-text { color: var(--orange); }
.ok-text { color: var(--green); }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Shell */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px; }
.brand-title { font-weight: 650; }
.brand-sub { font-size: 12px; color: var(--muted); }
nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; }
nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 8px; text-decoration: none; color: var(--text);
}
nav a:hover { background: rgba(127, 127, 127, 0.1); }
nav a.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
nav svg { width: 18px; height: 18px; flex: none; }
nav .badge-count {
  margin-left: auto; background: var(--orange); color: #fff; border-radius: 10px;
  font-size: 11px; font-weight: 700; padding: 0 7px; line-height: 18px;
}
.sidebar-foot { margin-top: auto; padding: 14px 16px; font-size: 12.5px; border-top: 1px solid var(--border); }
main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.page { padding: 20px 24px 60px; max-width: 1040px; width: 100%; }

@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  nav { flex-direction: row; overflow-x: auto; padding-bottom: 10px; }
  nav a { white-space: nowrap; }
  .sidebar-foot { display: none; }
  .page { padding: 16px; }
  .topbar { padding: 12px 16px; }
}

/* Cards & forms */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card-title { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; margin-bottom: 12px; }
.card-title svg { width: 18px; height: 18px; color: var(--accent); }
.section { margin-bottom: 22px; }
.section-head { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 4px 6px; }
.section-foot { font-size: 12.5px; color: var(--muted); margin: 6px 4px 0; }
.group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.group > .item { padding: 11px 14px; border-top: 1px solid var(--border); }
.group > .item:first-child { border-top: 0; }
.item.field { display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap; }
.item.field > label, .item.field > .label { flex: 1 1 220px; min-width: 0; }
.item.field > .control { flex: 1 1 300px; display: flex; justify-content: flex-end; align-items: center; gap: 6px; min-width: 0; }
.label-sub { display: block; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }

input[type=text], input[type=password], input[type=number], input[type=url], input:not([type]), select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border-strong); border-radius: 7px; padding: 6px 9px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.control input:not([type=checkbox]):not([type=range]), .control select { width: 100%; max-width: 420px; }
textarea { width: 100%; font-family: var(--mono); font-size: 13px; min-height: 70px; resize: vertical; }
input.mono, .mono input { font-family: var(--mono); font-size: 13px; }
input.inline-name { border-color: transparent; background: transparent; font-weight: 600; padding-left: 4px; }
input.inline-name:hover, input.inline-name:focus { border-color: var(--border-strong); background: var(--surface-2); }

.btn {
  font: inherit; font-size: 13.5px; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 7px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--faint); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn.danger { color: var(--red); }
.btn.link { border: 0; background: none; color: var(--accent-strong); padding: 4px 2px; }
.btn.small { font-size: 12.5px; padding: 3px 9px; }
.btn.icon { padding: 5px 7px; }
.btn svg { width: 15px; height: 15px; }
.iconbtn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 3px; border-radius: 5px; display: inline-flex; }
.iconbtn:hover { color: var(--text); background: rgba(127, 127, 127, 0.12); }
.iconbtn svg { width: 16px; height: 16px; }

/* Switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--track); border-radius: 22px; transition: 0.15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.25); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:disabled + span { opacity: 0.5; cursor: default; }
.switch.mini { width: 30px; height: 18px; }
.switch.mini span::before { width: 14px; height: 14px; }
.switch.mini input:checked + span::before { transform: translateX(12px); }

.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.segmented button { font: inherit; font-size: 13px; border: 0; background: var(--surface); color: var(--text); padding: 5px 12px; cursor: pointer; border-left: 1px solid var(--border-strong); }
.segmented button:first-child { border-left: 0; }
.segmented button.on { background: var(--accent); color: #fff; }

/* Status */
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent); background: currentColor; }
.dot.green { color: var(--green); } .dot.orange { color: var(--orange); } .dot.red { color: var(--red); } .dot.gray { color: var(--faint); } .dot.yellow { color: #d8b31d; }
.status { display: inline-flex; align-items: center; gap: 8px; }
.badge { display: inline-block; font-size: 11px; font-weight: 650; padding: 1px 7px; border-radius: 10px; background: rgba(127,127,127,0.14); color: var(--muted); white-space: nowrap; }
.badge.red { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }
.badge.orange { background: color-mix(in srgb, var(--orange) 15%, transparent); color: var(--orange); }
.badge.accent { background: var(--accent-soft); color: var(--accent-strong); }
.code-status { font-family: var(--mono); font-weight: 650; font-size: 12.5px; }
.code-status.ok { color: var(--green); } .code-status.warn { color: var(--orange); } .code-status.err { color: var(--red); } .code-status.none { color: var(--faint); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.stat-value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--muted); }
.divider { border-top: 1px solid var(--border); margin: 14px 0; }

.usage { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.usage-head { display: flex; gap: 6px; color: var(--muted); }
.usage-head b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--track); border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 6px; min-width: 4px; }
.bar.compact { height: 5px; }

.account-row { display: grid; grid-template-columns: minmax(220px, 300px) 1fr auto; gap: 16px; align-items: start; padding: 12px 0; border-top: 1px solid var(--border); }
.account-row:first-of-type { border-top: 0; }
@media (max-width: 700px) { .account-row { grid-template-columns: 1fr; } }
.account-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.meta-line { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }

.cmd {
  font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 7px; padding: 8px 10px; word-break: break-all; user-select: all; flex: 1; min-width: 0;
}
pre.term {
  font-family: var(--mono); font-size: 12px; background: #151412; color: #e8e6e1; border-radius: 8px;
  padding: 10px 12px; max-height: 300px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0;
}

.notice { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; }
.notice svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }

/* Providers page */
.split { display: grid; grid-template-columns: 240px 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.plist { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px; position: sticky; top: 70px; box-shadow: var(--shadow); }
.plist-head { font-size: 11.5px; font-weight: 650; text-transform: uppercase; color: var(--muted); padding: 8px 8px 4px; letter-spacing: 0.04em; }
.plist a { display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 8px; text-decoration: none; color: var(--text); cursor: pointer; }
.plist a:hover { background: rgba(127,127,127,0.1); }
.plist a.active { background: var(--accent-soft); }
.plist a svg { width: 17px; height: 17px; color: var(--accent); flex: none; }
.plist a.off svg { color: var(--faint); }
.plist .sub { font-size: 12px; color: var(--muted); }
.plist-foot { display: flex; gap: 6px; padding: 8px 4px 4px; border-top: 1px solid var(--border); margin-top: 6px; }
.plist-foot select { flex: 1; }

.acct { padding: 12px 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.acct:first-child { border-top: 0; }
.acct.off { opacity: 0.6; }
.acct-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 9px; box-shadow: 0 8px 24px rgba(0,0,0,0.15); padding: 4px;
}
.menu-list button { display: block; width: 100%; text-align: left; font: inherit; font-size: 13px; border: 0; background: none; color: var(--text); padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.menu-list button:hover:not(:disabled) { background: var(--accent-soft); }
.menu-list button:disabled { opacity: 0.45; cursor: default; }
.menu-list button.danger { color: var(--red); }
.menu-list hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.menu-list .menu-head { font-size: 11px; color: var(--muted); text-transform: uppercase; padding: 6px 10px 2px; font-weight: 650; }

.kv { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.kv-row { display: flex; gap: 6px; align-items: center; }
.kv-row input { flex: 1; font-family: var(--mono); font-size: 13px; }
.kv-row .arrow { color: var(--faint); }

/* Routes */
.route { display: grid; grid-template-columns: auto 1fr; gap: 12px; padding: 14px; border-top: 1px solid var(--border); }
.route:first-child { border-top: 0; }
.route.off { opacity: 0.55; }
.route-lines { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.route-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.route-line .lbl { width: 110px; text-align: right; color: var(--muted); flex: none; }
@media (max-width: 700px) { .route-line .lbl { width: auto; text-align: left; } }
.route-line input { flex: 1 1 200px; font-family: var(--mono); font-size: 13px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; background: rgba(127,127,127,0.14); border-radius: 14px; font-size: 13px; }
.chain { display: flex; flex-direction: column; gap: 5px; }
.chain-step { display: flex; gap: 8px; align-items: center; }
.chain-step .n { width: 30px; text-align: right; color: var(--muted); font-size: 12px; }

/* Requests */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1 1 240px; font: inherit; padding: 6px 10px; border-radius: 7px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); white-space: nowrap; }
td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.sel { background: var(--accent-soft); }
td.num { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.detail { margin-top: 12px; }
.detail-grid { display: grid; grid-template-columns: 140px 1fr; gap: 6px 14px; font-size: 13px; }
.detail-grid dt { color: var(--muted); text-align: right; }
.detail-grid dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: var(--faint); margin-bottom: 8px; }

/* Welcome */
.steps { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 14px; }
.step { display: flex; gap: 10px; align-items: baseline; }
.step b { width: 20px; height: 20px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); font-size: 12px; display: inline-grid; place-items: center; flex: none; }

/* Server card */
.server-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.server-icon { width: 38px; height: 38px; flex: none; }
.server-head > .grow { flex: 1 1 240px; }
.server-title { font-size: 17px; font-weight: 650; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login-card img { align-self: center; }
.login-card h1 { font-size: 20px; }
.login-card input { padding: 9px 11px; }

/* Modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,0.35); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; border: 1px solid var(--border); width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal h3 { font-size: 17px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 9px; font-size: 13.5px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,0.25); max-width: calc(100vw - 32px); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
input.invalid { border-color: var(--red); outline-color: color-mix(in srgb, var(--red) 25%, transparent); }

/* User view (personal key, read-only) */
.me { min-height: 100vh; }
.me-top { justify-content: space-between; }
.me-page { margin: 0 auto; max-width: 900px; }
.me tbody tr { cursor: default; }
