:root {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;
  --card: 240 10% 5.5%;
  --card-foreground: 0 0% 98%;
  --popover: 240 10% 5.5%;
  --popover-foreground: 0 0% 98%;
  --primary: 0 0% 98%;
  --primary-foreground: 240 5.9% 10%;
  --secondary: 240 3.7% 15.9%;
  --secondary-foreground: 0 0% 98%;
  --muted: 240 3.7% 15.9%;
  --muted-foreground: 240 5% 64.9%;
  --accent: 240 3.7% 15.9%;
  --accent-foreground: 0 0% 98%;
  --destructive: 0 62.8% 40%;
  --border: 240 3.7% 15.9%;
  --input: 240 3.7% 15.9%;
  --ring: 240 4.9% 83.9%;
  --radius: 0.75rem;
  --ok: 142 70% 45%;
  --warn: 38 92% 50%;
  --bad: 0 72% 55%;
  --sidebar: 240 10% 4.5%;
  --font: "Geist", ui-sans-serif, system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: hsl(var(--foreground));
  background:
    radial-gradient(900px 420px at 0% 0%, hsl(240 10% 12% / .55), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, hsl(240 8% 10% / .4), transparent 50%),
    hsl(var(--background));
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
.muted { color: hsl(var(--muted-foreground)); }
.mono { font-family: var(--mono); font-size: 0.8rem; }
.pad-x { padding: 0 16px 12px; }

.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: hsl(var(--sidebar));
  border-right: 1px solid hsl(var(--border));
  padding: 20px 14px; display: flex; flex-direction: column; gap: 20px;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 700; font-size: 0.85rem;
  background: hsl(var(--foreground)); color: hsl(var(--background));
}
.brand-title { font-weight: 600; letter-spacing: -0.02em; }
.brand-sub { color: hsl(var(--muted-foreground)); font-size: 0.75rem; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  padding: 9px 12px; border-radius: calc(var(--radius) - 2px);
  color: hsl(var(--muted-foreground)); font-size: 0.9rem; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.nav-item.active { background: hsl(var(--secondary)); color: hsl(var(--foreground)); }
.sidebar-foot {
  border-top: 1px solid hsl(var(--border)); padding-top: 14px; padding-left: 8px;
  font-size: 0.78rem;
}

.main { min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; gap: 16px; align-items: flex-start;
  padding: 22px 28px 8px; flex-wrap: wrap;
}
.page-title { margin: 0; font-size: 1.5rem; letter-spacing: -0.03em; font-weight: 650; }
.page-desc { margin: 4px 0 0; color: hsl(var(--muted-foreground)); font-size: 0.9rem; }
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.content { padding: 12px 28px 40px; }

.btn {
  appearance: none; border: 1px solid hsl(var(--border));
  background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground));
  border-radius: calc(var(--radius) - 2px); padding: 8px 14px;
  font: 500 0.875rem var(--font); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: hsl(240 3.7% 20%); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  border-color: transparent; font-weight: 600;
}
.btn-primary:hover { filter: brightness(0.92); }
.btn-ghost { background: transparent; }
.btn-xs { padding: 4px 8px; font-size: 0.75rem; }

.input {
  background: hsl(var(--background));
  border: 1px solid hsl(var(--input));
  color: hsl(var(--foreground));
  border-radius: calc(var(--radius) - 2px);
  padding: 8px 12px; font: 0.875rem var(--font);
  outline: none;
}
.input:focus { border-color: hsl(var(--ring)); box-shadow: 0 0 0 2px hsl(var(--ring) / .2); }

.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 0 hsl(0 0% 100% / .02);
}
.card-head {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid hsl(var(--border)); flex-wrap: wrap;
}
.card-head h2, .card h2, .card h3 { margin: 0; font-size: 0.95rem; letter-spacing: -0.01em; }
.panel-card { margin-top: 16px; }

.kpi-grid {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px;
}
.kpi { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.kpi .label {
  color: hsl(var(--muted-foreground)); font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 500;
}
.kpi strong { font-size: 1.45rem; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.kpi strong.small { font-size: 1rem; }
.kpi em { font-style: normal; color: hsl(var(--muted-foreground)); font-size: 0.78rem; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters .input { min-width: 140px; }
#search { min-width: 220px; flex: 1; }

.table-wrap { overflow: auto; max-height: 58vh; }
.table-wrap.compact { max-height: 420px; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid hsl(var(--border)); vertical-align: top; }
th {
  position: sticky; top: 0; z-index: 1;
  background: hsl(240 10% 6.5%);
  color: hsl(var(--muted-foreground));
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 550;
}
tbody tr { cursor: pointer; transition: background .12s; }
tbody tr:hover { background: hsl(240 3.7% 12%); }
.name { font-weight: 550; letter-spacing: -0.01em; }
.badge, .pill {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 999px; font-size: 0.72rem; font-weight: 500;
  background: hsl(var(--secondary)); border: 1px solid hsl(var(--border));
  margin-right: 4px;
}
.pill.ok { color: hsl(var(--ok)); border-color: hsl(var(--ok) / .35); }
.pill.bad { color: hsl(var(--bad)); border-color: hsl(var(--bad) / .35); }
.pager {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-top: 1px solid hsl(var(--border));
}
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 16px; }
.chart-card { padding: 14px 16px 18px; min-height: 250px; }
.chart-card canvas { max-height: 200px; }

.job-bar {
  margin: 0 28px; padding: 10px 14px; border-radius: var(--radius);
  background: hsl(var(--card)); border: 1px solid hsl(var(--border));
}
.job-text { font-family: var(--mono); font-size: 0.8rem; color: hsl(var(--muted-foreground)); margin-bottom: 8px; }
.progress { height: 6px; background: hsl(var(--secondary)); border-radius: 99px; overflow: hidden; }
.progress .bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, hsl(0 0% 98%), hsl(240 5% 64.9%));
  transition: width .25s;
}

.form-card { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.875rem; }
.field small { color: hsl(var(--muted-foreground)); font-size: 0.75rem; }
.field.check { flex-direction: row; align-items: center; gap: 10px; }

.timeline { list-style: none; margin: 0; padding: 8px 16px 16px; }
.timeline li { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid hsl(var(--border)); }
.timeline li:last-child { border-bottom: 0; }
.tl-dot {
  width: 10px; height: 10px; border-radius: 99px; margin-top: 5px; flex: 0 0 auto;
  background: hsl(var(--muted-foreground));
}
.tl-dot.ok { background: hsl(var(--ok)); }
.tl-dot.bad { background: hsl(var(--bad)); }
.tl-dot.warn { background: hsl(var(--warn)); }
.tl-title { font-weight: 550; font-size: 0.9rem; margin-bottom: 2px; }

.policy {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 16px;
}
.step {
  border: 1px dashed hsl(var(--border)); border-radius: var(--radius); padding: 14px;
  display: flex; gap: 10px; align-items: flex-start;
}
.step span {
  width: 24px; height: 24px; border-radius: 99px; display: grid; place-items: center;
  background: hsl(var(--secondary)); font-size: 0.75rem; font-weight: 600;
}
.step p { margin: 0; font-size: 0.85rem; color: hsl(var(--muted-foreground)); }

.api-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 16px;
}
.api-card {
  border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 2px);
  padding: 14px; display: flex; flex-direction: column; gap: 6px;
  transition: background .15s, border-color .15s;
}
.api-card:hover { background: hsl(var(--secondary)); border-color: hsl(var(--ring) / .35); }
.api-card strong { font-family: var(--mono); font-size: 0.8rem; }
.api-card span { color: hsl(var(--muted-foreground)); font-size: 0.8rem; }
.code-out {
  margin: 0 16px 16px; padding: 14px; border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--background)); border: 1px solid hsl(var(--border));
  font-family: var(--mono); font-size: 0.75rem; max-height: 420px; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
}

dialog.dlg {
  border: 1px solid hsl(var(--border)); border-radius: var(--radius);
  background: hsl(var(--popover)); color: hsl(var(--popover-foreground));
  width: min(720px, 94vw); padding: 0;
}
dialog.dlg::backdrop { background: hsl(0 0% 0% / .6); }
dialog.dlg header, dialog.dlg footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; gap: 10px;
}
dialog.dlg header { border-bottom: 1px solid hsl(var(--border)); }
dialog.dlg footer { border-top: 1px solid hsl(var(--border)); }
dialog.dlg h2 { margin: 0; font-size: 1rem; }
dialog.dlg pre {
  margin: 0; padding: 14px; max-height: 55vh; overflow: auto;
  font-family: var(--mono); font-size: 0.75rem; white-space: pre-wrap; word-break: break-all;
  background: hsl(var(--background));
}

.country-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 10px 14px; border-bottom: 1px solid hsl(var(--border));
}
.chip {
  appearance: none; border: 1px solid hsl(var(--border));
  background: hsl(var(--secondary)); color: hsl(var(--muted-foreground));
  border-radius: 999px; padding: 5px 10px; font: 500 0.75rem var(--font);
  cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.chip em { font-style: normal; opacity: .7; margin-left: 2px; }
.chip:hover { color: hsl(var(--foreground)); border-color: hsl(var(--ring) / .4); }
.chip.active {
  background: hsl(var(--foreground)); color: hsl(var(--background));
  border-color: transparent;
}

.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: 0.72rem; font-weight: 600;
  border: 1px solid hsl(var(--border)); background: hsl(var(--secondary));
  text-transform: uppercase; letter-spacing: 0.04em;
}
.status-badge .dot {
  width: 6px; height: 6px; border-radius: 99px; background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in oklab, currentColor 20%, transparent);
}
.status-badge.ok { color: hsl(var(--ok)); border-color: hsl(var(--ok) / .3); }
.status-badge.warn { color: hsl(var(--warn)); border-color: hsl(var(--warn) / .3); }
.status-badge.bad { color: hsl(var(--bad)); border-color: hsl(var(--bad) / .3); }

.ping-bar {
  margin-top: 4px; height: 3px; width: 72px; border-radius: 99px;
  background: hsl(var(--secondary)); overflow: hidden;
}
.ping-bar i { display: block; height: 100%; border-radius: 99px; }
.ping-bar i.ok { background: hsl(var(--ok)); }
.ping-bar i.good { background: #86efac; }
.ping-bar i.warn { background: hsl(var(--warn)); }
.ping-bar i.bad { background: hsl(var(--bad)); }

.group-row td { padding: 0; border-bottom: 1px solid hsl(var(--border)); }
.group-label {
  padding: 8px 14px; font-size: 0.8rem; font-weight: 600;
  background: hsl(240 10% 7%); color: hsl(var(--muted-foreground));
  letter-spacing: 0.02em;
}
.group-label em { font-style: normal; opacity: .65; margin-left: 6px; font-weight: 500; }

.actions-cell { white-space: nowrap; }
.cc { font-variant-numeric: tabular-nums; }
#btnReverse.active { background: hsl(var(--foreground)); color: hsl(var(--background)); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(12px);
  background: hsl(var(--foreground)); color: hsl(var(--background));
  padding: 10px 16px; border-radius: 999px; font-size: 0.85rem; font-weight: 560;
  z-index: 50; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s;
  box-shadow: 0 10px 30px hsl(0 0% 0% / .35);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 1100px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .grid-2, .api-grid, .policy { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .content, .topbar, .job-bar { padding-left: 14px; padding-right: 14px; }
}
