/* ==========================================================================
   Components: buttons, pills, tags, status, bars, segmented control,
   tooltip, ledger tables, chips, accordion, row highlight, lightbox.
   ========================================================================== */

/* ---------- Buttons ---------- */

.btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2xs);
  min-height: 44px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-2);
  transition:
    transform var(--dur-1) var(--ease-out-quart),
    color var(--dur-1) ease,
    background-color var(--dur-1) ease;
  -webkit-tap-highlight-color: transparent;
}

.btn { padding-inline: var(--space-sm); }

.icon-btn {
  justify-content: center;
  width: 44px;
}

.btn svg,
.icon-btn svg { width: 18px; height: 18px; flex: none; }

.btn:active,
.icon-btn:active,
.chip:active,
.seg-btn:active { transform: scale(0.97); }

@media (hover: hover) and (pointer: fine) {
  .btn:hover,
  .icon-btn:hover { color: var(--text); background: var(--hover-wash); }
}

.btn-quiet {
  min-height: 44px;
  padding-inline: var(--space-sm);
  border: 1px solid var(--line);
  color: var(--text);
}

/* Theme toggle icon swap */
.theme-toggle .i-sun,
.theme-toggle .i-moon { transition: transform var(--dur-3) var(--ease-out-expo), opacity var(--dur-2) ease; }
:root[data-theme="dark"] .theme-toggle .i-moon,
:root[data-theme="light"] .theme-toggle .i-sun { position: absolute; opacity: 0; transform: rotate(-60deg) scale(0.7); }
.theme-toggle { position: relative; }

/* ---------- Pills, tags, status ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  min-height: 32px;
  padding: 0 0.875rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  color: var(--text-2);
}

.pill strong { color: var(--text); font-weight: 600; }

.tag-sample {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.15em 0.6em;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  line-height: 1.4;
  color: var(--text-3);
  white-space: nowrap;
  vertical-align: middle;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
}

.status-live { color: var(--text); }

.status-live::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 3px var(--live-wash);
}

.status-removed {
  padding: 0.1em 0.55em;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.1em 0.55em 0.1em 0.4em;
  border-radius: var(--radius-pill);
  background: var(--accent-wash);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}

.badge svg { width: 10px; height: 10px; color: var(--accent); }

.badge-sample { color: var(--text-3); font-weight: 500; }

.sub {
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap;
}

/* Upvote glyph used inline */
.glyph {
  display: inline-block;
  width: 0.75em;
  height: 0.75em;
  vertical-align: -0.04em;
  color: var(--text-3);
}

/* ---------- Link arrow ---------- */

.arrow {
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  margin-left: 0.3em;
  vertical-align: 0.02em;
  color: var(--text-3);
  transition: transform var(--dur-2) var(--ease-out-expo), color var(--dur-1) ease;
}

@media (hover: hover) and (pointer: fine) {
  a:hover .arrow,
  .row-link:hover .arrow { transform: translate(2px, -2px); color: var(--accent); }
}

a:focus-visible .arrow { color: var(--accent); }

/* ---------- Bars ---------- */

.bar {
  position: relative;
  display: block;
  height: 10px;
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  background: var(--bar-track);
  overflow: hidden;
}

.bar-fill {
  position: absolute;
  inset: 0;
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  background: var(--bone-mid);
  transform-origin: 0 50%;
  transform: scaleX(var(--v, 0));
  transition: transform var(--dur-3) var(--ease-out-quart), background-color var(--dur-2) ease;
}

.is-lead .bar-fill { background: var(--accent); }

.js-motion .bar-fill.is-pending { transform: scaleX(0); }

/* ---------- Segmented control ---------- */

.seg {
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  isolation: isolate;
}

.seg-thumb {
  position: absolute;
  z-index: -1;
  top: 3px;
  bottom: 3px;
  left: 0;
  width: var(--thumb-w, 0px);
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  box-shadow: 0 0 0 1px var(--line-strong);
  transform: translateX(var(--thumb-x, 3px));
  transition: transform var(--dur-2) var(--ease-out-expo), width var(--dur-2) var(--ease-out-expo);
}

.seg-btn {
  min-height: 38px;
  padding-inline: var(--space-sm);
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-3);
  transition: color var(--dur-2) ease, transform var(--dur-1) var(--ease-out-quart);
  white-space: nowrap;
}

.seg-btn[aria-checked="true"] { color: var(--text); }

@media (hover: hover) and (pointer: fine) {
  .seg-btn:hover { color: var(--text); }
}

@media (pointer: coarse) {
  .seg-btn { min-height: 44px; }
}

/* ---------- Tooltip ---------- */

.tip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: var(--z-tip);
  max-width: min(300px, calc(100vw - 24px));
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  box-shadow: var(--shadow-pop);
  font-size: var(--fs-sm);
  line-height: 1.4;
  color: var(--text-2);
  pointer-events: none;
  opacity: 0;
  transform: translate3d(var(--tx, 0), var(--ty, 0), 0) scale(0.97);
  transition:
    opacity var(--dur-1) ease,
    transform var(--dur-1) var(--ease-out-quart);
}

.tip.is-on {
  opacity: 1;
  transform: translate3d(var(--tx, 0), var(--ty, 0), 0);
}

.tip.is-instant { transition-property: opacity; }

.tip-value {
  display: block;
  font-family: var(--font-display);
  font-stretch: 112%;
  font-weight: 750;
  font-size: 1.25rem;
  line-height: 1.1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.tip-title { display: block; margin-top: 4px; color: var(--text); font-weight: 600; }
.tip-meta { display: block; margin-top: 2px; color: var(--text-3); }
.tip-list { list-style: none; padding: 0; margin-top: 6px; display: grid; gap: 6px; }
.tip-list li { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: baseline; }
.tip-list .num { color: var(--text); font-weight: 600; }
.tip-key {
  display: inline-block;
  width: 10px;
  height: 2px;
  margin-right: 6px;
  vertical-align: middle;
  border-radius: 1px;
  background: var(--accent);
}

/* ---------- Shared row highlight (one element that slides) ---------- */

.hl-host { position: relative; isolation: isolate; }

.row-hl {
  position: absolute;
  z-index: -1;
  left: 0;
  right: 0;
  top: 0;
  height: 100px;
  border-radius: var(--radius-sm);
  background: var(--hover-wash);
  transform-origin: 0 0;
  opacity: 0;
  pointer-events: none;
  transition:
    transform var(--dur-2) var(--ease-out-expo),
    opacity var(--dur-2) ease;
}

.row-hl.is-on { opacity: 1; }
.row-hl.is-jump { transition: opacity var(--dur-2) ease; }

/* ---------- Ledger tables ---------- */

.ledger-wrap { position: relative; }

.ledger {
  font-size: var(--fs-sm);
  line-height: 1.4;
}

.ledger th {
  padding: 0 var(--space-xs) var(--space-xs);
  text-align: left;
  vertical-align: bottom;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.ledger td {
  padding: 0.9rem var(--space-xs);
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.ledger th:first-child,
.ledger td:first-child { padding-left: var(--space-2xs); }

.ledger th:last-child,
.ledger td:last-child { padding-right: var(--space-2xs); }

.ledger .is-num { text-align: right; font-variant-numeric: tabular-nums; }
.ledger td.is-num { color: var(--text); font-weight: 500; }
.ledger .is-date { white-space: nowrap; color: var(--text-2); font-variant-numeric: tabular-nums; }

.ledger tbody tr { position: relative; }

.ledger .cell-title a {
  text-decoration: none;
  font-weight: 600;
  color: var(--text);
}

.ledger .cell-title a:hover { text-decoration: underline; text-decoration-color: var(--accent); }

.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  min-height: 32px;
  margin: -6px -6px;
  padding: 0 6px;
  border-radius: var(--radius-xs);
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  transition: color var(--dur-1) ease;
}

.is-num .sort-btn { flex-direction: row-reverse; }

.sort-btn svg {
  width: 9px;
  height: 9px;
  opacity: 0.35;
  transition: transform var(--dur-2) var(--ease-out-expo), opacity var(--dur-1) ease;
}

[aria-sort] .sort-btn { color: var(--text); }
[aria-sort] .sort-btn svg { opacity: 1; color: var(--accent); }
[aria-sort="ascending"] .sort-btn svg { transform: rotate(180deg); }

@media (hover: hover) and (pointer: fine) {
  .sort-btn:hover { color: var(--text); }
  .sort-btn:hover svg { opacity: 0.8; }
}

.ledger-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  flex-wrap: wrap;
  margin-top: var(--space-md);
}

/* ---------- Filter chips ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2xs);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  min-height: 40px;
  padding-inline: 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-2);
  transition:
    color var(--dur-1) ease,
    border-color var(--dur-1) ease,
    background-color var(--dur-1) ease,
    transform var(--dur-1) var(--ease-out-quart);
}

.chip .num { color: var(--text-3); font-weight: 500; }

.chip[aria-pressed="true"] {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.chip[aria-pressed="true"] .num { color: var(--text-2); }

@media (hover: hover) and (pointer: fine) {
  .chip:hover { color: var(--text); border-color: var(--line-strong); }
}

@media (pointer: coarse) {
  .chip { min-height: 44px; }
}

/* ---------- Accordion (collapsed Reddit comment style) ---------- */

.acc { border-top: 1px solid var(--line-soft); }
.acc:last-child { border-bottom: 1px solid var(--line-soft); }

.acc-btn {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-xs);
  width: 100%;
  min-height: 56px;
  padding: var(--space-xs) var(--space-2xs);
  text-align: left;
  color: var(--text-2);
  border-radius: var(--radius-sm);
  transition: background-color var(--dur-1) ease, color var(--dur-1) ease;
}

@media (hover: hover) and (pointer: fine) {
  .acc-btn:hover { background: var(--hover-wash); color: var(--text); }
}

.acc-sign {
  font-family: var(--font-text);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.acc-sign b { display: inline-block; width: 0.7em; text-align: center; color: var(--accent); font-weight: 700; }

.acc-main { min-width: 0; display: grid; gap: 2px; }

.acc-title {
  color: var(--text);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.acc-meta { font-size: var(--fs-sm); color: var(--text-3); }

.acc-count {
  font-size: var(--fs-sm);
  color: var(--text-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.acc-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur-2) var(--ease-out-quart);
}

.acc.is-open .acc-panel { grid-template-rows: 1fr; }

.acc-inner {
  min-height: 0;
  overflow: hidden;
}

.acc-body {
  padding: var(--space-2xs) 0 var(--space-md) calc(var(--space-2xs) + 1.6rem);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity var(--dur-2) ease, transform var(--dur-2) var(--ease-out-quart);
}

.acc.is-open .acc-body { opacity: 1; transform: none; transition-delay: 60ms; }

/* ---------- Capture thumbnails + lightbox ---------- */

.thumb {
  position: relative;
  display: block;
  width: 72px;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-xs);
  overflow: hidden;
  background: var(--serp-page);
  box-shadow: 0 0 0 1px var(--line);
  transition: transform var(--dur-2) var(--ease-out-expo), box-shadow var(--dur-1) ease;
}

.thumb svg,
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top left; }

@media (hover: hover) and (pointer: fine) {
  .thumb:hover { transform: translateY(-2px); box-shadow: 0 0 0 1px var(--line-strong); }
}

.lightbox {
  width: min(960px, calc(100vw - 2 * var(--gutter)));
  max-width: none;
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  color: var(--text);
  box-shadow: var(--shadow-pop);
  overflow: auto;
}

.lightbox::backdrop {
  background: oklch(0.1 0.006 50 / 0.72);
}

.lightbox[open] { animation: lb-in var(--dur-2) var(--ease-out-expo); }
.lightbox[open]::backdrop { animation: fade-in var(--dur-2) ease; }
.lightbox.no-anim[open] { animation: none; }

@keyframes lb-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes fade-in { from { opacity: 0; } }

.lb-figure { display: grid; }

.lb-media {
  background: var(--serp-page);
  border-bottom: 1px solid var(--line);
}

.lb-media svg,
.lb-media img { width: 100%; height: auto; }

.lb-caption {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-sm);
  align-items: start;
  padding: var(--space-md);
}

.lb-query {
  font-family: var(--font-display);
  font-stretch: 112%;
  font-weight: 750;
  font-size: var(--fs-lg);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.lb-meta { margin-top: 6px; color: var(--text-2); font-size: var(--fs-sm); }

.lb-controls { display: flex; gap: 4px; }

.lb-controls .icon-btn { border: 1px solid var(--line); }
