/* ============================================================
   base.css — Semantic-first CSS framework
   Filosofía: el HTML semántico carga el estilo.
   Las clases son solo para estructura de layout.
   ============================================================ */


/* ── 1. VARIABLES ────────────────────────────────────────── */

:root {
  /* Escala de spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Tipografía */
  --font-xs:   0.75rem;
  --font-sm:   0.875rem;
  --font-base: 1rem;
  --font-lg:   1.125rem;
  --font-xl:   1.25rem;
  --font-2xl:  1.5rem;
  --font-3xl:  1.875rem;
  --font-4xl:  2.25rem;

  /* Escala de color — neutral */
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --white:    #ffffff;

  /* Acento — azul neutro, fácil de sobreescribir */
  --accent:       #2563eb;
  --accent-dark:  #1d4ed8;
  --accent-light: #dbeafe;

  /* Superficie y texto base */
  --bg:          var(--white);
  --text:        var(--gray-900);
  --text-muted:  var(--gray-500);
  --border:      var(--gray-200);

  /* Radio */
  --radius-sm: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;

  /* Transición base */
  --transition: 0.2s ease;
}


/* ── 2. RESET MÍNIMO ─────────────────────────────────────── */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}


/* ── 3. BODY & TIPOGRAFÍA BASE ───────────────────────────── */

body {
  font-family: system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: var(--font-base);
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
}


/* ── 4. HEADINGS ─────────────────────────────────────────── */

h1, h2, h3, h4, h5, h6 {
  line-height: 1.25;
  font-weight: 600;
  margin-bottom: var(--space-3);
  color: var(--gray-900);
}

h1 { font-size: var(--font-4xl); font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: var(--font-3xl); letter-spacing: -0.01em; }
h3 { font-size: var(--font-2xl); }
h4 { font-size: var(--font-xl);  }
h5 { font-size: var(--font-lg);  font-weight: 500; }
h6 { font-size: var(--font-base); font-weight: 500; }

@media (min-width: 640px) {
  h1 { font-size: calc(var(--font-4xl) * 1.2); }
  h2 { font-size: calc(var(--font-3xl) * 1.1); }
}


/* ── 5. PROSA ────────────────────────────────────────────── */

p {
  margin-bottom: var(--space-4);
  max-width: 70ch; /* legibilidad óptima */
}

p:last-child { margin-bottom: 0; }

strong  { font-weight: 700; }
em      { font-style: italic; }
small   { font-size: var(--font-sm); color: var(--text-muted); }
mark    { background-color: var(--accent-light); color: var(--gray-900); padding: 0 var(--space-1); border-radius: var(--radius-sm); }
abbr[title] { text-decoration: underline dotted; cursor: help; }


/* ── 6. ENLACES ──────────────────────────────────────────── */

a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color var(--transition);
}

a:hover { color: var(--accent-dark); }
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}


/* ── 7. LISTAS ───────────────────────────────────────────── */

ul, ol {
  padding-left: var(--space-6);
  margin-bottom: var(--space-4);
}

li { margin-bottom: var(--space-1); }

/* Listas anidadas */
li > ul, li > ol {
  margin-top: var(--space-1);
  margin-bottom: 0;
}

/* Lista de navegación: sin estilo visual */
nav ul, nav ol {
  list-style: none;
  padding: 0;
  margin: 0;
}

nav li { margin: 0; }


/* ── 8. BLOCKQUOTE ───────────────────────────────────────── */

blockquote {
  border-left: 3px solid var(--border);
  padding: var(--space-3) var(--space-6);
  margin: var(--space-6) 0;
  color: var(--text-muted);
  font-style: italic;
}

blockquote p { max-width: none; }

blockquote cite {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--font-sm);
  font-style: normal;
  color: var(--gray-400);
}

blockquote cite::before { content: "— "; }


/* ── 9. CÓDIGO ───────────────────────────────────────────── */

code {
  font-family: "JetBrains Mono", "Fira Code", "Courier New", monospace;
  font-size: 0.9em;
  background-color: var(--gray-100);
  color: var(--gray-700);
  padding: 0.1em 0.4em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-200);
}

pre {
  font-family: "JetBrains Mono", "Fira Code", "Courier New", monospace;
  font-size: var(--font-sm);
  line-height: 1.7;
  background-color: var(--gray-900);
  color: var(--gray-100);
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  margin-bottom: var(--space-6);
}

pre code {
  /* Resetear estilos inline dentro de bloque */
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}


/* ── 10. SEPARADORES ─────────────────────────────────────── */

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-8) 0;
}


/* ── 11. IMÁGENES & MEDIOS ───────────────────────────────── */

img, video, svg {
  display: block;
  max-width: 100%;
  height: auto;
}

figure {
  margin: var(--space-6) 0;
}

figcaption {
  margin-top: var(--space-2);
  font-size: var(--font-sm);
  color: var(--text-muted);
  text-align: center;
}


/* ── 12. TABLAS ──────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-sm);
  margin-bottom: var(--space-6);
}

thead {
  background-color: var(--gray-50);
  border-bottom: 2px solid var(--border);
}

th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: 600;
  color: var(--gray-700);
  font-size: var(--font-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--gray-700);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background-color: var(--gray-50); }

/* Scroll horizontal en tablas anchas */
table { display: table; }

@media (max-width: 640px) {
  .table-wrap { overflow-x: auto; }
}


/* ── 13. FORMULARIOS ─────────────────────────────────────── */

label {
  display: block;
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: var(--space-1);
}

input:not([type="checkbox"]):not([type="radio"]), textarea, select {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-base);
  font-family: inherit;
  line-height: 1.5;
  color: var(--gray-900);
  background-color: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

input:disabled, textarea:disabled, select:disabled {
  background-color: var(--gray-100);
  color: var(--gray-400);
  cursor: not-allowed;
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  display: inline-block;
  padding: 0;
  margin-right: var(--space-2);
  vertical-align: middle;
  accent-color: var(--accent);
  cursor: pointer;
}

textarea {
  min-height: 6rem;
  resize: vertical;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-8);
  cursor: pointer;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-6);
  margin-bottom: var(--space-6);
}

legend {
  padding: 0 var(--space-2);
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--gray-700);
}

/* Agrupación inline de checkbox/radio + label */
fieldset label {
  display: inline-flex;
  align-items: center;
  font-weight: 400;
  margin-bottom: var(--space-2);
  cursor: pointer;
}

/* Mensaje de error */
[aria-invalid="true"] {
  border-color: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

[aria-describedby] + [role="alert"] {
  font-size: var(--font-xs);
  color: #dc2626;
  margin-top: var(--space-1);
  display: block;
}


/* ── 14. BOTONES ─────────────────────────────────────────── */

button, [type="submit"], [type="reset"], [type="button"] {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-6);
  font-family: inherit;
  font-size: var(--font-sm);
  font-weight: 500;
  line-height: 1.5;
  color: var(--white);
  background-color: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--transition), box-shadow var(--transition);
  user-select: none;
  white-space: nowrap;
}

button:hover, [type="submit"]:hover {
  background-color: var(--accent-dark);
}

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

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Variante secundaria: solo contorno */
button[data-variant="secondary"] {
  background-color: transparent;
  color: var(--accent);
  border-color: var(--accent);
}

button[data-variant="secondary"]:hover {
  background-color: var(--accent-light);
}

/* Variante ghost */
button[data-variant="ghost"] {
  background-color: transparent;
  color: var(--gray-700);
  border-color: var(--border);
}

button[data-variant="ghost"]:hover {
  background-color: var(--gray-100);
}

/* Variante danger */
button[data-variant="danger"] {
  background-color: #dc2626;
  border-color: #dc2626;
}

button[data-variant="danger"]:hover {
  background-color: #b91c1c;
}


/* ── 15. ELEMENTOS SEMÁNTICOS DE LAYOUT ──────────────────── */

header {
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border);
}

footer {
  padding: var(--space-8) 0;
  border-top: 1px solid var(--border);
  font-size: var(--font-sm);
  color: var(--text-muted);
}

main {
  padding: var(--space-8) 0;
}

section {
  margin-bottom: var(--space-12);
}

article {
  max-width: 72ch;
}

/* Detalle/Resumen nativo */
details {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
}

summary {
  font-weight: 500;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

summary::before {
  content: "▶";
  font-size: 0.7em;
  transition: transform var(--transition);
  display: inline-block;
  color: var(--text-muted);
}

details[open] summary::before { transform: rotate(90deg); }
details[open] summary { margin-bottom: var(--space-3); }


/* ── 16. ACCESIBILIDAD ───────────────────────────────────── */

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

/* Saltar al contenido */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: var(--white);
  border-radius: var(--radius-md);
  font-size: var(--font-sm);
  font-weight: 500;
  text-decoration: none;
  z-index: 9999;
  transition: top var(--transition);
}

.skip-link:focus { top: var(--space-4); }

.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;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}


/* ══════════════════════════════════════════════════════════
   CLASES DE LAYOUT — mínimas e imprescindibles
   Únicas clases requeridas para estructurar páginas.
   ══════════════════════════════════════════════════════════ */


/* ── L1. CONTENEDOR ──────────────────────────────────────── */

.container {
  width: 100%;
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.container-sm  { max-width: 640px;  }
.container-md  { max-width: 768px;  }
.container-lg  { max-width: 1024px; }
.container-xl  { max-width: 1280px; }


/* ── L2. GRID ────────────────────────────────────────────── */

.grid {
  display: grid;
  gap: var(--space-4);
}

/* Columnas explícitas */
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* Auto-adaptable sin media queries: el más usado en la práctica */
.grid-auto-sm { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid-auto-md { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-auto-lg { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

/* Gaps alternativos */
.gap-2 { gap: var(--space-2); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

/* Responsive: colapsa a 1 columna en móvil */
@media (max-width: 640px) {
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
}

@media (min-width: 641px) and (max-width: 900px) {
  .cols-3, .cols-4 { grid-template-columns: repeat(2, 1fr); }
}


/* ── L3. FLEX ────────────────────────────────────────────── */

.flex {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
  align-items: center;
}

/* Modificadores de eje */
.flex-col  { flex-direction: column; }
.flex-row  { flex-direction: row; }

/* Alineación */
.items-start    { align-items: flex-start; }
.items-center   { align-items: center; }
.items-end      { align-items: flex-end; }
.justify-start  { justify-content: flex-start; }
.justify-center { justify-content: center; }
.justify-end    { justify-content: flex-end; }
.justify-between{ justify-content: space-between; }

/* Crecimiento */
.flex-1    { flex: 1; }
.flex-none { flex: none; }

/* Patrón muy común: sidebar + contenido */
.flex-sidebar {
  display: flex;
  gap: var(--space-6);
  align-items: flex-start;
}

.flex-sidebar > :first-child { flex: 0 0 240px; }
.flex-sidebar > :last-child  { flex: 1; min-width: 0; }

@media (max-width: 768px) {
  .flex-sidebar { flex-direction: column; }
  .flex-sidebar > :first-child { flex: none; width: 100%; }
}
