/* =====================================================================
   Panel de Loterías — CSS base con variables.
   Los tokens se redefinen por cada tema. body[data-tema="..."] elige.
   Los tokens de tipografía y radios son globales (no cambian por tema).
   ===================================================================== */

/* ---------- Tokens NO-color (comunes a todos los temas) ---------- */
:root {
    /* Interfaz plana y densa: sin esquinas redondeadas ni sombras. */
    --radio-boton:         0;
    --radio-card:          0;
    --sombra-card:         none;
    --sombra-flotante:     0 2px 8px rgba(20, 30, 60, .20);

    --tipo-familia:        system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --tipo-familia-mono:   ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
    --tipo-tam:            13px;
    --tipo-tam-titulo:     16px;
    --tipo-tam-pequeno:    12px;
}

/* ---------- TEMAS ---------- */
/* Los tokens comunes se listan aquí, cada tema los redefine.            */
/* --color-input-bg / --color-input-borde permiten que dark themes       */
/*    no queden con inputs blancos.                                      */
/* --auth-fondo es el gradiente por defecto del login (se sobreescribe   */
/*    con una imagen subida por el operador).                            */

/* == 1. claro_azul (por defecto) == */
:root, [data-tema="claro_azul"] {
    --color-bg:            #f4f6fb;
    --color-superficie:    #ffffff;
    --color-borde:         #e2e6ef;
    --color-texto:         #202533;
    --color-texto-suave:   #5c667a;
    --color-primario:      #2f5bff;
    --color-primario-h:    #234ce6;
    --color-primario-txt:  #ffffff;
    --color-input-bg:      #ffffff;
    --color-input-borde:   #d5dbe6;
    --color-input-txt:     #202533;
    --color-ok:            #1b8f3a;
    --color-warn:          #b26a00;
    --color-error:         #c22b2b;
    --color-menu-bg:       #1a2138;
    --color-menu-txt:      #cfd6ea;
    --color-menu-txt-h:    #ffffff;
    --color-menu-activo:   #2f5bff;
    --auth-fondo:          linear-gradient(135deg, #2f5bff 0%, #6a8dff 60%, #a4c0ff 100%);
}

/* == 2. claro_esmeralda == */
[data-tema="claro_esmeralda"] {
    --color-bg:            #f2f8f5;
    --color-superficie:    #ffffff;
    --color-borde:         #dbe7e1;
    --color-texto:         #1c2a24;
    --color-texto-suave:   #56685e;
    --color-primario:      #0e9f6e;
    --color-primario-h:    #0b8760;
    --color-primario-txt:  #ffffff;
    --color-input-bg:      #ffffff;
    --color-input-borde:   #ced9d3;
    --color-input-txt:     #1c2a24;
    --color-ok:            #1b8f3a;
    --color-warn:          #b26a00;
    --color-error:         #c22b2b;
    --color-menu-bg:       #123028;
    --color-menu-txt:      #c8dcd2;
    --color-menu-txt-h:    #ffffff;
    --color-menu-activo:   #0e9f6e;
    --auth-fondo:          linear-gradient(135deg, #0e9f6e 0%, #3fb98f 60%, #a5e5cd 100%);
}

/* == 3. claro_ambar == */
[data-tema="claro_ambar"] {
    --color-bg:            #fbf7f0;
    --color-superficie:    #ffffff;
    --color-borde:         #ece0cd;
    --color-texto:         #2a2318;
    --color-texto-suave:   #6a5f4d;
    --color-primario:      #d97706;
    --color-primario-h:    #b96305;
    --color-primario-txt:  #ffffff;
    --color-input-bg:      #ffffff;
    --color-input-borde:   #e2d5bd;
    --color-input-txt:     #2a2318;
    --color-ok:            #1b8f3a;
    --color-warn:          #b26a00;
    --color-error:         #c22b2b;
    --color-menu-bg:       #2a1e10;
    --color-menu-txt:      #e5d3b8;
    --color-menu-txt-h:    #ffffff;
    --color-menu-activo:   #d97706;
    --auth-fondo:          linear-gradient(135deg, #d97706 0%, #f0a141 60%, #ffd9a3 100%);
}

/* == 4. oscuro_zafiro == */
[data-tema="oscuro_zafiro"] {
    --color-bg:            #0f1526;
    --color-superficie:    #182036;
    --color-borde:         #2a334f;
    --color-texto:         #e5eaf5;
    --color-texto-suave:   #9aa4bf;
    --color-primario:      #5b7fff;
    --color-primario-h:    #7391ff;
    --color-primario-txt:  #ffffff;
    --color-input-bg:      #101731;
    --color-input-borde:   #2f3a5c;
    --color-input-txt:     #e5eaf5;
    --color-ok:            #35c069;
    --color-warn:          #eab364;
    --color-error:         #f26d6d;
    --color-menu-bg:       #0a0f1e;
    --color-menu-txt:      #a3adca;
    --color-menu-txt-h:    #ffffff;
    --color-menu-activo:   #5b7fff;
    --auth-fondo:          linear-gradient(135deg, #0a0f1e 0%, #24325c 55%, #5b7fff 100%);
}

/* == 5. oscuro_ciruela == */
[data-tema="oscuro_ciruela"] {
    --color-bg:            #1a1122;
    --color-superficie:    #24172f;
    --color-borde:         #3a2848;
    --color-texto:         #f0e6f5;
    --color-texto-suave:   #a598b0;
    --color-primario:      #c266ff;
    --color-primario-h:    #d283ff;
    --color-primario-txt:  #180a20;
    --color-input-bg:      #170d1e;
    --color-input-borde:   #43304f;
    --color-input-txt:     #f0e6f5;
    --color-ok:            #6ecd7f;
    --color-warn:          #f0b95c;
    --color-error:         #ff7d7d;
    --color-menu-bg:       #100716;
    --color-menu-txt:      #b8a7c5;
    --color-menu-txt-h:    #ffffff;
    --color-menu-activo:   #c266ff;
    --auth-fondo:          linear-gradient(135deg, #100716 0%, #3d1f4f 55%, #c266ff 100%);
}

/* == 6. oscuro_bosque == */
[data-tema="oscuro_bosque"] {
    --color-bg:            #0e1a15;
    --color-superficie:    #16241e;
    --color-borde:         #263a30;
    --color-texto:         #e0eee6;
    --color-texto-suave:   #92a89a;
    --color-primario:      #34d399;
    --color-primario-h:    #56dfaa;
    --color-primario-txt:  #05170f;
    --color-input-bg:      #0e1d17;
    --color-input-borde:   #2e4438;
    --color-input-txt:     #e0eee6;
    --color-ok:            #56e08c;
    --color-warn:          #ecbc63;
    --color-error:         #ff7f7f;
    --color-menu-bg:       #07110c;
    --color-menu-txt:      #9ec1ac;
    --color-menu-txt-h:    #ffffff;
    --color-menu-activo:   #34d399;
    --auth-fondo:          linear-gradient(135deg, #07110c 0%, #163a2a 55%, #34d399 100%);
}

/* ---------- Reset mínimo ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--color-bg);
    color: var(--color-texto);
    font-family: var(--tipo-familia);
    font-size: var(--tipo-tam);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--color-primario); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout autenticado (sidebar + main) ---------- */
.app { display: grid; grid-template-columns: 180px 1fr; min-height: 100vh; }

.sidebar {
    background: var(--color-menu-bg);
    color: var(--color-menu-txt);
    padding: 0 0 12px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255,255,255,.14);
}
.brand-text { font-weight: 600; font-size: 13px; color: var(--color-menu-txt-h); }

/* Menu plano: filas seguidas separadas por linea, sin bordes redondeados
   ni animaciones. Se lee como una lista, no como botones flotantes. */
.menu { display: flex; flex-direction: column; padding: 0; gap: 0; }
.menu-item {
    display: flex; align-items: center; gap: 7px;
    padding: 6px 12px;
    border-radius: 0;
    border-bottom: 1px solid rgba(255,255,255,.06);
    color: var(--color-menu-txt);
    font-size: 12px;
    line-height: 1.5;
}
.menu-item:hover { background: rgba(255,255,255,.08); color: var(--color-menu-txt-h); text-decoration: none; }
.menu-item.is-active { background: var(--color-menu-activo); color: var(--color-primario-txt); font-weight: 600; }
.menu-item.is-disabled { opacity: .5; pointer-events: none; }
.menu-item small { margin-left: auto; font-size: 10px; opacity: .7; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
    background: var(--color-superficie);
    border-bottom: 1px solid var(--color-borde);
    padding: 6px 14px;
    display: flex; align-items: center; justify-content: space-between;
}
.topbar-titulo { margin: 0; font-size: var(--tipo-tam-titulo); font-weight: 600; }
.topbar-usuario { display: flex; align-items: center; gap: 10px; }
.usuario-nombre { color: var(--color-texto-suave); font-size: 12px; }
.logout-form { margin: 0; }

.container { padding: 12px 14px; max-width: 1400px; }

/* ---------- Cards + grid ---------- */
.card {
    background: var(--color-superficie);
    border: 1px solid var(--color-borde);
    border-radius: var(--radio-card);
    padding: 10px 12px;
    box-shadow: var(--sombra-card);
    margin-bottom: 10px;
}
.card-titulo { margin: 0 0 8px; font-size: 13px; font-weight: 600; }

.grid { display: grid; gap: 8px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .grid-4, .grid-3 { grid-template-columns: 1fr; } }

.kpi { text-align: center; padding: 8px 6px; }
.kpi-num { font-size: 17px; font-weight: 600; color: var(--color-primario); line-height: 1.2; }
.kpi-lbl { color: var(--color-texto-suave); margin-top: 2px; font-size: 11px; }

.tabla-clave-valor { width: 100%; border-collapse: collapse; }
.tabla-clave-valor th, .tabla-clave-valor td { padding: 4px 6px; text-align: left; border-bottom: 1px solid var(--color-borde); }
.tabla-clave-valor th { font-weight: 500; color: var(--color-texto-suave); width: 180px; }
.tabla-clave-valor tr:last-child th, .tabla-clave-valor tr:last-child td { border-bottom: 0; }

.muted { color: var(--color-texto-suave); }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 5px 11px;
    border-radius: var(--radio-boton);
    border: 1px solid transparent;
    background: transparent;
    color: var(--color-texto);
    font: inherit; font-size: 12px; font-weight: 500;
    cursor: pointer;
}
.btn-primario { background: var(--color-primario); color: var(--color-primario-txt); }
.btn-primario:hover { background: var(--color-primario-h); }
.btn-ghost { border: 1px solid var(--color-borde); color: var(--color-texto-suave); padding: 4px 10px; background: transparent; }
.btn-ghost:hover { background: var(--color-bg); color: var(--color-texto); }
.btn-peligro { background: var(--color-error); color: #ffffff; }
.btn-peligro:hover { filter: brightness(.92); }
.btn-block { display: flex; width: 100%; }

/* ---------- Formularios ---------- */
.form { display: flex; flex-direction: column; gap: 8px; max-width: 560px; }
.campo { display: flex; flex-direction: column; gap: 3px; }
.campo-label { font-size: 11px; font-weight: 500; color: var(--color-texto-suave); }
.campo-ayuda { font-size: 11px; color: var(--color-texto-suave); }
.campo input[type="text"], .campo input[type="password"], .campo input[type="number"],
.campo input[type="email"], .campo input[type="date"], .campo input[type="file"],
.campo select, .campo textarea {
    background: var(--color-input-bg);
    border: 1px solid var(--color-input-borde);
    border-radius: 0;
    padding: 4px 7px;
    font-size: 12px;
    font: inherit; color: var(--color-input-txt);

}
.campo input:focus, .campo select:focus, .campo textarea:focus {
    outline: none;
    border-color: var(--color-primario);
    box-shadow: 0 0 0 3px rgba(120, 150, 255, .18);
}
.row { display: flex; gap: 10px; align-items: center; }
.acciones { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

/* ---------- Flash messages ---------- */
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.flash {
    padding: 12px 16px;
    border-radius: 0;
    border: 1px solid var(--color-borde);
    background: var(--color-superficie);
    font-size: 14px;
}
.flash-ok    { border-color: color-mix(in srgb, var(--color-ok)    35%, transparent); background: color-mix(in srgb, var(--color-ok)    12%, transparent); color: var(--color-ok); }
.flash-error { border-color: color-mix(in srgb, var(--color-error) 35%, transparent); background: color-mix(in srgb, var(--color-error) 12%, transparent); color: var(--color-error); }
.flash-warn  { border-color: color-mix(in srgb, var(--color-warn)  35%, transparent); background: color-mix(in srgb, var(--color-warn)  12%, transparent); color: var(--color-warn); }

/* ---------- Login ---------- */
.body-auth { min-height: 100vh; }
.auth-bg {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    background: var(--auth-fondo);
    background-size: cover; background-position: center;
}
.auth-card {
    background: var(--color-superficie);
    padding: 32px 30px 28px;
    border-radius: 0;
    box-shadow: var(--sombra-flotante);
    width: 100%; max-width: 380px;
}
.auth-brand { margin-bottom: 22px; text-align: center; }
.auth-titulo { margin: 0; font-size: 20px; font-weight: 600; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form input { font-size: 15px; }
.auth-pie { text-align: center; color: var(--color-texto-suave); margin: 20px 0 0; font-size: 12px; }

/* ---------- Selector de tema (Fase 6) ---------- */
.temas-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 700px) { .temas-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px) { .temas-grid { grid-template-columns: 1fr; } }

.tema-opcion { position: relative; }
.tema-opcion input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.tema-card {
    display: block;
    border: 2px solid var(--color-borde);
    border-radius: 0;
    padding: 12px;
    cursor: pointer;
    background: var(--color-superficie);

}
.tema-card:hover { border-color: var(--color-primario); }
.tema-opcion input[type="radio"]:checked + .tema-card {
    border-color: var(--color-primario);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primario) 25%, transparent);
}
.tema-preview {
    height: 60px; border-radius: 0; margin-bottom: 8px;
    display: flex; overflow: hidden;
}
.tema-preview span { flex: 1; }
.tema-nombre { font-size: 13px; font-weight: 500; text-align: center; }
.tema-desc { font-size: 11px; color: var(--color-texto-suave); text-align: center; }

/* ---------- Timeline y pills de estado ---------- */
.timeline { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.timeline-fila { display: flex; align-items: center; gap: 12px; }
.timeline-loteria {
    min-width: 180px;
    font-weight: 500;
    color: var(--color-texto);
    padding-right: 12px;
    border-right: 1px solid var(--color-borde);
}
.timeline-pills { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }

.pill {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px;
    border-radius: 0;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--color-borde);
    background: var(--color-bg);
    color: var(--color-texto-suave);
    min-width: 70px;
    justify-content: center;
    white-space: nowrap;
}
.pill strong { color: var(--color-texto); font-weight: 600; }

/* Colores por estado — usan mezclas de tokens para adaptarse al tema. */
.pill-programado { background: color-mix(in srgb, var(--color-texto-suave) 12%, transparent); color: var(--color-texto-suave); border-color: color-mix(in srgb, var(--color-texto-suave) 35%, transparent); }
.pill-pending    { background: color-mix(in srgb, var(--color-warn) 15%, transparent);        color: var(--color-warn);        border-color: color-mix(in srgb, var(--color-warn) 40%, transparent); }
.pill-processing { background: color-mix(in srgb, var(--color-primario) 18%, transparent);    color: var(--color-primario);    border-color: color-mix(in srgb, var(--color-primario) 45%, transparent); }
.pill-done       { background: color-mix(in srgb, var(--color-ok) 15%, transparent);          color: var(--color-ok);          border-color: color-mix(in srgb, var(--color-ok) 45%, transparent); }
.pill-partial    { background: color-mix(in srgb, var(--color-warn) 18%, transparent);        color: var(--color-warn);        border-color: color-mix(in srgb, var(--color-warn) 50%, transparent); }
.pill-failed     { background: color-mix(in srgb, var(--color-error) 15%, transparent);       color: var(--color-error);       border-color: color-mix(in srgb, var(--color-error) 45%, transparent); }
.pill-skipped    { background: color-mix(in srgb, var(--color-texto-suave) 10%, transparent); color: var(--color-texto-suave); border-color: color-mix(in srgb, var(--color-texto-suave) 30%, transparent); }
.pill-canceled   { background: color-mix(in srgb, var(--color-texto-suave) 10%, transparent); color: var(--color-texto-suave); border-color: color-mix(in srgb, var(--color-texto-suave) 30%, transparent); }

.pill-leyenda { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; font-size: 11px; }

/* ---------- Tabla de cola / intentos ---------- */
.tabla-cola th, .tabla-cola td { padding: 8px 10px; font-size: 13px; }
.tabla-cola thead th { color: var(--color-texto-suave); font-weight: 500; text-align: left; border-bottom: 1px solid var(--color-borde); }
.tabla-cola tbody tr:hover { background: color-mix(in srgb, var(--color-primario) 5%, transparent); }
.tabla-cola code { font-family: var(--tipo-familia-mono); font-size: 12px; }

/* ---------- Grid catálogo de animales ---------- */
.grid-animales {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 10px;
}
.animal-cell {
    display: block;
    text-align: center;
    padding: 8px 6px;
    border: 1px solid var(--color-borde);
    border-radius: 0;
    background: var(--color-superficie);
    color: var(--color-texto);

}
.animal-cell:hover { border-color: var(--color-primario); text-decoration: none; box-shadow: var(--sombra-card); }
.animal-cell.empty { opacity: .55; }
.animal-cell.has-img { border-color: color-mix(in srgb, var(--color-ok) 40%, var(--color-borde)); }
.animal-cell.sin-img { border-color: color-mix(in srgb, var(--color-warn) 45%, var(--color-borde)); }
.animal-falta {
    width: 100%; aspect-ratio: 1/1; margin-bottom: 6px;
    display: flex; align-items: center; justify-content: center;
    background: var(--color-bg); color: var(--color-warn);
    font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
}
.animal-cell img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 0; margin-bottom: 6px; background: var(--color-bg); }
.animal-num { font-weight: 600; font-size: 15px; }
.animal-nom { font-size: 11px; color: var(--color-texto-suave); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Grid de agenda (fechas × sorteos) ---------- */
.agenda { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
.agenda th, .agenda td { border-bottom: 1px solid var(--color-borde); border-right: 1px solid var(--color-borde); padding: 6px 8px; text-align: center; }
.agenda thead th { background: var(--color-bg); font-weight: 500; color: var(--color-texto-suave); position: sticky; top: 0; }
.agenda th.sticky { position: sticky; left: 0; background: var(--color-superficie); text-align: left; z-index: 1; min-width: 130px; }
.agenda thead th.sticky { background: var(--color-bg); z-index: 2; }
.agenda input {
    width: 46px; padding: 4px 6px; text-align: center;
    border: 1px solid var(--color-input-borde);
    background: var(--color-input-bg); color: var(--color-input-txt);
    border-radius: 0; font: inherit;
}
.agenda input:focus { outline: none; border-color: var(--color-primario); box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primario) 25%, transparent); }
.agenda input[readonly] { opacity: 0.7; cursor: not-allowed; }

.agenda-done    { background: color-mix(in srgb, var(--color-ok) 12%, transparent); }
.agenda-pending { background: color-mix(in srgb, var(--color-warn) 12%, transparent); }
.agenda-fail    { background: color-mix(in srgb, var(--color-error) 12%, transparent); }
.agenda-skip    { background: color-mix(in srgb, var(--color-texto-suave) 10%, transparent); }

/* ---------- Campo secreto con badge + botón Ver ---------- */
.campo-secreto .badge-secreto {
    display: inline-block; margin-left: 8px;
    padding: 2px 8px; border-radius: 0;
    font-size: 11px; font-weight: 500;
    border: 1px solid var(--color-borde);
}
.badge-secreto.badge-si { color: var(--color-ok); border-color: color-mix(in srgb, var(--color-ok) 40%, transparent); background: color-mix(in srgb, var(--color-ok) 12%, transparent); }
.badge-secreto.badge-no { color: var(--color-texto-suave); background: var(--color-bg); }
.input-secreto-wrap { display: flex; gap: 8px; align-items: stretch; }
.input-secreto-wrap input, .input-secreto-wrap textarea { flex: 1; }
.input-secreto-wrap .btn-secreto-ver { padding: 6px 12px; align-self: flex-start; white-space: nowrap; }

/* ---------- Login fondo actual preview ---------- */
.fondo-preview {
    width: 180px; height: 100px;
    border: 1px solid var(--color-borde);
    border-radius: 0;
    background-size: cover; background-position: center;
}

/* ---------- Ventas en vivo (Odisea) ---------- */
.reco-animal {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-width: 130px; padding: 16px 20px;
    border: 2px solid var(--color-ok); border-radius: 0;
    background: color-mix(in srgb, var(--color-ok) 10%, transparent);
}
.reco-num { font-size: 40px; font-weight: 700; line-height: 1; color: var(--color-ok); }
.reco-nom { margin-top: 6px; font-size: 13px; color: var(--color-texto-suave); text-align: center; }

.barra {
    height: 6px; width: 100%; border-radius: 0;
    background: color-mix(in srgb, var(--color-texto-suave) 18%, transparent);
    overflow: hidden;
}
.barra span { display: block; height: 100%; background: var(--color-primario); }

.tabla-cola tr.fila-reco    { background: color-mix(in srgb, var(--color-ok) 12%, transparent); }
.tabla-cola tr.fila-excede  { background: color-mix(in srgb, var(--color-error) 8%, transparent); }

/* ---------- Responsive ---------- */
@media (max-width: 780px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; }
    .topbar-titulo { font-size: 18px; }
    .container { padding: 16px; }
}
