/* Expediente — estilos de página */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px 24px; }
.detail-item label { font-size: 12px; color: #888; text-transform: uppercase; margin-bottom: 4px; }
.detail-item p { margin: 0; font-size: 15px; }
.registros-table td:last-child { white-space: nowrap; }
.registros-table td.expediente-acciones-cell { white-space: normal; }
.btn-action.btn-pdf { background-color: #e53935; color: #fff; }
.btn-action.btn-pdf i { color: inherit; }
.btn-action.btn-pdf:hover { background-color: #c62828; }
.btn-action.btn-qr { background-color: #1565c0; color: #fff; }
.btn-action.btn-qr i { color: inherit; }
.btn-action.btn-qr:hover { background-color: #0d47a1; }
.qr-modal-body { text-align: center; }
.qr-cliente-nombre { font-size: 1.1rem; font-weight: 700; margin: 0 0 16px; color: #333; }
.qr-canvas-wrap { display: flex; justify-content: center; margin-bottom: 16px; }
.qr-canvas-wrap canvas,
.qr-canvas-wrap img { border-radius: 8px; box-shadow: 0 2px 12px rgba(0,0,0,0.12); max-width: 100%; height: auto; }
.qr-code-holder { display: inline-block; }
.qr-texto-preview {
    text-align: left;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0 0 16px;
    font-family: inherit;
}
.qr-modal-actions { justify-content: center; flex-wrap: wrap; }
.detail-footer-blocks { margin-top: 24px; padding-top: 20px; border-top: 2px solid #e8e0d8; display: flex; flex-direction: column; gap: 16px; }
.detail-block { border-radius: 10px; padding: 14px 16px; border: 2px solid #ddd; background: #fafafa; }
.detail-block h3 { margin: 0 0 10px; font-size: 14px; color: #5d4037; display: flex; align-items: center; gap: 8px; }
.detail-block h3 i { opacity: 0.85; }
.detail-block-atraso-si { border-color: #ff9800; background: #fff8e1; }
.detail-block-atraso-no { border-color: #c8e6c9; background: #f1f8e9; }
.detail-atraso-fecha { margin: 0; font-size: 15px; }
.detail-siniestro-hint { margin: 0 0 8px; font-size: 12px; color: #666; }
.cancel-contrato-info { white-space: pre-line; }
.detail-block-eventos { border-color: #90caf9; }
.detail-eventos-vacio { margin: 0 0 6px; font-size: 13px; color: #666; }
.detail-eventos-hint { margin: 8px 0 0; font-size: 12px; color: #888; }
.detail-eventos-select-wrap { display: flex; flex-direction: column; gap: 10px; }
.detail-eventos-label { font-size: 12px; font-weight: 600; color: #555; text-transform: uppercase; letter-spacing: 0.02em; }
.detail-eventos-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cfd8dc;
    border-radius: 8px;
    background: #fff;
    font-size: 14px;
    color: #333;
}
.detail-eventos-accion-box {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 10px 12px;
    background: #e3f2fd;
    border-radius: 8px;
    border: 1px solid #bbdefb;
}
.detail-eventos-wrap { overflow-x: auto; }
.detail-eventos-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.detail-eventos-table th { text-align: left; font-size: 11px; text-transform: uppercase; color: #888; padding: 6px 8px; border-bottom: 2px solid #e0d6cc; }
.detail-eventos-table td { padding: 8px; border-bottom: 1px solid #f0ebe6; vertical-align: middle; }
.detail-eventos-accion { text-align: right; white-space: nowrap; }
.btn-ver-evento {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px; font-size: 12px; font-weight: 600;
    color: #1565c0; background: #e3f2fd; border: 1px solid #90caf9;
    border-radius: 6px; text-decoration: none;
}
.btn-ver-evento:hover { background: #bbdefb; color: #0d47a1; }
.detail-input-mayus { width: 100%; max-width: 100%; box-sizing: border-box; padding: 10px 12px; border: 2px solid #bcaaa4; border-radius: 8px; font-size: 14px; letter-spacing: 0.02em; text-transform: uppercase; font-family: inherit; }
.detail-input-mayus:focus { outline: none; border-color: #795548; }
.detail-ultimo-pago-vacio { margin: 0; color: #666; font-size: 14px; }
.detail-ultimo-pago-dl { margin: 0; display: grid; gap: 8px 16px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); font-size: 14px; }
.detail-ultimo-pago-dl dt { font-size: 11px; text-transform: uppercase; color: #888; margin: 0 0 2px; font-weight: 600; }
.detail-ultimo-pago-dl dd { margin: 0; font-weight: 500; }
.detail-pest-notas { grid-column: 1 / -1; }
.detail-pagos-subtitle { margin: 0 0 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: #795548; letter-spacing: 0.03em; }
.detail-pagos-subtitle--hist { margin-top: 18px; }
.detail-pagos-count { font-weight: 600; color: #888; text-transform: none; letter-spacing: 0; }
.detail-pagos-ultimo-wrap { margin-bottom: 4px; }
.detail-pagos-historial-wrap { max-height: 260px; overflow: auto; border: 1px solid #e0d6cc; border-radius: 8px; background: #fff; }
.detail-pagos-historial-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.detail-pagos-historial-table thead { position: sticky; top: 0; background: #f5efe8; z-index: 1; }
.detail-pagos-historial-table th { padding: 8px 10px; text-align: left; font-size: 11px; text-transform: uppercase; color: #888; border-bottom: 1px solid #e0d6cc; white-space: nowrap; }
.detail-pagos-historial-table td { padding: 8px 10px; border-bottom: 1px solid #eee; vertical-align: top; }
.detail-pagos-historial-table tbody tr:last-child td { border-bottom: none; }
.detail-pagos-historial-table tbody tr:hover { background: #faf7f4; }
.detail-pagos-row-ultimo { background: #fff8e1; }
.detail-pagos-row-ultimo:hover { background: #fff3cd !important; }
.detail-pagos-notas { max-width: 220px; font-size: 12px; color: #555; word-break: break-word; }
.detail-pagos-periodos-cell { min-width: 180px; vertical-align: top; }
.detail-pagos-acciones-cell {
    text-align: center;
    width: 1%;
    white-space: nowrap;
    vertical-align: middle;
}
.btn-eliminar-pago {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(180deg, #ff5b57 0%, #e53935 100%);
    box-shadow: 0 2px 0 #c62828, 0 4px 10px rgba(229, 57, 53, 0.28);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn-eliminar-pago i {
    font-size: 14px;
    line-height: 1;
    color: inherit;
    filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.15));
}
.btn-eliminar-pago:hover {
    background: linear-gradient(180deg, #ff6e6a 0%, #d32f2f 100%);
    transform: translateY(-1px);
    box-shadow: 0 3px 0 #b71c1c, 0 8px 14px rgba(198, 40, 40, 0.32);
}
.btn-eliminar-pago:active {
    transform: translateY(1px);
    box-shadow: 0 1px 0 #b71c1c, 0 2px 6px rgba(198, 40, 40, 0.25);
}
.btn-eliminar-pago:focus-visible {
    outline: 2px solid #ffcdd2;
    outline-offset: 2px;
}
.detail-pagos-historial-table .btn-eliminar-pago { margin: 2px 0; }
.detail-periodos-wrap { margin-top: 4px; }
.detail-periodos-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.detail-periodos-table th { text-align: left; font-size: 10px; text-transform: uppercase; color: #888; padding: 4px 6px; border-bottom: 1px solid #e0d6cc; }
.detail-periodos-table td { padding: 4px 6px; border-bottom: 1px solid #f0ebe6; white-space: nowrap; }
.detail-periodos-table--compact { font-size: 11px; }
.detail-periodos-table--compact td,
.detail-periodos-table--compact th { padding: 3px 4px; }
.periodos-tipo-anual {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    background: #e8f5e9;
    color: #2e7d32;
    font-weight: 600;
    font-size: 11px;
}
.periodos-tipo-plan {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    background: #e3f2fd;
    color: #1565c0;
    font-weight: 600;
    font-size: 11px;
}
.periodos-tipo-mensual {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    background: #f5f5f5;
    color: #616161;
    font-size: 11px;
}
.detail-pago-extra { margin-top: 14px; }
.detail-pago-texto { margin: 0; font-size: 13px; color: #444; line-height: 1.45; }
.detail-pago-saldo-favor { color: #2e7d32; font-weight: 600; }
.detail-block-desglose { border-color: #bcaaa4; background: #fff; margin-bottom: 16px; }
.detail-desglose-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.detail-desglose-table td { padding: 6px 4px; border-bottom: 1px solid #eee; }
.detail-desglose-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.detail-desglose-menos { color: #2e7d32; }
.detail-desglose-total td { border-bottom: none; border-top: 2px solid #bcaaa4; padding-top: 10px; }
.detail-desglose-periodos { margin-top: 12px; }
.detail-periodos-debe-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.detail-periodos-debe-table th { text-align: left; font-size: 10px; text-transform: uppercase; color: #888; padding: 4px 6px; border-bottom: 1px solid #e0d6cc; }
.detail-periodos-debe-table td { padding: 5px 6px; border-bottom: 1px solid #f0ebe6; }
.detail-periodo-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.detail-periodo-badge--atrasado { background: #ffebee; color: #c62828; }
.detail-periodo-badge--actual { background: #fff8e1; color: #f57f17; }
.detail-pagos-acciones { margin-top: 14px; }
.btn-periodos-manuales {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 14px; border: 1px solid #8d6e63; background: #fff; color: #5d4037;
    border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-periodos-manuales:hover { background: #efebe9; }
/* Por encima del modal Ver detalles (z-index 1000 en admin.css) */
#periodosModal { z-index: 1100; }
.periodos-modal-hint { font-size: 13px; color: #666; margin: 0 0 12px; line-height: 1.45; }
.periodos-modal-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.periodos-modal-table th { text-align: left; font-size: 11px; text-transform: uppercase; color: #888; padding: 6px 8px; border-bottom: 2px solid #e0d6cc; }
.periodos-modal-table td { padding: 8px; border-bottom: 1px solid #f0ebe6; vertical-align: middle; }
.periodos-modal-estado { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.periodos-modal-estado--pago { background: #e8f5e9; color: #2e7d32; }
.periodos-modal-estado--manual { background: #e3f2fd; color: #1565c0; }
.periodos-modal-estado--duplicado { background: #fff3e0; color: #e65100; }
.periodos-modal-estado--pendiente { background: #fafafa; color: #757575; }
.periodos-modal-estado--adelanto { background: #f3e5f5; color: #6a1b9a; }
.periodo-manual-row--futuro { background: #faf8ff; }
.periodos-modal-actions { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
.periodo-manual-campo.is-hidden { display: none; }
.periodo-manual-campo input[type="date"],
.periodo-manual-campo input[type="number"] {
    width: 100%; max-width: 140px; padding: 5px 8px; font-size: 12px;
    border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box;
}
.periodos-modal-table .periodo-manual-campo { min-width: 110px; }
.detail-pagos-row-manual,
.pagos-row-manual { background: #f3f8ff; }
.detail-pagos-row-manual:hover,
.pagos-row-manual:hover { background: #e8f1fc; }
.estado-badge-manual { background: #e3f2fd; color: #1565c0; font-size: 10px; vertical-align: middle; }
.estado-badge-vigente { display: inline-block; padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; background: #e8f5e9; color: #2e7d32; }
.estado-badge-suspendido { display: inline-block; padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; background: #fff3e0; color: #e65100; }
.detail-footer-acciones { margin-top: 24px; padding-top: 20px; border-top: 2px solid #e0d6cc; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.btn-eliminar-contrato { padding: 10px 18px; font-size: 14px; font-weight: 600; background: #b71c1c; color: #fff; border: none; border-radius: 8px; cursor: pointer; font-family: inherit; }
.btn-eliminar-contrato:hover { background: #8b0000; }
.btn-autorizar-servicio { padding: 10px 18px; font-size: 14px; font-weight: 600; background: #1565c0; color: #fff; border: none; border-radius: 8px; cursor: pointer; font-family: inherit; }
.btn-autorizar-servicio:hover { background: #0d47a1; }
.btn-cancel-contrato-detail { padding: 10px 18px; font-size: 14px; font-weight: 600; background: #9c1d3e; color: #fff; border: none; border-radius: 8px; cursor: pointer; font-family: inherit; }
.btn-cancel-contrato-detail:hover { background: #741530; }
/* Granate: rojo distinto del PDF (#e53935 rojo brillante) */
.btn-action.btn-cancel-contrato { background-color: #9c1d3e; color: #fff; }
.btn-action.btn-cancel-contrato i { color: inherit; }
.btn-action.btn-cancel-contrato:hover { background-color: #741530; }
.btn-action.btn-reactivar { background: #43a047; color: #fff; }
.btn-action.btn-reactivar:hover { background: #2e7d32; }
.detail-block-cancelacion { border-color: #bcaaa4; }
.historial-cancel-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.historial-cancel-table th,
.historial-cancel-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #e0e0e0; }
.historial-cancel-table th { font-size: 11px; text-transform: uppercase; color: #888; }
#cancelMotivoOtroGroup { display: none; margin-top: 10px; }
#cancelMotivoOtroGroup.is-visible { display: block; }

.input-uppercase { text-transform: uppercase; }
.filter-group-end { align-self: end; }
.btn-clear-filters-full { width: 100%; }

.is-hidden { display: none !important; }

#emptyState:not(.is-hidden),
#pagosEmpty:not(.is-hidden) {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ========== Expediente responsive ========== */

.expediente-page {
    overflow-x: hidden;
}

.expediente-page .admin-container {
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
}

.expediente-header-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.expediente-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
}

.expediente-header-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    width: 100%;
}

.expediente-nav-menu {
    position: relative;
}

.expediente-nav-menu > summary {
    list-style: none;
    cursor: pointer;
}

.expediente-nav-menu > summary::-webkit-details-marker {
    display: none;
}

.expediente-nav-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 8px;
}

.expediente-nav-toggle:hover {
    background: rgba(255, 255, 255, 0.28);
}

.expediente-nav-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 300;
    min-width: 220px;
    padding: 8px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
    border: 1px solid #e8e8e8;
}

.expediente-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: #333;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
}

.expediente-nav-link:hover {
    background: #f5f0eb;
    color: #4e342e;
}

.expediente-nav-link i {
    width: 18px;
    color: #8d6e63;
    text-align: center;
}

.expediente-btn-toolbar-clear {
    cursor: pointer;
    border: none;
    font-family: inherit;
}

.expediente-page .stats-dashboard,
.expediente-page .filters-section,
.expediente-page .registros-section,
.expediente-page .pagination-container,
.expediente-page .loading-indicator,
.expediente-page .empty-state {
    padding-left: 0;
    padding-right: 0;
}

.expediente-page .table-container {
    border-radius: 10px;
}

.expediente-page .filters-section {
    margin-bottom: 20px;
}

.expediente-page .filters-grid {
    gap: 12px;
}

.expediente-page .filter-group input {
    min-height: 44px;
}

.expediente-page .btn-clear-filters,
.expediente-page .btn-refresh,
.expediente-page .btn-back {
    min-height: 44px;
}

.expediente-acciones-cell {
    vertical-align: middle;
    width: 132px;
    min-width: 132px;
}
.expediente-acciones-grid {
    display: grid;
    grid-template-columns: repeat(3, 36px);
    grid-template-rows: repeat(2, 36px);
    gap: 6px;
    width: max-content;
    justify-items: stretch;
    align-items: stretch;
}
/* Las filas ceden sus botones al grid padre para una cuadrícula 3×2 perfecta */
.expediente-acciones-fila {
    display: contents;
}

.expediente-page .expediente-acciones-grid .btn-action {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    max-width: 36px;
    max-height: 36px;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1;
    text-decoration: none;
}
.expediente-page .expediente-acciones-grid .btn-action i {
    font-size: 14px;
    width: 14px;
    height: 14px;
    line-height: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
}

@media (min-width: 900px) {
    .expediente-header-content {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
    }

    .expediente-header-top {
        width: auto;
        flex: 0 1 auto;
    }

    .expediente-header-toolbar {
        width: auto;
        flex: 1 1 auto;
        justify-content: flex-end;
    }
}

@media (max-width: 768px) {
    .expediente-page .admin-container {
        padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
        padding-left: max(12px, env(safe-area-inset-left, 0px));
        padding-right: max(12px, env(safe-area-inset-right, 0px));
    }

    .expediente-header {
        margin-bottom: 16px;
        padding-bottom: 14px;
    }

    .expediente-header-toolbar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 250;
        margin: 0;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
        background: #fff;
        border-top: 1px solid #e0dcd8;
        box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.12);
        justify-content: center;
        flex-direction: row;
        width: 100%;
    }

    .expediente-header-toolbar .btn-refresh,
    .expediente-header-toolbar .btn-back,
    .expediente-header-toolbar .expediente-btn-toolbar-clear {
        width: auto;
        flex: 1 1 auto;
        max-width: 160px;
        justify-content: center;
    }

    .expediente-btn-label {
        display: none;
    }

    .expediente-page .stats-dashboard {
        grid-template-columns: 1fr;
        padding: 0;
        gap: 12px;
    }

    .expediente-page .stat-card {
        padding: 14px;
    }

    .expediente-page .filters-section,
    .expediente-page .registros-section {
        padding: 0;
    }

    .expediente-page .filters-grid {
        grid-template-columns: 1fr;
    }

    .expediente-page .filter-group-end {
        align-self: stretch;
    }

    .expediente-page .registros-table {
        min-width: 720px;
    }

    .expediente-page .registros-table th,
    .expediente-page .registros-table td {
        padding: 10px 8px;
    }

    .expediente-page .pagination-container {
        padding: 0;
    }

    .expediente-page .detail-grid {
        grid-template-columns: 1fr;
    }

    .expediente-page .detail-ultimo-pago-dl {
        grid-template-columns: 1fr 1fr;
    }

    .expediente-page .modal-content {
        width: calc(100% - 16px);
        max-height: 92vh;
        margin: 8px auto;
    }

    .expediente-page .modal-body {
        padding: 16px;
    }

    .expediente-page .qr-modal-actions .btn,
    .expediente-page .periodos-modal-actions .btn {
        flex: 1 1 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .expediente-header-top h1 {
        font-size: 1.15rem;
    }

    .expediente-header-toolbar .btn-refresh,
    .expediente-header-toolbar .expediente-btn-toolbar-clear {
        padding: 10px 14px;
        min-width: 48px;
    }

    .expediente-page .detail-ultimo-pago-dl {
        grid-template-columns: 1fr;
    }

    .expediente-page .expediente-acciones-grid .btn-action {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        max-width: 36px;
        max-height: 36px;
        padding: 0;
    }
}
