:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #dde1e7;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --accent-soft: #e6eefc;
  --warn-bg: #fff4e0;
  --warn-text: #7a4b00;
  --error-bg: #fdecec;
  --error-text: #9b1c1c;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #181c21;
    --surface-2: #20252c;
    --border: #2d343d;
    --text: #e6e9ed;
    --muted: #9aa5b1;
    --accent: #6b9cf0;
    --accent-text: #0d1117;
    --accent-soft: #1d2b44;
    --warn-bg: #3a2c12;
    --warn-text: #f3c77a;
    --error-bg: #3b1919;
    --error-text: #f4a3a3;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
}

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; z-index: 10; background: var(--surface); padding: 6px 10px; }

.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top-row { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; padding-top: 14px; padding-bottom: 14px; }
.brand { font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
.stats { margin: 0; color: var(--muted); font-size: 13px; }
.account { margin-left: auto; display: flex; align-items: baseline; gap: 10px; font-size: 14px; }
.account .who { color: var(--muted); max-width: 16em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.button { display: inline-block; padding: 7px 14px; border-radius: var(--radius); background: var(--accent); color: var(--accent-text); font-weight: 600; text-decoration: none; }
a.button:hover { filter: brightness(1.08); }
.gate { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.gate p { margin: 0; }

main { padding-top: 20px; padding-bottom: 32px; }
main:focus, main:focus-visible { outline: none; }

h1 { font-size: 20px; margin: 4px 0 12px; word-break: break-all; }
h1.mono { font-size: 17px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); font-weight: 600; }

.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* Filters */
.filters { display: grid; grid-template-columns: minmax(220px, 2fr) repeat(2, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
input, select, button { font: inherit; color: inherit; }
input, select {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 7px 10px; min-width: 0;
}
input:focus, select:focus { border-color: var(--accent); }
/* Own chevron instead of the native arrow: same in every browser, both themes, room to breathe. */
select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  text-overflow: ellipsis;
}
select:hover { border-color: var(--muted); }
select option { background: var(--surface); color: var(--text); }

button, .button {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius);
  padding: 7px 14px; text-decoration: none; color: var(--text);
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { cursor: not-allowed; opacity: .6; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }

/* Results */
.summary-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 0 0 8px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.table-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.file { white-space: nowrap; font-size: 12px; }
td .line + .line { margin-top: 2px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
[aria-busy="true"] { opacity: .55; transition: opacity .15s; }

.pager { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 12px; }

.notice { padding: 12px 14px; border-radius: var(--radius); background: var(--surface-2); }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice.error { background: var(--error-bg); color: var(--error-text); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

/* File page */
.back { display: inline-block; margin-bottom: 8px; font-size: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.head-grid { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: start; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 13px; }
dl.kv dd { margin: 0; word-break: break-all; }
.download { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; min-width: 220px; }
.download p { margin: 0; font-size: 13px; text-align: right; max-width: 260px; }
.ecus { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; vertical-align: middle; }
tr.current td { background: var(--accent-soft); }

/* Tree */
.tree { font-size: 13px; }
.tree ul { list-style: none; margin: 0; padding-left: 18px; border-left: 1px dashed var(--border); }
.tree > ul { padding-left: 0; border-left: 0; }
.tree li { margin: 2px 0; }
.tree summary { cursor: pointer; }
.tree .name { font-weight: 600; }
.tree .meta { color: var(--muted); font-size: 12px; margin-left: 6px; }
.tree button.part { margin-left: 8px; font-size: 13px; }
.tree .part-note { margin-left: 8px; font-size: 12px; }
.tree .notice-inline { color: var(--error-text); }
.tree .val { font-family: var(--mono); font-size: 12px; margin-left: 8px; word-break: break-all; }
.tree .hidden { color: var(--muted); font-style: italic; margin-left: 8px; }
.tree details > summary + pre.script { margin: 6px 0 6px 0; }
.tree pre.script {
  font-family: var(--mono); font-size: 12px; line-height: 1.45; white-space: pre; overflow: auto;
  max-height: 420px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius);
}

@media (max-width: 760px) {
  /* Search results as cards */
  .results table, .results tbody, .results tr, .results td { display: block; }
  .results thead { position: absolute; left: -9999px; }
  .results tr { padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .results tbody tr:last-child { border-bottom: 0; }
  .results td { border: 0; padding: 2px 0; text-align: left; display: flex; gap: 8px; }
  .results td::before { content: attr(data-label); color: var(--muted); font: 12px/1.9 var(--sans); min-width: 92px; flex: none; }
  .results td.file { white-space: normal; word-break: break-all; font-size: 13px; margin-bottom: 4px; }
  .results td.file::before { display: none; }
  .results td .line + .line { margin-top: 0; }
  .results td > .line { display: block; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .field:first-child { grid-column: 1 / -1; }
  .head-grid { grid-template-columns: 1fr; }
  .download { align-items: stretch; }
  .download p { text-align: left; max-width: none; }
  .ecus { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 1fr; }
  dl.kv dd { margin-bottom: 6px; }
}

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

/* History tables: as wide as their content */
.card .table-box { display: inline-block; max-width: 100%; }
.card .table-box table { width: auto; }
