/* ==========================================================================
   BASE · reset, tipografía y elementos de formulario
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-variant-numeric: lining-nums;
  overflow: hidden;
  transition: background-color var(--dur-3) var(--ease-out), color var(--dur-3) var(--ease-out);
}

img, svg, video, canvas { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
::selection { background: color-mix(in oklab, var(--accent) 22%, transparent); }

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

/* Textura de papel */
:root[data-grain="on"] body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: .5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.3 0 0 0 0 0.25 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
:root[data-grain="on"][data-scheme="dark"] body::after { mix-blend-mode: screen; opacity: .35; }

/* Barras de desplazamiento discretas */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Iconos ---------- */
.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Tipografía ---------- */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: .45em;
  font-family: var(--font-ui);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.eyebrow .icon { width: 1.1em; height: 1.1em; color: var(--accent); }

.view-title {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -.02em;
}
.view-lead { color: var(--ink-2); font-size: var(--fs-md); max-width: 52ch; }
.muted { color: var(--ink-3); }
.subhead {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 500;
  margin: var(--space-7) 0 var(--space-4);
}

.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.6em;
  padding: .1em .45em;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 6px;
  font-family: var(--font-ui);
  font-size: .72rem;
  font-weight: 600;
  color: var(--ink-3);
  background: var(--surface);
  line-height: 1.4;
}

/* ---------- Botones ---------- */
.btn {
  --btn-bg: var(--surface);
  --btn-ink: var(--ink);
  --btn-line: var(--line-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5em;
  min-height: 42px;
  padding: 0 1.1em;
  border-radius: var(--radius-pill);
  border: 1px solid var(--btn-line);
  background: var(--btn-bg);
  color: var(--btn-ink);
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: .01em;
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--dur-1) var(--ease-out), background-color var(--dur-2), border-color var(--dur-2), box-shadow var(--dur-2);
}
.btn:hover { border-color: var(--ink-4); background: var(--raise); }
.btn:active { transform: scale(.97); }
.btn .icon { width: 1.15em; height: 1.15em; }
.btn-accent { --btn-bg: var(--accent); --btn-ink: var(--accent-ink); --btn-line: transparent; box-shadow: 0 6px 18px -8px color-mix(in oklab, var(--accent) 70%, transparent); }
.btn-accent:hover { background: var(--accent-2); border-color: transparent; }
.btn-ghost { --btn-bg: transparent; --btn-line: transparent; }
.btn-ghost:hover { background: var(--sunk); border-color: transparent; }
.btn-danger { --btn-bg: transparent; --btn-ink: #B42318; --btn-line: color-mix(in oklab, #B42318 40%, var(--bg)); }
:root[data-scheme="dark"] .btn-danger { --btn-ink: #FF8A7A; }
.btn-danger:hover { background: color-mix(in oklab, #B42318 10%, var(--bg)); }
.btn-lg { min-height: 52px; padding: 0 1.5em; font-size: var(--fs-md); }
.btn-sm { min-height: 34px; padding: 0 .9em; font-size: var(--fs-sm); }
.btn[disabled] { opacity: .5; pointer-events: none; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: var(--radius-pill);
  color: var(--ink-2);
  transition: background-color var(--dur-1), color var(--dur-1), transform var(--dur-1) var(--ease-out);
}
.icon-btn:hover { background: var(--sunk); color: var(--ink); }
.icon-btn:active { transform: scale(.92); }
.icon-btn[aria-pressed="true"], .icon-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); }
.icon-btn.danger:hover { color: #B42318; }

.link-more {
  display: inline-flex;
  align-items: center;
  gap: .35em;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--accent);
}
.link-more .icon { transition: transform var(--dur-2) var(--ease-out); }
.link-more:hover .icon { transform: translateX(3px); }

/* ---------- Campos ---------- */
.input, .field-search input, textarea.input {
  width: 100%;
  min-height: 44px;
  padding: .65em .9em;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--surface);
  outline: none;
  transition: border-color var(--dur-1), box-shadow var(--dur-1);
}
.input:focus, .field-search input:focus, textarea.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in oklab, var(--accent) 14%, transparent);
}
textarea.input { resize: vertical; line-height: 1.6; }

.field { display: grid; gap: var(--space-2); }
.field-inline { grid-template-columns: auto 1fr auto; align-items: center; gap: var(--space-3); }
.field-label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }

.field-search { position: relative; display: block; }
.field-search .icon { position: absolute; left: 14px; top: 50%; translate: 0 -50%; color: var(--ink-3); pointer-events: none; }
.field-search input { padding-left: 42px; border-radius: var(--radius-pill); background: var(--sunk); border-color: transparent; }
.field-search input:focus { background: var(--surface); }
input[type="search"]::-webkit-search-cancel-button { filter: grayscale(1); opacity: .5; }

.select-wrap { position: relative; display: inline-flex; align-items: center; }
.select-wrap select {
  appearance: none;
  width: 100%;
  min-height: 42px;
  padding: 0 2.4em 0 1em;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-pill);
  background: var(--surface);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  outline: none;
}
.select-wrap select:focus { border-color: var(--accent); }
.select-wrap .icon { position: absolute; right: 12px; pointer-events: none; color: var(--ink-3); width: 1em; height: 1em; }

/* Selector segmentado */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--sunk);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
}
.seg button, .seg > a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4em;
  min-height: 34px;
  padding: 0 .95em;
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-3);
  white-space: nowrap;
  transition: background-color var(--dur-2) var(--ease-out), color var(--dur-2), box-shadow var(--dur-2);
}
.seg button:hover, .seg > a:hover { color: var(--ink); }
.seg button[aria-selected="true"], .seg button.is-active, .seg > a[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1), 0 0 0 1px var(--line);
}
.seg .icon { width: 1.05em; height: 1.05em; }
.seg-full { display: flex; width: 100%; }
.seg-full button { flex: 1; }

/* Interruptor */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: .7em;
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-2);
  user-select: none;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track {
  position: relative;
  width: 38px;
  height: 22px;
  flex: none;
  border-radius: 999px;
  background: var(--line-2);
  transition: background-color var(--dur-2) var(--ease-out);
}
.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-2) var(--ease-spring);
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); background: var(--accent-ink); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Deslizador */
input[type="range"] {
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: var(--line-2); }
input[type="range"]::-moz-range-track { height: 3px; border-radius: 3px; background: var(--line-2); }
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -7.5px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-1);
}
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.2); }

/* ---------- Estados vacíos y esqueletos ---------- */
.empty {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--ink-2);
}
.empty h2, .empty h3 { font-family: var(--font-display); font-weight: 500; font-size: var(--fs-xl); color: var(--ink); }
.empty p { max-width: 42ch; }
.empty .btn { margin-top: var(--space-3); }
.empty-icon { width: 44px; height: 44px; color: var(--accent); stroke-width: 1.2; margin-bottom: var(--space-2); opacity: .9; }

.skeleton-line {
  display: block;
  height: .8em;
  margin: .45em 0;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--line) 0%, var(--sunk) 50%, var(--line) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton-line.short { width: 60%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Utilidades ---------- */
.grow { flex: 1; }
.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 10000;
  padding: .6em 1em;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--radius);
}
.skip-link:focus { top: 12px; }
.noscript { padding: 2rem; text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
