/* ============================================================================
 * components.css — Componentes reutilizables
 * ----------------------------------------------------------------------------
 * Prefiere elementos nativos (<dialog>, popover, :has()) a JavaScript cuando se
 * puede. Clases en kebab-case. Modificadores con --.
 * ========================================================================== */

/* ============================================================================
 * CONTENEDORES
 * ========================================================================== */
.container        { width: 100%; margin-inline: auto; padding-inline: var(--sp-4); max-width: var(--w-content); }
.container--narrow { max-width: var(--w-narrow); }
.container--wide   { max-width: var(--w-wide); }

@media (min-width: 48rem) { .container { padding-inline: var(--sp-6); } }
@media (min-width: 64rem) { .container { padding-inline: var(--sp-8); } }

/* Grid de utilidad simple */
.grid { display: grid; gap: var(--sp-6); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 48rem) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
.stack > * + * { margin-top: var(--sp-4); }
.row { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }

/* ============================================================================
 * CARDS
 * ========================================================================== */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-base) var(--ease-out),
              border-color var(--dur-base) var(--ease-out);
}
@media (hover: hover) {
  .card:hover { border-color: var(--border-strong); transform: translateY(-2px); }
}
.card__title { margin: 0 0 var(--sp-2); font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 600; }
.card__sub   { color: var(--text-muted); margin: 0; font-size: var(--fs-sm); }

/* ============================================================================
 * BOTONES
 * ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--tap);
  padding: 0 var(--sp-5);
  border-radius: var(--r-md);
  font-weight: 600; font-size: var(--fs-base);
  cursor: pointer; user-select: none;
  transition: transform var(--dur-fast) var(--ease-out),
              background var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out),
              border-color var(--dur-base) var(--ease-out);
  text-decoration: none;
  white-space: nowrap;
}
.btn:active:not([disabled]) { transform: scale(0.98); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn--sm { min-height: 36px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn--lg { min-height: 52px; padding: 0 var(--sp-6); font-size: var(--fs-lg); }
.btn--block { width: 100%; }

.btn--primary {
  background: var(--primary-500);
  color: var(--on-primary);
  box-shadow: var(--shadow-1);
}
@media (hover: hover) {
  .btn--primary:hover:not([disabled]) { background: var(--primary-400); box-shadow: var(--glow-primary); }
}

.btn--secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
@media (hover: hover) {
  .btn--secondary:hover:not([disabled]) { background: var(--surface-3); }
}

.btn--ghost {
  background: transparent;
  color: var(--text);
}
@media (hover: hover) {
  .btn--ghost:hover:not([disabled]) { background: var(--surface-2); }
}

.btn--danger {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error);
}
@media (hover: hover) {
  .btn--danger:hover:not([disabled]) { background: var(--error); color: var(--on-primary); }
}

.btn--loading { pointer-events: none; opacity: 0.7; }
.btn--loading::after {
  content: ""; width: 1.25em; height: 1.25em;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin 0.6s linear infinite;
}

/* Botón flotante + */
.fab {
  position: fixed; right: var(--sp-5);
  bottom: calc(var(--bottom-bar-h) + var(--sp-5) + env(safe-area-inset-bottom, 0));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary-500); color: var(--on-primary);
  display: grid; place-items: center;
  box-shadow: var(--shadow-3);
  z-index: 20;
}

/* ============================================================================
 * FORMULARIOS
 * ========================================================================== */
.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field__label { font-size: var(--fs-sm); font-weight: 500; }
.field__help  { font-size: var(--fs-xs); color: var(--text-muted); }
.field__error { font-size: var(--fs-xs); color: var(--error-text); display: flex; align-items: center; gap: var(--sp-1); }

.input, .select, .textarea {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--r-md);
  padding: 0 var(--sp-4);
  min-height: var(--tap);
  font-size: var(--fs-base);
  width: 100%;
  transition: border-color var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out);
}
.textarea { padding: var(--sp-3) var(--sp-4); min-height: calc(var(--tap) * 2); line-height: var(--lh-normal); resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px rgb(var(--primary-rgb) / 0.2);
  outline: none;
}
.field:has(.field__error) .input,
.field:has(.field__error) .select,
.field:has(.field__error) .textarea { border-color: var(--error); }

.input[disabled], .select[disabled], .textarea[disabled] { opacity: 0.45; cursor: not-allowed; }

/* Switch (checkbox custom) */
.switch { position: relative; width: 44px; height: 24px; display: inline-block; }
.switch input { position: absolute; opacity: 0; inset: 0; }
.switch__slider {
  position: absolute; inset: 0;
  background: var(--surface-3);
  border-radius: var(--r-full);
  transition: background var(--dur-base) var(--ease-out);
}
.switch__slider::before {
  content: ""; position: absolute;
  left: 2px; top: 2px; width: 20px; height: 20px;
  background: var(--on-primary); border-radius: 50%;
  transition: transform var(--dur-base) var(--ease-out);
}
.switch input:checked + .switch__slider { background: var(--primary-500); }
.switch input:checked + .switch__slider::before { transform: translateX(20px); }
.switch input:focus-visible + .switch__slider { box-shadow: 0 0 0 3px rgb(var(--primary-rgb) / 0.3); }

/* ============================================================================
 * TABLAS
 * ========================================================================== */
.table-wrap { overflow-x: auto; border-radius: var(--r-lg); border: 1px solid var(--border); background: var(--surface-1); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: var(--sp-3) var(--sp-4); text-align: left; border-bottom: 1px solid var(--border); }
.table th { background: var(--surface-2); font-weight: 600; color: var(--text-muted); position: sticky; top: 0; z-index: 1; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-3); }
.table td.right, .table th.right { text-align: right; }
.table td.right { font-variant-numeric: tabular-nums; }

@media (max-width: 48rem) {
  .table-wrap--responsive .table thead { display: none; }
  .table-wrap--responsive .table tr { display: block; padding: var(--sp-3); border-bottom: 1px solid var(--border); }
  .table-wrap--responsive .table td { display: flex; justify-content: space-between; border: 0; padding: var(--sp-2) 0; }
  .table-wrap--responsive .table td::before { content: attr(data-label); color: var(--text-muted); font-weight: 500; }
}

/* ============================================================================
 * BADGES
 * ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  padding: 2px var(--sp-2); border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.4;
  background: var(--surface-3); color: var(--text);
}
.badge--success { background: var(--success-bg); color: var(--success-text); }
.badge--warning { background: var(--warning-bg); color: var(--warning-text); }
.badge--error   { background: var(--error-bg);   color: var(--error-text); }
.badge--info    { background: var(--info-bg);    color: var(--info-text); }

/* ============================================================================
 * TABS
 * ========================================================================== */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs__item {
  padding: var(--sp-3) var(--sp-4);
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}
.tabs__item[aria-selected="true"] { color: var(--text); border-color: var(--primary-500); }
@media (hover: hover) { .tabs__item:hover { color: var(--text); } }

/* ============================================================================
 * NAVEGACIÓN — top (desktop) y bottom (mobile)
 * ========================================================================== */
.top-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  view-transition-name: top-nav;
}
.top-nav__brand { font-family: var(--font-display); font-weight: 700; display: flex; gap: var(--sp-2); align-items: center; }
.top-nav__links { display: flex; gap: var(--sp-4); }
.top-nav__links a { color: var(--text-muted); padding: var(--sp-2); }
.top-nav__links a[aria-current="page"] { color: var(--text); }

.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  padding: var(--sp-1) var(--sp-2) calc(var(--sp-1) + env(safe-area-inset-bottom, 0));
  z-index: 10;
  view-transition-name: bottom-nav;
}
.bottom-nav__inner { display: flex; justify-content: space-around; max-width: var(--w-narrow); margin: 0 auto; }
.bottom-nav__item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: var(--sp-2);
  color: var(--text-muted); font-size: var(--fs-xs); font-weight: 500;
  min-height: var(--tap);
}
.bottom-nav__item[aria-current="page"] { color: var(--primary-400); }
[data-theme="light"] .bottom-nav__item[aria-current="page"] { color: var(--primary-600); }

@media (max-width: 48rem) {
  .bottom-nav { display: block; }
  body { padding-bottom: calc(var(--bottom-bar-h) + env(safe-area-inset-bottom, 0)); }
}

/* ============================================================================
 * PROGRESS BAR SUPERIOR (estilo YouTube/Vercel al cambiar panel)
 * ========================================================================== */
.topbar-progress {
  position: fixed; top: 0; left: 0; height: 3px;
  background: var(--primary-500);
  box-shadow: var(--glow-primary);
  width: 0%;
  z-index: 100;
  transition: width 400ms var(--ease-out), opacity 200ms var(--ease-out);
  pointer-events: none;
}
.topbar-progress[data-done] { opacity: 0; }

/* ============================================================================
 * TOASTS
 * ========================================================================== */
.toast-stack {
  position: fixed;
  left: var(--sp-4); right: var(--sp-4); bottom: calc(var(--bottom-bar-h) + var(--sp-5));
  display: flex; flex-direction: column; gap: var(--sp-2);
  z-index: 50; pointer-events: none;
}
@media (min-width: 48rem) {
  .toast-stack { left: auto; right: var(--sp-6); top: var(--sp-6); bottom: auto; max-width: 24rem; }
}
.toast {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-2);
  display: flex; align-items: center; gap: var(--sp-3);
  pointer-events: auto;
  animation: toast-in var(--dur-slow) var(--ease-out);
}
.toast--success { border-color: var(--success); }
.toast--warning { border-color: var(--warning); }
.toast--error   { border-color: var(--error); }
.toast--info    { border-color: var(--info); }
.toast button.undo {
  background: none; border: 0; color: var(--primary-400);
  padding: var(--sp-1) var(--sp-2); font-weight: 600; cursor: pointer;
}

/* ============================================================================
 * MODAL — <dialog> nativo (accesibilidad gratis)
 * ========================================================================== */
dialog.modal {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 0;
  max-width: min(32rem, calc(100% - var(--sp-8)));
  box-shadow: var(--shadow-3);
}
dialog.modal::backdrop { background: rgb(0 0 0 / 0.6); backdrop-filter: blur(2px); }
.modal__header { padding: var(--sp-6) var(--sp-6) 0; }
.modal__body   { padding: var(--sp-6); }
.modal__footer { padding: 0 var(--sp-6) var(--sp-6); display: flex; justify-content: flex-end; gap: var(--sp-3); }

/* Sheet desde abajo (móvil) */
@media (max-width: 48rem) {
  dialog.modal.modal--sheet {
    max-width: 100%; width: 100%;
    margin: 0; margin-top: auto;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    animation: toast-in var(--dur-slow) var(--ease-out);
  }
}

/* ============================================================================
 * AVATAR
 * ========================================================================== */
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface-3);
  display: grid; place-items: center;
  color: var(--text-muted); font-weight: 600; font-size: var(--fs-sm);
  overflow: hidden; flex-shrink: 0;
}
.avatar--lg { width: 56px; height: 56px; font-size: var(--fs-base); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ============================================================================
 * SKELETON
 * ========================================================================== */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s linear infinite;
  border-radius: var(--r-md);
  min-height: 1rem;
}

/* ============================================================================
 * ESTADO VACÍO
 * ========================================================================== */
.empty-state {
  text-align: center; padding: var(--sp-10) var(--sp-4);
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-3);
  color: var(--text-muted);
}
.empty-state__icon { width: 48px; height: 48px; opacity: 0.6; }
.empty-state__title { color: var(--text); font-weight: 600; font-size: var(--fs-lg); margin: 0; }

/* ============================================================================
 * SCROLL-DRIVEN ANIMATION (nativo) — ejemplo para hero
 * ========================================================================== */
@supports (animation-timeline: scroll()) {
  .scroll-fade {
    animation: scroll-fade linear;
    animation-timeline: view();
    animation-range: entry 0% cover 40%;
  }
  @keyframes scroll-fade {
    from { opacity: 0; transform: translateY(2rem); }
    to   { opacity: 1; transform: translateY(0); }
  }
}

/* ============================================================================
 * BRAND GALLERY (/brand) — swatches, muestras
 * ========================================================================== */
.swatch {
  display: grid; grid-template-columns: 48px 1fr auto; gap: var(--sp-3);
  align-items: center; padding: var(--sp-3);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.swatch__color { width: 48px; height: 48px; border-radius: var(--r-sm); border: 1px solid var(--border); }
.swatch__name  { font-weight: 600; }
.swatch__code  { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-muted); }


