*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f0f1a;
    --surface: #1a1a2e;
    --border: #2d2d4e;
    --text: #e8e8f0;
    --text-muted: #8888aa;
    --primary: #6366f1;
    --primary-hover: #4f52d4;
    --danger: #ef4444;
    --success: #22c55e;
    --seat-available: #4b5563;
    --seat-mine: #6366f1;
    --seat-reserved: #dc2626;
    --seat-booked: #374151;
    --timer-warning: #f59e0b;
}

/* ── Tema chiaro per il front-end pubblico ─────────────────────────────── */
.theme-light {
    --bg: #f0f0ff;
    --surface: #fafaff;
    --border: #d0d0ee;
    --text: #1e1e3a;
    --text-muted: #5a5a8a;
    --primary: #5254d4;
    --primary-hover: #3f41b8;
    --danger: #dc2626;
    --success: #16a34a;
    --seat-available: #94a3b8;   /* grigio-blu neutro: "libero, non selezionato" */
    --seat-mine: #4f46e5;        /* viola brillante: "selezionato da me" */
    --seat-reserved: #dc2626;
    --seat-booked: #cbd5e1;
    --timer-warning: #d97706;
}
.theme-light body { background: var(--bg); }
.theme-light .page-header { background: var(--surface); border-color: var(--border); }
.theme-light .sidebar { background: var(--surface); border-color: var(--border); }
.theme-light .timer-box { background: #ebebff; border-color: var(--border); }
.theme-light .card { background: var(--surface); border-color: var(--border); }
.theme-light .form-group input,
.theme-light .form-group select,
.theme-light .form-group textarea { background: #ffffff; border-color: var(--border); color: var(--text); }
.theme-light .tier-option label { border-color: var(--border); }
.theme-light .tier-option input:checked + label { background: #6366f110; }
.theme-light .btn-outline { border-color: var(--border); color: var(--text-muted); }
.theme-light .btn-outline:hover { border-color: var(--text-muted); color: var(--text); }
.theme-light .zoom-btn { background: rgba(240,240,255,.88); border-color: var(--border); color: var(--text); }
.theme-light .zoom-btn:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
/* Stato disponibile: grigio neutro con testo scuro */
.theme-light .seat-available { background: var(--seat-available); border-color: #64748b; color: #fff; }
.theme-light .seat-available:hover { background: #64748b; transform: translate(-50%,-50%) scale(1.15); }
/* Stato selezionato: viola brillante con alone */
.theme-light .seat-mine { background: var(--seat-mine); border-color: #a5b4fc; color: #fff; box-shadow: 0 0 0 2px #4f46e540, 0 0 8px #4f46e560; }
.theme-light .seat-mine:hover { transform: translate(-50%,-50%) scale(1.15); }
/* Stato occupato: grigio chiaro quasi invisibile */
.theme-light .seat-booked { background: var(--seat-booked); border-color: #e2e8f0; color: #94a3b8; opacity: .7; }
.theme-light ::-webkit-scrollbar-thumb { background: var(--border); }

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* Layout */
.page-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.page-header h1 { font-size: 1.2rem; font-weight: 600; }
.page-header .subtitle { font-size: 0.85rem; color: var(--text-muted); }

.main-layout {
    display: flex;
    height: calc(100vh - 60px);
    overflow: hidden;
}

/* Seat map area */
.map-area {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.seat-container {
    position: relative;
    display: block;
    width: 100%;
    cursor: default;
    user-select: none;
    container-type: inline-size;
}
.seat-container img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 8px;
}
.seat-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* Seats — dimensione % del container → scala con la mappa e con lo zoom */
.seat {
    position: absolute;
    transform: translate(-50%, -50%);
    width: calc(var(--sz, 1) * var(--base-sz, 2.5%));
    aspect-ratio: 1;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(4px, 0.65cqw, 8px);
    font-weight: 700;
    line-height: 1;
    text-align: center;
    transition: transform 0.1s, opacity 0.1s;
    pointer-events: auto;
    border: 2px solid transparent;
    color: #fff;
    overflow: hidden;
}
.seat-available {
    background: var(--seat-available);
    cursor: pointer;
    border-color: #6b7280;
}
.seat-available:hover {
    background: #6b7280;
    transform: translate(-50%, -50%) scale(1.2);
}
.seat-mine {
    background: var(--seat-mine);
    cursor: pointer;
    border-color: #a5b4fc;
    box-shadow: 0 0 8px #6366f180;
}
.seat-mine:hover {
    transform: translate(-50%, -50%) scale(1.15);
}
.seat-reserved {
    background: var(--seat-reserved);
    cursor: not-allowed;
    opacity: 0.7;
}
.seat-booked {
    background: var(--seat-booked);
    cursor: not-allowed;
    opacity: 0.5;
    border-color: #4b5563;
}

/* Sidebar */
.sidebar {
    width: 300px;
    min-width: 260px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.sidebar-section {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

/* Timer */
.timer-box {
    background: var(--bg);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    text-align: center;
    border: 1px solid var(--border);
}
.timer-value {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--success);
    line-height: 1;
}
.timer-value.warning { color: var(--timer-warning); }
.timer-value.expired { color: var(--danger); }
.timer-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }

/* Selected seats list */
.seats-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 1.25rem;
}
.seat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}
.seat-item:last-child { border-bottom: none; }
.seat-item .seat-name { font-weight: 600; }
.seat-item .seat-zone { color: var(--text-muted); font-size: 0.75rem; }
.seat-remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    line-height: 1;
}
.seat-remove:hover { background: #ef444420; }

.empty-selection {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    padding: 1rem 0;
}

/* Legend */
.legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border);
    width: 100%;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.legend-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Proceed button */
.proceed-area {
    padding: 1rem 1.25rem;
}
.btn-proceed {
    width: 100%;
    padding: 0.85rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-proceed:hover:not(:disabled) { background: var(--primary-hover); }
.btn-proceed:disabled { opacity: 0.4; cursor: not-allowed; }

/* Booking form page */
.booking-page {
    max-width: 580px;
    margin: 2rem auto;
    padding: 0 1rem;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.75rem;
    margin-bottom: 1.25rem;
}
.card h2 { font-size: 1.1rem; margin-bottom: 1.25rem; }

.summary-item {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
}
.summary-item:last-child { border-bottom: none; }
.summary-item .label { color: var(--text-muted); }
.summary-total {
    display: flex;
    justify-content: space-between;
    font-size: 1.15rem;
    font-weight: 700;
    padding-top: 0.75rem;
    margin-top: 0.5rem;
    border-top: 2px solid var(--border);
}

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.65rem 0.85rem;
    color: var(--text);
    font-size: 0.95rem;
    transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}
.form-group textarea { resize: vertical; min-height: 80px; }

/* Tier selector */
.tier-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.75rem;
    margin-top: 0.25rem;
}
.tier-option {
    position: relative;
}
.tier-option input { display: none; }
.tier-option label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.85rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    text-align: center;
}
.tier-option label:hover { border-color: var(--primary); }
.tier-option input:checked + label {
    border-color: var(--primary);
    background: #6366f115;
}
.tier-name { font-size: 0.9rem; font-weight: 600; }
.tier-price { font-size: 1.1rem; font-weight: 700; color: var(--primary); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.15s, opacity 0.15s;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.btn-outline:hover { border-color: var(--text-muted); color: var(--text); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-full { width: 100%; }

/* Error / notice */
.alert {
    padding: 0.85rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}
.alert-error   { background: #ef444420; border: 1px solid #ef444450; color: #fca5a5; }
.alert-success { background: #22c55e20; border: 1px solid #22c55e50; color: #86efac; }
.alert-info    { background: #6366f115; border: 1px solid #6366f140; color: #a5b4fc; }

/* Confirmation page */
.confirm-icon {
    width: 64px;
    height: 64px;
    background: #22c55e20;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin: 0 auto 1.25rem;
}
.booking-ref {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--primary);
    text-align: center;
    margin: 0.5rem 0 1rem;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── SVG seat map ───────────────────────────────────────────────────────── */
svg#seat-container {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 8px;
}

#seat-overlay .seat { cursor: default; }

#seat-overlay .seat circle {
    stroke-width: 2;
    transition: transform 0.1s;
    transform-box: fill-box;
    transform-origin: center;
}

#seat-overlay .seat text {
    fill: #fff;
    font-weight: 700;
    pointer-events: none;
    font-family: system-ui, -apple-system, sans-serif;
}

#seat-overlay .seat-available { cursor: pointer; }
#seat-overlay .seat-available circle { fill: var(--seat-available); stroke: #6b7280; }
#seat-overlay .seat-available:hover circle { fill: #6b7280; transform: scale(1.25); }

#seat-overlay .seat-mine { cursor: pointer; }
#seat-overlay .seat-mine circle {
    fill: var(--seat-mine);
    stroke: #a5b4fc;
    filter: drop-shadow(0 0 5px #6366f180);
}
#seat-overlay .seat-mine:hover circle { transform: scale(1.15); }

#seat-overlay .seat-reserved { cursor: not-allowed; }
#seat-overlay .seat-reserved circle { fill: var(--seat-reserved); stroke: none; opacity: 0.7; }

#seat-overlay .seat-booked { cursor: not-allowed; }
#seat-overlay .seat-booked circle { fill: var(--seat-booked); stroke: #4b5563; opacity: 0.5; }

/* ── Zoom wrapper ───────────────────────────────────────────────────────── */
#map-zoom-wrap {
    position: relative;
    overflow: hidden;
    display: block;
    width: 100%;
    flex: 1;
    min-height: 0;
    cursor: grab;
    touch-action: none;
    border-radius: 8px;
    -webkit-user-select: none;
    user-select: none;
}
#map-zoom-wrap:active { cursor: grabbing; }
#seat-container { transform-origin: 0 0; will-change: transform; display: block; width: 100%; }

.zoom-controls {
    display: flex;
    flex-direction: row;
    gap: .25rem;
    margin-left: auto;
}
.zoom-btn {
    width: 30px; height: 30px;
    background: rgba(15,15,26,.82);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 1.15rem;
    font-weight: 700;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(6px);
    transition: background .15s;
    line-height: 1;
    padding: 0;
}
.zoom-btn:hover { background: var(--primary); border-color: var(--primary); }

@keyframes fadeout { to { opacity: 0; } }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
    .page-header { padding: .75rem 1rem; gap: .5rem; }
    .page-header h1 { font-size: 1rem; }

    .main-layout { flex-direction: column; height: auto; overflow: visible; }
    .map-area { padding: .75rem; overflow: visible; min-height: unset; }
    #map-zoom-wrap { flex: none; min-height: unset; }

    #map-zoom-wrap { width: 100%; }
    #seat-container { width: 100%; }
    #seat-container img { width: 100%; height: auto; }

    .sidebar { width: 100%; min-width: unset; border-left: none; border-top: 1px solid var(--border); }
    .sidebar-section { padding: .75rem 1rem; }
    .seats-list { max-height: 150px; }

    .proceed-area {
        position: sticky;
        bottom: 0;
        background: var(--surface);
        border-top: 1px solid var(--border);
        z-index: 10;
    }

    .booking-page { margin: 1rem auto; }
    .card { padding: 1.25rem; }
    .tier-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}
