: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; display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "text actions"
    "job job";
  grid-template-rows: auto 48px; /* reserved job row — no content jump */
  gap: 10px 16px;
  align-items: start;
  padding: 16px 28px 12px;
  background: hsl(var(--background) / .82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid hsl(var(--border) / .7);
}
.topbar-text { grid-area: text; min-width: 0; }
.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 { grid-area: actions; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.content { padding: 12px 28px 40px; flex: 1; }

.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;
  min-height: 96px; justify-content: space-between;
}
.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; font-feature-settings: "tnum";
  font-family: var(--mono);
  min-height: 1.35em;
}
.kpi strong.small { font-size: 1rem; }
.kpi em {
  font-style: normal; color: hsl(var(--muted-foreground)); font-size: 0.78rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

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

/* Lives in reserved topbar row — opacity only, never collapses layout */
.job-bar {
  grid-area: job;
  display: grid !important; /* keep slot even with [hidden] */
  grid-template-rows: auto 6px;
  gap: 6px;
  align-content: center;
  height: 48px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: hsl(var(--card) / .55);
  border: 1px solid transparent;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, border-color .2s ease, background .2s ease;
}
.job-bar.is-on {
  opacity: 1;
  pointer-events: auto;
  background: hsl(var(--card));
  border-color: hsl(var(--border));
}
.job-bar[hidden] { /* ignore native collapse — slot stays */ }
.job-text {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  min-height: 1.2em;
}
.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); }
.status-badge.muted {
  color: hsl(var(--muted-foreground));
  border-color: hsl(var(--border));
  opacity: 0.9;
}
tr.server-row.is-archive { opacity: 0.72; }

.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; }
.tag-row { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; }
.pill.tag-lte { color: #93c5fd; border-color: rgba(147,197,253,.35); }
.pill.tag-wl { color: #86efac; border-color: rgba(134,239,172,.35); }
.pill.tag-mobile { color: #fcd34d; border-color: rgba(252,211,77,.35); }
#btnReverse.active { background: hsl(var(--foreground)); color: hsl(var(--background)); }

/* —— client subscription panel —— */
.sub-hero {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 0;
  overflow: hidden;
  background:
    linear-gradient(135deg, hsl(240 10% 7%) 0%, hsl(240 8% 5%) 55%, hsl(150 20% 8% / .35) 100%),
    hsl(var(--card));
}
.sub-hero-main { padding: 22px 22px 20px; }
.sub-kicker {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em;
  color: hsl(var(--muted-foreground)); font-weight: 600; margin-bottom: 8px;
}
.sub-hero-title {
  margin: 0 0 8px; font-size: 1.35rem; letter-spacing: -0.03em; font-weight: 650;
}
.sub-hero-text {
  margin: 0 0 14px; color: hsl(var(--muted-foreground)); font-size: 0.9rem;
  line-height: 1.45; max-width: 46ch;
}
.sub-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.sub-hero-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
  background: hsl(var(--border));
  border-left: 1px solid hsl(var(--border));
}
.sub-stat {
  background: hsl(240 10% 5.2%);
  padding: 18px 16px; display: flex; flex-direction: column; gap: 4px;
}
.sub-stat em {
  font-style: normal; font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: hsl(var(--muted-foreground)); font-weight: 550;
}
.sub-stat strong {
  font-size: 1.55rem; letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
}

.sub-link-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px;
  padding: 16px;
}
.sub-link {
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  padding: 14px 14px 12px;
  display: flex; flex-direction: column; gap: 10px;
  background: hsl(240 10% 4.8%);
  transition: border-color .15s, background .15s;
}
.sub-link:hover { border-color: hsl(var(--ring) / .4); background: hsl(240 8% 7%); }
.sub-link.is-primary {
  border-color: hsl(0 0% 100% / .18);
  background:
    linear-gradient(160deg, hsl(0 0% 100% / .06), transparent 55%),
    hsl(240 10% 6%);
}
.sub-link-top {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
}
.sub-link-title { margin: 0; font-size: 0.95rem; font-weight: 600; letter-spacing: -0.01em; }
.sub-link-sub { margin: 3px 0 0; font-size: 0.78rem; color: hsl(var(--muted-foreground)); }
.sub-link-clients { font-size: 0.72rem; color: hsl(var(--muted-foreground)); }
.sub-link-url {
  width: 100%; font-family: var(--mono); font-size: 0.72rem;
  background: hsl(var(--background));
}
.sub-link-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.howto-list {
  margin: 0; padding: 14px 18px 18px 32px;
  color: hsl(var(--muted-foreground)); font-size: 0.88rem; line-height: 1.55;
}
.howto-list li { margin-bottom: 8px; }
.howto-list strong { color: hsl(var(--foreground)); font-weight: 600; }
.chip.soft { cursor: default; }
.chip.soft:hover { color: hsl(var(--muted-foreground)); border-color: hsl(var(--border)); }

.truncate {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.muted.bad { color: hsl(var(--bad)); }

.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, .sub-hero, .sub-link-grid { grid-template-columns: 1fr; }
  .sub-hero-stats { border-left: 0; border-top: 1px solid hsl(var(--border)); }
}
@media (max-width: 700px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .content, .topbar { padding-left: 14px; padding-right: 14px; }
  .topbar { grid-template-columns: 1fr; grid-template-areas: "text" "actions" "job"; grid-template-rows: auto auto 48px; }
  .top-actions { justify-content: flex-start; }
}
