:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1c1d1f;
  --muted: #61666d;
  --line: #d9dadd;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --mark: #ffe58a;
  --mark-line: #f2c200;
  --row-odd: #f3f4f6;
  --warn-bg: #fde8e8;
  --warn-text: #8a1c1c;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --panel: #1d2024;
    --text: #e6e7e9;
    --muted: #9ba1a9;
    --line: #353a41;
    --accent: #7fb0ff;
    --accent-text: #0d1a2e;
    --mark: #6b5a0f;
    --mark-line: #b8970a;
    --row-odd: #23272c;
    --warn-bg: #3a1f1f;
    --warn-text: #ffb4b4;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
h1 { font-size: 1.15rem; margin: 0; }
h2 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.top, main { max-width: 80rem; margin: 0 auto; padding: 0 16px; }
.top { padding-top: 12px; }
.brand { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; }
.privacy { margin: 4px 0 12px; color: var(--muted); font-size: 0.9rem; }

button, select, input[type="search"] {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
}
button { cursor: pointer; }
button:disabled { opacity: 0.5; cursor: default; }
button.link {
  border: 0; background: none; padding: 0; color: var(--accent);
  text-decoration: underline; font-family: var(--mono); font-size: inherit;
}

.intake { display: flex; flex-wrap: wrap; gap: 12px; align-items: stretch; }
.drop {
  flex: 1 1 18rem;
  position: relative;
  display: flex; flex-direction: column; gap: 2px; justify-content: center;
  min-height: 5rem; padding: 12px 16px;
  border: 2px dashed var(--line); border-radius: 10px; background: var(--panel);
  cursor: pointer;
}
.drop.over { border-color: var(--accent); }
.drop:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.drop input {
  position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden;
}
.drop-title { font-weight: 600; }

.status { margin: 12px 0; font-weight: 600; }
.alert {
  margin: 12px 0; padding: 10px 14px; border-radius: 8px;
  background: var(--warn-bg); color: var(--warn-text); border: 1px solid currentColor;
  overflow-wrap: anywhere;
}

.tabs { display: flex; overflow-x: auto; gap: 2px; margin-top: 16px; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 0 0 auto; border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none;
}
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); font-weight: 600; }
.badge {
  display: inline-block; min-width: 1.5em; padding: 0 6px; border-radius: 999px;
  background: var(--line); font-size: 0.8rem; text-align: center;
}

[role="tabpanel"] { padding: 12px 0 32px; }

.facts, .card dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 10px 16px; margin: 0; }
.field dt { color: var(--muted); font-size: 0.8rem; }
.field dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; }
.field dd.missing { color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; }
.card dl { grid-template-columns: 1fr; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 8px; }
.toolbar .group { display: inline-flex; gap: 6px; align-items: center; }
.toolbar input[type="search"] { flex: 1 1 10rem; min-width: 0; }

.grid, .textview {
  position: relative; overflow: auto;
  height: max(18rem, calc(100vh - 17rem));
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  font-family: var(--mono); font-size: 0.85rem;
}
.v-sizer { position: relative; }
.grid .row { display: flex; align-items: center; }
.grid .row.odd { background: var(--row-odd); }
.grid .row.head {
  position: sticky; top: 0; z-index: 2; height: 30px;
  background: var(--panel); border-bottom: 2px solid var(--line); font-weight: 700;
}
.grid .cell {
  flex: 0 0 auto; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.grid .cell.null { color: var(--muted); font-style: italic; }

.textview .line { display: flex; white-space: pre; align-items: center; }
.textview .no {
  flex: 0 0 5ch; padding: 0 8px; margin-right: 8px; text-align: right; color: var(--muted);
  position: sticky; left: 0; background: var(--panel);
}
.textview .line.current { background: var(--mark); }
.textview .line.current .no { background: var(--mark); }
.textview .line.path { color: var(--muted); padding-left: calc(5ch + 24px); background: var(--row-odd); font-style: italic; }
.textview mark {
  background: var(--accent); color: var(--accent-text); border-radius: 2px;
  outline: 2px solid var(--mark-line); display: inline-block; min-width: 1ch;
}

.diag-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.diag-tools button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.diag-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.diag {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
}
.diag .level { font-weight: 700; margin-right: 8px; }
.diag .path { color: var(--muted); font-family: var(--mono); font-size: 0.85rem; }
.diag .text { margin: 4px 0; font-family: var(--mono); font-size: 0.85rem; overflow-wrap: anywhere; }
.diag button.jump { text-decoration: underline; color: var(--accent); border: 0; background: none; padding: 0; }

.tree, .tree ul { list-style: none; margin: 0; padding-left: 18px; }
.tree { padding-left: 0; font-family: var(--mono); font-size: 0.85rem; }
.tree summary { cursor: pointer; padding: 2px 0; overflow-wrap: anywhere; }
.tree .tag { color: var(--muted); }
.tree .ids button.link { margin-right: 6px; }

@media (max-width: 480px) {
  body { font-size: 14px; }
  .top, main { padding: 0 12px; }
  .grid, .textview { height: max(16rem, calc(100vh - 20rem)); }
}

.v-sizer > * { right: 0; }
