/* BMECat Explorer. Dense, data-tool styling.
   Light theme only -- deliberately fixed, not following the OS preference. */

:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #dfe3e8;
  --text: #1b1f24;
  --muted: #666e7a;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --ok: #1a7f37;
  --ok-soft: #e8f5ec;
  --warn: #9a6700;
  --warn-soft: #fff6e0;
  --err: #cf222e;
  --err-soft: #fdeced;
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
header h1 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
header .sub { color: var(--muted); font-size: 12.5px; }
header .spacer { flex: 1; }

main { padding: 20px; max-width: 1600px; margin: 0 auto; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 12px;
  font-weight: 600;
}

/* Layout: filter rail + results */
.explore { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .explore { grid-template-columns: 1fr; } }

.rail { position: sticky; top: 60px; max-height: calc(100vh - 80px); overflow-y: auto; }

/* Forms */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=search], input[type=number],
input[type=password], select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field { margin-bottom: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

button, .btn {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { background: var(--err); border-color: var(--err); color: #fff; }
button.danger:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--muted); }

/* Outcome cards: tinted so the result of an export reads at a glance. */
.warn-card { border-color: var(--warn); background: var(--warn-soft); }
.ok-card { border-color: var(--ok); background: var(--ok-soft); }
.err-card { border-color: var(--err); background: var(--err-soft); }
.status-warn { color: var(--warn); }

/* Facets */
.facet { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.facet-list { max-height: 220px; overflow-y: auto; margin: 0; padding: 0; list-style: none; }
.facet-list li { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.facet-list label {
  display: flex; align-items: center; gap: 6px; margin: 0;
  font-size: 12.5px; color: var(--text); cursor: pointer; width: 100%;
}
.facet-list input { margin: 0; flex: none; }
.facet-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facet-list .count { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }

/* Counts banner */
.counts { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.counts .big { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.counts .of { color: var(--muted); }
.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 11.5px; font-weight: 600;
}

/* Table */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-weight: 600; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted);
  border-bottom: 1px solid var(--border); padding: 6px 8px; position: sticky; top: 0;
  background: var(--panel);
}
td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:hover { background: var(--accent-soft); }
td.pid { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* Jobs / progress */
.progress {
  height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: 6px;
}
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.job { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.job:last-child { border-bottom: 0; }
.status-done { color: var(--ok); }
.status-failed { color: var(--err); }
.status-running, .status-queued { color: var(--warn); }

/* Catalog cards */
.catalogs { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.cat {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; background: var(--panel); display: block;
}
.cat:hover { border-color: var(--accent); text-decoration: none; }
.cat .name { font-weight: 600; color: var(--text); margin-bottom: 2px; }
.cat .meta { font-size: 12px; color: var(--muted); }

details summary { cursor: pointer; font-size: 12.5px; color: var(--muted); padding: 3px 0; }
details summary:hover { color: var(--accent); }

.htmx-request .spin { visibility: visible; }
.spin { visibility: hidden; color: var(--muted); font-size: 12px; }

/* Header navigation and language switcher */
.topnav { display: flex; gap: 14px; align-items: baseline; }
.topnav a { font-size: 13px; color: var(--muted); }
.topnav a.on { color: var(--text); font-weight: 600; }
.langform { margin: 0; display: flex; align-items: center; }
.langform select { width: auto; padding: 3px 6px; font-size: 12.5px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Login */
.login-wrap { max-width: 380px; margin: 8vh auto 0; }
.login-wrap h2 { font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--text); }

/* API key display: shown once, so it must be easy to select and copy. */
.keybox {
  display: flex; gap: 8px; align-items: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 10px;
}
.keybox code {
  flex: 1; font-family: var(--mono); font-size: 12.5px;
  overflow-wrap: anywhere; user-select: all;
}

/* Docs code blocks */
pre {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px; overflow-x: auto; margin: 0;
}
pre code { font-family: var(--mono); font-size: 12.5px; white-space: pre; }
code { font-family: var(--mono); font-size: 12.5px; }

/* File input */
input[type=file] {
  width: 100%; padding: 6px 8px; font: inherit;
  border: 1px dashed var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
}

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 0; font-size: 12.5px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Category tree. Nested lists indent by their own padding, so depth needs no
   per-level classes and a branch can be rendered without knowing its level. */
.tree, .tree-root ul { list-style: none; margin: 0; padding: 0; }
.tree-children { display: none; padding-left: 14px; }
li.open > .tree-children { display: block; }

.tree-row { display: flex; align-items: center; gap: 4px; padding: 1px 0; }
.tree-row .name {
  flex: 1; display: flex; align-items: center; gap: 5px;
  font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin: 0; color: var(--text); cursor: pointer;
}
.tree-row .name input { margin: 0; flex: none; }
.tree-row .count { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }

.tree-toggle {
  flex: none; width: 16px; height: 16px; padding: 0; line-height: 1;
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 10px; transition: transform .12s;
}
.tree-toggle:hover { color: var(--accent); }
li.open > .tree-row > .tree-toggle { transform: rotate(90deg); }
.tree-leaf { cursor: default; }

.tree-selected { color: var(--accent); font-weight: 600; }
.tree-root { max-height: 320px; overflow-y: auto; }

/* Category breadcrumbs on the article panel. The leaf is a link into the
   filtered list; the ancestors are context only. */
ul.crumbs { list-style: none; margin: 4px 0 0; padding: 0; font-size: 12.5px; }
ul.crumbs li { padding: 2px 0; line-height: 1.45; }
ul.crumbs .sep { color: var(--muted); margin: 0 4px; }

/* Feature rows with an exclusion toggle. The summary is the flex row, so the
   "−" sits hard right of the name and count without extra wrappers. */
details.feature > summary {
  display: flex; align-items: center; gap: 6px;
  list-style: none;                     /* our own layout, not the default marker */
}
details.feature > summary::-webkit-details-marker { display: none; }
details.feature > summary::marker { content: ""; }
details.feature .feature-name {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Excluded: struck through, so the state is obvious without reading the count. */
details.feature.excluded > summary .feature-name {
  text-decoration: line-through;
  color: var(--muted);
}

.excl {
  flex: none; margin: 0; display: inline-flex; align-items: center;
  justify-content: center; width: 18px; height: 18px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--muted); font-size: 13px; line-height: 1; background: var(--panel);
}
.excl:hover { border-color: var(--err); color: var(--err); }
.excl input { position: absolute; opacity: 0; pointer-events: none; }
/* :has lets the checked state style its own label without any script. */
.excl:has(input:checked) {
  background: var(--err); border-color: var(--err); color: #fff;
}
