:root {
  --bg: #0a0d0b;
  --surface: #101512;
  --surface-2: #151c18;
  --surface-3: #1d2620;
  --ink: #eef3ef;
  --muted: #93a39a;
  --hairline: rgba(255, 255, 255, 0.075);
  --hairline-strong: rgba(255, 255, 255, 0.14);
  --accent: #34d399;
  --accent-strong: #6ee7b7;
  --accent-ink: #04271c;
  --accent-soft: rgba(52, 211, 153, 0.14);
  --signal: #34d399;
  --signal-soft: rgba(52, 211, 153, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --warn: #f5b544;
  --warn-soft: rgba(245, 181, 68, 0.13);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.5 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  color-scheme: dark;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--hairline);
  background: rgba(16, 21, 18, 0.92);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .left, .topbar .right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-family: 'Space Grotesk', sans-serif; font-size: 15px; }
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 0 3px var(--signal-soft); }

input, select, button, a.btn {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 7px 11px;
  font: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
button, a.btn { cursor: pointer; white-space: nowrap; font-weight: 500; min-height: 34px; }
button:hover, a.btn:hover { background: var(--surface-3); border-color: var(--hairline-strong); }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: var(--accent-strong); border-color: transparent; }
.btn-danger { background: var(--danger); border-color: transparent; color: #2a0808; font-weight: 600; }
.btn-danger:hover { background: #ef4444; border-color: transparent; }
.btn-accent { background: var(--accent-soft); border-color: rgba(52, 211, 153, 0.35); color: #a7f3d0; }
.btn-ghost { background: transparent; color: var(--muted); }
.user-pill { padding: 2px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--hairline); font-size: 11px; }
.user-pill:empty { display: none; }

.dim { color: var(--muted); font-size: 12px; margin: 0; }
.subhead { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.err { color: #fca5a5; min-height: 1.2em; margin: 4px 0 0; font-size: 12px; }
.msg { color: #6ee7b7; min-height: 1.2em; margin: 6px 0; font-size: 12px; }
.msg.bad { color: #fca5a5; }

.gate-wrap { min-height: calc(100dvh - 58px); display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 50% 25%, rgba(52, 211, 153, 0.11), transparent 55%); }
.gate { width: min(360px, 100%); display: flex; flex-direction: column; gap: 10px; }

main { max-width: 1200px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--hairline); border-radius: 12px; padding: 16px; }
.gate h2, .card h2 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 16px; }
.sec-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat .k { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.stat .v { font-family: 'Space Grotesk', sans-serif; font-size: 18px; font-weight: 700; }
.stat .sub { font-size: 11px; color: var(--muted); word-break: break-word; font-family: 'JetBrains Mono', ui-monospace, monospace; }

.pill { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 500; border: 1px solid var(--hairline); }
.pill.ok { color: #6ee7b7; background: var(--signal-soft); border-color: rgba(16, 185, 129, 0.35); }
.pill.bad { color: #fca5a5; background: var(--danger-soft); border-color: rgba(239, 68, 68, 0.35); }
.pill.warn { color: #fcd34d; background: var(--warn-soft); border-color: rgba(245, 158, 11, 0.35); }
.pill.acc { color: #a7f3d0; background: var(--accent-soft); border-color: rgba(52, 211, 153, 0.35); }

.form-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.form-row input { flex: 1 1 160px; min-width: 0; }
.form-row select, .form-row input[type=number] { flex: 0 1 95px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
td.row-acts { display: flex; flex-wrap: wrap; gap: 5px; }
td.row-acts button { padding: 4px 8px; font-size: 11px; min-height: 28px; }
td.row-acts button.danger { color: #fca5a5; border-color: rgba(239, 68, 68, 0.35); background: var(--danger-soft); }

.feed { display: flex; flex-direction: column; gap: 8px; max-height: 360px; overflow-y: auto; }
.ev {
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 10px 12px;
  background: #0d120f;
}
.ev .top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.ev .detail { color: var(--muted); font-size: 12px; word-break: break-word; font-family: 'JetBrains Mono', ui-monospace, monospace; }

.manifest-box { margin-top: 12px; }
.manifest-box summary { cursor: pointer; color: var(--muted); padding: 6px 0; font-weight: 500; }
.manifest-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-top: 10px; font-size: 12px; }
.manifest-grid pre {
  margin: 6px 0 0;
  background: #080b09;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 10px;
  overflow: auto;
  max-height: 250px;
  color: var(--muted);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
}

[hidden] { display: none !important; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 13, 0.72);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 60;
}
.modal-box {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.modal-box h3 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 16px; }
#modalFieldWrap input { width: 100%; }
.modal-acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
@media (max-width: 720px) {
  input, select { font-size: 16px; }
  main { padding: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .card { padding: 12px; }
  .topbar { padding-left: 12px; padding-right: 12px; }
  .gate-wrap { min-height: calc(100dvh - 64px); padding: 12px; }
}
