:root {
  --paper: #f4f6f5;
  --surface: #ffffff;
  --ink: #16211e;
  --ink-muted: #5b6763;
  --rule: #d5dbd8;
  --rule-soft: #e6eae8;
  /* Complementarios: azul (212°) para compra y ámbar (28°) para venta; el oficial es una referencia neutra. */
  --buy: #1f5fa8;
  --sell: #b4530c;
  --official: #3d4844;
  --warning: #9a4a12;
  --focus: #1f5fa8;
  --code-bg: #eef1ef;

  --font: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* Escala modular 1.25 sobre 16px */
  --t-sm: 0.8125rem;
  --t-base: 1rem;
  --t-md: 1.25rem;
  --t-lg: 1.5625rem;
  --t-xl: clamp(1.9rem, 1.2rem + 2.6vw, 3.05rem);

  --max-width: 1120px;
  --gutter: clamp(16px, 4vw, 40px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #101715;
    --surface: #16201d;
    --ink: #e4ebe8;
    --ink-muted: #9aa8a3;
    --rule: #2c3a36;
    --rule-soft: #222e2b;
    --buy: #7fb0f0;
    --sell: #f2a65a;
    --official: #c9d3cf;
    --warning: #e39a5f;
    --focus: #7fb0f0;
    --code-bg: #1c2724;
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--t-base);
  line-height: 1.55;
  font-feature-settings: 'tnum' 1;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  color: var(--buy);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

.wrapper {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Cabecera */

.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
}

.site-header .wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.brand img {
  flex: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-size: 1.125rem;
  letter-spacing: -0.02em;
}

.brand-tagline {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--ink-muted);
  letter-spacing: 0;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 4px;
}

.nav a {
  padding: 8px 12px;
  border-radius: 4px;
  color: var(--ink-muted);
  font-size: 0.9375rem;
  text-decoration: none;
}

.nav a:hover {
  color: var(--ink);
  background: var(--rule-soft);
}

.nav a[aria-current='page'] {
  color: var(--ink);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--ink);
  border-radius: 0;
}

/* Tipografía de sección */

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.15;
  letter-spacing: -0.015em;
}

h1 {
  font-size: var(--t-xl);
  font-weight: 300;
  max-width: 22ch;
}

h1 strong {
  font-weight: 650;
}

h2 {
  font-size: var(--t-lg);
  font-weight: 600;
}

h3 {
  font-size: var(--t-md);
  font-weight: 600;
}

.lede {
  margin: 12px 0 0;
  color: var(--ink-muted);
  max-width: 68ch;
}

.section {
  padding: 48px 0;
  border-top: 1px solid var(--rule);
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 16px 32px;
  margin-bottom: 28px;
}

/* Portada del panel */

.hero {
  padding: 56px 0 44px;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 24px;
  margin-top: 20px;
  color: var(--ink-muted);
  font-size: 0.9375rem;
}

.next-official {
  color: var(--ink);
}

.next-official b {
  font-weight: 650;
}

.live-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.live-status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--buy);
}

.live-status[data-state='error']::before {
  background: var(--warning);
}

/* Escala de rangos: el elemento principal */

.range-chart {
  --col-nombre: 172px;
  --col-valores: 132px;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 20px 24px 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  font-size: var(--t-sm);
  color: var(--ink-muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.swatch.buy {
  background: var(--buy);
}

.swatch.sell {
  background: var(--sell);
}

.swatch.official {
  width: 2px;
  height: 14px;
  border-radius: 0;
  background: var(--official);
}

.range-rows {
  position: relative;
  margin: 28px 0 0;
  padding: 0;
  list-style: none;
}

/* Capa que cruza todas las filas con la línea del tipo oficial */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: var(--col-nombre) 1fr var(--col-valores);
  gap: 16px;
  pointer-events: none;
}

.overlay-track {
  position: relative;
}

.row {
  display: grid;
  grid-template-columns: var(--col-nombre) 1fr var(--col-valores);
  align-items: center;
  gap: 16px;
  min-height: 44px;
  border-top: 1px solid var(--rule-soft);
}

.row:first-child {
  border-top: 0;
}

.row-name {
  font-weight: 600;
  font-size: 0.9375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-values {
  font-size: var(--t-sm);
  text-align: right;
  color: var(--ink-muted);
  white-space: nowrap;
}

.row-values b {
  color: var(--ink);
  font-weight: 600;
}

.track {
  position: relative;
  height: 28px;
}

.track::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 1px dashed var(--rule);
}

.range-bar {
  position: absolute;
  top: 50%;
  height: 6px;
  margin-top: -3px;
  border-radius: 3px;
  /* OKLab mantiene limpio el paso entre complementarios, sin un centro turbio. */
  background: linear-gradient(90deg, var(--buy), var(--sell));
  background: linear-gradient(in oklab 90deg, var(--buy), var(--sell));
  opacity: 0.6;
}

.dot {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  border: 2px solid var(--surface);
}

.dot.buy {
  background: var(--buy);
}

.dot.sell {
  background: var(--sell);
}

.dot.reference {
  background: var(--surface);
  border: 2px solid var(--sell);
}

.official-tick {
  display: none;
  position: absolute;
  top: 4px;
  bottom: 4px;
  border-left: 2px solid var(--official);
}

.official-line {
  position: absolute;
  top: -6px;
  bottom: -10px;
  width: 0;
  border-left: 2px solid var(--official);
  pointer-events: none;
}

.official-line span {
  position: absolute;
  top: -22px;
  left: 6px;
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--official);
  white-space: nowrap;
}

.axis-row {
  display: grid;
  grid-template-columns: var(--col-nombre) 1fr var(--col-valores);
  gap: 16px;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--rule);
}

.axis {
  position: relative;
  height: 20px;
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.axis span {
  position: absolute;
  transform: translateX(-50%);
}

.caption {
  margin: 14px 0 0;
  font-size: var(--t-sm);
  color: var(--ink-muted);
}

/* Mejores precios: cada dato lleva el color de lo que compara (compra, venta o neutro) */

.best-prices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 0;
}

.best-prices div {
  padding: 16px 20px 18px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-top: 3px solid var(--ink-muted);
  border-radius: 0 0 6px 6px;
}

.best-prices .buy {
  border-top-color: var(--buy);
}

.best-prices .sell {
  border-top-color: var(--sell);
}

.best-prices dt {
  color: var(--ink-muted);
  font-size: 0.9375rem;
}

.best-prices dd {
  margin: 6px 0 0;
  font-size: var(--t-lg);
  font-weight: 650;
  line-height: 1.2;
}

.best-prices .buy dd {
  color: var(--buy);
}

.best-prices .sell dd {
  color: var(--sell);
}

.best-prices dd small {
  display: block;
  margin-top: 4px;
  font-size: var(--t-sm);
  font-weight: 400;
  color: var(--ink-muted);
}

/* Tabla */

.table-wrapper {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

th,
td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--rule-soft);
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

thead th {
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

th.num,
td.num {
  text-align: right;
}

th button {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

th button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

th button::after {
  content: '';
  width: 0;
  height: 0;
  border: 4px solid transparent;
  opacity: 0.35;
  border-top-color: currentColor;
  margin-top: 4px;
}

th[aria-sort='ascending'] button::after {
  border-top-color: transparent;
  border-bottom-color: currentColor;
  margin: 0 0 4px;
  opacity: 1;
}

th[aria-sort='descending'] button::after {
  opacity: 1;
}

th[aria-sort] button {
  color: var(--ink);
}

td .bank-link {
  font-weight: 600;
}

td .bank-name {
  display: block;
  font-size: var(--t-sm);
  color: var(--ink-muted);
}

td.buy {
  color: var(--buy);
  font-weight: 600;
}

td.sell {
  color: var(--sell);
  font-weight: 600;
}

.empty {
  color: var(--ink-muted);
}

.warning-text {
  color: var(--warning);
  font-size: var(--t-sm);
}

/* Histórico */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

select {
  font: inherit;
  font-size: 0.9375rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 8px 32px 8px 12px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface);
}

.segmented button {
  font: inherit;
  font-size: 0.9375rem;
  border: 0;
  background: none;
  color: var(--ink-muted);
  padding: 8px 14px;
  cursor: pointer;
}

.segmented button + button {
  border-left: 1px solid var(--rule);
}

.segmented button[aria-pressed='true'] {
  background: var(--ink);
  color: var(--surface);
}

.chart {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 20px 20px 12px;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart .axis-label {
  font-size: 11px;
  fill: var(--ink-muted);
}

.chart .gridline {
  stroke: var(--rule-soft);
}

.chart-empty {
  padding: 48px 8px;
  text-align: center;
  color: var(--ink-muted);
}

/* Pie */

.site-footer {
  border-top: 1px solid var(--rule);
  padding: 28px 0 40px;
  color: var(--ink-muted);
  font-size: var(--t-sm);
}

.site-footer p {
  margin: 0 0 6px;
  max-width: 80ch;
}

/* Documentación */

.docs {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 56px;
  padding-top: 48px;
  padding-bottom: 64px;
}

.toc {
  position: sticky;
  top: 24px;
  align-self: start;
  font-size: 0.9375rem;
}

.toc p {
  margin: 0 0 8px;
  font-weight: 600;
}

.toc ol {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  border-left: 1px solid var(--rule);
}

.toc a {
  display: block;
  padding: 4px 0 4px 14px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--ink-muted);
  text-decoration: none;
}

.toc a:hover {
  color: var(--ink);
}

.toc a[aria-current='true'] {
  color: var(--ink);
  border-left-color: var(--ink);
  font-weight: 600;
}

.toc code {
  font-size: 0.8125rem;
}

.content {
  max-width: 760px;
}

.content > section {
  padding: 8px 0 36px;
  scroll-margin-top: 16px;
}

.content > section + section {
  border-top: 1px solid var(--rule);
  padding-top: 36px;
}

.content h2 {
  margin-bottom: 14px;
}

.content h3 {
  margin: 28px 0 10px;
}

.content p,
.content li {
  max-width: 70ch;
}

.content ul {
  padding-left: 20px;
}

code {
  font-family: var(--mono);
  font-size: 0.875em;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 3px;
}

pre {
  margin: 0;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
}

pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

.endpoint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.9375rem;
  word-break: break-all;
}

.method {
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--surface);
  background: var(--buy);
  padding: 2px 8px;
  border-radius: 3px;
}

.params {
  display: block;
  overflow-x: auto;
  margin: 12px 0 20px;
}

.params th,
.params td {
  white-space: normal;
  vertical-align: top;
}

.params td:first-child {
  white-space: nowrap;
}

.code-block {
  margin: 12px 0 20px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
}

.code-block-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 8px 0 0;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}

.tabs {
  display: flex;
}

.tabs button,
.text-button {
  font: inherit;
  font-size: var(--t-sm);
  background: none;
  border: 0;
  color: var(--ink-muted);
  padding: 9px 14px;
  cursor: pointer;
}

.tabs button[aria-selected='true'] {
  color: var(--ink);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--ink);
}

.text-button:hover,
.tabs button:hover {
  color: var(--ink);
}

.code-block pre {
  padding: 14px 16px;
  max-height: 420px;
}

.block-title {
  padding: 9px 14px;
  font-size: var(--t-sm);
  color: var(--ink-muted);
}

.button {
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--surface);
  background: var(--ink);
  border: 0;
  border-radius: 4px;
  padding: 8px 16px;
  cursor: pointer;
}

.button:hover {
  opacity: 0.88;
}

.try-it {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 8px 0 0;
}

.try-it input {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.875rem;
  flex: 1 1 260px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
}

.response-status {
  font-size: var(--t-sm);
  color: var(--ink-muted);
}

.note {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 3px solid var(--official);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9375rem;
}

/* Responsivo */

@media (max-width: 860px) {
  .docs {
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
  }

  .toc {
    position: static;
  }

  .toc ol {
    display: flex;
    flex-wrap: wrap;
    border-left: 0;
    gap: 4px 0;
  }

  .toc a {
    border-left: 0;
    padding: 4px 12px 4px 0;
  }
}

@media (max-width: 720px) {
  .range-chart {
    --col-nombre: 1fr;
    padding: 16px 16px 10px;
  }

  .row {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      'name values'
      'track track';
    gap: 2px 12px;
    padding: 8px 0 4px;
  }

  .row-name {
    grid-area: name;
  }

  .row-values {
    grid-area: values;
  }

  .track {
    grid-area: track;
  }

  .axis-row {
    grid-template-columns: 1fr;
  }

  .overlay {
    display: none;
  }

  .official-tick {
    display: block;
  }

  .range-rows {
    margin-top: 0;
  }

  .axis-row > span {
    display: none;
  }

  .best-prices {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  td .bank-name {
    display: none;
  }

  th,
  td {
    padding: 12px;
  }

  .nav a {
    padding: 8px;
  }
}

/* En pantallas angostas el menú pasa a una segunda fila para no esconder la marca ni las pestañas. */
@media (max-width: 520px) {
  .site-header .wrapper {
    flex-wrap: wrap;
    gap: 2px 16px;
    min-height: 0;
    padding-top: 10px;
  }

  .nav {
    width: 100%;
    margin-left: -8px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  /* Única animación: la barra crece desde la compra hacia la venta al cargar. */
  .range-chart[data-ready] .range-bar {
    transform-origin: left center;
    animation: grow 700ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
  }

  .range-chart[data-ready] .dot.sell,
  .range-chart[data-ready] .dot.reference {
    animation: fade-in 300ms 450ms both;
  }

  @keyframes grow {
    from {
      transform: scaleX(0);
    }
  }

  @keyframes fade-in {
    from {
      opacity: 0;
    }
  }
}

.content h1 {
  max-width: none;
}
