/* =====================================================================
   APICE — Base: reset, tipografía, layout y componentes de interfaz
   ===================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 16px);
}

body {
  margin: 0;
  /* Red de seguridad: si algún elemento se pasa de ancho, no aparece la barra
     de desplazamiento horizontal en toda la página. */
  overflow-x: clip;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

img, svg, video, canvas, iframe { display: block; max-width: 100%; }
img { height: auto; }

h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -0.02em;
  margin: 0 0 0.5em;
  color: var(--text);
  text-wrap: balance;
}
h1 { font-size: clamp(2.1rem, 1.2rem + 3.4vw, var(--fs-5xl)); }
h2 { font-size: clamp(1.6rem, 1.1rem + 2vw, var(--fs-3xl)); }
h3 { font-size: clamp(1.15rem, 1rem + 0.7vw, var(--fs-xl)); }
h4 { font-size: var(--fs-lg); }
p { margin: 0 0 1em; text-wrap: pretty; }
p:last-child { margin-bottom: 0; }

a { color: var(--link); text-decoration: none; transition: color var(--dur) var(--ease); }
a:hover { color: var(--primary-hov); }

small { font-size: var(--fs-sm); }
code, kbd, pre { font-family: var(--font-mono); font-size: 0.9em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 32px 0; }

::selection { background: var(--brand-600); color: #fff; }

:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* Scrollbar sutil */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ============================== LAYOUT ============================== */
.container {
  width: min(100% - 40px, var(--container));
  margin-inline: auto;
}
@media (max-width: 640px) { .container { width: calc(100% - 32px); } }

.section { padding: clamp(56px, 7vw, 104px) 0; }
.section--tight { padding: clamp(40px, 5vw, 68px) 0; }
.section--alt { background: var(--bg-soft); }

.stack > * + * { margin-top: var(--gap, 16px); }
.grid { display: grid; gap: var(--gap, 24px); }
/* Los hijos de una rejilla traen min-width:auto, así que un contenido ancho
   (una tabla, un bloque de código) estira la columna más allá de la pantalla.
   Con min-width:0 la columna respeta su espacio y el contenido se ajusta. */
.grid > *, .bloque > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(272px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(252px, 1fr)); }
.row { display: flex; gap: var(--gap, 12px); align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.row--nowrap { flex-wrap: nowrap; }
.spacer { flex: 1 1 auto; }

.text-center { text-align: center; }
.muted { color: var(--text-muted); }
.soft { color: var(--text-soft); }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Encabezado de sección */
.sec-head { max-width: 720px; margin-bottom: clamp(32px, 4vw, 56px); }
.sec-head--center { margin-inline: auto; text-align: center; }
.sec-head p { color: var(--text-soft); font-size: var(--fs-lg); }

.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-display);
  font-size: var(--fs-sm); font-weight: 650;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--on-brand-soft);
  margin-bottom: 14px;
}
.eyebrow::before {
  content: ''; width: 26px; height: 2px; border-radius: 2px;
  background: var(--grad-accent);
}
.sec-head--center .eyebrow::before { display: none; }

/* ============================== BOTONES ============================= */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  font-family: var(--font-display);
  font-size: var(--fs-base); font-weight: 600; line-height: 1;
  padding: 12px 20px;
  min-height: 44px;
  border-radius: var(--r-full);
  border: 1px solid var(--btn-bd);
  background: var(--btn-bg);
  color: var(--btn-fg);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); color: var(--btn-fg); }
.btn:active { transform: translateY(0); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; pointer-events: none; }

.btn--primary { --btn-bg: var(--primary); --btn-fg: var(--primary-fg); --btn-bd: transparent; box-shadow: var(--shadow-brand); }
.btn--primary:hover { --btn-bg: var(--primary-hov); }
.btn--accent { --btn-bg: var(--accent-500); --btn-fg: #04252A; --btn-bd: transparent; }
.btn--accent:hover { --btn-bg: var(--accent-400); }
.btn--ghost { --btn-bg: transparent; --btn-bd: var(--border-strong); }
.btn--ghost:hover { --btn-bg: var(--surface-3); }
.btn--soft { --btn-bg: var(--surface-brand); --btn-fg: var(--on-brand-soft); --btn-bd: transparent; }
.btn--quiet { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--text-soft); box-shadow: none; }
.btn--quiet:hover { --btn-bg: var(--surface-3); box-shadow: none; }
.btn--danger { --btn-bg: var(--danger-fg); --btn-fg: #fff; --btn-bd: transparent; }
.btn--onbrand { --btn-bg: rgba(255,255,255,.12); --btn-fg: #fff; --btn-bd: rgba(255,255,255,.32); backdrop-filter: blur(8px); }
.btn--onbrand:hover { --btn-bg: rgba(255,255,255,.22); }
.btn--sm { padding: 8px 14px; min-height: 36px; font-size: var(--fs-sm); }
.btn--lg { padding: 15px 28px; min-height: 52px; font-size: var(--fs-md); }
.btn--block { width: 100%; }
.btn--icon { padding: 0; width: 42px; min-height: 42px; border-radius: var(--r-full); }
.btn--icon.btn--sm { width: 34px; min-height: 34px; }
.btn svg { width: 18px; height: 18px; flex: none; }

/* ============================== TARJETAS ============================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.card--flat { box-shadow: none; }
.card--pad-sm { padding: 16px; }
.card--pad-lg { padding: clamp(24px, 3vw, 38px); }
.card--hover:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--brand-300); }
.card__title { font-family: var(--font-display); font-weight: 650; font-size: var(--fs-lg); margin: 0 0 8px; }
.card__body { color: var(--text-soft); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel__head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.panel__head h3, .panel__head h2 { margin: 0; font-size: var(--fs-md); }
.panel__body { padding: 20px; }
.panel__foot { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* Icono en pastilla */
.icon-pill {
  display: inline-grid; place-items: center;
  width: 50px; height: 50px; flex: none;
  border-radius: 15px;
  background: var(--surface-brand);
  color: var(--on-brand-soft);
  border: 1px solid var(--border-soft);
}
.icon-pill svg { width: 24px; height: 24px; }
.icon-pill--brand { background: var(--grad-accent); color: #fff; border-color: transparent; box-shadow: var(--shadow-brand); }
.icon-pill--gold { background: var(--grad-gold); color: #3B2A05; border-color: transparent; }
.icon-pill--sm { width: 38px; height: 38px; border-radius: 11px; }
.icon-pill--sm svg { width: 19px; height: 19px; }

/* ============================== BADGES ============================== */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 650;
  font-family: var(--font-display);
  letter-spacing: 0.01em;
  background: var(--neutral-bg); color: var(--neutral-fg);
  border: 1px solid var(--neutral-bd);
  white-space: nowrap;
}
.badge--ok { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-bd); }
.badge--warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-bd); }
.badge--danger { background: var(--danger-bg); color: var(--danger-fg); border-color: var(--danger-bd); }
.badge--info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-bd); }
.badge--accent { background: var(--accent-bg); color: var(--accent-fg); border-color: var(--accent-bd); }
.badge--brand { background: var(--surface-brand); color: var(--on-brand-soft); border-color: var(--border-soft); }
.badge__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

/* ========================== FORMULARIOS ============================= */
.field { display: block; margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }
.label {
  display: block;
  font-family: var(--font-display);
  font-size: var(--fs-sm); font-weight: 600;
  color: var(--text); margin-bottom: 7px;
}
.label .req { color: var(--danger-fg); margin-left: 2px; }
.hint { display: block; font-size: var(--fs-xs); color: var(--text-muted); margin-top: 6px; }
.err-msg { display: block; font-size: var(--fs-xs); color: var(--danger-fg); margin-top: 6px; font-weight: 600; }

.input, .select, .textarea {
  width: 100%;
  font-family: inherit;
  font-size: var(--fs-base);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 11px 14px;
  min-height: 44px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--brand-400); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--ring);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); opacity: 0.85; }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] {
  border-color: var(--danger-fg);
  box-shadow: 0 0 0 4px rgba(217, 45, 32, 0.14);
}
.select {
  appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236E807E' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  background-size: 17px;
}
:root[data-theme="dark"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2385A09D' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
.input-icon { position: relative; }
.input-icon > svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-muted); pointer-events: none; }
.input-icon > .input { padding-left: 42px; }

.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: var(--fs-base); }
.check input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--primary); flex: none; cursor: pointer; }

.form-grid { display: grid; gap: 0 18px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.form-grid .field--full { grid-column: 1 / -1; }

fieldset { border: 0; padding: 0; margin: 0 0 24px; }
legend {
  font-family: var(--font-display); font-weight: 650; font-size: var(--fs-sm);
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted);
  padding: 0 0 12px; width: 100%; border-bottom: 1px solid var(--border-soft); margin-bottom: 18px;
}

/* ============================== TABLAS ============================== */
.table-wrap { overflow-x: auto; border-radius: var(--r-md); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.table th {
  text-align: left; font-family: var(--font-display); font-weight: 650;
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); padding: 12px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 13px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table tbody tr { transition: background-color 140ms var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.is-clickable { cursor: pointer; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ============================== TABS =============================== */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  appearance: none; background: none; border: 0; cursor: pointer;
  font-family: var(--font-display); font-size: var(--fs-base); font-weight: 600;
  color: var(--text-muted); padding: 12px 16px; white-space: nowrap;
  border-bottom: 2.5px solid transparent; margin-bottom: -1px;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

.segmented { display: inline-flex; background: var(--surface-3); border-radius: var(--r-full); padding: 4px; gap: 2px; }
.segmented button {
  appearance: none; border: 0; background: none; cursor: pointer;
  font-family: var(--font-display); font-size: var(--fs-sm); font-weight: 600;
  color: var(--text-muted); padding: 7px 15px; border-radius: var(--r-full);
  transition: all var(--dur) var(--ease);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }

/* ============================== MODAL ============================== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(8, 20, 19, 0.55);
  backdrop-filter: blur(5px);
  display: grid; place-items: center;
  padding: 20px;
  animation: fade-in 180ms var(--ease);
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  width: min(100%, 620px);
  max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  animation: pop-in 220ms var(--ease);
}
.modal--wide { width: min(100%, 940px); }
.modal__head { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.modal__head h3 { margin: 0; font-size: var(--fs-lg); }
.modal__body { padding: 24px; overflow-y: auto; }
.modal__foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; background: var(--surface-2); }

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } }

/* ============================== TOASTS ============================= */
.toast-host {
  position: fixed; z-index: 400; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 11px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  padding: 13px 16px; max-width: 380px; font-size: var(--fs-base);
  animation: slide-in 260ms var(--ease);
}
.toast--ok { border-left-color: var(--ok-fg); }
.toast--err { border-left-color: var(--danger-fg); }
.toast--warn { border-left-color: var(--warn-fg); }
.toast svg { width: 19px; height: 19px; flex: none; margin-top: 1px; }
.toast--ok svg { color: var(--ok-fg); }
.toast--err svg { color: var(--danger-fg); }
.toast--warn svg { color: var(--warn-fg); }
@keyframes slide-in { from { opacity: 0; transform: translateX(22px); } }

/* ============================ EMPTY / LOADER ======================= */
.empty { text-align: center; padding: 56px 24px; color: var(--text-muted); }
.empty svg { width: 46px; height: 46px; margin: 0 auto 16px; color: var(--border-strong); }
.empty h4 { color: var(--text-soft); margin-bottom: 6px; }

.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid var(--border-strong); border-top-color: var(--primary);
  animation: spin 700ms linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-block { display: grid; place-items: center; padding: 56px; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm);
  min-height: 14px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ============================ ACCESIBILIDAD ======================== */
.skip-link {
  position: absolute; left: 12px; top: -100px; z-index: 500;
  background: var(--primary); color: var(--primary-fg);
  padding: 11px 18px; border-radius: var(--r-md); font-weight: 600;
  transition: top 160ms var(--ease);
}
.skip-link:focus { top: 12px; color: var(--primary-fg); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
