﻿/* === TEMA LIGHT AMIGABLE (DEFAULT) === */
        :root {
            /* Paleta Claro */
            --bg-body: #f8f9fc;
            --bg-surface: #ffffff;
            --bg-input: #f1f3f9;
            --border: #e4e7f0;
            
            --primary: #6366f1; /* Indigo moderno */
            --primary-hover: #4f46e5;
            --success: #10b981;
            --danger: #f43f5e;
            --warning: #f59e0b;
            --info: #06b6d4;

            --text-main: #1f2937;
            --text-sec: #6b7280;
            --text-muted: #9ca3af;

            --radius: 8px;
            --sidebar-width: 260px;
            --sidebar-collapsed-width: 80px;
            --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            --shadow: 0 2px 8px rgba(0,0,0,0.08);
            --shadow-hover: 0 4px 12px rgba(0,0,0,0.12);
        }

        /* === TEMA DARK === */
        html[data-theme="dark"] {
            --bg-body: #0f172a;
            --bg-surface: #1e293b;
            --bg-input: #334155;
            --border: #475569;
            
            --primary: #818cf8;
            --primary-hover: #6366f1;
            --text-main: #f1f5f9;
            --text-sec: #cbd5e1;
            --text-muted: #94a3b8;
            
            --shadow: 0 2px 8px rgba(0,0,0,0.3);
            --shadow-hover: 0 4px 12px rgba(0,0,0,0.4);
        }

        * { box-sizing: border-box; outline: none; }

        body {
            margin: 0;
            font-family: 'Ubuntu', sans-serif;
            background-color: var(--bg-body);
            color: var(--text-main);
            height: 100vh;
            overflow: hidden;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }

        .hidden { display: none !important; }

        /* === SIDEBAR COLAPSABLE === */
        header {
            width: var(--sidebar-width);
            background-color: var(--bg-surface);
            border-right: 1px solid var(--border);
            display: flex;
            flex-direction: column;
            padding: 16px 12px;
            position: fixed;
            top: 0;
            left: 0;
            height: 100vh;
            z-index: 1000;
            box-shadow: var(--shadow);
            transition: var(--transition);
            overflow-y: auto;
            overflow-x: hidden;
        }

        header.collapsed {
            width: var(--sidebar-collapsed-width);
            padding: 12px 8px;
            align-items: center;
        }

        .brand {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 6px;
            font-size: 1.2rem;
            font-weight: 700;
            color: var(--text-main);
            margin-bottom: 24px;
            letter-spacing: -0.5px;
            transition: var(--transition);
            min-height: 32px;
        }
        
        .brand-content {
            display: flex;
            align-items: center;
            gap: 6px;
            flex: 1;
            min-width: 0;
            overflow: hidden;
        }

        .brand-icon {
            font-size: 24px !important;
            flex-shrink: 0;
            min-width: 24px;
        }

        .brand-text {
            white-space: nowrap;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            opacity: 1;
            flex: 1;
        }

        .brand-text-collapsed {
            font-size: 0.85rem;
            font-weight: 700;
            color: var(--primary);
            letter-spacing: 0.5px;
            display: none;
        }

        header.collapsed .brand-text {
            opacity: 0;
            width: 0;
            margin: 0;
            display: none;
        }

        header.collapsed .brand-text-collapsed {
            display: block;
        }
        
        header.collapsed .brand {
            justify-content: center;
            margin-bottom: 16px;
            gap: 0;
            flex-direction: column;
            align-items: center;
        }

        .brand span { color: var(--primary); }

        /* === SEARCH BOX === */
        .search-box {
            position: relative;
            display: flex;
            align-items: center;
        }
        .search-box .material-icons {
            position: absolute;
            left: 12px;
            color: var(--text-muted);
            font-size: 20px;
            pointer-events: none;
            z-index: 1;
        }
        .search-box input {
            padding-left: 40px !important;
        }

        .toggle-sidebar {
            background: transparent;
            border: none;
            color: var(--text-sec);
            cursor: pointer;
            font-size: 1.2rem;
            padding: 6px;
            transition: var(--transition);
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: var(--radius);
            flex-shrink: 0;
            min-width: 36px;
            height: 36px;
        }

        .toggle-sidebar:hover {
            color: var(--primary);
            background-color: var(--bg-input);
        }

        header.collapsed .toggle-sidebar {
            transform: rotate(180deg);
        }

        nav {
            display: flex;
            flex-direction: column;
            gap: 4px;
            flex: 1;
        }

        nav button {
            background: transparent;
            border: none;
            color: var(--text-sec);
            cursor: pointer;
            padding: 10px 12px;
            border-radius: var(--radius);
            font-weight: 500;
            display: flex;
            align-items: center;
            gap: 12px;
            transition: var(--transition);
            font-size: 0.9rem;
            width: 100%;
            text-align: left;
            font-family: 'Ubuntu', sans-serif;
            border-left: 3px solid transparent;
            white-space: nowrap;
            min-height: 40px;
        }

        header.collapsed nav button {
            justify-content: center;
            gap: 0;
            padding: 10px;
            width: 100%;
            border-left: none;
        }

        nav button:hover {
            background-color: var(--bg-input);
            color: var(--primary);
        }

        nav button.active {
            background: linear-gradient(135deg, rgba(99, 102, 241, 0.12) 0%, rgba(79, 70, 229, 0.08) 100%);
            color: var(--primary);
            font-weight: 700;
            border-left: 3px solid var(--primary);
        }

        header.collapsed nav button.active {
            border-left: none;
            background: linear-gradient(135deg, rgba(99, 102, 241, 0.15) 0%, rgba(79, 70, 229, 0.1) 100%);
        }

        .nav-label {
            display: inline;
        }

        header.collapsed .nav-label {
            display: none;
        }

        .user-panel {
            margin-top: auto;
            padding-top: 15px;
            border-top: 1px solid var(--border);
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 10px;
        }

        header.collapsed .user-panel {
            flex-direction: column;
            justify-content: center;
        }
        
        .user-info-text { min-width: 0; }
        .user-info-text strong { display: block; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .user-info-text span { font-size: 0.75rem; color: var(--text-sec); white-space: nowrap; }

        header.collapsed .user-info-text {
            display: none;
        }

        .theme-toggle {
            background: transparent;
            border: 1px solid var(--border);
            color: var(--text-sec);
            cursor: pointer;
            padding: 8px;
            border-radius: var(--radius);
            font-size: 1rem;
            transition: var(--transition);
            display: flex;
            align-items: center;
        }

        .theme-toggle:hover {
            color: var(--primary);
            border-color: var(--primary);
        }

        /* === CONTENIDO PRINCIPAL === */
        main {
            margin-left: var(--sidebar-width);
            width: calc(100% - var(--sidebar-width));
            height: 100vh;
            padding: 30px 40px;
            overflow-y: auto;
            background-color: var(--bg-body);
            transition: var(--transition);
        }

        main.collapsed-main {
            margin-left: var(--sidebar-collapsed-width);
            width: calc(100% - var(--sidebar-collapsed-width));
        }

        /* === TARJETAS === */
        .card {
            background: var(--bg-surface);
            border-radius: var(--radius);
            border: 1px solid var(--border);
            margin-bottom: 24px;
            box-shadow: var(--shadow);
            transition: var(--transition);
        }
        .card:hover {
            border-color: #555;
            transform: translateY(-2px);
        }
        .card-header {
            padding: 16px 22px;
            border-bottom: 1px solid var(--border);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .card-header h4 { margin: 0; color: var(--text-main); font-size: 1.1rem; font-weight: 500;}
        .card-content { padding: 22px; }
        .card-actions {
            padding: 16px 22px;
            border-top: 1px solid var(--border);
            background: rgba(0,0,0,0.1);
            display: flex;
            justify-content: flex-end;
            gap: 12px;
        }

        .grid-container {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 24px;
        }

        /* === INPUTS & FORMS === */
        .form-group { margin-bottom: 18px; position: relative; }
        .form-group label {
            display: block; margin-bottom: 8px; font-size: 0.8rem;
            color: var(--text-sec); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px;
        }
        input:not([type="checkbox"]), select, textarea {
            width: 100%; padding: 12px 16px;
            background: var(--bg-input); 
            border: 1px solid var(--border);
            border-radius: var(--radius); 
            color: var(--text-main); 
            font-size: 0.95rem;
            font-family: 'Ubuntu', sans-serif;
            transition: var(--transition);
        }
        input:focus, select:focus, textarea:focus { 
            border-color: var(--primary); 
            background: var(--bg-surface);
            box-shadow: 0 0 0 3px rgba(233, 84, 32, 0.2);
        }

        /* === TABLAS === */
        .table-wrapper {
            border: 1px solid var(--border);
            border-radius: var(--radius);
            overflow: auto;
            max-height: 600px;
        }
        table { width: 100%; border-collapse: collapse; }
        th {
            background: #333; 
            color: var(--text-sec);
            font-size: 0.75rem; 
            font-weight: 700;
            text-transform: uppercase;
            padding: 14px 18px; 
            text-align: left;
            border-bottom: 2px solid var(--primary);
            letter-spacing: 0.5px;
        }
        td {
            padding: 14px 18px; 
            border-bottom: 1px solid var(--border);
            color: var(--text-main); 
            font-size: 0.9rem;
        }
        tbody tr:hover { 
            background-color: rgba(255,255,255,0.03); 
        }
        tbody tr { transition: var(--transition); }

        /* === BOTONES === */
        .btn {
            padding: 10px 20px; 
            border-radius: var(--radius); 
            border: 1px solid transparent;
            font-weight: 700; 
            cursor: pointer; 
            display: inline-flex;
            align-items: center; 
            gap: 8px; 
            font-size: 0.9rem;
            font-family: 'Ubuntu', sans-serif;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            transition: var(--transition);
        }
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: var(--shadow);
        }
        .btn-primary { 
            background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
            color: white; 
            border-color: var(--primary);
            box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
        }
        .btn-primary:hover { 
            background: linear-gradient(135deg, var(--primary-hover) 0%, var(--primary) 100%);
            border-color: var(--primary-hover);
            box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35);
        }

        .btn-secondary { 
            background: var(--bg-input); 
            color: var(--text-sec); 
            border-color: var(--border); 
        }
        .btn-secondary:hover { background: #444; color: var(--text-main); border-color: #555; }

        .btn-warning { 
            background: linear-gradient(135deg, rgba(245, 158, 11, 0.12) 0%, rgba(245, 158, 11, 0.08) 100%);
            color: #f59e0b; 
            border-color: rgba(245, 158, 11, 0.3);
        }
        .btn-warning:hover { 
            background: linear-gradient(135deg, rgba(245, 158, 11, 0.25) 0%, rgba(245, 158, 11, 0.18) 100%);
            color: #d97706;
            box-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
        }

        .btn-danger { 
            background: linear-gradient(135deg, rgba(244, 63, 94, 0.12) 0%, rgba(244, 63, 94, 0.08) 100%);
            color: var(--danger); 
            border-color: rgba(244, 63, 94, 0.3);
        }
        .btn-danger:hover { 
            background: linear-gradient(135deg, rgba(244, 63, 94, 0.25) 0%, rgba(244, 63, 94, 0.18) 100%);
            color: #e11d48;
            box-shadow: 0 4px 12px rgba(244, 63, 94, 0.2);
        }

        /* === MODALES === */
        .modal-overlay {
            position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0,0,0,0.6); 
            backdrop-filter: blur(8px);
            z-index: 2000; display: flex; align-items: center; justify-content: center;
        }
        .modal {
            background: var(--bg-surface); 
            border: 1px solid var(--border);
            border-radius: 12px; 
            width: 90%; 
            max-width: 800px;
            box-shadow: 0 20px 50px rgba(0,0,0,0.5); 
            display: flex; 
            flex-direction: column;
            max-height: 90vh;
            overflow: hidden;
        }
        .modal-header { 
            padding: 20px 25px; 
            border-bottom: 1px solid var(--border); 
            display: flex; 
            justify-content: space-between; 
            align-items: center; 
            background: var(--bg-surface);
            border-radius: 12px 12px 0 0;
        }

        .modal-header h3 {
            color: var(--text-main);
            margin: 0;
            font-weight: 600;
        }

        .modal-close-btn {
            background: transparent !important;
            border: none !important;
            color: var(--text-sec) !important;
            font-size: 1.8rem !important;
            cursor: pointer;
            padding: 4px 8px !important;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: var(--radius) !important;
            transition: var(--transition);
            min-width: 40px;
            height: 40px;
        }

        .modal-close-btn:hover {
            color: var(--danger) !important;
            background-color: rgba(239, 68, 68, 0.1) !important;
        }

        .modal-body { 
            padding: 25px; 
            overflow-y: auto; 
            background: var(--bg-body);
            flex: 1;
        }
        
        .modal-footer {
            padding: 15px 20px;
            border-top: 1px solid var(--border);
            display: flex;
            gap: 10px;
            justify-content: flex-end;
            background: var(--bg-surface);
            border-radius: 0 0 12px 12px;
        }

        /* === LOGIN === */
        #login-screen { background: var(--bg-body); }
        #login-screen .card { 
            background: var(--bg-surface); 
            border: 1px solid var(--border); 
            box-shadow: var(--shadow);
        }
        #login-screen h2 { color: var(--text-main); font-weight: 600; }

        /* === LOADER === */
        #loader {
            position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: var(--bg-body); 
            z-index: 3000;
            display: flex; flex-direction: column; align-items: center; justify-content: center;
        }
        .spinner {
            width: 40px; height: 40px; 
            border: 4px solid rgba(255,255,255,0.1);
            border-top-color: var(--primary); 
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }
        @keyframes spin { 100% { transform: rotate(360deg); } }
        @keyframes pulse { 
            0%, 100% { opacity: 1; } 
            50% { opacity: 0.6; } 
        }
        @keyframes slideRight {
            0%, 100% { width: 100%; }
            50% { width: 95%; }
        }
        @keyframes alertPulse {
            0%, 100% { transform: scale(1); box-shadow: 0 4px 12px rgba(217, 48, 37, 0.4), inset 0 1px 2px rgba(255, 255, 255, 0.2); }
            50% { transform: scale(1.08); box-shadow: 0 6px 16px rgba(217, 48, 37, 0.5), inset 0 1px 2px rgba(255, 255, 255, 0.2); }
        }

        /* === AUTOCOMPLETE === */
        .autocomplete-list {
            position: absolute; top: 100%; left: 0; right: 0;
            background: var(--bg-input); 
            border: 1px solid var(--border);
            border-radius: 0 0 var(--radius) var(--radius); 
            z-index: 50; 
            max-height: 200px; 
            overflow-y: auto;
            box-shadow: var(--shadow);
        }
        .autocomplete-item { 
            padding: 12px 18px; 
            border-bottom: 1px solid var(--border); 
            cursor: pointer; 
            color: var(--text-main); 
            transition: var(--transition);
        }
        .autocomplete-item:last-child { border-bottom: none; }
        .autocomplete-item:hover { background: var(--primary); }
        
        /* === BADGES === */
        .stock-tag { 
            padding: 5px 10px; 
            border-radius: 20px; /* Pill shape */
            font-size: 0.75rem; 
            font-weight: 700;
            text-transform: uppercase;
        }
        .stock-ok { background: rgba(18, 161, 93, 0.2); color: var(--success); }
        .stock-low { background: rgba(218, 68, 83, 0.2); color: var(--danger); }

        /* === KPIs (Dashboard Cards) === */
        .kpi-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 24px;
        }
        .kpi-card { 
            background: var(--bg-surface); 
            border: 1px solid var(--border); 
            color: var(--text-main); 
            border-radius: var(--radius);
            padding: 20px;
            display: flex;
            align-items: center;
            gap: 20px;
        }
        .kpi-icon {
            flex-shrink: 0;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .kpi-icon .material-icons {
            color: white;
            font-size: 24px;
        }
        .kpi-info h3 { margin: 0; font-size: 1.8rem; font-weight: 700; }
        .kpi-info p { margin: 4px 0 0 0; color: var(--text-sec); font-size: 0.85rem; }
        
        /* === ALERTAS DE STOCK - BANNER STYLE === */
        .alert-banner {
            background: linear-gradient(135deg, #fef2f2 0%, #fef5f5 100%);
            border: 2px solid #f43f5e;
            border-radius: 8px;
            box-shadow: 0 8px 24px rgba(244, 63, 94, 0.2);
            position: relative;
            overflow: hidden;
        }
        .alert-banner::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 3px;
            background: linear-gradient(90deg, #f43f5e, #fb7185, #f43f5e);
            animation: slideAlert 3s ease-in-out infinite;
        }
        @keyframes slideAlert {
            0%, 100% { background-position: 0% center; }
            50% { background-position: 100% center; }
        }
        #alert-list {
            display: grid;
            gap: 8px;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        }
        .alert-item {
            background: white;
            border: 1px solid #fda4af;
            border-left: 3px solid #f43f5e;
            border-radius: 4px;
            padding: 10px 12px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 12px;
            cursor: pointer;
            transition: all 0.2s ease;
            box-shadow: 0 2px 6px rgba(244, 63, 94, 0.12);
        }
        .alert-item:hover {
            box-shadow: 0 6px 16px rgba(244, 63, 94, 0.25);
            transform: translateY(-2px);
            border-color: #fb7185;
        }
        .alert-item strong {
            color: #be123c;
            font-size: 12px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.3px;
        }
        .alert-item small {
            color: #f43f5e;
            font-size: 11px;
            font-weight: 600;
        }

        /* === PAGE & TABS === */
        .page-header {
            margin-bottom: 30px;
        }
        .page-header h2 {
            margin: 0;
            font-size: 1.8rem;
            font-weight: 700;
        }
        .page-header p {
            color: var(--text-sec);
            margin: 5px 0 0 0;
        }
        .tab-nav {
            display: flex;
            border-bottom: 1px solid var(--border);
            margin-bottom: 30px;
            gap: 10px;
        }
        .tab-nav button {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            background: none;
            border: none;
            color: var(--text-sec);
            padding: 10px 15px;
            cursor: pointer;
            font-size: 0.95rem;
            font-weight: 500;
            font-family: 'Ubuntu', sans-serif;
            border-bottom: 3px solid transparent;
            transition: var(--transition);
            border-radius: 4px 4px 0 0;
        }
        .tab-nav button:hover {
            color: var(--text-main);
            background: var(--bg-input);
        }
        .tab-nav button.active {
            color: var(--primary);
            font-weight: 700;
            border-bottom-color: var(--primary);
        }

        /* CC Stats Cards */
        .cc-stat-card {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 14px 18px;
            background: var(--bg-surface);
            border-radius: 8px;
            border: 1px solid var(--border);
        }
        .cc-stat-value {
            font-size: 1.3rem;
            font-weight: bold;
        }
        .cc-stat-label {
            font-size: 0.78rem;
            color: var(--text-sec);
        }
        
        /* Single Column Layout for Forms */
        #comp-view-new .grid-container,
        #depo-view-entradas .grid-container,
        #depo-view-salidas .grid-container,
        #depo-view-new .grid-container,
        #depo-view-adj .grid-container,
        #conf-view-params .grid-container,
        #conf-view-system .grid-container {
            grid-template-columns: 1fr;
            max-width: 1000px; 
        }

        /* === CHAT STYLES === */

        /* ---- Layout ---- */
        .chat-container {
            display: grid;
            grid-template-columns: 300px 1fr;
            height: calc(100vh - 120px);
            overflow: hidden;
            background: var(--bg-surface);
            border-radius: var(--radius);
            border: 1px solid var(--border);
            box-shadow: var(--shadow);
        }

        /* ---- Sidebar ---- */
        .conversaciones-lista {
            background: var(--bg-body);
            border-right: 1px solid var(--border);
            overflow-y: auto;
            display: flex;
            flex-direction: column;
        }
        .conversaciones-lista::-webkit-scrollbar { width: 5px; }
        .conversaciones-lista::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

        .conversacion-item {
            padding: 12px 16px;
            cursor: pointer;
            transition: background 0.12s;
            border-bottom: 1px solid var(--border);
            position: relative;
        }
        .conversacion-item:hover { background: var(--bg-input); }
        .conversacion-item.active {
            background: rgba(99,102,241,0.08);
            border-left: 3px solid var(--primary);
        }
        html[data-theme="dark"] .conversacion-item.active {
            background: rgba(129,140,248,0.12);
        }

        .conversacion-item-header {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            margin-bottom: 3px;
        }

        .conversacion-titulo {
            font-weight: 600;
            color: var(--text-main);
            font-size: 0.92rem;
            flex: 1;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .conversacion-fecha {
            font-size: 0.7rem;
            color: var(--text-muted);
            white-space: nowrap;
            margin-left: 6px;
        }

        .conversacion-ultimo-mensaje {
            color: var(--text-sec);
            font-size: 0.82rem;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .conversacion-badge {
            position: absolute;
            top: 12px;
            right: 12px;
            background: var(--primary);
            color: white;
            font-size: 0.66rem;
            min-width: 18px;
            height: 18px;
            border-radius: 9px;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 0 5px;
            font-weight: 700;
        }

        /* ---- Chat panel ---- */
        .chat-panel {
            background: var(--bg-surface);
            display: flex;
            flex-direction: column;
            height: 100%;
            overflow: hidden;
        }

        #chat-activo {
            display: flex;
            flex-direction: column;
            flex: 1;
            min-height: 0;
            overflow: hidden;
        }

        .chat-header {
            padding: 10px 16px;
            border-bottom: 1px solid var(--border);
            background: var(--bg-surface);
            display: flex;
            justify-content: space-between;
            align-items: center;
            min-height: 58px;
            flex-shrink: 0;
            box-shadow: 0 1px 4px rgba(0,0,0,0.06);
        }

        .chat-header-titulo {
            font-size: 1rem;
            font-weight: 700;
            color: var(--text-main);
        }

        .chat-header-info {
            font-size: 0.76rem;
            color: var(--text-sec);
            margin-top: 1px;
        }

        /* ---- Messages area ---- */
        .mensajes-container {
            flex: 1;
            min-height: 0;
            overflow-y: auto;
            padding: 16px;
            display: flex;
            flex-direction: column;
            gap: 4px;
            background: var(--bg-body);
        }

        .mensajes-container::-webkit-scrollbar { width: 5px; }
        .mensajes-container::-webkit-scrollbar-track { background: transparent; }
        .mensajes-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

        /* ---- Date separator ---- */
        .chat-fecha-separador {
            display: flex;
            align-items: center;
            gap: 10px;
            margin: 14px 0 6px;
            color: var(--text-muted);
            font-size: 0.73rem;
        }
        .chat-fecha-separador::before,
        .chat-fecha-separador::after {
            content: '';
            flex: 1;
            height: 1px;
            background: var(--border);
        }
        .chat-fecha-separador span {
            background: var(--bg-surface);
            border: 1px solid var(--border);
            padding: 2px 10px;
            border-radius: 10px;
            font-size: 0.71rem;
            font-weight: 600;
            white-space: nowrap;
        }

        /* ---- Message row ---- */
        .mensaje {
            display: flex;
            gap: 8px;
            padding: 1px 0;
            animation: msgIn 0.18s ease-out;
            align-items: flex-end;
        }

        @keyframes msgIn {
            from { opacity: 0; transform: translateY(5px); }
            to   { opacity: 1; transform: translateY(0); }
        }

        .mensaje.propio {
            flex-direction: row-reverse;
        }

        /* Avatar */
        .mensaje-avatar {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
            font-size: 0.7rem;
            flex-shrink: 0;
            align-self: flex-end;
        }

        .mensaje.propio .mensaje-avatar { display: none; }

        /* Bubble wrapper */
        .mensaje-contenido {
            max-width: 70%;
            display: flex;
            flex-direction: column;
            align-items: flex-start;
        }

        .mensaje.propio .mensaje-contenido {
            align-items: flex-end;
        }

        .mensaje-autor {
            font-weight: 600;
            font-size: 0.75rem;
            color: var(--primary);
            margin-bottom: 3px;
            padding-left: 12px;
        }

        /* ---- Bubble ---- */
        .mensaje-burbuja {
            padding: 8px 12px 5px;
            border-radius: 16px;
            line-height: 1.5;
            word-wrap: break-word;
            word-break: break-word;
            max-width: 100%;
            font-size: 0.92rem;
            box-shadow: var(--shadow);
        }

        /* Others bubble */
        .mensaje .mensaje-burbuja {
            background: var(--bg-surface);
            color: var(--text-main);
            border: 1px solid var(--border);
            border-bottom-left-radius: 4px;
        }

        /* Own bubble */
        .mensaje.propio .mensaje-burbuja {
            background: var(--primary);
            color: #fff;
            border: none;
            border-bottom-right-radius: 4px;
        }

        /* Timestamp */
        .mensaje-burbuja .burbuja-hora {
            display: block;
            text-align: right;
            margin-top: 3px;
            font-size: 0.62rem;
            white-space: nowrap;
            line-height: 1;
        }

        .mensaje .burbuja-hora { color: var(--text-muted); }

        .mensaje.propio .burbuja-hora { color: rgba(255,255,255,0.75); }

        .mensaje.propio .burbuja-hora::after {
            content: ' \2713\2713';
            color: rgba(255,255,255,0.6);
        }

        /* ---- Mention chip ---- */
        .chat-mencion {
            display: inline-block;
            color: var(--primary);
            background: rgba(99,102,241,0.1);
            padding: 1px 6px;
            border-radius: 4px;
            font-weight: 600;
            cursor: pointer;
            font-size: 0.9em;
        }
        .chat-mencion:hover {
            background: rgba(99,102,241,0.18);
            text-decoration: underline;
        }

        /* ---- System message ---- */
        .mensaje-sistema {
            align-self: center;
            text-align: center;
            width: 100%;
            margin: 8px 0;
        }
        .mensaje-sistema .mensaje-burbuja {
            display: inline-block;
            background: var(--bg-input);
            color: var(--text-muted);
            border: 1px solid var(--border);
            font-size: 0.77rem;
            font-style: italic;
            padding: 4px 14px;
            border-radius: 20px;
            box-shadow: none;
        }

        /* ---- File / image attachments ---- */
        .mensaje-archivo {
            display: inline-flex;
            align-items: center;
            gap: 10px;
            padding: 8px 12px;
            background: var(--bg-input);
            border: 1px solid var(--border);
            border-radius: 8px;
            margin-bottom: 2px;
            cursor: pointer;
            transition: var(--transition);
        }
        .mensaje-archivo:hover { box-shadow: var(--shadow-hover); }
        .mensaje-archivo .material-icons { color: var(--primary); font-size: 22px; }
        .mensaje.propio .mensaje-archivo {
            background: rgba(255,255,255,0.15);
            border-color: rgba(255,255,255,0.3);
        }
        .mensaje.propio .mensaje-archivo .material-icons { color: rgba(255,255,255,0.9); }

        .mensaje-imagen { border-radius: 10px; overflow: hidden; margin-bottom: 2px; max-width: 280px; }
        .mensaje-imagen img { width: 100%; display: block; border-radius: 10px; cursor: pointer; }
        .mensaje-imagen img:hover { opacity: 0.9; }

        /* ---- Input area ---- */
        .chat-input-container {
            flex-shrink: 0;
            padding: 10px 14px 12px;
            background: var(--bg-surface);
            border-top: 1px solid var(--border);
        }

        .chat-input-wrapper {
            display: flex;
            gap: 6px;
            align-items: flex-end;
            background: var(--bg-input);
            border: 1px solid var(--border);
            border-radius: 24px;
            padding: 4px 6px 4px 14px;
            transition: border-color 0.2s, box-shadow 0.2s;
        }

        .chat-input-wrapper:focus-within {
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
        }

        .chat-input {
            flex: 1;
            min-height: 34px;
            max-height: 110px;
            padding: 6px 4px;
            border: none;
            background: transparent;
            color: var(--text-main);
            font-family: 'Ubuntu', sans-serif;
            font-size: 0.93rem;
            resize: none;
            line-height: 1.45;
        }
        .chat-input::placeholder { color: var(--text-muted); }
        .chat-input:focus { outline: none; }

        .chat-attach-btn {
            background: none;
            border: none;
            color: var(--text-muted);
            cursor: pointer;
            padding: 6px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.15s;
        }
        .chat-attach-btn:hover { color: var(--primary); background: rgba(99,102,241,0.08); }
        .chat-attach-btn .material-icons { font-size: 21px; }

        .chat-send-btn {
            background: var(--primary);
            border: none;
            color: white;
            width: 38px;
            height: 38px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            flex-shrink: 0;
            transition: background 0.15s, transform 0.1s;
        }
        .chat-send-btn:hover { background: var(--primary-hover); transform: scale(1.05); }
        .chat-send-btn .material-icons { font-size: 19px; }

        /* ---- Mention dropdown ---- */
        .mencion-item {
            padding: 10px 14px;
            cursor: pointer;
            transition: background 0.12s;
            border-bottom: 1px solid var(--border);
        }
        .mencion-item:hover, .mencion-item.selected { background: var(--bg-input); }
        .mencion-item-header { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
        .mencion-item-badge {
            font-size: 0.67rem;
            padding: 2px 6px;
            border-radius: 4px;
            font-weight: 700;
            text-transform: uppercase;
        }
        .mencion-item-badge.solicitud { background: rgba(99,102,241,0.1); color: var(--primary); }
        .mencion-item-badge.oc        { background: rgba(16,185,129,0.1); color: var(--success); }
        .mencion-item-titulo { font-weight: 600; font-size: 0.87rem; color: var(--text-main); }
        .mencion-item-desc   { font-size: 0.79rem; color: var(--text-sec); }

        /* ---- Empty state ---- */
        .chat-empty {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100%;
            color: var(--text-muted);
            text-align: center;
            padding: 40px;
            background: var(--bg-body);
        }
        .chat-empty .material-icons { font-size: 64px; opacity: 0.25; margin-bottom: 16px; color: var(--primary); }
        .chat-empty h3 { color: var(--text-sec); margin-bottom: 8px; font-weight: 500; }
        .chat-empty p { color: var(--text-muted); font-size: 0.9rem; }

        /* ---- Search bar ---- */
        #chat-search-bar { animation: slideDown 0.2s ease-out; }
        @keyframes slideDown {
            from { opacity: 0; transform: translateY(-8px); }
            to   { opacity: 1; transform: translateY(0); }
        }
        #chat-search-messages:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
        }
        mark { background: #fef08a; color: #713f12; font-weight: 600; padding: 1px 3px; border-radius: 3px; }

        /* ---- Reference badge ---- */
        .referencia-badge {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            padding: 2px 8px;
            background: rgba(99,102,241,0.1);
            color: var(--primary);
            border-radius: 4px;
            font-size: 0.72rem;
            font-weight: 600;
            border: 1px solid rgba(99,102,241,0.2);
        }
        .referencia-badge .material-icons { font-size: 13px; }


                /* ============ TOAST NOTIFICATIONS ============ */
        #toast-container {
            position: fixed;
            bottom: 24px;
            right: 24px;
            z-index: 99999;
            display: flex;
            flex-direction: column-reverse;
            gap: 8px;
            pointer-events: none;
        }
        .toast {
            padding: 12px 18px;
            border-radius: 8px;
            font-size: 0.88rem;
            color: #fff;
            max-width: 340px;
            box-shadow: 0 4px 14px rgba(0,0,0,0.18);
            transition: opacity 0.3s ease;
            pointer-events: auto;
            line-height: 1.4;
            animation: toastSlideIn 0.25s ease;
        }
        @keyframes toastSlideIn {
            from { opacity: 0; transform: translateY(16px); }
            to   { opacity: 1; transform: translateY(0); }
        }
        .toast-success { background: #1e8e3e; }
        .toast-error   { background: #d93025; }
        .toast-info    { background: #1a73e8; }
        .toast-warning { background: #e37400; }

        /* ===== Custom Dialog / Confirm / Prompt Modal ===== */
        .custom-dialog-overlay {
            position: fixed; inset: 0;
            background: rgba(0,0,0,0.45);
            z-index: 200000;
            display: flex; align-items: center; justify-content: center;
            animation: dialogFadeIn 0.18s ease;
        }
        .custom-dialog-overlay.hidden { display: none !important; }
        @keyframes dialogFadeIn {
            from { opacity: 0; } to { opacity: 1; }
        }
        .custom-dialog-box {
            background: #fff;
            border-radius: 14px;
            padding: 28px 30px 22px;
            max-width: 440px; width: 90%;
            box-shadow: 0 12px 40px rgba(0,0,0,0.22);
            animation: dialogSlideUp 0.2s ease;
        }
        @keyframes dialogSlideUp {
            from { opacity: 0; transform: translateY(20px); }
            to   { opacity: 1; transform: translateY(0); }
        }
        .custom-dialog-box p {
            margin: 0 0 18px;
            font-size: 0.95rem;
            line-height: 1.55;
            white-space: pre-line;
            color: var(--text-main, #202124);
        }
        .custom-dialog-input {
            width: 100%; box-sizing: border-box;
            padding: 9px 12px; border: 1px solid #ccc;
            border-radius: 8px; font-size: 0.92rem;
            margin-bottom: 16px; outline: none;
        }
        .custom-dialog-input:focus { border-color: var(--primary, #1a73e8); box-shadow: 0 0 0 2px rgba(26,115,232,0.2); }
        .custom-dialog-input.hidden { display: none !important; }
        .custom-dialog-btns {
            display: flex; gap: 10px; justify-content: flex-end;
        }

        /* === MÓDULO GASTOS POR PROYECTO === */

        /* Badge genérico (usado en gastos) */
        .badge {
            display: inline-flex; align-items: center; gap: 4px;
            padding: 3px 10px; border-radius: 12px;
            font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
            letter-spacing: 0.4px; line-height: 1.4;
            white-space: nowrap;
        }
        .badge-success { background: rgba(16,185,129,0.12); color: var(--success, #10b981); }
        .badge-warning { background: rgba(245,158,11,0.12); color: var(--warning, #f59e0b); }
        .badge-danger  { background: rgba(239,68,68,0.12);  color: var(--danger,  #ef4444); }
        .badge-primary { background: rgba(99,102,241,0.12); color: var(--primary, #6366f1); }
        .badge-neutral { background: rgba(100,116,139,0.12); color: #64748b; }

        /* Botón pequeño */
        .btn-sm {
            padding: 5px 12px !important;
            font-size: 0.82rem !important;
            gap: 4px !important;
        }
        .btn-icon-sm {
            display: inline-flex; align-items: center; justify-content: center;
            width: 30px; height: 30px; border-radius: var(--radius);
            border: none; cursor: pointer; background: transparent;
            color: var(--text-sec); transition: var(--transition);
        }
        .btn-icon-sm:hover       { background: var(--bg-input); }
        .btn-icon-sm.btn-danger:hover { background: rgba(239,68,68,0.1); color: var(--danger); }
        .btn-icon-sm .material-icons { font-size: 16px; }

        /* Grid de proyectos */
        .gastos-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
            gap: 16px;
        }

        /* Tarjeta de proyecto */
        .gasto-card {
            background: var(--bg-surface);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 16px 20px;
            cursor: pointer;
            transition: var(--transition);
            display: flex; flex-direction: column; gap: 12px;
        }
        .gasto-card:hover {
            border-color: var(--primary);
            box-shadow: 0 4px 12px rgba(99,102,241,0.12);
            transform: translateY(-2px);
        }
        .gasto-card-header {
            display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
        }
        .gasto-card-title {
            display: flex; align-items: flex-start; gap: 10px; flex: 1; min-width: 0;
        }
        .gasto-card-icon {
            color: var(--primary); font-size: 24px; flex-shrink: 0; margin-top: 2px;
        }
        .gasto-card-title h4 {
            margin: 0; font-size: 0.97rem; font-weight: 700;
            color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        }
        .gasto-card-sub {
            display: block; font-size: 0.8rem; color: var(--text-sec); margin-top: 2px;
        }

        /* Barra de progreso */
        .gasto-progress-wrap { display: flex; flex-direction: column; gap: 4px; }
        .gasto-progress-bar {
            height: 6px; background: var(--bg-input); border-radius: 3px; overflow: hidden;
        }
        .gasto-progress-fill {
            height: 100%; border-radius: 3px; transition: width 0.5s ease;
        }
        .gasto-progress-label {
            display: flex; justify-content: space-between;
            font-size: 0.78rem; color: var(--text-sec);
        }

        /* Stats de la card */
        .gasto-card-stats {
            display: flex; gap: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
        }
        .gasto-stat {
            flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
            padding: 8px 4px; text-align: center;
        }
        .gasto-stat:not(:last-child) { border-right: 1px solid var(--border); }
        .gasto-stat .material-icons   { font-size: 16px; color: var(--primary); }
        .gasto-stat > span > small    { display: block; font-size: 0.7rem; color: var(--text-muted); }
        .gasto-stat > span            { font-size: 0.82rem; font-weight: 600; color: var(--text-main); line-height: 1.2; }

        /* Fechas en card */
        .gasto-card-fechas {
            display: flex; gap: 12px; flex-wrap: wrap;
            font-size: 0.78rem; color: var(--text-sec);
        }
        .gasto-card-fechas span {
            display: flex; align-items: center; gap: 3px;
        }
        .gasto-card-fechas .material-icons { font-size: 13px; }

        /* KPI cards del detalle */
        .gastos-kpis {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            gap: 12px;
        }
        .gasto-kpi-card {
            background: var(--bg-surface); border: 1px solid var(--border);
            border-radius: var(--radius); padding: 14px 16px;
            display: flex; align-items: center; gap: 12px;
        }
        .gasto-kpi-card.gasto-kpi-danger { border-color: rgba(239,68,68,0.3); }
        .gasto-kpi-card .material-icons  { font-size: 28px; flex-shrink: 0; }
        .gasto-kpi-value {
            font-size: 1.05rem; font-weight: 700; color: var(--text-main); line-height: 1.2;
        }
        .gasto-kpi-label {
            font-size: 0.78rem; color: var(--text-sec); margin-top: 2px;
        }

        /* ── Sub-obras / Rubros en modal-proyecto ───────────────────────── */
        .subobra-item {
            border: 1px solid var(--border);
            border-radius: 8px;
            overflow: hidden;
            background: var(--bg-main);
        }
        .subobra-header {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 8px 10px;
            background: var(--bg-surface);
            cursor: default;
        }
        .subobra-rubros {
            padding: 6px 10px 10px 28px;
            display: flex;
            flex-direction: column;
            gap: 4px;
        }
        .rubro-item {
            display: flex;
            align-items: center;
            gap: 6px;
            padding: 3px 4px;
            border-radius: 4px;
        }
        .rubro-item:hover { background: var(--bg-hover, rgba(99,102,241,0.06)); }
        .rubro-add-row {
            display: flex;
            gap: 6px;
            align-items: center;
            margin-top: 6px;
        }
        .form-control-sm {
            flex: 1;
            padding: 5px 8px;
            border: 1px solid var(--border);
            border-radius: 6px;
            background: var(--bg-surface);
            color: var(--text-main);
            font-size: 0.85rem;
        }
        .form-control-sm:focus { outline: 2px solid var(--primary); }
