:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #18202a;
  --muted: #637083;
  --line: #d9dee7;
  --accent: #126b68;
  --danger: #9f2d2d;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; color: var(--text); text-decoration: none; }
nav { display: flex; gap: 14px; align-items: center; }
nav a { color: var(--text); text-decoration: none; }
nav form { margin: 0; }
.page { max-width: 1180px; margin: 24px auto; padding: 0 16px; }

.public-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.login-link {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 6px;
  padding: 8px 13px;
  text-decoration: none;
  font-weight: 700;
}
.public-page {
  max-width: 980px;
  margin: 28px auto;
  padding: 0 16px;
}
.public-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.public-status-card,
.public-empty {
  min-height: 88px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.public-status-card {
  border-left-width: 7px;
}
.public-status-card.online {
  border-left-color: #15803d;
  background: #f0fdf4;
}
.public-status-card.offline {
  border-left-color: #b91c1c;
  background: #fef2f2;
}
.public-status-card strong,
.public-empty strong {
  display: block;
  font-size: 18px;
  line-height: 1.2;
}
.public-status-card span,
.public-empty span {
  display: inline-block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.public-status-card.online span { color: #15803d; }
.public-status-card.offline span { color: #b91c1c; }

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
}
button:disabled { opacity: .5; cursor: not-allowed; }
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
}
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: white;
}

.toolbar {
  display: grid;
  grid-template-columns: 2fr auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}
.toolbar form { display: flex; gap: 8px; }
.vpn-load-toolbar {
  grid-template-columns: auto;
  justify-content: start;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.summary-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.summary-card strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}
.history-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.history-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.history-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 10px;
}
.history-bars {
  display: flex;
  align-items: end;
  gap: 2px;
  height: 62px;
}
.history-bars i {
  flex: 1;
  min-width: 3px;
  min-height: 4px;
  border-radius: 3px 3px 0 0;
}
.history-card.online i { background: #16a34a; }
.history-card.speed i { background: #0e7490; }
.history-card.load i { background: #d97706; }
.history-card.ram i { background: #7c3aed; }

.table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 13px; }
th[data-sort] { cursor: pointer; }
td span { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.load-row.ok { background: #f0fdf4; }
.load-row.warning { background: #fffbeb; }
.load-row.danger { background: #fef2f2; }
.load-row.offline { background: #f8fafc; color: #64748b; }
.sparkline {
  display: flex;
  align-items: end;
  gap: 2px;
  min-width: 96px;
  height: 34px;
}
.sparkline i {
  display: block;
  width: 4px;
  min-height: 4px;
  border-radius: 2px 2px 0 0;
  background: #126b68;
}
.recommendations {
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.recommendations h2 {
  margin: 0 0 8px;
  font-size: 18px;
}
.recommendations p {
  margin: 7px 0;
}
.inline-form { display: grid; grid-template-columns: auto; gap: 8px; }
.proxy-form { display: grid; grid-template-columns: minmax(180px, 1fr) auto; gap: 8px; }
.flag-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 18px;
  margin: 0 7px 0 0;
  border: 1px solid #aeb7c5;
  border-radius: 2px;
  color: #1f2937;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
}
.flag-nl {
  background: linear-gradient(to bottom, #ae1c28 0 33%, #ffffff 33% 66%, #21468b 66% 100%);
}
.flag-ee {
  background: linear-gradient(to bottom, #0072ce 0 33%, #000000 33% 66%, #ffffff 66% 100%);
  color: #ffffff;
  text-shadow: 0 1px 1px #000000;
}
.flag-de {
  background: linear-gradient(to bottom, #000000 0 33%, #dd0000 33% 66%, #ffce00 66% 100%);
  color: #ffffff;
  text-shadow: 0 1px 1px #000000;
}
.flag-fi {
  background:
    linear-gradient(to bottom, transparent 0 38%, #002f6c 38% 62%, transparent 62% 100%),
    linear-gradient(to right, transparent 0 32%, #002f6c 32% 48%, transparent 48% 100%),
    #ffffff;
}
.flag-lv {
  background: linear-gradient(to bottom, #9e3039 0 40%, #ffffff 40% 60%, #9e3039 60% 100%);
}
.flag-unknown {
  background: repeating-linear-gradient(45deg, #eef2f7, #eef2f7 4px, #d9dee7 4px, #d9dee7 8px);
}
td .status-pill {
  display: inline-block;
  min-width: 62px;
  margin: 0;
  padding: 4px 8px;
  border-radius: 999px;
  color: white;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
td .status-pill.online { background: #15803d; }
td .status-pill.offline { background: #b91c1c; }
.metrics {
  display: grid;
  gap: 6px;
  min-width: 170px;
}
.metric {
  position: relative;
  display: grid;
  grid-template-columns: 42px 44px 1fr;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  padding: 3px 6px;
}
.metric span,
.metric strong {
  position: relative;
  z-index: 1;
  margin: 0;
  color: #172033;
  font-size: 12px;
}
.metric strong { text-align: right; }
.metric i {
  position: absolute;
  inset: 0 auto 0 0;
  max-width: 100%;
  opacity: .82;
  z-index: 0;
}
.metric.ok { border-color: #16a34a; }
.metric.warning { border-color: #d97706; }
.metric.danger { border-color: #dc2626; }
.metric.ok i { background: #bbf7d0; }
.metric.warning i { background: #fed7aa; }
.metric.danger i { background: #fecaca; }
.metric.unknown i { background: #cbd5e1; }
.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}
.confirm-dialog::backdrop { background: rgb(0 0 0 / 35%); }
.confirm-dialog h2 { margin: 0 0 10px; font-size: 20px; }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
button.secondary {
  border-color: var(--line);
  background: white;
  color: var(--text);
}
button.danger {
  border-color: var(--danger);
  background: var(--danger);
}
button.reboot-button {
  border-color: #d97706;
  background: #d97706;
}
button.reboot-button:hover { background: #b45309; }
.vpn-form { margin-bottom: 6px; }
.vpn-summary {
  display: inline-block;
  margin-top: 2px;
  padding: 4px 7px;
  border-radius: 6px;
  color: white;
  font-size: 12px;
  font-weight: 700;
}
.vpn-summary.ok { background: #15803d; }
.vpn-summary.warning { background: #f59e0b; color: #172033; }
.vpn-summary.danger { background: #b91c1c; }
.vpn-peers {
  display: grid;
  gap: 3px;
  margin-top: 5px;
}
.vpn-peers span {
  display: grid;
  grid-template-columns: auto auto;
  gap: 2px 6px;
  width: max-content;
  max-width: 220px;
  margin: 0;
  font-size: 11px;
}
.vpn-peers b,
.vpn-peers em,
.vpn-peers small {
  font: inherit;
}
.vpn-peers small {
  grid-column: 1 / -1;
  color: #475569;
}
.vpn-peers .active { color: #15803d; }
.vpn-peers .idle { color: #64748b; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.login-panel {
  width: min(420px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}
.login-panel form, .settings form {
  display: grid;
  gap: 14px;
}
label { display: grid; gap: 6px; color: var(--muted); }

@media (max-width: 760px) {
  .topbar, nav { align-items: flex-start; flex-direction: column; }
  .toolbar, .summary-grid, .history-grid { grid-template-columns: 1fr; }
  .toolbar form, .inline-form, .proxy-form { grid-template-columns: 1fr; }
}
