:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --ink: #15131f;
    --muted: #6b6878;
    --line: #ececf2;
    --brand: #7c3aed;
    --brand-2: #ec4899;
    --brand-ink: #6d28d9;
    --radius: 16px;
    --shadow: 0 6px 24px rgba(20, 16, 40, .07);
    --shadow-hover: 0 14px 38px rgba(124, 58, 237, .16);
    --grad: linear-gradient(100deg, #7c3aed, #ec4899);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    font-size: 16px;
}

a { color: inherit; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Topbar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255, 255, 255, .8);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--line);
}
.topbar-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: .7rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}
.brand {
    font-weight: 900;
    font-size: 1.35rem;
    letter-spacing: -.02em;
    text-decoration: none;
    background: var(--grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.brand-dot { color: var(--brand-2); -webkit-text-fill-color: var(--brand-2); }
.topnav { display: flex; gap: .35rem; margin-left: auto; }
.topnav-link {
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
    font-size: .95rem;
    padding: .45rem .8rem;
    border-radius: 999px;
    transition: background .15s, color .15s;
}
.topnav-link:hover { color: var(--ink); background: #f1eefe; }
.topnav-link.active { color: var(--brand-ink); background: #f1eafe; }

/* ---------- Main / footer ---------- */
.app-main { flex: 1; width: 100%; max-width: 1120px; margin: 0 auto; padding: 1.25rem 1.25rem 3rem; }
.app-footer {
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: .82rem;
    padding: 1.25rem;
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1.5rem;
    justify-content: center;
}

/* ---------- Hero ---------- */
.hero { padding: 1.75rem 0 1.25rem; }
.hero-eyebrow {
    display: inline-block;
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--brand-ink);
    background: #f1eafe;
    padding: .25rem .6rem;
    border-radius: 999px;
}
.hero h1 { font-size: clamp(1.9rem, 4vw, 2.9rem); font-weight: 900; letter-spacing: -.03em; margin: .6rem 0 .2rem; }
.hero h1 .grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--muted); margin: 0; font-size: 1.05rem; }

/* ---------- Filtri ---------- */
.filters {
    position: sticky;
    top: 56px;
    z-index: 20;
    background: var(--bg);
    padding: .75rem 0 1rem;
    margin-bottom: .25rem;
}
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .6rem; }
.chip {
    text-decoration: none;
    font-weight: 700;
    font-size: .85rem;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--line);
    padding: .4rem .85rem;
    border-radius: 999px;
    transition: all .15s;
}
.chip:hover { border-color: #d9c9fb; color: var(--ink); }
.chip.active { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 4px 14px rgba(124, 58, 237, .3); }
.filter-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filter-row input[type=text], .filter-row select {
    padding: .6rem .85rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    font-size: .95rem;
    color: var(--ink);
}
.filter-row input[type=text] { flex: 1; min-width: 220px; }
.filter-row input[type=text]:focus, .filter-row select:focus { outline: 2px solid #c9b6fb; border-color: transparent; }
.toggle { display: inline-flex; align-items: center; gap: .4rem; color: var(--muted); font-weight: 600; font-size: .9rem; background: var(--surface); border: 1px solid var(--line); padding: .55rem .8rem; border-radius: 12px; cursor: pointer; }
.filter-row button {
    padding: .6rem 1.3rem;
    border: 0;
    border-radius: 12px;
    background: var(--grad);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(124, 58, 237, .3);
}
.filter-row button:hover { filter: brightness(1.05); }
.nearme {
    padding: .6rem 1rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--brand-ink);
    font-weight: 700;
    cursor: pointer;
}
.nearme:hover { border-color: #d9c9fb; }

.count { color: var(--muted); font-size: .88rem; margin: 0 0 1rem; }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 1.1rem; }
.card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: .5rem;
    overflow: hidden;
    transition: transform .15s, box-shadow .15s;
}
.card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--grad); opacity: .9; }
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.card h3 { font-size: 1.08rem; font-weight: 800; letter-spacing: -.01em; margin: .2rem 0 0; line-height: 1.25; }
.card .badge {
    align-self: flex-start;
    background: #f1eafe;
    color: var(--brand-ink);
    font-size: .68rem;
    font-weight: 800;
    padding: .2rem .55rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.card[data-cat="Music"] .badge { background:#e0f2fe; color:#0369a1; }
.card[data-cat="Nightlife"] .badge { background:#fce7f3; color:#be185d; }
.card[data-cat="Theatre"] .badge { background:#fef3c7; color:#b45309; }
.card[data-cat="Exhibition"] .badge,.card[data-cat="Arts"] .badge { background:#ede9fe; color:#6d28d9; }
.card[data-cat="Food"] .badge { background:#dcfce7; color:#15803d; }
.card[data-cat="Sport"] .badge { background:#ffedd5; color:#c2410c; }
.card .meta { display: flex; flex-wrap: wrap; gap: .2rem .8rem; color: var(--muted); font-size: .86rem; margin: 0; }
.card .when { color: var(--ink); font-weight: 700; }
.card .price { font-weight: 800; color: var(--brand-2); margin: 0; min-height: 1em; font-size: .9rem; }
.card .link { margin-top: auto; align-self: flex-start; color: var(--brand-ink); font-weight: 700; text-decoration: none; font-size: .9rem; }
.card .link:hover { text-decoration: underline; }
.card-actions { margin-top: auto; display: flex; flex-wrap: wrap; gap: .45rem; padding-top: .25rem; }
.btn-mini {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: #f1eafe;
    color: var(--brand-ink);
    font-weight: 700;
    font-size: .82rem;
    padding: .35rem .7rem;
    border-radius: 999px;
    text-decoration: none;
    border: 1px solid transparent;
    transition: background .15s, border-color .15s, transform .15s;
}
.btn-mini:hover { background: #e7dbfd; border-color: #d9c9fb; transform: translateY(-1px); }

/* ---------- Map popup links ---------- */
.leaflet-popup-content .popup-links { margin-top: .5rem; display: flex; flex-wrap: wrap; gap: .15rem .5rem; }
.leaflet-popup-content .popup-links a { color: var(--brand-ink); font-weight: 700; text-decoration: none; font-size: .85rem; }
.leaflet-popup-content .popup-links a:hover { text-decoration: underline; }

/* ---------- Notice / map ---------- */
.notice { padding: 1.1rem 1.25rem; background: var(--surface); border: 1px dashed #d7d4e2; border-radius: var(--radius); color: var(--muted); }
.notice.error { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.notice code { background: #f1eefe; padding: .12rem .4rem; border-radius: 6px; font-size: .85em; }
.map { height: 72vh; min-height: 440px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow); }

/* ---------- Blazor error ---------- */
#blazor-error-ui {
    color-scheme: light only;
    background: #1f2937;
    color: #fff;
    bottom: 0; left: 0; width: 100%;
    display: none;
    padding: .7rem 1.25rem;
    position: fixed;
    z-index: 1000;
    box-shadow: 0 -1px 12px rgba(0,0,0,.3);
}
#blazor-error-ui .reload { color: #c4b5fd; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 1rem; top: .6rem; }

@media (max-width: 640px) {
    .topbar-inner { gap: .75rem; }
    .brand { font-size: 1.2rem; }
    .topnav-link { padding: .4rem .55rem; font-size: .88rem; }
    .filters { top: 52px; }
}

/* ===================== THEME TOGGLE ===================== */
.theme-toggle {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    width: 38px; height: 38px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: border-color .15s, transform .15s, background .15s;
}
.theme-toggle:hover { transform: translateY(-1px); border-color: var(--brand); }

/* ===================== DARK MODE ===================== */
[data-theme="dark"] {
    --bg: #0e0d14;
    --surface: #1a1825;
    --ink: #f1eef9;
    --muted: #a39fb4;
    --line: #2b2839;
    --brand: #a78bfa;
    --brand-2: #f472b6;
    --brand-ink: #c4b5fd;
    --shadow: 0 6px 24px rgba(0, 0, 0, .45);
    --shadow-hover: 0 14px 38px rgba(124, 58, 237, .35);
    --grad: linear-gradient(100deg, #a78bfa, #f472b6);
    color-scheme: dark;
}
[data-theme="dark"] .topbar { background: rgba(14, 13, 20, .8); }
[data-theme="dark"] .hero-eyebrow,
[data-theme="dark"] .card .badge,
[data-theme="dark"] .badge { background: rgba(167, 139, 250, .16); }
[data-theme="dark"] .topnav-link:hover { background: rgba(167, 139, 250, .12); }
[data-theme="dark"] .topnav-link.active { background: rgba(167, 139, 250, .18); }
[data-theme="dark"] .btn-mini { background: rgba(167, 139, 250, .16); }
[data-theme="dark"] .btn-mini:hover { background: rgba(167, 139, 250, .28); border-color: var(--brand); }
[data-theme="dark"] .chip:hover { border-color: var(--brand); }
[data-theme="dark"] .nearme:hover { border-color: var(--brand); }
[data-theme="dark"] .notice { border-color: var(--line); }
[data-theme="dark"] .notice.error { background: #2a1416; border-color: #5b2326; color: #fca5a5; }
[data-theme="dark"] .notice code { background: rgba(167, 139, 250, .16); }
[data-theme="dark"] .card[data-cat="Music"] .badge { background: rgba(56, 189, 248, .18); color: #7dd3fc; }
[data-theme="dark"] .card[data-cat="Nightlife"] .badge { background: rgba(244, 114, 182, .18); color: #f9a8d4; }
[data-theme="dark"] .card[data-cat="Theatre"] .badge { background: rgba(251, 191, 36, .16); color: #fcd34d; }
[data-theme="dark"] .card[data-cat="Exhibition"] .badge,
[data-theme="dark"] .card[data-cat="Arts"] .badge { background: rgba(167, 139, 250, .2); color: #ddd6fe; }
[data-theme="dark"] .card[data-cat="Food"] .badge { background: rgba(34, 197, 94, .16); color: #86efac; }
[data-theme="dark"] .card[data-cat="Sport"] .badge { background: rgba(249, 115, 22, .16); color: #fdba74; }
/* CARTO Dark Matter è già scuro: nessun filtro sui tiles. */

/* ===================== CARD IMAGE ===================== */
.card-img {
    display: block;
    width: calc(100% + 2.2rem);      /* sfora i 1.1rem di padding su entrambi i lati → immagine a tutta larghezza */
    margin: -1.1rem -1.1rem .55rem -1.1rem;
    height: 160px;
    background-size: cover;
    background-position: center;
    background-color: var(--line);
}
/* Placeholder per gli eventi senza immagine: header uniforme su tutte le card. */
.card-img--ph {
    background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 22%, var(--surface)), color-mix(in srgb, var(--brand-2) 22%, var(--surface)));
    display: flex; align-items: center; justify-content: center;
    font-size: 2.4rem; opacity: .95;
}
.card h3 { color: var(--ink); }
.card-title-link { text-decoration: none; color: var(--ink); }
.card-title-link:hover { color: var(--brand-ink); }

/* ===================== MAP: pin & popup ===================== */
.fm-pin span {
    display: block;
    width: 100%; height: 100%;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .4);
}
[data-theme="dark"] .fm-pin span { border-color: #1a1825; }
.fm-pin--event span { background: #ec4899; }
.fm-pin--venue span { background: #2563eb; }
.fm-pin--me span {
    background: #22c55e;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, .6);
    animation: fmPulse 2s infinite;
}
@keyframes fmPulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .55); }
    70% { box-shadow: 0 0 0 12px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
.leaflet-popup-content-wrapper {
    border-radius: 12px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--surface); }
.fm-popup strong { font-weight: 800; font-size: .98rem; }
.fm-popup-cat { color: var(--muted); font-size: .82rem; margin-top: .1rem; }

/* Cluster: palette brand coerente (no verde/giallo di default) + conteggio sempre leggibile. */
.marker-cluster { background: rgba(124, 58, 237, .22) !important; }
.marker-cluster div {
    background: var(--brand) !important;
    color: #fff !important;
    font-weight: 800;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}
.marker-cluster span { color: #fff !important; }
.marker-cluster-large { background: rgba(236, 72, 153, .22) !important; }
.marker-cluster-large div { background: var(--brand-2) !important; }

/* ===================== EVENT DETAIL ===================== */
.back-link { display: inline-block; margin: .3rem 0 1rem; color: var(--brand-ink); text-decoration: none; font-weight: 700; font-size: .9rem; }
.back-link:hover { text-decoration: underline; }
.detail {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.4rem;
    box-shadow: var(--shadow);
    max-width: 820px;
}
.detail-hero {
    margin: -1.4rem -1.4rem 1.1rem;
    height: clamp(180px, 34vw, 320px);
    background-size: cover;
    background-position: center;
    background-color: var(--line);
    border-radius: var(--radius) var(--radius) 0 0;
}
.detail-title { font-size: clamp(1.5rem, 3.5vw, 2.2rem); font-weight: 900; letter-spacing: -.02em; margin: .5rem 0 .6rem; line-height: 1.15; }
.detail-meta { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; color: var(--muted); font-size: .95rem; margin-bottom: 1.1rem; align-items: center; }
.detail-meta .when { color: var(--ink); font-weight: 700; }
.detail-meta .price { color: var(--brand-2); font-weight: 800; }
.detail-actions { display: flex; flex-wrap: wrap; gap: .55rem; margin-bottom: 1.2rem; }
.btn-primary {
    display: inline-flex; align-items: center; gap: .4rem;
    background: var(--grad); color: #fff; font-weight: 800;
    padding: .6rem 1.2rem; border-radius: 999px; text-decoration: none;
    box-shadow: 0 4px 14px rgba(124, 58, 237, .3);
}
.btn-primary:hover { filter: brightness(1.05); }
.detail-desc { color: var(--ink); line-height: 1.7; white-space: pre-line; margin: 0 0 1.2rem; }
.detail-map { height: 320px; min-height: 0; margin-bottom: 1rem; }
.source-note { color: var(--muted); font-size: .82rem; margin: 0; }
.source-note a { color: var(--brand-ink); text-decoration: none; }

/* ===================== DIAGNOSTICA ===================== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 1.2rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .25rem;
}
.stat-n { font-size: 1.9rem; font-weight: 900; letter-spacing: -.02em; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat-l { color: var(--muted); font-size: .85rem; }
.sec-title { font-size: 1.1rem; font-weight: 800; margin: 1.5rem 0 .8rem; }

/* ===================== PAGER ===================== */
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin: 1.6rem 0 .5rem; }
.pager-info { color: var(--muted); font-weight: 700; font-size: .9rem; }

/* ===================== MAP LEGEND ===================== */
.map-legend { display: flex; flex-wrap: wrap; gap: .35rem .9rem; margin: 0 0 .7rem; }
.legend-item { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .8rem; font-weight: 600; }
.legend-dot { width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }

/* ===================== LOADER OVERLAY ===================== */
.loader-overlay {
    position: fixed; inset: 0; z-index: 200;
    display: flex; align-items: center; justify-content: center;
    background: color-mix(in srgb, var(--bg) 70%, transparent);
    backdrop-filter: blur(3px);
}
.loader-card {
    display: flex; flex-direction: column; align-items: center; gap: .9rem;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 1.6rem 2rem; box-shadow: var(--shadow-hover);
}
.loader-text { color: var(--muted); font-weight: 700; font-size: .9rem; }
.loader-spinner {
    width: 34px; height: 34px; border-radius: 50%;
    border: 3px solid var(--line); border-top-color: var(--brand);
    animation: fmSpin .8s linear infinite;
}
@keyframes fmSpin { to { transform: rotate(360deg); } }

/* ===================== AUTH / ACCOUNT ===================== */
.auth-form {
    max-width: 420px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: .9rem;
}
.auth-form label { display: flex; flex-direction: column; gap: .3rem; font-weight: 700; font-size: .9rem; color: var(--ink); }
.auth-form input[type=text], .auth-form input[type=email], .auth-form input[type=password] {
    padding: .65rem .85rem; border: 1px solid var(--line); border-radius: 12px;
    background: var(--bg); color: var(--ink); font-size: .95rem; font-weight: 500;
}
.auth-form input:focus { outline: 2px solid var(--brand); border-color: transparent; }
.auth-form .consent { flex-direction: row; align-items: flex-start; gap: .5rem; font-weight: 500; color: var(--muted); font-size: .85rem; }
.auth-form .btn-primary { justify-content: center; border: 0; cursor: pointer; font-size: 1rem; }
.auth-alt { color: var(--muted); font-size: .88rem; margin: 0; text-align: center; }
.auth-alt a { color: var(--brand-ink); font-weight: 700; text-decoration: none; }

.inline-form { display: inline; margin: 0; }
.logout-btn { border: 0; background: none; cursor: pointer; font: inherit; }

.save-bar { display: flex; flex-wrap: wrap; gap: .55rem; align-items: center; margin-bottom: 1.2rem; }
.save-bar .btn-mini { border: 0; cursor: pointer; font: inherit; }
.saved-tag { font-weight: 800; color: var(--brand-ink); }
.save-badge { align-self: flex-start; background: rgba(34, 197, 94, .15); color: #15803d; margin-left: .4rem; }
[data-theme="dark"] .save-badge { background: rgba(34, 197, 94, .2); color: #86efac; }
