@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Палитра: тёмная слейт-синева (не чёрный), три статусных акцента вместо одного. */
  --bg: #0B0E14;
  --surface: #121722;
  --surface-raised: #1A2130;
  --border: #262E40;
  --border-soft: #1D2434;
  --text: #E7EAF2;
  --text-muted: #8A93AB;
  --text-faint: #5B6478;

  --accent: #4C9FE8;
  --accent-dim: #2C4C6E;
  --ok: #3ADC8C;
  --ok-dim: #1E4A34;
  --warn: #F0B443;
  --warn-dim: #4E3E1A;
  --orange: #FF8A3D;
  --orange-dim: #57301D;
  --danger: #EC5D6A;
  --danger-dim: #4E222A;

  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --radius: 6px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, .mono { font-family: var(--font-mono); }

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, var(--surface), var(--bg));
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  font-family: var(--font-mono);
  color: var(--ok);
  letter-spacing: 2px;
  font-size: 13px;
}
.brand-name { font-size: 16px; }

.topnav { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.mobile-nav { display: none; position: relative; z-index: 50; }
.mobile-nav > summary { list-style: none; cursor: pointer; }
.mobile-nav > summary::-webkit-details-marker { display: none; }
.mobile-nav-popover {
  position: absolute; top: calc(100% + 8px); right: 0; width: min(290px, calc(100vw - 32px));
  padding: 8px; border: 1px solid var(--border); border-radius: 10px; background: #121722;
  box-shadow: 0 18px 50px rgba(0,0,0,.55);
}
.mobile-nav-popover a, .mobile-nav-popover button {
  display: flex; width: 100%; min-height: 42px; align-items: center; padding: 9px 11px;
  border: 0; border-radius: 6px; background: transparent; color: var(--text);
  font: 500 14px var(--font-body); text-align: left; cursor: pointer;
}
.mobile-nav-popover a:hover, .mobile-nav-popover button:hover { background: rgba(77,163,255,.09); text-decoration: none; }
.mobile-nav-popover form { margin: 6px 0 0; padding-top: 6px; border-top: 1px solid var(--border-soft); }
.inline-form { display: inline-flex; margin: 0; }
.nav-action, .nav-user {
  min-height: 36px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 12px;
  background: var(--surface-raised); color: var(--text-muted); font: 500 13px var(--font-body);
  line-height: 1; white-space: nowrap;
}
.topnav .nav-action:hover { color: var(--text); border-color: var(--text-faint); text-decoration: none; }
.topnav .nav-action-accent { color: var(--accent); border-color: var(--accent-dim); background: rgba(76,159,232,.09); }
.topnav .nav-action-accent:hover { background: rgba(76,159,232,.17); border-color: var(--accent); }
.nav-user { color: var(--text-faint); background: transparent; font-family: var(--font-mono); }
button.nav-action { cursor: pointer; }
.topnav .nav-action-danger:hover { color: var(--danger); border-color: var(--danger-dim); background: rgba(236,93,106,.09); }

@media (max-width: 720px) {
  .topbar { align-items: center; padding: 12px 16px; gap: 12px; }
  .topnav-desktop { display: none; }
  .mobile-nav { display: block; }
}

/* ---------- Layout ---------- */

.shell {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  padding: 32px 28px 80px;
}

.footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
  padding: 24px;
  border-top: 1px solid var(--border-soft);
}
.footer code { color: var(--text-faint); }

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-header > div:first-child { min-width: 0; flex: 1 1 360px; }
.page-header h1, .page-header .sub, .crumbs { overflow-wrap: anywhere; }
.page-header h1 { margin: 0; font-size: 22px; }
.page-header .sub { color: var(--text-muted); font-size: 14px; margin-top: 4px; }
.crumbs { color: var(--text-faint); font-family: var(--font-mono); font-size: 13px; margin-bottom: 6px; }
.crumbs a { color: var(--text-muted); }

/* ---------- Flash / signature "receipt" ---------- */

.flash {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 24px;
  background: var(--surface);
}
.flash-success { border-color: var(--ok-dim); }
.flash-warning { border-color: var(--warn); }
.flash-error { border-color: var(--danger-dim); }
.flash-message { font-size: 14px; }
.flash-success .flash-message { color: var(--ok); }
.flash-warning .flash-message { color: var(--warn); }
.flash-error .flash-message { color: var(--danger); }
.flash-trace {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-faint);
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  font-family: var(--font-body);
}
.btn:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0B121C; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

/* ---------- Channel speed-test result ---------- */

.speedtest-dialog {
  width: min(820px, calc(100vw - 32px));
  max-width: 100%;
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  color: var(--text);
  color-scheme: dark;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #121722;
  box-shadow: 0 30px 100px rgba(0,0,0,.72);
}
.speedtest-dialog[open] { display: flex; flex-direction: column; }
.speedtest-dialog::backdrop { background: rgba(4,7,12,.78); backdrop-filter: blur(3px); }
.speedtest-dialog-head {
  display: flex; flex: 0 0 auto; align-items: flex-start; justify-content: space-between; gap: 18px;
  padding: 18px 20px; border-bottom: 1px solid var(--border-soft); background: var(--surface);
}
.speedtest-dialog-head > div { min-width: 0; }
.speedtest-dialog-head h2 { margin: 3px 0 0; font-size: 21px; overflow-wrap: anywhere; }
.speedtest-dialog-body { min-height: 0; padding: 20px; overflow: auto; overscroll-behavior: contain; }
.speedtest-dialog-actions {
  display: flex; flex: 0 0 auto; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--border-soft); background: var(--surface);
}
.speedtest-dialog-actions form { display: inline-flex; margin: 0; }
.speed-result-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.speedtest-dialog .speed-quality-grid { grid-template-columns: minmax(0, 1fr); }
.speedtest-error {
  display: flex; flex-direction: column; gap: 7px; padding: 16px;
  border: 1px solid var(--danger-dim); border-radius: 10px; background: rgba(236,93,106,.07);
}
.speedtest-error strong { color: var(--danger); }
.speedtest-error span { color: var(--text-muted); line-height: 1.55; overflow-wrap: anywhere; }

.speed-result-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 18px 0; }
.speed-result-head h1 { margin: 3px 0 0; font-size: clamp(22px, 3vw, 30px); }
.speed-result-kicker { color: var(--text-muted); font: 12px/1.4 var(--font-mono); overflow-wrap: anywhere; }
.speed-direction-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.speed-direction-card { min-width: 0; padding: 20px; border: 1px solid var(--accent-dim); border-radius: 12px; background: linear-gradient(145deg, rgba(76,159,232,.12), var(--surface) 62%); }
.speed-direction-slower { border-color: var(--warn-dim); background: linear-gradient(145deg, rgba(240,180,67,.10), var(--surface) 62%); }
.speed-direction-label { min-height: 42px; color: var(--text-muted); font-size: 13px; line-height: 1.4; }
.speed-direction-value { margin-top: 12px; color: var(--text); font: 700 clamp(38px, 7vw, 64px)/.95 var(--font-mono); letter-spacing: -.06em; overflow-wrap: anywhere; }
.speed-direction-unit { margin-top: 8px; color: var(--accent); font: 700 13px var(--font-mono); }
.speed-direction-slower .speed-direction-unit { color: var(--warn); }
.speed-direction-path { margin-top: 18px; color: var(--text-faint); font-size: 11px; overflow-wrap: anywhere; }
.speed-result-notice { display: flex; align-items: baseline; gap: 8px 12px; flex-wrap: wrap; margin-top: 14px; padding: 13px 15px; border: 1px solid var(--warn-dim); border-radius: 9px; background: rgba(240,180,67,.06); }
.speed-result-notice strong { color: var(--warn); }
.speed-result-notice span { color: var(--text-muted); font-size: 13px; }
.speed-quality-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.speed-quality-item { min-width: 0; padding: 14px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.speed-quality-item span, .speed-quality-item small { display: block; color: var(--text-faint); font-size: 11px; }
.speed-quality-item strong { display: block; margin: 6px 0 3px; color: var(--text); font: 700 18px var(--font-mono); overflow-wrap: anywhere; }
.speed-quality-item .speed-value-warn { color: var(--warn); }
.speed-result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.speed-result-actions form { display: inline-flex; margin: 0; }

@media (max-width: 720px) {
  .speed-result-head { align-items: stretch; flex-direction: column; }
  .speed-result-head .badge { align-self: flex-start; }
  .speed-quality-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .speedtest-dialog { width: calc(100vw - 12px); max-height: calc(100dvh - 12px); border-radius: 11px; }
  .speedtest-dialog-head { gap: 10px; padding: 14px; }
  .speedtest-dialog-head h2 { font-size: 18px; }
  .speedtest-dialog-body { padding: 14px; }
  .speed-result-summary { align-items: flex-start; flex-direction: column; }
  .speedtest-dialog-actions { align-items: stretch; flex-direction: column; padding: 12px 14px; }
  .speedtest-dialog-actions form, .speedtest-dialog-actions .btn { width: 100%; }
  .speedtest-dialog-actions .btn { justify-content: center; }
  .speed-direction-grid, .speed-quality-grid { grid-template-columns: 1fr; }
  .speed-direction-card { padding: 17px; }
  .speed-direction-label { min-height: 0; }
  .speed-direction-value { font-size: clamp(38px, 16vw, 56px); }
  .speed-result-notice { align-items: flex-start; flex-direction: column; }
  .speed-result-actions, .speed-result-actions form, .speed-result-actions .btn { width: 100%; }
  .speed-result-actions .btn { justify-content: center; }
}

.create-menu { position: relative; z-index: 20; }
.create-menu > summary { list-style: none; }
.create-menu > summary::-webkit-details-marker { display: none; }
.create-menu-popover {
  position: absolute; top: calc(100% + 8px); right: 0; width: 220px; padding: 8px;
  border: 1px solid var(--border); border-radius: 10px; background: #121722;
  box-shadow: 0 18px 50px rgba(0,0,0,.48);
}
.create-menu-popover a { display: block; padding: 9px 10px; border-radius: 6px; color: var(--text); font-size: 14px; }
.create-menu-popover a:hover { background: rgba(77,163,255,.09); text-decoration: none; }
.create-menu-label { display: block; padding: 8px 10px 4px; color: var(--text-faint); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.create-menu-label:not(:first-child) { margin-top: 6px; border-top: 1px solid var(--border-soft); padding-top: 12px; }

/* ---------- Cards / grid ---------- */

/* ---------- Live dashboard ---------- */

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 30px;
}
.dashboard-tile {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(26,33,48,.96), rgba(18,23,34,.96));
  box-shadow: 0 10px 28px rgba(0,0,0,.16);
  padding: 18px;
}
.dashboard-tile-wide { grid-column: span 2; }
.dashboard-tile-alert { border-color: var(--danger-dim); }
.dashboard-tile-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 15px; }
.dashboard-tile-head > * { min-width: 0; }
.dashboard-tile-head h2, .dashboard-section-head h2 { margin: 3px 0 0; font-size: 17px; line-height: 1.3; }
.dashboard-eyebrow { display: block; color: var(--text-faint); font: 10px/1.4 var(--font-mono); letter-spacing: .06em; text-transform: uppercase; overflow-wrap: anywhere; }
.dashboard-eyebrow b { color: var(--text-muted); font-weight: 500; }
.dashboard-head-value { color: var(--text); font: 700 25px/1 var(--font-mono); white-space: nowrap; }
.live-indicator { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); font: 11px var(--font-mono); }
.live-indicator i, .client-online-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px rgba(58,220,140,.09); }
.dashboard-offline .live-indicator { color: var(--danger); }
.dashboard-offline .live-indicator i { background: var(--danger); }
.dashboard-metrics { display: flex; gap: 28px; margin-bottom: 10px; }
.dashboard-metrics div { display: flex; min-width: 0; flex-direction: column; }
.dashboard-metrics span { color: var(--text-faint); font-size: 11px; }
.dashboard-metrics strong { margin-top: 3px; color: var(--text); font: 700 clamp(20px, 2.3vw, 30px)/1.2 var(--font-mono); overflow-wrap: anywhere; }
.dashboard-metrics div:first-child strong { color: var(--accent); }
.dashboard-metrics div:last-child strong { color: var(--ok); }
.dashboard-chart-wrap { width: 100%; height: 170px; margin: 5px -2px 0; }
.dashboard-chart-cpu { height: 142px; }
.dashboard-chart { display: block; width: 100%; height: 100%; }
.dashboard-chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; color: var(--text-faint); font-size: 11px; }
.dashboard-chart-legend span::before { content: ""; display: inline-block; width: 14px; height: 2px; margin: 0 6px 3px 0; background: currentColor; }
.dashboard-chart-legend .legend-rx { color: var(--accent); }
.dashboard-chart-legend .legend-tx { color: var(--ok); }
.dashboard-chart-legend small { margin-left: auto; color: var(--text-faint); }
.dashboard-resource-row { display: flex; justify-content: space-between; gap: 10px; color: var(--text-muted); font: 11px var(--font-mono); }
.dashboard-client-list, .dashboard-issue-list { max-height: 250px; overflow: auto; padding-right: 3px; }
.dashboard-client-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border-soft); }
.dashboard-client-row:first-child { border-top: 0; padding-top: 0; }
.dashboard-client-row div { min-width: 0; }
.dashboard-client-row strong, .dashboard-client-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dashboard-client-row strong { font-size: 13px; }
.dashboard-client-row small { color: var(--text-faint); font-size: 10px; }
.dashboard-client-address { text-align: right; }
.dashboard-client-address span { color: var(--text-muted); font-size: 11px; }
.dashboard-client-address small { margin-top: 2px; }
.dashboard-speed-candidates { display: flex; flex-wrap: wrap; gap: 8px; }
.dashboard-speed-candidates form { margin: 0; }
.server-traffic-list { display: grid; gap: 11px; }
.server-traffic-row { display: grid; grid-template-columns: minmax(110px, .7fr) minmax(150px, 1.7fr) minmax(135px, .7fr); align-items: center; gap: 13px; }
.server-traffic-name, .server-traffic-values { min-width: 0; }
.server-traffic-name strong, .server-traffic-name small, .server-traffic-values strong, .server-traffic-values small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server-traffic-name strong { font-size: 13px; }
.server-traffic-name small, .server-traffic-values small { color: var(--text-faint); font-size: 10px; }
.server-traffic-values { text-align: right; }
.server-traffic-values strong { font: 600 12px var(--font-mono); }
.server-traffic-meter { height: 9px; overflow: hidden; border-radius: 999px; background: var(--bg); box-shadow: inset 0 0 0 1px var(--border-soft); }
.server-traffic-meter span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--ok)); transition: width .35s ease; }
.dashboard-issue { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; padding: 9px 0; border-top: 1px solid var(--border-soft); }
.dashboard-issue:first-child { border-top: 0; padding-top: 0; }
.dashboard-issue > span { display: grid; width: 20px; height: 20px; place-items: center; border-radius: 50%; color: var(--danger); background: var(--danger-dim); font: 700 11px var(--font-mono); }
.dashboard-issue p { margin: 0; color: var(--text-muted); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; }
.dashboard-health-ok, .dashboard-speed-match { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 13px; border: 1px solid var(--ok-dim); border-radius: 9px; background: rgba(58,220,140,.05); }
.dashboard-health-ok > span { color: var(--ok); font-size: 20px; }
.dashboard-health-ok strong, .dashboard-health-ok small, .dashboard-speed-match strong, .dashboard-speed-match small { display: block; }
.dashboard-health-ok small, .dashboard-speed-match small { margin-top: 2px; color: var(--text-faint); font-size: 11px; }
.dashboard-speed-unmatched { padding: 13px; border: 1px solid var(--border); border-radius: 9px; color: var(--text-muted); background: var(--bg); font-size: 12px; line-height: 1.5; }
.dashboard-tile-text { margin: 13px 0; color: var(--text-faint); font-size: 11px; line-height: 1.5; }
.dashboard-speed-tile form, .dashboard-speed-tile .btn { width: 100%; }
.dashboard-speed-tile .btn { justify-content: center; }
.dashboard-tunnel-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 12px; }
.dashboard-tunnel-form label { min-width: 0; }
.dashboard-tunnel-form label > span { display: block; margin-bottom: 6px; color: var(--text-muted); font-size: 12px; }
.dashboard-tunnel-form select { width: 100%; }
.dashboard-empty-compact { padding: 22px 10px; color: var(--text-faint); text-align: center; font-size: 12px; }
.dashboard-section-head { display: flex; align-items: flex-end; justify-content: space-between; margin: 30px 0 14px; }

@media (max-width: 1180px) {
  .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-tile-wide { grid-column: span 2; }
}
@media (max-width: 700px) {
  .dashboard-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .dashboard-tile, .dashboard-tile-wide { grid-column: 1; padding: 15px; }
  .dashboard-chart-wrap { height: 150px; }
  .dashboard-chart-cpu { height: 125px; }
  .dashboard-metrics { gap: 16px; justify-content: space-between; }
  .dashboard-metrics > div { flex: 1 1 0; }
  .dashboard-chart-legend small { width: 100%; margin-left: 0; }
  .server-traffic-row { grid-template-columns: minmax(0, 1fr) auto; gap: 7px 10px; }
  .server-traffic-meter { grid-column: 1 / -1; grid-row: 2; }
  .server-traffic-values { grid-column: 2; grid-row: 1; }
  .dashboard-tunnel-form { grid-template-columns: 1fr; }
  .dashboard-tunnel-form .btn { width: 100%; justify-content: center; }
}
@media (max-width: 420px) {
  .dashboard-tile-head { gap: 9px; }
  .dashboard-tile-head h2 { font-size: 15px; }
  .dashboard-head-value { font-size: 21px; }
  .dashboard-client-row { grid-template-columns: auto minmax(0, 1fr); }
  .dashboard-client-address { grid-column: 2; text-align: left; }
  .dashboard-speed-candidates, .dashboard-speed-candidates form, .dashboard-speed-candidates .btn { width: 100%; }
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.server-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  display: block;
  color: var(--text);
}
.server-card:hover { border-color: var(--accent); text-decoration: none; }
.server-card-head { display: flex; justify-content: space-between; align-items: center; }
.server-card-name { font-weight: 600; font-size: 16px; }
.server-card-meta { color: var(--text-muted); font-family: var(--font-mono); font-size: 12.5px; margin-top: 6px; }
.server-card-summary { margin-top: 12px; font-size: 13px; color: var(--text-muted); }

.server-list { display: flex; flex-direction: column; gap: 10px; }
.server-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.1fr) minmax(210px, 1.5fr) minmax(150px, 1fr) auto;
  align-items: center;
  gap: 16px;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.server-row:hover { border-color: var(--accent-dim); }
.server-row > * { min-width: 0; }
.server-row-main, .server-row-actions { display: flex; align-items: center; gap: 10px; }
.server-row-main { min-width: 0; flex-wrap: wrap; }
.server-row-main .server-card-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server-row-endpoint { margin-top: 0; overflow: hidden; overflow-wrap: anywhere; text-overflow: ellipsis; white-space: nowrap; }
.server-row .server-card-summary { margin-top: 0; white-space: nowrap; }
.server-row-actions { justify-content: flex-end; }
.server-row-actions form { display: inline-flex; margin: 0; }
.server-table { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.server-table-head, .server-table-row {
  display: grid;
  grid-template-columns: 150px 145px 125px 190px 190px minmax(620px, 1fr);
  align-items: center;
  column-gap: 14px;
  min-width: 1490px;
}
.server-table-head {
  min-height: 42px; padding: 0 14px; border-bottom: 1px solid var(--border);
  background: var(--bg); color: var(--text-faint); font-size: 11px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
}
.server-table-row { min-height: 64px; padding: 10px 14px; border-bottom: 1px solid var(--border-soft); }
.server-table-row:last-child { border-bottom: 0; }
.server-table-row:hover { background: rgba(77,163,255,.025); }
.server-table-cell { min-width: 0; }
.server-table-name, .server-table-endpoint, .server-table-users { display: flex; flex-direction: column; gap: 3px; }
.tunnel-overview-endpoints { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.server-table-name .server-card-name, .server-table-endpoint span, .server-table-users span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.server-table-endpoint { font-family: var(--font-mono); font-size: 12.5px; }
.server-table-users { font-size: 13px; }
.server-table-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.server-table-actions form { display: inline-flex; flex: 0 0 auto; margin: 0; }
.server-table-actions .btn { white-space: nowrap; }
.server-table-actions-title { text-align: right; }
.tunnel-overview-table { margin-top: 20px; }
.tunnel-overview-table .server-table-head,
.tunnel-overview-table .server-table-row {
  grid-template-columns: minmax(150px, 1fr) 90px 165px minmax(220px, 1.35fr) minmax(150px, 1fr) minmax(250px, 1fr);
  min-width: 1050px;
}
.tunnel-overview-table .server-table-actions { flex-wrap: wrap; }
.tunnel-mobile-summary { display: none; }
.label-mobile { display: none; }
.tunnel-type-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.tunnel-type-card {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 7px 10px;
  min-width: 0; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.tunnel-type-card:hover { border-color: var(--accent); text-decoration: none; }
.tunnel-type-card .badge { grid-row: 1 / 3; align-self: start; }
.tunnel-type-card strong { font-size: 16px; }
.tunnel-type-card > span:last-child { color: var(--text-muted); font-size: 13px; overflow-wrap: anywhere; }
.routing-row { grid-template-columns: minmax(190px, 1fr) minmax(180px, 1fr) minmax(260px, 1.7fr) auto; }
.route-set-row { grid-template-columns: minmax(160px, .8fr) minmax(180px, 1fr) minmax(0, 1.8fr) auto; }
.text-danger { color: var(--danger); margin-top: 4px; }
.routing-summary { min-width: 0; overflow: hidden; white-space: normal !important; }
.route-details { display: block; width: 100%; min-width: 0; max-width: 100%; margin-top: 5px; overflow: hidden; }
.route-details summary { color: var(--accent); cursor: pointer; font-size: 12px; }
.route-values {
  box-sizing: border-box; width: 100%; min-width: 0; max-width: 100%; max-height: 220px; overflow: auto; margin-top: 6px; padding: 8px 10px; border: 1px solid var(--border-soft);
  border-radius: var(--radius); background: var(--bg); font: 12px/1.5 var(--font-mono); white-space: pre-wrap;
  overflow-wrap: anywhere; word-break: break-word;
}
.route-editor { min-height: 360px; }
.route-set-field { min-width: 0; }
.route-set-field-vpn { grid-column: 1; }
.route-set-field-direct { grid-column: 2; }
.route-selector-card { position: relative; height: 100%; overflow: hidden; border: 1px solid var(--border); border-radius: calc(var(--radius) + 2px); background: var(--bg); }
.route-selector-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent); }
.route-selector-direct::before { background: var(--warn); }
.route-selector-header { display: flex; flex-direction: column; align-items: stretch; gap: 16px; padding: 20px 20px 17px 22px; }
.route-selector-heading { min-width: 0; }
.route-selector-kicker { display: block; margin-bottom: 5px; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.route-selector-direct .route-selector-kicker { color: var(--warn); }
.route-selector-heading h3 { margin: 0; color: var(--text); font-size: 16px; line-height: 1.35; }
.route-selector-heading p { max-width: 680px; margin: 5px 0 0; color: var(--text-muted); font-size: 13px; line-height: 1.45; }
.route-selector-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 10px; }
.route-selector-actions .btn { flex: 1 1 0; min-height: 34px; text-align: center; }
.route-set-selected { display: grid; gap: 8px; min-width: 0; padding: 14px 20px 18px 22px; border-top: 1px solid var(--border-soft); background: rgba(255,255,255,.018); }
.route-set-selected-empty { display: flex; flex-direction: column; gap: 2px; padding: 5px 0; }
.route-set-selected-empty strong { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.route-set-selected-empty span { color: var(--text-faint); font-size: 12px; }
.route-set-chip { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 42px; padding: 6px 8px 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 13px; }
.route-set-chip-marker { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: rgba(77,163,255,.12); color: var(--accent); font-size: 12px; font-weight: 700; }
.route-selector-direct .route-set-chip-marker { background: rgba(240,180,67,.12); color: var(--warn); }
.route-set-chip strong { overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
.route-set-chip button { border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 12px; padding: 5px 8px; }
.route-set-chip button:hover { background: rgba(236,93,106,.08); color: var(--danger); }
.route-set-dialog { position: fixed; inset: 0; width: min(920px, calc(100vw - 32px)); max-height: min(760px, calc(100vh - 32px)); margin: auto; padding: 0; color: var(--text); color-scheme: dark; border: 1px solid var(--border); border-radius: 12px; background: #121722; box-shadow: 0 28px 90px rgba(0,0,0,.72); }
.route-set-dialog::backdrop { background: rgba(4,7,12,.72); }
.route-set-dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 22px 24px 18px; border-bottom: 1px solid var(--border-soft); }
.route-set-dialog-head h2 { margin: 0 0 5px; color: var(--text); font-size: 20px; line-height: 1.3; }
.route-set-dialog-head .sub { color: var(--text-muted); font-size: 13px; }
.dialog-close { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text-muted); cursor: pointer; font-size: 22px; line-height: 1; }
.dialog-close:hover { border-color: var(--accent-dim); color: var(--text); }
.route-set-search { padding: 14px 24px; border-bottom: 1px solid var(--border-soft); background: var(--bg); }
.route-set-search input { width: 100%; }
.route-set-table-wrap { max-height: min(480px, calc(100vh - 260px)); overflow: auto; }
.route-set-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.route-set-table th { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--text-faint); text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.route-set-table th, .route-set-table td { padding: 14px 18px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.route-set-table tbody tr { cursor: pointer; }
.route-set-table tbody tr:hover { background: rgba(77,163,255,.05); }
.route-set-table tbody tr:has(input:checked) { background: rgba(77,163,255,.09); }
.route-set-table td strong { color: var(--text); font-size: 14px; }
.route-set-description { max-width: 420px; color: var(--text-muted); line-height: 1.4; }
.route-count-badge { display: inline-flex; min-width: 34px; justify-content: center; padding: 3px 8px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg); color: var(--text-muted); font: 12px var(--font-mono); }
.route-set-table .check-col { width: 76px; text-align: center; }
.route-set-table input[type=checkbox] { width: 19px; height: 19px; accent-color: var(--accent); cursor: pointer; }
.route-set-dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 24px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 13px; background: var(--surface); }
.route-set-dialog-actions .btn-row { margin: 0; }
@media (max-width: 640px) {
  .route-set-field-vpn, .route-set-field-direct { grid-column: 1; }
  .route-selector-actions { width: 100%; flex-wrap: wrap; }
  .route-selector-actions .btn { flex: 1; text-align: center; }
  .route-set-dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .route-set-dialog-head { gap: 10px; padding: 14px; }
  .route-set-dialog-head h2 { font-size: 17px; }
  .route-set-search { padding: 10px 14px; }
  .route-set-table-wrap { max-height: calc(100dvh - 270px); }
  .route-set-table th, .route-set-table td { padding: 11px 9px; overflow-wrap: anywhere; }
  .route-set-table .check-col { width: 54px; }
  .route-set-table th:nth-child(3), .route-set-table td:nth-child(3) { display: none; }
  .route-set-dialog-actions { align-items: stretch; flex-direction: column; gap: 10px; padding: 12px 14px; }
  .route-set-dialog-actions .btn-row { width: 100%; }
  .route-set-dialog-actions .btn { flex: 1 1 0; justify-content: center; }
}
@media (max-width: 900px) {
  .server-row { grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr); }
  .route-set-row { grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr); }
  .server-row-actions { justify-content: flex-start; grid-column: 1 / -1; }
  .server-table-head { display: none; }
  .server-table { border: 0; background: transparent; overflow: visible; }
  .server-table-row {
    grid-template-columns: 1fr;
    min-width: 0;
    gap: 10px 14px; margin-bottom: 10px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--surface);
  }
  .server-table-cell { display: grid; grid-template-columns: 120px minmax(0, 1fr); align-items: center; gap: 10px; }
  .server-table-cell::before { content: attr(data-label); color: var(--text-faint); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
  .server-table-actions { grid-column: auto; display: flex; flex-wrap: wrap; justify-content: flex-start; padding-top: 10px; border-top: 1px solid var(--border-soft); }
  .server-table-actions::before { display: none; }
  .server-table-actions > a, .server-table-actions > form { flex: 1 1 190px; }
  .server-table-actions > a, .server-table-actions > form .btn { width: 100%; text-align: center; }
  .tunnel-overview-table .server-table-row { min-width: 0; }
}
@media (max-width: 600px) {
  .server-row { grid-template-columns: 1fr; }
  .server-row-actions { grid-column: auto; flex-wrap: wrap; }
  .server-row-endpoint { white-space: normal; }
  .server-row-actions > a, .server-row-actions > form { flex: 1 1 100%; }
  .server-row-actions > a, .server-row-actions > form .btn { width: 100%; justify-content: center; }
  .server-table-row { padding: 13px; }
  .server-table-cell { grid-template-columns: 1fr; gap: 4px; align-items: start; }
  .server-table-cell::before { margin-bottom: 1px; }
  .server-table-actions > a, .server-table-actions > form { flex-basis: 100%; }
  .tunnel-type-grid { grid-template-columns: 1fr; }
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-family: var(--font-mono);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { color: var(--ok); border-color: var(--ok-dim); background: rgba(58,220,140,0.08); }
.badge-warn { color: var(--warn); border-color: var(--warn-dim); background: rgba(240,180,67,0.08); }
.badge-orange { color: var(--orange); border-color: var(--orange-dim); background: rgba(255,138,61,0.09); }
.badge-danger { color: var(--danger); border-color: var(--danger-dim); background: rgba(236,93,106,0.08); }
.badge-muted { color: var(--text-faint); }
.badge-shared { color: var(--accent); border-color: var(--accent-dim); background: rgba(76,159,232,0.1); }

/* ---------- Tables ---------- */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border-soft); }
th { color: var(--text-faint); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
tr:hover td { background: rgba(255,255,255,0.015); }
td.mono, th.mono { font-family: var(--font-mono); font-size: 13px; }
.table-wrap {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--surface);
  scrollbar-gutter: stable;
}
.clients-table { min-width: 1180px; }
.table-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 290px; }
.table-actions form { display: inline-flex; margin: 0; }

@media (max-width: 900px) {
  .shell { padding-left: 16px; padding-right: 16px; }
  .clients-table { min-width: 1080px; }
}

/* ---------- Forms ---------- */

.panel {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
}

/* ---------- Tunnel workspace ---------- */

.tunnel-notice {
  display: flex; gap: 10px; align-items: flex-start; margin-bottom: 18px; padding: 12px 14px;
  border: 1px solid var(--warn-dim); border-radius: var(--radius); background: rgba(240,180,67,.055);
  color: var(--text-muted); font-size: 13px; line-height: 1.5;
}
.tunnel-notice strong { color: var(--warn); }
.tunnel-notice-icon { color: var(--warn); font-size: 16px; line-height: 1.25; }
.tunnel-create { margin-bottom: 24px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.tunnel-create > summary {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 15px 18px;
  cursor: pointer; list-style: none; color: var(--text); font-weight: 600;
}
.tunnel-create > summary::-webkit-details-marker { display: none; }
.tunnel-create > summary::after { content: "+"; color: var(--accent); font-size: 22px; font-weight: 400; }
.tunnel-create[open] > summary::after { content: "−"; }
.tunnel-create[open] > summary { border-bottom: 1px solid var(--border-soft); }
.tunnel-create-summary { display: flex; flex-direction: column; gap: 3px; }
.tunnel-create-summary, .tunnel-create-summary small, .tunnel-notice > div { min-width: 0; overflow-wrap: anywhere; }
.tunnel-create-summary small { color: var(--text-faint); font-size: 12px; font-weight: 400; }
.tunnel-form-body { padding: 20px; }
.settings-block { margin-bottom: 20px; }
.settings-block:last-child { margin-bottom: 0; }
.settings-block-title { margin: 0 0 12px; color: var(--text-faint); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.settings-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ipsec-settings { margin: 12px 0 18px; padding: 16px; border: 1px solid var(--border-soft); border-radius: 9px; background: rgba(4,7,12,.22); }
.ipsec-phase-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.ipsec-phase-card { min-width: 0; padding: 15px; border: 1px solid var(--border-soft); border-radius: 9px; background: var(--surface); }
.ipsec-phase-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; margin-bottom: 14px; }
.ipsec-phase-head span { color: var(--accent); font: 700 11px/1 var(--font-mono); text-transform: uppercase; }
.ipsec-phase-head strong { font-size: 14px; }
.ipsec-algorithm-field { margin-bottom: 15px; }
.ipsec-algorithm-label { display: block; margin-bottom: 7px; color: var(--text-muted); font-size: 13px; }
.ipsec-choice-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 10px; }
.ipsec-choice { display: flex; min-width: 0; align-items: center; gap: 6px; color: var(--text); font: 12px/1.3 var(--font-mono); overflow-wrap: anywhere; }
.ipsec-choice input { flex: 0 0 auto; accent-color: var(--accent); }
.ipsec-compatibility-note { display: block; margin: 12px 0 0; }
.tunnel-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(520px, 100%), 1fr)); gap: 16px; }
.tunnel-card { min-width: 0; overflow: hidden; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.tunnel-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 18px; border-bottom: 1px solid var(--border-soft); }
.tunnel-identity { min-width: 0; }
.tunnel-identity h2 { margin: 0; font-size: 18px; }
.tunnel-identity h2, .tunnel-identity h3, .server-card-name { overflow-wrap: anywhere; word-break: break-word; }
.tunnel-identity-meta { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin-top: 6px; }
.tunnel-path { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 12px; padding: 18px; }
.tunnel-endpoint { min-width: 0; padding: 12px; border: 1px solid var(--border-soft); border-radius: 8px; background: var(--bg); }
.tunnel-endpoint-label { display: block; margin-bottom: 5px; color: var(--text-faint); font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.tunnel-endpoint-value { display: block; overflow-wrap: anywhere; color: var(--text); font: 13px/1.45 var(--font-mono); }
.tunnel-direction { color: var(--accent); font-size: 18px; }
.tunnel-facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--border-soft); border-bottom: 1px solid var(--border-soft); }
.tunnel-facts-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tunnel-fact { min-width: 0; padding: 12px 14px; border-right: 1px solid var(--border-soft); }
.tunnel-fact:last-child { border-right: 0; }
.tunnel-fact-label { display: block; margin-bottom: 4px; color: var(--text-faint); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
.tunnel-fact-value { display: block; overflow: hidden; color: var(--text-muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.tunnel-actions { display: flex; flex-wrap: wrap; gap: 7px; padding: 14px 18px; }
.tunnel-actions form { display: inline-flex; margin: 0; }
.tunnel-statuses { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.tunnel-list-status { display: flex; min-width: 0; flex-direction: column; align-items: flex-start; gap: 6px; }
.ipsec-runtime { padding: 14px 18px; border-bottom: 1px solid var(--border-soft); background: rgba(255,255,255,0.015); }
.ipsec-runtime-established { box-shadow: inset 3px 0 0 var(--ok); }
.ipsec-runtime-shared { box-shadow: inset 3px 0 0 var(--accent); background: rgba(76,159,232,.045); }
.ipsec-runtime-waiting, .ipsec-runtime-partial { box-shadow: inset 3px 0 0 var(--warn); }
.ipsec-runtime-error { box-shadow: inset 3px 0 0 var(--danger); }
.ipsec-runtime-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.ipsec-runtime-head > * { min-width: 0; }
.ipsec-runtime-head .badge { flex: 0 1 auto; text-align: left; }
.ipsec-runtime-head strong { display: block; font-size: 13px; }
.ipsec-runtime-head .muted { margin-top: 3px; font-size: 11px; }
.ipsec-runtime-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.ipsec-runtime-grid > div { min-width: 0; padding: 9px 10px; border: 1px solid var(--border-soft); border-radius: 7px; background: var(--bg); }
.ipsec-runtime-grid span, .ipsec-runtime-grid small { display: block; color: var(--text-faint); font-size: 10px; }
.ipsec-runtime-grid strong { display: block; margin: 4px 0 2px; overflow-wrap: anywhere; color: var(--text); font-size: 13px; }
.ipsec-runtime-message { margin-top: 10px; color: var(--danger); font: 11px/1.45 var(--font-mono); overflow-wrap: anywhere; }
.ipsec-runtime-note { margin-top: 9px; color: var(--text-muted); font-size: 11px; line-height: 1.45; overflow-wrap: anywhere; }
.route-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.route-table-groups { display: grid; gap: 16px; }
.route-table-group { overflow: hidden; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.route-table-group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border-soft); }
.route-table-wrap { overflow-x: auto; }
.route-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.route-table th { padding: 9px 12px; color: var(--text-faint); text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; background: var(--bg); }
.route-table td { min-width: 0; padding: 11px 12px; border-top: 1px solid var(--border-soft); vertical-align: middle; overflow-wrap: anywhere; }
.route-table tbody tr:first-child td { border-top: 0; }
.route-table-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; white-space: nowrap; }
.route-table-actions form { display: inline-flex; margin: 0; }
.route-row-disabled { opacity: .65; }
@media (max-width: 760px) {
  .route-table-group-head { align-items: flex-start; flex-direction: column; }
  .route-table-group-head .btn { width: 100%; justify-content: center; }
  .route-table-wrap { overflow: visible; }
  .route-table, .route-table tbody, .route-table tr, .route-table td { display: block; width: 100%; }
  .route-table thead { display: none; }
  .route-table tbody { padding: 10px; }
  .route-table tr { margin-bottom: 10px; overflow: hidden; border: 1px solid var(--border-soft); border-radius: 8px; background: var(--bg); }
  .route-table tr:last-child { margin-bottom: 0; }
  .route-table td { display: grid; grid-template-columns: minmax(92px, 34%) minmax(0, 1fr); gap: 10px; align-items: start; border-top: 1px solid var(--border-soft); }
  .route-table td:first-child { border-top: 0; }
  .route-table td::before { content: attr(data-label); color: var(--text-faint); font: 700 10px/1.5 var(--font-body); letter-spacing: .04em; text-transform: uppercase; }
  .route-table-actions { display: flex !important; justify-content: stretch; white-space: normal; }
  .route-table-actions::before { display: none; }
  .route-table-actions > a, .route-table-actions > form { flex: 1 1 120px; }
  .route-table-actions > a, .route-table-actions > form .btn { width: 100%; justify-content: center; }
}
.tunnel-config { border-top: 1px solid var(--border-soft); }
.tunnel-config > summary { padding: 13px 18px; cursor: pointer; list-style: none; color: var(--accent); font-size: 13px; overflow-wrap: anywhere; }
.tunnel-config > summary::-webkit-details-marker { display: none; }
.tunnel-config > summary::before { content: "›"; display: inline-block; width: 15px; transition: transform .12s ease; }
.tunnel-config[open] > summary::before { transform: rotate(90deg); }
.tunnel-config-body { padding: 18px; border-top: 1px solid var(--border-soft); background: rgba(4,7,12,.22); }
.compact-form { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.compact-form .field { flex: 1 1 220px; margin-bottom: 0; }
.tunnel-settings-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin-top: 6px; padding-top: 16px; border-top: 1px solid var(--border-soft); }
.danger-zone { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--danger-dim); }
.danger-zone p { margin: 0 0 10px; color: var(--text-faint); font-size: 12px; }

@media (max-width: 760px) {
  .settings-grid, .settings-grid-3 { grid-template-columns: 1fr; }
  .ipsec-phase-grid { grid-template-columns: 1fr; }
  .ipsec-choice-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tunnel-path { grid-template-columns: 1fr; }
  .tunnel-direction { transform: rotate(90deg); justify-self: center; }
  .tunnel-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ipsec-runtime-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tunnel-fact:nth-child(2) { border-right: 0; }
  .tunnel-fact:nth-child(-n+2) { border-bottom: 1px solid var(--border-soft); }
  .create-menu-popover { right: auto; left: 0; }
  .page-header { align-items: stretch; }
  .page-header > * { min-width: 0; }
  .page-header-actions, .page-header > .btn-row, .page-header > .create-menu { width: 100%; }
  .page-header-actions .btn, .page-header > .btn-row .btn, .page-header > .create-menu > summary { flex: 1 1 150px; text-align: center; }
  .page-header > .btn { width: 100%; justify-content: center; }
  .tunnel-card-head { flex-wrap: wrap; }
  .tunnel-form-body, .tunnel-config-body { padding: 14px; }
  .tunnel-actions form, .tunnel-actions > a { flex: 1 1 180px; }
  .tunnel-actions form .btn, .tunnel-actions > a { width: 100%; justify-content: center; }
  .compact-form { align-items: stretch; }
  .compact-form .field { flex-basis: 100%; }
  .compact-form > .btn { width: 100%; }
  .tunnel-settings-actions { flex-direction: column; align-items: stretch; }
  .tunnel-settings-actions form, .tunnel-settings-actions .btn { width: 100%; }
}

@media (max-width: 480px) {
  .shell { padding: 22px 12px 64px; }
  .page-header h1 { font-size: 20px; }
  .page-header-actions .btn { flex-basis: 100%; }
  .page-header > .btn-row .btn { flex-basis: 100%; justify-content: center; }
  .panel { padding: 14px; }
  .tunnel-create > summary { padding: 13px 14px; }
  .tunnel-card-head { flex-direction: column; padding: 14px; }
  .tunnel-statuses { width: 100%; justify-content: flex-start; }
  .tunnel-path { padding: 14px; }
  .tunnel-facts { grid-template-columns: 1fr; }
  .ipsec-runtime { padding: 12px 14px; }
  .ipsec-runtime-head { flex-direction: column; }
  .ipsec-runtime-head .badge { width: 100%; justify-content: flex-start; }
  .ipsec-runtime-grid { grid-template-columns: 1fr; }
  .tunnel-fact, .tunnel-fact:nth-child(2) { border-right: 0; border-bottom: 1px solid var(--border-soft); }
  .tunnel-fact:last-child { border-bottom: 0; }
  .tunnel-actions { padding: 12px 14px; }
  .tunnel-actions form, .tunnel-actions > a { flex-basis: 100%; }
  .ipsec-settings, .ipsec-phase-card { padding: 12px; }
  .ipsec-choice-grid { grid-template-columns: 1fr 1fr; }
}

/* Compact mobile tunnel overview and controls. */
@media (max-width: 900px) {
  .tunnel-overview-table .server-table-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 0;
    overflow: hidden;
  }
  .tunnel-mobile-summary {
    display: flex;
    min-width: 0;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px;
    border-bottom: 1px solid var(--border-soft);
    background: rgba(77,163,255,.035);
  }
  .tunnel-mobile-identity { display: flex; min-width: 0; flex-direction: column; gap: 5px; }
  .tunnel-mobile-identity .server-card-name,
  .tunnel-mobile-identity .mono { overflow-wrap: anywhere; }
  .tunnel-mobile-badges { display: flex; min-width: 0; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
  .tunnel-overview-table .server-table-name,
  .tunnel-overview-table .tunnel-type-cell,
  .tunnel-overview-table .tunnel-status-cell,
  .tunnel-overview-table .tunnel-channel-cell { display: none; }
  .tunnel-overview-table .server-table-endpoint {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 10px;
    padding: 12px 14px;
  }
  .tunnel-overview-table .server-table-endpoint::before { align-self: start; }
  .tunnel-overview-table .tunnel-overview-endpoints { min-width: 0; }
  .tunnel-overview-table .tunnel-overview-endpoints span { white-space: normal; overflow-wrap: anywhere; }
  .tunnel-overview-table .server-table-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    padding: 12px 14px 14px;
  }
  .tunnel-overview-table .server-table-actions > a,
  .tunnel-overview-table .server-table-actions > form { min-width: 0; width: 100%; }
  .tunnel-overview-table .server-table-actions > a,
  .tunnel-overview-table .server-table-actions > form .btn {
    width: 100%;
    min-height: 38px;
    justify-content: center;
    padding-inline: 8px;
    white-space: normal;
    line-height: 1.25;
  }
  .tunnel-overview-table .tunnel-action-danger { grid-column: -2 / -1; }
  .label-desktop { display: none; }
  .label-mobile { display: inline; }
}

@media (max-width: 600px) {
  .tunnel-page-header .page-header-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .tunnel-page-header .page-header-actions .btn { width: 100%; min-width: 0; justify-content: center; }
  .tunnel-page-header .page-header-actions .btn:last-child { grid-column: 1 / -1; }
  .tunnel-peer-import { margin-bottom: 14px; }
  .tunnel-peer-import-description { margin-top: 0; }
  .tunnel-type-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tunnel-type-card { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 12px; }
  .tunnel-type-card .badge { align-self: flex-start; }
  .tunnel-type-card > span:last-child { display: none; }
  .tunnel-overview-table { margin-top: 14px; }
  .tunnel-mobile-summary { flex-direction: column; }
  .tunnel-mobile-badges { justify-content: flex-start; }
  .tunnel-overview-table .server-table-endpoint { grid-template-columns: 98px minmax(0, 1fr); }
  .tunnel-overview-table .server-table-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tunnel-overview-table .tunnel-action-danger { grid-column: auto; }
  .tunnel-card .tunnel-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }
  .tunnel-card .tunnel-actions > form,
  .tunnel-card .tunnel-actions > a { min-width: 0; width: 100%; }
  .tunnel-card .tunnel-actions > form .btn,
  .tunnel-card .tunnel-actions > a {
    width: 100%; min-height: 40px; justify-content: center; padding-inline: 7px;
    white-space: normal; text-align: center; line-height: 1.25;
  }
  .tunnel-card .tunnel-actions > a,
  .tunnel-card .tunnel-actions > .badge,
  .tunnel-card .tunnel-actions > form:last-child { grid-column: 1 / -1; }
}

@media (max-width: 360px) {
  .tunnel-overview-table .server-table-endpoint { grid-template-columns: 1fr; gap: 5px; }
  .tunnel-overview-table .server-table-actions { grid-template-columns: 1fr; }
  .tunnel-card .tunnel-actions { grid-template-columns: 1fr; }
  .tunnel-card .tunnel-actions > a,
  .tunnel-card .tunnel-actions > .badge,
  .tunnel-card .tunnel-actions > form:last-child { grid-column: auto; }
}

/* Phone layout: one readable control per row.  Two-column button grids look
   compact in CSS but overflow as soon as Russian labels or long tunnel names
   are rendered on a real 360–430 px screen. */
@media (max-width: 600px) {
  .tunnel-page-header,
  .tunnel-peer-import,
  .tunnel-type-grid,
  .tunnel-overview-table,
  .tunnel-cards,
  .tunnel-card { width: 100%; min-width: 0; max-width: 100%; }

  .tunnel-page-header .page-header-actions {
    grid-template-columns: minmax(0, 1fr);
  }
  .tunnel-page-header .page-header-actions .btn,
  .tunnel-page-header .page-header-actions .btn:last-child { grid-column: auto; }

  .tunnel-type-grid { grid-template-columns: minmax(0, 1fr); }
  .tunnel-type-card { width: 100%; }

  .tunnel-mobile-summary { gap: 9px; padding: 12px; }
  .tunnel-mobile-identity,
  .tunnel-mobile-badges { width: 100%; }
  .tunnel-mobile-badges .badge { justify-content: flex-start; }

  .tunnel-overview-table .server-table-endpoint {
    grid-template-columns: minmax(0, 1fr);
    gap: 5px;
    padding: 11px 12px;
  }
  .tunnel-overview-table .server-table-actions,
  .tunnel-card .tunnel-actions {
    grid-template-columns: minmax(0, 1fr);
    padding: 11px 12px 13px;
  }
  .tunnel-overview-table .server-table-actions > a,
  .tunnel-overview-table .server-table-actions > form,
  .tunnel-card .tunnel-actions > a,
  .tunnel-card .tunnel-actions > form,
  .tunnel-card .tunnel-actions > .badge,
  .tunnel-card .tunnel-actions > form:last-child {
    grid-column: auto;
    width: 100%;
  }
  .tunnel-overview-table .server-table-actions > form .btn,
  .tunnel-card .tunnel-actions > form .btn,
  .tunnel-card .tunnel-actions > a { width: 100%; justify-content: center; }

  .tunnel-card-head,
  .tunnel-path,
  .tunnel-config-body { padding-inline: 12px; }
  .tunnel-facts { grid-template-columns: minmax(0, 1fr); }
  .tunnel-fact,
  .tunnel-fact:nth-child(2) { border-right: 0; border-bottom: 1px solid var(--border-soft); }
  .tunnel-fact:last-child { border-bottom: 0; }
  .tunnel-fact-value { white-space: normal; overflow-wrap: anywhere; text-overflow: clip; }
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: 1; }
}

.field { display: flex; min-width: 0; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--text-muted); }
.field .hint { font-size: 12px; color: var(--text-faint); }

input:not([type]), input[type=text], input[type=search], input[type=number], input[type=password], textarea, select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 11px;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 14px;
}
textarea { font-family: var(--font-mono); font-size: 13px; min-height: 64px; resize: vertical; }
input[type=file] {
  width: 100%; min-width: 0; max-width: 100%; border: 1px dashed var(--border); background: var(--bg); color: var(--text-muted);
  padding: 12px; border-radius: var(--radius); font-family: var(--font-body);
}
input:focus, textarea:focus, select:focus, button:focus, a:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.checkbox-field { flex-direction: row; align-items: center; gap: 8px; }
.checkbox-field label { color: var(--text); font-size: 14px; }

details.add-form {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-top: 20px;
}
details.add-form > summary {
  padding: 12px 16px;
  cursor: pointer;
  color: var(--accent);
  font-size: 14px;
  list-style: none;
}
details.add-form > summary::-webkit-details-marker { display: none; }
details.add-form > summary::before { content: "+ "; }
details.add-form[open] > summary::before { content: "− "; }
details.add-form .body { padding: 4px 16px 20px; border-top: 1px solid var(--border-soft); }

/* ---------- Detail sections ---------- */

.section { margin-top: 28px; }
.section h2 { font-size: 15px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 12px; }
.log-output {
  max-height: 480px; overflow: auto; margin: 0; padding: 16px; border: 1px solid var(--border);
  border-radius: var(--radius); background: #080b10; color: var(--text-muted); font: 12.5px/1.55 var(--font-mono);
  white-space: pre-wrap; overflow-wrap: anywhere;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 4px;
}
.kv { border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 10px 12px; background: var(--surface); }
.kv .k { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.kv .v { font-family: var(--font-mono); font-size: 14px; margin-top: 3px; }

.danger-zone { border: 1px solid var(--danger-dim); border-radius: var(--radius); padding: 16px; background: rgba(236,93,106,0.04); margin-top: 28px; }
.danger-zone h2 { color: var(--danger); }

/* ---------- Login ---------- */

.login-shell { max-width: 360px; margin: 12vh auto 0; padding: 0 20px; }
.login-shell .panel { padding: 28px; }
.login-shell h1 { font-size: 18px; margin: 0 0 20px; text-align: center; }
.login-error { color: var(--danger); font-size: 13px; margin-bottom: 14px; }

.muted { color: var(--text-faint); }

/* Xray / VLESS + REALITY */
.xray-help { margin-bottom: 18px; }
.xray-help summary { cursor: pointer; color: var(--accent); font-weight: 650; }
.xray-help-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 16px; }
.xray-help-grid div { display: flex; flex-direction: column; gap: 5px; padding: 12px; border: 1px solid var(--border-soft); border-radius: 8px; background: var(--bg); }
.xray-help-grid span, .xray-action-help { color: var(--text-muted); font-size: 12px; line-height: 1.5; }
.xray-submit-field { justify-content: flex-end; }
.xray-list-title { margin: 24px 0 12px; }
.xray-server-list { display: grid; gap: 16px; }
.xray-server-card { padding: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.xray-server-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border-soft); }
.xray-server-head h3 { margin: 0 0 4px; font-size: 19px; }
.xray-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 16px 0; }
.xray-fact { display: flex; min-width: 0; flex-direction: column; gap: 3px; padding: 10px 12px; border-radius: 7px; background: var(--bg); }
.xray-fact-label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.xray-fact strong { overflow-wrap: anywhere; font: 13px var(--font-mono); }
.xray-fact small { color: var(--text-faint); font-size: 11px; }
.xray-user-section { margin-top: 18px; padding-top: 4px; }
.xray-user-section h4 { margin: 0 0 4px; }
.xray-user-section > p { margin: 0 0 14px; }
.link-button { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; text-align: left; }
.link-button:hover { text-decoration: underline; }
.xray-access-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.xray-qr-wrap { display: flex; align-items: center; gap: 16px; margin-top: 16px; padding: 14px; border-radius: 8px; background: #fff; color: #1b1f28; }
.xray-qr-wrap img { width: 180px; height: 180px; image-rendering: pixelated; }
.xray-qr-wrap span { max-width: 220px; font-size: 13px; line-height: 1.45; }
.xray-network-mode-note { margin: 4px 0 16px; padding: 11px 13px; border: 1px solid var(--border); border-radius: 7px; color: var(--text-muted); font-size: 12px; line-height: 1.5; }
.xray-network-mode-open { border-color: var(--warn); color: var(--warn); }
.xray-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--border-soft); }
.xray-action-help { margin: 8px 0 0; }
.xray-dialog { width: min(720px, calc(100vw - 32px)); padding: 22px; color: var(--text); color-scheme: dark; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.xray-dialog::backdrop { background: rgba(4,7,12,.76); }
.xray-dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.xray-dialog-head h2, .xray-dialog-head p { margin: 0; }
.xray-dialog-head p { margin-top: 5px; color: var(--text-muted); font-size: 13px; }
@media (max-width: 700px) {
  .xray-help-grid, .xray-facts { grid-template-columns: 1fr; }
  .xray-server-head { flex-direction: column; }
}
.field-disabled {
  opacity: 0.5;
}

.field-disabled input,
.field-disabled textarea {
  cursor: not-allowed;
}

/* ---------- /30 tunnel address constructor ---------- */

.ipv4-30-builder {
  display: grid;
  gap: 14px;
  margin: 14px 0;
  padding: 16px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--bg);
}
.ipv4-30-controls {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(210px, 1fr);
  gap: 14px;
  align-items: end;
}
.ipv4-30-octets {
  display: grid;
  grid-template-columns: repeat(3, minmax(48px, 1fr) auto) minmax(56px, 1fr) auto;
  gap: 6px;
  align-items: center;
}
.ipv4-30-octets input {
  min-width: 0;
  padding-inline: 7px;
  text-align: center;
  font-family: var(--font-mono);
}
.ipv4-30-octets > span { color: var(--text-muted); font-family: var(--font-mono); }
.ipv4-30-mask { padding-left: 2px; color: var(--accent) !important; font-weight: 700; }
.ipv4-30-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-muted);
  font: 12px/1.45 var(--font-mono);
}
.ipv4-30-preview strong { color: var(--text); font-family: var(--font-body); }
.ipv4-30-builder [hidden] { display: none !important; }

@media (max-width: 700px) {
  .ipv4-30-controls { grid-template-columns: 1fr; align-items: stretch; }
  .ipv4-30-octets {
    grid-template-columns: minmax(44px, 1fr) auto minmax(44px, 1fr) auto;
  }
  .ipv4-30-octets input:nth-of-type(3) { grid-column: 1; }
  .ipv4-30-octets input:nth-of-type(4) { grid-column: 3; }
  .ipv4-30-preview { flex-direction: column; gap: 5px; }
}

/* ---------- Long-running operations ---------- */

.operation-progress[hidden] { display: none; }
.operation-progress {
  position: fixed;
  z-index: 10000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 7, 12, .72);
  backdrop-filter: blur(2px);
}
.operation-progress-card {
  width: min(460px, 100%);
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 20px 70px rgba(0, 0, 0, .45);
}
.operation-progress-head { display: flex; align-items: center; gap: 14px; }
.operation-progress-head strong { display: block; font-size: 16px; }
.operation-progress-description { margin-top: 4px; color: var(--text-muted); font-size: 13px; }
.operation-progress-spinner {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: operation-spin .85s linear infinite;
}
.operation-progress-track {
  height: 7px;
  margin-top: 20px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg);
}
.operation-progress-track span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #78dce8);
  animation: operation-slide 1.35s ease-in-out infinite;
}
.operation-progress-time { margin-top: 10px; color: var(--text-faint); font: 12px var(--font-mono); text-align: right; }
.operation-in-progress body { overflow: hidden; }

@keyframes operation-spin { to { transform: rotate(360deg); } }
@keyframes operation-slide {
  from { transform: translateX(-110%); }
  to { transform: translateX(345%); }
}
@media (prefers-reduced-motion: reduce) {
  .operation-progress-spinner, .operation-progress-track span { animation-duration: 2.8s; }
}
