/* ==========================================================
   BASE / RESET
   ========================================================== */

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

html {
    font-size: 16px; /* leggibilità ottimale per 35-50 anni */
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding-top: 70px; /* spazio per header fisso */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
                 Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f5f7f8;
    color: #2f3a40;
    line-height: 1.6;
    min-height: 100vh;
}

/* ==========================================================
   VARIABILI DI STILE
   ========================================================== */

:root {
    /* Colori */
    --bg-main: #f5f7f8;
    --bg-card: #ffffff;
    
    --primary: #5b7c87;
    --primary-light: #7a9aa5;
    --primary-soft: #e6eff2;
    
    --text-main: #2f3a40;
    --text-muted: #6f7f87;
    --text-light: #8a98a0;
    
    --border-soft: #d9e1e5;
    --border-light: #e5e7eb;
    
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    
    /* Spaziature */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    
    /* Bordi arrotondati */
    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 50%;
    
    /* Ombre */
    --shadow-soft: 0 2px 8px rgba(47, 58, 64, 0.04);
    --shadow-md: 0 4px 12px rgba(47, 58, 64, 0.06);
    --shadow-lg: 0 8px 24px rgba(47, 58, 64, 0.08);
    
    /* Transizioni */
    --transition-fast: 0.2s ease;
    --transition-smooth: 0.3s ease;
}

/* ==========================================================
   CONTAINER
   ========================================================== */

.container {
    width: 100%;
    max-width: 560px; /* ottimale per mobile */
    margin: 0 auto;
    padding: 0 var(--space-md);
}

/* ==========================================================
   HEADER
   ========================================================== */

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ffffff;
    border-bottom: 1px solid var(--border-light);
    z-index: 1000;
    box-shadow: var(--shadow-soft);
}

.header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px var(--space-md);
    max-width: 100%;
    gap: 12px;
}

.hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: background-color var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.hamburger-btn:hover {
    background-color: var(--primary-soft);
}

.hamburger-btn:active {
    transform: scale(0.96);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.header-brand-link {
    text-decoration: none;
    color: inherit;
    border-radius: var(--radius-md);
    transition: opacity var(--transition-fast);
}

.header-brand-link:hover {
    opacity: 0.85;
}

.header-brand-link:focus-visible {
    outline: 2px solid var(--primary, #1e6fba);
    outline-offset: 2px;
}

.app-logo {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.app-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.app-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.2;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Selettore Lingua */
.language-selector {
    position: relative;
}

.lang-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: 1px solid var(--border-soft);
    background: white;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-main);
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
    height: 40px;
    width: 100%;
}

.lang-btn:hover {
    background-color: var(--primary-soft);
    border-color: var(--primary-light);
}

.lang-btn:active {
    transform: scale(0.96);
}

.lang-btn img {
    border-radius: var(--radius-xs);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.lang-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 50;
    animation: dropdownFadeIn 0.2s ease;
}

.lang-dropdown.show {
    display: block;
}

.lang-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    color: var(--text-main);
    text-decoration: none;
    transition: background-color var(--transition-fast);
    font-size: 0.9375rem;
}

.lang-option:first-child {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.lang-option:last-child {
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.lang-option:hover {
    background-color: var(--primary-soft);
}

.lang-option.active {
    background-color: var(--primary-soft);
    color: var(--primary);
    font-weight: 500;
}

.lang-option img {
    border-radius: var(--radius-xs);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.lang-option__label {
    flex: 1;
}

.lang-option__badge {
    margin-left: auto;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted, #6b7280);
    background: var(--border-light, #f3f4f6);
    padding: 2px 6px;
    border-radius: var(--radius-xs);
    white-space: nowrap;
}

.lang-option--disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.lang-option--disabled:hover {
    background-color: transparent;
}

/* Notifiche */
.notification-btn,
a.notification-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: background-color var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
}

.notification-btn:hover {
    background-color: var(--primary-soft);
}

.notification-btn:active {
    transform: scale(0.96);
}

.notification-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--error);
    color: white;
    font-size: 0.625rem;
    font-weight: 600;
    border-radius: 10px;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
}

/* Menu Profilo */
.profile-menu {
    position: relative;
}

.profile-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: var(--radius-full);
    padding: 0;
    transition: transform var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.profile-btn:active {
    transform: scale(0.94);
}

.profile-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    object-fit: cover;
    border: 2px solid var(--border-light);
}

.profile-avatar-default {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
    border: 2px solid var(--border-light);
}

.profile-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 280px;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 50;
    animation: dropdownFadeIn 0.2s ease;
}

.profile-dropdown.show {
    display: block;
}

.profile-dropdown-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: var(--space-md);
}

.profile-dropdown-avatar img {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    object-fit: cover;
    border: 2px solid var(--border-light);
}

.profile-avatar-default-large {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.25rem;
    border: 2px solid var(--border-light);
}

.profile-dropdown-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.profile-dropdown-info strong {
    font-size: 0.9375rem;
    color: var(--text-main);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-dropdown-info span {
    font-size: 0.8125rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-dropdown-divider {
    height: 1px;
    background: var(--border-light);
    margin: var(--space-sm) 0;
}

.profile-dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px var(--space-md);
    color: var(--text-main);
    text-decoration: none;
    transition: background-color var(--transition-fast);
    font-size: 0.9375rem;
}

.profile-menu-badge {
    margin-left: auto;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--error);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.profile-dropdown-item:first-of-type {
    margin-top: var(--space-xs);
}

.profile-dropdown-item:hover {
    background-color: var(--primary-soft);
}

.profile-dropdown-item:active {
    background-color: #dae6ea;
}

.profile-dropdown-item.logout {
    color: var(--error);
}

.profile-dropdown-item.logout:hover {
    background-color: #fef2f2;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 70px;
    left: -280px;
    width: 280px;
    height: calc(100vh - 70px);
    background: white;
    border-right: 1px solid var(--border-light);
    transition: left var(--transition-smooth);
    z-index: 999;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.sidebar.show {
    left: 0;
}

.sidebar-nav {
    padding: var(--space-md);
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px var(--space-md);
    color: var(--text-main);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    margin-bottom: var(--space-xs);
    font-size: 0.9375rem;
}

.sidebar-item:hover {
    background-color: var(--primary-soft);
}

.sidebar-item:active {
    transform: scale(0.98);
}

.sidebar-item.active {
    background-color: var(--primary-soft);
    color: var(--primary);
    font-weight: 500;
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(47, 58, 64, 0.4);
    backdrop-filter: blur(2px);
    display: none;
    z-index: 998;
    animation: overlayFadeIn 0.2s ease;
}

.overlay.show {
    display: block;
}

.page-title-mobile {
    display: none;
    padding: var(--space-md);
    border-top: 1px solid var(--border-light);
}

.page-title-mobile h2 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-main);
    font-weight: 600;
}

/* ==========================================================
   MAIN CONTENT
   ========================================================== */

.app-main {
    padding: var(--space-lg) 0;
    min-height: calc(100vh - 70px);
}

.app-main .container {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* Box generici (cards, sezioni, moduli) */
.box,
.card,
section,
form {
    background-color: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    box-shadow: var(--shadow-soft);
    animation: contentFadeIn 0.3s ease;
}

/* ==========================================================
   TESTI
   ========================================================== */

h1, h2, h3, h4, h5, h6 {
    margin-top: 0;
    color: var(--primary);
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

h2 {
    font-size: 1.5rem;
    margin-bottom: var(--space-md);
}

h3 {
    font-size: 1.25rem;
    margin-bottom: var(--space-sm);
}

h4 {
    font-size: 1.125rem;
    margin-bottom: var(--space-sm);
}

p {
    margin: 0 0 var(--space-md) 0;
    color: var(--text-main);
    line-height: 1.6;
}

p:last-child {
    margin-bottom: 0;
}

.small,
.muted {
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ==========================================================
   FORM
   ========================================================== */

label {
    display: block;
    font-size: 0.9375rem;
    margin-bottom: var(--space-sm);
    color: var(--text-main);
    font-weight: 500;
}

/* Stile base per tutti gli input */
input,
textarea,
select {
    font-size: 1rem;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    background-color: #ffffff;
    color: var(--text-main);
    transition: border-color var(--transition-fast),
                box-shadow var(--transition-fast);
}

/* Solo per text inputs, textarea e select - NON checkbox/radio */
input:not([type="checkbox"]):not([type="radio"]), 
textarea, 
select {
    width: 100%;
    padding: 12px 14px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Stile specifico per CHECKBOX */
input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--primary);
}

/* Stile specifico per RADIO */
input[type="radio"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--primary);
}

/* Checkbox e Radio focus */
input[type="checkbox"]:focus,
input[type="radio"]:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

input::placeholder,
textarea::placeholder {
    color: var(--text-light);
}

/* ==========================================================
   BUTTONS
   ========================================================== */

button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    background-color: var(--primary);
    color: #ffffff;
    transition: all var(--transition-fast);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px; /* minimo per touch target */
}

button:hover,
.btn:hover {
    background-color: var(--primary-light);
    box-shadow: var(--shadow-md);
}

button:active,
.btn:active {
    transform: scale(0.98);
}

button:disabled,
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Variante secondaria */
.btn-secondary {
    background-color: #ffffff;
    color: var(--primary);
    border: 1px solid var(--border-soft);
}

.btn-secondary:hover {
    background-color: var(--primary-soft);
    border-color: var(--primary-light);
}

/* ==========================================================
   FOOTER
   ========================================================== */

.app-footer {
    margin-top: var(--space-xl);
    background-color: var(--bg-card);
    border-top: 1px solid var(--border-soft);
}

.app-footer .container {
    padding: var(--space-md);
    text-align: center;
}

.app-footer p {
    margin: var(--space-xs) 0;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.debug-info {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: var(--space-sm);
}

/* ==========================================================
   ANIMAZIONI
   ========================================================== */

@keyframes contentFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ==========================================================
   RESPONSIVE
   ========================================================== */

/* Tablet piccoli (640px+) */
@media (min-width: 640px) {
    body {
        padding-top: 70px;
    }
    
    .header-container {
        padding: 14px 20px;
    }
    
    .container {
        padding: 0 20px;
    }
    
    .app-main {
        padding: var(--space-xl) 0;
    }
}

/* Mobile piccoli (max 480px) */
@media (max-width: 480px) {
    html {
        font-size: 15px; /* leggermente più piccolo per schermi stretti */
    }
    
    .header-container {
        padding: 10px 12px;
        gap: 8px;
    }
    
    .app-title {
        font-size: 1rem;
    }
    
    .app-subtitle {
        display: none;
    }
    
    .lang-btn span {
        display: none;
    }
    
    .lang-btn {
        padding: 8px;
        width: 40px;
    }
    
    .notification-btn,
    .profile-btn,
    .hamburger-btn {
        width: 40px;
        height: 40px;
    }
    
    .profile-avatar,
    .profile-avatar-default {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }
    
    .page-title-mobile {
        display: block;
    }
    
    .container {
        padding: 0 12px;
    }
    
    .box,
    .card,
    section,
    form {
        padding: 14px;
    }
}
.container {
    width: 100%;
    max-width: 560px; /* mobile-first */
    margin: 0 auto;
    padding: 0 var(--space-md);
}
@media (min-width: 640px) {
    .container {
        max-width: 720px;
    }
}

@media (min-width: 768px) {
    .container {
        max-width: 960px;
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: 1140px;
    }
}
@media (min-width: 1280px) {
    .container {
        max-width: 1280px;
    }
}
@media (min-width: 1536px) {
    .container {
        max-width: 1440px;
    }
}

.role-switch {
    display: flex;
    position: relative;
    background: #f1f3f5;
    border-radius: 50px;
    padding: 4px;
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
}
.role-switch input { display: none; }
.role-switch label {
    flex: 1;
    text-align: center;
    /*padding: 10px 15px;*/
    cursor: pointer;
    z-index: 2;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.3s ease;
    margin-top: 8px;
}
.role-slider {
    position: absolute;
    width: calc(50% - 4px);
    height: calc(100% - 8px);
    background: #e6eff2;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    border-radius: 40px;
    transition: transform 0.3s ease;
}
#role-user:checked ~ .role-slider { transform: translateX(0); }
#role-professional:checked ~ .role-slider { transform: translateX(100%); }
#role-user:checked + label { color: var(--primary-color); }
#role-professional:checked + label { color: var(--primary-color); }

/* ==========================================================
   MODAL (shared)
   ========================================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
    padding: var(--space-md);
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-card);
    padding: var(--space-xl);
    border-radius: var(--radius-lg);
    text-align: center;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.modal-content p {
    color: var(--text-muted);
    font-size: 0.9375rem;
    margin: 0;
    line-height: 1.6;
}

.purchase-confirm-content {
    max-width: 420px;
    padding: 32px;
}

.purchase-confirm-icon {
    font-size: 48px;
    margin-bottom: 12px;
    line-height: 1;
}

.purchase-confirm-content h3 {
    margin: 0 0 12px;
    font-size: 1.375rem;
    color: var(--text-main);
}

.purchase-confirm-text {
    color: var(--text-muted);
    line-height: 1.6;
    margin: 0 0 12px;
    font-size: 0.9375rem;
}

.purchase-confirm-balance {
    font-size: 0.875rem;
    color: var(--text-light);
    margin: 0 0 24px;
}

.purchase-confirm-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-modal-primary {
    display: block;
    width: 100%;
    background: var(--primary);
    color: white;
    padding: 14px 32px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
}

.btn-modal-primary:hover {
    background: var(--primary-light);
}

.btn-modal-primary--success {
    background: var(--success);
}

.btn-modal-primary--success:hover {
    background: #0d9668;
}

.btn-cancel-modal {
    display: block;
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 12px;
    font-size: 0.875rem;
    cursor: pointer;
}

.btn-cancel-modal:hover {
    color: var(--text-main);
}

.modal-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-soft);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: modalSpin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes modalSpin {
    to { transform: rotate(360deg); }
}

