/* DENTWARE mobile usability layer */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    min-width: 0;
}

img, svg, video, canvas {
    max-width: 100%;
}

input, select, textarea, button {
    max-width: 100%;
    font-size: 16px;
}

button, a, input, select, textarea {
    touch-action: manipulation;
}

table {
    max-width: 100%;
}

.mobile-list {
    display: none;
}

.table-container,
.table-wrapper,
.tabla-wrapper,
.card:has(table),
.panel:has(table),
.container:has(table) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 900px) {
    body {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    .container,
    .main-container,
    .page,
    .ficha-container,
    .register-container,
    .form-container {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }

    .container,
    .card,
    .panel,
    .form-container,
    .ficha-container,
    .register-container,
    .topbar,
    .stat-card,
    .money-box {
        border-radius: 10px !important;
    }

    .topbar,
    .navbar,
    .header-paciente,
    .header-full,
    .header-ficha,
    .actions,
    .brand,
    .dato-row {
        flex-wrap: wrap !important;
    }

    .main-container,
    .chart-grid,
    .kpi-grid,
    .stats-grid,
    .finance-grid,
    .resumen-grid,
    .personal-data-grid,
    .grid-form,
    .menu-grid,
    .anamnesis-grid {
        grid-template-columns: 1fr !important;
    }

    .form-group.full,
    .full-width {
        grid-column: 1 / -1 !important;
    }

    .actions,
    .header-full,
    .header-paciente,
    .header-ficha {
        align-items: stretch !important;
        gap: 10px !important;
    }

    .actions > *,
    .header-full a,
    .header-paciente a,
    .btn,
    .btn-nav,
    .btn-header,
    .btn-volver,
    .btn-cancel,
    .btn-save,
    .btn-finalizar,
    .btn-register {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    table {
        min-width: 680px;
    }

    .tabla-historial {
        min-width: 760px;
    }

    .odontograma-container,
    .evoluciones-container {
        width: 100% !important;
        flex: 1 1 100% !important;
    }

    .main-layout,
    .header-section,
    .header-box,
    .search-box,
    .form-row,
    .header-actions {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    [style*="grid-template-columns: 1fr 320px"],
    [style*="grid-template-columns: 1.5fr 1fr 1fr 1fr 1.5fr 0.8fr"],
    [style*="grid-template-columns: repeat(auto-fill, minmax(130px, 1fr))"] {
        grid-template-columns: 1fr !important;
    }

    [style*="grid-column: span 2"] {
        grid-column: 1 / -1 !important;
    }

    [style*="display: flex"][style*="justify-content: space-between"],
    [style*="display:flex"][style*="justify-content: space-between"],
    [style*="display: flex"][style*="gap: 10px"],
    [style*="display:flex"][style*="gap: 10px"] {
        flex-wrap: wrap !important;
        gap: 10px !important;
    }

    .search-box input,
    .search-box button,
    .search-box a,
    .header-section a,
    .header-box a,
    .header-actions a {
        width: 100% !important;
        text-align: center !important;
    }

    .table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 640px) {
    body {
        padding-top: 12px !important;
        font-size: 15px;
    }

    h1 {
        font-size: 1.35rem !important;
        line-height: 1.2;
    }

    h2 {
        font-size: 1.2rem !important;
        line-height: 1.25;
    }

    h3 {
        font-size: 1rem !important;
    }

    .container,
    .card,
    .panel,
    .form-container,
    .ficha-container,
    .register-container,
    .topbar {
        padding: 16px !important;
    }

    .kpi,
    .stat-card,
    .money-box {
        padding: 14px !important;
    }

    .kpi strong,
    .stat-card h2 {
        font-size: 1.45rem !important;
        line-height: 1.1;
        overflow-wrap: anywhere;
    }

    .brand img,
    .navbar img {
        width: min(70vw, 180px) !important;
        height: auto !important;
    }

    .dato-row {
        display: block !important;
    }

    .dato-row .label {
        width: auto !important;
        margin-bottom: 4px;
    }

    input, select, textarea, button,
    .btn, .btn-nav, .btn-header {
        min-height: 44px;
    }

    .slot {
        min-height: 74px !important;
    }

    .grid-disponibilidad {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .actions,
    .action-cell {
        display: grid !important;
        grid-template-columns: 1fr !important;
        width: 100%;
    }

    .btn-action {
        justify-content: center;
        min-height: 38px;
    }

    .timeline,
    .timeline-container-fixed {
        max-height: none !important;
        overflow: visible !important;
    }

    [style*="display: flex"][style*="justify-content: space-between"],
    [style*="display:flex"][style*="justify-content: space-between"] {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    [style*="display: flex"][style*="justify-content: space-between"] > *,
    [style*="display:flex"][style*="justify-content: space-between"] > * {
        width: 100%;
    }
}

@media (max-width: 760px) {
    .desktop-table {
        display: none !important;
    }

    .desktop-table-shell,
    .table-container:has(.desktop-table) {
        display: none !important;
    }

    .mobile-list {
        display: grid;
        gap: 12px;
        margin-top: 14px;
    }

    .mobile-record {
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        overflow: hidden;
        box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
    }

    .mobile-record summary {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 10px;
        align-items: center;
        padding: 14px;
        cursor: pointer;
        list-style: none;
    }

    .mobile-record summary::-webkit-details-marker {
        display: none;
    }

    .mobile-record summary::after {
        content: "Ver";
        color: #2563eb;
        font-size: 0.78rem;
        font-weight: 800;
        text-transform: uppercase;
    }

    .mobile-record[open] summary::after {
        content: "Cerrar";
    }

    .mobile-record-title {
        min-width: 0;
        font-weight: 800;
        color: #1e293b;
        overflow-wrap: anywhere;
    }

    .mobile-record-subtitle {
        margin-top: 3px;
        color: #64748b;
        font-size: 0.85rem;
    }

    .mobile-record-body {
        display: grid;
        gap: 10px;
        padding: 0 14px 14px;
        border-top: 1px solid #f1f5f9;
    }

    .mobile-field {
        display: grid;
        gap: 3px;
        padding-top: 10px;
    }

    .mobile-label {
        color: #64748b;
        font-size: 0.72rem;
        font-weight: 800;
        text-transform: uppercase;
    }

    .mobile-value {
        color: #1e293b;
        font-size: 0.95rem;
        overflow-wrap: anywhere;
    }

    .mobile-actions {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
        padding-top: 10px;
    }

    .mobile-actions a,
    .mobile-actions button {
        width: 100%;
        min-height: 42px;
        border-radius: 8px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        text-decoration: none;
        font-weight: 800;
    }

    .mobile-actions button {
        border: 0;
        cursor: pointer;
    }

    .mobile-actions .btn-delete {
        background: #fee2e2;
        color: #991b1b;
        opacity: 1;
        padding: 0 12px;
    }

    .agenda-page .grid-disponibilidad {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        max-height: 42vh;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 4px 4px 8px;
        margin-top: 12px !important;
        -webkit-overflow-scrolling: touch;
    }

    .agenda-page .grid-disponibilidad .slot {
        width: 100% !important;
        min-height: 0 !important;
        padding: 12px !important;
        border-radius: 10px !important;
        display: grid !important;
        grid-template-columns: 68px minmax(0, 1fr) auto;
        align-items: center;
        gap: 10px;
        text-align: left !important;
        flex: 0 0 auto;
    }

    .agenda-page .grid-disponibilidad .slot > span:first-child {
        font-size: 0.95rem;
        font-weight: 800;
    }

    .agenda-page .grid-disponibilidad .slot.libre > span:last-child,
    .agenda-page .grid-disponibilidad .slot.ocupado .paciente-nombre {
        margin: 0 !important;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .agenda-page .grid-disponibilidad .slot.libre > span:last-child {
        justify-self: end;
        font-size: 0.74rem !important;
        font-weight: 800;
    }

    .agenda-page .grid-disponibilidad .slot.ocupado .btn-cancelar-mini {
        width: auto !important;
        min-height: 32px;
        padding: 0 8px !important;
        border-radius: 8px;
        background: #fff1f2;
        text-decoration: none;
        font-weight: 800;
        font-size: 0.7rem;
    }
}
