/* ==========================================
    1. VARIABLES GLOBALES Y RESET BÁSICO
    ========================================== */
:root {
    --primary: #2563eb; 
    --secondary: #1e40af; 
    --accent: #10b981; 
    --danger: #ef4444; 
    --warning: #f59e0b;
    --bg-main: #f8fafc; 
    --bg-card: #ffffff; 
    --text-dark: #0f172a; 
    --text-muted: #64748b;
    --text-gray: #475569;
    --border: #e2e8f0; 
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1); 
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', system-ui, sans-serif; }
body { background-color: var(--bg-main); color: var(--text-dark); display: flex; height: 100vh; overflow: hidden; }

/* ==========================================
    2. SIDEBAR E INTERFAZ BASE
    ========================================== */
.sidebar { width: 280px; background: #0f172a; color: white; display: flex; flex-direction: column; overflow-y: auto; flex-shrink: 0; transition: var(--transition); border-right: 1px solid #1e293b; }
.sidebar-header { padding: 1.5rem; border-bottom: 1px solid #1e293b; display: flex; align-items: center; gap: 10px; font-size: 1.5rem; font-weight: bold; color: white; background: #0b1120; }
.nav-section { padding: 1.2rem 0 0.5rem 1.5rem; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; color: #64748b; font-weight: bold; }
.nav-item { padding: 0.8rem 1.5rem; display: flex; align-items: center; gap: 12px; color: #94a3b8; text-decoration: none; transition: var(--transition); border-left: 4px solid transparent; font-size: 0.95rem; margin: 2px 0; }
.nav-item:hover { background: #1e293b; color: white; border-left-color: #475569; }
.nav-item.active { background: #1e293b; color: #38bdf8; border-left-color: #38bdf8; font-weight: 600; }

.main-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar { height: 70px; background: white; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; padding: 0 2rem; flex-shrink: 0; box-shadow: var(--shadow-sm); z-index: 10; }
.topbar-user { display: flex; align-items: center; gap: 15px; font-weight: 600; }
.btn-logout { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; padding: 0.5rem 1rem; border-radius: 8px; cursor: pointer; font-weight: bold; transition: var(--transition); }
.btn-logout:hover { background: var(--danger); color: white; }

.content-area { flex: 1; padding: 2rem; overflow-y: auto; background: var(--bg-main); }
.panel { display: none; animation: fadeIn 0.3s ease; }
.panel.active { display: block; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.panel-header h2 { font-size: 1.8rem; color: #0f172a; font-weight: 800; letter-spacing: -0.5px; }
.card { background: white; border-radius: 16px; padding: 1.5rem; box-shadow: var(--shadow-sm); border: 1px solid var(--border); margin-bottom: 1.5rem; transition: var(--transition); }

/* CLASES PARA EL MENÚ HAMBURGUESA Y OVERLAY */
.btn-menu-mobile { display: none; background: transparent; border: none; color: var(--primary); cursor: pointer; padding: 5px; margin-right: 10px; }
.sidebar-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.5); z-index: 9998; display: none; opacity: 0; transition: opacity 0.3s ease; backdrop-filter: blur(2px); }
.sidebar-overlay.active { display: block; opacity: 1; }

/* ==========================================
    3. DASHBOARD PREMIUM
    ========================================== */
.dash-header-wrap { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 2rem; }
.dash-kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
.kpi-card { background: white; border-radius: 16px; padding: 1.5rem; box-shadow: 0 4px 20px rgba(0,0,0,0.03); border: 1px solid rgba(226, 232, 240, 0.8); display: flex; align-items: center; gap: 1.2rem; transition: transform 0.3s ease; position: relative; overflow: hidden; }
.kpi-card:hover { transform: translateY(-5px); box-shadow: 0 10px 25px rgba(0,0,0,0.08); border-color: #cbd5e1; }

.kpi-icon { width: 54px; height: 54px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; flex-shrink: 0; box-shadow: inset 0 2px 4px rgba(255,255,255,0.5); }
.kpi-icon.green { background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%); color: #15803d; border: 1px solid #86efac; }
.kpi-icon.blue { background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%); color: #1d4ed8; border: 1px solid #93c5fd; }
.kpi-icon.orange { background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%); color: #b45309; border: 1px solid #fcd34d; }
.kpi-icon.purple { background: linear-gradient(135deg, #f3e8ff 0%, #e9d5ff 100%); color: #7e22ce; border: 1px solid #d8b4fe; }

.kpi-info { flex: 1; }
.kpi-title { font-size: 0.8rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.kpi-value { font-size: 2rem; font-weight: 900; color: #0f172a; line-height: 1; margin-bottom: 6px; letter-spacing: -0.5px; }
.kpi-trend { font-size: 0.8rem; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 50px; }
.trend-up { background: #ecfdf5; color: #10b981; }
.trend-down { background: #fef2f2; color: #ef4444; }
.trend-neutral { background: #f1f5f9; color: #64748b; }

.dash-main-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; }
@media(max-width: 1100px) { .dash-main-grid { grid-template-columns: 1fr; } }

.quick-action-btn { display: flex; align-items: center; gap: 12px; padding: 1rem 1.2rem; background: white; border: 1px solid var(--border); border-radius: 12px; color: var(--text-dark); font-weight: 600; text-decoration: none; transition: 0.2s; box-shadow: var(--shadow-sm); }
.quick-action-btn:hover { background: #f8fafc; border-color: var(--primary); color: var(--primary); transform: translateX(4px); box-shadow: var(--shadow-md); }
.quick-action-btn .icon { font-size: 1.5rem; background: #f1f5f9; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 8px; }

.stat-card { background: white; padding: 1.5rem; border-radius: 12px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.stat-card.orange { border-left: 4px solid var(--warning); background: linear-gradient(to right, #fffbeb, #ffffff); }
.stat-card.green { border-left: 4px solid var(--accent); background: linear-gradient(to right, #ecfdf5, #ffffff); }
.stat-card.red { border-left: 4px solid var(--danger); background: linear-gradient(to right, #fef2f2, #ffffff); }
.stat-title { color: var(--text-muted); font-size: 0.9rem; font-weight: 600; text-transform: uppercase; }
.stat-value { font-size: 2rem; font-weight: 800; color: #1e293b; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }

/* ==========================================
    4. TABLAS PREMIUM
    ========================================== */
.table-responsive { overflow-x: auto; background: white; border-radius: 12px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); width: 100%; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); }
th { background: #f8fafc; font-weight: 600; color: var(--text-muted); font-size: 0.85rem; text-transform: uppercase; }
tbody tr:hover { background: #f1f5f9; }

.table-premium { width: 100%; border-collapse: separate; border-spacing: 0 10px; margin-top: -10px; }
.table-premium th { background: transparent; font-size: 0.75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; border: none; padding: 0.5rem 1.5rem; }
.table-premium tbody tr { background: white; box-shadow: 0 2px 8px rgba(0,0,0,0.04); transition: transform 0.2s ease, box-shadow 0.2s ease; border-radius: 12px;}
.table-premium tbody tr:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); z-index: 10; position: relative; background: white; }
.table-premium td { padding: 1.2rem 1.5rem; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); vertical-align: middle; background: white; }
.table-premium td:first-child { border-left: 1px solid var(--border); border-top-left-radius: 12px; border-bottom-left-radius: 12px; }
.table-premium td:last-child { border-right: 1px solid var(--border); border-top-right-radius: 12px; border-bottom-right-radius: 12px; }

.badge { padding: 0.3rem 0.8rem; border-radius: 50px; font-size: 0.8rem; font-weight: bold; }
.bg-success { background: #dcfce7; color: #166534; }
.bg-warning { background: #fef3c7; color: #b45309; }
.bg-danger { background: #fee2e2; color: #b91c1c; }
.bg-info { background: #e0f2fe; color: #0369a1; }
.bg-gray { background: #f1f5f9; color: #475569; }

/* ==========================================
    5. COMPONENTES PREMIUM Y BOTONES
    ========================================== */
.btn-filter { padding: 0.5rem 1.2rem; border: none; background: transparent; border-radius: 6px; font-size: 0.9rem; font-weight: 600; color: var(--text-gray); cursor: pointer; transition: all 0.2s ease; }
.btn-filter:hover { color: var(--primary); }
.btn-filter.active { background: white; color: var(--primary); box-shadow: 0 2px 5px rgba(0,0,0,0.08); }

.btn-icon-premium { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 8px; border: 1px solid var(--border); background: white; cursor: pointer; transition: all 0.2s ease; }
.btn-icon-premium svg { width: 18px; height: 18px; stroke-width: 2; }
.btn-pay { color: #10b981; } .btn-pay:hover { background: #10b981; color: white; border-color: #10b981; box-shadow: 0 4px 6px rgba(16,185,129,0.2); transform: translateY(-2px); }
.btn-edit { color: #3b82f6; } .btn-edit:hover { background: #3b82f6; color: white; border-color: #3b82f6; box-shadow: 0 4px 6px rgba(59,130,246,0.2); transform: translateY(-2px); }
.btn-delete { color: #ef4444; } .btn-delete:hover { background: #ef4444; color: white; border-color: #ef4444; box-shadow: 0 4px 6px rgba(239,68,68,0.2); transform: translateY(-2px); }

.btn-estado-premium { font-size: 0.75rem; font-weight: 600; padding: 0.4rem 0.8rem; border-radius: 6px; border: 1px solid var(--primary); background: #eff6ff; color: var(--primary); cursor: pointer; transition: all 0.2s ease; display: inline-flex; align-items: center; gap: 6px; }
.btn-estado-premium:hover { background: var(--primary); color: white; box-shadow: 0 4px 6px rgba(37,99,235,0.2); }

.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 20px; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.3px; }
.status-pendiente { background: #fef3c7; color: #d97706; }
.status-confirmada { background: #dbeafe; color: #2563eb; }
.status-completada { background: #dcfce7; color: #166534; }
.status-cancelada { background: #fee2e2; color: #b91c1c; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-pendiente { background: #f59e0b; box-shadow: 0 0 5px #f59e0b; }
.dot-confirmada { background: #3b82f6; box-shadow: 0 0 5px #3b82f6; }
.dot-completada { background: #10b981; box-shadow: 0 0 5px #10b981; }
.dot-cancelada { background: #ef4444; box-shadow: 0 0 5px #ef4444; }

.toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast { background: white; padding: 1rem 1.5rem; border-radius: 10px; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 12px; color: var(--text-dark); font-weight: 600; animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards; border-left: 5px solid; }
.toast.success { border-left-color: var(--accent); } 
.toast.error { border-left-color: var(--danger); } 
.toast.warning { border-left-color: var(--warning); } 
.toast.info { border-left-color: var(--primary); }
.toast-icon { font-size: 1.2rem; }

.btn { padding: 0.6rem 1.2rem; border-radius: 8px; border: none; cursor: pointer; font-weight: 600; font-size: 0.95rem; transition: var(--transition); display: inline-flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
.btn:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0,0,0,0.08); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn-primary { background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%); color: white; box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2); }
.btn-primary:hover { background: linear-gradient(135deg, var(--secondary) 0%, #1e3a8a 100%); color: white; box-shadow: 0 6px 12px rgba(37, 99, 235, 0.3); }
.btn-outline { background: white; border: 1px solid var(--border); color: var(--text-dark); }
.btn-outline:hover { background: #f8fafc; border-color: var(--text-muted); }
.btn-danger { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); color: white; }
.btn-danger:hover { background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%); color: white; box-shadow: 0 6px 10px rgba(220, 38, 38, 0.3); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.header-with-btn { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; border-bottom: 2px solid #f1f5f9; padding-bottom: 0.8rem; }

/* ==========================================
    6. FORMULARIOS Y CAJAS DE TEXTO
    ========================================== */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1.5rem; }
.form-group { margin-bottom: 1rem; width: 100%; }
.form-group label { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 0.5rem; color: var(--text-dark); }
.form-control { width: 100%; padding: 0.8rem; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; outline: none; transition: var(--transition); background: white; box-sizing: border-box; }
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); }
.form-control:read-only { background-color: #f1f5f9; color: var(--text-muted); cursor: not-allowed; }

select.form-control {
    appearance: none; 
    -webkit-appearance: none; 
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat; 
    background-position: right 1rem center; 
    background-size: 1.2em; 
    padding-right: 2.5rem; 
    cursor: pointer;
}

textarea.form-control { resize: vertical; min-height: 80px; }
.search-bar { display: flex; gap: 10px; margin-bottom: 1.5rem; width: 100%; max-width: 500px; }

/* ==========================================
    7. FICHAS CLÍNICAS Y TABS INTERNOS
    ========================================== */
.ficha-tabs { display: flex; gap: 0; margin-bottom: 1rem; border-bottom: 2px solid var(--border); flex-wrap: wrap; }
.ficha-tab { padding: 1rem 1.5rem; font-size: 1.1rem; color: var(--text-muted); cursor: pointer; transition: var(--transition); border-bottom: 3px solid transparent; margin-bottom: -2px; }
.ficha-tab:hover { color: var(--primary); }
.ficha-tab.active { color: var(--text-dark); font-weight: 600; border-bottom-color: var(--text-dark); }

.ficha-section { display: none; animation: fadeIn 0.3s ease; padding-top: 1rem; }
.ficha-section.active { display: block; }

.section-title-ficha { color: var(--primary); font-size: 1rem; font-weight: bold; margin-bottom: 1rem; }

.panel-box { background: white; border: 1px solid var(--border); border-radius: 8px; padding: 1.5rem; margin-bottom: 1.5rem; }

.check-group { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; cursor: pointer; font-size: 0.95rem; color: var(--text-dark); }
.check-group input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

.radio-group { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.95rem; }
.radio-group input[type="radio"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

.table-lensometria { width: 100%; border-collapse: collapse; text-align: center; }
.table-lensometria th { font-size: 0.75rem; color: var(--text-muted); padding-bottom: 10px; border: none; background: transparent;}
.table-lensometria td { padding: 5px; border: none;}
.table-lensometria .form-control { text-align: center; }

.category-nav { display: flex; gap: 10px; overflow-x: auto; padding: 10px 0; margin-bottom: 1.5rem; }
.btn-pill-filter { padding: 0.6rem 1.5rem; border-radius: 50px; border: 1px solid var(--border); background: white; color: var(--text-dark); cursor: pointer; transition: all 0.2s ease; font-weight: 600; white-space: nowrap; font-size: 0.9rem; }
.btn-pill-filter:hover { border-color: var(--primary); color: var(--primary); background: #eff6ff; }
.btn-pill-filter.active[data-cat="Todos"] { background: var(--text-dark); color: white; border-color: var(--text-dark); box-shadow: 0 4px 6px rgba(15,23,42,0.2); }
.btn-pill-filter.active[data-cat="Armazones"] { background: var(--primary); color: white; border-color: var(--primary); box-shadow: 0 4px 6px rgba(37,99,235,0.2); }
.btn-pill-filter.active[data-cat="Lunas/Cristales"] { background: #9333ea; color: white; border-color: #9333ea; box-shadow: 0 4px 6px rgba(147,51,234,0.2); }
.btn-pill-filter.active[data-cat="Lentes Solares"] { background: #f97316; color: white; border-color: #f97316; box-shadow: 0 4px 6px rgba(249,115,22,0.2); }
.btn-pill-filter.active[data-cat="Lentes de Contacto"] { background: #0891b2; color: white; border-color: #0891b2; box-shadow: 0 4px 6px rgba(8,145,178,0.2); }
.btn-pill-filter.active[data-cat="Accesorios"] { background: var(--accent); color: white; border-color: var(--accent); box-shadow: 0 4px 6px rgba(16,185,129,0.2); }
.stock-bullet { font-size: 1.4rem; margin-right: 8px; line-height: 1; }

/* ==========================================
    8. MODALES GLOBALES
    ========================================== */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.8); display: none; justify-content: center; align-items: center; z-index: 2000; padding: 1rem; backdrop-filter: blur(4px); }
.modal-content { background: white; padding: 2rem; border-radius: 16px; width: 100%; max-width: 600px; box-shadow: var(--shadow-lg); animation: popIn 0.3s ease-out; max-height: 90vh; overflow-y: auto; }

/* Estilos de Impresión */
@media print {
    body * { visibility: hidden; }
    .print-area, .print-area * { visibility: visible; }
    .print-area { position: absolute; left: 0; top: 0; width: 100%; border: none !important; padding: 0 !important; }
    .modal-overlay { background: transparent; position: absolute; }
    .modal-content { box-shadow: none; width: 100%; max-width: 100%; margin: 0; padding: 0; }
    .no-print { display: none !important; }
    .main-wrapper, .sidebar { display: none !important; }
}

/* ANIMACIONES CSS */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes popIn { 0% { opacity: 0; transform: scale(0.95); } 100% { opacity: 1; transform: scale(1); } }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; display: none; } }

/* ==========================================
    9. MODALES ESTILO APPLE (SEGURIDAD Y SISTEMA)
    ========================================== */
.apple-modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center; z-index: 9999;
    opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease;
}
.apple-modal-overlay.active { opacity: 1; visibility: visible; }
.apple-modal {
    background: #ffffff; border-radius: 20px; padding: 30px 24px; width: 90%; max-width: 400px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: scale(0.95) translateY(10px); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-align: center;
}
.apple-modal-overlay.active .apple-modal { transform: scale(1) translateY(0); }
.apple-modal-icon {
    width: 60px; height: 60px; background: #f1f5f9; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 1.8rem; margin: 0 auto 15px auto;
}
.apple-modal h3 { margin: 0 0 10px 0; color: #0f172a; font-size: 1.3rem; font-weight: 700; }
.apple-modal p { margin: 0 0 20px 0; color: #64748b; font-size: 0.95rem; line-height: 1.5; }
.apple-actions { display: flex; gap: 10px; margin-top: 10px; }
.apple-btn {
    flex: 1; padding: 12px 5px; border-radius: 12px; font-size: 0.95rem; font-weight: 600; cursor: pointer;
    border: none; transition: all 0.2s;
}
.apple-btn-confirm { background: #2563eb; color: white; }
.apple-btn-confirm:hover { background: #1d4ed8; }

/* ==========================================
    10. RESPONSIVIDAD (MÓVILES Y TABLETAS) BLINDADA Y OPTIMIZADA
    ========================================== */

/* TABLETS Y MÓVILES (hasta 1024px) */
@media (max-width: 1024px) {
    body { display: flex !important; flex-direction: column !important; height: 100vh !important; }
    
    .btn-menu-mobile { display: block !important; margin-right: 15px; }

    .sidebar { 
        position: fixed !important;
        top: 0 !important;
        left: -300px !important; /* Oculto por defecto */
        width: 280px !important;
        height: 100% !important;
        min-height: 100vh !important;
        flex-direction: column !important;
        background: #0f172a !important;
        z-index: 9999 !important;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        border-right: 1px solid #1e293b !important;
        box-shadow: none !important;
        padding-top: 10px !important;
    }
    
    .sidebar.open {
        left: 0 !important;
        box-shadow: 10px 0 25px rgba(0,0,0,0.5) !important;
    }

    .sidebar-header { display: flex !important; } 
    .nav-section { display: block !important; }    
    
    .nav-item { 
        display: flex !important; 
        border-bottom: none !important; 
        border-left: 4px solid transparent !important; 
        padding: 0.8rem 1.5rem !important; 
        height: auto !important; 
        margin: 2px 0 !important; 
        align-items: center !important;
        font-size: 0.95rem !important;
    }
    .nav-item.active { border-left-color: #38bdf8 !important; background: #1e293b !important; }

    .sidebar > div[style*="padding"] { display: block !important; padding: 1.5rem !important; }
    .sidebar > div[style*="padding"] > a { margin: 0 !important; white-space: normal !important; font-size: 0.9rem !important;}

    .main-wrapper { width: 100% !important; flex: 1 !important; overflow: hidden !important; }
}

/* 📱 MÓVILES PEQUEÑOS (hasta 768px) - ESTILO APPLE OPTIMIZADO 📱 */
@media (max-width: 768px) {
    body { background-color: #f2f2f7 !important; }
    
    /* TOPBAR REESCRITO */
    .topbar { 
        padding: 8px 15px !important; 
        flex-direction: row !important; 
        height: 55px !important; 
        gap: 5px !important; 
        border-bottom: 1px solid #c6c6c8 !important; 
        box-shadow: none !important; 
        background: rgba(255, 255, 255, 0.95) !important;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        align-items: center !important;
    }
    
    #lbl-fecha-actual { display: none !important; }
    .btn-menu-mobile { margin-right: 0 !important; }

    .topbar-user { 
        flex-direction: row !important; 
        justify-content: flex-end !important; 
        align-items: center !important; 
        flex: 1 !important; 
        gap: 5px !important;
    }
    
    .topbar-user button.btn-outline { display: none !important; }
    
    .topbar-user span { 
        font-size: 0.95rem !important; 
        font-weight: 700 !important; 
        color: #000 !important;
        text-align: right !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        padding: 0 10px !important;
        display: block !important;
        max-width: 140px;
    }
    
    .topbar-user button.btn-logout {
        width: auto !important;
        padding: 6px 10px !important;
        font-size: 0.8rem !important;
        border-radius: 12px !important;
        background: rgba(239, 68, 68, 0.1) !important;
        color: #ef4444 !important;
        border: none !important;
        flex-shrink: 0;
        font-weight: 600 !important;
    }

    .content-area { padding: 12px !important; }
    
    /* TÍTULOS Y CABECERAS */
    h2 { font-size: 1.4rem !important; font-weight: 700 !important; letter-spacing: -0.5px !important; color: #000 !important;}
    .header-with-btn { flex-direction: column !important; align-items: flex-start !important; gap: 12px !important; border-bottom: none !important; margin-bottom: 15px !important; padding-bottom: 0 !important;}
    .header-with-btn div p { font-size: 0.85rem !important; color: #8e8e93 !important;}
    .header-with-btn button { width: 100% !important; padding: 12px !important; border-radius: 14px !important; font-size: 1rem !important; background: #007aff !important; border: none !important; box-shadow: 0 4px 10px rgba(0,122,255,0.2) !important;}
    
    /* FIX: CABECERA REPORTES FINANCIEROS (Para que el botón y los filtros no desborden la pantalla) */
    #tab-reportes .header-with-btn > div:last-child {
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100% !important;
    }
    #tab-reportes .header-with-btn > div:last-child > div {
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap !important;
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
        scrollbar-width: none;
    }
    #tab-reportes .header-with-btn > div:last-child > div::-webkit-scrollbar { display: none; }
    
    /* CARDS Y DASHBOARD */
    .card { padding: 16px !important; border-radius: 20px !important; border: none !important; box-shadow: 0 2px 12px rgba(0,0,0,0.04) !important; margin-bottom: 15px !important; background: white !important;}
    .dash-kpi-grid { grid-template-columns: 1fr 1fr !important; gap: 12px !important; }
    .kpi-card { padding: 15px !important; flex-direction: column !important; align-items: flex-start !important; gap: 10px !important; border-radius: 20px !important; border: none !important; box-shadow: 0 2px 10px rgba(0,0,0,0.03) !important; background: white !important;}
    .kpi-icon { width: 36px !important; height: 36px !important; font-size: 1.1rem !important; border-radius: 10px !important; margin-bottom: 5px; }
    .kpi-value { font-size: 1.4rem !important; letter-spacing: -0.5px !important; }
    .kpi-title { font-size: 0.7rem !important; line-height: 1.1 !important; color: #8e8e93 !important; font-weight: 600 !important;}
    .kpi-trend { font-size: 0.7rem !important; padding: 4px 8px !important; border-radius: 8px !important;}

    /* 🚨 TABLAS TIPO LISTA DE IPHONE (iCloud Style) APLICADO A TODAS LAS TABLAS 🚨 */
    .table-responsive { background: transparent !important; box-shadow: none !important; border: none !important; overflow: visible !important; padding: 0 !important; margin: 0 !important; }
    
    .table-responsive table { min-width: 100% !important; margin-top: 0 !important; border-spacing: 0 !important; display: flex !important; flex-direction: column !important; gap: 12px !important; }
    .table-responsive thead { display: none !important; }
    .table-responsive tbody { display: flex !important; flex-direction: column !important; gap: 12px !important; }
    .table-responsive tbody tr { display: flex !important; flex-direction: column !important; background: white !important; border-radius: 16px !important; padding: 16px !important; margin: 0 !important; border: none !important; box-shadow: 0 1px 8px rgba(0,0,0,0.04) !important; position: relative !important; }
    
    .table-responsive tbody td { display: flex !important; flex-direction: column !important; justify-content: flex-start !important; align-items: flex-start !important; border: none !important; padding: 4px 0 !important; width: 100% !important; text-align: left !important; border-bottom: none !important; }
    .table-responsive tbody td > div { align-items: flex-start !important; text-align: left !important; width: 100% !important; }
    .table-responsive tbody td br { display: none; }
    
    .table-responsive tbody td:last-child { margin-top: 10px !important; padding-top: 12px !important; border-top: 1px solid #e5e5ea !important; flex-direction: row !important; justify-content: center !important;}
    .table-responsive tbody td:last-child > div { justify-content: space-around !important; width: 100% !important; flex-direction: row !important; }
    .table-responsive tbody td:last-child button { flex: 1; margin: 0 5px; }

    /* Ajustes específicos Pacientes */
    #tabla-pacientes tr td:nth-child(2) { order: -3; }
    #tabla-pacientes tr td:nth-child(3) { order: -2; flex-direction: row !important; gap: 10px; margin-top: 8px;}
    #tabla-pacientes tr td:nth-child(1) { order: -1; position: absolute; right: 16px; top: 16px; width: auto !important; padding: 0 !important;}
    #tabla-pacientes tr td:nth-child(1) code { background: #f2f2f7 !important; border: none !important; color: #8e8e93 !important; font-size: 0.75rem !important; border-radius: 8px !important;}
    
    /* Ajustes específicos Órdenes */
    #tabla-pedidos-global tr td:nth-child(1) { padding-bottom: 10px !important; border-bottom: 1px dashed #e2e8f0 !important; margin-bottom: 5px !important; }
    #tabla-pedidos-global tr td:nth-child(3) > div { flex-direction: row !important; align-items: center !important; justify-content: space-between !important; }
    
    /* Ajustes específicos Inventario */
    #tabla-inventario tr td:nth-child(4) { flex-direction: row !important; justify-content: space-between !important; align-items: center !important; background: #f8fafc !important; padding: 10px !important; border-radius: 8px !important; margin-top: 5px !important; }

    /* 🚨 FIX: BUSCADOR ESTILO APPLE Y SUPERPOSICIÓN DE LA LUPA 🚨 */
    .search-bar { max-width: 100% !important; margin-bottom: 15px !important; }
    
    /* Regla súper estricta para asegurar que ninguna caja de texto con lupa pierda su margen izquierdo */
    input#search-paciente, 
    input#search-citas, 
    input#search-pedidos-global, 
    input#search-inventario, 
    input#inputBusquedaPacCita, 
    input#inputBusquedaProd, 
    input#inputBusquedaCat,
    input#search-fichas-perfil,
    input#search-pedidos-perfil,
    div[style*="position: relative"] > input.form-control { 
        padding-left: 45px !important; 
        border-radius: 12px !important; 
        background: #e3e3e8 !important; 
        border: none !important; 
        height: 40px !important; 
        box-shadow: none !important; 
        color: #000 !important;
    }
    
    .search-bar input::placeholder { color: #8e8e93 !important; }
    .search-bar span { color: #8e8e93 !important; }
    
    /* Ajuste contenedor buscador y filtros (Órdenes y Citas) para que no se aprieten */
    div[style*="display: flex; gap: 15px; margin-bottom: 1.5rem; align-items: center; flex-wrap: wrap;"] {
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 15px !important;
    }
    div[style*="display: flex; gap: 15px; margin-bottom: 1.5rem; align-items: center; flex-wrap: wrap;"] > div {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Contenedor de los botones de filtro (Todas, Pendientes, etc) */
    div[style*="background: #f1f5f9; padding: 4px; border-radius: 8px; border: 1px solid var(--border); margin-left: auto;"] {
        margin-left: 0 !important;
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap !important;
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
        scrollbar-width: none;
    }
    div[style*="background: #f1f5f9; padding: 4px; border-radius: 8px; border: 1px solid var(--border); margin-left: auto;"]::-webkit-scrollbar { display: none; }

    /* Filtros Píldora Generales */
    div[style*="overflow-x: auto"] { margin-bottom: 10px; padding-bottom: 5px; border: none !important; background: transparent !important; flex-wrap: nowrap !important; overflow-x: auto !important; -webkit-overflow-scrolling: touch; scrollbar-width: none;}
    div[style*="overflow-x: auto"]::-webkit-scrollbar { display: none; }
    .btn-filter { background: white !important; border-radius: 16px !important; box-shadow: 0 1px 4px rgba(0,0,0,0.05) !important; white-space: nowrap !important; border: none !important; padding: 8px 16px !important; color: #8e8e93 !important;}
    .btn-filter.active { background: #007aff !important; color: white !important; font-weight: 600 !important;}

    div[style*="background: #e0f2fe"] { background: white !important; border-radius: 20px !important; border: none !important; flex-direction: column !important; align-items: stretch !important; gap: 15px !important; padding: 1.2rem !important; box-shadow: 0 2px 12px rgba(0,0,0,0.04) !important;}
    div[style*="background: #e0f2fe"] > div { flex-direction: row !important; align-items: center !important; text-align: left !important; }
    div[style*="background: #e0f2fe"] h3 { color: #000 !important; }
    div[style*="background: #e0f2fe"] p { color: #8e8e93 !important; }
    div[style*="background: #e0f2fe"] button { width: 100% !important; background: #f2f2f7 !important; color: #007aff !important; border: none !important; border-radius: 12px !important; font-weight: 600 !important;}

    /* 🚨 FIX: TABLAS DE REFRACCIÓN Y LENSOMETRÍA (Evitar que se aplaste, Permitir Scroll) 🚨 */
    .table-lensometria { display: block !important; overflow-x: auto !important; white-space: nowrap !important; -webkit-overflow-scrolling: touch;}
    .table-lensometria tbody { display: table-row-group !important; }
    .table-lensometria tbody tr { display: table-row !important; padding: 0 !important; border: none !important; box-shadow: none !important; background: transparent !important;}
    .table-lensometria tbody td { display: table-cell !important; padding: 5px !important; }

    /* Cuadrícula de Refracción Subjetiva Ficha Médica */
    #f-refraccion div[style*="grid-template-columns: 40px 80px"] {
        display: grid !important;
        grid-template-columns: 40px 70px 75px 75px 75px 75px 75px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 10px;
    }
    #f-refraccion div[style*="grid-template-columns: 40px 80px"]::-webkit-scrollbar { display: none; }
    
    /* Refracción miniatura en el Historial del paciente */
    td > div[style*="grid-template-columns: 35px"] {
        display: grid !important;
        grid-template-columns: 35px 45px 45px 45px 45px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
}

/* 📱 MÓVILES PEQUEÑOS Y MODALES (hasta 480px) 📱 */
@media (max-width: 480px) {
    .ficha-tabs { flex-direction: row !important; flex-wrap: nowrap !important; overflow-x: auto !important; padding-bottom: 10px !important; -webkit-overflow-scrolling: touch; border-bottom: none !important; margin-bottom: 10px !important; scrollbar-width: none;}
    .ficha-tabs::-webkit-scrollbar { display: none; }
    .ficha-tab { border: none !important; background: white !important; border-radius: 16px !important; box-shadow: 0 1px 5px rgba(0,0,0,0.05) !important; white-space: nowrap !important; padding: 10px 16px !important; margin-right: 10px !important; font-size: 0.9rem !important; color: #8e8e93 !important;}
    .ficha-tab.active { background: #007aff !important; color: white !important; font-weight: bold !important; }
    
    .modal-content { padding: 1.5rem !important; margin: 15px !important; width: auto !important; border-radius: 24px !important; }
    .modal-content h2 { font-size: 1.3rem !important; }
    
    .form-grid { grid-template-columns: 1fr !important; gap: 12px !important; }
    
    /* Aplicar borde redondeado y padding a los inputs normales, EXCEPTO a los que son buscadores para no borrarles el margen izquierdo de la lupa */
    .form-control:not([id*="search"]):not([id*="Busqueda"]) { 
        border-radius: 12px !important; 
        background: #f2f2f7 !important; 
        border: none !important; 
        padding: 12px !important;
    }
    
    .form-group label { color: #8e8e93 !important; font-size: 0.8rem !important;}
}