/* ============================================
   CITALIS DASHBOARD - RESPONSIVE MOBILE-FIRST
   ============================================ */

@media (max-width: 768px) {
    /* ============================================
       1. SIDEBAR COLAPSABLE (OFFCANVAS)
       ============================================ */
    body {
        flex-direction: column;
    }

    /* Barra superior móvil e Icono (Ver base_dashboard.html) */

    .mobile-menu-btn svg {
        width: 24px;
        height: 24px;
        color: white;
    }

    /* Sidebar oculto por defecto en móvil */
    #sidebar {
        position: fixed !important;
        left: 0;
        top: 0;
        height: 100vh;
        width: 280px !important;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 9999 !important;
    }

    #sidebar.mobile-open {
        transform: translateX(0) !important;
    }

    /* Overlay oscuro */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9998;
        backdrop-filter: blur(2px);
    }

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

    /* ============================================
       2. CONTENIDO PRINCIPAL
       ============================================ */
    main {
        width: 100% !important;
        padding-top: 72px;
    }

    main > div {
        padding: 16px !important;
    }

    /* ============================================
       3. HEADER DASHBOARD
       ============================================ */
    .page-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 16px !important;
        margin-bottom: 24px !important;
    }

    .page-header h1 {
        font-size: 2rem !important;
        line-height: 1.1 !important;
    }

    .page-header-actions {
        flex-direction: column !important;
        width: 100%;
    }

    .page-header-actions a,
    .page-header-actions button {
        width: 100%;
        justify-content: center;
        padding: 14px 20px !important;
    }

    /* ============================================
       4. TARJETAS KPI / STATS
       ============================================ */
    .stats-grid,
    .grid.grid-cols-1.lg\:grid-cols-3,
    .grid.grid-cols-1.lg\:grid-cols-10 {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    .card-premium {
        padding: 20px !important;
    }

    /* ============================================
       5. TABLAS → CARDS RESPONSIVAS
       ============================================ */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Tabla → Cards en móvil */
    table.w-full,
    table {
        border-collapse: collapse;
    }

    thead {
        display: none !important;
    }

    tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    tbody tr {
        display: flex;
        flex-direction: column;
        background: white;
        border: 1px solid rgba(216, 216, 192, 0.2);
        border-radius: 8px;
        padding: 16px;
        margin-bottom: 0;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    }

    tbody tr td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0 !important;
        border: none !important;
        text-align: left !important;
    }

    /* Diseño específico para la tabla de citas en modo tarjeta */
    .appointments-table tbody tr {
        display: grid !important;
        grid-template-areas: 
            "client status"
            "date date"
            "service actions" !important;
        grid-template-columns: 1fr auto !important;
        gap: 10px !important;
        padding: 16px !important;
        align-items: center !important;
        transition: all 0.2s ease;
    }

    .appointments-table tbody tr:active {
        background-color: rgba(22, 147, 165, 0.05) !important;
        transform: scale(0.98);
    }

    .appointments-table tbody tr td {
        display: block !important;
        padding: 0 !important;
        height: auto !important;
        min-height: unset !important;
    }

    .appointments-table tbody tr td::before {
        display: none !important;
    }

    .appointments-table tbody tr td:nth-child(1) { 
        grid-area: date;
        padding-top: 8px !important;
        margin-top: 4px !important;
        border-top: 1px solid rgba(0,0,0,0.03) !important;
    }
    .appointments-table tbody tr td:nth-child(2) { 
        grid-area: client;
    }
    .appointments-table tbody tr td:nth-child(2) span:first-child {
        font-size: 1rem !important;
    }
    .appointments-table tbody tr td:nth-child(3) { 
        grid-area: service;
    }
    .appointments-table tbody tr td:nth-child(4) { 
        grid-area: status;
        text-align: right !important;
    }
    .appointments-table tbody tr td:nth-child(5) { 
        grid-area: actions; 
        text-align: right !important;
    }

    tbody tr td:first-child {
        padding-top: 0 !important;
    }

    tbody tr td:last-child {
        padding-bottom: 0 !important;
    }

    /* Labels para datos de cards */
    tbody tr td::before {
        content: attr(data-label);
        font-size: 9px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.15em;
        color: rgba(26, 26, 26, 0.4);
        min-width: 80px;
    }

    /* Acciones en cards */
    tbody tr td:last-child {
        justify-content: flex-end;
        padding-top: 12px !important;
        border-top: 1px solid rgba(216, 216, 192, 0.1) !important;
        margin-top: 8px;
    }

    /* Status badges en cards */
    tbody tr td:nth-last-child(2) {
        justify-content: flex-start;
    }

    /* ============================================
       6. DRAWERS / MODALES
       ============================================ */
    #serviceDrawer .max-w-md,
    #drawerPanel,
    #appointmentDrawer #drawerPanel {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 100vh;
        border-radius: 0;
    }

    .drawer-header {
        padding: 16px !important;
    }

    .drawer-content {
        padding: 16px !important;
    }

    .drawer-footer {
        padding: 16px !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    .drawer-footer button {
        width: 100% !important;
        min-height: 48px;
    }

    /* Formularios en drawer */
    .drawer-content .space-y-8 > div {
        margin-bottom: 20px;
    }

    .drawer-content input[type="text"],
    .drawer-content input[type="email"],
    .drawer-content input[type="number"],
    .drawer-content textarea,
    .drawer-content select {
        min-height: 48px;
        font-size: 16px;
    }

    /* ============================================
       7. FORMULARIOS
       ============================================ */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    select,
    textarea {
        min-height: 48px;
        font-size: 16px;
        padding: 12px 16px;
        -webkit-appearance: none;
        border-radius: 8px;
    }

    /* Labels más legibles */
    label:not(.cursor-pointer) {
        font-size: 11px;
        margin-bottom: 8px;
    }

    /* ============================================
       8. GRÁFICOS
       ============================================ */
    .chart-container {
        height: 200px !important;
    }

    /* ============================================
       9. FILTROS
       ============================================ */
    .filters-panel {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }

    .filters-panel .grid {
        grid-template-columns: 1fr !important;
    }

    /* ============================================
       10. MODAL DE CONFIRMACIÓN
       ============================================ */
    #deleteModal > div:last-child {
        margin: 16px;
        padding: 24px !important;
        border-radius: 12px;
    }

    #deleteModal .flex.gap-4 {
        flex-direction: column;
    }

    /* ============================================
       11. NAVEGACIÓN SECUNDARIA
       ============================================ */
    .quick-actions {
        display: flex;
        flex-direction: column;
    }

    .quick-actions a {
        padding: 16px !important;
    }

    /* ============================================
       12. BOTONES
       ============================================ */
    button,
    a.btn,
    .bg-primary {
        min-height: 44px;
        padding: 12px 20px;
        font-size: 11px;
    }

    /* Botones primarios full-width */
    .bg-primary.text-white {
        width: 100%;
        justify-content: center;
    }

    /* ============================================
       13. TOAST NOTIFICATIONS
       ============================================ */
    #toast {
        left: 16px !important;
        right: 16px !important;
        transform: none !important;
        bottom: 24px;
        text-align: center;
    }

    /* ============================================
       14. BADGES Y ESTADOS
       ============================================ */
    span[class*="uppercase"][class*="tracking-widest"] {
        font-size: 9px;
        padding: 6px 10px;
    }

    /* ============================================
       15. ESPACIADOS GENERALES
       ============================================ */
    .px-10,
    .p-10 {
        padding: 16px !important;
    }

    .py-5 {
        padding-top: 14px !important;
        padding-bottom: 14px !important;
    }

    .mb-16,
    .mb-10,
    .mb-8 {
        margin-bottom: 16px !important;
    }

    .mt-4 {
        margin-top: 12px !important;
    }

    .gap-10,
    .gap-8 {
        gap: 16px !important;
    }

    /* ============================================
       16. PRÓXIMAS CITAS (LISTA)
       ============================================ */
    .upcoming-appointments table {
        display: block;
    }

    .upcoming-appointments thead {
        display: none;
    }

    .upcoming-appointments tbody {
        display: flex;
        flex-direction: column;
        gap: 12px;
        padding: 16px !important;
    }

    .upcoming-appointments tbody tr {
        display: grid !important;
        grid-template-areas: 
            "client status"
            "date date"
            "service actions" !important;
        grid-template-columns: 1fr auto !important;
        gap: 10px !important;
        padding: 16px !important;
        background: white !important;
        border: 1px solid rgba(216, 216, 192, 0.2) !important;
        border-radius: 8px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04) !important;
        align-items: center !important;
    }

    .upcoming-appointments tbody tr td {
        display: block !important;
        padding: 0 !important;
        border: none !important;
        height: auto !important;
    }

    .upcoming-appointments tbody tr td::before {
        display: none !important;
    }

    .upcoming-appointments tbody tr td:nth-child(1) { 
        grid-area: date;
        padding-top: 8px !important;
        margin-top: 4px !important;
        border-top: 1px solid rgba(0,0,0,0.03) !important;
    }
    .upcoming-appointments tbody tr td:nth-child(2) { 
        grid-area: client;
    }
    .upcoming-appointments tbody tr td:nth-child(2) p:first-child {
        font-size: 1rem !important;
        font-weight: 900 !important;
    }
    .upcoming-appointments tbody tr td:nth-child(3),
    .upcoming-appointments tbody tr td:nth-child(4) { 
        grid-area: service;
    }
    /* El profesional lo mostramos debajo del servicio si existe */
    .upcoming-appointments tbody tr td:nth-child(4) {
        margin-top: 2px !important;
    }
    .upcoming-appointments tbody tr td:nth-child(5) { 
        grid-area: status;
        text-align: right !important;
    }
    .upcoming-appointments tbody tr td:nth-child(6) { 
        grid-area: actions; 
        text-align: right !important;
    }

    /* ============================================
       17. DATATABLES RESPONSIVE
       ============================================ */
    .dataTables_wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .dataTables_wrapper table {
        min-width: 600px;
    }

    .dataTables_paginate {
        display: flex !important;
        justify-content: center !important;
        margin-top: 24px !important;
        width: 100% !important;
    }

    .dataTables_paginate .paginate_button {
        padding: 8px 12px !important;
        font-size: 10px !important;
        font-weight: bold !important;
        text-transform: uppercase !important;
    }

    /* ============================================
       18. ESCALADO DE TIPOGRAFÍA
       ============================================ */
    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1rem;
    }

    .text-5xl,
    .text-4xl,
    .text-3xl {
        font-size: 1.75rem;
    }

    .text-xs {
        font-size: 10px;
    }

    .text-\[10px\] {
        font-size: 9px;
    }

    .text-\[9px\] {
        font-size: 8px;
    }

    /* ============================================
       19. UTILITY CLASSES MOBILE
       ============================================ */
    .hidden {
        display: none;
    }

    .block {
        display: block;
    }

    .flex {
        display: flex;
    }

    .flex-col {
        flex-direction: column;
    }

    .items-center {
        align-items: center;
    }

    .justify-between {
        justify-content: space-between;
    }

    .text-center {
        text-align: center;
    }

    .w-full {
        width: 100%;
    }

    .mb-6 {
        margin-bottom: 16px;
    }

    /* ============================================
       20. HIDE NON-ESSENTIAL ON MOBILE
       ============================================ */
    .desktop-only {
        display: none !important;
    }

    /* ============================================
       21. SCROLLBAR STYLING
       ============================================ */
    ::-webkit-scrollbar {
        width: 6px;
        height: 6px;
    }

    ::-webkit-scrollbar-track {
        background: transparent;
    }

    ::-webkit-scrollbar-thumb {
        background: rgba(22, 147, 165, 0.3);
        border-radius: 3px;
    }

/* ============================================
   22. TABLE-SPECIFIC CLASSES
   ============================================ */
.services-table thead th:nth-child(3),
.services-table thead th:nth-child(4),
.services-table tbody td:nth-child(3),
.services-table tbody td:nth-child(4) {
    display: none;
}

@media (min-width: 769px) {
    .services-table thead th:nth-child(3),
    .services-table thead th:nth-child(4),
    .services-table tbody td:nth-child(3),
    .services-table tbody td:nth-child(4) {
        display: table-cell;
    }
}

.resources-table thead th:nth-child(2),
.resources-table tbody td:nth-child(2) {
    display: none;
}

@media (min-width: 769px) {
    .resources-table thead th:nth-child(2),
    .resources-table tbody td:nth-child(2) {
        display: table-cell;
    }
}

.blocked-table thead th:nth-child(2),
.blocked-table tbody td:nth-child(2) {
    display: none;
}

@media (min-width: 769px) {
    .blocked-table thead th:nth-child(2),
    .blocked-table tbody td:nth-child(2) {
        display: table-cell;
    }
}

.availability-table thead th:nth-child(2),
.availability-table tbody td:nth-child(2) {
    display: none;
}

@media (min-width: 769px) {
    .availability-table thead th:nth-child(2),
    .availability-table tbody td:nth-child(2) {
        display: table-cell;
    }
}

.exceptions-table thead th:nth-child(2),
.exceptions-table tbody td:nth-child(2) {
    display: none;
}

@media (min-width: 769px) {
    .exceptions-table thead th:nth-child(2),
    .exceptions-table tbody td:nth-child(2) {
        display: table-cell;
    }
}

/* ============================================
   23. SAFE AREAS (iPhone notch)
   ============================================ */
    @supports (padding: max(0px)) {
        body {
            padding-left: max(0px, env(safe-area-inset-left));
            padding-right: max(0px, env(safe-area-inset-right));
        }
    }
}

/* ============================================
   DESKTOP OVERRIDES (min-width: 769px)
   ============================================ */
@media (min-width: 769px) {
    .mobile-menu-btn {
        display: none !important;
    }

    .sidebar-overlay {
        display: none !important;
    }

    aside {
        transform: none !important;
    }

    .desktop-only {
        display: table-cell;
    }

    /* Tablas normales en desktop */
    tbody tr {
        display: table-row;
    }

    tbody tr td {
        display: table-cell;
        padding: 20px 40px !important;
    }

    tbody tr td::before {
        content: none;
    }
}