:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --bg-elevated: #eef3f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-strong: #edf2f7;
  --text: #111827;
  --muted: #5b6b82;
  --subtle: #8a97a8;
  --border: #d7dee8;
  --border-strong: #c4cedb;
  --primary: #0f766e;
  --primary-dark: #0a5f59;
  --primary-soft: #dff4f1;
  --success: #15803d;
  --success-soft: #e5f7eb;
  --danger: #dc2626;
  --danger-soft: #fde8e8;
  --warning: #b45309;
  --warning-soft: #fff1d6;
  --active: #334155;
  --active-soft: #e7edf4;
  --focus: #2563eb;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-md: 0 10px 28px rgba(15, 23, 42, .08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .78), rgba(255, 255, 255, 0) 260px),
    linear-gradient(135deg, var(--bg), var(--bg-elevated));
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

::selection {
  background: rgba(15, 118, 110, .18);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .22);
  outline-offset: 2px;
}

code {
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--active);
  padding: 1px 6px;
}

.topbar {
  align-items: center;
  backdrop-filter: blur(16px);
  background: rgba(255, 255, 255, .9);
  border-bottom: 1px solid rgba(196, 206, 219, .85);
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(220px, 1fr) auto minmax(180px, 1fr);
  min-height: 70px;
  padding: 12px clamp(18px, 3vw, 38px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  align-items: center;
  display: inline-flex;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  align-items: center;
  background: linear-gradient(135deg, var(--primary), #2563eb);
  border: 1px solid rgba(255, 255, 255, .5);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  color: #fff;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 900;
  height: 42px;
  justify-content: center;
  width: 50px;
}

.brand strong,
.brand small {
  display: block;
  min-width: 0;
}

.brand strong {
  font-size: 15px;
  line-height: 1.15;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav {
  align-items: center;
  background: rgba(237, 242, 247, .9);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .65);
  display: inline-flex;
  gap: 3px;
  justify-self: center;
  padding: 3px;
}

.nav a {
  border-radius: 6px;
  color: var(--muted);
  font-weight: 750;
  min-height: 36px;
  padding: 8px 12px;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}

.nav a.active {
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--text);
}

.nav a:hover {
  color: var(--text);
}

.logout-form {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: end;
  min-width: 0;
}

.logout-form span {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page {
  margin: 0 auto;
  max-width: 1520px;
  padding: 30px clamp(18px, 2.8vw, 42px) 52px;
}

.hero {
  align-items: stretch;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  margin-bottom: 16px;
}

.hero h1,
.section-title h1 {
  font-size: 32px;
  line-height: 1.08;
  margin: 0 0 8px;
}

.hero p,
.section-title p {
  color: var(--muted);
  font-size: 15px;
  margin: 0;
}

.section-title {
  margin-bottom: 16px;
}

.gateway-panel,
.metric-card,
.login-card,
.panel-form,
.table-shell,
.vpn-card,
.toolbar {
  background: rgba(255, 255, 255, .92);
  border: 1px solid rgba(215, 222, 232, .95);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
}

.gateway-panel {
  border-left: 5px solid var(--active);
  display: grid;
  gap: 8px;
  overflow: hidden;
  padding: 16px 18px;
  position: relative;
}

.gateway-panel::after {
  background: linear-gradient(90deg, rgba(15, 118, 110, .12), transparent);
  content: "";
  inset: 0;
  pointer-events: none;
  position: absolute;
}

.gateway-panel.online {
  border-left-color: var(--primary);
}

.gateway-panel.unknown {
  border-left-color: var(--warning);
}

.gateway-panel span,
.metric-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.gateway-panel strong {
  font-size: 25px;
  line-height: 1.15;
  overflow-wrap: anywhere;
  position: relative;
}

.metrics {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.metric-card {
  display: grid;
  gap: 5px;
  min-height: 86px;
  overflow: hidden;
  padding: 15px 16px;
  position: relative;
}

.metric-card::before {
  background: var(--border-strong);
  content: "";
  height: 100%;
  left: 0;
  position: absolute;
  top: 0;
  width: 4px;
}

.metric-card.running::before {
  background: var(--success);
}

.metric-card.down::before {
  background: var(--danger);
}

.metric-card.transport::before {
  background: #2563eb;
}

.metric-card strong {
  font-size: 27px;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.toolbar {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  margin: 18px 0;
  padding: 12px;
}

.search {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  font-weight: 800;
  gap: 6px;
  min-width: 0;
}

.search input,
label input,
label select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  min-height: 42px;
  padding: 9px 11px;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
  width: 100%;
}

.search input:hover,
label input:hover,
label select:hover {
  border-color: var(--border-strong);
}

.search input:focus,
label input:focus,
label select:focus {
  background: #fff;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
  outline: none;
}

.segments {
  align-items: center;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: inline-flex;
  padding: 3px;
}

.segments button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
  min-height: 36px;
  padding: 8px 11px;
  transition: background .15s ease, color .15s ease;
  white-space: nowrap;
}

.segments button.active {
  background: var(--primary);
  color: #fff;
}

.vpn-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.vpn-card {
  border-left: 4px solid var(--muted);
  display: grid;
  gap: 13px;
  min-height: 172px;
  padding: 14px;
  transition: border-color .15s ease, box-shadow .15s ease, transform .12s ease;
}

.vpn-card:hover {
  box-shadow: 0 14px 34px rgba(15, 23, 42, .11);
  transform: translateY(-1px);
}

.vpn-card.running {
  border-left-color: var(--success);
}

.vpn-card.down {
  border-left-color: var(--danger);
}

.vpn-card.active {
  background: linear-gradient(0deg, rgba(231, 237, 244, .62), rgba(255, 255, 255, .96));
  border-left-color: var(--active);
}

.vpn-card-head {
  align-items: start;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.vpn-card h2 {
  font-size: 18px;
  line-height: 1.2;
  margin: 0;
  overflow-wrap: anywhere;
}

.vpn-card p,
.vpn-meta {
  color: var(--muted);
  font-size: 12px;
  margin: 4px 0 0;
}

.vpn-meta {
  align-content: start;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.vpn-meta span {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
}

.status-pill,
.status-label {
  align-items: center;
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 900;
  gap: 6px;
  line-height: 1;
  padding: 6px 9px;
  white-space: nowrap;
}

.status-pill::before {
  border-radius: 999px;
  content: "";
  height: 7px;
  width: 7px;
}

.status-pill.running {
  background: var(--success-soft);
  color: var(--success);
}

.status-pill.running::before {
  background: var(--success);
}

.status-pill.down {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-pill.down::before {
  background: var(--danger);
}

.status-pill.active {
  background: var(--active-soft);
  color: var(--active);
}

.status-pill.active::before {
  background: var(--active);
}

.status-label.success {
  background: var(--success-soft);
  color: var(--success);
}

.status-label.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-label.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.card-actions {
  align-self: end;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card-actions form,
.card-actions button,
.card-actions a {
  min-width: 0;
  width: 100%;
}

.primary,
.secondary,
.icon-button,
.link-button {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 850;
  justify-content: center;
  min-height: 42px;
  padding: 9px 13px;
  text-align: center;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .08s ease, box-shadow .15s ease;
  white-space: nowrap;
}

.primary {
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(15, 118, 110, .18);
  color: #fff;
}

.primary:hover {
  background: var(--primary-dark);
}

.secondary,
.icon-button {
  background: var(--surface);
  border-color: var(--border);
  color: var(--active);
}

.secondary:hover,
.icon-button:hover {
  background: var(--surface-strong);
  border-color: var(--border-strong);
}

.compact {
  min-height: 36px;
  padding: 7px 10px;
}

button:active,
.link-button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.alert {
  border: 1px solid var(--border);
  border-radius: 8px;
  font-weight: 700;
  margin-bottom: 14px;
  padding: 12px 14px;
}

.alert.success {
  background: var(--success-soft);
  border-color: rgba(21, 128, 61, .28);
  color: #14532d;
}

.alert.danger {
  background: var(--danger-soft);
  border-color: rgba(220, 38, 38, .28);
  color: #7f1d1d;
}

.alert.warning {
  background: var(--warning-soft);
  border-color: rgba(180, 83, 9, .28);
  color: #78350f;
}

.login-shell {
  display: grid;
  min-height: calc(100vh - 130px);
  place-items: center;
}

.login-card {
  max-width: 430px;
  padding: 26px;
  width: 100%;
}

.login-card h1 {
  font-size: 26px;
  margin: 0 0 8px;
}

.login-card p {
  color: var(--muted);
  margin: 0 0 20px;
}

.stack,
.panel-form {
  display: grid;
  gap: 16px;
}

.form-page {
  display: grid;
  gap: 16px;
  margin: 0 auto;
  max-width: 980px;
}

.panel-form {
  padding: 18px;
}

.form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid label,
.stack label {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  font-weight: 800;
  gap: 6px;
  min-width: 0;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.template-fields {
  border-top: 1px solid var(--border);
  display: grid;
  gap: 12px;
  padding-top: 16px;
}

.template-fields h2 {
  font-size: 17px;
  margin: 0;
}

.checkbox {
  align-items: center;
  color: var(--text);
  display: flex;
  font-size: 13px;
  font-weight: 800;
  gap: 9px;
  min-height: 42px;
}

.checkbox input {
  accent-color: var(--primary);
  min-height: auto;
  width: auto;
}

.form-actions {
  align-items: center;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding-top: 16px;
}

.inline-actions {
  display: flex;
  gap: 10px;
  justify-content: end;
}

.table-shell {
  overflow: auto;
}

table {
  border-collapse: collapse;
  min-width: 900px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .03em;
  position: sticky;
  text-transform: uppercase;
  top: 0;
  z-index: 1;
}

tbody tr:hover {
  background: var(--surface-soft);
}

.empty-state {
  background: rgba(255, 255, 255, .86);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  color: var(--muted);
  grid-column: 1 / -1;
  padding: 32px;
  text-align: center;
}

[hidden] {
  display: none !important;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #141414;
    --bg-elevated: #1d201f;
    --surface: #202322;
    --surface-soft: #252a28;
    --surface-strong: #2b302e;
    --text: #f3f4f6;
    --muted: #b5c0bd;
    --subtle: #87928f;
    --border: #3a4140;
    --border-strong: #4b5552;
    --primary: #2dd4bf;
    --primary-dark: #14b8a6;
    --primary-soft: rgba(45, 212, 191, .14);
    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, .13);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, .14);
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, .14);
    --active: #d1d5db;
    --active-soft: rgba(209, 213, 219, .12);
    --shadow-md: 0 12px 30px rgba(0, 0, 0, .28);
  }

  .topbar {
    background: rgba(32, 35, 34, .9);
    border-bottom-color: rgba(75, 85, 82, .85);
  }

  .gateway-panel,
  .metric-card,
  .login-card,
  .panel-form,
  .table-shell,
  .vpn-card,
  .toolbar,
  .empty-state {
    background: rgba(32, 35, 34, .92);
    border-color: var(--border);
  }

  .search input:focus,
  label input:focus,
  label select:focus {
    background: var(--surface);
  }
}

@media (max-width: 980px) {
  .topbar {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .nav {
    justify-self: start;
    max-width: 100%;
    overflow-x: auto;
  }

  .logout-form {
    justify-content: start;
  }

  .hero,
  .toolbar,
  .metrics {
    grid-template-columns: 1fr;
  }

  .toolbar {
    align-items: stretch;
  }

  .segments {
    overflow-x: auto;
    width: 100%;
  }

  .segments button {
    flex: 1 0 auto;
  }
}

@media (max-width: 700px) {
  .page {
    padding: 20px 14px 34px;
  }

  .hero h1,
  .section-title h1 {
    font-size: 26px;
  }

  .vpn-grid {
    grid-template-columns: 1fr;
  }

  .form-grid,
  .card-actions {
    grid-template-columns: 1fr;
  }

  .form-actions,
  .inline-actions {
    align-items: stretch;
    display: grid;
  }

  .brand {
    align-items: start;
  }
}
