:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --accent: #5b9dff;
  --accent-dim: #2f4a73;
  --green: #4ec988;
  --amber: #e8b84b;
  --red: #ef6c6c;
  --zebra: #14171d;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win, even over component rules that set an
   explicit display (e.g. .state-overlay { display:flex }). Without this the JS
   toggling el.hidden has no visual effect and overlays stay painted on top. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 15px; letter-spacing: 0.01em; }
h3 { font-size: 13px; }

button { font-family: inherit; }

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--accent), #7c5bff);
  color: #fff;
  font-weight: 700;
  border-radius: 9px;
  letter-spacing: 0.02em;
}
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.header-right { display: flex; align-items: center; gap: 20px; }
.scenario-context { margin: 0; color: var(--muted); font-size: 12px; font-family: var(--mono); word-break: break-all; max-width: 50vw; }
.health { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.bad { background: var(--red); box-shadow: 0 0 8px var(--red); }

/* ---------- Layout ---------- */
.layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}
.dashboard { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.card-context { color: var(--muted); font-size: 12.5px; }
.card-context.ok { color: var(--green); }
.card-context.warn { color: var(--amber); }
.card-context.bad { color: var(--red); }
.card-body { padding: 14px 16px; position: relative; min-height: 56px; }

/* ---------- Buttons + inputs ---------- */
.btn {
  background: var(--accent);
  color: #06101f;
  border: none;
  border-radius: 6px;
  padding: 7px 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 4px 9px; font-size: 12px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn.small:hover { border-color: var(--accent-dim); filter: none; }

input, select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  font-family: inherit;
  font-size: 13px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

/* ---------- Picker (no deep link) ---------- */
.picker {
  max-width: 720px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.picker-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.picker .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.scenario-list { display: flex; flex-direction: column; gap: 7px; }
.scenario-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 11px 13px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.scenario-item:hover { border-color: var(--accent); background: #1b2433; }
.scenario-item .name { font-weight: 600; }
.scenario-item .meta { color: var(--muted); font-size: 12px; }
.list-empty { color: var(--muted); font-size: 13px; padding: 8px 2px; }

/* ---------- Top-level dashboard error ---------- */
.dash-error {
  max-width: 720px;
  margin: 24px auto;
  background: var(--panel);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
}
.dash-error h2 { margin-bottom: 8px; color: var(--red); }
.dash-error p { color: var(--muted); margin: 0 0 16px; white-space: pre-wrap; }

/* ---------- (1) Validation ---------- */
.valid-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(78,201,136,.10);
  border: 1px solid rgba(78,201,136,.3);
  border-radius: 6px;
  color: var(--green);
}
.valid-banner.ok-with-warn {
  background: rgba(232,184,75,.10);
  border-color: rgba(232,184,75,.3);
  color: var(--amber);
}
.valid-banner .tick { font-weight: 700; }
.issue-group { margin-top: 12px; }
.issue-group:first-child { margin-top: 0; }
.group-title { margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em; font-size: 11px; }
.group-title.error { color: var(--red); }
.group-title.warning { color: var(--amber); }
.issue-list { display: flex; flex-direction: column; gap: 8px; }
.issue {
  padding: 9px 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 6px;
}
.issue.error { border-left-color: var(--red); }
.issue.warning { border-left-color: var(--amber); }
.issue-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 4px; }
.issue-code {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 4px;
}
.issue-code.error { background: rgba(239,108,108,.15); color: var(--red); }
.issue-code.warning { background: rgba(232,184,75,.15); color: var(--amber); }
.issue-stage { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.issue-pos { font-family: var(--mono); font-size: 11px; color: var(--accent); }
.issue-message { font-size: 13px; }
.issue-path { margin-top: 3px; font-family: var(--mono); font-size: 11px; color: var(--muted); word-break: break-all; }

/* ---------- (2) Entity counts ---------- */
.count-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.count-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color .12s, background .12s;
}
.count-card:hover { border-color: var(--accent); background: #1b2433; }
.count-num { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.count-label { color: var(--muted); font-size: 12.5px; word-break: break-word; }

/* ---------- (3) Inspector: tabs + toolbar + table ---------- */
.type-tabs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 60%; }
.type-tab {
  padding: 5px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  color: var(--text);
  font-size: 12px;
}
.type-tab:hover { border-color: var(--accent-dim); }
.type-tab.active { border-color: var(--accent); background: #1b2433; color: var(--accent); }
.type-tab .count { color: var(--muted); margin-left: 5px; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.toolbar #filter { width: 320px; max-width: 50%; }
.toolbar-right { display: flex; align-items: center; gap: 16px; }
.rowcount { color: var(--muted); font-size: 13px; }
.pagesize { flex-direction: row; align-items: center; gap: 6px; }
.pagesize select { padding: 4px 6px; }

.table-wrap { position: relative; max-height: 60vh; overflow: auto; min-height: 120px; }
table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--panel-2);
  text-align: left;
  padding: 9px 12px;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--text); }
thead th .arrow { color: var(--accent); margin-left: 4px; }
tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
}
tbody tr:nth-child(even) { background: var(--zebra); }
tbody tr:hover { background: #1b2433; cursor: pointer; }
td.col-state .state-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: #cfe0ff;
  font-size: 12px;
}
td.num { font-variant-numeric: tabular-nums; }

/* ---------- State overlays ---------- */
.state-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(15,17,21,.85);
  color: var(--muted);
  font-size: 14px;
  z-index: 8;
  padding: 24px;
  text-align: center;
}
.state-overlay.error { color: var(--red); white-space: pre-wrap; }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Pager ---------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
}
.pager #pageInfo { color: var(--muted); font-size: 13px; }

/* ---------- Drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }
.drawer {
  position: fixed;
  top: 0; right: 0;
  width: 460px;
  max-width: 92vw;
  height: 100vh;
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 30px rgba(0,0,0,.4);
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.drawer-body { padding: 8px 16px 24px; overflow-y: auto; position: relative; min-height: 60px; }
.detail-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.detail-row .k { color: var(--muted); font-size: 12px; word-break: break-word; }
.detail-row .v { font-family: var(--mono); font-size: 12.5px; word-break: break-word; }
