/* =========================================================================
   Vytts — Biblioteca de componentes. Deriva 100% de tokens.css.
   Un componente por función. Sin colores/tamaños sueltos.
   ========================================================================= */

/* --- Base / reset mínimo --- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--text);
  background: var(--surface-sunken);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Números que alinean en tablas/montos */
.u-num, .data-table td.num, .data-table th.num,
.mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }

:where(button, a, input, select, textarea):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* --- Tipografía utilitaria --- */
.h1 { font-size: var(--text-2xl); font-weight: var(--weight-bold);     line-height: var(--leading-tight); letter-spacing: -0.02em; }
.h2 { font-size: var(--text-xl);  font-weight: var(--weight-semibold); line-height: var(--leading-tight); letter-spacing: -0.01em; }
.h3 { font-size: var(--text-lg);  font-weight: var(--weight-semibold); line-height: var(--leading-tight); }
.text-muted     { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-xs { font-size: var(--text-xs); }

/* =========================================================================
   Botones — un solo set: primario / secundario / fantasma / peligro
   ========================================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: inherit; font-size: var(--text-sm); font-weight: var(--weight-medium);
  line-height: 1; white-space: nowrap;
  border: 1px solid transparent; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  cursor: pointer; transition: background var(--duration) var(--ease), border-color var(--duration) var(--ease);
}
.btn:active { transform: translateY(0.5px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.btn--primary   { background: var(--action-primary); color: var(--text-on-primary); border-color: var(--action-primary); }
.btn--primary:hover:not(:disabled)   { background: var(--action-hover); border-color: var(--action-hover); }
.btn--primary:active:not(:disabled)  { background: var(--action-hover); }

.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--secondary:hover:not(:disabled) { background: var(--surface-sunken); border-color: var(--gray-400); }

.btn--ghost     { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn--ghost:hover:not(:disabled)     { background: var(--surface-sunken); color: var(--text); }

.btn--danger    { background: #b91c1c; color: #fff; border-color: #b91c1c; }
.btn--danger:hover:not(:disabled)    { filter: brightness(0.94); }

.btn--sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn--block { width: 100%; }

/* =========================================================================
   Campos de formulario — inputs / selects / textarea, con estados
   ========================================================================= */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field-label { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text-secondary); }

.input, .select, .textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-family: inherit; font-size: var(--text-sm); color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-sunken); color: var(--text-muted); cursor: not-allowed; }
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.field-error { font-size: var(--text-xs); color: var(--danger); }

/* =========================================================================
   Tabla de datos — el corazón de la app. Densa, sticky, ordenable.
   ========================================================================= */
.table-wrap {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); overflow: auto;
}
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-sunken);
  padding: var(--space-3) var(--space-4);
  text-align: left; font-weight: var(--weight-semibold); font-size: var(--text-xs);
  color: var(--text-secondary); text-transform: none; letter-spacing: 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--primary-soft); }
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--text); }
.data-table th.sortable[aria-sort="ascending"]::after  { content: " ↑"; color: var(--primary); }
.data-table th.sortable[aria-sort="descending"]::after { content: " ↓"; color: var(--primary); }

/* =========================================================================
   Cards / paneles — borde fino, no sombra dramática
   ========================================================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.card--raised { box-shadow: var(--shadow-sm); }
.card__title { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text); margin: 0 0 var(--space-2); }
.card__metric { font-size: var(--text-2xl); font-weight: var(--weight-bold); font-variant-numeric: tabular-nums; line-height: 1.1; }
.card__label { font-size: var(--text-xs); color: var(--text-muted); }

/* =========================================================================
   Badges / píldoras de estado — UN sistema, color semántico
   ========================================================================= */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2);
  font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: 1.4;
  border-radius: var(--radius-full);
  background: var(--gray-100); color: var(--gray-700);
  border: 1px solid transparent;
}
.badge--neutral { background: var(--gray-100);    color: var(--gray-700); }
.badge--primary { background: var(--primary-soft); color: var(--primary-active); }
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.badge--dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* =========================================================================
   Estados vacíos / carga — momentos de diseño, no spinner pelado
   ========================================================================= */
.empty-state { text-align: center; padding: var(--space-12) var(--space-6); color: var(--text-muted); }
.empty-state .h3 { color: var(--text); margin-bottom: var(--space-2); }

.skeleton {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 200% 100%; border-radius: var(--radius-sm);
  animation: skeleton 1.2s ease-in-out infinite;
}
@keyframes skeleton { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* --- Layout helpers --- */
.stack   { display: flex; flex-direction: column; gap: var(--space-3); }
.row     { display: flex; align-items: center; gap: var(--space-3); }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-3); }

/* Product guidance: shared dialogs, actions, forms and status messages.
   The vx namespace isolates these from legacy dashboard inline rules. */
.vx-button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 40px; padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit;
  font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: 1.35;
  cursor: pointer; text-decoration: none;
}
.vx-button:hover:not(:disabled) { background: var(--surface-sunken); text-decoration: none; }
.vx-button:disabled { opacity: .55; cursor: not-allowed; }
.vx-button-primary { background: var(--action-primary); border-color: var(--action-primary); color: var(--text-on-primary); }
.vx-button-primary:hover:not(:disabled) { background: var(--action-hover); border-color: var(--action-hover); }
.vx-button:focus-visible, .vx-field :is(input, select, textarea):focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.vx-product-tools { display: flex; justify-content: space-between; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-3) var(--space-6) 0; }
.vx-product-tools-secondary { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.vx-product-tools .vx-button { background: transparent; border-color: transparent; color: var(--text-secondary); font-size: var(--text-xs); }
.vx-product-tools .vx-button:hover { background: var(--surface); border-color: var(--border); color: var(--text); }
.vx-news-badge { background: var(--primary-soft); color: var(--primary-active); padding: 2px 6px; font-size: 10px; border-radius: var(--radius-full); }
.vx-news-badge[hidden] { display: none; }
.vx-dialog { width: min(620px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); margin: auto; padding: 0; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--text); box-shadow: var(--shadow-md); font-family: var(--font-ui); }
.vx-dialog::backdrop { background: rgb(8 20 40 / .6); }
.vx-dialog-header { display: flex; gap: var(--space-4); align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-6); border-bottom: 1px solid var(--border); }
.vx-dialog-header h2 { font-size: var(--text-lg); line-height: 1.3; margin: 0; }
.vx-dialog-header .vx-button { flex-shrink: 0; }
.vx-dialog-body, .vx-form { padding: var(--space-6); }
.vx-form { display: flex; flex-direction: column; gap: var(--space-4); }
.vx-field { display: flex; flex-direction: column; gap: var(--space-2); font-size: var(--text-sm); }
.vx-field :is(input, select, textarea) { width: 100%; padding: var(--space-3); border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; }
.vx-field textarea { min-height: 128px; resize: vertical; }
.vx-field small, .vx-field p { font-size: var(--text-xs); color: var(--text-secondary); }
.vx-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-4); }
.vx-copy { font-size: var(--text-sm); line-height: 1.65; color: var(--text-secondary); margin: var(--space-3) 0 var(--space-4); }
.vx-eyebrow { color: var(--text-secondary); font-size: var(--text-xs); letter-spacing: .04em; font-weight: var(--weight-semibold); }
.vx-guide-title { font-size: var(--text-lg); font-weight: var(--weight-semibold); line-height: 1.4; margin-top: var(--space-2); }
.vx-release { padding: var(--space-4) 0; border-top: 1px solid var(--border); }
.vx-release:last-child { padding-bottom: 0; }
.vx-status { font-size: var(--text-sm); line-height: 1.5; margin-top: var(--space-3); overflow-wrap: anywhere; }
.vx-status:empty { display: none; }
.vx-status[data-state="error"] { color: var(--danger); }
.vx-status[data-state="success"] { color: var(--success); }
.vx-guide-target { outline: 3px solid var(--primary) !important; outline-offset: 4px; scroll-margin-top: 100px; }
@media (max-width: 600px) {
  .vx-product-tools { margin-inline: var(--space-3); }
  .vx-product-tools .vx-button { min-height: 44px; }
  .vx-product-tools-secondary { gap: 0; }
  .vx-dialog-header, .vx-dialog-body, .vx-form { padding: var(--space-4); }
  .vx-dialog-header h2 { font-size: var(--text-base); }
}
