/* =====================================================
   Colores (modo claro y oscuro)
   El modo lo pone static/js/app.js en <html data-bs-theme="light|dark">.
   ===================================================== */

:root, [data-bs-theme="light"] {
    --fondo: #f4f6f9;
    --tarjeta: #ffffff;
    --borde-suave: #eef0f3;
    --texto-2: #52514e;
    --texto-fuerte: #1f2a37;
    --verde: #198754;
    --lateral: #1f2a37;
    --lateral-hover: #2c3a4b;
    --lateral-texto: #dfe6ee;
    --lateral-tenue: #9aa7b6;
    --sombra: 0 1px 4px rgba(0, 0, 0, .06);
    /* gráficas: posiciones 1 y 2 de la paleta de referencia, pasos para fondo claro */
    --serie-entradas: #2a78d6;
    --serie-salidas: #eb6834;
    --grafica-texto: #52514e;
    --grafica-rejilla: #eef0f3;
}

[data-bs-theme="dark"] {
    --fondo: #11161c;
    --tarjeta: #1a2129;
    --borde-suave: #2a323c;
    --texto-2: #b7bec7;
    --texto-fuerte: #eef1f4;
    --verde: #3fb37f;
    --lateral: #0b1016;
    --lateral-hover: #1b2430;
    --lateral-texto: #dfe6ee;
    --lateral-tenue: #8794a3;
    --sombra: 0 1px 4px rgba(0, 0, 0, .35);
    /* mismos tonos, pasos para fondo oscuro */
    --serie-entradas: #3987e5;
    --serie-salidas: #d95926;
    --grafica-texto: #b7bec7;
    --grafica-rejilla: #2a323c;
    --bs-body-bg: #11161c;
}

body { background: var(--fondo); overflow-x: hidden; }

/* Solo mientras se cambia de modo: el cambio de colores es suave, no un parpadeo. */
.cambiando-tema, .cambiando-tema * {
    transition: background-color .3s ease, color .3s ease, border-color .3s ease !important;
}

/* =====================================================
   Barra lateral
   ===================================================== */

.sidebar {
    position: fixed; top: 0; left: 0;
    width: 232px; height: 100vh;
    background: var(--lateral); color: #fff;
    padding: 18px 12px 14px;
    display: flex; flex-direction: column; gap: 14px;
    overflow-y: auto;
}

.marca { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.marca .logo {
    width: 38px; height: 38px; border-radius: 10px; flex: none;
    display: grid; place-items: center;
    background: #0d6efd; font-size: 1.15rem;
}
.marca .nombre { font-weight: 700; font-size: 1.05rem; line-height: 1.1; }
.marca .sub { color: var(--lateral-tenue); font-size: .75rem; }

.menu { display: flex; flex-direction: column; gap: 4px; }
.sidebar .nav-link {
    position: relative;
    color: var(--lateral-texto); border-radius: 8px; padding: 9px 12px;
    transition: background-color .2s ease, color .2s ease, transform .15s ease;
}
.sidebar .nav-link i { margin-right: 10px; display: inline-block; transition: transform .2s ease; }
.sidebar .nav-link:hover { background: var(--lateral-hover); color: #fff; }
.sidebar .nav-link:hover i { transform: translateX(2px) scale(1.1); }
.sidebar .nav-link:active { transform: scale(.97); }
.sidebar .nav-link.active { background: #0d6efd; color: #fff; }
/* marca a la izquierda del elemento elegido: crece al entrar a la página */
.sidebar .nav-link.active::before {
    content: ""; position: absolute; left: -12px; top: 50%;
    width: 4px; height: 60%; border-radius: 0 4px 4px 0; background: #fff;
    transform: translateY(-50%);
    animation: crecer .35s ease both;
}

.titulo-lateral { color: var(--lateral-tenue); font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
                  padding: 0 8px; margin-bottom: 6px; }

/* Resumen de hoy en la barra (se actualiza solo) */
.hoy-lateral { background: var(--lateral-hover); border-radius: 10px; padding: 12px; font-size: .82rem; }
.hoy-lateral .fila { display: flex; justify-content: space-between; align-items: baseline; padding: 3px 0; }
.hoy-lateral .fila span:first-child { color: var(--lateral-tenue); }
.hoy-lateral .fila strong { font-size: .95rem; }
.hoy-lateral .estado { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; color: var(--lateral-texto); }
.punto { width: 9px; height: 9px; border-radius: 50%; background: #6c757d; flex: none; }
.punto.conectado { background: #3fb37f; box-shadow: 0 0 0 0 rgba(63, 179, 127, .6); animation: latido 2s infinite; }
.punto.sin_contacto { background: #f0ad4e; }
.punto.desconectado { background: #e5534b; }

/* Pie: usuario, modo claro/oscuro y salir */
.pie-lateral { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.usuario-lateral {
    display: flex; align-items: center; gap: 10px;
    background: var(--lateral-hover); border-radius: 10px; padding: 8px 10px;
}
.avatar {
    width: 32px; height: 32px; border-radius: 50%; flex: none;
    display: grid; place-items: center; font-weight: 700; text-transform: uppercase;
    background: #0d6efd; color: #fff; font-size: .9rem;
}
.usuario-lateral .datos { min-width: 0; flex: 1; line-height: 1.15; }
.usuario-lateral .datos div { font-weight: 600; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usuario-lateral .datos small { color: var(--lateral-tenue); font-size: .72rem; white-space: nowrap; }
.boton-lateral {
    border: none; background: transparent; color: var(--lateral-texto);
    width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; flex: none;
    transition: background-color .2s ease, transform .15s ease;
}
.boton-lateral:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.boton-lateral:active { transform: scale(.9); }
.boton-tema i { display: inline-block; transition: transform .4s ease; }
.boton-tema:hover i { transform: rotate(-25deg); }
.dispositivo-lateral { color: var(--lateral-tenue); font-size: .72rem; text-align: center; }

/* =====================================================
   Contenido
   ===================================================== */

.contenido { margin-left: 232px; padding: 28px; }

.card { border: none; border-radius: 12px; box-shadow: var(--sombra); background: var(--tarjeta);
        transition: box-shadow .2s ease, transform .2s ease; }
.card-header { background: var(--tarjeta); font-weight: 600; border-bottom: 1px solid var(--borde-suave); }

.dato { font-size: clamp(1.4rem, 2.3vw, 2rem); font-weight: 700; line-height: 1.1; white-space: nowrap; }
.dato-label { font-size: .8rem; color: var(--bs-secondary-color); text-transform: uppercase; letter-spacing: .03em; }

.estado-badge { font-size: .95rem; padding: .45em .8em; white-space: normal; text-align: left; }

.registro { font-family: Consolas, monospace; font-size: .8rem; max-height: 320px; overflow-y: auto; }
.registro div { padding: 2px 0; border-bottom: 1px dashed var(--borde-suave); }

.btn-grupo .btn { margin: 0 6px 6px 0; }

pre.codigo { background: #1f2a37; color: #e6edf3; padding: 14px; border-radius: 8px; font-size: .82rem; }

.tarjeta-ganancias { border-left: 4px solid var(--verde); }
.tarjeta-ganancias .dato { color: var(--verde); }
.text-success { color: var(--verde) !important; }

/* Gráficas y tablas */
.grafica { position: relative; height: 240px; }
.dato-sm { font-size: 1.25rem; font-weight: 700; line-height: 1.2; white-space: nowrap; }
.resumen-mes { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 18px 12px; }
.resumen-mes .dato-label { white-space: nowrap; }
.lista-cruces { max-height: 290px; overflow-y: auto; overflow-x: hidden; font-size: .85rem; }
.lista-cruces .badge { font-size: .72rem; }
.tabla-estado th { font-weight: 600; color: var(--texto-2); white-space: nowrap; }
.pestanas .nav-link { color: var(--texto-2); transition: color .2s ease, background-color .2s ease; }
.pestanas .nav-link.active { font-weight: 600; color: var(--texto-fuerte); }
.tabla-datos td, .tabla-datos th { text-align: right; white-space: nowrap; }
.tabla-datos td:first-child, .tabla-datos th:first-child { text-align: left; }

/* Encabezados de tabla «table-light» en modo oscuro */
[data-bs-theme="dark"] .table-light {
    --bs-table-bg: #222a33; --bs-table-color: var(--texto-fuerte); --bs-table-border-color: var(--borde-suave);
}
[data-bs-theme="dark"] .card .table { --bs-table-bg: var(--tarjeta); }
[data-bs-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * { --bs-table-bg-type: rgba(255, 255, 255, .03); }

/* =====================================================
   Animaciones
   ===================================================== */

@keyframes aparecer { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes crecer { from { height: 0; } to { height: 60%; } }
@keyframes latido {
    0% { box-shadow: 0 0 0 0 rgba(63, 179, 127, .6); }
    70% { box-shadow: 0 0 0 7px rgba(63, 179, 127, 0); }
    100% { box-shadow: 0 0 0 0 rgba(63, 179, 127, 0); }
}
@keyframes cambio { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* Al entrar a una página: el contenido sube suavemente y las tarjetas aparecen una tras otra. */
.contenido { animation: aparecer .35s ease both; }
.contenido .card { animation: aparecer .4s ease both; }
.contenido .row > :nth-child(2) > .card { animation-delay: .05s; }
.contenido .row > :nth-child(3) > .card { animation-delay: .1s; }
.contenido .row > :nth-child(4) > .card { animation-delay: .15s; }
.contenido .card:hover { box-shadow: 0 4px 14px rgba(0, 0, 0, .1); }

/* Al hacer clic en el menú o en una pestaña: el contenido se desvanece antes de cambiar de página. */
.contenido.saliendo { animation: none; opacity: 0; transform: translateY(6px); transition: opacity .15s ease, transform .15s ease; }

/* Un número que cambia (por ejemplo, entra alguien) late una vez. */
.cambio { display: inline-block; animation: cambio .4s ease; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* =====================================================
   Botón «Instalar app»
   ===================================================== */

.boton-instalar {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    border: 1px dashed rgba(255, 255, 255, .35); background: transparent; color: var(--lateral-texto);
    border-radius: 10px; padding: 8px; font-size: .85rem;
    transition: background-color .2s ease, border-color .2s ease;
}
.boton-instalar:hover { background: var(--lateral-hover); border-color: rgba(255, 255, 255, .6); color: #fff; }
.boton-instalar[hidden] { display: none; }

/* =====================================================
   Celular: barra arriba compacta y menú abajo, como una app
   ===================================================== */

@media (max-width: 900px) {
    .sidebar {
        position: sticky; top: 0; z-index: 1030;
        width: 100%; height: auto; flex-direction: row; align-items: center; gap: 8px;
        padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
        overflow: visible;
    }
    .marca { flex: 1; padding: 0; }
    .marca .logo { width: 34px; height: 34px; font-size: 1rem; }
    .bloque-hoy, .dispositivo-lateral { display: none; }
    .pie-lateral { margin-top: 0; flex-direction: row; align-items: center; gap: 6px; }
    .usuario-lateral { background: transparent; padding: 0; gap: 4px; }
    .usuario-lateral .datos { display: none; }
    .usuario-lateral .avatar { width: 30px; height: 30px; }
    .boton-instalar { padding: 6px 10px; }
    .boton-instalar span { display: none; }

    /* menú fijo abajo */
    .menu {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
        flex-direction: row; justify-content: space-around; gap: 0;
        background: var(--lateral); padding: 6px 6px max(6px, env(safe-area-inset-bottom));
        box-shadow: 0 -2px 12px rgba(0, 0, 0, .25);
    }
    .sidebar .nav-link {
        flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
        padding: 6px 4px; font-size: .72rem; text-align: center;
    }
    .sidebar .nav-link i { margin: 0; font-size: 1.25rem; }
    .sidebar .nav-link.active { background: transparent; color: #4d9bff; }
    .sidebar .nav-link.active::before {
        display: block; left: 50%; top: -6px; width: 28px; height: 3px; transform: translateX(-50%);
        border-radius: 0 0 3px 3px; background: #4d9bff; animation: none;
    }
    .sidebar .nav-link:hover i { transform: none; }

    .contenido { margin-left: 0; padding: 16px; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
    .toast-container { top: auto !important; bottom: calc(76px + env(safe-area-inset-bottom)); right: 0; left: 0;
                       display: flex; flex-direction: column; align-items: center; }
}

/* Inicio de sesión */
.pantalla-login { min-height: 100vh; background: var(--lateral); }
.tarjeta-login { width: 100%; max-width: 380px; animation: aparecer .4s ease both; }

/* =====================================================
   Aviso del usuario demo (una línea, se puede cerrar)
   ===================================================== */

.aviso-demo {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    background: var(--bs-warning-bg-subtle); color: var(--bs-warning-text-emphasis);
    border: 1px solid var(--bs-warning-border-subtle); border-radius: 10px;
    padding: 7px 12px; margin-bottom: 18px; font-size: .88rem;
    transition: opacity .25s ease, transform .25s ease;
}
.aviso-demo span { flex: 1; min-width: 200px; }
.aviso-demo a { font-weight: 600; color: inherit; }
.aviso-demo.cerrando { opacity: 0; transform: translateY(-6px); }

/* =====================================================
   Días con datos (botoncitos)
   ===================================================== */

.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 999px; font-size: .8rem; text-decoration: none;
    background: var(--tarjeta); color: var(--texto-fuerte); border: 1px solid var(--borde-suave);
    transition: background-color .2s ease, border-color .2s ease, transform .15s ease;
}
.chip span { color: var(--bs-secondary-color); font-size: .72rem; }
.chip:hover { border-color: #0d6efd; transform: translateY(-1px); }
.chip.activo { background: #0d6efd; border-color: #0d6efd; color: #fff; }
.chip.activo span { color: rgba(255, 255, 255, .8); }

/* =====================================================
   Comparación con ayer en el dashboard
   ===================================================== */

.delta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .78rem; margin-top: 4px; min-height: 1.3em; }
.etiqueta-delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.etiqueta-delta.sube { color: var(--verde); background: rgba(25, 135, 84, .12); }
.etiqueta-delta.baja { color: #dc3545; background: rgba(220, 53, 69, .12); }
.etiqueta-delta.igual { color: var(--bs-secondary-color); background: var(--borde-suave); }
[data-bs-theme="dark"] .etiqueta-delta.baja { color: #f07178; }

/* =====================================================
   Avisos flotantes
   ===================================================== */

.toast-container { z-index: 1090; }
.aviso { border: none; border-left: 4px solid var(--bs-info); background: var(--tarjeta); color: var(--texto-fuerte);
         box-shadow: 0 6px 24px rgba(0, 0, 0, .15); font-size: .9rem; }
.aviso > div > i { font-size: 1.1rem; line-height: 1.2; }
.aviso-success { border-left-color: var(--verde); } .aviso-success > div > i { color: var(--verde); }
.aviso-danger { border-left-color: #dc3545; }       .aviso-danger > div > i { color: #dc3545; }
.aviso-warning { border-left-color: #f0ad4e; }      .aviso-warning > div > i { color: #f0ad4e; }
.aviso-info > div > i { color: var(--bs-info); }
.toast.showing, .toast.show { animation: aparecer .25s ease both; }

@media (max-width: 576px) {
    .contenido .card.p-3 { padding: 12px !important; }
    .dato-label { font-size: .7rem; }
    .delta { font-size: .72rem; }
    h2 { font-size: 1.5rem; }
}
