/* ============================================================
   Design system — tokens
   ============================================================ */
:root {
  --bg: #ffffff;
  --bg-alt: #f5f5f5;
  --bg-panel: #fafafa;
  --border: #e0e0e0;
  --text: #333333;
  --text-mute: #666666;

  --accent: #009b91;
  --accent-strong: #00766f;

  --ai-blind: #7b61ff;
  --ai-enriched: #3d8bff;
  --ai-corrected: #1a3a5f;
  --ground-truth: #5b7c99;

  --ok: #2e8540;
  --warn: #e08a00;
  --err: #c8362d;
  --mute: #9e9e9e;

  --font-stack: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --fs-sm: 14px;
  --fs-base: 16px;
  --fs-md: 18px;
  --fs-lg: 22px;
  --fs-xl: 28px;
  --fs-xxl: 36px;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.08);

  --radius: 4px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --sidebar-w: 280px;
  --header-h: 64px;
}

/* ============================================================
   Reset / base
   ============================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-stack);
  font-size: var(--fs-base);
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}

button {
  font: inherit;
  cursor: pointer;
}

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

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
}

/* ============================================================
   App header
   ============================================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 var(--space-5);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.app-header__brand h1 {
  font-size: var(--fs-lg);
  line-height: 1;
}

.app-header__subtitle {
  margin: 2px 0 0;
  font-size: var(--fs-sm);
  color: var(--text-mute);
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.app-header__actions button {
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: var(--fs-sm);
}
.app-header__actions button:hover:not(:disabled) {
  background: var(--accent-strong);
}
.app-header__actions button:disabled {
  background: var(--mute);
  cursor: not-allowed;
}

/* ============================================================
   Layout
   ============================================================ */
.app-main {
  min-height: calc(100vh - var(--header-h));
}

.view[hidden] {
  display: none;
}

.view--gallery {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--header-h));
}

.view--detail {
  padding: 0;
}

.filter-sidebar {
  padding: var(--space-4) var(--space-5);
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  max-height: calc(100vh - var(--header-h));
  position: sticky;
  top: var(--header-h);
}

.filter-sidebar__placeholder {
  margin: 0;
  color: var(--text-mute);
  font-size: var(--fs-sm);
}

.filter-block {
  margin-bottom: var(--space-5);
}

.filter-block__label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filter-block__input {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  font-size: var(--fs-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.filter-block__input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.filter-block__reset {
  width: 100%;
  padding: 8px 10px;
  font-size: var(--fs-sm);
  background: transparent;
  color: var(--text-mute);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-block__reset:hover {
  color: var(--text);
  background: var(--bg);
}

.filter-checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 0;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.filter-checkbox input {
  margin: 0;
}

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--mute);
}
.status-dot--ok { background: var(--ok); }
.status-dot--warn { background: var(--warn); }
.status-dot--err { background: var(--err); }
.status-dot--mute { background: var(--mute); }

/* ============================================================
   Thesaurus tree
   ============================================================ */
.thesaurus-tree {
  font-size: 13px;
  line-height: 1.3;
}

.thesaurus-tree__node {
  margin: 0;
}

.thesaurus-tree details > summary {
  list-style: none;
  cursor: pointer;
  padding: 3px 4px;
  border-radius: var(--radius);
  user-select: none;
  display: flex;
  align-items: baseline;
  gap: 4px;
  hyphens: auto;
  word-break: normal;
  overflow-wrap: break-word;
}
.thesaurus-tree details > summary::-webkit-details-marker {
  display: none;
}
.thesaurus-tree details > summary:hover {
  background: var(--bg);
}
.thesaurus-tree details > summary::before {
  content: "▸";
  display: inline-block;
  width: 10px;
  flex-shrink: 0;
  font-size: 10px;
  color: var(--text-mute);
  transition: transform 0.1s ease;
}
.thesaurus-tree details[open] > summary::before {
  transform: rotate(90deg);
}
.thesaurus-tree__top-label {
  font-weight: 600;
}
.thesaurus-tree details[open] {
  padding-bottom: 2px;
}
.thesaurus-tree details[open] > .thesaurus-tree__leaf {
  border-left: 1px solid var(--border);
  margin-left: 7px;
}
.thesaurus-tree__leaf {
  display: block;
  padding: 2px 4px 2px 12px;
  cursor: pointer;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-mute);
  font-weight: 400;
  hyphens: auto;
  overflow-wrap: break-word;
}
.thesaurus-tree__leaf:hover {
  background: var(--bg);
  color: var(--accent-strong);
}
.thesaurus-tree__leaf--active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-left-color: var(--accent-strong) !important;
}
.thesaurus-tree__leaf--active:hover {
  background: var(--accent-strong);
  color: #fff;
}
.thesaurus-tree__count {
  margin-left: 4px;
  font-size: 11px;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
}
.thesaurus-tree__leaf--active .thesaurus-tree__count,
.thesaurus-tree__top-label.thesaurus-tree__leaf--active .thesaurus-tree__count {
  color: rgba(255, 255, 255, 0.85);
}

.gallery-section {
  padding: var(--space-5);
}

.gallery-section__header {
  margin-bottom: var(--space-4);
}

.gallery-section__header h2 {
  font-size: var(--fs-md);
  color: var(--text-mute);
  font-weight: 500;
}

/* ============================================================
   Gallery grid
   ============================================================ */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}

.gallery[aria-busy="true"]::before {
  content: "";
}

.gallery__card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
  box-shadow: var(--shadow-card);
}

.gallery__card:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-1px);
}

.gallery__thumb {
  aspect-ratio: 4 / 3;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.gallery__thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.gallery__thumb--missing {
  color: var(--text-mute);
  font-size: var(--fs-sm);
  background: var(--bg-alt);
}

.gallery__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--space-3);
  font-size: var(--fs-sm);
}

.gallery__name {
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text);
}

.gallery__term {
  color: var(--text-mute);
}

.gallery__top {
  margin-top: auto;
  font-size: 12px;
  color: var(--text-mute);
  border-top: 1px solid var(--border);
  padding-top: 6px;
}

/* ============================================================
   Status pill
   ============================================================ */
.status-pill {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  border-radius: 999px;
  background: var(--mute);
}

.status-pill--ok {
  background: var(--ok);
}
.status-pill--warn {
  background: var(--warn);
}
.status-pill--err {
  background: var(--err);
}
.status-pill--mute {
  background: var(--mute);
}

/* ============================================================
   Gallery empty state
   ============================================================ */
.gallery__empty {
  grid-column: 1 / -1;
  color: var(--text-mute);
  font-size: var(--fs-sm);
  padding: var(--space-6) 0;
  text-align: center;
}

/* ============================================================
   Dashboard (Inkrement E)
   ============================================================ */
.dashboard {
  margin-bottom: var(--space-4);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.dashboard__summary {
  cursor: pointer;
  padding: 10px var(--space-4);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
  list-style: none;
  user-select: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.dashboard__summary::-webkit-details-marker {
  display: none;
}

.dashboard__summary::before {
  content: "▸";
  color: var(--text-mute);
  transition: transform 0.1s ease;
}

.dashboard[open] .dashboard__summary::before {
  transform: rotate(90deg);
}

.dashboard__body {
  padding: 0 var(--space-4) var(--space-4);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
}

.dashboard__panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
}

.dashboard__panel h3 {
  margin: 0 0 var(--space-2);
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.dashboard__metric {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  font-size: var(--fs-sm);
}

.dashboard__metric b {
  font-size: var(--fs-lg);
  color: var(--text);
  font-weight: 700;
}

.dashboard__metric span {
  color: var(--text-mute);
}

.dashboard__list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
}

.dashboard__list li {
  padding: 4px 0;
  color: var(--text);
  border-bottom: 1px dashed var(--border);
}

.dashboard__list li:last-child {
  border-bottom: none;
}

.dashboard__empty {
  color: var(--text-mute);
  font-size: var(--fs-sm);
  font-style: italic;
}

.dashboard__metric--hero b {
  font-size: var(--fs-xl);
  color: var(--warn);
}

.dashboard__note {
  margin: 0 0 var(--space-3);
  font-size: var(--fs-sm);
  color: var(--text-mute);
  line-height: 1.45;
}

.dashboard__list li.is-clickable {
  cursor: pointer;
  padding-left: var(--space-2);
  padding-right: var(--space-2);
}

.dashboard__list li.is-clickable:hover {
  background: var(--bg-alt);
  color: var(--accent-strong);
}

/* ============================================================
   Detail page (Inkrement C) — real route, not a drawer
   ============================================================ */
.detail-page {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-5);
}

.detail-page__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.detail-page__back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 12px;
  font-size: var(--fs-sm);
  color: var(--text);
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
}
.detail-page__back:hover {
  background: var(--bg);
  text-decoration: none;
}

.detail-page__title-wrap {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.detail-page__title {
  margin: 0;
  font-size: var(--fs-xl);
  font-weight: 700;
}

.detail-page__meta {
  margin-top: 4px;
  font-size: var(--fs-sm);
  color: var(--text-mute);
}

.detail-page__nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.detail-page__nav button {
  min-width: 36px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  color: var(--text);
  cursor: pointer;
}
.detail-page__nav button:hover:not(:disabled) {
  background: var(--bg-alt);
}
.detail-page__nav button:disabled {
  color: var(--mute);
  cursor: not-allowed;
}

.detail-page__body {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(0, 1.5fr);
  gap: var(--space-5);
}

.detail-page__photo {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  position: sticky;
  top: calc(var(--header-h) + var(--space-4));
  max-height: calc(100vh - var(--header-h) - var(--space-5) * 2);
}

.detail-page__photo img {
  max-width: 100%;
  max-height: calc(100vh - var(--header-h) - var(--space-6) * 2);
  object-fit: contain;
}

.detail-page__variants {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

.variant-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.variant-card--original { border-left-color: var(--ground-truth); }
.variant-card--ai-blind { border-left-color: var(--ai-blind); }
.variant-card--ai-enriched { border-left-color: var(--ai-enriched); }
.variant-card--ai-corrected { border-left-color: var(--ai-corrected); }

.variant-card__header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
}

.variant-card__badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--mute);
  white-space: nowrap;
}
.variant-card__badge--original { background: var(--ground-truth); }
.variant-card__badge--ai-blind { background: var(--ai-blind); }
.variant-card__badge--ai-enriched { background: var(--ai-enriched); }
.variant-card__badge--ai-corrected { background: var(--ai-corrected); }

.variant-card__model {
  font-size: 11px;
  color: var(--text-mute);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.variant-card__subtitle {
  margin: 0 0 var(--space-3);
  font-size: var(--fs-sm);
  color: var(--text-mute);
  font-style: italic;
  line-height: 1.45;
}

.variant-card__field {
  display: flex;
  gap: var(--space-2);
  margin-bottom: 6px;
  font-size: var(--fs-sm);
  line-height: 1.4;
}

.variant-card__field-label {
  flex: 0 0 108px;
  font-weight: 600;
  color: var(--text-mute);
}

.variant-card__field-value {
  flex: 1;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.variant-card__empty {
  font-size: var(--fs-sm);
  color: var(--text-mute);
  font-style: italic;
}

.variant-card__meta {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--border);
  font-size: 11px;
  color: var(--text-mute);
}

.variant-card__hints {
  margin: var(--space-2) 0 0;
  padding-left: var(--space-4);
  font-size: var(--fs-sm);
}

.variant-card__hints li {
  margin-bottom: 4px;
}

.variant-card__quirk {
  margin: 0 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: #fff8e1;
  border-left: 3px solid var(--warn);
  color: #5a4200;
  font-size: var(--fs-sm);
  line-height: 1.4;
}

.match-mark {
  display: inline-block;
  margin-left: 4px;
  font-weight: 700;
}
.match-mark--ok { color: var(--ok); }
.match-mark--err { color: var(--err); }

@media (max-width: 900px) {
  .detail-page__body {
    grid-template-columns: 1fr;
  }
  .detail-page__photo {
    position: static;
    max-height: 50vh;
  }
}

