/* ============================================================================
   LINK ADVANCE — BASE
   Reset, tipografía y componentes de una sola pieza (botón, input, tarjeta,
   badge, tabla, modal). Depende de tokens.css. Escritorio y móvil comparten
   este archivo; el chasis táctil (ios.css) solo lo reencuadra.
   ============================================================================ */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background-color: var(--page);
  background-image: var(--gradient-page);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--text-strong);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -.02em;
}
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

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

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
img, svg { display: block; max-width: 100%; }

/* Cifras y códigos: tabulares, para que las columnas no bailen. */
.num, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ── Utilidades ── */
.muted   { color: var(--text-muted); }
.strong  { color: var(--text-strong); font-weight: 700; }
.row     { display: flex; align-items: center; gap: 12px; }
.row.wrap{ flex-wrap: wrap; }
.spacer  { flex: 1; }
.grid    { display: grid; gap: 20px; }
.nowrap  { white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ============================================================================
   BOTONES — píldora siempre. Es el sello más reconocible de la marca.
   ============================================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--row-h);
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  font-family: var(--font-body);
  font-size: 14px; font-weight: 600;
  white-space: nowrap;
  background: var(--surface-2); color: var(--text);
  transition: background var(--t-fast), box-shadow var(--t-fast),
              transform var(--t-fast), border-color var(--t-fast);
}
.btn .ico { width: 18px; height: 18px; flex: none; }
.btn:active { transform: translateY(1px) scale(.985); opacity: .85; }
.btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: default; box-shadow: none; transform: none; }

@media (hover: hover) {
  .btn:hover { background: var(--border); }
}

.btn-primary {
  color: #fff;
  background: var(--primary);
  box-shadow: var(--shadow-brand);
}
@media (hover: hover) { .btn-primary:hover { background: var(--primary-hover); } }

/* Variante translúcida: primario sobre héroes, barras de marca y fondos con
   degradado. Es el material que da el aire de app nativa. */
.btn-glass {
  color: #fff;
  border-color: rgba(255, 255, 255, .32);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, .26), transparent 44%),
    var(--gradient-brand);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .36),
    inset 0 -1px 0 rgba(10, 45, 88, .24),
    var(--shadow-brand);
  backdrop-filter: blur(16px) saturate(1.35);
  -webkit-backdrop-filter: blur(16px) saturate(1.35);
}

.btn-ghost   { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-soft    { background: var(--primary-soft); color: var(--blue-800); border-color: var(--blue-100); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-warning { background: var(--warning); color: #4a3410; }
@media (hover: hover) {
  .btn-ghost:hover, .btn-soft:hover { background: var(--primary-soft); }
  .btn-success:hover, .btn-danger:hover, .btn-warning:hover { filter: brightness(.95); }
}

.btn-sm    { min-height: 34px; padding: 6px 14px; font-size: 13px; }
.btn-block { width: 100%; }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: var(--row-h); height: var(--row-h); padding: 0;
  border: 1px solid transparent; border-radius: var(--r-pill);
  background: transparent; color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.btn-icon:active { transform: translateY(1px); }
.btn-icon:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn-icon:disabled { opacity: .38; cursor: default; }
@media (hover: hover) {
  .btn-icon:hover { background: var(--primary-soft); color: var(--primary); }
}

/* ============================================================================
   FORMULARIOS
   ============================================================================ */
.field { display: grid; gap: 6px; margin-bottom: var(--space-4); }
.field label,
.form-label {
  font-size: 13px; font-weight: 600; color: var(--text-strong);
}
.field .hint { font-size: 12px; color: var(--text-muted); }
.field .err  { font-size: 12px; color: var(--danger); }

.input, .select, .textarea {
  width: 100%;
  min-height: var(--row-h);
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;              /* 16px o iOS hace zoom al enfocar. No bajar. */
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.textarea { min-height: 96px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-focus);
}
.input:disabled, .select:disabled { background: var(--surface-2); color: var(--text-muted); }
.input[aria-invalid="true"] { border-color: var(--danger); }

@media (min-width: 900px) {
  .input, .select, .textarea { font-size: 14px; }
}

/* Input con ícono a la izquierda (correo, contraseña, búsqueda). */
.input-icon { position: relative; }
.input-icon .ico {
  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; }

/* Interruptor de sistema. */
.switch { position: relative; display: inline-block; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track {
  position: absolute; inset: 0; border-radius: var(--r-pill);
  background: var(--fill-1); transition: background var(--t-ios);
}
.switch .track::before {
  content: ""; position: absolute; left: 2px; top: 2px;
  width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
  transition: transform var(--t-ios);
}
.switch input:checked + .track { background: var(--success); }
.switch input:checked + .track::before { transform: translateX(20px); }
.switch input:focus-visible + .track { box-shadow: var(--shadow-focus); }

/* Segmentado — reemplaza a las pestañas subrayadas en toda la app. */
.segmented {
  display: flex; gap: 0; padding: 3px;
  background: var(--fill-3); border-radius: var(--r-ios-md);
}
.segmented button {
  flex: 1 1 0; min-height: 34px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: var(--r-ios-sm);
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  transition: background var(--t-ios), color var(--t-ios);
}
.segmented button.active {
  color: var(--text-strong); background: var(--surface);
  box-shadow: 0 1px 3px rgba(12, 23, 38, .16);
}

/* ============================================================================
   TARJETAS Y BADGES
   ============================================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xs);
  padding: var(--space-5);
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: var(--space-4); }
.card-head h3 { flex: 1; }
@media (hover: hover) {
  .card.is-link:hover { box-shadow: var(--shadow-sm); transform: translateY(-2px); }
}
.card.is-link { transition: box-shadow var(--t), transform var(--t); cursor: pointer; }

/* KPI. La cifra va en Sora: es la que se lee de lejos. */
.stat {
  display: grid; gap: 4px;
  padding: var(--space-4) var(--space-5);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); box-shadow: var(--shadow-xs);
  border-left: 4px solid var(--primary);
}
.stat .label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: none; }
.stat .value { font-family: var(--font-display); font-size: 28px; font-weight: 800; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.stat .delta { font-size: 12px; font-weight: 600; }
.stat .delta.up   { color: var(--success-fg); }
.stat .delta.down { color: var(--danger-fg); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 11px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 600; line-height: 1.6;
  background: var(--surface-2); color: var(--text);
  border: 1px solid transparent;
}
.badge .ico { width: 13px; height: 13px; }
.badge-blue    { background: var(--info-bg);    color: var(--info-fg); }
.badge-success { background: var(--success-bg); color: var(--success-fg); }
.badge-warning { background: var(--warning-bg); color: var(--warning-fg); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger-fg); }
.badge-muted   { background: var(--surface-2);  color: var(--text-muted); }
.badge-solid   { background: var(--primary);    color: #fff; }

/* ============================================================================
   TABLAS — en teléfono se convierten en tarjetas (ver ios.css).
   ============================================================================ */
.table-wrap { overflow-x: auto; border-radius: var(--r-lg); }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-weight: 700; color: var(--text-muted);
  font-size: 12px; padding: 10px 12px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
@media (hover: hover) { .table tbody tr:hover { background: var(--surface-2); } }
.table tbody tr:active { background: var(--surface-2); }

/* ============================================================================
   ESTADOS
   ============================================================================ */
.empty {
  display: grid; gap: 10px; justify-items: center; text-align: center;
  padding: var(--space-12) var(--space-5); color: var(--text-muted);
}
.empty .ico { width: 44px; height: 44px; opacity: .3; }
.empty h3 { color: var(--text-strong); }

.skeleton {
  border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: la-shimmer 1.4s ease infinite;
}
@keyframes la-shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }

.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--r-md);
  font-size: 13px; border: 1px solid transparent;
}
.alert-info    { background: var(--info-bg);    color: var(--info-fg); }
.alert-success { background: var(--success-bg); color: var(--success-fg); }
.alert-warning { background: var(--warning-bg); color: var(--warning-fg); }
.alert-error   { background: var(--danger-bg);  color: var(--danger-fg); }

/* ============================================================================
   MODAL — en teléfono se convierte en hoja inferior (ver ios.css).
   ============================================================================ */
.scrim {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(6, 24, 46, .45);
  backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none; transition: opacity var(--t);
}
.scrim.open { opacity: 1; pointer-events: auto; }

.modal {
  position: fixed; z-index: 61; inset: 0;
  display: grid; place-items: center; padding: var(--space-4);
  pointer-events: none;
}
.modal .sheet {
  width: min(100%, 560px); max-height: 88dvh; overflow: auto;
  background: var(--surface); border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  transform: translateY(12px) scale(.98); opacity: 0;
  transition: transform var(--t), opacity var(--t);
  pointer-events: auto;
}
.modal.sm .sheet { width: min(100%, 420px); }
.modal.open .sheet { transform: none; opacity: 1; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: var(--space-5); border-bottom: 1px solid var(--border); }
.sheet-head h2 { flex: 1; font-size: 17px; }
.sheet-body { padding: var(--space-5); }
.sheet-foot { display: flex; gap: 10px; justify-content: flex-end; padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); }
.sheet-handle { display: none; }

/* ============================================================================
   TOASTS
   ============================================================================ */
.toasts {
  position: fixed; z-index: 90;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: grid; gap: 8px; max-width: 380px;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-md); font-size: 13.5px;
  animation: la-toast-in .25s var(--ease-ios);
}
.toast.ok  { border-left: 4px solid var(--success); }
.toast.err { border-left: 4px solid var(--danger); }
@keyframes la-toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ── Sin animación si el sistema lo pide ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}
