/* Móvil (≤640px): tablas marcadas con .mob-cards se muestran como tarjetas.
   Es opt-in: solo afecta a las tablas/controles que llevan estas clases.
   Las marcas .mob-title / .mob-actions / .mob-keep las pone eskin-mobile-cards.js. */

@media (max-width: 640px) {

    /* ---------- acordeones y pestañas más compactos ---------- */
    .ui-accordion .ui-accordion-header a {
        padding: 12px 14px !important;
        font-size: 15px !important;
    }

    .ui-tabs-panel:has(.mob-cards) .ShowOnMobile,
    .ui-accordion-content:has(.mob-cards) .ShowOnMobile {
        display: none !important;
    }

    /* ---------- filtros de opción única como chips en una fila ---------- */
    .mob-chips {
        max-width: 100%;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .mob-chips::-webkit-scrollbar {
        display: none;
    }

    .mob-chips table,
    .mob-chips tbody,
    .mob-chips tr {
        display: flex;
        flex-wrap: nowrap;
        gap: 6px;
        border: 0;
    }

    .mob-chips td {
        flex: 0 0 auto;
        padding: 0 !important;
        display: block;
    }

    .mob-chips .ui-radiobutton {
        display: none;
    }

    .mob-chips label {
        display: inline-flex;
        align-items: center;
        min-height: 40px;
        margin: 0;
        padding: 8px 14px;
        border: 1px solid #dbe4f0;
        border-radius: 999px;
        color: #64748b;
        background: #ffffff;
        font-size: .82rem !important;
        font-weight: 700;
        white-space: nowrap;
        cursor: pointer;
    }

    .mob-chips .ui-radiobutton:has(.ui-state-active) + label,
    .mob-chips .ui-radiobutton:has(input:checked) + label {
        border-color: #2196F3;
        color: #2196F3;
        background: #eff6ff;
    }

    /* ---------- tablas como tarjetas ---------- */
    .mob-cards thead tr {
        display: block;
    }

    .mob-cards thead th {
        display: none;
        width: 100% !important;
        padding: 0 !important;
        border: 0 !important;
        background: transparent !important;
    }

    .mob-cards thead th.mob-keep {
        display: block;
    }

    .mob-cards thead th .ui-column-title {
        display: none !important;
    }

    .mob-cards thead th input {
        width: 100% !important;
        height: 42px;
        margin: 0 0 10px;
    }

    .mob-cards tbody tr:not(.ui-datatable-empty-message) {
        display: flex;
        flex-direction: column;
        gap: 4px;
        margin: 0 0 10px;
        padding: 12px;
        background: #ffffff;
        border: 1px solid #e5eaf3;
        border-radius: 12px;
    }

    .mob-cards tbody tr:not(.ui-datatable-empty-message) > td {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        float: none;
        width: auto !important;
        padding: 0 !important;
        border: 0 !important;
        background: transparent !important;
        text-align: left !important;
        font-size: 13px;
    }

    .mob-cards tbody td .ui-column-title {
        flex: 0 0 auto;
        margin: 0;
        color: #94a3b8;
        font-size: 12px;
        font-weight: 400;
    }

    .mob-cards tbody td .ui-outputlabel,
    .mob-cards tbody td .ui-cell-editor,
    .mob-cards tbody td > span:not(.ui-column-title) {
        float: none !important;
        font-size: 13px !important;
        text-align: right;
    }

    .mob-cards tbody td .ui-cell-editor {
        flex: 1 1 auto;
        min-width: 0;
    }

    /* la columna principal (nombre, cliente…) va primero y sin rótulo */
    .mob-cards tbody tr > td.mob-title {
        order: -1;
        justify-content: flex-start;
        margin-bottom: 2px;
    }

    .mob-cards tbody tr > td.mob-title .ui-column-title {
        display: none !important;
    }

    .mob-cards tbody tr > td.mob-title .ui-outputlabel,
    .mob-cards tbody tr > td.mob-title > span:not(.ui-column-title) {
        font-size: 15px !important;
        font-weight: 600;
        text-align: left;
    }

    /* las acciones van al final, a la derecha, con área táctil de 44px */
    .mob-cards tbody tr > td.mob-actions {
        order: 99;
        justify-content: flex-end;
        margin-top: 4px;
    }

    .mob-cards tbody tr > td.mob-actions .ui-column-title {
        display: none !important;
    }

    .mob-cards tbody tr > td.mob-actions .ui-button,
    .mob-cards tbody tr > td.mob-actions a {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        margin: 0 0 0 6px !important;
    }

    /* pie de totales: una franja suave */
    .mob-cards tfoot tr {
        display: flex;
        flex-wrap: wrap;
        gap: 4px 16px;
        padding: 10px 12px;
        background: #eff6ff;
        border-radius: 12px;
    }

    .mob-cards tfoot td {
        display: block;
        padding: 0 !important;
        border: 0 !important;
        background: transparent !important;
        text-align: left !important;
    }

    .mob-cards tfoot td:empty {
        display: none;
    }

    /* fechas y botones de las barras de filtros */
    .mob-form .ui-calendar,
    .mob-form .ui-calendar .ui-inputfield,
    .mob-form .ui-selectonemenu,
    .mob-form .ui-inputfield {
        width: 100% !important;
    }

    .mob-form .ui-button {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 640px) {
    /* rejilla de filtros: Desde y Hasta lado a lado, lo demás a todo el ancho */
    .mob-form.p-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin: 0;
    }

    .mob-form.p-grid > [class*="p-col"] {
        width: 100%;
        max-width: 100%;
        padding: 0;
        min-width: 0;
    }

    .mob-form.p-grid > [class*="p-col"]:nth-child(n+3) {
        grid-column: 1 / -1;
    }

    /* barra de botones: Cargar a todo el ancho, exportar en dos columnas */
    .mob-actionbar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-top: 8px;
    }

    .mob-actionbar .ui-button {
        width: 100%;
        min-height: 44px;
        margin: 0 !important;
        float: none !important;
        justify-content: center;
    }

    .mob-actionbar .ui-button:last-child {
        grid-column: 1 / -1;
        order: -1;
    }
}

@media (max-width: 640px) {
    /* horario semanal: día, casilla y dos horas caben en una sola fila */
    .ui-panel:has(.mob-week) .ui-panel-content {
        padding: 8px;
    }

    .mob-week table {
        table-layout: fixed;
        width: 100%;
    }

    .mob-week th,
    .mob-week td {
        padding: 6px 3px !important;
        vertical-align: middle;
    }

    .mob-week th {
        font-size: 11px !important;
        line-height: 1.2;
    }

    .mob-week th:nth-child(1) { width: 24%; }
    .mob-week th:nth-child(2) { width: 17%; }
    .mob-week th:nth-child(3),
    .mob-week th:nth-child(4) { width: 29.5%; }

    .mob-week .ui-selectonemenu {
        width: 100% !important;
        min-width: 0;
    }

    .mob-week .ui-selectonemenu .ui-selectonemenu-label {
        padding: 6px 18px 6px 6px;
        font-size: 13px;
    }

    .mob-week .ui-selectonemenu .ui-selectonemenu-trigger {
        width: 18px;
    }
}

@media (max-width: 640px) {
    .mob-week th:nth-child(2) {
        font-size: 9.5px !important;
        letter-spacing: -.2px;
    }
}

@media (max-width: 480px) {
    /* chips sin ícono (Honorarios): sin el rótulo solo se ven números sueltos, así que se muestra */
    .stat-chip:not(:has(.stat-chip-icon)) {
        padding: 7px 14px;
        gap: 6px;
    }

    .stat-chip:not(:has(.stat-chip-icon)) .stat-chip-label {
        position: static;
        width: auto;
        height: auto;
        margin: 0;
        overflow: visible;
        clip: auto;
    }

    .honorarios-report-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .honorarios-report-row .ui-button {
        width: 100%;
        min-height: 44px;
        justify-content: center;
    }
}

@media (max-width: 640px) {
    /* honorarios: rangos rápidos repartidos y fechas lado a lado */
    .honorarios-quick-range {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        margin-bottom: 10px;
    }

    .honorarios-quick-range .ui-button {
        width: 100%;
        min-height: 44px;
    }

    .honorarios-filter-row {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .honorarios-filter-row .honorarios-filter-doctor,
    .honorarios-filter-row .honorarios-filter-submit {
        grid-column: 1 / -1;
    }

    .honorarios-filter-row .ui-calendar,
    .honorarios-filter-row .ui-calendar .ui-inputfield,
    .honorarios-filter-row .ui-selectonemenu {
        width: 100% !important;
    }
}

@media (max-width: 640px) {
    /* selectores y campos dentro de tarjetas: nunca más anchos que la tarjeta */
    .mob-cards tbody td .ui-selectonemenu,
    .mob-cards tbody td .ui-inputfield,
    .mob-cards tbody td .ui-inputnumber {
        flex: 1 1 auto;
        min-width: 0 !important;
        max-width: 68%;
        width: auto !important;
    }

    .mob-cards tbody td .ui-selectonemenu .ui-selectonemenu-label {
        width: 100% !important;
        box-sizing: border-box;
        text-overflow: ellipsis;
    }
}

@media (max-width: 640px) {
    /* con tarjetas ya no hace falta pedir que giren el dispositivo */
    body:has(.mob-cards) .ShowOnMobile {
        display: none !important;
    }
}

@media (max-width: 640px) {
    /* foto/avatar: pequeña, redonda y al inicio de la tarjeta */
    .mob-cards tbody tr > td.mob-avatar {
        order: -2;
        justify-content: flex-start;
    }

    .mob-cards tbody td img {
        width: 44px;
        height: 44px;
        max-width: 44px;
        border-radius: 50%;
        object-fit: cover;
    }
}

@media (max-width: 640px) {
    /* la foto va arriba a la derecha y el nombre queda a la izquierda, en la misma franja */
    .mob-cards tbody tr:not(.ui-datatable-empty-message):has(> td.mob-avatar) {
        position: relative;
        min-height: 68px;
    }

    .mob-cards tbody tr > td.mob-avatar {
        position: absolute;
        top: 12px;
        right: 12px;
    }

    .mob-cards tbody td img {
        margin: 0 !important;
    }

    .mob-cards tbody tr:has(> td.mob-avatar) > td.mob-title {
        min-height: 44px;
        padding-right: 56px !important;
    }
}

@media (max-width: 640px) {
    .mob-cards tbody tr:not(.ui-datatable-empty-message) > td.mob-avatar {
        width: 44px !important;
        height: 44px;
        overflow: visible;
    }
}

@media (max-width: 640px) {
    /* foto simple: arriba a la izquierda, sin posicionamiento absoluto */
    .mob-cards tbody tr:not(.ui-datatable-empty-message):has(> td.mob-avatar) {
        min-height: 0;
    }

    .mob-cards tbody tr:not(.ui-datatable-empty-message) > td.mob-avatar {
        position: static;
        width: auto !important;
        height: auto;
        justify-content: flex-start;
    }

    .mob-cards tbody tr:has(> td.mob-avatar) > td.mob-title {
        min-height: 0;
        padding-right: 0 !important;
    }
}

@media (max-width: 640px) {
    .mob-cards tbody td .ui-column-title:empty {
        display: none !important;
    }
}

/* PDF incrustado: en escritorio se ve el visor; en móvil, un botón que lo abre completo. */
.mob-pdf-open {
    display: none;
}

@media (max-width: 640px) {
    .mob-pdf-object {
        display: none;
    }

    .mob-pdf-open {
        display: block;
        clear: both;
        padding: 16px 0 8px;
        text-align: center;
    }

    .mob-pdf-text {
        margin: 0 0 12px;
        color: #64748b;
        font-size: 14px;
    }

    .mob-pdf-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        min-height: 48px;
        color: #ffffff;
        text-decoration: none;
    }
}

@media (max-width: 640px) {
    /* formularios de dos columnas: un campo por fila */
    .mob-single .ui-g > div,
    .mob-single .ui-panelgrid-cell,
    .mob-single .ui-grid-row > div {
        flex: 0 0 100% !important;
        width: 100% !important;
        max-width: 100%;
    }

    .mob-single .ui-calendar,
    .mob-single .ui-calendar .ui-inputfield,
    .mob-single .ui-inputfield,
    .mob-single .ui-inputnumber,
    .mob-single .ui-selectonemenu,
    .mob-single textarea {
        width: 100% !important;
        box-sizing: border-box;
    }

    /* panel con alto fijo: en móvil crece con el formulario en vez de tener scroll interno */
    .mob-flat.ui-scrollpanel {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }

    .mob-flat .ui-scrollpanel-container,
    .mob-flat .ui-scrollpanel-wrapper,
    .mob-flat .ui-scrollpanel-content {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }
}

@media (max-width: 640px) {
    /* cambio de contraseña: campos a todo el ancho, no de 40% */
    .mob-pass .ui-password,
    .mob-pass .ui-inputfield {
        width: 100% !important;
        max-width: 360px;
        box-sizing: border-box;
    }
}

@media (max-width: 640px) {
    /* pestañas en una sola fila que se desliza (opt-in con .mob-tabs) */
    .mob-tabs > .ui-tabs-nav {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        padding: 0;
    }

    .mob-tabs > .ui-tabs-nav::-webkit-scrollbar {
        display: none;
    }

    .mob-tabs > .ui-tabs-nav > li {
        flex: 0 0 auto;
        width: auto;
        margin: 0;
        white-space: nowrap;
    }
}
