/* ==================== ANTIGRAVITY DESIGN SYSTEM ==================== */
:root {
    --bg-dark: #090d16;
    --bg-sidebar: rgba(15, 23, 42, 0.65);
    --bg-card: rgba(30, 41, 59, 0.45);
    
    --primary: #4f46e5;
    --primary-light: #6366f1;
    --primary-gradient: linear-gradient(135deg, #4f46e5, #3b82f6);
    --secondary-gradient: linear-gradient(135deg, #10b981, #059669);
    
    --success: #10b981;
    --success-light: rgba(16, 185, 129, 0.15);
    --warning: #f59e0b;
    --warning-light: rgba(245, 158, 11, 0.15);
    --danger: #ef4444;
    --danger-light: rgba(239, 68, 68, 0.15);
    --info: #06b6d4;
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.05);
    
    --sidebar-width: 260px;
    --border-radius-lg: 16px;
    --border-radius-md: 10px;
    --border-radius-sm: 6px;
    
    --shadow-main: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    --glow-primary: 0 0 20px rgba(79, 70, 229, 0.25);
    --glow-success: 0 0 20px rgba(16, 185, 129, 0.2);
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==================== GENERAL & RESET ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow-x: hidden;
    line-height: 1.5;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-dark);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-sm);
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.app-container {
    display: flex;
    min-height: 100vh;
    background: radial-gradient(circle at 80% 20%, #1e1b4b 0%, var(--bg-dark) 50%);
}

/* ==================== SIDEBAR ==================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    overflow: hidden; /* El contenedor del sidebar queda fijo */
}

/* Scrollbar ultra-delgado solo para el menú interno */
.sidebar-menu::-webkit-scrollbar {
    width: 4px;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.06);
    border-radius: var(--border-radius-sm);
}

.sidebar-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.18);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 36px;
    padding-left: 8px;
    flex-shrink: 0; /* Evita que el logo se encoja */
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-gradient);
    border-radius: var(--border-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
    box-shadow: var(--glow-primary);
}

.brand-text h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: white;
}

.brand-text span {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    overflow-y: auto; /* Permite scroll vertical interno únicamente en los enlaces */
    padding-right: 4px;
    margin-bottom: 12px; /* Margen elegante antes de la línea divisoria del footer */
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--border-radius-md);
    transition: var(--transition-smooth);
    border: 1px solid transparent;
}

.menu-item i {
    font-size: 16px;
    transition: var(--transition-smooth);
}

.menu-item:hover {
    color: white;
    background: rgba(255, 255, 255, 0.03);
}

.menu-item.active {
    color: white;
    background: rgba(79, 70, 229, 0.15);
    border: 1px solid rgba(79, 70, 229, 0.3);
    box-shadow: 0 4px 20px -5px rgba(79, 70, 229, 0.2);
}

.menu-item.active i {
    color: var(--primary-light);
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 16px;
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
    flex-shrink: 0; /* Evita que el footer se comprima o encoja */
}

.simulation-badge {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.25);
    border-radius: var(--border-radius-md);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--warning);
}

.simulation-badge.real-mode {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: var(--success);
}

.pulse-icon {
    width: 8px;
    height: 8px;
    background-color: var(--warning);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7);
    animation: pulse 1.6s infinite;
}

.simulation-badge.real-mode .pulse-icon {
    background-color: var(--success);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulse-success 1.6s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(245, 158, 11, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

@keyframes pulse-success {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.emisor-badge {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px;
}

.emisor-badge i {
    font-size: 24px;
    color: var(--primary-light);
}

.emisor-info h4 {
    font-size: 13px;
    font-weight: 600;
    color: white;
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.emisor-info span {
    font-size: 11px;
    color: var(--text-muted);
}

/* ==================== MAIN CONTENT ==================== */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 32px 40px;
    overflow-y: auto;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.header-title h2 {
    font-size: 24px;
    font-weight: 700;
    color: white;
}

.header-title p {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
}

.content-view {
    display: none;
    animation: fadeIn 0.4s ease-out forwards;
}

.content-view.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-main);
}

/* ==================== STAT CARDS ==================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow-main);
    transition: var(--transition-smooth);
}

.stat-card:hover {
    transform: translateY(-4px);
    border-color: rgba(255, 255, 255, 0.15);
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--border-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.icon-blue { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.icon-green { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.icon-amber { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.icon-red { background: rgba(239, 68, 68, 0.15); color: #ef4444; }

.stat-info h3 {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}

.stat-number {
    font-size: 22px;
    font-weight: 700;
    color: white;
    margin-top: 4px;
}

.stat-trend {
    font-size: 11px;
    margin-top: 6px;
    display: inline-block;
    font-weight: 600;
}

.trend-up { color: #3b82f6; }
.trend-green { color: #10b981; }
.trend-amber { color: #f59e0b; }
.trend-red { color: #ef4444; }

/* ==================== BUTTONS ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--border-radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition-smooth);
    outline: none;
    font-family: inherit;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    box-shadow: var(--glow-primary);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 0 25px rgba(79, 70, 229, 0.4);
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.btn-secondary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

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

.btn-block {
    display: flex;
    width: 100%;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 16px;
}

.btn-icon-only {
    width: 42px;
    height: 42px;
    padding: 0;
}

/* ==================== FORM CONTROLS ==================== */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.form-control {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 10px 14px;
    color: white;
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition-smooth);
    outline: none;
    width: 100%;
}

.form-control:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.form-control::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* ==================== TABLES ==================== */
.table-responsive {
    overflow-x: auto;
    width: 100%;
}

.table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 14px;
}

.table th {
    padding: 16px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
}

.table td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    vertical-align: middle;
}

.table tbody tr {
    transition: var(--transition-smooth);
}

.table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* Status Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-secondary { background: rgba(255, 255, 255, 0.08); color: var(--text-muted); }

/* ==================== INVOICE FORM LAYOUT ==================== */
.invoice-form-grid {
    display: grid;
    grid-template-columns: 2.3fr 1fr;
    gap: 32px;
}

.invoice-details-column {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.form-section {
    padding: 24px;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    color: white;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title i {
    color: var(--primary-light);
}

.product-add-bar {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

.flex-3 { flex: 3; }
.flex-2 { flex: 2; }
.flex-1 { flex: 1; }

.align-bottom {
    margin-bottom: 20px;
}

.summary-card {
    padding: 28px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.summary-title {
    font-size: 18px;
    font-weight: 700;
    color: white;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
    margin-bottom: 20px;
}

.summary-details {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 28px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: var(--text-muted);
}

.summary-row.total-row {
    border-top: 1px solid var(--border-color);
    padding-top: 18px;
    margin-top: 10px;
    font-size: 18px;
    font-weight: 700;
    color: white;
}

.summary-row.total-row span:last-child {
    color: var(--primary-light);
}

.summary-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sticky-element {
    position: sticky;
    top: 32px;
}

/* ==================== FILTERS BAR ==================== */
.table-filter-card {
    padding: 16px 24px;
    margin-bottom: 24px;
}

.filter-bar {
    display: flex;
    gap: 20px;
    align-items: flex-end;
}

/* ==================== CONFIGURATION PANELS ==================== */
.config-tabs {
    display: flex;
    gap: 10px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
    margin-bottom: 28px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    padding: 8px 16px;
    cursor: pointer;
    border-radius: var(--border-radius-sm);
    transition: var(--transition-smooth);
}

.tab-btn:hover {
    color: white;
}

.tab-btn.active {
    color: white;
    background: rgba(255, 255, 255, 0.05);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.config-actions {
    border-top: 1px solid var(--border-color);
    padding-top: 24px;
    margin-top: 28px;
    display: flex;
    justify-content: flex-end;
}

/* Toggle Switch */
.simulation-switch-container {
    background: rgba(245, 158, 11, 0.04);
    border: 1px solid rgba(245, 158, 11, 0.15);
    border-radius: var(--border-radius-lg);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
}

.simulation-switch-info h4 {
    font-size: 15px;
    font-weight: 600;
    color: var(--warning);
}

.simulation-switch-info p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px; width: 18px;
    left: 4px; bottom: 4px;
    background-color: white;
    transition: .4s;
}

input:checked + .slider { background-color: var(--warning); }
input:checked + .slider:before { transform: translateX(24px); }
.slider.round { border-radius: 34px; }
.slider.round:before { border-radius: 50%; }

.signature-upload-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    margin-bottom: 20px;
}

/* ==================== MODALS ==================== */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-dialog {
    width: 90%;
    max-width: 500px;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.active .modal-dialog {
    transform: scale(1);
}

.modal-lg {
    max-width: 800px;
}

.modal-content {
    background: #0f172a;
    border: 1px solid var(--border-color);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition-smooth);
}

.modal-close:hover {
    color: white;
}

.modal-body {
    max-height: 70vh;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
    margin-top: 24px;
}

/* ==================== LOADING OVERLAY ==================== */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.loader-card {
    width: 90%;
    max-width: 450px;
    text-align: center;
    padding: 40px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(79, 70, 229, 0.1);
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 24px;
}

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

.loader-card h3 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 24px;
}

.loader-steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-align: left;
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
}

.loader-step {
    font-size: 13px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 10px;
}

.loader-step i.fa-spinner {
    color: var(--primary-light);
}

.loader-step.active {
    color: white;
    font-weight: 600;
}

.loader-step.completed {
    color: var(--success);
}

.loader-step.completed i {
    color: var(--success);
}

/* ==================== TOASTS ==================== */
.toast-container {
    position: fixed;
    bottom: 32px; right: 32px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 3000;
}

.toast {
    background: #0f172a;
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary-light);
    border-radius: var(--border-radius-md);
    padding: 16px 20px;
    color: white;
    min-width: 300px;
    max-width: 400px;
    box-shadow: var(--shadow-main);
    display: flex;
    align-items: center;
    gap: 14px;
    animation: slideInRight 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.toast.toast-success { border-left-color: var(--success); }
.toast.toast-danger { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }

.toast-icon { font-size: 18px; }
.toast-success .toast-icon { color: var(--success); }
.toast-danger .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }

.toast-content h4 { font-size: 13px; font-weight: 700; }
.toast-content p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.margin-top-20 { margin-top: 20px; }
.text-center { text-align: center !important; }
.text-right { text-align: right !important; }
.text-muted { color: var(--text-muted) !important; }

/* ==================== SEGREGACIÓN DE ROLES & SEGURIDAD ==================== */
.superadmin-only, .usuario-only {
    display: none !important;
}

body.role-superadmin .superadmin-only {
    display: flex !important;
}

body.role-usuario .usuario-only {
    display: flex !important;
}

/* Ajustes específicos de Sidebar Menu para que sea flex en display */
.sidebar-menu a.menu-item.superadmin-only {
    display: none !important;
}
.sidebar-menu a.menu-item.usuario-only {
    display: none !important;
}

body.role-superadmin .sidebar-menu a.menu-item.superadmin-only {
    display: flex !important;
}

body.role-usuario .sidebar-menu a.menu-item.usuario-only {
    display: flex !important;
}

/* ==================== LOGIN SCREEN OVERLAYS ==================== */
.login-overlay {
    display: none;
    transition: all 0.4s ease-in-out;
}

.login-overlay.active {
    display: flex;
}

@keyframes loginFadeIn {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ==================== DYNAMIC COMPROBANTE SELECTOR TABS ==================== */
.creator-tab-btn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.creator-tab-btn:hover {
    color: white !important;
    background: rgba(255, 255, 255, 0.05);
}

.creator-tab-btn.active {
    color: white !important;
    background: var(--primary) !important;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
}

.creator-subview {
    display: none;
}

.creator-subview.active {
    display: block !important;
    animation: subviewFadeIn 0.4s ease-out;
}

@keyframes subviewFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Glassmorphism backgrounds */
.bg-glass {
    background: rgba(30, 41, 59, 0.4) !important;
    backdrop-filter: blur(12px) !important;
    border: 1px solid rgba(255, 255, 255, 0.06) !important;
}

.border-primary {
    border-color: rgba(99, 102, 241, 0.3) !important;
}

/* ==================== RESPONSIVE LAYOUT (MOBILE RESPONSIVENESS) ==================== */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
    }
    
    .app-container {
        flex-direction: column;
    }
    
    /* Responsive Sidebar Drawer */
    .sidebar {
        left: -280px;
        width: 280px;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: none;
        z-index: 100000;
    }
    
    .sidebar.show {
        left: 0;
        box-shadow: 10px 0 40px rgba(0, 0, 0, 0.7);
    }
    
    /* Responsive Main Content */
    .main-content {
        margin-left: 0 !important;
        padding: 20px 16px !important;
        width: 100%;
        overflow-x: hidden;
    }
    
    /* Content Header Mobile Adapt */
    .content-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
        margin-bottom: 24px;
        position: relative;
    }
    
    .content-header > div {
        flex-direction: column;
        align-items: stretch !important;
        width: 100%;
        gap: 12px !important;
    }
    
    .header-emisor-selector {
        width: 100% !important;
        justify-content: space-between;
    }
    
    .header-emisor-select {
        width: 100% !important;
    }
    
    .header-actions {
        width: 100%;
    }
    
    .header-actions .btn {
        width: 100% !important;
    }
    
    /* Hamburger Menu Button */
    .mobile-sidebar-toggle-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.04);
        border: 1px solid var(--border-color);
        color: white;
        width: 44px;
        height: 44px;
        border-radius: var(--border-radius-md);
        font-size: 20px;
        cursor: pointer;
        transition: background 0.2s;
        flex-shrink: 0;
    }
    
    .mobile-sidebar-toggle-btn:active {
        background: rgba(255, 255, 255, 0.1);
    }
    
    /* Backdrop Overlay for mobile sidebar */
    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 99999;
        display: none;
    }
    
    .sidebar-backdrop.show {
        display: block;
    }
    
    /* Stats Grid stack to 1 column on mobile */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 14px;
    }
    
    /* Forms and grids mobile adaptation */
    .invoice-form-grid, .form-grid-2, .grid-2col, .grid-3col {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
    
    .product-add-bar {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    
    .product-add-bar .btn {
        width: 100% !important;
    }
    
    /* Scrollable pill tabs on mobile */
    .creator-tabs, .config-tabs {
        overflow-x: auto;
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 8px !important;
        padding-bottom: 8px;
        -webkit-overflow-scrolling: touch;
    }
    
    .creator-tab-btn, .config-tabs button {
        white-space: nowrap !important;
        flex-shrink: 0 !important;
    }
    
    /* Tables responsive container wrap */
    .card-table-wrap, .table-responsive, .dashboard-table-card, .dashboard-sections {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Modals mobile sizing */
    .modal-dialog {
        width: 95% !important;
        margin: 20px auto !important;
        max-height: 90vh !important;
    }
    
    .modal-body {
        max-height: 70vh !important;
        overflow-y: auto;
    }
    
    /* Scanner Overlay on Mobile */
    #barcode-scanner-reader {
        width: 100% !important;
        height: auto !important;
    }
}

@media (max-width: 480px) {
    .content-header {
        text-align: center;
        align-items: center;
    }
    
    .header-title {
        text-align: center;
        width: 100%;
    }
    
    .header-title h2 {
        font-size: 20px;
    }
}

/* ==================== AJUSTES DE ROL SUPERADMINISTRADOR (CONTROL GLOBAL) ==================== */
.role-superadmin .sidebar-footer {
    display: none !important;
}

.role-superadmin .header-emisor-selector {
    display: none !important;
}

.role-superadmin .header-actions {
    display: none !important;
}

.role-superadmin #emisores-table th:nth-child(6),
.role-superadmin #emisores-table td:nth-child(6) {
    display: none !important;
}
