/* ── sphinx_autodoc_api_style ─────────────────────────────
 * Badge system for Python API entries: functions, classes,
 * methods, properties, attributes, data, exceptions.
 *
 * Uses the `gas-` prefix (gp-sphinx api style) to avoid
 * collision with `spf-` (sphinx pytest fixtures).
 *
 * Design language matches sphinx_autodoc_pytest_fixtures:
 * same badge metrics, border radius, tooltip pattern,
 * card treatment, and Furo integration.
 * ────────────────────────────────────────────────────────── */

/* ── Token system ──────────────────────────────────────── */
:root {
  /* Type: function — blue */
  --gas-type-function-bg:     #e8f0fe;
  --gas-type-function-fg:     #1a56db;
  --gas-type-function-border: #3b82f6;

  /* Type: class — indigo */
  --gas-type-class-bg:     #eef2ff;
  --gas-type-class-fg:     #4338ca;
  --gas-type-class-border: #6366f1;

  /* Type: method — cyan */
  --gas-type-method-bg:     #ecfeff;
  --gas-type-method-fg:     #0e7490;
  --gas-type-method-border: #06b6d4;

  /* Type: property — teal */
  --gas-type-property-bg:     #f0fdfa;
  --gas-type-property-fg:     #0f766e;
  --gas-type-property-border: #14b8a6;

  /* Type: attribute — slate */
  --gas-type-attribute-bg:     #f1f5f9;
  --gas-type-attribute-fg:     #475569;
  --gas-type-attribute-border: #94a3b8;

  /* Type: data — neutral grey */
  --gas-type-data-bg:     #f5f5f5;
  --gas-type-data-fg:     #525252;
  --gas-type-data-border: #a3a3a3;

  /* Type: exception — rose/red */
  --gas-type-exception-bg:     #fff1f2;
  --gas-type-exception-fg:     #be123c;
  --gas-type-exception-border: #f43f5e;

  /* Type: type alias — violet */
  --gas-type-type-bg:     #f5f3ff;
  --gas-type-type-fg:     #6d28d9;
  --gas-type-type-border: #8b5cf6;

  /* Modifier: async — purple (outlined) */
  --gas-mod-async-fg:     #7c3aed;
  --gas-mod-async-border: #a78bfa;

  /* Modifier: classmethod — amber (outlined) */
  --gas-mod-classmethod-fg:     #b45309;
  --gas-mod-classmethod-border: #f59e0b;

  /* Modifier: staticmethod — cool grey (outlined) */
  --gas-mod-staticmethod-fg:     #475569;
  --gas-mod-staticmethod-border: #94a3b8;

  /* Modifier: abstract — indigo (outlined) */
  --gas-mod-abstract-fg:     #4338ca;
  --gas-mod-abstract-border: #818cf8;

  /* Modifier: final — emerald (outlined) */
  --gas-mod-final-fg:     #047857;
  --gas-mod-final-border: #34d399;

  /* Modifier: deprecated — muted red/grey (matches spf-deprecated) */
  --gas-deprecated-bg:     transparent;
  --gas-deprecated-fg:     #8a4040;
  --gas-deprecated-border: #c07070;

  /* Shared badge metrics — match fixture extension */
  --gas-badge-font-size: 0.67rem;
  --gas-badge-padding-v: 0.16rem;
  --gas-badge-border-w:  1px;
}

/* ── Dark mode (OS-level) ──────────────────────────────── */
@media (prefers-color-scheme: dark) {
  body:not([data-theme="light"]) {
    --gas-type-function-bg:     #172554;
    --gas-type-function-fg:     #93c5fd;
    --gas-type-function-border: #3b82f6;

    --gas-type-class-bg:     #1e1b4b;
    --gas-type-class-fg:     #a5b4fc;
    --gas-type-class-border: #6366f1;

    --gas-type-method-bg:     #083344;
    --gas-type-method-fg:     #67e8f9;
    --gas-type-method-border: #22d3ee;

    --gas-type-property-bg:     #042f2e;
    --gas-type-property-fg:     #5eead4;
    --gas-type-property-border: #2dd4bf;

    --gas-type-attribute-bg:     #1e293b;
    --gas-type-attribute-fg:     #cbd5e1;
    --gas-type-attribute-border: #64748b;

    --gas-type-data-bg:     #262626;
    --gas-type-data-fg:     #d4d4d4;
    --gas-type-data-border: #737373;

    --gas-type-exception-bg:     #4c0519;
    --gas-type-exception-fg:     #fda4af;
    --gas-type-exception-border: #fb7185;

    --gas-type-type-bg:     #2e1065;
    --gas-type-type-fg:     #c4b5fd;
    --gas-type-type-border: #a78bfa;

    --gas-mod-async-fg:     #c4b5fd;
    --gas-mod-async-border: #8b5cf6;

    --gas-mod-classmethod-fg:     #fcd34d;
    --gas-mod-classmethod-border: #f59e0b;

    --gas-mod-staticmethod-fg:     #cbd5e1;
    --gas-mod-staticmethod-border: #64748b;

    --gas-mod-abstract-fg:     #a5b4fc;
    --gas-mod-abstract-border: #818cf8;

    --gas-mod-final-fg:     #6ee7b7;
    --gas-mod-final-border: #34d399;

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

/* ── Furo explicit dark toggle ─────────────────────────── */
body[data-theme="dark"] {
  --gas-type-function-bg:     #172554;
  --gas-type-function-fg:     #93c5fd;
  --gas-type-function-border: #3b82f6;

  --gas-type-class-bg:     #1e1b4b;
  --gas-type-class-fg:     #a5b4fc;
  --gas-type-class-border: #6366f1;

  --gas-type-method-bg:     #083344;
  --gas-type-method-fg:     #67e8f9;
  --gas-type-method-border: #22d3ee;

  --gas-type-property-bg:     #042f2e;
  --gas-type-property-fg:     #5eead4;
  --gas-type-property-border: #2dd4bf;

  --gas-type-attribute-bg:     #1e293b;
  --gas-type-attribute-fg:     #cbd5e1;
  --gas-type-attribute-border: #64748b;

  --gas-type-data-bg:     #262626;
  --gas-type-data-fg:     #d4d4d4;
  --gas-type-data-border: #737373;

  --gas-type-exception-bg:     #4c0519;
  --gas-type-exception-fg:     #fda4af;
  --gas-type-exception-border: #fb7185;

  --gas-type-type-bg:     #2e1065;
  --gas-type-type-fg:     #c4b5fd;
  --gas-type-type-border: #a78bfa;

  --gas-mod-async-fg:     #c4b5fd;
  --gas-mod-async-border: #8b5cf6;

  --gas-mod-classmethod-fg:     #fcd34d;
  --gas-mod-classmethod-border: #f59e0b;

  --gas-mod-staticmethod-fg:     #cbd5e1;
  --gas-mod-staticmethod-border: #64748b;

  --gas-mod-abstract-fg:     #a5b4fc;
  --gas-mod-abstract-border: #818cf8;

  --gas-mod-final-fg:     #6ee7b7;
  --gas-mod-final-border: #34d399;

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

/* ── Signature flex layout ─────────────────────────────── */
dl.py:not(.fixture) > dt {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

/* ── Toolbar: badges + [source] ────────────────────────── */
dl.py:not(.fixture) > dt .gas-toolbar {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  margin-left: auto;
  white-space: nowrap;
  text-indent: 0;
  order: 99;
}

dl.py:not(.fixture) > dt .gas-badge-group {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
}

/* ── Shared badge base ─────────────────────────────────── */
.gas-badge {
  position: relative;
  display: inline-block;
  font-size: var(--gas-badge-font-size, 0.67rem);
  font-weight: 700;
  line-height: normal;
  letter-spacing: 0.01em;
  padding: var(--gas-badge-padding-v, 0.16rem) 0.5rem;
  border-radius: 0.22rem;
  border: var(--gas-badge-border-w, 1px) solid;
  vertical-align: middle;
}

/* Touch/keyboard tooltip */
.gas-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;
}

.gas-badge[tabindex]:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}

/* ── Type badges (filled) ──────────────────────────────── */
.gas-type-function {
  background-color: var(--gas-type-function-bg);
  color: var(--gas-type-function-fg);
  border-color: var(--gas-type-function-border);
}

.gas-type-class {
  background-color: var(--gas-type-class-bg);
  color: var(--gas-type-class-fg);
  border-color: var(--gas-type-class-border);
}

.gas-type-method,
.gas-type-classmethod,
.gas-type-staticmethod {
  background-color: var(--gas-type-method-bg);
  color: var(--gas-type-method-fg);
  border-color: var(--gas-type-method-border);
}

.gas-type-property {
  background-color: var(--gas-type-property-bg);
  color: var(--gas-type-property-fg);
  border-color: var(--gas-type-property-border);
}

.gas-type-attribute {
  background-color: var(--gas-type-attribute-bg);
  color: var(--gas-type-attribute-fg);
  border-color: var(--gas-type-attribute-border);
}

.gas-type-data {
  background-color: var(--gas-type-data-bg);
  color: var(--gas-type-data-fg);
  border-color: var(--gas-type-data-border);
}

.gas-type-exception {
  background-color: var(--gas-type-exception-bg);
  color: var(--gas-type-exception-fg);
  border-color: var(--gas-type-exception-border);
}

.gas-type-type {
  background-color: var(--gas-type-type-bg);
  color: var(--gas-type-type-fg);
  border-color: var(--gas-type-type-border);
}

/* ── Modifier badges (outlined, transparent bg) ────────── */
.gas-mod-async {
  background-color: transparent;
  color: var(--gas-mod-async-fg);
  border-color: var(--gas-mod-async-border);
}

.gas-mod-classmethod {
  background-color: transparent;
  color: var(--gas-mod-classmethod-fg);
  border-color: var(--gas-mod-classmethod-border);
}

.gas-mod-staticmethod {
  background-color: transparent;
  color: var(--gas-mod-staticmethod-fg);
  border-color: var(--gas-mod-staticmethod-border);
}

.gas-mod-abstract {
  background-color: transparent;
  color: var(--gas-mod-abstract-fg);
  border-color: var(--gas-mod-abstract-border);
}

.gas-mod-final {
  background-color: transparent;
  color: var(--gas-mod-final-fg);
  border-color: var(--gas-mod-final-border);
}

.gas-deprecated {
  background-color: var(--gas-deprecated-bg);
  color: var(--gas-deprecated-fg);
  border-color: var(--gas-deprecated-border);
}

/* ── abbr[title] specificity fix ───────────────────────────
 * Same fix as fixture extension: Normalize.css sets
 *   abbr[title] { border-bottom: none; text-decoration: underline dotted }
 * which conflicts with badge border styling.
 * ────────────────────────────────────────────────────────── */
abbr.gas-badge {
  border-bottom-style: solid;
  border-bottom-width: var(--gas-badge-border-w, 1px);
  text-decoration: underline dotted;
}

abbr.gas-type-function   { border-color: var(--gas-type-function-border); }
abbr.gas-type-class      { border-color: var(--gas-type-class-border); }
abbr.gas-type-method     { border-color: var(--gas-type-method-border); }
abbr.gas-type-classmethod { border-color: var(--gas-type-method-border); }
abbr.gas-type-staticmethod { border-color: var(--gas-type-method-border); }
abbr.gas-type-property   { border-color: var(--gas-type-property-border); }
abbr.gas-type-attribute  { border-color: var(--gas-type-attribute-border); }
abbr.gas-type-data       { border-color: var(--gas-type-data-border); }
abbr.gas-type-exception  { border-color: var(--gas-type-exception-border); }
abbr.gas-type-type       { border-color: var(--gas-type-type-border); }
abbr.gas-mod-async       { border-color: var(--gas-mod-async-border); }
abbr.gas-mod-classmethod { border-color: var(--gas-mod-classmethod-border); }
abbr.gas-mod-staticmethod { border-color: var(--gas-mod-staticmethod-border); }
abbr.gas-mod-abstract    { border-color: var(--gas-mod-abstract-border); }
abbr.gas-mod-final       { border-color: var(--gas-mod-final-border); }
abbr.gas-deprecated      { border-color: var(--gas-deprecated-border); }

/* ── Deprecated entry muting ───────────────────────────── */
dl.py.gas-deprecated > dt {
  opacity: 0.7;
}

/* ── Card treatment for top-level API entries ──────────── */
dl.py:not(.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);
}

dl.py:not(.fixture) > dt {
  background: var(--color-background-secondary);
  border-bottom: 1px solid var(--color-background-border);
  padding: 0.5rem 0.75rem;
  text-indent: 0;
  margin: 0;
  padding-left: 1rem;
  padding-top: 0.5rem !important;
  padding-bottom: 0.5rem !important;
  min-height: 2rem;
  transition: background 100ms ease-out;
}

dl.py:not(.fixture) > dt:hover {
  background: var(--color-api-background-hover);
}

dl.py:not(.fixture) > dd {
  padding: 0.75rem 1rem;
  margin-left: 0 !important;
}

/* Nested API entries (methods inside classes) get lighter treatment */
dl.py:not(.fixture) dd dl.py:not(.fixture) {
  border-color: var(--color-background-border);
  box-shadow: none;
  margin-bottom: 1rem;
}

dl.py:not(.fixture) dd dl.py:not(.fixture) > dt {
  background: transparent;
  border-bottom-color: var(--color-background-border);
  padding-left: 0.75rem;
  transition: background 100ms ease-out;
}

dl.py:not(.fixture) dd dl.py:not(.fixture) > dt:hover {
  background: var(--color-api-background-hover);
}

/* ── Metadata fields (compact grid) ────────────────────── */
dl.py:not(.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:not(.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:not(.fixture) > dd > dl.field-list > dd {
  grid-column: 2;
  margin-left: 0;
}

@media (max-width: 52rem) {
  dl.py:not(.fixture) > dd > dl.field-list {
    grid-template-columns: 1fr;
  }
  dl.py:not(.fixture) > dd > dl.field-list > dt,
  dl.py:not(.fixture) > dd > dl.field-list > dd {
    grid-column: 1;
  }
}
