:root {
    /* UI Palette - Light Mode */
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --accent: #0ea5e9;
    --bg-main: #f8fafc;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.3);
    --panel-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
    --card-bg: rgba(255, 255, 255, 0.8);
    --sidebar-w: 260px;
    --border-radius: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-main: #0b0f1a;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --glass-bg: rgba(15, 23, 42, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --card-bg: rgba(30, 41, 59, 0.8);
    --panel-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Plus Jakarta Sans', sans-serif;
}

body {
    background: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background 0.5s ease;
}

/* Glassmorphism System */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    box-shadow: var(--panel-shadow);
}

.main-glass-bg {
    background: radial-gradient(circle at top left, #4f46e522 0%, transparent 40%),
        radial-gradient(circle at bottom right, #0ea5e922 0%, transparent 40%);
}

/* Screens */
.screen {
    width: 100%;
    height: 100vh;
    display: flex;
}

/* Loader */
.loader-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-main);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Login */
#login-screen {
    align-items: center;
    justify-content: center;
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 3rem;
    text-align: center;
}

.logo {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -1px;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.logo span {
    color: var(--text-main);
    font-weight: 500;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 2rem;
}

.input-group {
    text-align: left;
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.input-group input {
    width: 100%;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    transition: var(--transition);
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.1);
}

.btn-primary {
    width: 100%;
    padding: 0.8rem;
    border-radius: 12px;
    border: none;
    background: var(--primary);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

.login-footer {
    margin-top: 2rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.login-footer span {
    font-weight: 700;
    color: var(--primary);
}

.btn-secondary {
    padding: 0.8rem 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--primary);
}

.btn-sm-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-sm-icon:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-2px);
}

.btn-sm-icon.danger:hover {
    background: #ef4444;
    border-color: #ef4444;
}

.custom-badge {
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Layout */
.sidebar {
    width: var(--sidebar-w);
    height: calc(100vh - 40px);
    margin: 20px 0 20px 20px;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 2rem;
}

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

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.8rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    transition: var(--transition);
}

.nav-link i {
    font-size: 1.2rem;
    margin-right: 1rem;
}

.nav-link:hover,
.nav-link.active {
    background: var(--primary);
    color: white;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-pill {
    flex: 1;
    padding: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.user-info span {
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.logout-btn {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.logout-btn:hover {
    background: #ef4444;
    color: white;
}

/* Content Area */
.content-area {
    flex: 1;
    padding: 20px 40px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Responsive Grid System */
.layout-grid {
    display: grid;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.grid-2-1 {
    grid-template-columns: 2fr 1fr;
}

.grid-1-1 {
    grid-template-columns: 1fr 1fr;
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1200px) {
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 850px) {
    .grid-3, .grid-4 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

@media (max-width: 1200px) {

    .grid-2-1,
    .grid-1-1 {
        grid-template-columns: 1fr;
    }
}

.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.theme-toggle {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.theme-toggle .sun {
    display: none;
}

[data-theme="dark"] .theme-toggle .sun {
    display: block;
    color: #fbbf24;
}

[data-theme="dark"] .theme-toggle .moon {
    display: none;
}

.notifications-bell {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    padding: 1.5rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

/* Table Style */
.table-container {
    padding: 1.5rem;
    margin-top: 1.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
    border-bottom: 1px solid var(--glass-border);
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.badge-info {
    background: rgba(14, 165, 233, 0.1);
    color: #0ea5e9;
}

/* ============================================
   REFACTORIZACIÓN NUCLEAR UI (DEFINTIVA)
   ============================================ */

/* 1. Reset de Modales SweetAlert2 */
body.swal2-shown .swal2-container {
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    background: rgba(15, 23, 42, 0.5) !important;
}

/* Ocultamiento Total y Absoluto de Elementos Fantasmas */
body.swal2-shown .swal2-checkbox, 
body.swal2-shown .swal2-footer, 
body.swal2-shown .swal2-progress-steps, 
body.swal2-shown .swal2-validation-message,
.swal2-checkbox, .swal2-footer {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    overflow: hidden !important;
}

.swal2-popup {
    border-radius: 24px !important;
    background: var(--card-bg) !important;
    backdrop-filter: blur(30px) !important;
    -webkit-backdrop-filter: blur(30px) !important;
    border: 1px solid var(--glass-border) !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5) !important;
    padding: 3rem !important;
    max-width: 95% !important;
}

/* 2. Legibilidad Absoluta (Forzar Colores Sólidos) */
.swal2-input, 
.swal2-textarea, 
select.swal2-input, 
select.swal2-select,
.ticket-select {
    background-color: rgba(255, 255, 255, 0.4) !important;
    border: 1px solid rgba(0, 0, 0, 0.2) !important;
    border-radius: 14px !important;
    color: #000000 !important; /* Negro puro para lectura infalible */
    font-size: 0.9rem !important;
    font-weight: 500 !important;
    margin: 5px 0 !important;
    height: 46px !important;
    width: 100% !important;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05) !important;
    transition: all 0.2s ease !important;
}

[data-theme="dark"] .swal2-input, 
[data-theme="dark"] .swal2-textarea, 
[data-theme="dark"] select.swal2-input,
[data-theme="dark"] .ticket-select {
    background-color: rgba(255, 255, 255, 0.05) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important; /* Blanco puro en modo oscuro */
    box-shadow: none !important;
}

/* Fix Autocompletado Chrome/Safari */
input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus {
    -webkit-text-fill-color: #000000 !important;
    -webkit-box-shadow: 0 0 0px 1000px #ffffff inset !important;
    transition: background-color 5000s ease-in-out 0s !important;
}

[data-theme="dark"] input:-webkit-autofill,
[data-theme="dark"] input:-webkit-autofill:hover, 
[data-theme="dark"] input:-webkit-autofill:focus {
    -webkit-text-fill-color: #ffffff !important;
    -webkit-box-shadow: 0 0 0px 1000px #1e1e2d inset !important;
}

.swal2-input:focus, 
.swal2-textarea:focus, 
select:focus {
    border-color: var(--primary) !important;
    background-color: #ffffff !important;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15) !important;
}

[data-theme="dark"] .swal2-input:focus, 
[data-theme="dark"] .swal2-textarea:focus {
    background-color: rgba(255, 255, 255, 0.08) !important;
}

/* 3. Estética de Flechas y Labels */
select.swal2-input, 
select.swal2-select, 
select.ticket-select, 
select {
    appearance: none !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2364748b' class='bi bi-chevron-down' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 1.25rem center !important;
    background-size: 1rem !important;
    padding: 0 3rem 0 1.25rem !important;
}

[data-theme="dark"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23ffffff' class='bi bi-chevron-down' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E") !important;
}

.swal2-html-container label, 
.swal2-popup label,
.swal2-label,
.input-group label {
    display: block !important;
    font-size: 0.72rem !important;
    font-weight: 800 !important;
    color: var(--text-muted) !important;
    margin: 8px 0 2px 0 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.8px !important;
    text-align: left !important;
}

.swal2-textarea {
    min-height: 140px !important;
    padding: 1rem 1.25rem !important;
    line-height: 1.6 !important;
}

.swal2-actions {
    margin-top: 1.5rem !important;
    gap: 12px !important;
}
.swal2-styled.swal2-confirm {
    background-color: var(--primary) !important;
    border-radius: 12px !important;
    padding: 12px 2rem !important;
    font-size: 0.9rem !important;
    font-weight: 600 !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
}

.swal2-styled.swal2-cancel {
    background-color: #64748b !important;
    border-radius: 12px !important;
    padding: 12px 2rem !important;
    font-size: 0.9rem !important;
    font-weight: 600 !important;
}

/* ============================================
   OPTIMIZACIÓN RESPONSIVA (MOBILE & OVERFLOW)
   ============================================ */
.swal2-popup,
.swal2-html-container,
.swal2-content {
    max-height: 98vh !important;
    overflow-y: auto !important;
    display: flex !important;
    flex-direction: column !important;
    scrollbar-width: none !important; /* Firefox */
    -ms-overflow-style: none !important;  /* IE and Edge */
}

/* Hide scrollbar for Chrome, Safari and Opera */
.swal2-popup::-webkit-scrollbar,
.swal2-html-container::-webkit-scrollbar,
.swal2-content::-webkit-scrollbar {
    display: none !important;
}

/* Forzar que las grillas de 2 columnas se apilen en pantallas pequeñas */
@media (max-width: 850px) {
    .swal2-html-container div[style*="display: grid"],
    .swal2-html-container div[style*="display:grid"] {
        grid-template-columns: 1fr !important;
        gap: 0.6rem !important;
    }
    
    .swal2-html-container div[style*="grid-column"] {
        grid-column: 1 / -1 !important;
    }
    
    .swal2-popup {
        padding: 1.5rem 1rem !important;
        width: 95% !important;
    }
    
    .swal2-input, select.swal2-input, .ticket-select {
        height: 46px !important;
        font-size: 16px !important;
    }
}

@media (max-width: 480px) {
    .swal2-actions {
        flex-direction: column !important;
        width: 100% !important;
    }
    
    .swal2-actions button {
        width: 100% !important;
        margin: 5px 0 !important;
    }
}
/* ============================================
   MOBILE RESPONSIVENESS OVERRIDES
   ============================================ */
@media (max-width: 850px) {
    #sidebar-toggle {
        display: flex !important;
    }

    .sidebar {
        position: fixed !important;
        left: -320px !important;
        top: 0 !important;
        bottom: 0 !important;
        margin: 0 !important;
        z-index: 9999 !important;
        width: 280px !important;
        height: 100vh !important;
        transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
        border-radius: 0 !important;
        box-shadow: 20px 0 50px rgba(0,0,0,0.3) !important;
    }

    .sidebar.active {
        left: 0 !important;
    }

    .content-area {
        padding: 15px !important;
        width: 100% !important;
    }

    .top-header {
        margin-bottom: 1.5rem !important;
    }

    #live-clock {
        display: none !important;
    }
    
    #page-title {
        font-size: 1.25rem !important;
    }

    .login-card {
        padding: 1.5rem !important;
        width: 90% !important;
    }
}

@media (max-width: 480px) {
    .header-right {
        gap: 0.5rem !important;
    }
    
    .theme-toggle, .notifications-bell {
        width: 40px !important;
        height: 40px !important;
    }
}

/* ============================================
   RESPONSIVE GLOBAL OVERRIDES
   ============================================ */
@media (max-width: 850px) {
    /* Main module header container styling */
    #content-view > div[style*="display: flex"][style*="justify-content: space-between"],
    #content-view > div[style*="display:flex"][style*="justify-content:space-between"] {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1.25rem !important;
        margin-top: 0 !important;
        margin-bottom: 1.5rem !important;
        height: auto !important;
    }
    
    /* Subtitle description */
    #content-view > div[style*="display: flex"] > div:first-child,
    #content-view > div[style*="display:flex"] > div:first-child {
        width: 100% !important;
    }

    /* Actions row container (search, filters, buttons) */
    #content-view > div[style*="display: flex"] > div[style*="display: flex"][style*="align-items: center"],
    #content-view > div[style*="display:flex"] > div[style*="display:flex"][style*="align-items:center"] {
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100% !important;
        gap: 0.75rem !important;
    }
    
    /* Buttons, inputs, and selects sizing */
    #content-view > div[style*="display: flex"] > div[style*="display: flex"] > .glass-panel,
    #content-view > div[style*="display: flex"] > div[style*="display: flex"] > button,
    #content-view > div[style*="display: flex"] > div[style*="display: flex"] > .btn-primary,
    #content-view > div[style*="display: flex"] > div[style*="display: flex"] > .btn-secondary {
        width: 100% !important;
        flex: 0 0 auto !important;
        justify-content: center !important;
        height: 48px !important;
    }
    
    #content-view > div[style*="display: flex"] > div[style*="display: flex"] > .glass-panel input {
        width: 100% !important;
        flex: 1 !important;
    }
    
    #content-view > div[style*="display: flex"] > div[style*="display: flex"] > .glass-panel select {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
    }

    /* Cash register bar stack */
    #cash-register-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1rem !important;
        padding: 1.25rem 1rem !important;
    }
    
    #cash-register-bar #cash-register-actions,
    #cash-register-bar #cash-register-actions button {
        width: 100% !important;
        margin: 5px 0 !important;
    }

    /* SweetAlert2 Services Modal Header Stack */
    .swal2-html-container div[style*="display: flex"][style*="align-items: center"][style*="gap: 1.5rem"],
    .swal2-html-container div[style*="display:flex"][style*="align-items:center"][style*="gap:1.5rem"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem !important;
        padding: 1.25rem !important;
    }
    
    .swal2-html-container div[style*="display: flex"][style*="align-items: center"][style*="gap: 1.5rem"] > div:last-child,
    .swal2-html-container div[style*="display:flex"][style*="align-items:center"][style*="gap:1.5rem"] > div:last-child {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    .swal2-html-container div[style*="display: flex"][style*="align-items: center"][style*="gap: 1.5rem"] #btn-new-contract,
    .swal2-html-container div[style*="display:flex"][style*="align-items:center"][style*="gap:1.5rem"] #btn-new-contract {
        width: 100% !important;
        padding: 12px 20px !important;
    }
    
    /* Table horizontal scrolling within Swal */
    .swal2-html-container div[style*="overflow-y: auto"] {
        overflow-x: auto !important;
    }
}

/* Styled horizontal scrollbars for mobile to guide horizontal swipe actions */
@media (max-width: 850px) {
    .table-container::-webkit-scrollbar,
    .swal2-html-container div[style*="overflow-y: auto"]::-webkit-scrollbar {
        height: 6px !important;
        display: block !important;
    }
    
    .table-container::-webkit-scrollbar-track,
    .swal2-html-container div[style*="overflow-y: auto"]::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.03) !important;
        border-radius: 10px !important;
    }
    
    .table-container::-webkit-scrollbar-thumb,
    .swal2-html-container div[style*="overflow-y: auto"]::-webkit-scrollbar-thumb {
        background: var(--primary) !important;
        border-radius: 10px !important;
    }
}
