/* Pure Data Quality, Smart Tools design language */
:root {
  --bg: #f5f6f3;
  --sidebar-bg: #eef1ec;
  --surface: #ffffff;
  --surface2: #eef1ec;
  --border: #dadfd9;
  --border-lite: #e4e8e2;
  --accent: #355e56;
  --accent-dim: rgba(53, 94, 86, 0.1);
  --accent-line: rgba(53, 94, 86, 0.22);
  --accent2: #6d4c5c;
  --accent2-dim: rgba(109, 76, 92, 0.1);
  --accent2-line: rgba(109, 76, 92, 0.25);
  --success: #4f7942;
  --success-dim: rgba(79, 121, 66, 0.1);
  --success-line: rgba(79, 121, 66, 0.25);
  --warn: #b8860b;
  --warn-dim: rgba(184, 134, 11, 0.1);
  --warn-line: rgba(184, 134, 11, 0.28);
  --error: #a23b3b;
  --error-dim: rgba(162, 59, 59, 0.08);
  --error-line: rgba(162, 59, 59, 0.25);
  --text: #1c2321;
  --text-dim: #5b6b66;
  --text-faint: #838f89;
  --on-accent: #ffffff;
  --backdrop: rgba(28, 35, 33, 0.45);
  --serif: 'Source Serif 4', Georgia, serif;
  --sans: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --radius: 10px;
  --radius-sm: 7px;
  color-scheme: light;
}

.dark {
  --bg: #151917;
  --sidebar-bg: #1b201e;
  --surface: #1f2523;
  --surface2: #262d2a;
  --border: #333b38;
  --border-lite: #2c3330;
  --accent: #7fb3a6;
  --accent-dim: rgba(127, 179, 166, 0.12);
  --accent-line: rgba(127, 179, 166, 0.25);
  --accent2: #c49aae;
  --accent2-dim: rgba(196, 154, 174, 0.12);
  --accent2-line: rgba(196, 154, 174, 0.28);
  --success: #8fbf7f;
  --success-dim: rgba(143, 191, 127, 0.12);
  --success-line: rgba(143, 191, 127, 0.28);
  --warn: #e0b04a;
  --warn-dim: rgba(224, 176, 74, 0.12);
  --warn-line: rgba(224, 176, 74, 0.3);
  --error: #e07a7a;
  --error-dim: rgba(224, 122, 122, 0.1);
  --error-line: rgba(224, 122, 122, 0.28);
  --text: #e6ebe8;
  --text-dim: #a3b0ab;
  --text-faint: #76827d;
  --on-accent: #151917;
  --backdrop: rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ── Shell ─────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 228px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-lite);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { padding: 0 8px; }
.brand-name { font-family: var(--serif); font-weight: 600; font-size: 18px; line-height: 1.2; }
.brand-name span { color: var(--accent); }
.brand-sub { font-family: var(--mono); font-size: 10px; color: var(--text-faint); margin-top: 3px; letter-spacing: 0.04em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label, .eyebrow {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-faint);
}
.nav-label { padding: 0 8px 6px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}
.nav-item svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; opacity: 0.7; }
.nav-item:hover { background: var(--surface); }
.nav-item.active { background: var(--accent-dim); border-color: var(--accent-line); color: var(--accent); font-weight: 600; }
.nav-item.active svg { opacity: 1; }

.dataset { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--border-lite); display: flex; flex-direction: column; gap: 4px; }
.dataset .nav-label { padding: 0 0 4px; }
.dataset-name { font-family: var(--mono); font-size: 11px; font-weight: 500; word-break: break-all; }
.dataset-meta { font-family: var(--mono); font-size: 10px; color: var(--text-faint); margin-bottom: 8px; }

.main { flex: 1; min-width: 0; border-top: 3px solid var(--accent); }
.topbar { display: flex; justify-content: flex-end; padding: 10px 24px 0; }
.content { max-width: 1200px; margin: 0 auto; padding: 8px 36px 48px; }

/* ── Page header ───────────────────────────────────────────────── */
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.page-tag { font-family: var(--mono); font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.16em; color: var(--accent); margin-bottom: 6px; }
.page-title { font-family: var(--serif); font-weight: 600; font-size: 27px; line-height: 1.2; margin: 0; }
.page-title span { color: var(--accent); }
.page-desc { margin: 6px 0 0; color: var(--text-dim); font-weight: 300; max-width: 640px; }

/* ── Card / buttons / inputs ───────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; }

.btn {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 8px 14px;
  cursor: pointer;
  background: transparent;
  color: var(--text);
  transition: opacity 0.15s, background 0.15s;
}
.btn:active:not(:disabled) { transform: scale(0.99); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-sm { font-size: 11px; padding: 5px 10px; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { opacity: 0.88; }
.btn-outline { background: var(--surface); border-color: var(--border); }
.btn-outline:hover:not(:disabled) { background: var(--surface2); }
.btn-ghost { color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.input {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  min-height: 32px;
}
.input::placeholder { color: var(--text-faint); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.inline-label { font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: 0.04em; color: var(--text-dim); }

.pill {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  border-radius: 999px;
  padding: 1px 8px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  white-space: nowrap;
}
.pill-ok { background: var(--success-dim); border-color: var(--success-line); color: var(--success); }
.pill-plum { background: var(--accent2-dim); border-color: var(--accent2-line); color: var(--accent2); }
.pill-missing { border-style: dashed; color: var(--text-faint); }
.pill-neutral { background: transparent; }

.alert { border-radius: 9px; padding: 12px 16px; margin-top: 16px; border: 1px solid; }
.alert-error { background: var(--error-dim); border-color: var(--error-line); color: var(--error); }
.alert-title { font-family: var(--mono); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }

.progress { height: 4px; background: var(--surface2); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 999px; transition: width 0.2s; }

/* ── Upload ────────────────────────────────────────────────────── */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 56px 24px;
  background: var(--surface);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-dim); }
.dropzone.busy { pointer-events: none; opacity: 0.6; }
.dropzone svg { width: 30px; height: 30px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 6px; }
.dropzone-title { font-family: var(--serif); font-weight: 600; font-size: 18px; }
.dropzone-sub { color: var(--text-dim); font-weight: 300; font-size: 13px; }
.progress-wrap { margin-top: 18px; }
.progress-label { font-family: var(--mono); font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }

/* ── Filters ───────────────────────────────────────────────────── */
.filters-card { padding: 14px 16px; margin-bottom: 16px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.ms { position: relative; }
.ms-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  max-width: 340px;
}
.ms-btn:hover { border-color: var(--text-faint); }
.ms-btn.active { background: var(--accent-dim); border-color: var(--accent-line); }
.ms-label { color: var(--text-dim); font-weight: 500; }
.ms-btn.active .ms-label { color: var(--accent); }
.ms-value { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-caret { color: var(--text-faint); font-size: 10px; }
.ms-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  width: 380px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  padding: 8px;
}
.ms-search { width: 100%; margin-bottom: 6px; }
.ms-list { max-height: 300px; overflow-y: auto; }
.ms-opt {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.ms-opt:hover { background: var(--surface2); }
.ms-opt input { accent-color: var(--accent); margin: 0; }
.ms-opt-label { overflow-wrap: anywhere; }
.ms-opt-label.mono { font-size: 11.5px; }
.ms-opt-count { font-family: var(--mono); font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.ms-opt.zero .ms-opt-label { color: var(--text-faint); }
.ms-opt.none .ms-opt-label { font-style: italic; color: var(--text-dim); }
.ms-empty { font-size: 12px; color: var(--text-faint); padding: 8px 6px; }
.ms-foot { display: flex; justify-content: flex-end; border-top: 1px solid var(--border-lite); margin-top: 6px; padding-top: 6px; }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-lite); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  background: var(--accent-dim);
  border: 1px solid var(--accent-line);
  color: var(--text);
  border-radius: 999px;
  padding: 2px 4px 2px 10px;
  max-width: 100%;
}
.chip > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-key { font-family: var(--mono); font-size: 10px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.08em; }
.chip-x { border: 0; background: transparent; color: var(--text-dim); cursor: pointer; font-size: 11px; border-radius: 999px; width: 20px; height: 20px; }
.chip-x:hover { background: var(--accent-line); color: var(--text); }

/* ── Key numbers ───────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat-value { font-family: var(--mono); font-size: 30px; font-weight: 500; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-sub { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.stat .progress { margin-top: 8px; }

/* ── List ──────────────────────────────────────────────────────── */
.list-card { padding: 0; overflow: hidden; }
.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border-lite);
}
.list-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.list-controls #search { width: 220px; }
.list { list-style: none; margin: 0; padding: 0; counter-reset: none; }
.item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-lite);
}
.item:hover { background: color-mix(in srgb, var(--surface2) 55%, transparent); }
.item-main { min-width: 0; }
.item-title {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  line-height: 1.4;
}
.item-title:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.item-meta { font-size: 12px; color: var(--text-dim); font-weight: 300; margin-top: 2px; }
.item-badges { display: flex; gap: 6px; flex-shrink: 0; padding-top: 2px; }
.empty { padding: 48px 16px; text-align: center; }
.empty-title { font-family: var(--serif); font-weight: 600; font-size: 18px; }
.empty-sub { color: var(--text-dim); font-weight: 300; }

.pager { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; }
.pager-size, .pager-nav { display: flex; align-items: center; gap: 8px; }
.pager-info { font-family: var(--mono); font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ── Dialog ────────────────────────────────────────────────────── */
.dialog {
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}
.dialog[open] { display: flex; flex-direction: column; }
.dialog::backdrop { background: var(--backdrop); }
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 20px 12px;
  background: var(--surface2);
}
.dialog-title { font-family: var(--serif); font-weight: 600; font-size: 18px; line-height: 1.3; margin: 4px 0 6px; }
.detail-ids { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--text-dim); }
.detail-ids code { font-size: 11px; }
.dialog-tabs { display: flex; gap: 2px; padding: 0 16px; background: var(--surface2); border-bottom: 1px solid var(--border-lite); }
.tab {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: 8px 10px;
  cursor: pointer;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.dialog-body { overflow-y: auto; padding: 14px 20px 22px; }
.raw {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 10px 0 0;
  overflow-x: auto;
  white-space: pre;
}

/* ── Metadata tree ─────────────────────────────────────────────── */
.tv-obj { margin: 0; }
.tv-row { display: grid; grid-template-columns: 190px 1fr; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--border-lite); }
.tv-row:last-child { border-bottom: 0; }
.tv-row dt { font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: 0.02em; color: var(--text-dim); padding-top: 2px; overflow-wrap: anywhere; }
.tv-row dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.tv-row-nested { display: block; }
.tv-node > summary {
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  padding: 2px 0;
  list-style: revert;
}
.tv-node > summary::marker { color: var(--text-faint); }
.tv-node > .tv-obj, .tv-node > .tv-array, .tv-node > .tv-inline-list, .tv-node > .tv-chips {
  margin: 4px 0 6px 6px;
  padding-left: 14px;
  border-left: 1px solid var(--border);
}
.tv-array { display: flex; flex-direction: column; gap: 2px; }
.tv-idx {
  display: inline-block;
  min-width: 20px;
  margin-right: 6px;
  text-align: center;
  font-size: 10px;
  color: var(--text-faint);
  background: var(--surface2);
  border-radius: 4px;
}
.tv-term { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.tv-uri { font-family: var(--mono); font-size: 10px; color: var(--text-faint); overflow-wrap: anywhere; }
.tv-ref { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tv-uuid, .tv-num { font-size: 11.5px; }
.tv-empty { color: var(--text-faint); }
.tv-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.tv-inline-list { display: flex; flex-direction: column; gap: 4px; }
.tv-link { overflow-wrap: anywhere; }

/* ── Narrow screens ────────────────────────────────────────────── */
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px 20px; padding: 14px 16px; border-right: 0; border-bottom: 1px solid var(--border-lite); }
  .nav { display: none; }
  .dataset { margin: 0 0 0 auto; padding: 0; border: 0; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
  .dataset .nav-label { display: none; }
  .dataset-meta { margin: 0; }
  .content { padding: 8px 16px 32px; }
  .topbar { padding: 8px 16px 0; }
  .stats { grid-template-columns: 1fr; }
  .tv-row { grid-template-columns: 1fr; gap: 2px; }
  .list-controls #search { width: 100%; }
  .item { flex-direction: column; gap: 6px; }
}
