html, body {
    margin: 0;
    min-height: 100%;
    font-family: system-ui, sans-serif;
    background: #f2f2f5;
    color: #1a1a1a;
}

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

.error {
    color: #b91c1c;
    font-size: 13px;
}

.success {
    color: #15803d;
    font-size: 13px;
}

/* Card di login/registrazione, mobile-first */
.foto-card {
    box-sizing: border-box;
    max-width: 380px;
    margin: 40px auto;
    background: #fff;
    padding: 28px 24px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.foto-card h1 {
    font-size: 20px;
    margin: 0;
}

.foto-card label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 14px;
}

.foto-card input {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 16px;
    box-sizing: border-box;
    width: 100%;
}

.foto-card button {
    padding: 12px;
    min-height: 48px;
    border: none;
    border-radius: 6px;
    background: #2563eb;
    color: #fff;
    font-size: 15px;
    cursor: pointer;
}

.foto-card button:hover {
    background: #1d4ed8;
}

.auth-switch {
    display: flex;
    gap: 8px;
}

.auth-switch a {
    flex: 1;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #2563eb;
    border-radius: 10px;
    color: #2563eb;
    font-weight: 600;
    font-size: 15px;
    text-decoration: none;
    box-sizing: border-box;
}

.auth-switch a[aria-current="page"] {
    background: #2563eb;
    color: #fff;
}

.password-field {
    position: relative;
    display: flex;
}

.password-field input {
    flex: 1;
    min-width: 0;
    padding-right: 48px;
}

/* Specificità alta per non ereditare lo stile dei pulsanti .foto-card button */
.foto-card .toggle-password {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.foto-card .toggle-password:hover,
.foto-card .toggle-password:focus-visible {
    background: #f1f5f9;
    color: #2563eb;
}

.foto-card .toggle-password svg {
    width: 22px;
    height: 22px;
}

.foto-card .toggle-password .icon-hide {
    display: none;
}

.foto-card .toggle-password[aria-pressed="true"] .icon-show {
    display: none;
}

.foto-card .toggle-password[aria-pressed="true"] .icon-hide {
    display: block;
}

/* Galleria: barra superiore + filtri (sticky insieme) */
body.foto-gallery-page {
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
}

.foto-sticky {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(242, 242, 245, 0.92);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    padding-top: env(safe-area-inset-top);
}

.foto-topbar {
    display: grid;
    grid-template-columns: 64px 1fr 64px;
    align-items: center;
    padding: 8px 8px 0;
}

.topbar-title {
    text-align: center;
    min-width: 0;
}

.topbar-title h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.topbar-title p {
    margin: 2px 0 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #555;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.avatar {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #2563eb;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.topbar-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 48px;
    border-radius: 10px;
    color: #374151;
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
}

.topbar-icon svg {
    width: 22px;
    height: 22px;
}

.topbar-icon:active {
    background: rgba(0, 0, 0, 0.06);
}

.topbar-icon--logout {
    color: #b91c1c;
}

/* Barra caricamento fissa in basso, a portata di pollice */
.upload-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.95);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
}

.upload-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    max-width: 420px;
    min-height: 54px;
    box-sizing: border-box;
    background: #2563eb;
    color: #fff;
    border-radius: 14px;
    font-weight: 700;
    font-size: 17px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
    -webkit-tap-highlight-color: transparent;
}

.upload-button svg {
    width: 24px;
    height: 24px;
}

.upload-button:hover {
    background: #1d4ed8;
}

.upload-button:active {
    transform: scale(0.98);
}

.upload-hint {
    margin: 0;
    font-size: 12px;
    color: #6b7280;
    text-align: center;
}

.upload-progress {
    font-size: 13px;
    font-weight: 600;
    color: #1e3a8a;
    background: #eff6ff;
    border-radius: 999px;
    padding: 6px 14px;
}

.upload-progress:empty {
    display: none;
}

.filter-bar {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    background: transparent;
    padding: 10px 16px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.filter-bar::-webkit-scrollbar {
    display: none;
}

.chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid #ccc;
    background: #fff;
    color: #333;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    scroll-snap-align: start;
}

.chip[aria-pressed="true"] {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.chip-count {
    font-size: 11px;
    opacity: 0.8;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 12px 16px 24px;
}

@media (min-width: 640px) {
    .gallery-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 960px) {
    .gallery-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

.photo-tile {
    margin: 0;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.photo-tile img {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    cursor: zoom-in;
}

.photo-tile figcaption {
    padding: 6px 8px;
    font-size: 12px;
    color: #444;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.delete-photo {
    border: none;
    background: none;
    color: #b91c1c;
    font-size: 11px;
    cursor: pointer;
    padding: 0;
}

.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.lightbox[hidden] {
    display: none;
}

.lightbox img {
    max-width: 92vw;
    max-height: 92vh;
    object-fit: contain;
}

#lightbox-close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    color: #fff;
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
}

/* Elimina più facile da toccare sulle proprie foto */
.photo-tile figcaption {
    min-height: 36px;
    box-sizing: border-box;
}

.delete-photo {
    font-size: 13px !important;
    font-weight: 600;
    padding: 6px 8px !important;
    margin: -6px -4px -6px 0;
    border-radius: 6px;
}

.delete-photo:active {
    background: #fee2e2;
}

/* Link "Torna alla mappa" nelle pagine di accesso */
.back-to-map {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 44px;
    margin: -12px 0 -4px -10px;
    padding: 0 12px 0 6px;
    border-radius: 999px;
    color: #2563eb;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.back-to-map svg {
    width: 20px;
    height: 20px;
}

.back-to-map:hover,
.back-to-map:active {
    background: #eff6ff;
}

/* ===== Lightbox con navigazione ===== */
.lightbox {
    flex-direction: column;
    background: rgba(0, 0, 0, 0.95);
    touch-action: pan-y pinch-zoom;
}

.lightbox-topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px 16px;
    color: #fff;
    background: linear-gradient(rgba(0, 0, 0, 0.6), transparent);
}

.lightbox-counter {
    font-size: 14px;
    font-weight: 600;
    opacity: 0.9;
}

.lightbox-caption {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lightbox #lightbox-close {
    position: static;
    width: 44px;
    height: 44px;
    font-size: 34px;
}

.lightbox-stage {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox img {
    max-width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
    object-fit: contain;
    transition: opacity 0.15s;
    -webkit-user-select: none;
    user-select: none;
}

.lightbox img.is-loading {
    opacity: 0.4;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

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

.lightbox-nav svg {
    width: 26px;
    height: 26px;
}

.lightbox-nav:active {
    background: rgba(255, 255, 255, 0.35);
}

.lightbox-nav--prev {
    left: 10px;
}

.lightbox-nav--next {
    right: 10px;
}
