/* ── Theme tokens ─────────────────────────────────────────────────────────
   Light is the default (matches the Manage Subsites design); dark is opt-in
   via <html data-theme="dark">. Toggle lives in the sidebar. */
:root,
:root[data-theme="light"] {
  --bg: #eef0f3;
  --card: #ffffff;
  --card-hover: #fbfcfd;
  --line: #e3e6ea;
  --line-soft: #eef0f3;
  --fg: #1c2530;
  --fg-soft: #3c4756;
  --muted: #6b7785;
  --label: #9aa5b1;
  --accent: #2f6fed;
  --accent-soft: #eaf1fe;
  --sidebar-bg: #ffffff;
  --sidebar-fg: #1c2530;
  --sidebar-line: #e3e6ea;
  --input-bg: #ffffff;
  --code-bg: #f3f5f7;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.04);
  --shadow-hover: 0 2px 6px rgba(16,24,40,.10), 0 4px 12px rgba(16,24,40,.06);
  --ok: #18794e; --ok-bg: #e6f6ec;
  --warn: #92610b; --warn-bg: #fcf3e3;
  --err: #c4332a; --err-bg: #fdeceb;
  --info: #1d4ed8; --info-bg: #e6effe;
  --ibadge-bg: #f0f0f0; --ibadge-fg: #475569;
}
:root[data-theme="dark"] {
  --bg: #0f1419;
  --card: #1a212b;
  --card-hover: #1e2733;
  --line: #2a3441;
  --line-soft: #222b36;
  --fg: #e6edf3;
  --fg-soft: #c4cdd6;
  --muted: #8b98a5;
  --label: #6b7785;
  --accent: #2f81f7;
  --accent-soft: #2f81f71f;
  --sidebar-bg: #131922;
  --sidebar-fg: #e6edf3;
  --sidebar-line: #2a3441;
  --input-bg: #0f1419;
  --code-bg: #0d1117;
  --shadow: 0 1px 2px rgba(0,0,0,.30);
  --shadow-hover: 0 4px 14px rgba(0,0,0,.45);
  --ok: #7ee2a8; --ok-bg: #1f7a4422;
  --warn: #e3b341; --warn-bg: #9e6a0022;
  --err: #ff7b72; --err-bg: #c4332a22;
  --info: #79c0ff; --info-bg: #1f6feb22;
  --ibadge-bg: #222b36; --ibadge-fg: #c4cdd6;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex: 0 0 236px; background: var(--sidebar-bg); color: var(--sidebar-fg);
  border-right: 1px solid var(--sidebar-line); display: flex; flex-direction: column; padding: 18px 0;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 8px; padding: 0 18px 16px; }
.brand .logo { font-weight: 800; font-size: 18px; letter-spacing: -.01em; }
.brand .logo span { color: var(--accent); }
/* mode badge pinned to the sidebar's top-right corner (dbdash pill + dot) */
.brand .badge { margin-left: auto; font-size: 10px; font-weight: 700; letter-spacing: .4px;
  padding: 3px 8px; border-radius: 999px; line-height: 1.4;
  display: inline-flex; align-items: center; gap: 5px; }
.brand .badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.brand .badge-live::before { animation: rp-pulse 2s infinite; }
@keyframes rp-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(24,121,78,.5); }
  70%  { box-shadow: 0 0 0 6px rgba(24,121,78,0); }
  100% { box-shadow: 0 0 0 0 rgba(24,121,78,0); }
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 8px; }
.sidebar nav a {
  padding: 9px 12px; color: var(--muted); border-radius: 9px; font-weight: 550;
  display: flex; align-items: center; gap: 11px;
}
.sidebar nav a .ic { width: 18px; height: 18px; }

/* generic inline icon */
.ic { width: 14px; height: 14px; flex: 0 0 auto; vertical-align: -2px; }
.sidebar nav a:hover { background: var(--card-hover); color: var(--fg); text-decoration: none; }
.sidebar nav a.on { background: var(--accent-soft); color: var(--accent); }
.side-foot { margin-top: auto; padding: 12px 18px 0; color: var(--muted); display: flex; align-items: center; justify-content: flex-end; gap: 8px; }

/* footer action buttons (logout + theme) — dbdash .toggle style, 34x34 square */
.foot-actions { display: flex; align-items: center; gap: 8px; }
.toggle {
  border: 1px solid var(--line); background: var(--card-hover); color: var(--muted);
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
  display: grid; place-items: center; text-decoration: none;
}
.toggle:hover { border-color: var(--accent); color: var(--accent); }
.toggle svg, .toggle .ic { width: 16px; height: 16px; }
/* raw stroke icons (logout, hamburger) — the .ic macro icons carry their own */
.toggle svg:not(.ic), .mtop #menuBtn svg { stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
/* theme toggle: box from .toggle; nudge the icon right to optically center it */
.theme-toggle { padding-left: 9px; }
.theme-toggle .ic-sun, .theme-toggle .ic-moon { display: none; align-items: center; }
/* light mode shows the moon (click → dark); dark mode shows the sun (click → light) */
:root[data-theme="light"] .theme-toggle .ic-moon { display: inline-flex; }
:root[data-theme="dark"]  .theme-toggle .ic-sun  { display: inline-flex; }

.content { flex: 1; padding: 26px 30px; max-width: 1280px; width: 100%; }

/* mobile top bar + drawer backdrop — hidden on desktop, shown under the mobile
   breakpoint (see Responsive) where the sidebar goes off-canvas */
.mtop { display: none; }
.mbackdrop { display: none; }

/* ── Toolbar / page head ────────────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.toolbar .count-pill {
  color: var(--muted); font-size: 13px; margin-left: 2px;
}
.toolbar .spacer { flex: 1; }
.page-head { display: flex; align-items: baseline; gap: 16px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; margin: 0; font-weight: 700; }

/* ── Filter / pagination bar ────────────────────────────────────────────── */
.filterbar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.filterbar .spacer { flex: 1 1 12px; }
.searchwrap { position: relative; flex: 0 0 200px; width: 200px; }
.searchwrap input { width: 100%; padding-left: 34px; }
.searchwrap::before {
  content: "⌕"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  font-size: 17px; color: var(--muted); pointer-events: none;
}
/* labels sit on top of their dropdown */
.selwrap {
  flex-direction: column; align-items: flex-start; gap: 5px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase; color: var(--label);
}
.selwrap select {
  font-size: 13px; text-transform: none; letter-spacing: normal; font-weight: 500;
  color: var(--fg); padding: 7px 9px;
}
/* count + page dropdown: keep them vertically centred with each other */
.pagination { display: flex; align-items: center; gap: 12px; }
.showing { color: var(--muted); font-size: 13px; white-space: nowrap; }
.filterbar button.primary { padding: 9px 15px; }
/* page dropdown (label baked into the options) — match the filter selects */
.filterbar .pagesel { padding: 7px 9px; font-size: 13px; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 20px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; margin: 0 0 14px; font-weight: 600; }
.count { color: var(--muted); font-weight: 400; }
.muted { color: var(--muted); }
.section-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; }
.section-head h2 { margin: 0; }

/* ── Card-row list (the Manage-Subsites look) ───────────────────────────── */
.list { display: flex; flex-direction: column; gap: 12px; }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 16px 18px; transition: box-shadow .12s, border-color .12s, background .12s;
}
.item:hover { box-shadow: var(--shadow-hover); border-color: var(--line); background: var(--card-hover); }
.item-row { display: flex; align-items: center; gap: 20px; }
/* fixed-width info column so the field columns line up across every card */
.item-main { display: flex; align-items: center; gap: 14px; flex: 0 0 360px; width: 360px; min-width: 0; }
.item-main > div { min-width: 0; }
/* proxies: the title column FLEXES (grows/shrinks) so the fixed stat columns +
   the actions kebab always stay on screen and line up across every card */
.item-main.wide { flex: 1 1 300px; width: auto; min-width: 0; }
/* long titles truncate with an ellipsis (hover shows the full name via title="") */
.item-main .item-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; word-break: normal; }
.avatar {
  width: 46px; height: 46px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--line);
}
/* proxy cards stack title + two badge rows; the logo box grows to match that
   3-row height and top-aligns with the title */
.item-main.wide { align-items: flex-start; }
.item-main.wide .avatar { width: 84px; height: 84px; border-radius: 16px; font-size: 33px; }
.item-title { font-size: 16px; font-weight: 650; color: var(--fg); line-height: 1.25; word-break: break-all; }
.item-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.item-sub code { background: var(--code-bg); padding: 1px 6px; border-radius: 5px; color: var(--fg-soft); }
.item-sub.badges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

/* icon badges (origin / upstream on proxy cards) */
.ibadge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 7px;
  font-size: 12px; font-weight: 600; max-width: 280px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
  background: var(--ibadge-bg); color: var(--ibadge-fg);   /* neutral, incl. the #ID badge */
}
.ibadge .ic { width: 13px; height: 13px; }
/* type badge: org (blue) vs player (green) vs event (amber) — colored to stand out from the
   neutral origin/upstream/#ID badges */
.ibadge.ptype-org    { background: #e6effb; color: #1f5fb0; }
.ibadge.ptype-player { background: #e7f6ec; color: #2f7d34; }
.ibadge.ptype-event  { background: #fdf0dd; color: #9a6212; }
:root[data-theme="dark"] .ibadge.ptype-org    { background: #1c3350; color: #8fbaf0; }
:root[data-theme="dark"] .ibadge.ptype-player { background: #1d3a25; color: #8fd39a; }
:root[data-theme="dark"] .ibadge.ptype-event  { background: #40300f; color: #e3b467; }
.item-sub .alias { font-size: 12px; color: var(--muted); }

/* unique-visitors column: 7-day area sparkline on the left, total on the right
   (own 200px column between the title block and Status/Cache/SSL, pushing them right) */
.traffic-col { flex: 0 0 200px; width: 200px; padding-right: 18px; }
.fields.fixed .traffic-col .tvalue { display: flex; align-items: center; gap: 10px; white-space: nowrap; word-break: normal; }
.spark { display: block; width: 118px; height: 28px; flex: 0 0 auto; overflow: visible; }
.spark .line {
  fill: none; stroke: var(--accent, #3b82f6); stroke-width: 1.5;
  stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke;
}
.spark .area { stroke: none; fill: url(#spark-grad); }
.spark-grad-top { stop-color: var(--accent, #3b82f6); stop-opacity: .30; }
.spark-grad-bot { stop-color: var(--accent, #3b82f6); stop-opacity: 0; }
/* no-traffic state: a clearly-visible muted flat baseline so the chart area still
   reads as an (empty) chart — the number keeps the exact same column position as
   rows that have data, it just no longer floats next to an invisible sparkline */
svg.spark.empty { padding: 0; }
.spark.empty .line { stroke: var(--muted); opacity: .6; stroke-dasharray: 3 3; }
.spark.empty .area { fill: none; }
.tnum { font-size: 15px; font-weight: 700; color: var(--fg); white-space: nowrap; }

.fields { display: flex; align-items: center; gap: 26px; flex: 1; flex-wrap: wrap; }
/* fixed columns (proxy cards): Status / Cache / SSL, aligned row-to-row */
.fields.fixed { flex: 0 0 auto; flex-wrap: nowrap; gap: 0; }
.fields.fixed .field { padding-right: 18px; }
/* explicit column widths (named, not positional) so reordering never shifts them.
   Order on the card: Status · Unique visitors · Cache · SSL */
.fields.fixed .col-status { flex: 0 0 108px; width: 108px; }
.fields.fixed .col-cache  { flex: 0 0 172px; width: 172px; }
.fields.fixed .col-ssl    { flex: 0 0 264px; width: 264px; }
.fields.fixed .value { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }

/* inline quick-action icon buttons in the Cache / SSL columns */
.iconbtn {
  display: inline-grid; place-items: center; width: 28px; height: 28px; padding: 0; margin-left: 3px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--card);
  color: var(--muted); cursor: pointer; flex: 0 0 auto;
  transition: color .12s, border-color .12s, background .12s;
}
.iconbtn:hover { color: var(--accent); border-color: var(--accent); background: var(--card-hover); }
.iconbtn .ic { width: 16px; height: 16px; }

/* cache green/grey dot + size; SSL green/grey padlock + expiry */
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.dot-on { background: var(--ok); }
.dot-off { background: var(--label); }
.dot-red { background: var(--err); }
.metric { font-size: 13px; color: var(--fg-soft); }
.metric.muted { color: var(--muted); text-transform: uppercase; font-size: 12px; letter-spacing: .03em; }
.ssl-on, .ssl-off { display: inline-flex; align-items: center; }
.ssl-on .ic { color: var(--ok); width: 15px; height: 15px; }
.ssl-off .ic { color: var(--muted); width: 15px; height: 15px; }


/* origins cards: fixed per-column widths so DOMAIN / API BASE URL / PROXIES align */
.fields.origins { flex: 0 0 auto; flex-wrap: nowrap; gap: 0; }
.fields.origins .field { padding-right: 18px; }
.fields.origins .field:nth-child(1) { flex: 0 0 200px; width: 200px; }   /* Domain */
.fields.origins .field:nth-child(2) { flex: 0 0 300px; width: 300px; }   /* API Base URL */
.fields.origins .field:nth-child(3) { flex: 0 0 90px;  width: 90px; }    /* Proxies */
.fields.origins .value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field .label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--label); display: inline-flex; align-items: center; gap: 5px;
}
.field .label .ic { width: 12px; height: 12px; }
.field .value { font-size: 13.5px; color: var(--fg-soft); word-break: break-all; }
.field .value.big { font-size: 18px; font-weight: 700; color: var(--fg); }
.field.num { min-width: 64px; }

.item-actions { display: flex; align-items: center; gap: 7px; flex: 0 0 auto; margin-left: auto; position: relative; }

/* ── Kebab (⋯) dropdown menu ─────────────────────────────────────────────── */
.item:has(details.menu[open]) { z-index: 20; }
details.menu { position: relative; }
details.menu > summary {
  list-style: none; cursor: pointer; width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--fg-soft);
  display: grid; place-items: center; font-size: 20px; line-height: 1; user-select: none;
}
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary:hover,
details.menu[open] > summary { border-color: var(--accent); color: var(--accent); }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 178px; z-index: 40;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-hover); padding: 6px; display: flex; flex-direction: column; gap: 1px;
}
/* prefixed with details.menu so these beat the bordered `.item-actions button`
   rule (equal specificity otherwise → the later, bordered rule would win) */
details.menu .menu-list a, details.menu .menu-list button {
  text-align: left; width: 100%; background: none; border: none; color: var(--fg-soft);
  padding: 8px 10px; border-radius: 7px; font-size: 13px; font-weight: 500; cursor: pointer;
  display: flex; align-items: center; gap: 9px;
}
details.menu .menu-list .ic { width: 15px; height: 15px; opacity: .8; flex: 0 0 auto; }
details.menu .menu-list a:hover, details.menu .menu-list button:hover {
  background: var(--accent-soft); color: var(--accent); text-decoration: none; filter: none; border: none;
}
details.menu .menu-list button.danger { color: var(--err); background: none; border: none; }
details.menu .menu-list button.danger:hover { background: var(--err-bg); color: var(--err); border: none; }
.menu-sep { height: 1px; background: var(--line); margin: 5px 4px; }

/* ── Modal dialog ───────────────────────────────────────────────────────── */
dialog.modal {
  border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(560px, 92vw);
  background: var(--card); color: var(--fg); box-shadow: 0 24px 64px rgba(16,24,40,.32);
}
dialog.modal::backdrop { background: rgba(16,24,40,.45); }
.modal-form { display: flex; flex-direction: column; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-head .x {
  background: none; border: none; color: var(--muted); font-size: 24px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.modal-head .x:hover { color: var(--fg); filter: none; }
.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-body.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-body label { color: var(--muted); }
.modal-body input, .modal-body select { width: 100%; }
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--line);
  background: var(--line-soft); border-radius: 0 0 14px 14px;
}
.modal-foot .spacer { flex: 1; }

/* ── Error modal ────────────────────────────────────────────────────────── */
dialog.error-modal { width: min(560px, 94vw); }
.error-modal .modal-head h3 {
  display: flex; align-items: center; gap: 8px; color: var(--err);
}
.error-modal .modal-head h3 .ic { width: 18px; height: 18px; }
.err-msg { margin: 0; line-height: 1.5; color: var(--fg); }
.err-detail summary {
  cursor: pointer; color: var(--muted); font-size: 12px; user-select: none;
}
.err-detail pre {
  white-space: pre-wrap; word-break: break-word; margin: 8px 0 0;
  background: var(--code-bg); color: var(--fg-soft);
  padding: 10px 12px; border-radius: 8px; font-size: 12px;
  max-height: 220px; overflow: auto;
}

/* ── Right-side slide-in drawer (origin API logs) ───────────────────────── */
dialog.drawer {
  /* pin to the right edge, full height, 75% wide */
  position: fixed; inset: 0 0 0 auto; margin: 0;
  height: 100vh; max-height: 100vh; width: 75vw; max-width: 75vw;
  border: none; border-left: 1px solid var(--line); border-radius: 0;
  padding: 0; background: var(--card); color: var(--fg);
  box-shadow: -24px 0 64px rgba(16,24,40,.32);
  /* slide in/out; allow-discrete lets the open/close transition run */
  transform: translateX(100%);
  transition: transform .25s ease,
              overlay .25s ease allow-discrete,
              display .25s ease allow-discrete;
}
dialog.drawer[open] { transform: translateX(0); }
@starting-style { dialog.drawer[open] { transform: translateX(100%); } }
dialog.drawer::backdrop {
  background: rgba(16,24,40,0);
  transition: background .25s ease,
              overlay .25s ease allow-discrete,
              display .25s ease allow-discrete;
}
dialog.drawer[open]::backdrop { background: rgba(16,24,40,.45); }
@starting-style { dialog.drawer[open]::backdrop { background: rgba(16,24,40,0); } }

.drawer-inner { display: flex; flex-direction: column; height: 100%; }
.drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0 0 2px; font-size: 17px; font-weight: 700; }
.drawer-head .x {
  background: none; border: none; color: var(--muted); font-size: 20px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.drawer-head .x:hover { color: var(--fg); }
.drawer-body { flex: 1; overflow: auto; padding: 8px 22px 22px; }
@media (max-width: 760px) { dialog.drawer { width: 100vw; max-width: 100vw; } }

/* key cell */
.keycell { display: flex; align-items: center; gap: 8px; }
.keycell .key { background: var(--code-bg); padding: 3px 8px; border-radius: 6px; color: var(--fg-soft); }

/* ── Forms ──────────────────────────────────────────────────────────────── */
form .row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
input, select {
  padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--input-bg); color: var(--fg); font-size: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
form.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
form.searchbar { display: flex; gap: 8px; margin-bottom: 16px; }
form.searchbar input { flex: 1; max-width: 460px; }
form.inline input { font-size: 13px; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
button {
  padding: 8px 15px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; cursor: pointer; font-size: 13px; font-weight: 600;
}
button:hover { filter: brightness(1.07); }
.item-actions button, .btnlink, button.ghost {
  padding: 6px 11px; font-size: 12.5px; font-weight: 600; background: var(--card); color: var(--fg-soft);
  border: 1px solid var(--line); border-radius: 8px; display: inline-flex; align-items: center; gap: 5px;
}
.item-actions button:hover, .btnlink:hover, button.ghost:hover { border-color: var(--accent); color: var(--accent); filter: none; text-decoration: none; }
.item-actions button.danger, button.danger { color: var(--err); border-color: transparent; background: var(--err-bg); }
.item-actions button.danger:hover, button.danger:hover { border-color: var(--err); color: var(--err); }
button.link { border: none; background: none; color: var(--accent); padding: 2px 4px; font-size: 12px; font-weight: 600; }

/* ── Badges & pills ─────────────────────────────────────────────────────── */
.badge { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-sandbox { background: var(--info-bg); color: var(--info); border: 1px solid transparent; }
.badge-live { background: var(--ok-bg); color: var(--ok); border: 1px solid transparent; }

/* inline spinner (htmx request indicator, e.g. on the proxy Status while toggling) */
.spinner {
  width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: rp-spin .6s linear infinite; vertical-align: -3px; margin-left: 6px;
}
.spinner.htmx-indicator { display: none; }
.spinner.htmx-indicator.htmx-request { display: inline-block; }
@keyframes rp-spin { to { transform: rotate(360deg); } }

.pill { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.pill-active, .pill-on { background: var(--ok-bg); color: var(--ok); }
.pill-disabled, .pill-empty, .pill-off { background: var(--line-soft); color: var(--muted); }
.pill-pending { background: var(--warn-bg); color: var(--warn); }
.pill-error, .pill-none { background: var(--err-bg); color: var(--err); }
.tag { padding: 3px 10px; border-radius: 6px; font-size: 11px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; background: var(--info-bg); color: var(--info); }

/* ── Tables (settings / logs / audit) ───────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--label); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
tr:last-child td { border-bottom: none; }
table.kv th { width: 170px; text-transform: none; color: var(--muted); font-weight: 600; }
td code, .kv code { background: var(--code-bg); padding: 2px 6px; border-radius: 5px; }
small { color: var(--muted); }

/* ── Alerts ─────────────────────────────────────────────────────────────── */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.alert-error { background: var(--err-bg); border: 1px solid var(--err); color: var(--err); }
.alert-ok { background: var(--ok-bg); border: 1px solid var(--ok); color: var(--ok); }
.empty { color: var(--muted); text-align: center; padding: 28px; }
.audit .detail { color: var(--muted); font-size: 12px; max-width: 360px; word-break: break-word; }
tr.fail td { background: var(--err-bg); }
tr.ok td { }

.section-head h2 .ic, .card h2 .ic { width: 16px; height: 16px; vertical-align: -3px; margin-right: 4px; color: var(--muted); }

/* ── Tabs (API page) ────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs a {
  display: inline-flex; align-items: center; gap: 7px; padding: 10px 14px; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 14px; border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a:hover { color: var(--fg); text-decoration: none; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); }
.tabs a .ic { width: 15px; height: 15px; }

/* ── Engine mode card (Settings) ────────────────────────────────────────── */
.mode-card.live    { border-color: var(--err); box-shadow: inset 3px 0 0 var(--err), var(--shadow); }
.mode-card.sandbox { border-color: var(--info); box-shadow: inset 3px 0 0 var(--info), var(--shadow); }
.mode-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.mode-control { display: flex; align-items: center; gap: 14px; flex: 0 0 auto; }
.mode-control .badge { font-size: 13px; }

/* ── HTTP method labels & log tables ────────────────────────────────────── */
.method {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 5px; letter-spacing: .02em;
}
.method-get    { background: var(--ok-bg);   color: var(--ok); }
.method-post   { background: var(--info-bg); color: var(--info); }
.method-delete { background: var(--err-bg);  color: var(--err); }
.method-put, .method-patch { background: var(--warn-bg); color: var(--warn); }
table.logs td { font-size: 13px; vertical-align: middle; }
table.logs td code { background: var(--code-bg); padding: 2px 6px; border-radius: 5px; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1000px) {
  form .row { grid-template-columns: repeat(2, 1fr); }
  .item-row { flex-wrap: wrap; gap: 14px; }
  .fields { gap: 18px; }
}

/* ── Dashboard (home) ───────────────────────────────────────────────────── */
.kpi-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.kpi {
  flex: 1 1 220px; display: flex; align-items: center; gap: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 20px 22px;
}
.kpi-ic {
  width: 52px; height: 52px; border-radius: 12px; flex: 0 0 auto;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent);
}
.kpi-ic .ic { width: 26px; height: 26px; }
.kpi-num { font-size: 34px; font-weight: 750; line-height: 1; color: var(--fg); letter-spacing: -.02em; }
.kpi-label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.ok-text { color: var(--ok); font-weight: 600; }

.health-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px; margin-bottom: 22px;
}
.card.stat { padding: 16px 18px; }
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--label); }
.stat-val { font-size: 24px; font-weight: 700; color: var(--fg); margin: 6px 0 2px; letter-spacing: -.01em; }
.stat-val .muted { font-size: 16px; font-weight: 500; }
.stat-sub { font-size: 12px; color: var(--muted); }
.meter { height: 7px; border-radius: 5px; background: var(--line-soft); overflow: hidden; margin: 9px 0 6px; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.meter.meter-warn > span { background: var(--warn); }

/* window segmented control */
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 9px; background: var(--line-soft); margin-bottom: 14px; }
.seg-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 13px; font-weight: 600; padding: 6px 14px; border-radius: 7px;
  transition: background .12s, color .12s;
}
.seg-btn:hover { color: var(--fg); }
.seg-btn.on { background: var(--card); color: var(--accent); box-shadow: var(--shadow); }

/* top-proxies ranked list with proportional bars */
table.toplist { width: 100%; border-collapse: collapse; }
table.toplist th {
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; color: var(--label); padding: 0 10px 10px; border-bottom: 1px solid var(--line);
}
table.toplist td { padding: 11px 10px; border-bottom: 1px solid var(--line-soft); font-size: 14px; color: var(--fg-soft); }
table.toplist tr:last-child td { border-bottom: 0; }
.toplist .rank { width: 34px; color: var(--label); font-variant-numeric: tabular-nums; }
.toplist .tp-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.toplist .tp-num b { color: var(--fg); }
.toplist .tp-domain { position: relative; max-width: 0; width: 55%; }
.toplist .tp-domain .bar {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  height: 26px; background: var(--accent-soft); border-radius: 6px; z-index: 0;
}
.toplist .tp-name {
  position: relative; z-index: 1; display: inline-block; padding: 0 8px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  vertical-align: middle; font-weight: 500; color: var(--fg);
}
.toplist .empty { text-align: center; color: var(--muted); padding: 22px; }

/* dashboard: active/total ratio bar under the Proxies KPI + card-corner action */
.kpi-body { flex: 1; min-width: 0; }
.kpi-meter { margin: 11px 0 2px; max-width: 320px; }
.card.stat { position: relative; }
.card-action { position: absolute; top: 12px; right: 12px; margin-left: 0; }
.card-action:hover { color: var(--err); border-color: var(--err); background: var(--err-bg); }

/* dashboard: Cloudflare status KPI card */
.dot-warn { background: var(--warn); }
.kpi-cf { align-items: flex-start; }
.cf-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cf-status b { font-size: 14.5px; font-weight: 650; color: var(--fg); }
.cf-refresh { width: 24px; height: 24px; margin-left: 2px; }
.cf-line { font-size: 12.5px; color: var(--fg-soft); margin-top: 7px; display: flex; align-items: center; gap: 7px; }
.cf-line.muted { color: var(--muted); }
.cf-line .ic { width: 13px; height: 13px; color: var(--muted); flex: 0 0 auto; }

/* ═══ Responsive ═══════════════════════════════════════════════════════════
   Below 820px the shell stacks (sidebar → top bar) and every fixed-width
   column row wraps, so no page needs horizontal scrolling except wide tables
   (which scroll inside their own card). */
@media (max-width: 1024px) {
  .content { padding: 22px 20px; }
}

@media (max-width: 820px) {
  /* shell: the sidebar slides in off-canvas; a sticky top bar (hamburger +
     logo + tool switcher) replaces it — matches dbdash */
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 40; height: 100vh;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 2px 0 40px rgba(0, 0, 0, .18);
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 0 16px 40px; }
  .mtop {
    display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 30;
    margin: 0 -16px 10px; padding: 11px 16px;
    background: var(--sidebar-bg); border-bottom: 1px solid var(--line);
  }
  .mtop .logo { font-weight: 800; font-size: 18px; letter-spacing: -.01em; }
  .mtop .logo span { color: var(--accent); }
  .mbackdrop.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 35; }
  .toolbar h1, .page-head h1 { font-size: 20px; }

  /* filter bar: search spans the row, selects share the rest */
  .filterbar { gap: 10px; }
  .searchwrap { flex: 1 1 100%; width: auto; }
  .selwrap { flex: 1 1 130px; }
  .selwrap select { width: 100%; }
  .pagination { width: 100%; justify-content: space-between; }

  /* card-row list (proxies / origins): title + kebab on top, stats wrap below */
  .item-row { flex-wrap: wrap; gap: 12px 16px; }
  .item-main, .item-main.wide { flex: 1 1 auto; width: auto; order: 0; }
  .item-main.wide .avatar { width: 58px; height: 58px; font-size: 22px; border-radius: 12px; }
  .item-actions { order: 1; margin-left: auto; }
  .fields.fixed, .fields.origins { order: 2; flex: 1 1 100%; flex-wrap: wrap; gap: 14px 22px; }
  .fields.fixed .field, .fields.origins .field { padding-right: 0; }
  .fields.fixed .col-status, .fields.fixed .col-cache, .fields.fixed .col-ssl, .traffic-col {
    flex: 0 0 auto; width: auto;
  }
  .fields.origins .field:nth-child(1),
  .fields.origins .field:nth-child(2),
  .fields.origins .field:nth-child(3) { flex: 0 0 auto; width: auto; }

  /* wide tables scroll inside their card instead of overflowing the page */
  .card { overflow-x: auto; }
  table.logs, table.toplist, table.kv { min-width: 480px; }

  /* dashboard */
  .kpi-num { font-size: 28px; }
}

@media (max-width: 480px) {
  .content { padding: 0 12px 40px; }
  .mtop { margin: 0 -12px 10px; }
  .kpi { flex: 1 1 100%; }
  .item-main.wide .avatar { width: 48px; height: 48px; font-size: 19px; }
  .toolbar { gap: 10px; }
}

/* ── Filter loading indicator ───────────────────────────────────────────────
   Any filter/search/sort/page control (they inherit hx-indicator="#list-spin"
   from the filterbar) dims its list and shows a sticky "Loading…" chip while
   the htmx request is in flight, then the swapped-in list replaces it. */
.list, .loadhost { position: relative; }
.loadmask.htmx-indicator { display: none; }
.loadmask.htmx-indicator.htmx-request { display: flex; }
.loadmask {
  position: absolute; inset: 0; z-index: 6; pointer-events: none;
  justify-content: center; align-items: flex-start; padding-top: 54px;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
}
.loadchip {
  position: sticky; top: 76px;
  display: inline-flex; align-items: center; gap: 10px; padding: 9px 17px;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow-hover);
  border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--fg-soft);
}
.loadchip .spinner { width: 15px; height: 15px; margin-left: 0; vertical-align: middle; }

/* ── Three-dots app switcher ───────────────────────────────────────────────
   Cross-app launcher next to the sidebar brand. Palette mapped to rpdash's
   tokens (--card/--fg/--input-bg/--ibadge-bg vs dbdash's --panel/--ink/…). */
.appsmenu-btn{border:1px solid var(--line);background:var(--card-hover);color:var(--muted);
  width:30px;height:26px;padding:5px 7px;border-radius:8px;cursor:pointer;display:inline-grid;place-items:center}
.appsmenu-btn:hover{border-color:var(--accent);color:var(--accent)}
.appsmenu-btn svg{width:16px;height:16px;fill:currentColor}
#appsmenu{position:fixed;z-index:70;min-width:264px;background:var(--card);border:1px solid var(--line);
  border-radius:11px;box-shadow:var(--shadow-hover);padding:6px}
#appsmenu.hidden{display:none}
#appsmenu .menu-head{font-size:10.5px;font-weight:700;letter-spacing:.5px;text-transform:uppercase;
  color:var(--muted);padding:7px 9px 5px}
#appsmenu button{width:100%;text-align:left;border:none;background:none;color:var(--fg);font:inherit;
  padding:8px 9px;border-radius:8px;cursor:pointer;display:flex;align-items:center;gap:10px}
#appsmenu button:not(:disabled):hover{background:var(--card-hover)}
#appsmenu button:disabled{cursor:default}
#appsmenu .ava{width:26px;height:26px;border-radius:7px;background:var(--accent-soft);color:var(--accent);
  display:grid;place-items:center;font-weight:700;font-size:12px;flex:none}
#appsmenu .nm{font-weight:600}
#appsmenu .env{font-size:10px;font-weight:700;letter-spacing:.2px;padding:2px 7px;border-radius:999px;
  background:var(--accent-soft);color:var(--accent)}
#appsmenu .env-live{background:var(--ok-bg);color:var(--ok)}
#appsmenu .env-prelive{background:var(--warn-bg);color:var(--warn)}
#appsmenu .tag{margin-left:auto;font-size:10px;font-weight:700;color:var(--muted);
  background:var(--ibadge-bg);padding:2px 8px;border-radius:999px}
#appsmenu .go{margin-left:auto;width:15px;height:15px;stroke:var(--muted);fill:none;stroke-width:2;flex:none}


/* ── Login page ────────────────────────────────────────────────────────── */
.login-body{min-height:100%;display:grid;place-items:center;background:var(--bg);padding:24px}
.login-card{width:100%;max-width:340px;background:var(--card);border:1px solid var(--line);
  border-radius:14px;box-shadow:var(--shadow);padding:26px 24px;display:flex;flex-direction:column;gap:14px}
.login-brand{display:flex;align-items:center;gap:10px;margin-bottom:2px}
.login-card h1{margin:0;font-size:18px;color:var(--fg)}
.login-card label{display:flex;flex-direction:column;gap:5px;font-size:12px;font-weight:600;color:var(--muted)}
.login-card input{border:1px solid var(--line);background:var(--input-bg);color:var(--fg);
  border-radius:9px;padding:9px 11px;font:inherit}
.login-card input:focus{outline:none;border-color:var(--accent)}
.login-card button{margin-top:4px;background:var(--accent);color:#fff;border:none;border-radius:9px;
  padding:10px;font:inherit;font-weight:700;cursor:pointer}
.login-err{background:var(--err-bg);color:var(--err);border-radius:9px;padding:8px 11px;font-size:13px}
