@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;
  --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;
  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; }
.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: flex-start; padding: 12px 16px; gap: 12px; }
  .topnav { gap: 6px; }
  .nav-user { display: none; }
}

/* ---------- 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 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; }

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

.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; }
.server-row-main .server-card-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server-row-endpoint { margin-top: 0; overflow: hidden; 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; }
.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-table th:nth-child(3), .route-set-table td:nth-child(3) { display: none; }
}
@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; }
}
@media (max-width: 600px) {
  .server-row { grid-template-columns: 1fr; }
  .server-row-actions { grid-column: auto; flex-wrap: wrap; }
}

.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);
}
.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-danger { color: var(--danger); border-color: var(--danger-dim); background: rgba(236,93,106,0.08); }
.badge-muted { color: var(--text-faint); }

/* ---------- 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 {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
}

.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; } }

.field { display: flex; 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[type=text], input[type=search], input[type=number], input[type=password], textarea, select {
  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%; 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); }
.field-disabled {
  opacity: 0.5;
}

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