/**
 * COMPONENTS / PROJECT CARD
 * -----------------------------------------------------------------------------
 * Tarjeta de proyecto ejecutado: foto + etiqueta de tipo + métricas
 * (potencia y ahorro anual) + ubicación.
 *
 *   <article class="project-card">
 *       <div class="project-card__media">
 *           <img> <span class="project-card__tag">Comercial</span>
 *       </div>
 *       <div class="project-card__body">
 *           <div class="project-metrics"> … </div>
 *           <div class="project-card__location">SVG Chillán, Chile</div>
 *       </div>
 *   </article>
 */

.project-card {
    display: flex;
    flex-direction: column;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: var(--transition);
}

.project-card:hover {
    transform: var(--lift-lg);
    border-color: var(--border-blue);
    box-shadow: var(--shadow-md);
}

/* --- Media ------------------------------------------------------------- */

/*
 * Cuando el proyecto tiene varias fotos este contenedor es un <button>, así que
 * se neutralizan los estilos propios del elemento y se marca como pulsable.
 */
.project-card__media {
    position: relative;
    display: block;
    width: 100%;
    height: 180px;
    padding: 0;
    border: 0;
    overflow: hidden;
    background: var(--bg-soft);
}

.project-card__media--gallery {
    cursor: zoom-in;
}

.project-card__media--gallery:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: -2px;
}

/* Contador de fotos, para que se note que hay más detrás. */
.project-card__count {
    position: absolute;
    right: 12px;
    bottom: 12px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 9px;
    border-radius: var(--radius-xs);
    background: rgba(10, 23, 40, 0.82);
    color: var(--white);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.project-card__count svg {
    width: 14px;
    height: 14px;
}

.project-card__media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-slow);
}

.project-card:hover .project-card__media img {
    transform: scale(1.05);
}

.project-card__tag {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(10, 23, 40, 0.82);
    color: var(--white);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    letter-spacing: 0.3px;
    padding: 5px 11px;
    border-radius: var(--radius-xs);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* --- Cuerpo ------------------------------------------------------------ */

.project-card__body {
    padding: 16px 16px 18px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.project-card__title {
    font-family: var(--font-heading);
    font-weight: var(--fw-semibold);
    font-size: var(--fs-xl);
    letter-spacing: 0;
    color: var(--heading);
    margin-bottom: var(--space-sm);
}

.project-card__title a:hover {
    color: var(--blue);
}

.project-card__location {
    display: flex;
    align-items: center;
    gap: var(--space-2xs);
    font-size: var(--fs-base);
    color: var(--text-dim);
    margin-top: auto;
    margin-bottom: var(--space-sm);
}

/* Queda al fondo para que todas las tarjetas de la fila lo alineen. */
.project-card__quote {
    margin-top: auto;
}

.project-card__location svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    color: var(--text-muted);
}

/* =============================================================
   MÉTRICAS DEL PROYECTO
   Reutilizable en la ficha individual del proyecto.
============================================================= */

.project-metrics {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    margin-bottom: var(--space-sm);
}

.metric {
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
    padding: 8px 11px;
    min-width: 0;
}

.metric__label {
    font-size: var(--fs-2xs);
    font-weight: var(--fw-semibold);
    letter-spacing: 0.3px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.metric__value {
    font-family: var(--font-heading);
    font-weight: var(--fw-bold);
    font-size: 16px;
    color: var(--heading);
    white-space: nowrap;
}

/* Variante azul para el valor de referencia */
.metric--price {
    background: var(--blue-soft);
}

.metric--price .metric__label {
    color: var(--blue-dark);
}

.metric--price .metric__value {
    color: var(--blue-dark);
}

/* Variante verde para el ahorro */
.metric--saving {
    background: var(--green-soft);
}

.metric--saving .metric__label {
    color: var(--green-mid);
}

.metric--saving .metric__value {
    color: var(--green);
}

/*
 * En la ficha del proyecto las métricas van en rejilla.
 *
 * Antes era un flex con `flex: 1 1 150px`: como el ancho base era el mismo
 * para todas pero el contenido no ("5,4 kWp" frente a "Los Ángeles, Chile"),
 * cada celda acababa de un ancho distinto y la fila se veía descuadrada. Con
 * `auto-fit` + `minmax` todas miden lo mismo y la última fila no se estira.
 */
.project-metrics--row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: var(--space-xs);
}

.project-metrics--row .metric {
    padding: var(--space-sm) var(--space-md);
}

.project-metrics--row .metric__value {
    font-size: 22px;
    /*
     * La ubicación y el nombre del cliente son texto, no cifras: si no se les
     * deja partir, desbordan la celda. El `nowrap` solo tiene sentido en la
     * tarjeta, donde los valores son cortos.
     */
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.25;
}

/* =============================================================
   FILTROS DE TIPO DE PROYECTO
============================================================= */

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-bottom: var(--space-lg);
}

/* Son <button>: filtran las tarjetas de la página, no navegan. */
.filter-bar button {
    padding: 9px 18px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-strong);
    background: var(--white);
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--fs-base);
    font-weight: var(--fw-medium);
    cursor: pointer;
    transition: var(--transition);
}

.filter-bar button:hover {
    border-color: var(--blue);
    color: var(--blue);
}

.filter-bar button.is-active {
    background: var(--navy);
    border-color: var(--navy);
    color: var(--white);
}

/* Aviso cuando un tipo se queda sin resultados. */
.filter-empty {
    padding: var(--space-lg);
    text-align: center;
    color: var(--text-muted);
    background: var(--bg-alt);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
}

/* =============================================================
   GALERÍA DE LA FICHA DEL PROYECTO

   Es una galería EN LÍNEA, no el visor a pantalla completa: dentro de la
   ficha el visitante ya está viendo el proyecto y abrirle un diálogo encima
   sobra. El visor modal se reserva para las tarjetas de los listados, donde
   funciona como vista previa sin salir de la página.
============================================================= */

.project-gallery {
    margin-bottom: var(--space-lg);
}

.project-gallery__stage {
    position: relative;
    margin: 0;
    aspect-ratio: 16 / 9;
    border-radius: var(--radius-xl);
    overflow: hidden;
    background: var(--bg-soft);
}

.project-gallery__stage img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* El cambio de foto se funde en lugar de saltar. */
    transition: opacity var(--transition);
}

.project-gallery__stage.is-loading img {
    opacity: 0;
}

/* --- Miniaturas --------------------------------------------------------- */

/*
 * Rejilla, no flex con scroll: las galerías son de pocas fotos y una fila que
 * se desplaza en horizontal esconde la mitad sin avisar.
 */
.project-gallery__thumbs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: var(--space-xs);
    margin-top: var(--space-xs);
}

.project-gallery__thumb {
    display: block;
    aspect-ratio: 4 / 3;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-soft);
    /* El borde va siempre, transparente: así al activarse nada se mueve. */
    border: 2px solid transparent;
    opacity: 0.65;
    transition: var(--transition);
}

.project-gallery__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.project-gallery__thumb:hover,
.project-gallery__thumb:focus-visible {
    opacity: 1;
}

.project-gallery__thumb.is-active {
    border-color: var(--blue);
    opacity: 1;
}

@media (max-width: 700px) {

    .project-gallery__thumbs {
        grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    }
}

/* =============================================================
   VISOR DE GALERÍA

   Diálogo único y reutilizado por todas las tarjetas. Lo monta
   assets/js/project-gallery.js al pulsar la foto de un proyecto.
============================================================= */

.gallery-viewer {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
}

/* Sin scroll de fondo mientras el visor está abierto. */
body.has-gallery-open {
    overflow: hidden;
}

.gallery-viewer__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(6, 14, 26, 0.92);
}

.gallery-viewer__box {
    position: relative;
    z-index: 1;
    width: min(1100px, 100%);
    max-height: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

/* --- Barra superior ----------------------------------------------------- */

.gallery-viewer__bar {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--on-dark);
}

.gallery-viewer__title {
    flex: 1;
    min-width: 0;
    font-family: var(--font-heading);
    font-weight: var(--fw-semibold);
    font-size: var(--fs-lg);
    color: var(--white);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gallery-viewer__counter {
    font-size: var(--fs-base);
    color: var(--on-dark-dim);
}

.gallery-viewer__close {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border-on-dark);
    border-radius: var(--radius-circle);
    background: var(--surface-on-dark);
    color: var(--white);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    transition: var(--transition);
}

.gallery-viewer__close:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* --- Imagen -------------------------------------------------------------- */

.gallery-viewer__stage {
    margin: 0;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-viewer__stage img {
    max-width: 100%;
    max-height: 70vh;
    width: auto;
    height: auto;
    border-radius: var(--radius-lg);
    background: var(--navy);
}

/* --- Flechas ------------------------------------------------------------- */

.gallery-viewer__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 46px;
    height: 46px;
    border: 1px solid var(--border-on-dark);
    border-radius: var(--radius-circle);
    background: rgba(11, 19, 48, 0.7);
    color: var(--white);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    transition: var(--transition);
}

.gallery-viewer__nav:hover {
    background: rgba(11, 19, 48, 0.95);
}

.gallery-viewer__nav--prev { left: -8px; }
.gallery-viewer__nav--next { right: -8px; }

/* --- Miniaturas ---------------------------------------------------------- */

.gallery-viewer__thumbs {
    display: flex;
    gap: var(--space-xs);
    justify-content: center;
    flex-wrap: wrap;
}

.gallery-viewer__thumbs button {
    width: 64px;
    height: 48px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: var(--radius-xs);
    overflow: hidden;
    background: none;
    cursor: pointer;
    opacity: 0.55;
    transition: var(--transition);
}

.gallery-viewer__thumbs button:hover {
    opacity: 1;
}

.gallery-viewer__thumbs button.is-active {
    border-color: var(--blue-light);
    opacity: 1;
}

.gallery-viewer__thumbs img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

@media (max-width: 700px) {

    .gallery-viewer {
        padding: var(--space-xs);
    }

    .gallery-viewer__stage img {
        max-height: 60vh;
    }

    /* En táctil se pasa deslizando: las flechas solo estorban. */
    .gallery-viewer__nav {
        display: none;
    }

    .gallery-viewer__thumbs button {
        width: 52px;
        height: 40px;
    }
}
