:root {
    --ps-bg: #f4f6f9;
    --ps-sidebar: #16192c;
    --ps-sidebar-hover: #21253f;
    --ps-accent: #6f5af8;
    --ps-accent-dark: #5842d6;
    --ps-text-dark: #1c1e2b;
    --ps-text-muted: #6b7280;
    --ps-border: #e5e7eb;
    --ps-success: #12b76a;
    --ps-success-bg: #e6f9f0;
    --ps-warning: #f79009;
    --ps-warning-bg: #fef3e2;
    --ps-danger: #f04438;
    --ps-danger-bg: #fde8e6;
    --ps-white: #ffffff;
    --ps-radius: 14px;
    --ps-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
    --ps-shadow-md: 0 4px 8px rgba(16, 24, 40, .06), 0 2px 4px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--ps-bg);
    color: var(--ps-text-dark);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ============ LAYOUT ============ */
.ps-app {
    display: flex;
    min-height: 100vh;
}

.ps-sidebar {
    width: 260px;
    background: var(--ps-sidebar);
    color: #cbd0e6;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    transition: transform .2s ease;
}

.ps-sidebar__brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 24px 22px;
    font-weight: 700;
    font-size: 17px;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.06);
}

.ps-sidebar__close {
    display: block;
    background: none;
    border: none;
    color: #cbd0e6;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
}
.ps-sidebar__close:hover { color: #fff; }

.ps-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 11, 20, .5);
    z-index: 35;
}

.ps-sidebar__brand .ps-logo-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: linear-gradient(135deg, var(--ps-accent), #a78bfa);
    flex-shrink: 0;
}

.ps-sidebar__nav {
    flex: 1;
    padding: 18px 12px;
    overflow-y: auto;
}

.ps-nav-section {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #565c7d;
    margin: 18px 10px 8px;
    font-weight: 600;
}
.ps-nav-section:first-child { margin-top: 4px; }

.ps-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: #cbd0e6;
    font-weight: 500;
    margin-bottom: 2px;
    transition: background .15s ease, color .15s ease;
}

.ps-nav-link:hover {
    background: var(--ps-sidebar-hover);
    color: #fff;
}

.ps-nav-link.active {
    background: var(--ps-accent);
    color: #fff;
}

.ps-nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.ps-sidebar__footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.06);
    font-size: 12px;
    color: #565c7d;
}

.ps-main {
    margin-left: 260px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left .2s ease;
}

/* Toggle sidebar: due modalità isolate per breakpoint, mai attive insieme
   (le media query si escludono a vicenda per larghezza, zero conflitti di
   specificità), e nessuna dipende da JS per il rendering iniziale corretto:
   - Desktop (>960px): sidebar aperta di default, .closed la nasconde
   - Mobile (≤960px): sidebar chiusa di default, .open la mostra */
@media (min-width: 961px) {
    .ps-sidebar.closed { transform: translateX(-100%); }
    .ps-main.sidebar-closed { margin-left: 0; }
}

.ps-topbar {
    height: 68px;
    background: var(--ps-white);
    border-bottom: 1px solid var(--ps-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 30;
}

.ps-topbar__title { font-size: 18px; font-weight: 700; }
.ps-topbar__subtitle { font-size: 12.5px; color: var(--ps-text-muted); margin-top: 2px; }

.ps-user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ps-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--ps-accent), #a78bfa);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
}

.ps-role-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 600;
}
.ps-role-badge--super_admin { background: #fdeeea; color: #c4320a; }
.ps-role-badge--admin { background: #e6f0ff; color: #1849a9; }
.ps-role-badge--operatore { background: #eef2ff; color: #4338ca; }

.ps-content {
    padding: 26px 28px 60px;
}

.ps-mobile-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    color: var(--ps-text-dark);
}
.ps-mobile-toggle:hover { background: #f0f1f5; }

/* ============ CARDS ============ */
.ps-card {
    background: var(--ps-white);
    border-radius: var(--ps-radius);
    border: 1px solid var(--ps-border);
    box-shadow: var(--ps-shadow);
}

.ps-card__header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--ps-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.ps-card__title { font-size: 15.5px; font-weight: 700; }
.ps-card__body { padding: 22px; }

.ps-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
    margin-bottom: 22px;
}

.ps-stat-card {
    background: var(--ps-white);
    border: 1px solid var(--ps-border);
    border-radius: var(--ps-radius);
    padding: 20px 22px;
    box-shadow: var(--ps-shadow);
}

.ps-stat-card__label {
    font-size: 12.5px;
    color: var(--ps-text-muted);
    font-weight: 600;
    margin-bottom: 8px;
}

.ps-stat-card__value { font-size: 26px; font-weight: 800; }
.ps-stat-card__value.up { color: var(--ps-success); }
.ps-stat-card__hint { font-size: 12px; color: var(--ps-text-muted); margin-top: 4px; }

/* ============ FORMS ============ */
.ps-form-group { margin-bottom: 16px; }
.ps-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ps-text-dark); }

.ps-input, .ps-select, textarea.ps-input {
    width: 100%;
    padding: 10px 13px;
    border-radius: 10px;
    border: 1px solid var(--ps-border);
    font-size: 14px;
    font-family: inherit;
    background: var(--ps-white);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.ps-input:focus, .ps-select:focus {
    outline: none;
    border-color: var(--ps-accent);
    box-shadow: 0 0 0 3px rgba(111, 90, 248, .15);
}
.ps-input[readonly], .ps-input:disabled { background: #f8f9fb; color: var(--ps-text-muted); }

.ps-row { display: flex; gap: 16px; flex-wrap: wrap; }
.ps-row > * { flex: 1; min-width: 180px; }

/* ============ BUTTONS ============ */
.ps-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 13.5px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all .15s ease;
}
.ps-btn-primary { background: var(--ps-accent); color: #fff; }
.ps-btn-primary:hover { background: var(--ps-accent-dark); }
.ps-btn-secondary { background: var(--ps-white); color: var(--ps-text-dark); border-color: var(--ps-border); }
.ps-btn-secondary:hover { background: #f8f9fb; }
.ps-btn-danger { background: var(--ps-danger-bg); color: var(--ps-danger); }
.ps-btn-danger:hover { background: #fbdad7; }
.ps-btn-sm { padding: 6px 12px; font-size: 12.5px; }
.ps-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ============ TABLE ============ */
.ps-table-wrap { overflow-x: auto; }
.ps-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.ps-table th {
    text-align: left;
    padding: 12px 14px;
    background: #fafbfc;
    color: var(--ps-text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 1px solid var(--ps-border);
    white-space: nowrap;
}
.ps-table td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--ps-border);
    vertical-align: middle;
    white-space: nowrap;
}
.ps-table tbody tr:hover { background: #fafaff; }
.ps-table tbody tr:last-child td { border-bottom: none; }

/* ============ BADGES ============ */
.ps-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.ps-badge--available { background: var(--ps-success-bg); color: var(--ps-success); }
.ps-badge--sold { background: var(--ps-danger-bg); color: var(--ps-danger); }
.ps-badge--reserved { background: var(--ps-warning-bg); color: var(--ps-warning); }

/* ============ ALERTS / FLASH ============ */
.ps-alert {
    padding: 13px 16px;
    border-radius: 10px;
    font-size: 13.5px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.ps-alert--success { background: var(--ps-success-bg); color: #067a45; }
.ps-alert--danger { background: var(--ps-danger-bg); color: #b42318; }
.ps-alert--warning { background: var(--ps-warning-bg); color: #93590a; }
.ps-alert--info { background: #eef2ff; color: #3730a3; }

/* ============ LOGIN ============ */
.ps-auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 20% 20%, #201f3d, #101124 60%);
    padding: 20px;
}
.ps-auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--ps-white);
    border-radius: 18px;
    padding: 36px 32px;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.ps-auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 19px;
    margin-bottom: 6px;
}
.ps-auth-logo {
    max-height: 90px;
    width: auto;
    display: block;
    margin-bottom: 14px;
}
.ps-auth-sub { color: var(--ps-text-muted); font-size: 13.5px; margin-bottom: 26px; }
.ps-auth-card .ps-btn { width: 100%; justify-content: center; }
.ps-auth-links { margin-top: 18px; font-size: 13px; text-align: center; color: var(--ps-text-muted); }
.ps-auth-links a { color: var(--ps-accent); font-weight: 600; }

/* ============ MODAL ============ */
.ps-modal-backdrop {
    position: fixed; inset: 0; background: rgba(16,18,32,.5);
    display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.ps-modal-backdrop.open { display: flex; }
.ps-modal {
    background: #fff; border-radius: 16px; width: 100%; max-width: 480px;
    max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.ps-modal__header { padding: 20px 24px; border-bottom: 1px solid var(--ps-border); display: flex; justify-content: space-between; align-items: center; }
.ps-modal__title { font-weight: 700; font-size: 16px; }
.ps-modal__close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--ps-text-muted); }
.ps-modal__body { padding: 22px 24px; }
.ps-modal__footer { padding: 16px 24px; border-top: 1px solid var(--ps-border); display: flex; justify-content: flex-end; gap: 10px; }

/* ============ UTILITIES ============ */
.ps-flex { display: flex; align-items: center; }
.ps-gap-8 { gap: 8px; }
.ps-gap-12 { gap: 12px; }
.ps-mb-0 { margin-bottom: 0; }
.ps-text-muted { color: var(--ps-text-muted); }
.ps-text-right { text-align: right; }
.ps-w-full { width: 100%; }
.ps-mt-24 { margin-top: 24px; }
.ps-empty-state { text-align: center; padding: 60px 20px; color: var(--ps-text-muted); }

@media (max-width: 960px) {
    .ps-sidebar { transform: translateX(-100%); }
    .ps-sidebar.open { transform: translateX(0); }
    .ps-main { margin-left: 0; }
}

/* Overlay scuro dietro la sidebar: ha senso solo quando la sidebar si
   sovrappone al contenuto invece di spingerlo, cioè sotto i 960px. */
@media (max-width: 960px) {
    .ps-sidebar-overlay.open { display: block; }
}
