/* Polígons destacats (llistat de Polígons) */
.fd-section,
.fd-section * {
    font-family: 'Montserrat', sans-serif;
}

.fd-section {
    margin-top: 64px;
    min-width: 0;
    max-width: 100%;
}

.fd-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 28px;
}

.fd-title {
    margin: 0 0 8px;
    font-size: clamp(1.8rem, 3vw, 2.4rem);
    font-weight: 700;
    color: #1f1f1f;
    display: flex;
    align-items: center;
    gap: 12px;
}

.fd-subtitle {
    margin: 0;
    font-size: 16px;
    color: #555;
}

.fd-edit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    background: transparent;
    color: #7b6653;
    cursor: pointer;
}

.fd-edit-btn svg {
    width: 22px;
    height: 22px;
}

.fd-edit-btn:hover {
    opacity: 0.65;
}

/* Frecce */
.fd-nav {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.fd-nav[hidden] {
    display: none;
}

.fd-nav__btn {
    width: 42px;
    height: 42px;
    border-radius: 999px;
    border: none;
    background: #1f1f1f;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.fd-nav__btn svg {
    width: 20px;
    height: 20px;
}

.fd-nav__btn:disabled {
    background: #c8bca5;
    cursor: default;
}

/* Carousel (scroll-snap) */
.fd-track {
    --fd-gap: 24px;
    --fd-per-view: 3;
    display: flex;
    gap: var(--fd-gap);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    padding: 4px 4px 28px;
    margin: 0 -4px;
    scroll-padding: 0 4px;  /* l'aggancio coincide col bordo interno: a inizio corsa scrollLeft = 0 */
    /* La larghezza non dipende dal contenuto: titoli lunghi non allargano la pagina. */
    contain: inline-size;
    min-width: 0;
}

.fd-track::-webkit-scrollbar {
    display: none;
}

.fd-track:focus-visible {
    outline: 2px solid #7b6653;
    outline-offset: 2px;
}

.fd-card {
    flex: 0 0 calc((100% - (var(--fd-per-view) - 1) * var(--fd-gap)) / var(--fd-per-view));
    min-width: 0;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #e9d9cf;
    border-radius: 12px;
    overflow: hidden;
}

.fd-card__photo {
    position: relative;
    overflow: hidden;
    aspect-ratio: 11 / 3;
    background: #f4f2ec;
}

.fd-card__photo img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.fd-card__photo img.fd-card__photo--fallback {
    inset: auto;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: auto;
    height: 70%;
    max-width: 80%;
    object-fit: contain;
}

.fd-card__body {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: 14px 16px 14px;
}

.fd-card__name {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.25;
    color: #1f1f1f;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fd-card__place {
    margin: 2px 0 0;
    min-height: 1.3em;
    font-size: 14px;
    line-height: 1.3;
    color: #666;
}

.fd-card__info {
    display: flex;
    align-items: center;
    min-height: 22px;
    margin: 10px 0 12px;
    font-size: 13px;
    color: #444;
}

.fd-card__stat {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.fd-card__sep {
    align-self: stretch;
    width: 1px;
    margin: 2px 14px;
    background: #cfc6bd;
    flex-shrink: 0;
}

/* Ente: occupa lo spazio restante e viene troncato, senza allargare la card. */
.fd-card__entity {
    flex-shrink: 1;
    min-width: 0;
}

.fd-card__entity-name {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.fd-card__stat svg {
    width: 18px;
    height: 18px;
    color: #b0541f;
    flex-shrink: 0;
}

.fd-card__info > .fd-card__stat:only-child.fd-card__entity {
    max-width: 100%;
}

.fd-card__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: auto;
}

.fd-card__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: .5rem 1.25rem;
    border-radius: 999px;
    background: #1f1f1f;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
    white-space: nowrap;
}

.fd-card__btn:hover {
    color: #fff;
    text-decoration: none;
    opacity: 0.85;
}

.fd-card__lens {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    color: #1f1f1f;
    flex-shrink: 0;
}

.fd-card__lens svg {
    width: 20px;
    height: 20px;
}

.fd-card__lens:hover {
    color: #1f1f1f;
    opacity: 0.65;
}

/* 2 card per vista fino a 1199px (era 991px): a 1024-1150px con 3 card il pulsante "Sol·licita informació" (206px) usciva dalla card e veniva tagliato */
@media (max-width: 1199px) {
    .fd-track { --fd-per-view: 2; }
}

@media (max-width: 575px) {
    .fd-track { --fd-per-view: 1; }
    .fd-header { align-items: flex-start; }
}

/* Modal di gestione */
.fd-modal .modal-content {
    border-radius: 20px;
    border: none;
    box-shadow: 0 20px 50px rgba(0, 0, 0, .18);
}

.fd-modal .modal-header {
    border-bottom: none;
    padding: 24px 28px 0;
}

.fd-modal .modal-title {
    font-size: 20px;
    font-weight: 700;
    color: #161616;
}

.fd-modal .modal-body {
    padding: 20px 28px;
}

.fd-modal .modal-footer {
    border-top: none;
    padding: 0 28px 24px;
}

.fd-modal__label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
}

.fd-modal__input {
    width: 100%;
    height: 44px;
    padding: 0 16px;
    border: 1px solid #d8d2c4;
    border-radius: 999px;
    font-size: 15px;
}

.fd-modal__results {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
    border: 1px solid #e6e0d2;
    border-radius: 16px;
    max-height: 220px;
    overflow-y: auto;
}

.fd-modal__results[hidden] {
    display: none;
}

.fd-modal__results li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid #f0ece2;
    font-size: 14px;
}

.fd-modal__results li:last-child {
    border-bottom: none;
}

.fd-modal__subtitle {
    margin: 24px 0 10px;
    font-size: 15px;
    font-weight: 700;
}

.fd-modal__list {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: fd;
}

.fd-modal__list li {
    counter-increment: fd;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    margin-bottom: 8px;
    background: #EDE6D6;
    border-radius: 14px;
    font-size: 14px;
}

.fd-modal__list li::before {
    content: counter(fd) ".";
    font-weight: 700;
    min-width: 28px;
}

.fd-modal__list li.fd-modal__empty {
    counter-increment: none;
    background: transparent;
    padding: 6px 2px;
    color: #555;
}

.fd-modal__list li.fd-modal__empty::before {
    content: none;
}

.fd-item__text {
    flex: 1;
    min-width: 0;
}

.fd-item__muni {
    color: #555;
    font-size: 13px;
}

.fd-item__actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.fd-mini-btn {
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border: none;
    border-radius: 999px;
    background: #1f1f1f;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.fd-mini-btn:disabled {
    background: #c8bca5;
    cursor: default;
}

.fd-modal__error {
    margin: 12px 0 0;
    color: #b3261e;
    font-size: 14px;
    font-weight: 600;
}

.fd-modal__error[hidden] {
    display: none;
}

.fd-modal__btn {
    padding: .7rem 1.8rem;
    border-radius: 999px;
    border: none;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
}

.fd-modal__btn--dark {
    background: #000;
    color: #fff;
}

.fd-modal__btn--light {
    background: #EDE6D6;
    color: #1f1f1f;
}

.fd-modal__btn:disabled {
    opacity: .6;
    cursor: default;
}

/* Modal: form scheda */
.fd-modal [hidden] {
    display: none !important;
}

.fd-modal .modal-footer > div {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.fd-form .fd-modal__label {
    margin-top: 14px;
}

.fd-form__row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.fd-field-error {
    margin: 4px 0 0;
    min-height: 0;
    color: #b3261e;
    font-size: 13px;
    font-weight: 600;
}

.fd-field-error:empty {
    display: none;
}

.fd-photo {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.fd-photo__preview {
    width: 160px;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 14px;
    background: #f4f2ec;
}

.fd-photo__controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 14px;
}

.fd-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.fd-check--block {
    display: flex;
    margin-top: 18px;
    font-weight: 600;
}

.fd-link {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    padding: 8px 14px;
    background: #EDE6D6;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
}

.fd-thumb {
    width: 56px;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
}

.fd-modal__list li.fd-inactive {
    opacity: .6;
}

@media (max-width: 575px) {
    .fd-form__row { grid-template-columns: 1fr; }
}

/* Stato vuoto */
.fd-empty {
    margin: 0;
    padding: 28px 0 8px;
    font-size: 16px;
    color: #555;
}

/* Pulsante "Polígons destacats" nell'intestazione della lista (anchor alla sezione) */
/* Con spazio sufficiente il gruppo sta a destra del titolo (space-between); altrimenti va a capo
   sotto il titolo e, essendo l'unico elemento della riga, resta allineato a sinistra. */
.list-header {
    flex-wrap: wrap;
    gap: 18px 24px;
}

.list-header__actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 16px;
    max-width: 100%;
}

.fd-jump {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 46px;
    padding: 0 22px;
    border-radius: 999px;
    background: #b79b7a;
    color: #ffffff;
    font-family: 'Montserrat', sans-serif;
    font-size: 16px;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.fd-jump svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.fd-jump:hover {
    background: #7b6653;
    color: #ffffff;
    text-decoration: none;
}

.fd-jump:focus-visible {
    outline: 3px solid #1f1f1f;
    outline-offset: 3px;
}

.fd-section {
    scroll-margin-top: 24px;
}

html:has(#poligons-destacats),
html:has(#terrenys-destacats),
html:has(#naus-destacades) {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html:has(#poligons-destacats),
    html:has(#terrenys-destacats),
    html:has(#naus-destacades) {
        scroll-behavior: auto;
    }
}

/* Riferimento commerciale (Terrenys destacats): riga sempre riservata per l'altezza uniforme */
.fd-card__ref {
    margin: 0 0 12px;
    min-height: 1.3em;
    font-size: 13px;
    line-height: 1.3;
    color: #666;
}

/* Modal di gestione su schermi stretti: le azioni vanno su una seconda riga invece di sbordare dalla riga */
@media (max-width: 575px) {
    .fd-modal__list li {
        flex-wrap: wrap;
    }

    .fd-modal__list li .fd-item__text {
        flex: 1 1 0;
        min-width: 120px;
        overflow-wrap: anywhere;
    }

    .fd-modal__list li .fd-item__actions {
        flex: 0 0 100%;
        justify-content: flex-end;
        flex-wrap: wrap;
    }
}

/* Campo Nom con ricerca dei Poligons censiti (solo modal Polígons destacats) */
.fd-combo {
    position: relative;
}

.fd-combo__list {
    position: absolute;
    z-index: 5;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    margin: 0;
    padding: 4px;
    list-style: none;
    background: #fff;
    border: 1px solid #d8d2c4;
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
    max-height: 240px;
    overflow-y: auto;
}

.fd-combo__list[hidden] {
    display: none;
}

.fd-combo__option {
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    cursor: pointer;
    overflow-wrap: anywhere;
}

.fd-combo__option.is-active,
.fd-combo__option:hover {
    background: #f3efe4;
}

.fd-combo__muni {
    font-size: 13px;
    color: #666;
}

.fd-combo__manual {
    border-top: 1px solid #e6e0d2;
    border-radius: 0 0 12px 12px;
    font-weight: 600;
}

.fd-combo__empty {
    padding: 8px 12px;
    font-size: 13px;
    color: #666;
}

.fd-combo__linked {
    margin: 6px 0 0;
    font-size: 13px;
    color: #444;
}

.fd-combo__linked[hidden] {
    display: none;
}

.fd-combo__unlink {
    margin-left: 8px;
    padding: 0;
    border: 0;
    background: none;
    color: #b3261e;
    font-size: 13px;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
}
