/* Antbox Speedtest Portal — sitewide bright theme */
:root {
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --surface-2: #F4F4EF;
  --ink: #0A0A0A;
  --ink-2: #2A2A28;
  --ink-muted: #6B7066;
  --border: #E8E8E3;
  --border-strong: #D6D6CF;
  --accent: #0066FF;
  --accent-deep: #0044CC;
  --accent-soft: #E6EFFF;
  --yellow: #FFB800;
  --yellow-soft: #FFF5D6;
  --green: #00B050;
  --green-soft: #DDF7E5;
  --red: #E11D48;
  --red-soft: #FFE5EB;
  --shadow-sm: 0 1px 2px rgba(10,10,10,0.04);
  --shadow-md: 0 4px 16px rgba(10,10,10,0.06);
  --shadow-lg: 0 24px 60px -20px rgba(10,10,10,0.18);
  --radius: 14px;
  --radius-lg: 22px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--ink);
  font-family: 'Twemoji Country Flags', 'Geist', system-ui, -apple-system, sans-serif;
  font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Webfont for country flag emoji glyphs only — covers Windows, which doesn't
   include flag emojis in Segoe UI Emoji. Scoped via unicode-range so it's
   ignored for any non-flag character; only fetched if a flag is rendered.
   Self-hosted (no CDN dependency) so it works on networks that block jsDelivr. */
@font-face {
  font-family: 'Twemoji Country Flags';
  unicode-range: U+1F1E6-1F1FF, U+1F3F4, U+E0062-E007F;
  src: url('/assets/fonts/TwemojiCountryFlags.woff2') format('woff2');
  font-display: swap;
}
body.portal::before {
  content: '';
  position: fixed; inset: 0;
  background-image:
    radial-gradient(circle at 20% 10%, rgba(0,102,255,0.05), transparent 50%),
    radial-gradient(circle at 90% 80%, rgba(255,184,0,0.06), transparent 45%),
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 60px 60px, 60px 60px;
  opacity: 0.35; pointer-events: none; z-index: -1;
}

h1, h2, h3 {
  font-family: 'Bricolage Grotesque', serif;
  font-weight: 600; letter-spacing: -0.02em; margin: 0;
}
.mono { font-family: 'JetBrains Mono', monospace; }

a { color: var(--accent); }
button { font-family: inherit; }

/* ===== Topbar ===== */
header.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(8px);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto;
  padding: 14px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand img { height: 40px; width: auto; display: block; }
.brand .divider { width: 1px; height: 24px; background: var(--border-strong); }
.brand .product {
  font-family: 'Bricolage Grotesque', serif;
  font-size: 16px; font-weight: 600;
  color: var(--ink-2); letter-spacing: -0.01em;
}
.admin-badge {
  background: var(--ink); color: #FFF;
  padding: 3px 9px; border-radius: 6px;
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.1em; margin-left: 4px;
}

/* ===== Main layout ===== */
main { max-width: 1240px; margin: 0 auto; padding: 48px 28px 64px; }

.hero { text-align: center; margin-bottom: 40px; }
.hero .eyebrow {
  display: inline-block;
  padding: 6px 12px; background: var(--yellow-soft); color: #8A6500;
  border: 1px solid #F2D573; border-radius: 100px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; margin-bottom: 18px;
}
.hero h1 { font-size: clamp(36px, 5vw, 56px); line-height: 1.05; margin-bottom: 14px; }
.hero h1 .underline {
  background: linear-gradient(180deg, transparent 60%, var(--yellow) 60%);
  padding: 0 6px;
}
.hero p { color: var(--ink-muted); font-size: 17px; max-width: 540px; margin: 0 auto; }

/* ===== Server picker ===== */
.server-picker {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-sm);
}
.server-picker-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.server-picker-header h3 {
  font-size: 14px; font-weight: 600; color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.server-status-summary { font-size: 12px; color: var(--ink-muted); }

.server-chips {
  display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px;
}
.server-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px 10px 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  cursor: pointer; transition: all 0.15s;
  flex-shrink: 0; min-width: 160px;
}
.server-chip:hover { border-color: var(--border-strong); background: var(--surface-2); }
.server-chip.selected { background: var(--ink); border-color: var(--ink); color: #FFF; }
.server-chip.offline { opacity: 0.45; cursor: not-allowed; }
.server-chip .flag { font-size: 24px; line-height: 1; }
.server-chip .info { display: flex; flex-direction: column; }
.server-chip .name { font-weight: 600; font-size: 14px; }
.server-chip .ping { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--ink-muted); }
.server-chip.selected .ping { color: rgba(255,255,255,0.7); }

.empty-state {
  padding: 24px; text-align: center; color: var(--ink-muted);
  border: 1px dashed var(--border-strong); border-radius: 12px; width: 100%;
}

/* ===== Test panel ===== */
.test-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 36px; margin-bottom: 28px;
  box-shadow: var(--shadow-md);
  position: relative; overflow: hidden;
}
.test-panel::before {
  content: ''; position: absolute; top: -100px; right: -100px;
  width: 320px; height: 320px;
  background: radial-gradient(circle, rgba(0,102,255,0.08), transparent 70%);
  pointer-events: none;
}

.gauge-wrap { display: flex; justify-content: center; margin-bottom: 36px; }
.gauge { position: relative; width: 360px; height: 360px; }

.client-ip-row {
  display: flex; justify-content: center; margin-bottom: 20px;
}
.client-ip-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 22px;
  display: inline-flex; align-items: center; gap: 14px;
}
.client-ip-card .label {
  font-size: 11px; color: var(--ink-muted);
  letter-spacing: 0.08em; text-transform: uppercase; font-weight: 600;
}
.client-ip-card .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px; font-weight: 600; color: var(--ink);
  letter-spacing: -0.01em;
}
.gauge-value {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
}
.gauge-label {
  font-size: 12px; font-weight: 600; color: var(--ink-muted);
  letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 8px;
}
.gauge-number {
  font-family: 'JetBrains Mono', monospace;
  font-size: 84px; font-weight: 600; line-height: 1;
  letter-spacing: -0.04em; color: var(--ink);
}
.gauge-unit { font-size: 14px; color: var(--ink-muted); margin-top: 8px; font-weight: 500; }

.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
}
.stat {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px 20px;
}
.stat .icon {
  width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px; font-size: 14px;
}
.stat.ping .icon { background: #E6F0FF; color: var(--accent); }
.stat.jitter .icon { background: #FFF5D6; color: #B07A00; }
.stat.download .icon { background: #DDF7E5; color: #008A3D; }
.stat.upload .icon { background: #FFE5EB; color: #C81E47; }
.stat .label {
  font-size: 12px; color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 600; margin-bottom: 4px;
}
.stat .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 28px; font-weight: 600; color: var(--ink);
  letter-spacing: -0.02em;
}
.stat .value .unit { font-size: 13px; color: var(--ink-muted); margin-left: 4px; }

.start-btn-wrap { display: flex; justify-content: center; margin-top: 32px; }
.start-btn {
  background: var(--ink); color: #FFF; border: none;
  padding: 16px 48px; font-size: 16px; font-weight: 600;
  border-radius: 100px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 10px;
  transition: all 0.2s;
  box-shadow: 0 4px 14px rgba(10,10,10,0.15);
}
.start-btn:not(:disabled):hover {
  background: var(--accent); transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0,102,255,0.25);
}
.start-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Footer */
footer {
  text-align: center; margin-top: 56px; padding: 24px 0;
  color: var(--ink-muted); font-size: 13px;
  border-top: 1px solid var(--border);
}
footer a { color: var(--ink-2); text-decoration: none; font-weight: 500; }

@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .gauge { width: 280px; height: 280px; }
  .gauge-number { font-size: 64px; }
}


/* ============== ADMIN STYLES ============== */
.user-menu {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 8px 6px 14px;
  border: 1px solid var(--border); border-radius: 100px;
  cursor: pointer; font-size: 13px; background: var(--surface);
}
.user-menu:hover { background: var(--surface-2); }
.user-menu a { color: var(--ink-2); text-decoration: none; }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #FFF; display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px;
}

.layout {
  display: grid; grid-template-columns: 240px minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}
aside.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 14px;
}
.sidebar-section { margin-bottom: 22px; }
.sidebar-label {
  font-size: 11px; font-weight: 600; color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 0 10px; margin-bottom: 8px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--ink-2); text-decoration: none;
  font-size: 14px; font-weight: 500;
  margin-bottom: 2px; transition: all 0.15s;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--ink); color: #FFF; }
.nav-item.active .nav-icon { color: var(--yellow); }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; }
.nav-count {
  margin-left: auto; background: var(--surface-2); color: var(--ink-muted);
  padding: 2px 7px; border-radius: 6px;
  font-size: 11px; font-family: 'JetBrains Mono', monospace; font-weight: 600;
}
.nav-item.active .nav-count { background: rgba(255,255,255,0.15); color: #FFF; }

main.content { padding: 28px 32px; max-width: 1200px; }
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 28px; margin-bottom: 6px; }
.page-header .sub { color: var(--ink-muted); font-size: 14px; }

.btn {
  border: none; padding: 10px 18px; border-radius: 10px;
  font-family: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  transition: all 0.15s; text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--ink); color: #FFF; box-shadow: 0 2px 8px rgba(10,10,10,0.12); }
.btn-primary:hover { background: var(--accent); }
.btn-ghost { background: var(--surface); color: var(--ink-2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--red); color: #FFF; }
.btn-danger:hover { background: #C01040; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow-sm); margin-bottom: 24px;
}
.panel-header {
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.panel-header h2 { font-size: 16px; letter-spacing: -0.01em; }
.panel-body { padding: 20px; }

/* Panel header variant that also hosts a tab bar */
.panel-header-tabs { flex-wrap: wrap; gap: 12px; }

/* Admin tab bar (filters table by IP family) */
.tab-bar {
  display: inline-flex; gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}
.tab-bar .tab {
  background: transparent; border: 0; cursor: pointer;
  padding: 6px 12px; border-radius: 7px;
  font-size: 13px; font-weight: 500; color: var(--ink-muted);
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.12s, color 0.12s;
}
.tab-bar .tab:hover { color: var(--ink); }
.tab-bar .tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.tab-bar .tab-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--ink-muted);
  background: rgba(0,0,0,0.04);
  padding: 1px 6px; border-radius: 999px;
  min-width: 18px; text-align: center;
}
.tab-bar .tab.active .tab-count {
  background: rgba(0,0,0,0.06); color: var(--ink);
}

/* Small IP-family badge next to country code in the admin server list */
.ip-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  vertical-align: 1px;
}
.ip-badge.ip-ipv4 { background: #E8F0FE; color: #1A4480; }
.ip-badge.ip-ipv6 { background: #E8F5E9; color: #1B5E20; }
.ip-badge.ip-both { background: #FFF4E5; color: #6B4500; }

/* Radio-group used in the Add/Edit modal for IP family selection */
.radio-group { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 4px; }
.radio-opt {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.radio-opt:hover { border-color: var(--ink-muted); }
.radio-opt input[type="radio"] { display: none; }
.radio-opt input[type="radio"]:checked + span { color: var(--ink); font-weight: 600; }
.radio-opt input[type="radio"]:checked ~ small { color: var(--ink-muted); }
.radio-opt:has(input[type="radio"]:checked) {
  border-color: var(--ink);
  background: var(--surface-2);
}
.radio-opt span { font-size: 13px; }
.radio-opt small { font-size: 11px; color: var(--ink-muted); }

/* Public portal protocol toggle (above server picker) */
.proto-toggle {
  display: inline-flex; gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  margin: 12px 0 4px;
}
.proto-toggle .proto-btn {
  background: transparent; border: 0; cursor: pointer;
  padding: 6px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 500; color: var(--ink-muted);
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.02em;
  transition: background 0.12s, color 0.12s;
}
.proto-toggle .proto-btn:hover { color: var(--ink); }
.proto-toggle .proto-btn.active {
  background: var(--ink);
  color: var(--surface);
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}
.proto-status {
  font-size: 12px; color: var(--ink-muted);
  min-height: 16px;
  margin-bottom: 8px;
}

.table {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
.table th {
  text-align: left; padding: 10px 20px;
  background: var(--surface-2); color: var(--ink-muted);
  font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(244,244,239,0.5); }

.status {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 10px; border-radius: 100px;
  font-size: 12px; font-weight: 600;
}
.status .dot { width: 6px; height: 6px; border-radius: 50%; }
.status.online { background: var(--green-soft); color: #006B30; }
.status.online .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(0,176,80,0.18); }
.status.offline { background: var(--red-soft); color: #95163B; }
.status.offline .dot { background: var(--red); }
.status.degraded, .status.unknown { background: var(--yellow-soft); color: #6B5100; }
.status.degraded .dot, .status.unknown .dot { background: var(--yellow); }
.status.unverified { background: #E8F0FE; color: #1A4480; }
.status.unverified .dot { background: #4A7BBF; box-shadow: 0 0 0 3px rgba(74,123,191,0.18); }

/* Floating indicator shown when the Speedtest Servers page auto-refreshes
   agent statuses on load. Unobtrusive bottom-right pill. */
#auto-refresh-indicator {
  position: fixed; bottom: 16px; right: 16px; z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  font-size: 13px;
  color: var(--ink-muted);
  display: inline-flex; align-items: center; gap: 8px;
  animation: refresh-pill-in 180ms ease-out;
}
#auto-refresh-indicator::before {
  content: '';
  width: 10px; height: 10px;
  border: 2px solid var(--border);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: refresh-pill-spin 0.8s linear infinite;
}
#auto-refresh-indicator.done {
  color: #1B5E20; border-color: rgba(27,94,32,0.2);
}
#auto-refresh-indicator.done::before {
  border: none; width: 0; height: 0;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-bottom: 6px solid #1B5E20; border-radius: 0; animation: none;
  transform: rotate(45deg) translate(1px, -2px);
}
#auto-refresh-indicator.error {
  color: #95163B; border-color: rgba(149,22,59,0.2);
}
#auto-refresh-indicator.error::before { animation: none; border-top-color: var(--red); }
@keyframes refresh-pill-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes refresh-pill-spin {
  to { transform: rotate(360deg); }
}

.endpoint {
  font-family: 'JetBrains Mono', monospace; font-size: 12px;
  color: var(--ink-2); background: var(--surface-2);
  padding: 3px 8px; border-radius: 6px; display: inline-block;
  max-width: 280px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle;
}

.row-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 28px; height: 28px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--ink-muted);
  transition: all 0.15s; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.danger:hover { background: var(--red-soft); color: var(--red); border-color: var(--red-soft); }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field input, .field select, .field textarea {
  padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: 8px; background: var(--surface);
  font-family: inherit; font-size: 14px; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent); border-color: var(--accent);
}
.field .hint { font-size: 12px; color: var(--ink-muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }

/* Login */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-card .brand { justify-content: center; margin-bottom: 24px; }
.login-card h1 { font-size: 22px; margin-bottom: 6px; text-align: center; }
.login-card .sub { text-align: center; color: var(--ink-muted); margin-bottom: 24px; font-size: 14px; }
.login-card .btn { width: 100%; justify-content: center; }

.flash {
  padding: 10px 14px; border-radius: 10px; margin-bottom: 16px;
  font-size: 14px; display: flex; align-items: center; gap: 8px;
}
.flash.success { background: var(--green-soft); color: #006B30; }
.flash.error { background: var(--red-soft); color: #95163B; }
.flash.info { background: var(--accent-soft); color: var(--accent-deep); }
.flash.warn { background: var(--yellow-soft); color: #6B5100; }

.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 14px; margin-bottom: 28px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px 18px;
}
.stat-card .label {
  font-size: 12px; color: var(--ink-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px;
}
.stat-card .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 26px; font-weight: 600; color: var(--ink);
  line-height: 1.1; letter-spacing: -0.02em;
}
.stat-card .trend { font-size: 12px; margin-top: 6px; color: var(--green); }
.stat-card .trend.neutral { color: var(--ink-muted); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10,10,10,0.45);
  display: none; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 18px; }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
}
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--ink-muted); font-size: 20px; line-height: 1;
}

/* Test detail / MTR display in admin */
.mtr-block {
  background: var(--surface-2); border-radius: 10px;
  padding: 12px; font-family: 'JetBrains Mono', monospace;
  font-size: 12px; white-space: pre-wrap; word-break: break-all;
  max-height: 320px; overflow: auto;
}

/* ===================== RESPONSIVE / MOBILE ===================== */

/* Hamburger button (visible on mobile only) */
.menu-toggle {
  display: none;
  background: none; border: none; cursor: pointer;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  color: var(--ink); padding: 0;
}
.menu-toggle svg { width: 24px; height: 24px; }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 64px 0 0 0;
  background: rgba(10,10,10,0.4);
  z-index: 49;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}

/* Horizontal scroll for tables that don't fit */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; min-width: 0; }
.table-wrap .table { min-width: 0; }

/* Containers must allow themselves to shrink narrower than their content
   (default min-width:auto on flex/grid items causes phone-wide overflow). */
main.content, .panel, .panel-body, .panel-header { min-width: 0; }

/* Tablet breakpoint — collapse 4-col stat grid to 2 col, single-column forms */
@media (max-width: 900px) {
  /* Drop the grid on mobile — use block layout so main.content reliably
     fills the viewport. Chrome's grid track algorithm was computing
     content-based widths for `minmax(0, 1fr)` in some cases. */
  .layout { display: block; }
  main.content {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }

  /* Sidebar becomes a slide-in drawer */
  aside.sidebar {
    display: block;
    position: fixed;
    top: 64px; bottom: 0; left: -260px;
    width: 260px;
    z-index: 50;
    overflow-y: auto;
    transition: left 0.22s ease;
    border-right: 1px solid var(--border);
  }
  body.sidebar-open aside.sidebar { left: 0; }
  body.sidebar-open .sidebar-backdrop { display: block; opacity: 1; pointer-events: auto; }
  .menu-toggle { display: inline-flex; }

  /* Topbar tightening */
  .topbar-inner { padding: 12px 12px; gap: 10px; }
  .brand img { height: 32px; }
  .brand .divider { display: none; }
  .brand .product { display: none; }
  .admin-badge { display: none; }
  .user-menu { padding: 4px 8px 4px 4px; }
  .user-menu .user-name { display: none; }

  /* Tighter main content padding */
  main.content { padding: 16px 12px; max-width: 100%; }

  /* Stat cards: drop the grid entirely on mobile and use plain block flow
     so cards take exactly the same width as <section class="panel"> below.
     Grid was producing inconsistent widths due to 1fr's intrinsic min-content
     behaviour on some browsers. */
  .stat-grid {
    display: block;
    margin-bottom: 18px;
  }
  .stat-card {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 14px 14px;
    margin-bottom: 10px;
  }
  .stat-card:last-child { margin-bottom: 0; }

  .panel { margin-bottom: 14px; }
  .panel-body { padding: 14px 12px; }
  .panel-header { padding: 12px 14px; }
  .page-header { margin-bottom: 18px; }

  /* IP-family radio cards stack on mobile */
  .radio-group { grid-template-columns: 1fr; }

  /* Tab bar can wrap and span full width on narrow screens */
  .panel-header-tabs { flex-direction: column; align-items: stretch; gap: 10px; }
  .tab-bar { width: 100%; justify-content: stretch; }
  .tab-bar .tab { flex: 1; justify-content: center; }

  /* Page header stacks vertically */
  .page-header { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-header > div:last-child { display: flex; flex-wrap: wrap; gap: 8px; }
  .page-header > div:last-child .btn { flex: 1; justify-content: center; min-width: 140px; }

  /* Tables — by default, wrap cell content so non-card tables fit too */
  .table-wrap { margin: 0 -1px; }
  .table th, .table td { padding: 10px 14px; }
  .endpoint { max-width: none; word-break: break-all; }

  /* ── Responsive card pattern for data tables ──
     Tables marked `.table-cards` collapse on mobile: each row becomes a
     stacked card with `Label: value` lines. Eliminates horizontal overflow
     entirely — no swiping needed. */
  .table-cards { display: block; }
  .table-cards thead { display: none; }
  .table-cards tbody, .table-cards tr, .table-cards td { display: block; }
  .table-cards tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;
  }
  .table-cards td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
    border: none;
    white-space: normal !important;
    word-break: break-word;
    overflow-wrap: anywhere;
    text-align: right;
    max-width: none !important;     /* override any inline max-width */
  }
  .table-cards td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--ink-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex-shrink: 0;
    text-align: left;
  }
  .table-cards td:not([data-label])::before,
  .table-cards td[data-label=""]::before { content: ""; display: none; }
  .table-cards .endpoint { max-width: none; white-space: normal; }

  /* The action-icons cell — buttons row-aligned, no label */
  .table-cards td.row-actions-cell {
    justify-content: flex-end;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
    margin-top: 4px;
  }
  .table-cards td.row-actions-cell::before { display: none; }
  .table-cards .row-actions { gap: 10px; }

  /* Modal goes near-fullscreen */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 18px 18px 0 0;
  }

  /* Filter form on results page */
  section.panel form[method="get"] {
    grid-template-columns: 1fr !important;
  }

  /* Touch targets */
  .icon-btn { width: 36px; height: 36px; }
  .row-actions { gap: 8px; }

  /* Login card */
  .login-card { padding: 28px 22px; }
}

/* Phone breakpoint — major layout shifts */
@media (max-width: 760px) {
  /* Public portal main padding */
  main { padding: 24px 16px 40px; }

  /* Hero */
  .hero { margin-bottom: 28px; }
  .hero h1 { font-size: clamp(28px, 8vw, 40px); }
  .hero p { font-size: 15px; }
  .hero .eyebrow { font-size: 11px; padding: 5px 10px; }

  /* Topbar (public portal) */
  .topbar-inner { padding: 12px 12px; }
  .brand img { height: 32px; }
  .brand .divider { display: none; }
  .brand .product { font-size: 14px; }

  /* Server picker */
  .server-picker { padding: 16px; border-radius: 16px; }
  .server-picker-header { flex-direction: column; align-items: flex-start; gap: 6px; }
  .server-chip { min-width: 140px; padding: 8px 14px 8px 10px; }
  .server-chip .name { font-size: 13px; }
  .server-chip .flag { font-size: 20px; }

  /* Test panel */
  .test-panel { padding: 28px 18px; border-radius: 16px; }
  .gauge-wrap { margin-bottom: 24px; }
  .gauge { width: min(280px, 78vw); height: min(280px, 78vw); }
  .gauge svg { width: 100%; height: 100%; }
  .gauge-number { font-size: clamp(48px, 14vw, 72px); }

  /* Client IP card — flex-col on phone for breathing room */
  .client-ip-card { flex-direction: column; gap: 4px; padding: 10px 18px; }
  .client-ip-card .value { font-size: 15px; }

  /* Stats: keep 2 cols, tighten */
  .stats { gap: 10px; }
  .stat { padding: 14px 14px; }
  .stat .value { font-size: 22px; }
  .stat .label { font-size: 11px; }

  /* Start button: full width */
  .start-btn-wrap { margin-top: 24px; }
  .start-btn { width: 100%; justify-content: center; padding: 14px 32px; }

  /* Admin: stat-grid stays 2-col, smaller values */
  .stat-card { padding: 14px 16px; }
  .stat-card .value { font-size: 22px; }

  /* Admin tables — make tables scroll horizontally inside their wrapper */
  .panel { overflow: hidden; }
  .table-wrap { overflow-x: auto; }

  /* Panel header tightens */
  .panel-header { padding: 14px 16px; }
  .panel-header h2 { font-size: 15px; }
  .panel-body { padding: 16px; }

  /* Footer */
  footer { margin-top: 32px; padding: 18px 16px; }
}

/* Small phone breakpoint */
@media (max-width: 480px) {
  main { padding: 16px 10px 32px; }
  main.content { padding: 12px 10px; }
  .stat-card { padding: 12px 14px; }
  .stat-grid { gap: 8px; }
  .panel-body { padding: 12px 10px; }
  .panel-header { padding: 10px 12px; }
  .page-header { margin-bottom: 14px; }
  .page-header h1 { font-size: 22px; }

  .topbar-inner { padding: 10px 10px; }
  .brand img { height: 28px; }

  .hero h1 { font-size: clamp(24px, 7.5vw, 32px); }
  .stat-grid { grid-template-columns: 1fr; }
  .stat-card .value { font-size: 24px; }

  /* Stats stay 2-col but icons smaller */
  .stat .icon { width: 22px; height: 22px; margin-bottom: 8px; font-size: 12px; }

  /* Page-header buttons stack vertically */
  .page-header > div:last-child { flex-direction: column; }
  .page-header > div:last-child .btn { width: 100%; }

  /* Stat-grid on admin: 1 col on tiny screens */
  .stat-grid { grid-template-columns: 1fr; }
}
body.admin { background: var(--bg); }
.admin header.topbar { height: 64px; }
