/*
 * MoliShop ERP Theme (Dark Mode Premium)
 * 5S: Seiri (Sin clases redundantes), Seiton (Estructurado), Seiso (Limpio)
 */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

:root,
html[data-theme="dark"] {
    --moli-red: #e31e24;
    --moli-red-hover: #c4181e;
    
    /* Fondos Oscuros (Modo Noche 19:00 - 05:59) */
    --moli-bg-top: #0A1128;
    --moli-bg-bottom: #030612;
    --moli-surface: #0e172a;
    --moli-bg-elevated: #0f172a;
    --moli-bg-card: rgba(15, 23, 42, 0.75);
    --moli-border-card: rgba(255, 255, 255, 0.1);
    
    /* Textos */
    --moli-text-main: #FFFFFF;
    --moli-text: #f8fafc;
    --moli-text-secondary: #cbd5e1;
    --moli-text-muted: #94a3b8;
    --moli-link-accent: #93c5fd;

    /* Superficies Semánticas y Controles */
    --moli-row-folder-bg: rgba(15, 23, 42, 0.82);
    --moli-row-folder-hover: rgba(30, 41, 59, 0.95);
    --moli-row-folder-border: rgba(255, 255, 255, 0.08);
    --moli-subtle-bg: rgba(255, 255, 255, 0.03);
    --moli-subtle-border: rgba(255, 255, 255, 0.08);
    --moli-input-bg: rgba(15, 23, 42, 0.65);
    --moli-input-border: rgba(255, 255, 255, 0.14);
    --moli-modal-bg: #0f172a;
    --moli-modal-surface: #1e293b;

    /* Acentos Semánticos (Calibrados para Fondo Oscuro) */
    --moli-blue: #60a5fa;
    --moli-emerald: #34d399;
    --moli-amber: #fbbf24;
    --moli-danger: #f87171;
    --moli-purple: #c084fc;
    
    /* Componentes Glassmorphism */
    --sidebar-bg: rgba(10, 25, 47, 0.95);
    --glass-bg: rgba(10, 17, 40, 0.75);
    --glass-card-bg: rgba(10, 17, 40, 0.5);
    --glass-border: rgba(31, 48, 94, 0.5);
    
    --font-family: 'Poppins', sans-serif;
}

html[data-theme="light"] {
    --moli-red: #d91920;
    --moli-red-hover: #b8141a;

    /* Fondos Claros Corporativos (Modo Día 06:00 - 18:59, tono perla ejecutivo) */
    --moli-bg-top: #f4f6fb;
    --moli-bg-bottom: #e8edf5;
    --moli-surface: #ffffff;
    --moli-bg-elevated: #f1f5f9;
    --moli-bg-card: #ffffff;
    --moli-border-card: #cbd5e1;

    /* Textos de alto contraste WCAG AA/AAA */
    --moli-text-main: #0f172a;
    --moli-text: #0f172a;
    --moli-text-secondary: #334155;
    --moli-text-muted: #475569;
    --moli-link-accent: #1d4ed8;

    /* Superficies Semánticas y Controles en Modo Día */
    --moli-row-folder-bg: #e2e8f0;
    --moli-row-folder-hover: #cbd5e1;
    --moli-row-folder-border: #cbd5e1;
    --moli-subtle-bg: #f8fafc;
    --moli-subtle-border: #cbd5e1;
    --moli-input-bg: #ffffff;
    --moli-input-border: #94a3b8;
    --moli-modal-bg: #ffffff;
    --moli-modal-surface: #ffffff;

    /* Acentos Semánticos (Calibrados para Fondo Claro >= 4.5:1) */
    --moli-blue: #1d4ed8;
    --moli-emerald: #047857;
    --moli-amber: #b45309;
    --moli-danger: #b91c1c;
    --moli-purple: #6d28d9;

    /* Superficies ejecutivas limpias */
    --sidebar-bg: #ffffff;
    --glass-bg: rgba(255, 255, 255, 0.94);
    --glass-card-bg: rgba(255, 255, 255, 0.98);
    --glass-border: #cbd5e1;
}

/* Reset y Base */
* { box-sizing: border-box; margin: 0; padding: 0; }
html {
    background-color: var(--moli-bg-bottom);
}
body {
    font-family: var(--font-family);
    background-color: var(--moli-bg-bottom);
    background-image: radial-gradient(circle at center top, var(--moli-bg-top) 0%, var(--moli-bg-bottom) 100%);
    background-attachment: fixed;
    color: var(--moli-text-main);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Layout */
.app-container {
    display: flex;
    width: 100%;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: white;
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--glass-border);
    min-height: 70px;
}
.sidebar-header img {
    max-height: 35px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

.sidebar-nav {
    padding: 1.5rem 0;
    flex: 1;
    overflow-y: auto;
}

.sidebar-group {
    margin-bottom: 1.5rem;
}
.sidebar-group-title {
    padding: 0.5rem 1.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--moli-text-muted);
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: var(--moli-text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.3s;
    border-left: 4px solid transparent;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
    background: rgba(255,255,255,0.05);
    color: white;
    border-left-color: var(--moli-red);
}

/* --- MAIN WRAPPER --- */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Marca de Agua Global (Logo MoliShop) */
.main-wrapper::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60%;
    height: 60%;
    background-image: url('../img/logo-white.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.03; /* Marca de agua sutil */
    z-index: 0;
    pointer-events: none;
}

/* --- TOPBAR --- */
.topbar {
    height: 70px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    z-index: 90;
}
.topbar-left {
    display: flex;
    align-items: center;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--moli-red);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    box-shadow: 0 3px 6px rgba(227, 30, 36, 0.3);
}

/* --- CONTENT AREA --- */
.content {
    padding: 2rem;
    flex: 1;
    overflow-y: auto;
    animation: fadeInUp 0.6s ease-out;
}

/* --- GLASS CARD --- */
.glass-card {
    background: var(--glass-card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    border: 1px solid rgba(224, 169, 109, 0.15); /* Soft premium border */
    margin-bottom: 1.5rem;
    transition: transform 0.3s, box-shadow 0.3s, border-color 0.3s;
}
.glass-card:hover {
    border-color: rgba(227, 30, 36, 0.4);
    background: rgba(10, 17, 40, 0.7);
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.4);
}

/* --- TYPOGRAPHY & UTILITIES --- */
.page-title {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--moli-text-main);
}

/* --- HEADER ACTIONS --- */
.header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.header-actions h1, .header-actions .page-title {
    margin-bottom: 0;
}
.header-actions-group {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

/* --- BUTTONS --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    outline: none;
}
.btn-primary {
    background: var(--moli-red);
    color: white;
}
.btn-primary:hover {
    background: var(--moli-red-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(227, 30, 36, 0.3);
}

.btn-outline {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--moli-text-main);
}
.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

/* --- FORMS --- */
.form-group {
    margin-bottom: 1.2rem;
}
.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--moli-text-muted);
}
.form-control {
    width: 100%;
    padding: 0.7rem 1rem;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    font-family: var(--font-family);
    transition: border-color 0.3s, box-shadow 0.3s, background-color 0.3s;
    background-color: rgba(255,255,255,0.05);
    color: white;
    color-scheme: dark; /* Fuerza a los navegadores a usar UI oscura en calendarios nativos y scrollbars */
}
.form-control:focus {
    outline: none;
    border-color: var(--moli-red);
    box-shadow: 0 0 0 3px rgba(227, 30, 36, 0.2);
    background-color: rgba(255,255,255,0.1);
}

/* Solución para dropdowns (combobox) nativos en modo oscuro */
select.form-control {
    /* Forzar fondo sólido si el OS sobreescribe el rgba en la lista desplegada */
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1em;
}
select.form-control option {
    background-color: #0A1128; /* Color sólido corporativo para las opciones (var no siempre se parsea en <option> en todos los navegadores) */
    color: #FFFFFF;
    padding: 10px;
}

/* Reemplazar completamente el ícono nativo del calendario con un SVG blanco puro, evitando conflictos con color-scheme */
input[type="date"]::-webkit-calendar-picker-indicator {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'%3E%3C/rect%3E%3Cline x1='16' y1='2' x2='16' y2='6'%3E%3C/line%3E%3Cline x1='8' y1='2' x2='8' y2='6'%3E%3C/line%3E%3Cline x1='3' y1='10' x2='21' y2='10'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    width: 1.1rem;
    height: 1.1rem;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

/* --- TABLES --- */
.table-responsive {
    overflow-x: auto;
}
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th, .table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
}
.table th {
    font-weight: 600;
    color: var(--moli-text-muted);
    background: rgba(255,255,255,0.02);
}
.table tr { transition: background 0.2s; }
.table tr:hover { background: rgba(255,255,255,0.05); }

/* --- FLASH MESSAGES --- */
.flashes { list-style: none; margin-bottom: 1.5rem; }
.flash {
    padding: 1rem 1.5rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    font-weight: 500;
    animation: bounceIn 0.5s ease-out;
    display: flex;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.flash-success { background: rgba(40, 167, 69, 0.15); color: #4ade80; border: 1px solid rgba(40, 167, 69, 0.4); }
.flash-error, .flash-danger { background: rgba(227, 30, 36, 0.15); color: #ff6b6b; border: 1px solid rgba(227, 30, 36, 0.4); }

/* --- BADGES --- */
.badge {
    padding: 0.35em 0.65em;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-block;
}
.badge-success { background: rgba(40, 167, 69, 0.15); color: #4ade80; border: 1px solid rgba(40, 167, 69, 0.3); }
.badge-warning { background: rgba(255, 193, 7, 0.15); color: #ffd166; border: 1px solid rgba(255, 193, 7, 0.3); }
.badge-danger { background: rgba(227, 30, 36, 0.15); color: #ff6b6b; border: 1px solid rgba(227, 30, 36, 0.3); }

/* --- ANIMATIONS --- */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes bounceIn {
    0% { transform: scale(0.9); opacity: 0; }
    80% { transform: scale(1.02); opacity: 1; }
    100% { transform: scale(1); }
}

/* --- TABS --- */
.tabs-container { margin-bottom: 2rem; }
.tabs-header {
    display: flex;
    gap: 1rem;
    border-bottom: 2px solid var(--glass-border);
    margin-bottom: 1.5rem;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 0.5rem;
    scrollbar-width: none; /* Ocultar en Firefox */
}
.tabs-header::-webkit-scrollbar {
    display: none; /* Ocultar en Chrome/Edge/Safari */
}
.tab-btn {
    background: transparent;
    border: none;
    color: var(--moli-text-muted);
    font-size: 1rem;
    font-weight: 500;
    font-family: var(--font-family);
    cursor: pointer;
    padding: 0.5rem 1rem;
    transition: all 0.3s;
    white-space: nowrap;
}
.tab-btn:hover { color: white; }
.tab-btn.active {
    color: var(--moli-red);
    border-bottom: 2px solid var(--moli-red);
    margin-bottom: -0.65rem; /* Ajuste visual por el padding y borde */
}
.tab-pane {
    display: none;
    animation: fadeInUp 0.4s ease-out;
}
.tab-pane.active { display: block; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

/* --- THUMBNAILS Y MODAL FOTOGRAFICO --- */
.img-thumbnail {
    width: 65px;
    height: 65px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid var(--glass-border);
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    background-color: rgba(0,0,0,0.3);
}
.img-thumbnail:hover {
    transform: scale(1.1);
    border-color: var(--moli-red);
}

.modal-overlay {
    display: none; /* Oculto por defecto, se activa vía JS */
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    justify-content: center;
    align-items: center;
    padding: 1rem;
}
.modal-content {
    position: relative;
    max-width: 95vw;
    max-height: 90vh;
    animation: bounceIn 0.3s ease-out;
}
.modal-content img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.6);
    object-fit: contain;
}
.modal-close {
    position: absolute;
    top: -45px;
    right: 0;
    color: white;
    font-size: 2.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
    line-height: 1;
}
.modal-close:hover {
    color: var(--moli-red);
}

/* --- RESPONSIVE MOBILE --- */
@media (min-width: 1025px) {
    .hide-on-desktop { display: none !important; }
}

@media (max-width: 1024px) {
    .hide-on-mobile { display: none !important; }
    
    .sidebar-overlay {
        position: fixed;
        top: 0; left: 0; width: 100vw; height: 100vh;
        background: rgba(0,0,0,0.5);
        backdrop-filter: blur(3px);
        z-index: 90;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }

    .sidebar {
        position: fixed;
        height: 100vh;
        transform: translateX(-100%);
        box-shadow: none;
        z-index: 100;
    }
    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 10px 0 30px rgba(0,0,0,0.8);
    }
    .topbar {
        padding: 0 1rem;
    }
    .topbar-right {
        gap: 0.5rem;
    }
    .user-profile div span {
        display: none !important;
    }
    .user-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.85rem;
    }
    .content {
        padding: 1rem;
    }
    .glass-card {
        padding: 1rem;
    }
    
    /* Header Actions Responsivo (Móviles) */
    .header-actions {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    .header-actions-group {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }
    .header-actions-group > * {
        width: 100%;
    }
    .header-actions-group > div, 
    .header-actions-group > .search-container {
        width: 100%;
    }
    .header-actions-group input.moli-input {
        width: 100% !important;
    }
    .header-actions h1, .header-actions .page-title {
        font-size: 1.35rem !important;
        margin-bottom: 0.5rem;
    }
    html, body, .app-container, .main-wrapper, .content {
        max-width: 100vw;
        overflow-x: hidden;
    }
    .search-container,
    .search-container input.moli-input {
        width: 100% !important;
        max-width: 100% !important;
    }
    .tabs-header {
        display: flex;
        flex-wrap: wrap;
        gap: 0.35rem;
    }
}

/* --- MESA DE AYUDA: BARRAS DE AVANCE Y BITACORA --- */
.moli-progress-track {
    flex: 1;
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    overflow: hidden;
}
.moli-progress-track-lg {
    height: 12px;
    background: rgba(255, 255, 255, 0.08);
}
.moli-progress-fill {
    width: 0;
    height: 100%;
    transition: width 0.4s ease;
}
.moli-progress-high { background: #4ade80; }
.moli-progress-mid { background: #60a5fa; }
.moli-progress-low { background: #fbbf24; }

.moli-evento-card {
    padding: 0.85rem 1rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    border-left: 3px solid var(--moli-red);
}
.moli-evento-tecnico {
    background: rgba(59, 130, 246, 0.1);
    border-left-color: #60a5fa;
}
.moli-evento-interno {
    background: rgba(234, 179, 8, 0.1);
    border-left-color: #facc15;
}

.summary-red-directa { color: var(--moli-emerald); }
.summary-subred { color: var(--moli-blue); }

/* --- CONMUTADOR TEMA CLARO (DÍA) / OSCURO (NOCHE) --- */
html[data-theme="dark"] .sidebar-logo-light {
    display: none !important;
}
html[data-theme="light"] .sidebar-logo-dark {
    display: none !important;
}

.erp-theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.25s ease;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    color: var(--moli-text-main);
}
.erp-theme-toggle:hover {
    border-color: var(--moli-red);
    transform: translateY(-1px);
}
.erp-theme-icon {
    display: inline-flex;
    width: 17px;
    height: 17px;
    flex-shrink: 0;
}
html[data-theme="light"] .erp-theme-icon-moon {
    display: none !important;
}
html[data-theme="dark"] .erp-theme-icon-sun {
    display: none !important;
}
html[data-theme="light"] .erp-theme-icon-sun {
    color: #d97706;
}
html[data-theme="dark"] .erp-theme-icon-moon {
    color: #fcd34d;
}

/* Adaptación Integral Modo Claro (Día: 06:00 - 18:59 por defecto) */
html[data-theme="light"] .sidebar {
    color: var(--moli-text-main);
    box-shadow: 2px 0 14px rgba(15, 23, 42, 0.05);
}
html[data-theme="light"] .sidebar-header img {
    filter: none;
}
.sidebar-nav a.sidebar-link-pm {
    color: #fcd34d;
    font-weight: 700;
    border-left: 3px solid #fcd34d;
    padding-left: 17px;
}
.sidebar-nav a.sidebar-link-dat {
    color: #60a5fa;
    font-weight: 700;
}
html[data-theme="light"] .sidebar-nav a.sidebar-link-pm {
    color: #b45309;
    border-left-color: #d97706;
}
html[data-theme="light"] .sidebar-nav a.sidebar-link-dat {
    color: #1d4ed8;
}
html[data-theme="light"] .sidebar-nav a:hover,
html[data-theme="light"] .sidebar-nav a.active {
    background: rgba(227, 30, 36, 0.08);
    color: #181b22;
    border-left-color: var(--moli-red);
}
html[data-theme="light"] .main-wrapper::before {
    background-image: url('../img/logo.png');
    opacity: 0.035;
}
html[data-theme="light"] .topbar {
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}
html[data-theme="light"] .erp-theme-toggle {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #181b22;
}
html[data-theme="light"] .glass-card {
    background: var(--glass-card-bg);
    border: 1px solid #dce2ec;
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.06);
}
html[data-theme="light"] .glass-card:hover {
    background: #ffffff;
    border-color: rgba(227, 30, 36, 0.35);
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.1);
}
html[data-theme="light"] .btn-outline {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    color: #181b22;
}
html[data-theme="light"] .btn-outline:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}
html[data-theme="light"] .form-control {
    background-color: #f8fafc;
    color: #181b22;
    border-color: #cbd5e1;
    color-scheme: light;
}
html[data-theme="light"] .form-control:focus {
    background-color: #ffffff;
    border-color: var(--moli-red);
}
html[data-theme="light"] select.form-control {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23181b22' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}
html[data-theme="light"] select.form-control option {
    background-color: #ffffff;
    color: #181b22;
}
html[data-theme="light"] input[type="date"]::-webkit-calendar-picker-indicator {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23181b22' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'%3E%3C/rect%3E%3Cline x1='16' y1='2' x2='16' y2='6'%3E%3C/line%3E%3Cline x1='8' y1='2' x2='8' y2='6'%3E%3C/line%3E%3Cline x1='3' y1='10' x2='21' y2='10'%3E%3C/line%3E%3C/svg%3E");
}
html[data-theme="light"] .table th {
    background: #f1f5f9;
    color: #334155;
}
html[data-theme="light"] .table tr:hover {
    background: rgba(15, 23, 42, 0.03);
}
html[data-theme="light"] .tab-btn:hover {
    color: #181b22;
}
html[data-theme="light"] .badge-success {
    background: rgba(22, 163, 74, 0.14);
    color: #15803d;
    border-color: rgba(22, 163, 74, 0.35);
}
html[data-theme="light"] .badge-warning {
    background: rgba(217, 119, 6, 0.14);
    color: #b45309;
    border-color: rgba(217, 119, 6, 0.35);
}
html[data-theme="light"] .badge-danger {
    background: rgba(220, 38, 38, 0.14);
    color: #b91c1c;
    border-color: rgba(220, 38, 38, 0.35);
}
html[data-theme="light"] .flash-success {
    background: #dcfce7;
    color: #166534;
    border-color: #86efac;
}
html[data-theme="light"] .flash-error,
html[data-theme="light"] .flash-danger {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fca5a5;
}
html[data-theme="light"] .moli-progress-track,
html[data-theme="light"] .moli-progress-track-lg {
    background: #e2e8f0;
}
html[data-theme="light"] .moli-evento-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-left: 3px solid var(--moli-red);
}
html[data-theme="light"] .moli-evento-tecnico {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-left: 3px solid #2563eb;
}
html[data-theme="light"] .moli-evento-interno {
    background: #fefce8;
    border: 1px solid #fde68a;
    border-left: 3px solid #d97706;
}
html[data-theme="light"] .moli-input,
html[data-theme="light"] .content input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="submit"]):not([type="button"]),
html[data-theme="light"] .content select,
html[data-theme="light"] .content textarea {
    background-color: var(--moli-input-bg) !important;
    color: var(--moli-text) !important;
    border-color: var(--moli-input-border) !important;
    color-scheme: light;
}
html[data-theme="light"] .moli-input::placeholder,
html[data-theme="light"] .content input::placeholder,
html[data-theme="light"] .content textarea::placeholder {
    color: #64748b !important;
}
html[data-theme="light"] select option,
html[data-theme="light"] select optgroup {
    background-color: #ffffff !important;
    color: #0f172a !important;
}
html[data-theme="light"] .nodo-folder-row {
    background: var(--moli-row-folder-bg) !important;
}
html[data-theme="light"] .nodo-folder-row:hover {
    background: var(--moli-row-folder-hover) !important;
}
html[data-theme="light"] .nodo-titulo-raiz,
html[data-theme="light"] .nodo-titulo-hijo {
    color: var(--moli-text) !important;
}
html[data-theme="light"] .erp-table th,
html[data-theme="light"] .table-container thead th,
html[data-theme="light"] .content table thead th {
    background: #f1f5f9 !important;
    color: #1e293b !important;
    border-bottom-color: #cbd5e1 !important;
}
html[data-theme="light"] .erp-table td,
html[data-theme="light"] .table-container tbody td,
html[data-theme="light"] .content table tbody td {
    border-bottom-color: #e2e8f0 !important;
}
html[data-theme="light"] .form-container {
    background: #ffffff !important;
    border: 1px solid #cbd5e1 !important;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.05);
}
html[data-theme="light"] .tab-btn {
    color: #475569;
}
html[data-theme="light"] .tab-btn.active {
    color: var(--moli-red);
    border-bottom-color: var(--moli-red);
}

/* --- SISTEMA SOP (?) DE AYUDA CONTEXTUAL E INTERACTIVA --- */
.moli-sop-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    background: rgba(59, 130, 246, 0.14);
    border: 1px solid rgba(59, 130, 246, 0.4);
    color: var(--moli-link-accent);
    transition: all 0.2s ease;
    line-height: 1;
}
.moli-sop-btn:hover {
    background: var(--moli-red);
    border-color: var(--moli-red);
    color: #ffffff;
    transform: translateY(-1px);
}
.moli-sop-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--moli-red);
    color: #ffffff;
    font-size: 0.76rem;
    font-weight: 800;
}

.moli-sop-inline-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    margin-left: 0.4rem;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(227, 30, 36, 0.45);
    background: rgba(227, 30, 36, 0.14);
    color: var(--moli-red);
    font-size: 0.82rem;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    vertical-align: middle;
    transition: all 0.2s ease;
}
.moli-sop-inline-btn:hover {
    background: var(--moli-red);
    color: #ffffff;
    transform: scale(1.08);
}

.moli-sop-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(3, 6, 18, 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}
.moli-sop-overlay.active {
    display: flex;
}

.moli-sop-sheet {
    width: 100%;
    max-width: 820px;
    max-height: 88vh;
    background: var(--moli-surface);
    color: var(--moli-text-main);
    border: 1px solid var(--glass-border);
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: fadeInUp 0.25s ease-out;
}
.moli-sop-handle {
    display: none;
    width: 44px;
    height: 5px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.45);
    margin: 0.6rem auto 0.1rem;
}
.moli-sop-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.15rem 1.4rem 0.9rem;
    border-bottom: 1px solid var(--glass-border);
}
.moli-sop-pill {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: rgba(227, 30, 36, 0.14);
    color: var(--moli-red);
    border: 1px solid rgba(227, 30, 36, 0.35);
    margin-bottom: 0.3rem;
}
.moli-sop-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--moli-text-main);
    margin: 0;
}
.moli-sop-close {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--moli-text-muted);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}
.moli-sop-close:hover {
    color: #ffffff;
    background: var(--moli-red);
    border-color: var(--moli-red);
}
.moli-sop-selector-bar {
    padding: 0.75rem 1.4rem;
    background: rgba(148, 163, 184, 0.06);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.moli-sop-selector-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--moli-text-muted);
}
.moli-sop-select {
    flex: 1;
    min-width: 220px;
    padding: 0.48rem 2.4rem 0.48rem 0.85rem;
    font-size: 0.85rem;
    text-overflow: ellipsis;
}
.moli-sop-body {
    padding: 1.25rem 1.4rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}
.moli-sop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 0.9rem;
}
.moli-sop-card {
    background: rgba(148, 163, 184, 0.06);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.95rem 1.05rem;
    font-size: 0.88rem;
    line-height: 1.5;
}
.moli-sop-card-head {
    font-size: 0.84rem;
    font-weight: 700;
    color: var(--moli-red);
    margin-bottom: 0.45rem;
}
.moli-sop-list {
    margin: 0;
    padding-left: 1.15rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.moli-sop-focus-card {
    background: rgba(227, 30, 36, 0.06);
    border: 1px solid rgba(227, 30, 36, 0.35);
    border-radius: 14px;
    padding: 1rem;
}
.moli-sop-focus-badge {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--moli-red);
    margin-bottom: 0.2rem;
}
.moli-sop-focus-title {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--moli-text-main);
}
.moli-sop-controls-section {
    border-top: 1px solid var(--glass-border);
    padding-top: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}
.moli-sop-subtitle {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--moli-text-main);
}
.moli-sop-ctrl-item {
    background: rgba(148, 163, 184, 0.05);
    border: 1px solid var(--glass-border);
    border-left: 3px solid var(--moli-link-accent);
    border-radius: 10px;
    padding: 0.75rem 0.95rem;
}
.moli-sop-ctrl-name {
    font-weight: 700;
    font-size: 0.88rem;
    margin-bottom: 0.35rem;
    color: var(--moli-text-main);
}
.moli-sop-ctrl-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.35rem 0.85rem;
    font-size: 0.8rem;
    color: var(--moli-text-muted);
}

/* --- BARRA DE NAVEGACIÓN INFERIOR MÓVIL ESTILO APP NATIVA (iOS / Android) --- */
.moli-mobile-bottom-nav {
    display: none;
}

.moli-kpi-collapsible {
    margin-bottom: 0.9rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(148, 163, 184, 0.05);
    padding: 0.5rem 0.85rem;
}
.moli-kpi-collapsible[open] {
    padding-bottom: 0.75rem;
}
.moli-kpi-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--moli-text-muted);
    list-style: none;
    user-select: none;
}
.moli-kpi-summary::-webkit-details-marker {
    display: none;
}
.moli-kpi-summary::after {
    content: '▾ Ver resumen';
    font-size: 0.72rem;
    color: var(--moli-link-accent);
    font-weight: 700;
}
.moli-kpi-collapsible[open] .moli-kpi-summary::after {
    content: '▴ Ocultar';
}
.moli-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.65rem;
    margin-top: 0.65rem;
    margin-bottom: 0;
}
.moli-kpi-card {
    padding: 0.55rem 0.65rem !important;
    border-radius: 10px !important;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.moli-kpi-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem;
}
.moli-kpi-title {
    font-size: 0.66rem;
    color: var(--moli-text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.moli-kpi-value {
    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1.1;
}
.moli-kpi-sub {
    font-size: 0.65rem;
    color: var(--moli-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.moli-ticket-filter-bar {
    display: flex;
    gap: 0.65rem;
    flex-wrap: wrap;
    align-items: center;
    padding: 0 0 0.85rem !important;
    margin-bottom: 0.85rem;
    border-bottom: 1px solid var(--glass-border);
}
.moli-evento-interno-collapse {
    margin-top: 0.2rem;
    border-radius: 8px;
    border: 1px dashed rgba(234, 179, 8, 0.35);
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
    color: var(--moli-text-muted);
}
.moli-evento-interno-collapse summary {
    cursor: pointer;
    font-weight: 600;
}
.moli-control-tecnico-collapse {
    border-radius: 12px;
    border: 1px dashed var(--glass-border);
    background: rgba(148, 163, 184, 0.04);
    padding: 0.65rem 0.9rem;
}
.moli-control-tecnico-collapse summary {
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--moli-text-muted);
}

@media (max-width: 768px) {
    /* Experiencia App Nativa en Celular */
    * {
        -webkit-tap-highlight-color: transparent;
    }
    .topbar {
        position: sticky;
        top: 0;
        height: 58px;
        padding: 0 0.75rem;
    }
    .topbar-right {
        gap: 0.4rem;
    }
    .erp-theme-label {
        display: none !important;
    }
    .erp-theme-toggle {
        padding: 0.42rem;
        width: 36px;
        height: 36px;
        justify-content: center;
    }
    .moli-sop-btn-label {
        display: none;
    }
    .moli-sop-btn {
        padding: 0.32rem 0.5rem;
    }
    .content {
        padding: 0.9rem 0.85rem calc(86px + env(safe-area-inset-bottom, 0px)) !important;
    }
    /* QA-14: En celular el acceso a Soporte ya vive en la barra inferior y superior;
       ocultar el botón flotante evita tapar tarjetas o secciones de contenido */
    .moli-fab-reportar {
        display: none !important;
    }

    /* Evitar auto-zoom en iOS al tocar inputs y asegurar área táctil >= 44px */
    .form-control,
    select.form-control,
    input[type="text"],
    input[type="number"],
    input[type="tel"],
    input[type="email"],
    input[type="password"],
    textarea {
        font-size: 16px !important;
        min-height: 44px;
    }
    .btn {
        min-height: 44px;
    }

    /* KPIs ultra-compactos en tira horizontal de 4 columnas (MEJ-0008 / QUE-0003) */
    .moli-kpi-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
        gap: 0.35rem !important;
        margin-top: 0.5rem !important;
        margin-bottom: 0 !important;
    }
    .moli-kpi-card {
        padding: 0.4rem 0.45rem !important;
    }
    .moli-kpi-title {
        font-size: 0.58rem !important;
    }
    .moli-kpi-value {
        font-size: 0.98rem !important;
    }
    .moli-kpi-sub {
        display: none !important;
    }

    /* Tarjetas del Dashboard principal como filas compactas de App Móvil */
    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }
    .dashboard-grid .glass-card {
        flex-direction: row !important;
        text-align: left !important;
        justify-content: flex-start !important;
        padding: 1rem !important;
        gap: 0.95rem !important;
    }
    .dashboard-grid .glass-card > div:first-child {
        width: 52px !important;
        height: 52px !important;
        margin-bottom: 0 !important;
        flex-shrink: 0;
    }
    .dashboard-grid .glass-card h3 {
        font-size: 1.05rem !important;
        margin-bottom: 0.2rem !important;
    }

    /* Conversión automática de Tablas a Tarjetas Móviles Apiladas (Cero scroll horizontal) */
    .table-responsive,
    .table-container {
        overflow-x: visible !important;
        border: none !important;
        background: transparent !important;
    }
    table.moli-mobile-card-table,
    table.moli-mobile-card-table tbody {
        display: block;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }
    table.moli-mobile-card-table thead {
        display: none;
    }
    table.moli-mobile-card-table tbody tr {
        display: flex;
        flex-direction: column;
        gap: 0.35rem;
        padding: 0.9rem 1rem;
        margin-bottom: 0.75rem;
        border-radius: 14px;
        background: var(--glass-card-bg);
        border: 1px solid var(--glass-border);
        box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
    }
    table.moli-mobile-card-table tbody tr.nodo-row {
        background: var(--moli-row-folder-bg);
        padding: 0.7rem 0.85rem;
    }
    table.moli-mobile-card-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.75rem;
        padding: 0.35rem 0 !important;
        border-bottom: 1px dashed rgba(148, 163, 184, 0.2);
        text-align: right;
        width: 100%;
        min-width: 0;
        overflow-wrap: anywhere;
    }
    table.moli-mobile-card-table tbody td.nodo-td-header,
    table.moli-mobile-card-table tbody td.moli-td-folder {
        display: block !important;
        text-align: left !important;
        padding: 0.2rem 0 !important;
        border-bottom: none !important;
    }
    table.moli-mobile-card-table tbody td.nodo-td-header::before,
    table.moli-mobile-card-table tbody td.moli-td-folder::before {
        display: none !important;
    }
    table.moli-mobile-card-table tbody td.nodo-td-logo,
    table.moli-mobile-card-table tbody td.user-td {
        padding-left: 0 !important;
    }
    .moli-form-grid-2,
    .moli-form-grid-3,
    .moli-horario-row,
    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 0.85rem !important;
    }
    table.moli-mobile-card-table tbody td[data-label*="Resumen"],
    table.moli-mobile-card-table tbody td[data-label*="Acción"],
    table.moli-mobile-card-table tbody td[data-label*="Acciones"] {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
        gap: 0.35rem;
    }
    table.moli-mobile-card-table tbody td .moli-td-content {
        width: 100%;
    }
    table.moli-mobile-card-table tbody td:last-child {
        border-bottom: none;
        padding-top: 0.5rem !important;
    }
    table.moli-mobile-card-table tbody td::before {
        content: attr(data-label);
        font-size: 0.72rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        color: var(--moli-text-muted);
        text-align: left;
        flex-shrink: 0;
    }
    table.moli-mobile-card-table tbody td.moli-td-empty::before {
        display: none;
    }

    /* Bottom Sheet Nativo para el Modal SOP (?) en Celular */
    .moli-sop-overlay {
        padding: 0;
        align-items: flex-end;
    }
    .moli-sop-sheet {
        max-width: 100%;
        max-height: 88dvh;
        border-radius: 20px 20px 0 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .moli-sop-handle {
        display: block;
    }
    .moli-sop-grid {
        grid-template-columns: 1fr;
    }

    /* Barra de Navegación Inferior estilo iOS / Android */
    .moli-mobile-bottom-nav {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(64px + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--glass-bg);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
        border-top: 1px solid var(--glass-border);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.18);
        z-index: 95;
    }
    .moli-mobile-tab {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        text-decoration: none;
        color: var(--moli-text-muted);
        font-size: 0.68rem;
        font-weight: 600;
        border: none;
        background: transparent;
        cursor: pointer;
        position: relative;
        padding: 0.25rem 0.15rem;
    }
    .moli-mobile-tab svg {
        width: 20px;
        height: 20px;
    }
    .moli-mobile-tab.active {
        color: var(--moli-red);
    }
    .moli-mobile-tab.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 25%;
        right: 25%;
        height: 3px;
        border-radius: 0 0 4px 4px;
        background: var(--moli-red);
    }
}
