/* ============================================
   AR LAB - Mobile Responsive Styles
   ============================================
   Sistema de estilos responsive para móviles
   Importar DESPUÉS de los estilos principales
   ============================================ */

/* ============================================
   1. VARIABLES Y CONFIGURACIÓN
   ============================================ */
:root {
    --touch-min: 44px;
    --spacing-mobile: 0.75rem;
    --border-radius-mobile: 12px;
}

/* ============================================
   1.5 MENÚ HAMBURGUESA Y DRAWER MÓVIL
   ============================================ */

/* Botón Hamburguesa - Oculto en desktop */
.mobile-menu-btn {
    display: none;
    background: transparent;
    border: none;
    color: white;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}

.mobile-menu-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Overlay del drawer */
.mobile-drawer-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-drawer-overlay.active {
    display: block;
    opacity: 1;
}

/* Drawer lateral */
.mobile-drawer {
    position: fixed;
    top: 0;
    left: -300px;
    width: 280px;
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height para móviles */
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    z-index: 1999;
    display: flex;
    flex-direction: column;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    overflow-y: auto;
    overflow-x: hidden;
}

.mobile-drawer.open {
    left: 0;
}

/* Header del drawer */
.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.drawer-close {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
}

.drawer-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* Navegación del drawer */
.drawer-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.drawer-section {
    font-size: 0.7rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 1rem 1rem 0.5rem;
    margin-top: 0.5rem;
}

.drawer-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.drawer-item:hover,
.drawer-item:active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.drawer-item.active {
    background: var(--primary);
    color: white;
}

.drawer-item svg {
    flex-shrink: 0;
    opacity: 0.8;
}

.drawer-item-primary {
    background: var(--primary);
    color: white !important;
    margin: 0.5rem 0;
}

.drawer-item-primary:hover {
    background: var(--primary-dark);
}

/* Footer del drawer */
.drawer-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.drawer-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.drawer-user-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
}

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

.drawer-user-info span:first-child {
    color: white;
    font-weight: 500;
}

.drawer-user-role {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
}

.drawer-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #f87171;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.drawer-logout:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* MÓVIL: Mostrar hamburguesa, ocultar menú desktop */
@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    /* Ocultar navegación desktop */
    .navbar-nav {
        display: none !important;
    }

    /* Ocultar detalles de usuario en navbar */
    .navbar-user .user-details {
        display: none !important;
    }

    /* Navbar más compacta */
    .navbar {
        height: 60px !important;
        padding: 0 0.75rem !important;
    }

    .navbar-brand {
        flex: 1;
        justify-content: center;
    }

    .navbar-logo {
        height: 40px !important;
    }

    /* Body padding ajustado */
    body {
        padding-top: 60px !important;
    }
}

/* ============================================
   2. RESET TÁCTIL - Tamaños mínimos accesibles
   ============================================ */
@media (max-width: 768px) {

    /* Botones táctiles */
    .btn,
    button:not(.modal-close):not(.popover-close),
    [role="button"] {
        min-height: var(--touch-min);
        min-width: var(--touch-min);
        padding: 0.75rem 1rem;
    }

    /* Inputs táctiles */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="date"],
    input[type="time"],
    input[type="search"],
    select,
    textarea,
    .form-input,
    .form-select,
    .form-textarea {
        min-height: var(--touch-min);
        font-size: 16px !important;
        /* Previene zoom en iOS */
        padding: 0.75rem;
    }

    /* Checkboxes y radios más grandes */
    input[type="checkbox"],
    input[type="radio"] {
        width: 22px;
        height: 22px;
        margin-right: 0.5rem;
    }
}

/* ============================================
   3. UTILIDADES DE VISIBILIDAD
   ============================================ */
.hide-mobile {
    display: none !important;
}

.show-mobile {
    display: block !important;
}

.show-mobile-flex {
    display: flex !important;
}

@media (min-width: 769px) {
    .hide-mobile {
        display: block !important;
    }

    .hide-desktop {
        display: none !important;
    }

    .show-mobile,
    .show-mobile-flex {
        display: none !important;
    }
}

/* ============================================
   4. LAYOUT RESPONSIVE
   ============================================ */
@media (max-width: 768px) {

    /* Body y contenedor principal */
    body {
        font-size: 14px;
    }

    .main-content {
        padding: var(--spacing-mobile) !important;
        margin: 0 !important;
    }

    /* Grid de 12 columnas → stack vertical */
    .home-grid,
    .grid-12 {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .home-grid>*,
    [class*="grid-column"],
    .widget-stat,
    .widget-caja {
        grid-column: span 12 !important;
        width: 100% !important;
    }

    /* Cards */
    .card,
    .stat-card,
    .widget-stat {
        padding: 1rem !important;
        border-radius: var(--border-radius-mobile) !important;
    }

    /* Quick actions grid */
    .quick-actions {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem !important;
    }

    .action-card {
        padding: 1rem !important;
    }

    .action-card svg {
        width: 28px !important;
        height: 28px !important;
    }

    .action-card h3 {
        font-size: 0.85rem !important;
    }
}

/* ============================================
   5. TABLAS RESPONSIVE
   ============================================ */
@media (max-width: 768px) {

    /* Contenedor con scroll horizontal */
    .table-container,
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        margin: 0 -0.75rem;
        padding: 0 0.75rem;
    }

    /* Indicador de scroll */
    .table-container::after {
        content: '→ Desliza para ver más';
        display: block;
        text-align: center;
        font-size: 0.7rem;
        color: #94a3b8;
        padding: 0.5rem;
        background: linear-gradient(to right, transparent, #f1f5f9);
    }

    table {
        min-width: 600px;
    }

    th,
    td {
        padding: 0.75rem 0.5rem !important;
        font-size: 0.8rem !important;
        white-space: nowrap;
    }

    /* Ocultar columnas menos importantes */
    .hide-on-mobile,
    th.hide-mobile,
    td.hide-mobile {
        display: none !important;
    }

    /* Tabla de citas - versión card */
    .appointments-table {
        min-width: 100%;
    }

    .appointments-table thead {
        display: none;
    }

    .appointments-table tbody tr {
        display: block;
        background: white;
        border: 1px solid var(--border);
        border-radius: 12px;
        margin-bottom: 0.75rem;
        padding: 1rem;
    }

    .appointments-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0 !important;
        border-bottom: 1px solid #f1f5f9;
        white-space: normal;
    }

    .appointments-table tbody td:last-child {
        border-bottom: none;
    }

    .appointments-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #64748b;
        font-size: 0.75rem;
        text-transform: uppercase;
        flex-shrink: 0;
        margin-right: 1rem;
    }
}

/* ============================================
   6. MODALES RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 0 !important;
        align-items: flex-end !important;
    }

    .modal {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 90vh !important;
        border-radius: 20px 20px 0 0 !important;
        margin: 0 !important;
    }

    .modal-header {
        padding: 1rem !important;
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
    }

    .modal-body {
        padding: 1rem !important;
        overflow-y: auto;
        max-height: calc(90vh - 140px);
    }

    .modal-footer {
        padding: 1rem !important;
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 1px solid var(--border);
    }

    .modal-footer .btn {
        flex: 1;
    }

    .modal-close {
        width: 36px;
        height: 36px;
    }
}

/* ============================================
   7. FORMULARIOS RESPONSIVE
   ============================================ */
@media (max-width: 768px) {

    /* Stack vertical para form groups */
    .form-row,
    .form-group-row {
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .form-group {
        width: 100% !important;
        margin-bottom: 1rem;
    }

    .form-label {
        margin-bottom: 0.5rem;
        font-size: 0.85rem;
    }

    /* Botones de formulario a ancho completo */
    .form-actions,
    .modal-footer {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    .form-actions .btn,
    .form-actions button {
        width: 100% !important;
    }

    /* Selectores de fecha/hora lado a lado */
    .datetime-group {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }
}

/* ============================================
   8. DASHBOARD ESPECÍFICO
   ============================================ */
@media (max-width: 768px) {

    /* Top bar */
    .top-bar {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
        padding: 1rem !important;
    }

    .page-title {
        font-size: 1.25rem !important;
    }

    .top-bar-actions {
        width: 100%;
        justify-content: flex-end;
    }

    /* Stats widgets en 2 columnas */
    .stats-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem !important;
    }

    .widget-stat {
        padding: 1rem !important;
    }

    .widget-stat-value {
        font-size: 1.5rem !important;
    }

    .widget-stat-label {
        font-size: 0.75rem !important;
    }

    /* Widget caja */
    .widget-caja {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem !important;
        padding: 1rem !important;
    }

    .caja-balance {
        font-size: 1.5rem !important;
    }

    /* Calendario compacto */
    .calendar-grid {
        gap: 2px !important;
    }

    .calendar-day {
        font-size: 0.75rem !important;
        padding: 0.5rem !important;
    }
}

/* ============================================
   9. NUEVA CITA RESPONSIVE
   ============================================ */
@media (max-width: 900px) {

    /* Layout 70/30 → stack */
    .cita-container,
    .split-layout,
    .form-split {
        flex-direction: column !important;
    }

    .cita-left,
    .cita-right,
    .split-left,
    .split-right {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Secciones del formulario */
    .form-section {
        padding: 1rem !important;
        margin-bottom: 1rem !important;
    }

    .section-title {
        font-size: 1rem !important;
    }
}

/* ============================================
   10. RESULTADOS RESPONSIVE
   ============================================ */
@media (max-width: 768px) {

    /* Sidebar colapsable */
    .results-sidebar,
    .sidebar-left {
        position: fixed !important;
        left: -100% !important;
        top: 60px !important;
        width: 85% !important;
        max-width: 320px !important;
        height: calc(100vh - 60px) !important;
        background: white !important;
        z-index: 999 !important;
        transition: left 0.3s ease !important;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15) !important;
        overflow-y: auto !important;
    }

    .results-sidebar.open,
    .sidebar-left.open {
        left: 0 !important;
    }

    /* Overlay para sidebar */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Botón toggle sidebar móvil */
    .mobile-sidebar-toggle {
        display: flex !important;
        position: fixed;
        bottom: 20px;
        left: 20px;
        width: 56px;
        height: 56px;
        background: var(--primary);
        color: white;
        border: none;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(13, 148, 136, 0.4);
        z-index: 997;
        cursor: pointer;
    }

    .mobile-sidebar-toggle svg {
        width: 24px;
        height: 24px;
    }

    /* Contenido principal ocupa todo */
    .results-main,
    .main-panel {
        width: 100% !important;
        margin-left: 0 !important;
    }

    /* Tabla de resultados */
    .results-table {
        font-size: 0.8rem;
    }

    .results-table input {
        font-size: 14px !important;
        padding: 0.5rem !important;
    }
}

@media (min-width: 769px) {
    .mobile-sidebar-toggle {
        display: none !important;
    }
}

/* ============================================
   11. INDEX/LOGIN RESPONSIVE  
   ============================================ */
@media (max-width: 768px) {

    .login-container,
    .auth-container {
        padding: 1rem !important;
    }

    .login-box,
    .auth-box {
        padding: 1.5rem !important;
        margin: 0 !important;
        border-radius: 16px !important;
    }

    .login-title,
    .auth-title {
        font-size: 1.5rem !important;
    }

    .login-form .btn,
    .auth-form .btn {
        width: 100%;
        padding: 1rem;
    }
}

/* ============================================
   12. PACIENTES Y LISTAS RESPONSIVE
   ============================================ */
@media (max-width: 768px) {

    /* Filtros colapsables */
    .filters-bar,
    .search-filters {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    .filter-group {
        width: 100% !important;
    }

    .search-input {
        width: 100% !important;
    }

    /* Lista de pacientes como cards */
    .patients-list .patient-row {
        display: block !important;
        padding: 1rem !important;
        border: 1px solid var(--border);
        border-radius: 12px;
        margin-bottom: 0.75rem;
    }

    .patient-name {
        font-size: 1rem !important;
        font-weight: 600;
        margin-bottom: 0.5rem;
    }

    .patient-details {
        font-size: 0.8rem;
        color: #64748b;
    }
}

/* ============================================
   13. COMPROBANTES RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .voucher-card {
        padding: 1rem !important;
    }

    .voucher-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }

    .voucher-amount {
        font-size: 1.25rem !important;
    }

    .voucher-actions {
        width: 100%;
        display: flex;
        gap: 0.5rem;
    }

    .voucher-actions .btn {
        flex: 1;
    }
}

/* ============================================
   14. TOAST Y NOTIFICACIONES
   ============================================ */
@media (max-width: 768px) {
    .toast-container {
        left: 1rem !important;
        right: 1rem !important;
        bottom: 1rem !important;
    }

    .toast {
        min-width: auto !important;
        width: 100% !important;
    }
}

/* ============================================
   15. ANIMACIONES REDUCIDAS (accesibilidad)
   ============================================ */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   16. MEJORAS TÁCTILES GENERALES
   ============================================ */
@media (max-width: 768px) {

    /* Espaciado entre elementos clicables */
    .action-btns {
        gap: 0.75rem !important;
    }

    .action-btn {
        width: 36px !important;
        height: 36px !important;
    }

    /* Status badges más grandes */
    .status-badge {
        padding: 0.4rem 0.75rem !important;
        font-size: 0.75rem !important;
    }

    /* Semaforo dots más grandes */
    .step-dot,
    .status-dot {
        width: 10px !important;
        height: 10px !important;
    }

    /* Links y elementos interactivos */
    a,
    .clickable {
        padding: 0.25rem;
    }
}

/* ============================================
   17. LANDSCAPE MODE (Móvil horizontal)
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    .navbar {
        height: 50px !important;
    }

    body {
        padding-top: 50px !important;
    }

    .modal {
        max-height: 95vh !important;
    }
}

/* ============================================
   18. PRINT OVERRIDE (No afectar impresión)
   ============================================ */
@media print {

    .hide-mobile,
    .show-mobile,
    .mobile-sidebar-toggle {
        display: initial !important;
    }
}