/* ── sphinx_autodoc_pytest_fixtures ────────────────────────
 * Multi-badge group: scope + kind/state + FIXTURE
 * Three slots, hard ceiling: at most 3 badges per fixture.
 *
 * Slot 1 (scope):  session=amber, module=teal, class=slate
 *                  function → suppressed (absence = function-scope)
 * Slot 2 (kind):   factory=amber/brown, override_hook=violet
 *                  resource → suppressed (default, no badge needed)
 *   OR state:      autouse=rose (replaces kind when autouse=True)
 * Slot 3 (base):   FIXTURE — always shown, green
 *
 * Uses nodes.inline (portable across all Sphinx builders).
 * Class-based selectors replace data-* attribute selectors.
 * Flex layout replaces float with mobile-responsive wrapping.
 * ────────────────────────────────────────────────────────── */

/* Token system */
:root {
  /* Base FIXTURE badge — outlined green.  7.2:1 fg-on-bg (WCAG AA+AAA) */
  --spf-fixture-bg:     #e6f7ed;
  --spf-fixture-fg:     #1a5c2e;
  --spf-fixture-border: #3aad65;

  /* Scope: session — amber/gold.  6.2:1 fg-on-bg (WCAG AA) */
  --spf-scope-session-bg:     #fff3cd;
  --spf-scope-session-fg:     #7a5200;
  --spf-scope-session-border: #d4a017;

  /* Scope: module — teal.  6.7:1 fg-on-bg (WCAG AA) */
  --spf-scope-module-bg:     #e0f4f4;
  --spf-scope-module-fg:     #1a5c5c;
  --spf-scope-module-border: #3aabab;

  /* Scope: class — slate.  9.3:1 fg-on-bg (WCAG AA+AAA) */
  --spf-scope-class-bg:     #eeedf6;
  --spf-scope-class-fg:     #3c3670;
  --spf-scope-class-border: #7b76c0;

  /* Kind: factory — amber/brown (outlined).  8.1:1 fg-on-white (WCAG AA+AAA) */
  --spf-kind-factory-bg:     transparent;
  --spf-kind-factory-fg:     #7a4200;
  --spf-kind-factory-border: #c87f35;

  /* Kind: override_hook — violet (outlined).  11.3:1 fg-on-white (WCAG AA+AAA) */
  --spf-kind-override-bg:     transparent;
  --spf-kind-override-fg:     #5a1a7a;
  --spf-kind-override-border: #9b59c8;

  /* State: autouse — rose (outlined).  10.5:1 fg-on-white (WCAG AA+AAA) */
  --spf-state-autouse-bg:     transparent;
  --spf-state-autouse-fg:     #7a1a2a;
  --spf-state-autouse-border: #c85070;

  /* State: deprecated — muted red/grey (outlined).  8.5:1 fg-on-white */
  --spf-deprecated-bg:     transparent;
  --spf-deprecated-fg:     #8a4040;
  --spf-deprecated-border: #c07070;

  /* Shared badge metrics */
  --spf-badge-font-size: 0.67rem;
  --spf-badge-padding-v: 0.16rem;
  --spf-badge-border-w:  1px;
}

/* Dark mode — OS-level */
@media (prefers-color-scheme: dark) {
  body:not([data-theme="light"]) {
    --spf-fixture-bg:     #0d2e1a;
    --spf-fixture-fg:     #70dd90;
    --spf-fixture-border: #309050;

    --spf-scope-session-bg:     #3a2800;
    --spf-scope-session-fg:     #f5d580;
    --spf-scope-session-border: #c89030;

    --spf-scope-module-bg:     #0d2a2a;
    --spf-scope-module-fg:     #70dddd;
    --spf-scope-module-border: #309090;

    --spf-scope-class-bg:     #1a1838;
    --spf-scope-class-fg:     #b0acee;
    --spf-scope-class-border: #6060b0;

    --spf-kind-factory-fg:     #f0b060;
    --spf-kind-factory-border: #d08040;

    --spf-kind-override-fg:     #d090f0;
    --spf-kind-override-border: #a060d0;

    --spf-state-autouse-fg:     #f080a0;
    --spf-state-autouse-border: #d05070;

    --spf-deprecated-fg:     #e08080;
    --spf-deprecated-border: #c06060;
  }
}

/* Furo explicit dark toggle — must match OS-dark block above */
body[data-theme="dark"] {
  --spf-fixture-bg:     #0d2e1a;  /* 8.7:1 with fg #70dd90 */
  --spf-fixture-fg:     #70dd90;
  --spf-fixture-border: #309050;

  --spf-scope-session-bg:     #3a2800;
  --spf-scope-session-fg:     #f5d580;
  --spf-scope-session-border: #c89030;

  --spf-scope-module-bg:     #0d2a2a;
  --spf-scope-module-fg:     #70dddd;
  --spf-scope-module-border: #309090;

  --spf-scope-class-bg:     #1a1838;
  --spf-scope-class-fg:     #b0acee;
  --spf-scope-class-border: #6060b0;

  --spf-kind-factory-fg:     #f0b060;
  --spf-kind-factory-border: #d08040;

  --spf-kind-override-fg:     #d090f0;
  --spf-kind-override-border: #a060d0;

  --spf-state-autouse-fg:     #f080a0;
  --spf-state-autouse-border: #d05070;

  --spf-deprecated-fg:     #e08080;
  --spf-deprecated-border: #c06060;
}

/* "fixture" keyword prefix — keep Furo's default keyword colour */
dl.py.fixture > dt em.property {
  color: var(--color-api-keyword);
  font-style: normal;
}

/* Badge group container — flex layout for reliable multi-badge alignment.
 * Flexbox replaces the float: right approach; the dt becomes a flex row
 * (signature text + badge group side by side).
 * On narrow viewports the badge group wraps below the signature. */
dl.py.fixture > dt {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  background: var(--color-background-secondary);
  border-bottom: 1px solid var(--color-background-border);
  padding: 0.5rem 0.75rem;
}

/* Visual reorder: sig elements (0) → ¶ (1) → badges (2) → [source] (3).
 * The ¶ headerlink is injected by Sphinx's HTML translator AFTER our
 * doctree code runs, so CSS order is the only way to position it. */
dl.py.fixture > dt > .headerlink          { order: 1; }
dl.py.fixture > dt > .spf-badge-group { order: 2; }
dl.py.fixture > dt > a.reference.external { order: 3; }

dl.py.fixture > dt .spf-badge-group {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
  margin-left: auto;
  white-space: nowrap;
  text-indent: 0;
}

/* Mobile: badge group wraps below signature text, shares row with actions */
@media (max-width: 52rem) {
  dl.py.fixture > dt .spf-badge-group {
    margin-left: 0;
    white-space: normal;
    flex-wrap: wrap;
  }
  dl.py.fixture > dt .spf-badge {
    --spf-badge-font-size: 0.75rem;
  }
}

/* Shared badge base — component-scoped.
 * Applies wherever .spf-badge appears: fixture cards, index tables, or any
 * future context.  Context-specific layout rules (flex container, tooltip
 * positioning anchor, margin-left: auto in dt) remain on their containers. */
.spf-badge {
  position: relative;  /* positioning context for the CSS-only tooltip */
  display: inline-block;
  font-size: var(--spf-badge-font-size, 0.67rem);
  font-weight: 650;
  line-height: normal;
  letter-spacing: 0.01em;
  padding: var(--spf-badge-padding-v, 0.16rem) 0.5rem;
  border-radius: 0.22rem;
  border: var(--spf-badge-border-w, 1px) solid;
  vertical-align: middle;
}

/* Touch/keyboard tooltip — shows on focus (touch tap focuses the element).
 * Sphinx's <abbr title> tooltips are invisible on touch devices; this CSS-only
 * solution renders the title text as a positioned pseudo-element on :focus.
 * Works in both fixture cards and index table cells since .spf-badge carries
 * position: relative as the tooltip's containing block. */
.spf-badge[tabindex]:focus::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-background-primary);
  border: 1px solid var(--color-background-border);
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 400;
  white-space: nowrap;
  border-radius: 0.2rem;
  z-index: 10;
  pointer-events: none;
}

/* Restore visible focus outline for keyboard users. The tooltip still appears
 * on any :focus, but the ring only appears for :focus-visible (keyboard nav). */
.spf-badge[tabindex]:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}

/* FIXTURE badge (always shown, outlined green — same visual treatment
 * as scope badges: light bg, dark text, colored border) */
.spf-badge--fixture {
  background-color: var(--spf-fixture-bg);
  color: var(--spf-fixture-fg);
  border-color: var(--spf-fixture-border);
}

/* Scope badges — component-scoped (replaces data-* attribute selectors) */
.spf-scope-session {
  background-color: var(--spf-scope-session-bg);
  color: var(--spf-scope-session-fg);
  border-color: var(--spf-scope-session-border);
  letter-spacing: 0.03em;
}
.spf-scope-module {
  background-color: var(--spf-scope-module-bg);
  color: var(--spf-scope-module-fg);
  border-color: var(--spf-scope-module-border);
}
.spf-scope-class {
  background-color: var(--spf-scope-class-bg);
  color: var(--spf-scope-class-fg);
  border-color: var(--spf-scope-class-border);
}

/* Kind badges (outlined — behaviour, not lifecycle) */
.spf-factory {
  background-color: var(--spf-kind-factory-bg);
  color: var(--spf-kind-factory-fg);
  border-color: var(--spf-kind-factory-border);
}
.spf-override {
  background-color: var(--spf-kind-override-bg);
  color: var(--spf-kind-override-fg);
  border-color: var(--spf-kind-override-border);
}

/* State badge (autouse) */
.spf-autouse {
  background-color: var(--spf-state-autouse-bg);
  color: var(--spf-state-autouse-fg);
  border-color: var(--spf-state-autouse-border);
}

/* Deprecated badge — component-scoped; card muting stays dt-scoped */
.spf-deprecated {
  background-color: var(--spf-deprecated-bg);
  color: var(--spf-deprecated-fg);
  border-color: var(--spf-deprecated-border);
}

/* ── abbr[title] specificity fix ───────────────────────────────────────
 * Normalize.css (bundled with Furo) sets on abbr[title]:
 *   border-bottom: none          — removes bottom border entirely
 *   text-decoration: underline dotted — adds unwanted dotted underline
 * Specificity of abbr[title] is (0,1,1) which beats .spf-badge (0,1,0),
 * so the bottom border is trimmed and the underline bleeds through.
 *
 * Fix: use abbr.spf-badge (0,1,1) to win on source order.
 * The border-color reset by abbr[title] also needs per-variant overrides
 * at the same specificity, otherwise the bottom border colour falls back
 * to currentColor (the text fg colour) instead of the border variable.
 * ─────────────────────────────────────────────────────────────────────── */
abbr.spf-badge {
  border-bottom-style: solid;
  border-bottom-width: var(--spf-badge-border-w, 1px);
  text-decoration: underline dotted;
}
abbr.spf-badge--fixture { border-color: var(--spf-fixture-border); }
abbr.spf-scope-session  { border-color: var(--spf-scope-session-border); }
abbr.spf-scope-module   { border-color: var(--spf-scope-module-border); }
abbr.spf-scope-class    { border-color: var(--spf-scope-class-border); }
abbr.spf-factory        { border-color: var(--spf-kind-factory-border); }
abbr.spf-override       { border-color: var(--spf-kind-override-border); }
abbr.spf-autouse        { border-color: var(--spf-state-autouse-border); }
abbr.spf-deprecated     { border-color: var(--spf-deprecated-border); }

dl.py.fixture.spf-deprecated > dt {
  opacity: 0.7;
}

/* Badge group inside fixture index table cell — keep badges inline.
 * The card context has its own dl.py.fixture > dt .spf-badge-group rule
 * (with margin-left: auto and flex layout tied to the dt flex row).
 * Table cells need a simpler inline-flex without the card-specific overrides. */
.spf-fixture-index .spf-badge-group {
  display: inline-flex;
  gap: 0.3rem;
}

/* Suppress module prefix (libtmux.pytest_plugin.) */
dl.py.fixture > dt .sig-prename.descclassname {
  display: none;
}

/* ── Fixture card treatment ──────────────────────────────── */
dl.py.fixture {
  border: 1px solid var(--color-background-border);
  border-radius: 0.5rem;
  padding: 0;
  margin-bottom: 1.5rem;
  overflow: visible;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* Reset Furo's hanging-indent and negative-margin on dt so content
 * stays within the card border.  Furo sets text-indent: -35px and
 * margin: 0 -4px for wrapped signatures — both break our flex card.
 * !important on padding overrides Furo's .sig:not(.sig-inline) rule which
 * sets padding-top/bottom: 0.25rem and wins on specificity without it. */
dl.py.fixture > dt {
  text-indent: 0;
  margin: 0;
  padding-left: 1rem;
  padding-top: 0.5rem !important;
  padding-bottom: 0.5rem !important;
  min-height: 2rem;
}

dl.py.fixture > dd {
  padding: 0.75rem 1rem;
  margin-left: 0 !important;  /* override Furo's dd { margin-left: 32px } */
}

/* Metadata fields: compact grid that keeps dt/dd pairs together */
dl.py.fixture > dd > dl.field-list {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.25rem 1rem;
  border-top: 1px solid var(--color-background-border);
  padding-top: 0.5rem;
  margin-top: 0.5rem;
}
dl.py.fixture > dd > dl.field-list > dt {
  grid-column: 1;
  font-weight: normal;
  text-transform: uppercase;
  font-size: 0.85em;
  letter-spacing: 0.025em;
}
dl.py.fixture > dd > dl.field-list > dt .colon { display: none; }
dl.py.fixture > dd > dl.field-list > dd { grid-column: 2; margin-left: 0; }

/* Mobile: metadata fields stack to single column */
@media (max-width: 52rem) {
  dl.py.fixture > dd > dl.field-list {
    grid-template-columns: 1fr;
  }
  dl.py.fixture > dd > dl.field-list > dt,
  dl.py.fixture > dd > dl.field-list > dd {
    grid-column: 1;
  }
}

/* Suppress Rtype field-list on fixtures — return type is already in the
 * signature (→ Type).  sphinx_autodoc_typehints emits a separate field-list
 * with only "Rtype:" when autodoc_typehints = "description". Hide it. */
dl.py.fixture > dd > dl.field-list + dl.field-list {
  display: none;
}

/* Horizontal scroll wrapper for the fixture index table on narrow viewports */
.spf-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.spf-table-scroll table {
  min-width: 40rem;
  width: 100%;
}
