/**
 * Fichas de Pisos — Frontend Styles
 * Tabla de viviendas + modal + counter.
 */

.fichas-pisos-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 2em 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

.fichas-pisos-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
    font-size: 15px;
    line-height: 1.5;
}

/* ——— Header ——— */
.fichas-pisos-table thead th {
    background: #1b2a4a;
    color: #fff;
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    padding: 16px 24px;
    text-align: left;
    border: none;
    white-space: nowrap;
}
.fichas-pisos-table thead th.col-metros,
.fichas-pisos-table thead th.col-exterior,
.fichas-pisos-table thead th.col-precio,
.fichas-pisos-table thead th.col-plano {
    text-align: center;
}

/* ——— Body rows ——— */
.fichas-pisos-table tbody tr { transition: background-color 0.2s ease; }
.fichas-pisos-table tbody tr:nth-child(even) { background-color: #f8f9fb; }
.fichas-pisos-table tbody tr:nth-child(odd)  { background-color: #fff; }
.fichas-pisos-table tbody tr:hover { background-color: #eef3f9; }
.fichas-pisos-table tbody td {
    padding: 16px 24px;
    border-bottom: 1px solid #e8ecf1;
    vertical-align: middle;
    color: #2c3e50;
}
.fichas-pisos-table tbody tr:last-child td { border-bottom: none; }

/* Column alignment */
.fichas-pisos-table td.col-metros,
.fichas-pisos-table td.col-exterior,
.fichas-pisos-table td.col-precio,
.fichas-pisos-table td.col-plano { text-align: center; }

/* ——— Vivienda ——— */
.vivienda-nombre { font-weight: 600; color: #1b2a4a; font-size: 15px; }
.vivienda-nombre--clickable {
    cursor: pointer;
    border-bottom: 1px dashed #1b2a4a;
    transition: color 0.2s, border-color 0.2s;
}
.vivienda-nombre--clickable:hover { color: #3a5a9a; border-color: #3a5a9a; }

/* ——— Badges ——— */
.badge {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    white-space: nowrap;
}
.badge--exterior { background: #e8f4f0; color: #1a7a5a; border: 1px solid #b8ddd0; }
.badge--interior { background: #f0f2f5; color: #5a6577; border: 1px solid #d5dae2; }
.badge--disponible { background: #e8f4f0; color: #1a7a5a; border: 1px solid #b8ddd0; }
.badge--reservado { background: #fff8e1; color: #b8860b; border: 1px solid #f0d78c; }
.badge--vendido { background: #fdf0f0; color: #c0392b; border: 1px solid #f0c4c4; }

/* ——— Reserved rows ——— */
.fichas-pisos-row--reservado td { color: #999; }
.fichas-pisos-row--reservado td:first-child { color: #1b2a4a; }

/* ——— Sold rows ——— */
.fichas-pisos-row--vendido { background-color: #f5f5f5 !important; }
.fichas-pisos-row--vendido td { color: #aaa; }
.fichas-pisos-row--vendido .vivienda-nombre { text-decoration: line-through; color: #aaa; }
.fichas-pisos-row--vendido .btn-pdf,
.fichas-pisos-row--vendido .afm-unit-pdf { opacity: 1; }
.fichas-pisos-row--vendido .badge--vendido,
.fichas-pisos-row--vendido .afm-unit-status--sold { background: #fdf0f0; color: #c0392b; border-color: #f0c4c4; opacity: 1; }

/* ——— Price column ——— */
.precio-valor { font-weight: 700; color: #1b2a4a; font-size: 15px; }
.no-precio { color: #8899aa; font-style: italic; font-size: 13px; }

/* ——— PDF button ——— */
.btn-pdf {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 18px; background: #1b2a4a; color: #fff;
    border-radius: 6px; font-size: 12px; font-weight: 700;
    letter-spacing: 0.6px; text-decoration: none; text-transform: uppercase;
    transition: background-color 0.2s, transform 0.15s;
    line-height: 1; white-space: nowrap;
}
.btn-pdf:hover { background: #2c4270; transform: translateY(-1px); color: #fff; text-decoration: none; }
.btn-pdf:active { transform: translateY(0); }
.btn-pdf svg { flex-shrink: 0; }
.no-plano { color: #b0b8c5; font-size: 18px; }

/* ——— Summary counter ——— */
.fichas-pisos-summary {
    display: flex; align-items: center; justify-content: center;
    flex-wrap: wrap; gap: 6px;
    margin-top: 16px; padding: 14px 24px;
    background: #f4f6f9; border-radius: 8px;
    font-size: 14px; color: #4a5568;
}
.summary-total { font-weight: 700; color: #1b2a4a; }
.summary-sep { color: #cbd5e0; }
.summary-disponible { color: #1a7a5a; font-weight: 600; }
.summary-reservado { color: #b8860b; font-weight: 600; }
.summary-vendido { color: #c0392b; font-weight: 600; }

/* ——— Modal ——— */
.fichas-pisos-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 999999; display: flex; align-items: center; justify-content: center;
}
.fichas-pisos-modal-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
}
.fichas-pisos-modal-content {
    position: relative; background: #fff; border-radius: 12px;
    padding: 32px 36px; max-width: 560px; width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: fichasModalIn 0.25s ease-out;
    max-height: 80vh; overflow-y: auto;
}
@keyframes fichasModalIn {
    from { opacity: 0; transform: translateY(20px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.fichas-pisos-modal-close {
    position: absolute; top: 12px; right: 16px;
    background: none; border: none; font-size: 28px; color: #999;
    cursor: pointer; line-height: 1; padding: 4px;
    transition: color 0.2s;
}
.fichas-pisos-modal-close:hover { color: #333; }
.fichas-pisos-modal-content h3 {
    margin: 0 0 8px; font-size: 20px; color: #1b2a4a; font-weight: 700;
}
.modal-planta {
    margin: 0 0 16px; font-size: 13px; color: #7a8a9a;
    text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
}
.modal-descripcion {
    font-size: 15px; line-height: 1.7; color: #4a5568; margin-bottom: 20px;
}
.modal-specs {
    display: flex; flex-wrap: wrap; gap: 12px;
    padding-top: 16px; border-top: 1px solid #edf0f4;
}
.modal-spec {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 6px 14px; background: #f4f6f9; border-radius: 6px;
    font-size: 13px; color: #4a5568; font-weight: 500;
}

/* ——— Responsive: card layout ——— */
@media (max-width: 768px) {
    .fichas-pisos-table-wrap,
    .afm-units-table-wrap { margin: 1em 0; overflow-x: visible; }

    .fichas-pisos-table,
    .afm-units-table { min-width: 0; }

    .fichas-pisos-table thead,
    .afm-units-table thead { display: none; }

    .fichas-pisos-table tbody tr,
    .afm-units-table tbody tr {
        display: block;
        margin-bottom: 16px;
        border: 1px solid #e8ecf1;
        border-radius: 8px;
        overflow: hidden;
        box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    }

    .fichas-pisos-table tbody td,
    .afm-units-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 16px;
        border-bottom: 1px solid #f0f2f5;
        text-align: right;
    }
    .fichas-pisos-table tbody td:last-child,
    .afm-units-table tbody td:last-child { border-bottom: none; }

    /* Force data-label over any external nth-child overrides (high specificity) */
    .fichas-pisos-table-wrap .fichas-pisos-table tbody tr td[data-label]::before,
    .afm-units-table-wrap .afm-units-table tbody tr td[data-label]::before,
    .afm-units-shortcode .afm-units-table tbody tr td[data-label]::before {
        content: attr(data-label) !important;
        font-weight: 600;
        font-size: 11px;
        letter-spacing: 0.5px;
        text-transform: uppercase;
        color: #8899aa;
        text-align: left;
        flex-shrink: 0;
        margin-right: 12px;
    }

    /* Explicit nth-child overrides to beat AFM landing CSS */
    .afm-units-shortcode .afm-units-table tbody td:nth-child(2)::before,
    .afm-units-shortcode .afm-units-table tbody td:nth-child(3)::before,
    .afm-units-shortcode .afm-units-table tbody td:nth-child(4)::before,
    .afm-units-shortcode .afm-units-table tbody td:nth-child(5)::before,
    .afm-units-shortcode .afm-units-table tbody td:nth-child(6)::before,
    .afm-units-shortcode .afm-units-table tbody td:nth-child(7)::before,
    .afm-units-table-wrap .afm-units-table tbody td:nth-child(2)::before,
    .afm-units-table-wrap .afm-units-table tbody td:nth-child(3)::before,
    .afm-units-table-wrap .afm-units-table tbody td:nth-child(4)::before,
    .afm-units-table-wrap .afm-units-table tbody td:nth-child(5)::before,
    .afm-units-table-wrap .afm-units-table tbody td:nth-child(6)::before,
    .afm-units-table-wrap .afm-units-table tbody td:nth-child(7)::before {
        content: attr(data-label) !important;
    }

    /* Primera celda (Vivienda) como header de la card */
    .fichas-pisos-table tbody td:first-child,
    .afm-units-table tbody td:first-child {
        background: #f8f9fb;
        font-size: 15px;
        font-weight: 700;
        padding: 14px 16px;
    }
    .afm-units-shortcode .afm-units-table tbody td:first-child::before,
    .afm-units-table-wrap .afm-units-table tbody td:first-child::before,
    .fichas-pisos-table-wrap .fichas-pisos-table tbody tr td:first-child::before { display: none !important; }

    /* Precio en móvil */
    .fichas-pisos-table tbody td[data-label="Precio"],
    .afm-units-table tbody td[data-label="Precio"] {
        font-weight: 700;
    }

    .btn-pdf,
    .afm-unit-pdf { padding: 6px 12px; font-size: 11px; }

    .fichas-pisos-summary { font-size: 12px; padding: 10px 16px; }
    .fichas-pisos-modal-content { padding: 24px 20px; }
}
