@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/inter-latin-wght-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/inter-latin-wght-italic.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2");
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
:root {
  color-scheme: light dark;
  --bg: light-dark(#ffffff, #0f0f11);
  --stage: light-dark(#f4f4f6, #0a0a0c);
  --side: light-dark(#f7f7f8, #141417);
  --raised: light-dark(#ffffff, #18181c);
  --subtle: light-dark(#f1f1f3, #1e1e24);
  --hover: light-dark(#18181b0a, #ffffff0b);
  --selected: light-dark(#18181b12, #ffffff14);
  --line: light-dark(#e5e5e8, #27272e);
  --line-strong: light-dark(#d0d0d7, #3a3a44);
  --text: light-dark(#18181b, #ededef);
  --muted: light-dark(#565660, #a0a0aa);
  --quiet: light-dark(#686873, #8c8c98);

  --accent: light-dark(#18181b, #ededef);
  --on-accent: light-dark(#ffffff, #0f0f11);
  --ok: light-dark(#1b7a46, #5fc48a);
  --ok-soft: light-dark(#1b7a4614, #5fc48a1c);
  --ok-line: light-dark(#1b7a4640, #5fc48a48);
  --info: light-dark(#2457c5, #7ea4ff);
  --info-soft: light-dark(#2457c512, #7ea4ff1c);
  --info-line: light-dark(#2457c538, #7ea4ff45);
  --warn: light-dark(#9a5800, #f0b45a);
  --warn-soft: light-dark(#9a580014, #f0b45a1a);
  --warn-line: light-dark(#9a58003d, #f0b45a45);
  --danger: light-dark(#b91c3b, #ff7a92);
  --danger-soft: light-dark(#b91c3b14, #ff7a921a);
  --danger-line: light-dark(#b91c3b40, #ff7a9245);
  --ring: light-dark(#1b7a46, #5fc48a);
  --scrim: light-dark(#18181b59, #000000a6);

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --t-xs: 12px;
  --t-s: 13px;
  --t-m: 14px;
  --t-l: 16px;
  --t-xl: 20px;
  --t-display: 24px;

  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;

  --r-s: 6px;
  --r-m: 10px;
  --r-l: 14px;
  --r-pill: 999px;

  --shadow-card: light-dark(0 1px 2px #18181b0a, 0 1px 2px #00000040);
  --shadow-pop: light-dark(0 12px 32px #18181b1f, 0 16px 40px #00000073);
  --ms-fast: 140ms;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 var(--t-m)/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
:where(button, input, select, textarea) { font: inherit; color: inherit; }
:where(h1, h2, h3, p, ul) { margin: 0; }
:where(:focus-visible) { outline: 2px solid var(--ring); outline-offset: 2px; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.digits { font-variant-numeric: tabular-nums; }
.quiet { color: var(--muted); font-size: var(--t-s); }
.xs { font-size: var(--t-xs); line-height: 1.45; }
.break-all { overflow-wrap: anywhere; word-break: break-word; }

/* Boot & Gate screens */
.boot-state, .gate-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--s-6) var(--s-4);
  background: var(--stage);
}
.boot-card {
  display: grid;
  justify-items: center;
  gap: var(--s-3);
}
.gate-card {
  width: 100%;
  max-width: 440px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: var(--s-6);
  box-shadow: var(--shadow-card);
  display: grid;
  gap: var(--s-5);
}
.gate-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-weight: 600;
  font-size: var(--t-l);
  letter-spacing: -0.015em;
  color: var(--text);
}
.brand-mark { border-radius: var(--r-s); flex-shrink: 0; }
.gate-title { font-size: var(--t-xl); font-weight: 600; letter-spacing: -0.02em; line-height: 1.3; }
.gate-copy { color: var(--muted); font-size: var(--t-s); line-height: 1.5; }
.gate-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  padding-top: var(--s-3);
  border-top: 1px solid var(--line);
  font-size: var(--t-xs);
  color: var(--quiet);
}

/* App Shell */
.shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  background: var(--bg);
}
.sidebar {
  background: var(--side);
  border-right: 1px solid var(--line);
  padding: var(--s-5) var(--s-3);
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  position: sticky;
  top: 0;
  height: 100dvh;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s-2);
}
.nav {
  display: grid;
  gap: var(--s-1);
}
.nav-btn {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  min-height: 40px;
  padding: 0 var(--s-3);
  border: 1px solid transparent;
  border-radius: var(--r-s);
  background: transparent;
  color: var(--muted);
  font-size: var(--t-s);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--ms-fast) ease, color var(--ms-fast) ease;
}
.nav-btn:hover { background: var(--hover); color: var(--text); }
.nav-btn[aria-current="page"] {
  background: var(--raised);
  border-color: var(--line);
  color: var(--text);
  box-shadow: var(--shadow-card);
}
.nav-btn svg { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; }
.nav-count {
  margin-left: auto;
  font-size: var(--t-xs);
  color: var(--quiet);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.sidebar-foot {
  margin-top: auto;
  display: grid;
  gap: var(--s-2);
  padding-top: var(--s-4);
  border-top: 1px solid var(--line);
}
.session-chip {
  display: grid;
  gap: 2px;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-s);
  background: var(--subtle);
}
.session-label { font-size: var(--t-xs); font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-sub { font-size: var(--t-xs); color: var(--muted); }
.foot-actions { display: flex; gap: var(--s-2); }

.mobile-bar { display: none; }

/* Main canvas */
.main {
  min-width: 0;
  padding: var(--s-6) var(--s-8) var(--s-8);
}
.container {
  max-width: 960px;
  margin: 0 auto;
  display: grid;
  gap: var(--s-6);
  min-width: 0;
}

.sandbox-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  flex-wrap: wrap;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-m);
  border: 1px solid var(--ok-line);
  background: var(--ok-soft);
  font-size: var(--t-s);
}
.sandbox-banner-left {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-weight: 500;
  color: var(--text);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--ok);
  flex-shrink: 0;
}
.dot.warn { background: var(--warn); }
.dot.info { background: var(--info); }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-4);
  flex-wrap: wrap;
}
.page-title { font-size: var(--t-display); font-weight: 600; letter-spacing: -0.025em; line-height: 1.25; }
.page-sub { color: var(--muted); font-size: var(--t-s); margin-top: var(--s-1); }
.head-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }

/* Cards & Grids */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s-3);
}
.kpi-card {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: var(--s-4);
  display: grid;
  gap: var(--s-1);
}
.kpi-label { font-size: var(--t-xs); color: var(--muted); font-weight: 500; }
.kpi-value { font-size: var(--t-display); font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi-hint { font-size: var(--t-xs); color: var(--quiet); }

.section { display: grid; gap: var(--s-3); min-width: 0; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  flex-wrap: wrap;
}
.section-title { font-size: var(--t-l); font-weight: 600; letter-spacing: -0.015em; }

.card {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: var(--s-4);
  display: grid;
  gap: var(--s-3);
  min-width: 0;
  box-shadow: var(--shadow-card);
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-3);
  min-width: 0;
}
.card-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
  flex-wrap: wrap;
}

/* Badges / Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: var(--r-pill);
  font-size: var(--t-xs);
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--subtle);
  color: var(--muted);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.badge.info { background: var(--info-soft); border-color: var(--info-line); color: var(--info); }
.badge.warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.badge.danger { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 36px;
  padding: 0 var(--s-3);
  border-radius: var(--r-s);
  border: 1px solid var(--line-strong);
  background: var(--raised);
  color: var(--text);
  font-size: var(--t-s);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--ms-fast) ease, border-color var(--ms-fast) ease, opacity var(--ms-fast) ease;
}
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:disabled { opacity: 0.48; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; stroke: currentColor; flex-shrink: 0; }
.btn.primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
.btn.primary:hover:not(:disabled) { opacity: 0.9; background: var(--accent); }
.btn.ok {
  background: var(--ok-soft);
  border-color: var(--ok-line);
  color: var(--ok);
}
.btn.danger {
  border-color: var(--danger-line);
  color: var(--danger);
}
.btn.danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.btn.ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.btn.sm { min-height: 30px; padding: 0 var(--s-2); font-size: var(--t-xs); }
.btn.full { width: 100%; min-height: 44px; }

/* Forms */
.form { display: grid; gap: var(--s-4); }
.field { display: grid; gap: 6px; }
.label { font-size: var(--t-s); font-weight: 500; color: var(--text); }
.input, .select {
  width: 100%;
  min-height: 40px;
  padding: 0 var(--s-3);
  border-radius: var(--r-s);
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--text);
  font-size: var(--t-m);
}
.input::placeholder { color: var(--quiet); }
.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-3);
}
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.pill-opt {
  min-height: 36px;
  padding: 0 var(--s-3);
  border-radius: var(--r-s);
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--muted);
  font-size: var(--t-s);
  font-weight: 500;
  cursor: pointer;
}
.pill-opt[aria-pressed="true"] {
  background: var(--selected);
  border-color: var(--text);
  color: var(--text);
}

/* Address / Key data display */
.kv-box {
  display: grid;
  gap: var(--s-2);
  padding: var(--s-3);
  border-radius: var(--r-s);
  background: var(--subtle);
  border: 1px solid var(--line);
  min-width: 0;
}
.card.card-ok { border-color: var(--ok-line); }
.pk-ident { display: flex; align-items: flex-start; gap: var(--s-3); flex: 1; min-width: 0; }
.pk-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-2); }
.pk-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.pk-logo {
  width: 34px;
  height: 34px;
  border-radius: var(--r-s);
  flex-shrink: 0;
  object-fit: contain;
  background: var(--subtle);
  padding: 4px;
  border: 1px solid var(--line);
}
.title-m { font-size: var(--t-m); font-weight: 600; letter-spacing: -0.01em; }
.title-l { font-size: var(--t-l); font-weight: 600; letter-spacing: -0.015em; }
.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 8px; }
.flex-1 { flex: 1; }
.min-w-0 { min-width: 0; }
.kv-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  flex-wrap: wrap;
  min-width: 0;
}
.kv-key { font-size: var(--t-xs); color: var(--muted); flex-shrink: 0; }
.kv-val {
  font-family: var(--mono);
  font-size: var(--t-xs);
  color: var(--text);
  overflow-wrap: anywhere;
  text-align: right;
  min-width: 0;
}

.code-block {
  font-family: var(--mono);
  font-size: var(--t-xs);
  line-height: 1.5;
  padding: var(--s-3);
  border-radius: var(--r-s);
  background: var(--subtle);
  border: 1px solid var(--line);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  margin: 0;
}

/* Checklist & Owner selector */
.checklist { display: grid; gap: var(--s-2); }
.check-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  background: var(--bg);
}
.check-num {
  width: 24px;
  height: 24px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-strong);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: var(--t-xs);
  color: var(--muted);
  flex-shrink: 0;
}
.check-item.done .check-num {
  background: var(--ok-soft);
  border-color: var(--ok-line);
  color: var(--ok);
}
.check-body { min-width: 0; flex: 1; }
.check-title { font-size: var(--t-s); font-weight: 500; }
.check-sub { font-size: var(--t-xs); color: var(--muted); }

.owner-option {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  background: var(--bg);
  cursor: pointer;
}
.owner-option input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--ok);
  flex-shrink: 0;
}
.owner-option:has(input:checked) {
  border-color: var(--ok-line);
  background: var(--ok-soft);
}

.chain-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s-2);
}
.chain-cell {
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-s);
  border: 1px solid var(--line);
  background: var(--bg);
  display: grid;
  gap: 2px;
}
.chain-cell.ok { border-color: var(--ok-line); background: var(--ok-soft); }
.chain-name { font-size: var(--t-xs); font-weight: 600; }
.chain-meta { font-size: var(--t-xs); color: var(--muted); font-family: var(--mono); }

/* Audit table */
.audit-list { display: grid; gap: var(--s-2); }
.audit-row {
  display: grid;
  grid-template-columns: 148px 180px minmax(0, 1fr) auto;
  gap: var(--s-3);
  align-items: center;
  padding: var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  background: var(--raised);
  font-size: var(--t-xs);
}

/* Modal */
dialog.modal {
  width: min(500px, calc(100vw - 24px));
  padding: var(--s-5);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  background: var(--raised);
  color: var(--text);
  box-shadow: var(--shadow-pop);
}
dialog.modal::backdrop { background: var(--scrim); }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.modal-title { font-size: var(--t-l); font-weight: 600; }

/* Toasts */
.toast-stack {
  position: fixed;
  right: var(--s-4);
  bottom: var(--s-4);
  z-index: 60;
  display: grid;
  gap: var(--s-2);
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-m);
  border: 1px solid var(--line-strong);
  background: var(--raised);
  color: var(--text);
  font-size: var(--t-s);
  box-shadow: var(--shadow-pop);
}
.toast.ok { border-color: var(--ok-line); }
.toast.danger { border-color: var(--danger-line); color: var(--danger); }

.empty-box {
  padding: var(--s-6) var(--s-4);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-m);
  text-align: center;
  display: grid;
  gap: var(--s-2);
  justify-items: center;
}

details.fold > summary {
  cursor: pointer;
  font-size: var(--t-xs);
  color: var(--muted);
  user-select: none;
}

/* Mobile (<= 820px, verified at 390px) */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-bar {
    display: grid;
    gap: var(--s-2);
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--side);
    border-bottom: 1px solid var(--line);
    padding: var(--s-3) var(--s-4) var(--s-2);
  }
  .mobile-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-2);
  }
  .mobile-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--s-1);
  }
  .mobile-tab {
    min-height: 44px;
    padding: 0 var(--s-1);
    border: 1px solid transparent;
    border-radius: var(--r-s);
    background: transparent;
    color: var(--muted);
    font-size: var(--t-xs);
    font-weight: 500;
    cursor: pointer;
    text-align: center;
  }
  .mobile-tab[aria-current="page"] {
    background: var(--raised);
    border-color: var(--line);
    color: var(--text);
  }
  .main { padding: var(--s-4) var(--s-4) var(--s-8); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-grid { grid-template-columns: 1fr; }
  .chain-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-row { grid-template-columns: 1fr; }
  .audit-row { grid-template-columns: 1fr; gap: var(--s-1); }
  .btn { min-height: 44px; }
  .btn.sm { min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
