/* ============================================================
   css/temas.css — Temas de color de Catanet
   ------------------------------------------------------------
   ÚNICA fuente de colores del sistema. Las páginas usan siempre
   var(--token); los únicos colores fijos permitidos son los
   semánticos: insignias de calificación, escala de color 1-9,
   recuadro de la firma y la "hoja carta" del dictamen.

   Temas: claro (por defecto), oscuro, marino y agave.
   El tema activo va en <html data-tema="...">: lo imprime PHP
   desde la cookie "catanet_tema" o, si no hay cookie, lo decide
   el script del <head> (includes/tema.php) antes de cargar este CSS.

   Convención de uso:
     --primary / --on-primary  -> FONDOS de marca (botones, pestaña activa)
     --link                    -> TEXTO de marca (enlaces, títulos de color)
     --nav-*                   -> navbar, footer y bloques "oscuros" (bienvenida, marcador)
   ============================================================ */

/* ---------- CLARO (por defecto) ---------- */
:root,
html[data-tema="claro"] {
    color-scheme: light;
    --bg: #f4f7f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #1f2937;
    --text-muted: #667080;
    --border: #e5e7eb;
    --nav-bg: #002d62;
    --nav-text: #ffffff;
    --primary: #002d62;
    --primary-hover: #001f44;
    --on-primary: #ffffff;
    --accent: #c5a022;
    --on-accent: #002d62;
    --link: #002d62;
    --input-bg: #ffffff;
    --exito-bg: #def7ec;  --exito-txt: #03543f;  --exito-borde: #bfecdb;
    --error-bg: #fde8e8;  --error-txt: #9b1c1c;  --error-borde: #f8b4b4;
    --aviso-bg: #fef3c7;  --aviso-txt: #92400e;  --aviso-borde: #fde68a;

    /* Auxiliares (derivados de la tabla de arriba) */
    --input-borde: #858d99;          /* borde de campos */
    --seleccion-bg: #eef4ff;         /* opción / aroma marcado */
    --info-bg: #f0f7ff;  --info-txt: #004085;  --info-borde: #cce4ff;
    --peligro: #c81e1e;              /* rojo semántico: defectos y descuentos negativos */
    --peligro-bg: #fdf8f8;  --peligro-borde: #f8b4b4;
    --ok-txt: #057a55;               /* descuento 0 */
    --medio-txt: #92400e;            /* descuento -0.5 */
    --nav-acento: #c5a022;           /* dorado legible sobre --nav-bg */
    --nav-peligro: #ff8a8a;          /* "Salir" y negativos sobre --nav-bg */
    --sombra: rgba(0, 0, 0, 0.08);
}

/* ---------- OSCURO ---------- */
html[data-tema="oscuro"] {
    color-scheme: dark;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #273449;
    --text: #e5e7eb;
    --text-muted: #94a3b8;
    --border: #334155;
    --nav-bg: #0b1220;
    --nav-text: #e5e7eb;
    --primary: #3b6fd8;
    --primary-hover: #2f5bb5;
    --on-primary: #ffffff;
    --accent: #d4af37;
    --on-accent: #111827;
    --link: #93c5fd;
    --input-bg: #0f172a;
    --exito-bg: #064e3b;  --exito-txt: #a7f3d0;  --exito-borde: #047857;
    --error-bg: #7f1d1d;  --error-txt: #fecaca;  --error-borde: #b91c1c;
    --aviso-bg: #78350f;  --aviso-txt: #fde68a;  --aviso-borde: #b45309;

    --input-borde: #7b8ba3;
    --seleccion-bg: #1e3a5f;
    --info-bg: #172554;  --info-txt: #bfdbfe;  --info-borde: #1e40af;
    --peligro: #f87171;
    --peligro-bg: rgba(248, 113, 113, 0.12);  --peligro-borde: rgba(248, 113, 113, 0.5);
    --ok-txt: #34d399;
    --medio-txt: #fbbf24;
    --nav-acento: #d4af37;
    --nav-peligro: #f87171;
    --sombra: rgba(0, 0, 0, 0.45);
}

/* ---------- AZUL MARINO ---------- */
html[data-tema="marino"] {
    color-scheme: dark;
    --bg: #0a1f3d;
    --surface: #102a4c;
    --surface-2: #16365f;
    --text: #f1f5f9;
    --text-muted: #a9b8cc;
    --border: #24466f;
    --nav-bg: #061630;
    --nav-text: #f1f5f9;
    --primary: #c5a022;
    --primary-hover: #d9b437;
    --on-primary: #0a1f3d;
    --accent: #c5a022;
    --on-accent: #0a1f3d;
    --link: #f2d675;
    --input-bg: #0c2445;
    --exito-bg: #0f3d33;  --exito-txt: #a7f3d0;  --exito-borde: #1b6b57;
    --error-bg: #4a1620;  --error-txt: #fecaca;  --error-borde: #8a2a3a;
    --aviso-bg: #4a3a10;  --aviso-txt: #fde68a;  --aviso-borde: #7a6119;

    --input-borde: #6d90be;
    --seleccion-bg: #1d4271;
    --info-bg: #12345c;  --info-txt: #dbeafe;  --info-borde: #2b5a8f;
    --peligro: #fa8585;
    --peligro-bg: rgba(248, 113, 113, 0.12);  --peligro-borde: rgba(248, 113, 113, 0.5);
    --ok-txt: #34d399;
    --medio-txt: #fbbf24;
    --nav-acento: #e0bc45;
    --nav-peligro: #ff9b9b;
    --sombra: rgba(0, 0, 0, 0.45);
}

/* ---------- AGAVE ---------- */
html[data-tema="agave"] {
    color-scheme: light;
    --bg: #eef3ef;
    --surface: #ffffff;
    --surface-2: #f4f8f5;
    --text: #1d2b24;
    --text-muted: #5b6b62;
    --border: #d3dfd7;
    --nav-bg: #2f5d50;
    --nav-text: #ffffff;
    --primary: #2f5d50;
    --primary-hover: #24493f;
    --on-primary: #ffffff;
    --accent: #b9853a;
    --on-accent: #1d2b24;
    --link: #2f5d50;
    --input-bg: #ffffff;
    --exito-bg: #dcefe2;  --exito-txt: #1f5135;  --exito-borde: #b6dcc3;
    --error-bg: #fbe5e1;  --error-txt: #8f2a1c;  --error-borde: #f2c1b8;
    --aviso-bg: #fbf0d9;  --aviso-txt: #7a4b12;  --aviso-borde: #efd9a8;

    --input-borde: #7a8e82;
    --seleccion-bg: #e2efe7;
    --info-bg: #eaf3ee;  --info-txt: #24493f;  --info-borde: #c4dccd;
    --peligro: #c81e1e;
    --peligro-bg: #fdf3f1;  --peligro-borde: #f2c1b8;
    --ok-txt: #057a55;
    --medio-txt: #92400e;
    --nav-acento: #f0c674;           /* el ocre #b9853a no se lee sobre el verde del navbar */
    --nav-peligro: #ffd1c9;
    --sombra: rgba(0, 0, 0, 0.08);
}

/* ---------- AL IMPRIMIR: SIEMPRE el tema claro ----------
   Va después de los temas: misma especificidad, gana por orden. */
@media print {
    :root,
    html[data-tema] {
        color-scheme: light;
        --bg: #ffffff;
        --surface: #ffffff;
        --surface-2: #f8fafc;
        --text: #1f2937;
        --text-muted: #667080;
        --border: #e5e7eb;
        --nav-bg: #002d62;
        --nav-text: #ffffff;
        --primary: #002d62;
        --primary-hover: #001f44;
        --on-primary: #ffffff;
        --accent: #c5a022;
        --on-accent: #002d62;
        --link: #002d62;
        --input-bg: #ffffff;
        --exito-bg: #def7ec;  --exito-txt: #03543f;  --exito-borde: #bfecdb;
        --error-bg: #fde8e8;  --error-txt: #9b1c1c;  --error-borde: #f8b4b4;
        --aviso-bg: #fef3c7;  --aviso-txt: #92400e;  --aviso-borde: #fde68a;
        --input-borde: #858d99;
        --seleccion-bg: #eef4ff;
        --info-bg: #f0f7ff;  --info-txt: #004085;  --info-borde: #cce4ff;
        --peligro: #c81e1e;
        --peligro-bg: #fdf8f8;  --peligro-borde: #f8b4b4;
        --ok-txt: #057a55;
        --medio-txt: #92400e;
        --nav-acento: #c5a022;
        --nav-peligro: #ff8a8a;
        --sombra: rgba(0, 0, 0, 0.08);
    }
}

/* ============================================================
   ESTILOS BASE TEMATIZADOS (las páginas pueden sobrescribirlos)
   ============================================================ */
body { background-color: var(--bg); color: var(--text); }
a { color: var(--link); }

/* :where() deja la especificidad en cero: cualquier regla de la página gana */
:where(input:not([type="radio"]):not([type="checkbox"]):not([type="hidden"]):not([type="range"]):not([type="color"]), select, textarea) {
    background-color: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--input-borde);
}
:where(input:disabled, input[readonly], select:disabled, textarea[readonly]) {
    background-color: var(--surface-2);
    color: var(--text-muted);
}
::placeholder { color: var(--text-muted); opacity: 1; }

/* Transición suave SOLO mientras se cambia de tema (la clase la pone el JS
   del selector unos milisegundos), así no interfiere con otras animaciones. */
html.cambiando-tema,
html.cambiando-tema *,
html.cambiando-tema *::before,
html.cambiando-tema *::after {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease !important;
}
@media (prefers-reduced-motion: reduce) {
    html.cambiando-tema,
    html.cambiando-tema *,
    html.cambiando-tema *::before,
    html.cambiando-tema *::after { transition: none !important; }
}

/* ============================================================
   SELECTOR DE TEMA (includes/selector_tema.php)
   Un botón pequeño fijo arriba a la derecha; al tocarlo despliega
   la lista de temas. Las páginas reservan ese rincón:
   header.php deja padding a la derecha del navbar.
   ============================================================ */
.selector-tema {
    position: fixed;
    top: calc(14px + env(safe-area-inset-top, 0px));
    right: calc(14px + env(safe-area-inset-right, 0px));
    z-index: 1000;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Botón que abre / cierra la lista */
.tema-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; min-height: 40px; padding: 0; margin: 0;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    cursor: pointer;
}
.tema-toggle svg { width: 22px; height: 22px; display: block; }
.tema-toggle:hover { background: var(--surface-2); }
.tema-toggle[aria-expanded="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--link); }

/* Lista desplegable */
.tema-panel {
    position: absolute; top: calc(100% + 8px); right: 0;
    min-width: 170px; padding: 6px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}
.tema-panel[hidden] { display: none; }
.tema-panel__titulo { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; padding: 4px 8px 6px; }

.tema-btn {
    display: flex; align-items: center; gap: 10px;
    width: 100%; min-height: 40px; padding: 6px 8px; margin: 0;
    background: none; color: var(--text); border: none; border-radius: 6px;
    font-size: 14px; text-align: left; cursor: pointer;
}
.tema-btn:hover { background: var(--surface-2); }
.tema-btn[aria-pressed="true"] { font-weight: 700; background: var(--seleccion-bg); }
.tema-btn[aria-pressed="true"]::after { content: '✓'; margin-left: auto; color: var(--link); }

.tema-toggle:focus-visible,
.tema-btn:focus-visible { outline: 3px solid var(--link); outline-offset: 1px; }

.tema-muestra {
    display: block; flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%;
    border: 1px solid rgba(127, 127, 127, 0.6);
}
/* Tema activo: anillo doble (se ve en fondos claros y oscuros) */
.tema-btn[aria-pressed="true"] .tema-muestra { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }

/* Cada muestra enseña los colores de su tema:
   fondo de página / color principal / acento */
.tema-muestra--claro  { background: linear-gradient(135deg, #f4f7f9 0 50%, #002d62 50% 78%, #c5a022 78%); }
.tema-muestra--oscuro { background: linear-gradient(135deg, #1e293b 0 50%, #3b6fd8 50% 78%, #d4af37 78%); }
.tema-muestra--marino { background: linear-gradient(135deg, #0a1f3d 0 50%, #16365f 50% 78%, #c5a022 78%); }
.tema-muestra--agave  { background: linear-gradient(135deg, #eef3ef 0 50%, #2f5d50 50% 78%, #b9853a 78%); }

/* Celular: un poco más pegado a la esquina */
@media screen and (max-width: 768px) {
    .selector-tema {
        top: calc(12px + env(safe-area-inset-top, 0px));
        right: calc(10px + env(safe-area-inset-right, 0px));
    }
}

@media print {
    .selector-tema { display: none !important; }
}
