/* src/web/static/css/character_appearances.css
   Styling for the "Appearances" section on /character/<slug>
   (_character_appearances.html + character_appearances_component.js).
   Reuses the app's shared theme tokens (theme.css) so the section stays
   consistent across light/dark and the oklch palette variants. */

.char-appearances {
  margin: 1.75rem 0;
  padding: 1.25rem 1.5rem 1.5rem;
  background: var(--surface-2, #f5f5f5);
  border: 1px solid var(--border, #ddd);
  border-radius: 12px;
}

.char-appearances .ca-head {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  margin-bottom: 1rem;
}

.char-appearances .ca-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

/* --- completion meter --- */

.char-appearances .ca-meter {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .35rem .75rem;
}

.char-appearances .ca-bar {
  --ca-pct: 0%;
  flex: 0 0 min(220px, 100%);
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in srgb, var(--text-muted, #888) 22%, transparent);
}

.char-appearances .ca-bar-fill {
  height: 100%;
  width: var(--ca-pct);
  min-width: 2px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-recent, #00939c), var(--brand, #7e59c7));
  transition: width .25s ease;
}

.char-appearances .ca-pct {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.char-appearances .ca-sub {
  color: var(--text-muted, #888);
  font-size: .88rem;
}

.char-appearances .ca-untracked {
  flex-basis: 100%;
  color: var(--text-dim, #999);
  font-size: .8rem;
  font-style: italic;
}

/* --- reading-order copy CTA --- */

.char-appearances .ca-order-cta {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.char-appearances .ca-create-order {
  appearance: none;
  border: 1px solid var(--border, #ddd);
  background: var(--surface, #fff);
  color: var(--text-muted, #888);
  font-size: .82rem;
  font-weight: 600;
  line-height: 1;
  padding: .4rem .85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.char-appearances .ca-create-order:hover {
  border-color: var(--brand, #7e59c7);
  color: var(--text);
}

.char-appearances .ca-create-order:disabled {
  opacity: .5;
  cursor: default;
}

.char-appearances .ca-order-cta a {
  color: var(--brand, #7e59c7);
  font-size: .85rem;
  font-weight: 600;
  text-decoration: none;
}

.char-appearances .ca-order-cta a:hover {
  text-decoration: underline;
}

/* The export control is an <a> wearing the .ca-create-order pill, so it needs
   the anchor bits that rule (written for a <button>) does not carry. No
   colours here on purpose: the pill's palette stays in one place. */
.char-appearances .ca-export {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

/* --- sticky control strip: role filters + decade facets --- */

/* One sticky wrapper around both chip rows. The sticky rule must NOT live on
   .ca-filters itself -- the decade row reuses that class for chip styling, so
   both rows would pin at the same offset and stack on top of each other. */
.char-appearances .ca-controls {
  position: sticky;
  top: var(--nav-h);
  z-index: 3;
  /* matches .char-appearances' own card background (--surface-2), not the
     page background: rows scroll under this strip and must not show through */
  background: var(--surface-2, #f5f5f5);
  padding: .75rem 0 .5rem;
  margin-bottom: 1rem;
  /* The wrapper owns the gap BETWEEN rows via flex `gap`, not a per-row
     margin-bottom. x-show hides the decade row with `display: none`, which
     removes it from flex layout entirely -- so `gap` naturally contributes
     nothing when it's hidden, unlike a `:last-child` margin override (which
     never applied, since the hidden row was still there in the DOM). */
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

/* Zero out the base .ca-filters margin-bottom (below) inside the controls
   wrapper -- spacing between rows comes from the wrapper's `gap` instead. */
.char-appearances .ca-controls .ca-filters {
  margin-bottom: 0;
}

/* One line, always. Nine decade chips plus the role row would wrap into
   3-4 rows of pinned chrome on a phone; scroll sideways instead.
   Selector must be `.ca-filters.ca-decades`, not just `.ca-decades`: the
   element carries BOTH classes (it reuses .ca-filters for chip styling),
   so a bare `.char-appearances .ca-decades` ties on specificity with
   `.char-appearances .ca-filters` below (2 classes each) -- the later rule
   in source order (`.ca-filters { flex-wrap: wrap }`) would win the cascade
   and silently wrap the row on narrow viewports. Chaining both classes here
   makes this rule strictly more specific so it always wins regardless of
   source order. */
.char-appearances .ca-filters.ca-decades {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
}

/* Chained for the same reason as the `.ca-filters.ca-decades` rule above:
   a bare `.char-appearances .ca-decades button` ties on specificity with
   `.char-appearances .ca-filters button` below and loses on source order.
   Not live today (no `.ca-filters button` rule sets `flex` yet), but the
   next flex property added there would silently win and un-fix this. */
.char-appearances .ca-filters.ca-decades button {
  flex: none;
}

.char-appearances .ca-decade-count {
  margin-left: .35rem;
  opacity: .65;
  font-variant-numeric: tabular-nums;
}

/* --- role filters (segmented pill control) --- */

.char-appearances .ca-filters {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: 1rem;
}

.char-appearances .ca-filters button {
  appearance: none;
  border: 1px solid var(--border, #ddd);
  background: var(--surface, #fff);
  color: var(--text-muted, #888);
  font-size: .82rem;
  font-weight: 600;
  line-height: 1;
  padding: .4rem .85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.char-appearances .ca-filters button:hover {
  border-color: var(--brand, #7e59c7);
  color: var(--text);
}

.char-appearances .ca-filters button.active {
  background: var(--brand, #7e59c7);
  border-color: var(--brand, #7e59c7);
  color: #fff;
}

/* --- appearance list --- */

.char-appearances .ca-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border, #ddd);
}

.char-appearances .ca-list li {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .1rem .6rem;
  padding: .55rem .25rem;
  border-bottom: 1px solid var(--border, #ddd);
  font-size: .92rem;
}

.char-appearances .ca-list li.owned {
  position: relative;
  padding-left: 1.1rem;
}

.char-appearances .ca-list li.owned::before {
  content: "\2713";
  position: absolute;
  left: 0;
  color: var(--accent-recent, #00939c);
  font-weight: 700;
}

.char-appearances .ca-list li.untrackable {
  color: var(--text-dim, #999);
  opacity: .7;
}

.char-appearances .ca-title {
  color: var(--text);
  font-weight: 600;
}

.char-appearances .ca-list li.untrackable .ca-title {
  color: inherit;
  font-weight: 500;
}

.char-appearances .ca-year {
  color: var(--text-muted, #888);
  font-size: .85rem;
}

.char-appearances .ca-tag {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .02em;
  color: var(--text-muted, #888);
  background: color-mix(in srgb, var(--text-muted, #888) 14%, transparent);
  border-radius: 999px;
  padding: .12rem .5rem;
}

/* --- load more --- */

.char-appearances .ca-more {
  display: block;
  margin: 1rem auto 0;
  appearance: none;
  border: 1px solid var(--border, #ddd);
  background: transparent;
  color: var(--text-muted, #888);
  font-size: .85rem;
  font-weight: 600;
  padding: .5rem 1.25rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.char-appearances .ca-more:hover {
  border-color: var(--brand, #7e59c7);
  color: var(--text);
}

.char-appearances .ca-sentinel {
  height: 1px;
}

.char-appearances .ca-more:disabled {
  cursor: default;
  opacity: .6;
}

/* --- loading state --- */

/* Inline "Loading appearances…" label in the head. .skel-spinner and the
   skel-sheen used by the ghost rows below both come from the globally-bundled
   skeleton.css, so no extra include or bundle rebuild is needed. */
.char-appearances .ca-loading {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  color: var(--text-muted, #888);
  font-size: .88rem;
}

/* Ghost rows reuse the real .ca-list li geometry (border, padding). Center the
   line + pill and drop the skeleton primitives' default margins so each ghost
   row sits at the same height as a real single-line appearance. */
.char-appearances .ca-list--skeleton li {
  align-items: center;
}

.char-appearances .ca-list--skeleton .skel-line,
.char-appearances .ca-list--skeleton .skel-pill {
  margin: 0;
}

.char-appearances .ca-skel-year {
  width: 2.75rem;
}

/* --- chronological-mode divider --- */

/* The row before the first appearance that has no Chronology Project
   position. A list row, not a heading, so keyboard and screen-reader list
   counts stay honest. */
.char-appearances .ca-list li.ca-divider {
  display: block;
  padding: 0.6rem 0 0.2rem;
  border-bottom: none;
}

.char-appearances .ca-divider-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.65;
}

/* Collected-line overlay. The label carries the shared .cc-chip primitive in
   markup; .ca-line-label only adjusts its scale -- same thin-extension pattern
   as .omni-chip in omnis.css.

   The modifier is deliberately NOT named *-chip: audit_css_building_blocks
   counts any class ending -btn/-button/-card/-chip/-pill/-toolbar/-empty/
   -loading/-panel/-surface outside the cc-/pm-/skel- prefixes as a new local
   primitive, and test_tta79_frontend_gate_closeout ceilings that inventory at
   246 -- which is exactly where it sits today. Zero headroom: one *-chip class
   here turns the gate red. Do not rename it back, and do not raise the ceiling. */
.ca-lens { align-items: center; gap: .4rem; }
.ca-lens-label { color: var(--text-dim); font-size: .85rem; }
.ca-lens-counts { color: var(--text-dim); font-size: .85rem; margin: .25rem 0 0; }
.ca-lens-error { color: var(--text-dim); font-size: .85rem; margin: .25rem 0 0; }
.ca-line { display: inline-flex; align-items: center; gap: .3rem; margin-left: .5rem; }
.ca-line-label { font-size: .8rem; padding: .1rem .5rem; }
.ca-line-absent { color: var(--text-dim); font-size: .8rem; font-style: italic; }
.ca-line-more {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: .75rem;
  padding: 0 .4rem;
}
.ca-line-more:hover { color: var(--text); border-color: var(--border-strong); }
/* The expanded +N region: the other books in the same line. */
.ca-line-extras {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  list-style: none;
  margin: .25rem 0 0;
  padding: 0 0 0 .5rem;
  width: 100%;
}

/* theme.css gives .cc-chip a 44px mobile tap target. The line label is an
   inline annotation inside a text row, not a tap target of its own, so that
   height would inflate every appearance row on a phone. Two classes beat
   theme.css's single .cc-chip regardless of stylesheet order. */
@media (max-width: 640px) {
  .char-appearances .ca-line-label { min-height: 0; }
}
