/* =========================
   BASE + VIEWPORT SAFE
========================= */
html,
body {
    height: 100%;
    margin: 0;
}

.afv-app {
    height: 100dvh;
    height: calc(var(--vh, 1vh) * 100);
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* =========================
   TOPBAR (search + actions su 1 riga, risultati sotto)
   HTML attuale: afv-topbar, afv-row1, afv-row2, afv-actions, afv-zoom, input+results
========================= */
.afv-topbar {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
        "search actions"
        "results results";
    gap: 8px 10px;
    padding: 10px 12px;
    background: #fff;
    border-bottom: 1px solid #eee;
    overflow: visible;
    color-scheme: light;
}

.afv-brand {
    display: none !important;
}

/* la riga 1 (actions) va a destra */
.afv-row1 {
    grid-area: actions;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
}

/* riga 2: lasciamo esistere ma non “impacchettare” layout */
.afv-row2 {
    display: contents;
}

.afv-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.afv-zoom {
    display: flex;
    gap: 4px;
}

.afv-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;

    border: 1px solid #e5e7eb;
    background: #fff;
    padding: 8px 10px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.1;
    cursor: pointer;

    color: #111 !important;
    -webkit-text-fill-color: #111 !important;
    -webkit-appearance: none;
    appearance: none;

    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.afv-btn:hover {
    background: #f9fafb;
}

.afv-btn:active {
    transform: translateY(1px) translateZ(0);
}

#afv-btnZoomIn,
#afv-btnZoomOut {
    width: 36px;
    font-weight: 800;
}

/* SEARCH a sinistra (riga 1) */
#afv-searchInput {
    grid-area: search;
    width: 100%;
    min-width: 220px;
    max-width: 720px;

    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid #e5e7eb;
    font-size: 14px;

    background: #fff !important;
    color: #111 !important;
    -webkit-text-fill-color: #111 !important;
    caret-color: #111;

    -webkit-appearance: none;
    appearance: none;
}

#afv-searchInput::placeholder {
    color: #6b7280;
    opacity: 1;
}

/* RISULTATI sotto (riga 2 full width) */
#afv-searchResults {
    grid-area: results;
    width: 100%;
    background: #fff !important;
    color: #111 !important;
}

#afv-searchResults:empty {
    display: none;
}

#afv-searchResults:not(:empty) {
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .12);
    overflow: hidden;
    max-height: min(50vh, 360px);
}

#afv-searchResults button,
#afv-searchResults .afv-search-item {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    background: #fff !important;
    text-align: left;
    cursor: pointer;
    font-size: 13px;
    line-height: 1.25;

    color: #111 !important;
    -webkit-text-fill-color: #111 !important;
    -webkit-appearance: none;
    appearance: none;
}

#afv-searchResults button:hover,
#afv-searchResults .afv-search-item:hover {
    background: #f9fafb !important;
}

@media (max-width: 520px) {
    .afv-topbar {
        padding: 8px 10px;
        gap: 8px;
    }

    .afv-actions {
        gap: 6px;
    }

    .afv-btn {
        padding: 8px 9px;
        font-size: 12px;
    }
}

/* =========================
   VIEWER (catena altezza + overlay corretto)
========================= */
.afv-wrap {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    background: #f4f6f8;
}

#afv-viewer {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    background: #111;

    touch-action: none;
    /* blocca gesture pagina */
    -webkit-user-select: none;
    user-select: none;

    cursor: grab;
}

#afv-viewer.is-panning {
    cursor: grabbing;
}

#afv-stage {
    position: absolute;
    left: 0;
    top: 0;
    transform-origin: 0 0;
    will-change: transform;
}

#afv-bg {
    display: block;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

/* QUESTO è IL PEZZO CHE TI MANCAVA quando il CSS si rompeva */
#afv-overlay {
    position: absolute;
    left: 0;
    top: 0;
    pointer-events: auto;
    overflow: visible;
}

/* =========================
   STANDS
========================= */
#afv-overlay polygon.stand {
    cursor: pointer;
    vector-effect: non-scaling-stroke;
    stroke-width: 2;
    opacity: .9;
}

#afv-overlay polygon.stand:hover {
    opacity: 1;
}

/* stati */
#afv-overlay polygon.stand[data-stato="disponibile"] {
    fill: #b9db65;
    stroke: #2E7D32;
}

#afv-overlay polygon.stand[data-stato="prenotato"] {
    fill: #f3988f;
    stroke: #B71C1C;
}

#afv-overlay polygon.stand[data-stato="opzionato"] {
    fill: #ffff99;
    stroke: #F57F17;
}

#afv-overlay polygon.stand[data-stato="servizio"] {
    fill: #0069b3;
    stroke: #0e4481;
}

#afv-overlay polygon.stand[data-stato="cancellato"] {
    fill: #E0E0E0;
    stroke: #616161;
}

#afv-overlay polygon.stand.match {
    stroke: #ff9800;
    stroke-width: 3;
}

#afv-overlay polygon.stand.selected {
    fill: #c62828 !important;
    stroke: #8e0000 !important;
    stroke-width: 2 !important;
    opacity: 1 !important;
}

#afv-overlay polygon.stand.selected.match {
    stroke: #ff9800 !important;
    stroke-width: 3 !important;
}

/* labels */
#afv-overlay text.label,
#afv-overlay text.label2 {
    font-weight: 500;
    fill: #111;
    stroke: rgba(255, 255, 255, .85);
    stroke-width: .5px;
    paint-order: stroke fill;
    pointer-events: none;
    user-select: none;
}

/* Testi dentro overlay */
#afv-overlay text.label {
    font-size: 18px;
    /* espositore */
    font-weight: 700;
}

#afv-overlay text.label2 {
    font-size: 14px;
    /* nome stand */
    font-weight: 600;
}

/* opzionale: testo più leggibile su colori */
#afv-overlay text.label,
#afv-overlay text.label2 {
    paint-order: stroke;
    stroke: rgba(255, 255, 255, 0.85);
    stroke-width: 3px;
    stroke-linejoin: round;
}

#afv-overlay text.label.selected,
#afv-overlay text.label2.selected {
    fill: #fff;
    stroke: rgba(0, 0, 0, .35);
    font-weight: 600;
}

/* =========================
   LABELS (SVG) - font per stato
========================= */

#afv-overlay text.label,
#afv-overlay text.label2 {
    font-weight: 500;
    font-style: normal;
    opacity: 1;

    fill: #111;
    stroke: rgba(255, 255, 255, .85);
    stroke-width: .5px;
    paint-order: stroke fill;
    pointer-events: none;
    user-select: none;
}

/* disponibile: default (già ok) */
#afv-overlay text[data-stato="disponibile"] {
    font-weight: 500;
}

/* opzionato: un filo più “importante” */
#afv-overlay text[data-stato="opzionato"] {
    font-weight: 600;
}

/* prenotato: evidenza massima */
#afv-overlay text[data-stato="prenotato"] {
    font-weight: 800;
}

/* servizio: corsivo (o puoi scegliere 700 se preferisci) */
#afv-overlay text[data-stato="servizio"] {
    font-weight: 800;
    font-size: 24px;
    fill: #fff;


}

/* cancellato: più “spento” */
#afv-overlay text[data-stato="cancellato"] {
    font-weight: 400;
    opacity: .55;
}

/* selected vince sempre */
#afv-overlay text.label.selected,
#afv-overlay text.label2.selected {
    fill: #fff;
    stroke: rgba(0, 0, 0, .35);
    font-weight: 800;
    /* così si legge anche sul rosso */
    font-style: normal;
    opacity: 1;
}



/* =========================
   MODAL (X dentro la card)
========================= */
.afv-modal {
    position: fixed;
    inset: 0;
    z-index: 2147483647;
    display: none;
}

.afv-modal.is-open {
    display: block;
}

.afv-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .45);
}

.afv-modal-card {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);

    width: min(720px, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    overflow: auto;

    background: #fff;
    /* sfondo SEMPRE presente (anche “Caricamento…”) */
    border-radius: 14px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, .35);

    padding-top: 44px;
    /* spazio per la X */
}

.afv-modal-close-x {
    position: absolute;
    top: 10px;
    right: 10px;

    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 10px;
    cursor: pointer;

    background: rgba(255, 255, 255, .95);
    color: #111;
    font-size: 16px;
    line-height: 34px;

    box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
}

.afv-modal-content {
    padding: 12px;
}

/* Se dentro arriva una .card bootstrap: piena larghezza */
.afv-modal-content .card {
    width: 100%;
    border-radius: 14px;
    overflow: hidden;
}

.afv-modal-content .card-footer a {
    margin-right: 12px;
    text-decoration: none;
    font-size: 22px;
}

.afv-loading {
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.afv-loader {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    border: 3px solid rgba(0, 0, 0, .15);
    border-top-color: rgba(0, 0, 0, .7);
    animation: afvspin .8s linear infinite;
}

.afv-loading-text {
    font-size: 14px;
    color: #111;
    -webkit-text-fill-color: #111;
}

@keyframes afvspin {
    to {
        transform: rotate(360deg);
    }
}