/* ===== Fonts (self-hosted for CSP font-src 'self') ===== */
@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-style: normal; font-display: swap; src: url("/fonts/ibm-plex-sans-400.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 500; font-style: normal; font-display: swap; src: url("/fonts/ibm-plex-sans-500.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 600; font-style: normal; font-display: swap; src: url("/fonts/ibm-plex-sans-600.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 700; font-style: normal; font-display: swap; src: url("/fonts/ibm-plex-sans-700.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-style: normal; font-display: swap; src: url("/fonts/ibm-plex-mono-400.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 500; font-style: normal; font-display: swap; src: url("/fonts/ibm-plex-mono-500.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 600; font-style: normal; font-display: swap; src: url("/fonts/ibm-plex-mono-600.woff2") format("woff2"); }

:root {
  color-scheme: dark;
  --bg: #0a0d13;
  --bar: #0c1017;
  --card: #0f141c;
  --field: #0a0e14;
  --deepest: #080b10;
  --tile: #141b25;
  --btn2: #131a23;
  --seg: #11161f;
  --seg-active: #1f2630;

  --bd-bar: #1b222c;
  --bd-card: #1e2631;
  --bd-field: #232c38;
  --bd-btn: #26303c;
  --bd-ring: #2c3742;
  --bd-strip: #1c242f;
  --div1: #161d26;
  --div2: #141b23;
  --div3: #1a212b;

  --tx: #e6e9ef;
  --tx2: #c4ccd8;
  --tx3: #d3dae4;
  --mut: #8b95a5;
  --mut2: #9aa4b2;
  --faint: #7b8492;
  --faint2: #6b7686;
  --faintest: #5a6472;
  --disabled: #4b5563;

  --grn: #3ddc84;
  --grn-hover: #6ff0a9;
  --grn-lt: #7ee6a8;
  --grn-lt2: #8ff0b9;
  --grn-dark: #06210f;
  --grn-fill: #c8f5db;

  --amber: #f5b95c;
  --amber-tx: #d9c9a6;
  --amber-chip: #f5cf87;
  --amber-chip-bg: #1a1508;

  --red: #ff7676;
  --red2: #ff9b9b;

  --font-sans: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Courier New", monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--tx);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
}
input, button, textarea { font-family: inherit; }
input:focus, textarea:focus { outline: none; }
input:focus { border-color: var(--bd-ring); }
::selection { background: rgba(61, 220, 132, 0.25); }
a { color: var(--grn); text-decoration: none; }
a:hover { color: var(--grn-hover); }
[hidden] { display: none !important; }

.mono { font-family: var(--font-mono); }

/* Custom scrollbars */
.scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.scroll::-webkit-scrollbar-thumb { background: #2a333f; border-radius: 6px; }
.scroll::-webkit-scrollbar-track { background: transparent; }

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* ===== Top bar ===== */
.topbar {
  display: flex; align-items: center; gap: 20px;
  height: 64px; padding: 0 28px;
  border-bottom: 1px solid var(--bd-bar);
  background: var(--bar);
  position: sticky; top: 0; z-index: 10;
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo-tile {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #3ddc84, #25a862);
  display: flex; align-items: center; justify-content: center;
  color: var(--grn-dark); font-family: var(--font-mono); font-weight: 600; font-size: 15px;
  box-shadow: 0 0 0 1px rgba(61, 220, 132, 0.25), 0 4px 14px rgba(61, 220, 132, 0.18);
}
.logo-text { display: flex; flex-direction: column; line-height: 1.1; }
.wordmark { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.sublabel { font-family: var(--font-mono); font-size: 11px; color: var(--faint2); letter-spacing: 0.04em; }

.tabs {
  margin-left: 16px; display: flex; padding: 4px; gap: 2px;
  background: var(--seg); border: 1px solid var(--bd-card); border-radius: 11px;
}
.tab {
  padding: 7px 16px; border: none; border-radius: 8px; cursor: pointer;
  font-size: 13.5px; font-weight: 500; transition: all 0.15s;
  background: transparent; color: var(--faint);
}
.tab.active { background: var(--seg-active); color: var(--tx); box-shadow: inset 0 0 0 1px var(--bd-ring); }

.auth { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.auth-out {
  font-family: var(--font-mono); font-size: 12px; color: var(--faintest);
  display: flex; align-items: center; gap: 7px;
}
.auth-out-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faintest); }
.auth-in {
  display: flex; align-items: center; gap: 9px; padding: 6px 12px 6px 8px;
  background: var(--seg); border: 1px solid var(--bd-card); border-radius: 999px;
}
.avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: #1f6f45; color: #bff5d5;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600;
}
.auth-name { font-size: 13px; color: var(--tx2); }
.signout { background: none; border: none; color: var(--faint2); font-size: 12px; cursor: pointer; padding: 2px 4px; }
.signout:hover { color: var(--tx2); }

/* ===== Main ===== */
.main { flex: 1; overflow: auto; padding: 44px 28px 80px; }
.view-admin { max-width: 1060px; margin: 0 auto; }
.view-runner { max-width: 920px; margin: 0 auto; }

.page-head {
  display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 8px;
  justify-content: space-between;
}
.page-head.end { align-items: flex-end; }
.page-head.start { align-items: flex-start; }
.eyebrow {
  font-family: var(--font-mono); font-size: 12px; color: var(--grn);
  letter-spacing: 0.12em; text-transform: uppercase; margin-bottom: 10px;
}
h1 { margin: 0; font-size: 30px; font-weight: 600; letter-spacing: -0.02em; }
h1 .mono { font-weight: 500; }
h2 { margin: 0; font-size: 17px; font-weight: 600; }
.desc { color: var(--mut); margin: 0 0 34px; font-size: 14.5px; }
.view-admin .desc { max-width: 620px; }
.view-runner .desc { max-width: 640px; margin-bottom: 26px; }
.desc strong { color: var(--tx2); font-weight: 600; }

.outline-link {
  font-family: var(--font-mono); font-size: 13px; display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border: 1px solid var(--bd-btn); border-radius: 9px;
  color: var(--tx2); background: var(--seg); white-space: nowrap; cursor: pointer;
}
.outline-link .ic { color: var(--grn); display: inline-flex; }

/* ===== Grids ===== */
.admin-grid { display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 24px; align-items: start; }
.runner-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 22px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 20px; }

/* ===== Cards ===== */
.card { background: var(--card); border: 1px solid var(--bd-card); border-radius: 16px; padding: 24px; }
.card.pad26 { padding: 26px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.card-head.tight { margin-bottom: 4px; }
.icon-tile {
  width: 32px; height: 32px; border-radius: 8px; flex: none;
  background: var(--tile); border: 1px solid var(--bd-field);
  display: flex; align-items: center; justify-content: center; color: var(--grn);
}
.card-sub { color: var(--faint); font-size: 13px; margin: 0 0 22px 42px; }

/* ===== Forms ===== */
.label { display: block; font-size: 12.5px; color: var(--mut2); margin-bottom: 7px; font-weight: 500; }
.label .opt { color: var(--faintest); }
.field {
  width: 100%; padding: 11px 13px; margin-bottom: 16px;
  background: var(--field); border: 1px solid var(--bd-field); border-radius: 10px;
  color: var(--tx); font-size: 14px; transition: border-color 0.15s;
}
.field.mono { color: var(--grn-fill); font-size: 13px; }
.field::placeholder { color: var(--faintest); }

.check-row { display: flex; align-items: center; gap: 10px; cursor: pointer; margin-bottom: 22px; user-select: none; }
.check-row.top { align-items: flex-start; }
.check-row span.check-label { font-size: 13px; color: var(--mut2); }
.check-row.top span.check-label { line-height: 1.4; }
.checkbox {
  width: 18px; height: 18px; flex: none; border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  background: var(--field); border: 1px solid var(--bd-ring); color: transparent; transition: all 0.15s;
}
.checkbox svg { width: 12px; height: 12px; opacity: 0; }
.checkbox.on { background: var(--grn); border-color: var(--grn); color: var(--grn-dark); }
.checkbox.on svg { opacity: 1; }

.btn-primary {
  width: 100%; padding: 12px; border: none; border-radius: 10px;
  font-size: 14.5px; font-weight: 600; cursor: pointer; transition: all 0.15s;
  background: var(--grn); color: var(--grn-dark);
}
.btn-primary:hover:not(:disabled) { background: var(--grn-hover); }
.btn-primary.running { background: #1a2820; color: var(--grn-lt2); cursor: default; }
.btn-primary:disabled { background: #161d26; color: var(--disabled); cursor: not-allowed; }
.btn-outline {
  width: 100%; padding: 12px; border-radius: 10px;
  font-size: 14.5px; font-weight: 500; cursor: pointer; transition: all 0.15s;
  background: var(--btn2); color: var(--tx); border: 1px solid var(--bd-ring);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-outline:hover:not(:disabled) { border-color: var(--faint2); }
.btn-outline:disabled { background: #0d1219; color: var(--disabled); border-color: var(--bd-strip); cursor: not-allowed; }

.error-line { margin-top: 14px; font-size: 12.5px; color: var(--red); font-family: var(--font-mono); }

/* ===== TTL segmented ===== */
.ttl-row { display: flex; gap: 8px; margin-bottom: 20px; }
.ttl-btn {
  flex: 1; padding: 9px 0; border-radius: 9px; cursor: pointer;
  font-size: 13px; font-weight: 500; transition: all 0.15s;
  background: var(--field); color: var(--mut); border: 1px solid var(--bd-field);
}
.ttl-btn.active { background: #16241b; color: var(--grn-lt2); border-color: rgba(61, 220, 132, 0.4); }

/* ===== New-link banner ===== */
.banner {
  background: linear-gradient(180deg, rgba(61, 220, 132, 0.09), rgba(61, 220, 132, 0.02));
  border: 1px solid rgba(61, 220, 132, 0.35); border-radius: 16px; padding: 20px;
}
.banner-eyebrow {
  display: flex; align-items: center; gap: 8px; font-family: var(--font-mono);
  font-size: 12px; color: var(--grn); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 12px;
}
.url-row { display: flex; gap: 10px; align-items: stretch; }
.url-field {
  flex: 1; overflow-x: auto; padding: 12px 14px;
  background: var(--deepest); border: 1px solid #22303a; border-radius: 10px;
  font-family: var(--font-mono); font-size: 13px; color: var(--grn-fill); white-space: nowrap;
}
.copy-btn {
  flex: none; padding: 0 18px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--bd-btn); background: var(--btn2); color: var(--tx);
  font-size: 13px; font-weight: 600; transition: all 0.15s;
}
.copy-btn.copied { border-color: rgba(61, 220, 132, 0.5); background: #16241b; color: var(--grn-lt2); }
.banner-foot { margin-top: 12px; font-size: 12px; color: var(--faint); }

/* ===== Tokens table ===== */
.tokens-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--div3);
}
.tokens-count { font-family: var(--font-mono); font-size: 12px; color: var(--faint2); }
.empty-state { padding: 56px 24px; text-align: center; color: var(--faintest); }
.empty-state .ic { display: inline-flex; margin-bottom: 10px; opacity: 0.6; color: var(--faintest); }
.empty-state .ic svg { width: 26px; height: 26px; }
.empty-state .msg { font-size: 14px; color: var(--faint); }

.trow {
  display: grid; grid-template-columns: 1fr 92px 88px 40px; gap: 12px; align-items: center;
}
.thead {
  padding: 11px 22px; border-bottom: 1px solid var(--div1);
  font-family: var(--font-mono); font-size: 11px; color: var(--faintest);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.tbody .trow { padding: 14px 22px; border-bottom: 1px solid var(--div2); }
.tcell-main { min-width: 0; }
.tcode { font-family: var(--font-mono); font-size: 13px; color: var(--tx3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tlabel { font-size: 12px; color: var(--faint2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tcreated { font-size: 12.5px; color: var(--mut); }
.badge {
  font-family: var(--font-mono); font-size: 11px; padding: 3px 9px; border-radius: 6px;
  text-transform: uppercase; letter-spacing: 0.04em; justify-self: start;
}
.badge.active { background: rgba(61, 220, 132, 0.13); color: var(--grn-lt); }
.badge.spent { background: rgba(122, 134, 150, 0.14); color: var(--mut2); }
.badge.expired { background: rgba(255, 118, 118, 0.12); color: var(--red2); }
.badge.revoked { background: rgba(255, 118, 118, 0.09); color: #d98a8a; }
.revoke {
  background: none; border: none; color: var(--faintest); cursor: pointer;
  padding: 4px; justify-self: end; display: inline-flex;
}
.revoke:hover { color: var(--red2); }

/* ===== Runner ===== */
.status-pill {
  display: inline-flex; align-items: center; gap: 9px; padding: 8px 15px;
  border-radius: 999px; font-size: 13px; font-weight: 500;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-pill.idle { color: var(--mut); background: rgba(122,134,150,0.12); border: 1px solid rgba(122,134,150,0.25); }
.status-pill.idle .status-dot { background: var(--mut); }
.status-pill.connected { color: var(--grn-lt); background: rgba(61,220,132,0.12); border: 1px solid rgba(61,220,132,0.3); }
.status-pill.connected .status-dot { background: var(--grn-lt); }
.status-pill.running { color: var(--amber); background: rgba(245,185,92,0.12); border: 1px solid rgba(245,185,92,0.3); }
.status-pill.running .status-dot { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.status-pill.done { color: var(--grn-lt); background: rgba(61,220,132,0.14); border: 1px solid rgba(61,220,132,0.4); }
.status-pill.done .status-dot { background: var(--grn-lt); }
.status-pill.error { color: var(--red2); background: rgba(255,118,118,0.12); border: 1px solid rgba(255,118,118,0.3); }
.status-pill.error .status-dot { background: var(--red2); }

.warning {
  display: flex; gap: 13px; padding: 15px 17px; margin-bottom: 26px;
  background: rgba(245, 185, 92, 0.07); border: 1px solid rgba(245, 185, 92, 0.3); border-radius: 12px;
}
.warning .ic { color: var(--amber); flex: none; }
.warning-tx { font-size: 13.5px; color: var(--amber-tx); }
.code-chip { font-family: var(--font-mono); background: var(--amber-chip-bg); padding: 1px 6px; border-radius: 5px; color: var(--amber-chip); }

.device-strip {
  display: flex; align-items: center; gap: 12px; padding: 13px 15px; margin-bottom: 22px;
  background: var(--field); border: 1px solid var(--bd-strip); border-radius: 12px;
}
.device-tile {
  width: 36px; height: 36px; border-radius: 9px; flex: none;
  background: var(--tile); display: flex; align-items: center; justify-content: center; color: var(--tx3);
}
.device-txt { flex: 1; min-width: 0; }
.device-l1 { font-size: 13.5px; color: var(--tx3); font-weight: 500; }
.device-l2 { font-size: 12px; color: var(--faint2); font-family: var(--font-mono); }
.device-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: #3a434f; }
.device-dot.on { background: var(--grn); box-shadow: 0 0 8px rgba(61, 220, 132, 0.6); }

.btn-col { display: flex; flex-direction: column; gap: 10px; }
.hint { margin-top: 14px; font-size: 12px; color: var(--faint2); text-align: center; }

/* ===== Run log ===== */
.log-panel {
  background: var(--deepest); border: 1px solid var(--bd-card); border-radius: 16px;
  overflow: hidden; display: flex; flex-direction: column; min-height: 360px;
}
.log-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 18px; border-bottom: 1px solid var(--div1); background: var(--bar);
}
.log-tools { display: flex; align-items: center; gap: 9px; }
.traffic { display: flex; gap: 6px; }
.traffic span { width: 10px; height: 10px; border-radius: 50%; background: #2a333f; }
.log-title { font-family: var(--font-mono); font-size: 12px; color: var(--mut); }
.clear-btn {
  background: none; border: 1px solid var(--bd-btn); color: var(--mut);
  font-size: 12px; cursor: pointer; padding: 5px 11px; border-radius: 7px; font-family: var(--font-mono);
}
.clear-btn:hover { color: var(--tx2); }
.log-body {
  flex: 1; overflow: auto; padding: 16px 18px;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.85;
  max-height: 60vh;
}
.log-line { white-space: pre-wrap; word-break: break-word; color: var(--tx2); }
.log-line.dim { color: var(--faint2); }
.log-line.mut { color: var(--mut); }
.log-line.ok { color: var(--grn-lt); }
.log-line.data { color: var(--tx2); }
.log-line.err { color: var(--red2); }
.log-line.final { color: var(--grn-lt2); }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .admin-grid, .runner-grid { grid-template-columns: 1fr; }
  .topbar { gap: 12px; padding: 0 16px; }
  .sublabel { display: none; }
  .main { padding: 28px 16px 60px; }
}
