/* Sistema de diseño Dukal Autos · tokens y componentes compartidos (chat público y administrador).
   Sin fuentes ni recursos externos: tipografía del sistema. */

:root {
  color-scheme: light dark;

  /* Tipografía */
  --fuente: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fuente-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --t-xs: .75rem;
  --t-sm: .875rem;
  --t-md: 1rem;
  --t-lg: 1.125rem;
  --t-xl: 1.375rem;
  --t-2xl: 1.75rem;

  /* Espaciado (escala de 4 px) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px;
  --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;

  /* Radios */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-pill: 999px;

  /* Color de marca (azul del logo, oscurecido para texto accesible) */
  --marca: #0b63bf;
  --marca-hover: #094f9a;
  --marca-suave: #e7f1fc;
  --marca-texto: #0a58aa;
  --acento: #00a9de;
  --sobre-marca: #ffffff;

  /* Superficies y texto */
  --bg: #f3f5f8;
  --sup: #ffffff;
  --sup-2: #f8fafc;
  --borde: #e1e6ed;
  --borde-fuerte: #c3ccd8;
  --texto: #111a26;
  --texto-2: #444f61;
  --texto-3: #5b677a;
  --foco: #1280df;
  --enlace: #0a58aa;

  /* Estados */
  --ok-bg: #e4f5ec; --ok-tx: #0d6338; --ok-bd: #b6e3cb;
  --warn-bg: #fff3d6; --warn-tx: #7d4a00; --warn-bd: #f0d596;
  --error-bg: #fde8e8; --error-tx: #a01919; --error-bd: #f3b9b9;
  --info-bg: #e7f1fc; --info-tx: #0a58aa; --info-bd: #b8d6f5;
  --neutro-bg: #edf0f4; --neutro-tx: #444f61; --neutro-bd: #d6dce5;
  --peligro: #c62828; --peligro-hover: #a31f1f;

  /* Barra lateral (oscura en ambos temas, como el logo) */
  --lateral-bg: #0e1620;
  --lateral-tx: #b9c4d3;
  --lateral-activo-bg: rgba(18, 128, 223, .2);

  /* Sombras */
  --sombra-1: 0 1px 2px rgba(15, 23, 42, .06);
  --sombra-2: 0 4px 14px rgba(15, 23, 42, .08);
  --sombra-3: 0 18px 48px rgba(15, 23, 42, .22);
}

@media (prefers-color-scheme: dark) {
  :root {
    --marca: #0b63bf;
    --marca-hover: #0d70d6;
    --marca-suave: #12304f;
    --marca-texto: #86c0ff;
    --bg: #0a1017;
    --sup: #121a24;
    --sup-2: #17212e;
    --borde: #243142;
    --borde-fuerte: #3a4b61;
    --texto: #e9eef4;
    --texto-2: #b0bbca;
    --texto-3: #93a0b3;
    --foco: #6db5ff;
    --enlace: #86c0ff;
    --ok-bg: #0f2e1f; --ok-tx: #72e2a4; --ok-bd: #1c5a3b;
    --warn-bg: #3a2a08; --warn-tx: #f4c76e; --warn-bd: #6b4d12;
    --error-bg: #3b1616; --error-tx: #ff9d9d; --error-bd: #7a2b2b;
    --info-bg: #12304f; --info-tx: #86c0ff; --info-bd: #1f4c7c;
    --neutro-bg: #1e2937; --neutro-tx: #b0bbca; --neutro-bd: #34445a;
    --peligro: #c62828; --peligro-hover: #dc3a3a;
    --lateral-bg: #070c12;
    --sombra-1: 0 1px 2px rgba(0, 0, 0, .4);
    --sombra-2: 0 4px 14px rgba(0, 0, 0, .35);
    --sombra-3: 0 18px 48px rgba(0, 0, 0, .6);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--fuente);
  font-size: var(--t-md);
  line-height: 1.5;
  color: var(--texto);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--enlace); }
img, svg { max-width: 100%; }
[hidden] { display: none !important; }
code { font-family: var(--fuente-mono); font-size: .9em; background: var(--neutro-bg); padding: 1px 6px; border-radius: var(--r-sm); }

:focus-visible { outline: 3px solid var(--foco); outline-offset: 2px; border-radius: var(--r-sm); }
.solo-lector { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.saltar { position: absolute; left: var(--sp-4); top: -80px; background: var(--sup); color: var(--texto); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); box-shadow: var(--sombra-2); z-index: 100; }
.saltar:focus { top: var(--sp-4); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 44px; padding: 0 var(--sp-4);
  font: inherit; font-size: var(--t-sm); font-weight: 600; line-height: 1.2;
  border: 1px solid transparent; border-radius: var(--r-md);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .15s, border-color .15s, box-shadow .15s;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primario { background: var(--marca); color: var(--sobre-marca); box-shadow: var(--sombra-1); }
.btn-primario:hover { background: var(--marca-hover); }
.btn-secundario { background: var(--sup); color: var(--texto); border-color: var(--borde-fuerte); }
.btn-secundario:hover { background: var(--sup-2); border-color: var(--texto-3); }
.btn-fantasma { background: transparent; color: var(--texto-2); }
.btn-fantasma:hover { background: var(--neutro-bg); color: var(--texto); }
.btn-peligro { background: var(--peligro); color: #fff; }
.btn-peligro:hover { background: var(--peligro-hover); }
.btn-peligro-suave { background: var(--sup); color: var(--error-tx); border-color: var(--error-bd); }
.btn-peligro-suave:hover { background: var(--error-bg); }
.btn-sm { font-size: var(--t-sm); padding: 0 var(--sp-3); }
.btn-icono { padding: 0; width: 44px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-cargando { position: relative; color: transparent !important; pointer-events: none; }
.btn-cargando::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff; animation: giro .7s linear infinite;
}
.btn-secundario.btn-cargando::after, .btn-fantasma.btn-cargando::after { border-color: var(--borde-fuerte); border-top-color: var(--marca); }
@media (pointer: fine) { .btn-sm { min-height: 36px; } }

@keyframes giro { to { transform: rotate(360deg); } }
.spinner { display: inline-block; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--borde-fuerte); border-top-color: var(--marca); animation: giro .7s linear infinite; }
@media (prefers-reduced-motion: reduce) {
  .spinner, .btn-cargando::after { animation-duration: 2.4s; }
}

/* ---------- Campos ---------- */
.campo { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.campo > label, .etiqueta { font-size: var(--t-sm); font-weight: 600; color: var(--texto); }
.campo .opcional { font-weight: 400; color: var(--texto-3); }
.ayuda { font-size: var(--t-sm); color: var(--texto-3); }
.error-campo { font-size: var(--t-sm); color: var(--error-tx); font-weight: 500; }
.entrada, .campo input[type="text"], .campo input[type="password"], .campo input[type="url"], .campo input[type="tel"],
.campo input[type="number"], .campo input[type="search"], .campo input[type="email"], .campo select, .campo textarea, .campo input:not([type]) {
  width: 100%; min-height: 44px; padding: 0 var(--sp-3);
  font: inherit; font-size: var(--t-md); color: var(--texto);
  background: var(--sup); border: 1px solid var(--borde-fuerte); border-radius: var(--r-md);
  transition: border-color .15s, box-shadow .15s;
}
.campo textarea { padding: var(--sp-3); min-height: 110px; resize: vertical; line-height: 1.45; }
.campo input::placeholder, .campo textarea::placeholder { color: var(--texto-3); opacity: 1; }
.campo input:hover, .campo select:hover, .campo textarea:hover { border-color: var(--texto-3); }
.campo input:focus-visible, .campo select:focus-visible, .campo textarea:focus-visible { outline: none; border-color: var(--foco); box-shadow: 0 0 0 3px color-mix(in srgb, var(--foco) 35%, transparent); }
.campo input:disabled, .campo select:disabled, .campo textarea:disabled { background: var(--neutro-bg); color: var(--texto-3); cursor: not-allowed; }
.campo.con-error input, .campo.con-error select, .campo.con-error textarea { border-color: var(--peligro); }
.campo input[type="file"] { padding: var(--sp-2) var(--sp-3); height: auto; }
.campo-clave { position: relative; }
.campo-clave input { padding-right: 48px !important; }
.campo-clave .ver { position: absolute; right: 2px; top: 0; bottom: 0; width: 44px; display: grid; place-items: center; background: none; border: 0; color: var(--texto-3); cursor: pointer; border-radius: var(--r-md); }
.campo-clave .ver:hover { color: var(--texto); }
.campo-clave .ver svg { width: 20px; height: 20px; }

.casilla { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-2) 0; cursor: pointer; font-size: var(--t-md); }
.casilla input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--marca); cursor: pointer; }
.casilla .ayuda { display: block; margin-top: 2px; }
/* Interruptor */
.interruptor { position: relative; display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; min-height: 44px; }
.interruptor input { position: absolute; opacity: 0; width: 44px; height: 44px; margin: 0; cursor: pointer; }
.interruptor .pista { width: 40px; height: 24px; border-radius: var(--r-pill); background: var(--borde-fuerte); position: relative; flex: none; transition: background-color .15s; }
.interruptor .pista::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--sombra-1); transition: transform .15s; }
.interruptor input:checked + .pista { background: var(--marca); }
.interruptor input:checked + .pista::after { transform: translateX(16px); }
.interruptor input:focus-visible + .pista { outline: 3px solid var(--foco); outline-offset: 2px; }
.interruptor input:disabled + .pista { opacity: .5; }
@media (prefers-reduced-motion: reduce) { .interruptor .pista, .interruptor .pista::after { transition: none; } }

.rejilla { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); align-items: start; }
.rejilla-2 { display: grid; gap: var(--sp-4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fila { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; }
.pila { display: flex; flex-direction: column; gap: var(--sp-4); }

/* ---------- Tarjetas ---------- */
.tarjeta { background: var(--sup); border: 1px solid var(--borde); border-radius: var(--r-lg); box-shadow: var(--sombra-1); }
.tarjeta-cabecera { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-5) var(--sp-6) 0; }
.tarjeta-cabecera h2, .tarjeta-cabecera h3 { font-size: var(--t-lg); }
.tarjeta-cabecera p { color: var(--texto-3); font-size: var(--t-sm); margin-top: var(--sp-1); }
.tarjeta-cuerpo { padding: var(--sp-5) var(--sp-6) var(--sp-6); }
.tarjeta-cuerpo.sin-relleno { padding: var(--sp-4) 0 0; }

/* ---------- Insignias ---------- */
.insignia { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; min-height: 24px; border-radius: var(--r-pill); font-size: var(--t-xs); font-weight: 600; line-height: 1.3; border: 1px solid transparent; white-space: nowrap; }
.insignia::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.insignia.sin-punto::before { display: none; }
.insignia-ok { background: var(--ok-bg); color: var(--ok-tx); border-color: var(--ok-bd); }
.insignia-warn { background: var(--warn-bg); color: var(--warn-tx); border-color: var(--warn-bd); }
.insignia-error { background: var(--error-bg); color: var(--error-tx); border-color: var(--error-bd); }
.insignia-info { background: var(--info-bg); color: var(--info-tx); border-color: var(--info-bd); }
.insignia-neutro { background: var(--neutro-bg); color: var(--neutro-tx); border-color: var(--neutro-bd); }

/* ---------- Alertas ---------- */
.alerta { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); border: 1px solid; font-size: var(--t-sm); line-height: 1.5; }
.alerta svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.alerta strong { font-weight: 700; }
.alerta-info { background: var(--info-bg); color: var(--info-tx); border-color: var(--info-bd); }
.alerta-ok { background: var(--ok-bg); color: var(--ok-tx); border-color: var(--ok-bd); }
.alerta-warn { background: var(--warn-bg); color: var(--warn-tx); border-color: var(--warn-bd); }
.alerta-error { background: var(--error-bg); color: var(--error-tx); border-color: var(--error-bd); }

/* ---------- Tablas ---------- */
.tabla-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabla { width: 100%; border-collapse: collapse; font-size: var(--t-sm); font-variant-numeric: tabular-nums; }
.tabla th { text-align: left; font-size: var(--t-xs); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--texto-3); padding: var(--sp-3) var(--sp-4); background: var(--sup-2); border-top: 1px solid var(--borde); border-bottom: 1px solid var(--borde); white-space: nowrap; }
.tabla td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--borde); vertical-align: middle; }
.tabla tbody tr:hover { background: var(--sup-2); }
.tabla tbody tr:last-child td { border-bottom: 0; }
.tabla .num { text-align: right; }
.tabla .acciones { text-align: right; white-space: nowrap; }
.tabla .acciones .btn + .btn { margin-left: var(--sp-1); }
.tabla .dato-principal { font-weight: 600; color: var(--texto); }
.tabla .secundario { color: var(--texto-3); font-size: var(--t-xs); display: block; }

/* ---------- Pestañas ---------- */
.pestanas { display: flex; flex-wrap: wrap; gap: var(--sp-1); border-bottom: 1px solid var(--borde); overflow-x: auto; }
.pestana { min-height: 44px; padding: 0 var(--sp-3); background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; font: inherit; font-size: var(--t-sm); font-weight: 600; color: var(--texto-3); cursor: pointer; white-space: nowrap; }
.pestana:hover { color: var(--texto); }
.pestana[aria-selected="true"] { color: var(--marca-texto); border-bottom-color: var(--marca); }

/* ---------- Diálogos ---------- */
dialog.dialogo { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--borde); border-radius: var(--r-lg); background: var(--sup); color: var(--texto); box-shadow: var(--sombra-3); }
dialog.dialogo::backdrop { background: rgba(8, 14, 22, .6); }
.dialogo-cab { padding: var(--sp-6) var(--sp-6) var(--sp-2); }
.dialogo-cab h2 { font-size: var(--t-xl); }
.dialogo-cuerpo { padding: var(--sp-2) var(--sp-6) var(--sp-4); color: var(--texto-2); display: flex; flex-direction: column; gap: var(--sp-4); }
.dialogo-pie { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-3); padding: var(--sp-4) var(--sp-6) var(--sp-6); }
@media (max-width: 480px) { .dialogo-pie .btn { flex: 1 1 100%; } }

/* ---------- Avisos emergentes (toast) ---------- */
.toasts { position: fixed; right: var(--sp-4); bottom: var(--sp-4); z-index: 200; display: flex; flex-direction: column; gap: var(--sp-2); width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4); background: var(--sup); color: var(--texto); border: 1px solid var(--borde); border-left-width: 4px; border-radius: var(--r-md); box-shadow: var(--sombra-2); font-size: var(--t-sm); animation: entra .2s ease-out; }
.toast svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.toast-ok { border-left-color: #1f9d5b; } .toast-ok svg { color: #1f9d5b; }
.toast-error { border-left-color: var(--peligro); } .toast-error svg { color: var(--peligro); }
.toast-info { border-left-color: var(--marca); } .toast-info svg { color: var(--marca-texto); }
.toast button { margin-left: auto; background: none; border: 0; color: var(--texto-3); cursor: pointer; padding: 4px; border-radius: var(--r-sm); min-width: 28px; min-height: 28px; }
@keyframes entra { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- Esqueletos y estados vacíos ---------- */
.esqueleto { background: linear-gradient(90deg, var(--neutro-bg) 25%, var(--sup-2) 50%, var(--neutro-bg) 75%); background-size: 200% 100%; animation: brillo 1.4s ease-in-out infinite; border-radius: var(--r-md); min-height: 16px; }
@keyframes brillo { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .esqueleto { animation: none; } }
.vacio { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-3); padding: var(--sp-10) var(--sp-6); color: var(--texto-2); }
.vacio svg { width: 40px; height: 40px; color: var(--texto-3); }
.vacio h3 { font-size: var(--t-lg); color: var(--texto); }
.vacio p { max-width: 44ch; color: var(--texto-3); }
