/* ═══════════════════════════════════════════════════════════════════════════
   Data Explorer (step 5) — a catalog spelunker.
   Two signature moves: the drill-path spine (source › schema › table) and the
   type-aware grid (every column wears a mono type sigil). Everything else quiet.
   Uses the app's theme tokens so it re-skins with golden/ocean/morpho/pearl.
   ═══════════════════════════════════════════════════════════════════════════ */

/* the Explorer's scroll body owns its inset (panel-body itself has none), so the
   path, grid header and grid all align with the panel title above them */
.exp-body { padding: 22px 28px 34px; }

/* ── drill-path spine ─────────────────────────────────────────────────────── */
.exp-path {
  display: flex; align-items: stretch; gap: 4px; flex-wrap: wrap;
  padding: 6px; margin-bottom: 18px;
  background: var(--depth); border: 1px solid var(--border); border-radius: var(--r);
}
.exp-seg {
  position: relative; display: flex; flex-direction: column; justify-content: center;
  padding: 5px 12px 6px; border-radius: 6px; min-width: 0;
  border: 1px solid transparent; transition: background .15s, border-color .15s;
}
.exp-seg:hover { background: var(--lift); }
.exp-seg-tag {
  font-family: var(--label-font, var(--mono)); font-size: max(9.5px, var(--label-min-size, 0px)); letter-spacing: var(--label-tracking, .16em);
  text-transform: var(--label-case, uppercase); color: var(--subtle-ink, var(--faint)); line-height: 1;
  margin-bottom: 3px; transition: color .15s;
}
/* The breadcrumb's selects are the platform's inline dropdown register (app.css):
   a value you edit in place, not a field. Only the truncation is local. */
.exp-seg select { max-width: 40ch; text-overflow: ellipsis; }
/* the deepest chosen level is where you ARE — mark it with the accent */
.exp-seg.is-active { background: var(--accent-bg); }
.exp-seg.is-active .exp-seg-tag { color: var(--accent); }
.exp-seg.is-active select { color: var(--text); }

.exp-sep {
  align-self: center; font-family: var(--mono); font-size: 17px;
  color: var(--faint); padding: 0 2px; user-select: none;
}

.exp-path-search {
  margin-left: auto; align-self: center; display: flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: 6px; background: var(--void);
  border: 1px solid var(--border); color: var(--faint);
  transition: border-color .15s, color .15s;
}
.exp-path-search:focus-within { border-color: var(--bhi); color: var(--muted); }
.exp-path-search input {
  border: 0; background: transparent; outline: none; width: 20ch;
  font-family: var(--mono); font-size: var(--type-meta, 12.5px); color: var(--text);
}
.exp-path-search input::placeholder { color: var(--faint); letter-spacing: .02em; }

/* ── result surface ───────────────────────────────────────────────────────── */
.explorer-result { position: relative; min-height: 220px; }
.explorer-result.explorer-loading { opacity: .45; pointer-events: none; transition: opacity .12s; }

.explorer-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 64px 20px; text-align: center;
  font-family: var(--mono); font-size: 13px; letter-spacing: .01em; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--r-lg);
}
.exp-empty-glyph { color: var(--faint); opacity: .8; }
.explorer-empty.explorer-err { color: var(--rose); border-color: color-mix(in srgb, var(--rose) 35%, transparent); }
.explorer-empty.explorer-err .exp-empty-glyph { display: none; }

/* ── grid header: table-as-subject + row count + pager ────────────────────── */
.explorer-toolbar {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; margin-bottom: 12px; padding: 0;
}
.exp-subject { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.exp-table-name {
  font-family: var(--display); font-size: 21px; font-weight: 600; letter-spacing: -.01em;
  color: var(--text); line-height: 1;
}
.explorer-count {
  font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap;
}
.explorer-count b { color: var(--accent); font-weight: 600; }
.explorer-pager { display: flex; align-items: center; gap: 4px; }
.exp-pgbtn {
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 11px; cursor: pointer; transition: border-color .12s, color .12s;
}
.exp-pgbtn:hover:not(:disabled) { border-color: var(--bhi); color: var(--text); }
.exp-pgbtn:disabled { opacity: .35; cursor: not-allowed; }

/* ── the grid ─────────────────────────────────────────────────────────────── */
.explorer-table-wrap {
  overflow: auto; max-height: 60vh;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
}
.explorer-table { border-collapse: separate; border-spacing: 0; width: 100%; }
.explorer-table th, .explorer-table td {
  text-align: left; white-space: nowrap; max-width: 380px;
  overflow: hidden; text-overflow: ellipsis;
  border-bottom: 1px solid var(--border);
}

/* The two header rows stick as ONE block: `thead` is the sticky box, not each
   th with its own `top`. A per-row offset has to equal the first row's height,
   which differs under every theme's type and density (76px and 78px with the
   distribution strip) — and the old one never applied anyway, because
   `.explorer-table thead th { top: 0 }` outranked `.explorer-filter-row th`. */
.explorer-table thead { position: sticky; top: 0; z-index: 3; }

/* header cell: column name over its type sigil */
.explorer-table thead th {
  background: var(--depth);
  padding: 9px 14px 8px; cursor: pointer; user-select: none;
  border-bottom: 1px solid var(--bhi);
  vertical-align: bottom;
}
.exp-th-name {
  display: block; font-family: var(--display); font-size: 12.5px; font-weight: 600;
  color: var(--text); letter-spacing: .01em; line-height: 1.2;
}
.exp-th-meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.exp-type {
  font-family: var(--label-font, var(--mono)); font-size: max(9.5px, var(--label-min-size, 0px)); letter-spacing: var(--label-tracking, .1em); text-transform: var(--label-case, uppercase);
  color: var(--muted); line-height: 1;
}
/* type sigils — a 2px leading tick color-codes the column's data category */
.exp-type::before {
  content: ""; display: inline-block; width: 5px; height: 5px; border-radius: 1px;
  margin-right: 5px; vertical-align: middle; background: currentColor;
}
.exp-type.t-number  { color: var(--cyan); }
.exp-type.t-date    { color: var(--violet); }
.exp-type.t-bool    { color: var(--emerald); }
.exp-type.t-text    { color: var(--muted); }
.exp-sort { color: var(--accent); font-family: var(--mono); font-size: 10px; margin-left: auto; }
.explorer-table thead th:hover .exp-th-name { color: var(--accent); }

/* per-column filters as a faint editable strip — present but never shouting,
   so the typed headers stay the star */
.explorer-filter-row th {
  background: var(--depth);
  padding: 0 14px 6px; cursor: default; border-bottom: 1px solid var(--bhi);
}
.exp-col-filter {
  width: 100%; box-sizing: border-box; padding: 2px 0;
  font-family: var(--mono); font-size: 10.5px; color: var(--text);
  background: transparent; border: 0; border-bottom: 1px solid var(--border);
  border-radius: 0; transition: border-color .12s;
}
.exp-col-filter:hover { border-bottom-color: var(--bhi); }
.exp-col-filter:focus { outline: none; border-bottom-color: var(--accent); }
.exp-col-filter::placeholder { color: var(--faint); letter-spacing: .06em; }

/* body cells — data as mono material */
.explorer-table tbody td {
  padding: 6px 14px; font-family: var(--mono); font-size: 12.5px; color: var(--text);
}
.explorer-table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--lift) 22%, transparent); }
.explorer-table tbody tr:hover td { background: var(--accent-bg); }
.exp-null { color: var(--faint); font-style: italic; letter-spacing: .04em; }
.exp-empty-row { text-align: center; color: var(--muted); padding: 28px; font-family: var(--mono); }

@media (prefers-reduced-motion: reduce) {
  .exp-seg, .exp-path-search, .exp-pgbtn, .exp-col-filter, .explorer-result { transition: none; }
}

@media (max-width: 720px) {
  .exp-path-search { margin-left: 0; width: 100%; }
  .exp-seg select { max-width: 24ch; }
}

/* ══ Imago (spec 005d): a tree of sources on the left, the grid on the right ══
   Data reads as values (Readex, tabular figures) rather than code; identifiers
   that genuinely are code stay mono nowhere here. Theme tokens only. */
.exp-body { padding: 0; display: flex; flex-direction: column; }
.exp-layout { flex: 1; min-height: 0; display: flex; flex-wrap: wrap; align-items: stretch; }
.exp-tree {
  flex: 1 1 220px; max-width: 300px; min-width: 0;
  padding: 18px 12px;
  border-right: 1px solid var(--border);
  background: var(--lift);
  display: flex; flex-direction: column; gap: 2px;
}
.exp-tree-empty { font-size: var(--type-secondary, 13.5px); color: var(--muted); padding: 8px 10px; }
.exp-tree ul { list-style: none; }
.exp-tree-row, .exp-tree-table {
  display: flex; align-items: center; gap: 8px; width: 100%;
  min-height: 36px; padding: 0 10px;
  border: 0; border-radius: var(--r); background: transparent;
  color: var(--text); font: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
.exp-tree-row:hover, .exp-tree-table:hover { background: var(--accent-bg); }
.exp-tree-row:focus-visible, .exp-tree-table:focus-visible { outline: 2px solid var(--focus, var(--accent)); outline-offset: 1px; }
.exp-tree-row.is-source { font-weight: 600; }
.exp-tree-row.is-schema { color: var(--muted); padding-left: 22px; }
.exp-tree-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp-tree-meta { font-size: 12px; color: var(--muted); font-weight: 400; }
.exp-chev { flex: none; color: var(--muted); transition: transform .12s; }
.exp-chev.is-open { transform: rotate(90deg); }
.exp-tree-tables { padding-left: 24px; }
.exp-tree-schemas .exp-tree-tables { padding-left: 38px; }
.exp-tree-table { min-height: 34px; font-size: var(--type-body, 13.5px); }
.exp-tree-table.is-on { background: var(--accent-mid); font-weight: 600; }

.exp-main { flex: 999 1 520px; min-width: 0; padding: var(--page-body-pad, 22px clamp(18px, 2.5vw, 32px) 28px); display: flex; flex-direction: column; gap: 14px; }
.explorer-toolbar { align-items: center; flex-wrap: wrap; margin: 0; }
.exp-subject { flex-direction: column; align-items: flex-start; gap: 4px; }
.exp-table-name { font-size: 26px; letter-spacing: -0.02em; }
.explorer-count { font-family: var(--sans); font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.exp-search {
  display: flex; align-items: center; gap: 8px;
  min-height: max(var(--control-h, 36px), var(--touch-min, 0px)); padding: 0 12px; width: min(320px, 100%);
  background: var(--field-bg, var(--surface)); border: 1px solid var(--field-border, var(--border));
  border-radius: var(--control-r, var(--r)); color: var(--muted);
}
.exp-search:focus-within { border-color: var(--focus, var(--accent)); }
.exp-search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font: inherit; font-size: 14px; color: var(--text); }
.exp-search input::placeholder { color: var(--faint); }

.explorer-table-wrap { max-height: none; flex: 1; min-height: 200px; border-color: var(--border); }
.explorer-table thead th { background: var(--lift); padding: var(--row-head-pad-y, 11px) var(--grid-pad-x, 14px) var(--row-head-pad-y, 9px); border-bottom: 1px solid var(--border); }
.exp-th-name { font-family: var(--sans); font-size: var(--type-body, 13.5px); font-weight: var(--weight-strong, 600); letter-spacing: 0; }
.exp-type { font-size: max(11px, var(--label-min-size, 0px)); }
.exp-sort { font-family: var(--sans); font-size: 13px; }
.explorer-filter-row th { background: var(--lift); padding: 0 14px 8px; }
.exp-col-filter { font-family: var(--sans); font-size: 13px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.exp-col-filter:focus { border-color: var(--focus, var(--accent)); }
.exp-col-filter::placeholder { letter-spacing: 0; }
.explorer-table tbody td { font-family: var(--sans); font-size: var(--type-body, 14px); padding: var(--grid-pad-y, 10px) var(--grid-pad-x, 14px); font-variant-numeric: tabular-nums; border-bottom-color: color-mix(in srgb, var(--border) 65%, transparent); }
.explorer-table tbody tr:nth-child(even) td { background: transparent; }
.exp-null { font-style: normal; font-size: var(--type-meta, 12.5px); }
.explorer-empty { font-family: var(--sans); font-size: var(--type-reading, 15px); padding: var(--empty-pad, 72px 24px); }
.exp-empty-row { font-family: var(--sans); }
.exp-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (max-width: 900px) {
  .exp-tree { max-width: none; flex-basis: 100%; border-right: 0; border-bottom: 1px solid var(--border); }
}
@media (prefers-reduced-motion: reduce) { .exp-chev { transition: none; } }
.explorer-table th.is-num, .explorer-table td.is-num { text-align: right; }
.explorer-table th.is-num .exp-th-meta { justify-content: flex-end; }

/* The approved data-dictionary description of the open table (spec 007). */
.exp-table-desc {
  margin: 2px 0 0; max-width: 72ch; font-size: var(--type-secondary, 13px); color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.exp-dict-btn { flex: none; }

/* ── column distributions (spec 008) ──────────────────────────────────────────
   The strip is imago.css's `.im-profile`; only its place in the header is
   local. Bars are --series-1: a histogram is a one-series chart. */
.explorer-table th.is-num .exp-profile { justify-content: flex-end; }
.exp-profile { cursor: default; border-radius: 2px; }
.exp-profile:focus-visible { outline: 2px solid var(--focus, var(--accent)); outline-offset: 2px; }
.exp-profile-skel { display: block; width: 48px; height: 100%; opacity: .7; }
.exp-profile-failed { color: var(--muted); }
/* Fixed, not inside the header cell: a th is overflow:hidden (its text
   ellipsises) and would clip it. */
.exp-profile-tip {
  position: fixed; z-index: 50; max-width: min(360px, calc(100vw - 16px));
  padding: 8px 10px; border-radius: var(--r, 8px);
  background: var(--surface); color: var(--text); border: 1px solid var(--bhi);
  box-shadow: var(--shadow-md, 0 6px 20px color-mix(in srgb, var(--text) 18%, transparent));
  font-family: var(--sans); font-size: var(--type-secondary, 13px); line-height: 1.45;
  font-variant-numeric: tabular-nums; pointer-events: none; white-space: normal;
}

/* ── "Summarise this view" (spec 008) ─────────────────────────────────────────
   A petal (.im-ai--sm): the words are Imago's. The numbers in them are bold
   and carry their fact; the queries that produced them fold away below. */
.exp-summarise { flex: none; }
/* Search, Summarise and Open in dictionary share the toolbar with the table's
   name. A wrapping row places items by their flex-basis before anything
   shrinks, so the search's basis is its smallest width; it grows to 320px. */
.explorer-toolbar .exp-search { flex: 1 1 180px; width: auto; min-width: 0; max-width: 320px; }
.exp-summary { max-width: 860px; }
.exp-summary-text { display: flex; flex-direction: column; gap: 6px; }
.exp-summary-text p { margin: 0; font-size: var(--type-body, 14px); line-height: 1.55; color: var(--text); }
.exp-summary-text strong { font-weight: 600; color: var(--ai-ink, var(--accent)); font-variant-numeric: tabular-nums; }
.exp-summary-queries summary { cursor: pointer; font-size: var(--type-secondary, 13px); color: var(--muted); }
.exp-summary-queries summary:focus-visible { outline: 2px solid var(--focus, var(--accent)); outline-offset: 2px; }
.exp-summary-query { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.exp-summary-query span { font-size: var(--type-secondary, 13px); color: var(--muted); }
.exp-summary-query pre {
  margin: 0; padding: 8px 10px; overflow-x: auto; white-space: pre-wrap; word-break: break-word;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r, 8px);
  font-family: var(--mono); font-size: var(--type-meta, 12.5px); color: var(--text);
}
.exp-summary-error { max-width: 860px; }
.exp-summary-why { margin: 4px 0 10px; color: var(--muted); font-size: var(--type-secondary, 13px); }
