/* facet admin panel. Light tokens on :root; dark via prefers-color-scheme or [data-theme=dark]. */

:root {
  --bg: #f1f3f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eceff3;
  --border: #e0e4ea;
  --border-strong: #c9d0d9;
  --text: #17202b;
  --text-2: #3e4957;
  --muted: #677283;
  --accent: #0d7680;
  --accent-hover: #0a636c;
  --accent-ink: #ffffff;
  --accent-soft: #e0f0f1;
  --accent-2: #74c3c8;
  --ok: #1f7a37;
  --ok-soft: #e1f2e5;
  --warn: #9a5d00;
  --warn-soft: #fbefd9;
  --danger: #b4281f;
  --danger-soft: #fbe5e3;
  --neutral-soft: #eaedf1;
  --side-bg: #15202c;
  --side-text: #c4cdd8;
  --side-muted: #7e8b9b;
  --side-hover: rgba(255, 255, 255, 0.06);
  --side-active: rgba(84, 201, 207, 0.14);
  --side-accent: #54c9cf;
  --focus: #1b8f99;
  --backdrop: rgba(12, 18, 26, 0.48);
  --shadow-pop: 0 18px 40px -12px rgba(16, 24, 40, 0.28), 0 2px 6px rgba(16, 24, 40, 0.08);
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04);
  --qr-bg: #ffffff;
  --r-xs: 5px;
  --r-s: 7px;
  --r-m: 11px;
  --r-l: 15px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --side-w: 232px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141b;
    --surface: #151d26;
    --surface-2: #19232e;
    --surface-3: #202b37;
    --border: #253140;
    --border-strong: #34424f;
    --text: #e5eaf0;
    --text-2: #c0c9d4;
    --muted: #8a96a6;
    --accent: #3fbcc4;
    --accent-hover: #5fcdd4;
    --accent-ink: #04262a;
    --accent-soft: rgba(63, 188, 196, 0.14);
    --accent-2: #1f6d73;
    --ok: #5cc97a;
    --ok-soft: rgba(92, 201, 122, 0.13);
    --warn: #e7b04b;
    --warn-soft: rgba(231, 176, 75, 0.14);
    --danger: #f07a6f;
    --danger-soft: rgba(240, 122, 111, 0.14);
    --neutral-soft: #222d39;
    --side-bg: #0a1016;
    --side-text: #b9c3cf;
    --side-muted: #6f7c8c;
    --side-hover: rgba(255, 255, 255, 0.05);
    --side-active: rgba(63, 188, 196, 0.14);
    --side-accent: #4fc6cd;
    --focus: #5fcdd4;
    --backdrop: rgba(0, 0, 0, 0.6);
    --shadow-pop: 0 18px 44px -12px rgba(0, 0, 0, 0.7), 0 2px 6px rgba(0, 0, 0, 0.4);
    --shadow-card: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e141b;
  --surface: #151d26;
  --surface-2: #19232e;
  --surface-3: #202b37;
  --border: #253140;
  --border-strong: #34424f;
  --text: #e5eaf0;
  --text-2: #c0c9d4;
  --muted: #8a96a6;
  --accent: #3fbcc4;
  --accent-hover: #5fcdd4;
  --accent-ink: #04262a;
  --accent-soft: rgba(63, 188, 196, 0.14);
  --accent-2: #1f6d73;
  --ok: #5cc97a;
  --ok-soft: rgba(92, 201, 122, 0.13);
  --warn: #e7b04b;
  --warn-soft: rgba(231, 176, 75, 0.14);
  --danger: #f07a6f;
  --danger-soft: rgba(240, 122, 111, 0.14);
  --neutral-soft: #222d39;
  --side-bg: #0a1016;
  --side-text: #b9c3cf;
  --side-muted: #6f7c8c;
  --side-hover: rgba(255, 255, 255, 0.05);
  --side-active: rgba(63, 188, 196, 0.14);
  --side-accent: #4fc6cd;
  --focus: #5fcdd4;
  --backdrop: rgba(0, 0, 0, 0.6);
  --shadow-pop: 0 18px 44px -12px rgba(0, 0, 0, 0.7), 0 2px 6px rgba(0, 0, 0, 0.4);
  --shadow-card: none;
  color-scheme: dark;
}

/* Base */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.text-ok { color: var(--ok); font-weight: 550; }
.text-warn { color: var(--warn); }
.text-danger { color: var(--danger); }

.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}

/* Boot */

.boot {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-content: center; justify-items: center; gap: 14px;
  color: var(--accent);
}
.boot-mark { width: 44px; height: 44px; }
.boot-text { color: var(--muted); font-size: 13px; }
.noscript { padding: 24px; text-align: center; }

/* Shell */

.shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  min-height: 100vh; min-height: 100dvh;
}

.skip {
  position: absolute; left: 12px; top: -48px; z-index: 50;
  background: var(--surface); color: var(--text); padding: 8px 12px; border-radius: var(--r-s);
  box-shadow: var(--shadow-pop);
}
.skip:focus { top: 12px; }

.sidebar {
  position: sticky; top: 0;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; gap: 22px;
  padding: 20px 14px 16px;
  background: var(--side-bg);
  color: var(--side-text);
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 8px;
  color: #f4f7fa;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; color: var(--side-accent); flex: none; }
.brand-name { font-size: 19px; font-weight: 650; letter-spacing: -0.02em; }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-link {
  position: relative;
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px;
  border-radius: var(--r-s);
  color: var(--side-text);
  font-weight: 500;
  text-decoration: none;
}
.nav-link:hover { background: var(--side-hover); color: #fff; text-decoration: none; }
.nav-link .icon { color: var(--side-muted); }
.nav-link[aria-current="page"] { background: var(--side-active); color: #fff; }
.nav-link[aria-current="page"] .icon { color: var(--side-accent); }
.nav-link[aria-current="page"]::before {
  content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--side-accent);
}

.side-foot {
  margin-top: auto;
  display: flex; flex-direction: column; gap: 2px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  padding-top: 12px;
}

.side-user { display: flex; align-items: center; gap: 10px; padding: 6px 10px 10px; min-width: 0; }
.side-user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #e8edf2; font-weight: 500; }
.avatar {
  width: 26px; height: 26px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--side-active); color: var(--side-accent);
  font-size: 12px; font-weight: 700;
}

.side-btn {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 8px 10px;
  border: 0; border-radius: var(--r-s);
  background: transparent; color: var(--side-text);
  text-align: left; cursor: pointer;
}
.side-btn:hover { background: var(--side-hover); color: #fff; }
.side-btn .icon { color: var(--side-muted); }

.main { min-width: 0; padding: 28px clamp(16px, 3vw, 40px) 56px; outline: none; }
.page { max-width: 1240px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

/* Page header */

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 4px; }
.page-head-text { min-width: 0; }
.page-title { font-size: 24px; line-height: 1.25; font-weight: 650; letter-spacing: -0.02em; }
.page-sub { color: var(--muted); margin-top: 3px; }
.page-actions { display: flex; align-items: center; gap: 10px; }

/* Buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--r-s);
  font-weight: 550; white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.btn .icon { width: 17px; height: 17px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.93); }
.btn.is-done { background: var(--ok); color: #fff; }

.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy .icon { visibility: hidden; }
.btn.is-busy::after {
  content: ""; position: absolute; width: 16px; height: 16px;
  border: 2px solid currentColor; border-radius: 50%;
  border-color: var(--muted); border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
.btn-primary.is-busy::after, .btn-danger.is-busy::after { border-color: rgba(255, 255, 255, 0.85); border-right-color: transparent; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: var(--r-s);
  background: transparent; color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.icon-btn-danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn.is-busy .icon { animation: spin 0.8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* Cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-card);
  min-width: 0;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 620; display: flex; align-items: center; gap: 8px; }
.card-title label { cursor: pointer; }
.card-sub { color: var(--muted); margin-top: 2px; font-size: 13px; max-width: 70ch; }
.card-count {
  display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--ok-soft); color: var(--ok); font-size: 12px; font-weight: 650;
}
.card-count:empty { display: none; }
.card-link { font-size: 13px; font-weight: 550; }
.card-body { padding: 16px 18px; }
.card-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 12px 18px; border-top: 1px solid var(--border);
  background: var(--surface-2); border-radius: 0 0 var(--r-m) var(--r-m);
}
.card.is-loading .card-body { opacity: 0.5; pointer-events: none; }

.stack { display: flex; flex-direction: column; gap: 18px; }
.stack-narrow { max-width: 880px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }

/* Dashboard */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: 18px 20px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--border); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 28px; line-height: 1.2; font-weight: 650; letter-spacing: -0.02em; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; min-height: 1.5em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.flows { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.flow-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.flow-label .icon { width: 15px; height: 15px; }
.flow:first-child .flow-label .icon { color: var(--accent); }
.flow:last-child .flow-label .icon { color: var(--accent-2); }
.flow-value { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; margin-top: 4px; }
.flow-rate { color: var(--muted); font-size: 12.5px; }

.split { display: flex; height: 8px; margin-top: 18px; border-radius: 4px; overflow: hidden; background: var(--surface-3); gap: 2px; }
.split-up { background: var(--accent); }
.split-down { background: var(--accent-2); }
.split-up, .split-down { transition: width 0.4s ease; }
.split-empty { gap: 0; }

.kvs { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; padding-top: 6px; padding-bottom: 6px; }
.kv { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.kv:nth-last-child(-n + 2) { border-bottom: 0; }
.kv-label { color: var(--text-2); }
.kv-value { font-weight: 620; }

.live { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.is-stale .live-dot { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }

/* Tables */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 10px 14px;
  text-align: left; font-size: 12.5px; font-weight: 550; color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; white-space: nowrap; }
.table th:first-child, .table td:first-child { padding-left: 18px; }
.table th:last-child, .table td:last-child { padding-right: 14px; }
.card > .table-wrap:first-child .table th:first-child { border-top-left-radius: var(--r-m); }
.card > .table-wrap:first-child .table th:last-child { border-top-right-radius: var(--r-m); }
.actions-col { width: 1%; text-align: right; white-space: nowrap; }

.cell-title { font-weight: 600; overflow-wrap: anywhere; }
.cell-sub { color: var(--muted); font-size: 12.5px; }
.clamp { max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.clients-table td { white-space: nowrap; }
.clients-table td.c-name { white-space: normal; min-width: 150px; }
.clients-table tr.is-off .c-name .cell-title { color: var(--text-2); }
.c-traffic { min-width: 170px; }
.c-actions { text-align: right; width: 1%; }
.row-actions { display: inline-flex; gap: 2px; }

.traffic-line { display: flex; align-items: baseline; gap: 0; }
.traffic-used { font-weight: 600; }
.traffic-of { color: var(--muted); font-size: 12.5px; white-space: pre; }
.traffic-split { display: flex; gap: 12px; color: var(--muted); font-size: 12px; margin-top: 2px; }
.traffic-split span { display: inline-flex; align-items: center; gap: 2px; }
.traffic-split .icon { width: 12px; height: 12px; stroke-width: 2; }
.traffic-split span:first-child .icon { color: var(--accent); }
.traffic-split span:last-child .icon { color: var(--accent-2); }

/* Two-tone usage meter: upload then download, against the limit. */
.meter {
  display: flex; gap: 1px;
  width: 100%; max-width: 180px; height: 6px; margin-top: 6px;
  border-radius: 3px; overflow: hidden;
  background: var(--surface-3);
}
.meter-up { background: var(--accent); }
.meter-down { background: var(--accent-2); }
.meter-warn .meter-up { background: var(--warn); }
.meter-warn .meter-down { background: color-mix(in srgb, var(--warn) 55%, transparent); }
.meter-danger .meter-up { background: var(--danger); }
.meter-danger .meter-down { background: color-mix(in srgb, var(--danger) 55%, transparent); }

.inline-confirm { display: inline-flex; align-items: center; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.inline-confirm-text { font-size: 13px; font-weight: 550; color: var(--text-2); max-width: 26ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Badges */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 9px;
  border-radius: 11px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: var(--neutral-soft); color: var(--text-2); }

/* Toolbar, search, segmented */

.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.search { position: relative; flex: 1 1 260px; max-width: 380px; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; pointer-events: none; }
.search .search-input { padding-left: 34px; }

.segmented {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--surface-3); border-radius: var(--r-s);
  max-width: 100%; overflow-x: auto;
}
.segmented-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 11px;
  border: 0; border-radius: var(--r-xs);
  background: transparent; color: var(--text-2);
  font-size: 13px; font-weight: 550; white-space: nowrap; cursor: pointer;
}
.segmented-btn:hover { color: var(--text); }
.segmented-btn[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12); }
.seg-count { color: var(--muted); font-weight: 500; font-size: 12px; }

/* Forms */

.input {
  display: block; width: 100%;
  height: 38px; padding: 0 11px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-s);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input::placeholder { color: var(--muted); opacity: 0.8; }
.input:hover:not(:disabled):not(:focus) { border-color: color-mix(in srgb, var(--border-strong) 60%, var(--text) 40%); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"], .input[aria-invalid=""] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus, .input[aria-invalid=""]:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.input[readonly] { background: var(--surface-2); }
.textarea { height: auto; min-height: 64px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
input[type="date"].input { padding-right: 6px; }
input[type="number"].input { -moz-appearance: textfield; appearance: textfield; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-weight: 550; font-size: 13px; color: var(--text-2); }
.field-hint { color: var(--muted); font-size: 12.5px; }
.field-error { color: var(--danger); font-size: 12.5px; font-weight: 500; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-inline { flex-direction: row; align-items: flex-start; gap: 12px; }
.field-inline .field-label { cursor: pointer; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-grid > .alert, .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 26px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 13px;
  background: var(--surface-2); color: var(--text-2);
  font-size: 12.5px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

.advanced { border-top: 1px solid var(--border); padding-top: 12px; }
.advanced summary { cursor: pointer; color: var(--text-2); font-weight: 550; font-size: 13px; margin-bottom: 4px; }
.advanced[open] summary { margin-bottom: 12px; }

/* Switch */

.switch { position: relative; display: inline-flex; flex: none; cursor: pointer; }
.switch-input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track {
  width: 36px; height: 20px; border-radius: 10px;
  background: var(--border-strong);
  transition: background-color 0.15s;
  display: flex; align-items: center; padding: 2px;
}
.switch-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s;
}
.switch-input:checked + .switch-track { background: var(--accent); }
.switch-input:checked + .switch-track .switch-thumb { transform: translateX(16px); }
.switch-input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch-input:disabled + .switch-track { opacity: 0.55; }

/* Settings rows (protocol) */

.settings-list > .setting + .setting { border-top: 1px solid var(--border); }
.setting {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 8px 32px;
  padding: 16px 18px; align-items: start;
}
.setting-label { font-weight: 600; display: block; }
.setting-hint { color: var(--muted); font-size: 13px; margin-top: 2px; max-width: 60ch; }
.card-body > .setting-hint { margin: 0 0 10px; }
.setting-control { display: flex; flex-direction: column; gap: 6px; }
.range-inputs { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.num-input { width: 108px; }
.range-sep, .unit { color: var(--muted); font-size: 13px; }
.field-hint-inline { color: var(--muted); font-size: 12.5px; }

/* Alerts */

.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px;
  border-radius: var(--r-s);
  font-size: 13.5px;
}
.alert .icon { margin-top: 1px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-error .alert-text { color: var(--text); }
.alert-info { background: var(--accent-soft); color: var(--accent); }
.alert-info .alert-text { color: var(--text); }
.alert-text { overflow-wrap: anywhere; }

/* Empty and loading */

.empty { padding: 44px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty-title { font-weight: 620; font-size: 15px; }
.empty-text { color: var(--muted); max-width: 46ch; margin-bottom: 10px; }

.skeleton-list { padding: 8px 18px; }
.skeleton-row { height: 44px; margin: 10px 0; border-radius: var(--r-s); background: var(--surface-3); opacity: 0.7; }
.skeleton-row:nth-child(2) { opacity: 0.5; }
.skeleton-row:nth-child(3) { opacity: 0.3; }

/* Modal */

.modal {
  padding: 0; border: 0;
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  border-radius: var(--r-l);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.modal-wide { width: min(800px, calc(100vw - 24px)); }
.modal::backdrop { background: var(--backdrop); }
.modal[open] { animation: modal-in 0.16s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(6px) scale(0.985); } }
.modal-inner { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 16px 12px 22px; }
.modal-title { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.modal-body { padding: 4px 22px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-body > * { flex-shrink: 0; }
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px 12px 22px;
  border-top: 1px solid var(--border); background: var(--surface-2);
}
.modal-foot-left { margin-right: auto; display: flex; align-items: center; min-width: 0; }

/* Link dialog */

.link-panel { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 22px; align-items: start; }
.qr-box {
  width: 296px; height: 296px; max-width: 100%;
  display: grid; place-items: center;
  padding: 8px;
  border-radius: var(--r-m);
  background: var(--qr-bg);
  border: 1px solid var(--border);
}
.qr-box.is-loading .qr-img { opacity: 0.25; }
.qr-img { width: 100%; height: auto; aspect-ratio: 1; max-width: 280px; }
.qr-msg { color: #5d6878; font-size: 13px; text-align: center; padding: 16px; }
.link-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.link-hint { color: var(--muted); font-size: 13px; }
.link-text { min-height: 96px; font-size: 12.5px; word-break: break-all; resize: none; }
.link-actions { display: flex; gap: 8px; }

/* Toasts */

.toasts {
  position: fixed; z-index: 100;
  right: 20px; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px;
  width: 360px; max-width: 100%;
  padding: 11px 10px 11px 14px;
  border-radius: var(--r-m);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  box-shadow: var(--shadow-pop);
  animation: toast-in 0.18s ease-out;
}
.toast-success { border-left-color: var(--ok); }
.toast-success .toast-icon { color: var(--ok); }
.toast-error { border-left-color: var(--danger); }
.toast-error .toast-icon { color: var(--danger); }
.toast-info .toast-icon { color: var(--accent); }
.toast-icon { margin-top: 1px; }
.toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-close { border: 0; background: transparent; color: var(--muted); padding: 2px; border-radius: var(--r-xs); cursor: pointer; display: grid; }
.toast-close:hover { color: var(--text); background: var(--surface-3); }
.toast-close .icon { width: 15px; height: 15px; }
.toast-out { opacity: 0; transform: translateY(4px); transition: opacity 0.18s, transform 0.18s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Login */

.login-page {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent 70%),
    var(--bg);
}
.login-card {
  width: min(380px, 100%);
  display: flex; flex-direction: column; gap: 16px;
  padding: 30px 28px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-pop);
}
.login-brand { display: flex; align-items: center; gap: 10px; color: var(--accent); margin-bottom: 6px; }
.login-mark { width: 34px; height: 34px; }
.login-name { color: var(--text); font-size: 21px; font-weight: 650; letter-spacing: -0.02em; }
.login-title { font-size: 19px; font-weight: 650; letter-spacing: -0.01em; }
.login-sub { color: var(--muted); margin-top: -10px; }
.login-card .btn { height: 40px; margin-top: 4px; }
.login-sso { display: flex; flex-direction: column; gap: 14px; }
.login-or {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 12.5px;
}
.login-or::before, .login-or::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* Responsive */

@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n + 3) { border-top: 1px solid var(--border); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .clients-table .c-seen { display: none; }
  .clients-table th:nth-child(5) { display: none; }
}

@media (max-width: 820px) {
  .shell { display: block; }
  .sidebar {
    position: sticky; top: 0; z-index: 20;
    height: auto;
    flex-direction: row; align-items: center; gap: 8px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
  }
  .brand-mark { width: 24px; height: 24px; }
  .brand-name { font-size: 17px; }
  .nav {
    position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(68px, 1fr); gap: 0;
    overflow-x: auto; scrollbar-width: none;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--side-bg);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }
  .nav-link { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 11.5px; justify-content: center; }
  .nav-link[aria-current="page"]::before { left: 30%; right: 30%; top: -6px; bottom: auto; width: auto; height: 2px; border-radius: 0 0 2px 2px; }
  .side-foot { margin: 0 0 0 auto; flex-direction: row; border: 0; padding: 0; gap: 2px; }
  .side-user { display: none; }
  .side-btn { width: 36px; height: 36px; padding: 0; justify-content: center; }
  .side-btn-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .main { padding: 18px 16px calc(88px + env(safe-area-inset-bottom, 0px)); }
  .page-title { font-size: 21px; }
  .toasts { left: 16px; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); align-items: stretch; }
  .toast { width: auto; }
  .setting { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 720px) {
  .stat { padding: 14px 16px; }
  .stat-value { font-size: 23px; }
  .kvs { grid-template-columns: 1fr; }
  .kv:nth-last-child(2) { border-bottom: 1px solid var(--border); }
  .form-grid, .field-row { grid-template-columns: minmax(0, 1fr); }
  .search { max-width: none; flex-basis: 100%; }
  .link-panel { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  .link-side { width: 100%; }
  .modal-body { padding: 4px 16px 18px; }
  .modal-head { padding-left: 16px; }
  .modal-foot { padding-left: 16px; }

  /* Clients table becomes a list of cards. */
  .clients-table thead { display: none; }
  .clients-table, .clients-table tbody { display: block; }
  .clients-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name status" "traffic traffic" "exp exp" "enabled actions";
    gap: 10px 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
  }
  .clients-table tbody tr:last-child { border-bottom: 0; }
  .clients-table td { display: block; padding: 0 !important; border: 0; white-space: normal; background: transparent !important; }
  .clients-table td.c-name { grid-area: name; min-width: 0; }
  .clients-table td.c-status { grid-area: status; justify-self: end; }
  .clients-table td.c-traffic { grid-area: traffic; min-width: 0; }
  .clients-table td.c-exp { grid-area: exp; display: flex; gap: 8px; align-items: baseline; }
  .clients-table td.c-exp::before { content: "Active until"; color: var(--muted); font-size: 12.5px; }
  .clients-table td.c-seen { display: none; }
  .clients-table td.c-enabled { grid-area: enabled; align-self: center; }
  .clients-table td.c-actions { grid-area: actions; width: auto; }
  .clients-table .meter { max-width: none; }
  .clamp { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .btn.is-busy::after, .icon-btn.is-busy .icon { animation-duration: 1.4s !important; animation-iteration-count: infinite !important; }
}

/* Xray page */
.xray-editor { min-height: 420px; font-size: 12.5px; line-height: 1.5; tab-size: 2; white-space: pre; overflow-wrap: normal; overflow-x: auto; }
.xray-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px; }
.xray-tag-label { font-size: 12px; color: var(--text-2); margin-left: 6px; }
.xray-tag-label:first-child { margin-left: 0; }

/* Xray pages: inbounds, outbounds, routing */
.stack-tight { display: flex; flex-direction: column; gap: 14px; }
.form-section { font-size: 13px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; padding-top: 6px; border-top: 1px solid var(--border); }
.field-gen { position: absolute; right: 0; top: -4px; }
.field:has(> .field-gen) { position: relative; }
.inbound-head { min-width: 0; }
.inbound-actions { flex-wrap: nowrap; align-items: center; }
.check-group { display: flex; flex-wrap: wrap; gap: 6px; }
.check-chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); font-size: 13px; cursor: pointer; }
.check-chip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.check-chip input { margin: 0; accent-color: var(--accent); }
.import-row { display: flex; gap: 8px; align-items: center; }
.import-row .input { flex: 1; min-width: 0; }
.mono-sm { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
.page-note { margin-top: 12px; }
.order-table td.num, .order-table th.num { width: 36px; }
.rule-match { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.rule-part { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.rule-key { color: var(--muted); font-size: 12.5px; }
.rules-table tr.is-off .c-match, .rules-table tr.is-off .c-target { opacity: 0.5; }
.strategy-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.strategy-control { display: flex; gap: 8px; align-items: center; min-width: min(100%, 360px); }
.strategy-control select { flex: 1; min-width: 0; }
select.input { padding-right: 28px; }
@media (max-width: 720px) {
  .card-head:has(.inbound-actions) { flex-wrap: wrap; }
  .xclients-table tr { grid-template-areas: "name status" "traffic traffic" "exp exp" "enabled actions"; }
  .order-table thead { display: none; }
  .order-table, .order-table tbody { display: block; }
  .order-table tr { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .order-table td { display: block; padding: 0 !important; border: 0; background: transparent !important; }
  .order-table td.c-actions { grid-column: 1 / -1; justify-self: end; width: auto; }
  .rules-table td.c-match { grid-column: 1 / -1; }
  .import-row { flex-wrap: wrap; }
}

/* Route log */
.rl-toolbar .search { max-width: 340px; }
.rl-filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.rl-filters select { width: auto; max-width: 180px; }
.rl-test-grid { display: grid; grid-template-columns: minmax(180px, 2fr) 90px 100px 130px minmax(120px, 1fr) minmax(120px, 1fr) auto; gap: 12px; align-items: end; }
.rl-test-go { justify-self: start; }
.rl-result { margin-top: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; min-height: 22px; }
.rl-ob { --h: 205; color: hsl(var(--h) 60% 32%); background: hsl(var(--h) 65% 93%); }
.rl-n { font-weight: 500; opacity: 0.75; }
.rl-outs { display: flex; flex-wrap: wrap; gap: 4px; }
.rl-rule { font-size: 13px; color: var(--text-2); }
.rl-default { font-size: 13px; color: var(--muted); font-style: italic; }
.rl-rules { display: flex; flex-wrap: wrap; gap: 2px 10px; }
.rl-chip { display: inline-block; padding: 0 6px; border-radius: var(--r-xs); background: var(--surface-3); color: var(--text-2); font-size: 11.5px; line-height: 18px; font-family: var(--mono); }
.rl-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; margin-top: 2px; }
.rl-nodomain { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rl-time { white-space: nowrap; width: 1%; }
.rl-err { color: var(--danger); font-size: 12.5px; }
.rl-table td { padding-top: 8px; padding-bottom: 8px; }
.rl-table tr.is-split td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.rl-table tr.is-err td { background: var(--danger-soft); }
.rl-more { margin-top: 8px; }
.rl-split .card-head { flex-wrap: wrap; gap: 10px; }
.rl-tip-list { margin: 10px 0 0; padding-left: 18px; color: var(--text-2); display: flex; flex-direction: column; gap: 6px; max-width: 90ch; }
.rl-tip-list .icon { width: 14px; height: 14px; vertical-align: -2px; }
.rl-tips .card-title .icon { color: var(--muted); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .rl-ob { color: hsl(var(--h) 70% 74%); background: hsl(var(--h) 35% 20%); }
}
:root[data-theme="dark"] .rl-ob { color: hsl(var(--h) 70% 74%); background: hsl(var(--h) 35% 20%); }
@media (max-width: 1100px) {
  .rl-test-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .rl-test-grid > .field:first-child { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .rl-test-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rl-filters { width: 100%; }
  .rl-filters select { flex: 1; max-width: none; }
}
