/*
 * PROTRACKER — Layout principale
 * Sidebar fissa a sinistra + Topbar fissa in alto + Area contenuto scrollabile
 */

/* ── App shell ────────────────────────────────────────────────────────────── */
.app-shell {
    --main-inline-start: var(--sidebar-width);
    display: flex;
    min-height: 100vh;
}

.app-shell.sidebar-collapsed {
    --main-inline-start: var(--sidebar-collapsed-width);
}

/* #ANCORA-NAVIGAZIONE-CON-MODULI: sfondo e finestra occupano solo la pagina. */
.app-shell [data-pt-browser-form] .modal-overlay:not(.modal .modal-overlay) {
    inset-block-start: var(--topbar-height);
    inset-inline-start: var(--main-inline-start);
    padding: clamp(var(--space-2), 2vmin, var(--space-4));
    overflow: auto;
    align-items: safe center;
    justify-content: safe center;
    transition: inset-inline-start var(--transition-slow);
}

.app-shell [data-pt-browser-form] .modal-overlay:not(.modal .modal-overlay) > .modal {
    flex-shrink: 1;
    min-inline-size: 0;
    max-block-size: 100%;
}

.app-shell [data-pt-browser-form] .modal-overlay:not(.modal .modal-overlay) > .modal > .modal-footer {
    flex-wrap: wrap;
}

.app-shell [data-pt-browser-form] dialog.casino-steps__modal {
    inset-block-start: var(--topbar-height);
    inset-inline-start: var(--main-inline-start);
    inline-size: calc(100dvw - var(--main-inline-start) - 16px);
    max-block-size: calc(100dvh - var(--topbar-height) - 16px);
}

/* ── Wrapper destra: topbar + content ────────────────────────────────────── */
.main-wrapper {
    margin-inline-start: var(--main-inline-start);
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;      /* altezza fissa: non sfora, lo scroll sta dentro .content */
    overflow: hidden;   /* blocca qualsiasi scroll qui */
    transition: margin-inline-start var(--transition-slow);
    min-width: 0;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--main-inline-start);
    height: 100vh;
    background: var(--color-sidebar-bg);
    border-right: 1px solid var(--color-sidebar-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: var(--z-sticky);
    transition: width var(--transition-slow);
}

/* ── Sidebar: Logo area ───────────────────────────────────────────────────── */
.sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    height: var(--topbar-height);
    border-bottom: 1px solid var(--color-sidebar-border);
    flex-shrink: 0;
    text-decoration: none;
}

.sidebar__brand-icon {
    width: 32px;
    height: 32px;
    background: transparent;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: none;
}

/* #ANCORA-PT-BRAND-ICON: asset vettoriale usato anche come favicon. */
.sidebar__brand-logo {
    width: 32px;
    height: 32px;
    display: block;
}

.sidebar__brand-text {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity var(--transition-slow), width var(--transition-slow);
}

.sidebar__brand-name {
    font-size: var(--text-base);
    font-weight: var(--font-bold);
    color: var(--color-text-primary);
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.sidebar__brand-version {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    font-family: var(--font-mono);
}

.app-shell.sidebar-collapsed .sidebar__brand-text {
    opacity: 0;
    width: 0;
    pointer-events: none;
}

/* ── Sidebar: Navigation ──────────────────────────────────────────────────── */
.sidebar__nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-3) 0;
}

.sidebar__section {
    margin-bottom: var(--space-2);
}

.sidebar__section-label {
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: var(--space-2) var(--space-5);
    margin-bottom: var(--space-1);
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--transition-slow);
}

.app-shell.sidebar-collapsed .sidebar__section-label {
    opacity: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-5);
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    border-radius: 0;
    position: relative;
    transition: color var(--transition-fast), background var(--transition-fast);
    white-space: nowrap;
    min-height: 40px;
    cursor: pointer;
    border: none;
    width: 100%;
    background: none;
    text-align: left;
}

.nav-item:hover {
    color: var(--color-text-primary);
    background: var(--color-nav-item-hover);
}

/* #ANCORA-PAGINA-ATTIVA-SIDEBAR: NavLink aggiunge "active" direttamente all'anchor. */
.nav-item.active {
    color: var(--color-accent);
    background: var(--color-nav-item-active);
    font-weight: var(--font-semibold);
    box-shadow: inset 0 0 0 1px rgba(79, 110, 247, 0.12);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: var(--color-nav-item-active-border);
    border-radius: 0 2px 2px 0;
}

.nav-item__icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
}

.nav-item.active .nav-item__icon,
.nav-item:hover .nav-item__icon {
    opacity: 1;
}

.nav-item.active .nav-item__icon {
    color: var(--color-accent);
}

.nav-item__label {
    flex: 1;
    transition: opacity var(--transition-slow), width var(--transition-slow);
    overflow: hidden;
}

.app-shell.sidebar-collapsed .nav-item__label {
    opacity: 0;
    width: 0;
    pointer-events: none;
}

.nav-item__badge {
    background: var(--color-accent);
    color: #fff;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    padding: 2px var(--space-1);
    border-radius: var(--radius-full);
    min-width: 18px;
    text-align: center;
    line-height: 14px;
    transition: opacity var(--transition-slow);
}

.app-shell.sidebar-collapsed .nav-item__badge {
    opacity: 0;
}

/* #ANCORA-PRELIEVO-IN-ATTESA-MENU: pallino di notifica visibile anche a sidebar compressa. */
.nav-item__notification-dot {
    width: 9px;
    height: 9px;
    flex: 0 0 9px;
    border-radius: var(--radius-full);
    background: var(--color-warning);
    box-shadow: 0 0 0 3px var(--color-warning-subtle);
}

/* #ANCORA-COPERTURA-SCOPERTA-MENU: variante rossa per interventi operativi urgenti. */
.nav-item__notification-dot--danger {
    background: var(--color-danger);
    box-shadow: 0 0 0 3px var(--color-danger-subtle);
}

.app-shell.sidebar-collapsed .nav-item__notification-dot {
    position: absolute;
    top: 7px;
    right: 12px;
}

/* ── Sidebar: Sub-navigation (per DashBook, etc.) ─────────────────────────── */
.nav-subitems {
    overflow: hidden;
    max-height: 0;
    transition: max-height var(--transition-slow);
}

.nav-subitems.open {
    max-height: 300px;
}

.nav-subitem {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-5) var(--space-2) calc(var(--space-5) + 28px);
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: var(--text-sm);
    transition: color var(--transition-fast), background var(--transition-fast);
    min-height: 34px;
}

.nav-subitem:hover {
    color: var(--color-text-secondary);
    background: var(--color-nav-item-hover);
}

.nav-subitem.active,
.nav-subitem:global(.active) {
    color: var(--color-accent);
}

/* ── Sidebar: Footer ──────────────────────────────────────────────────────── */
.sidebar__footer {
    border-top: 1px solid var(--color-sidebar-border);
    padding: var(--space-3) var(--space-4);
    flex-shrink: 0;
}

.user-menu {
    position: relative;
}

.user-widget {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2);
    width: 100%;
    border: 0;
    border-radius: var(--radius-md);
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    transition: background var(--transition-fast);
    text-decoration: none;
    text-align: left;
}

.user-widget:hover {
    background: var(--color-bg-overlay);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--color-accent-subtle);
    border: 1px solid var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--color-accent);
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    overflow: hidden;
    transition: opacity var(--transition-slow);
}

.app-shell.sidebar-collapsed .user-info {
    opacity: 0;
    width: 0;
    pointer-events: none;
}

.user-name {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

.user-menu__chevron {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    transition: transform var(--transition-fast), opacity var(--transition-slow), width var(--transition-slow);
}

.user-menu__chevron--open {
    transform: rotate(180deg);
}

.app-shell.sidebar-collapsed .user-menu__chevron {
    opacity: 0;
    width: 0;
    pointer-events: none;
}

.user-menu__dropdown {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + var(--space-2));
    padding: var(--space-2);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    background: var(--color-bg-elevated);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
}

.user-menu__limits {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: var(--space-2) var(--space-3);
}

.user-menu__limits-title {
    margin-bottom: 2px;
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
}

.user-menu__limit-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    color: var(--color-text-secondary);
    font-size: 10px;
}

.user-menu__limit-row strong {
    color: var(--color-text-primary);
    font-size: 11px;
    font-weight: 700;
}

.user-menu__limit-row--reached,
.user-menu__limit-row--reached strong {
    color: var(--color-danger);
}

.user-menu__divider {
    height: 1px;
    margin: var(--space-1) 0 var(--space-2);
    background: var(--color-border-subtle);
}

.user-menu__item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    min-height: 36px;
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    text-align: left;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.user-menu__item:hover {
    background: var(--color-bg-overlay);
    color: var(--color-text-primary);
}

.user-menu__item--danger {
    color: var(--color-danger);
}

.user-menu__item--community-unread,
.user-menu__item--community-unread:hover {
    background: var(--color-accent-subtle);
    color: var(--color-accent);
}

.user-menu__community-dot {
    margin-left: auto;
}

.user-menu__item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* #ANCORA-COMMUNITY-UNREAD-DOTS: indicatore sul profilo e richiamo nel menu utente. */
.user-widget__community-dot,
.user-menu__community-dot {
    width: 9px;
    height: 9px;
    border: 2px solid var(--color-bg-surface);
    border-radius: var(--radius-full);
    background: var(--color-accent);
    box-shadow: 0 0 0 2px var(--color-accent-subtle);
    flex: 0 0 auto;
}

.user-widget__community-dot {
    position: absolute;
    top: 4px;
    left: 31px;
    border-color: var(--color-sidebar-bg);
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */
/* #ANCORA-EXPORT-MENU-TOPBAR */
.header-export {
    position: relative;
    flex-shrink: 0;
}
.header-export__backdrop {
    position: fixed;
    top: 0;
    right: 0;
    width: 100vw;
    height: 100dvh;
    z-index: 1;
}
.header-export__menu {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    z-index: 2;
    width: max-content;
    max-width: calc(100vw - var(--space-6) * 2);
    max-height: calc(100dvh - var(--topbar-height) - var(--space-4));
    overflow-y: auto;
    padding: var(--space-1);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    background: var(--color-bg-elevated);
}
.header-export__menu button {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-primary);
    text-align: left;
    font-size: var(--text-sm);
    cursor: pointer;
}
.header-export__menu button:hover,
.header-export__menu button:focus-visible {
    background: var(--color-bg-overlay);
}

@media (max-width: 760px) {
    /* Il menu resta nel viewport anche con il pannello laterale aperto. */
    .topbar:has(.header-export__menu) {
        backdrop-filter: none;
    }
    .header-export__menu {
        position: fixed;
        top: calc(var(--topbar-height) + var(--space-2));
        right: var(--space-4);
    }
}

.topbar {
    position: sticky;
    top: 0;
    height: var(--topbar-height);
    background: var(--color-topbar-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--color-border-subtle);
    display: flex;
    align-items: center;
    padding: 0 var(--space-6);
    gap: var(--space-4);
    z-index: var(--z-sticky);
    flex-shrink: 0;
}

.topbar__toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    transition: background var(--transition-fast), color var(--transition-fast);
    cursor: pointer;
    flex-shrink: 0;
}

.topbar__toggle:hover {
    background: var(--color-bg-overlay);
    color: var(--color-text-primary);
}

.topbar__breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 1;
}

.topbar__page-title {
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
    color: var(--color-text-primary);
}

.topbar__breadcrumb-sep {
    color: var(--color-text-muted);
    font-size: var(--text-sm);
}

.topbar__subtitle {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

.topbar__actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
}

/* ── Content area ─────────────────────────────────────────────────────────── */
/* #ANCORA-LAYOUT-SCROLL-PAGINA: unico scroll verticale per ogni pagina autenticata. */
.content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;        /* delimita lo scroll container nel flex column */
    overscroll-behavior-y: contain;
    scrollbar-gutter: stable;
    animation: fadeIn var(--transition-slow);
}

.content-inner {
    padding: var(--space-6);
    min-height: 100%;
}

/* Se il primo elemento dentro content-inner è una tab bar,
   azzera il padding-top per farla partire a filo col bordo superiore */
/*.content-inner:has(> .tabs) {
    padding-top: 0;
}*/

/* ── Layout autenticazione (login page) ───────────────────────────────────── */
.auth-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-base);
    position: relative;
    overflow: hidden;
}

.auth-layout::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--color-accent-glow) 0%, transparent 70%);
    top: -200px;
    right: -100px;
    pointer-events: none;
}

.auth-layout::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(34,201,122,0.08) 0%, transparent 70%);
    bottom: -100px;
    left: -100px;
    pointer-events: none;
}

/* ── Page section ─────────────────────────────────────────────────────────── */
.page-header {
    margin-bottom: var(--space-6);
}

.page-title {
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    color: var(--color-text-primary);
    letter-spacing: -0.02em;
}

.page-subtitle {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

.page-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}
