:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1a1d23;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --err: #b91c1c;
  --err-bg: #fee2e2;
  --info: #1d4ed8;
  --info-bg: #dbeafe;
  --neutral-bg: #e5e7eb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --accent: #818cf8;
    --accent-text: #0f1115;
    --ok: #4ade80;
    --ok-bg: rgba(74, 222, 128, 0.14);
    --warn: #fbbf24;
    --warn-bg: rgba(251, 191, 36, 0.14);
    --err: #f87171;
    --err-bg: rgba(248, 113, 113, 0.14);
    --info: #60a5fa;
    --info-bg: rgba(96, 165, 250, 0.14);
    --neutral-bg: #2a2f3a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); font-weight: normal; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.small { font-size: 12px; }
.warn { color: var(--warn); font-weight: 600; }

/* Layout */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 16px; color: var(--text); white-space: nowrap; }
.brand b { color: var(--accent); }
.brand span { color: var(--muted); font-weight: 500; font-size: 0.8em; margin-left: 2px; }
.brand:hover { text-decoration: none; }
.brand.big { font-size: 24px; text-align: center; margin-bottom: 20px; }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.topbar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topbar nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.me { display: flex; align-items: center; gap: 14px; white-space: nowrap; }
.me form { margin: 0; }
.container { max-width: 1280px; margin: 0 auto; padding: 24px; }
.container.narrow { max-width: 420px; padding-top: 12vh; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.crumb { margin: 0 0 4px; font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.grid2.wide-left { grid-template-columns: 2fr 1fr; }
.grid2 > * { min-width: 0; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.card.flush { padding: 0; overflow-x: auto; }
.card.danger { border-color: var(--err-bg); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.pad { padding: 16px 20px; margin: 0; }
.card-head.pad { padding-bottom: 0; margin-bottom: 4px; }
.empty-state { text-align: center; padding: 40px; }
.empty-state h1 { justify-content: center; font-size: 40px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; color: var(--text); box-shadow: var(--shadow);
}
a.stat:hover { border-color: var(--accent); text-decoration: none; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat .value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 15px; color: var(--muted); font-weight: 500; }
.stat .sub { color: var(--muted); font-size: 12.5px; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.card:not(.flush) th:first-child, .card:not(.flush) td:first-child { padding-left: 0; }
.card:not(.flush) th:last-child, .card:not(.flush) td:last-child { padding-right: 0; }
.card.flush th:first-child, .card.flush td:first-child { padding-left: 20px; }
.card.flush th:last-child, .card.flush td:last-child { padding-right: 20px; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.dim td { opacity: 0.55; }
tr.note-row td { padding-top: 0; font-size: 12.5px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row-actions form { margin: 0; }

/* Badges & status */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; text-transform: capitalize; white-space: nowrap;
  background: var(--neutral-bg); color: var(--muted); vertical-align: 1px;
}
.s-active { background: var(--ok-bg); color: var(--ok); }
.s-trial, .s-lead, .s-provisioning { background: var(--info-bg); color: var(--info); }
.s-past_due, .s-suspended, .s-maintenance { background: var(--warn-bg); color: var(--warn); }
.s-cancelled, .s-expired, .s-closed, .s-retired { background: var(--neutral-bg); color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; background: var(--muted); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot.off { background: var(--err); }
.meter { display: inline-block; width: 60px; height: 6px; border-radius: 3px; background: var(--neutral-bg); overflow: hidden; vertical-align: middle; }
.meter span { display: block; height: 100%; width: 0; background: var(--ok); }
.meter span.hot { background: var(--warn); }

/* Forms */
.form label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; font-weight: 550; font-size: 13px; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.form h1 { margin-bottom: 16px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: 8px 10px; width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: auto; flex: none; margin: 0; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
small.err { color: var(--err); font-weight: 500; }
.actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input[type="search"] { max-width: 340px; }
.filters select { width: auto; }
.inline-form { display: flex; gap: 8px; margin-top: 14px; }
.inline-form select { width: auto; flex: 1; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 550; padding: 7px 14px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.sm { padding: 3px 10px; font-size: 12.5px; }
.btn.block { width: 100%; padding: 10px; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
.linklike:hover { color: var(--text); text-decoration: underline; }

/* Flash messages */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }

/* Misc */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 5px 12px; border-radius: 999px; color: var(--muted); text-transform: capitalize; border: 1px solid transparent; }
.tabs a:hover { background: var(--surface); text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--surface); border-color: var(--border); color: var(--text); font-weight: 600; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin: -4px 0 20px; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.notes { margin-top: 14px; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; white-space: pre-wrap; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.copy-row { display: flex; gap: 10px; align-items: flex-start; }
.key { flex: 1; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; overflow-wrap: anywhere; font-size: 13px; }
.code { flex: 1; margin: 0; padding: 12px 14px; background: var(--surface-2); border-radius: 8px; overflow-x: auto; font-size: 12.5px; line-height: 1.6; }
.login .card { padding: 24px; }
.stack-forms { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; align-items: flex-start; }
.stack-forms form { margin: 0; }
.stack-forms .inline-form { margin-top: 0; width: 100%; }
.config-form { display: flex; gap: 6px; align-items: center; margin: 0; }
.config-form select { width: auto; padding: 3px 6px; font-size: 12.5px; }
.inline-form input { flex: 1; }
fieldset.access { border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px 6px; margin: 0 0 16px; }
fieldset.access legend { font-weight: 600; font-size: 13px; padding: 0 6px; }
fieldset.access label.check { margin-bottom: 8px; }
.node-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 16px; margin: 6px 0 8px; padding-top: 10px; border-top: 1px dashed var(--border); }
.qr-card { text-align: center; }
.qr-card img { max-width: 100%; height: auto; background: #fff; border-radius: 8px; padding: 8px; }

@media (max-width: 960px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid2, .grid2.wide-left { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 8px 16px; }
  .topbar nav { order: 3; flex-basis: 100%; }
  .me { margin-left: auto; }
  .container { padding: 16px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .value { font-size: 22px; }
  .copy-row { flex-direction: column; }
}
