/* ========== DESIGN TOKENS ========== */
:root {
    /* Navy + Gold Palette */
    --primary: #0F172A;
    --primary-light: #1E293B;
    --primary-lighter: #334155;
    --secondary: #1E3A8A;
    --secondary-light: #3B82F6;
    --accent: #CA8A04;
    --accent-light: #EAB308;
    --accent-hover: #A16207;
    --success: #059669;
    --success-bg: #D1FAE5;
    --success-text: #065F46;
    --warning: #D97706;
    --warning-bg: #FEF3C7;
    --warning-text: #92400E;
    --danger: #DC2626;
    --danger-bg: #FEE2E2;
    --danger-text: #991B1B;
    --info: #2563EB;
    --info-bg: #DBEAFE;
    --info-text: #1E40AF;

    /* Neutrals (Slate scale) */
    --gray-50: #F8FAFC;
    --gray-100: #F1F5F9;
    --gray-200: #E2E8F0;
    --gray-300: #CBD5E1;
    --gray-400: #94A3B8;
    --gray-500: #64748B;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1E293B;
    --gray-900: #0F172A;
    --white: #FFFFFF;
    --bg: #F8FAFC;
    --text: #020617;
    --text-muted: #64748B;

    /* Spacing scale (4px base) */
    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
    --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;

    /* Typography scale */
    --text-xs: 0.75rem; --text-sm: 0.875rem; --text-base: 1rem;
    --text-lg: 1.125rem; --text-xl: 1.25rem; --text-2xl: 1.5rem;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(15,23,42,0.05);
    --shadow-md: 0 4px 6px -1px rgba(15,23,42,0.07), 0 2px 4px -2px rgba(15,23,42,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(15,23,42,0.08), 0 4px 6px -4px rgba(15,23,42,0.04);
    --shadow-xl: 0 25px 50px rgba(15,23,42,0.15);

    /* Radius */
    --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; --radius-xl: 16px; --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;
}

/* ========== RESET ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    min-height: 100vh;
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ========== CONFIG MODAL ========== */
.config-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15,23,42,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.config-modal.hidden { display: none; }
.config-box {
    background: var(--white);
    padding: var(--sp-10);
    border-radius: var(--radius-xl);
    max-width: 500px;
    width: 90%;
    box-shadow: var(--shadow-xl);
}
.config-box h2 {
    margin-bottom: var(--sp-5);
    color: var(--primary);
}
.config-box p {
    color: var(--text-muted);
    margin-bottom: var(--sp-5);
    font-size: var(--text-sm);
}

/* ========== LOGIN ========== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
}
.login-container.hidden { display: none; }
.login-box {
    background: var(--white);
    padding: var(--sp-10);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 400px;
}
.login-box h1 {
    text-align: center;
    margin-bottom: 30px;
    color: var(--primary);
}
.login-box .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-top: -20px;
    margin-bottom: 30px;
    font-size: var(--text-sm);
}

/* ========== APP CONTAINER ========== */
.app-container { display: none; }
.app-container.visible { display: block; }

/* ========== HEADER ========== */
.header {
    background: var(--primary);
    padding: var(--sp-4) var(--sp-6);
    box-shadow: var(--shadow-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}
.header h1 {
    font-size: var(--text-xl);
    color: var(--white);
}
.header-actions {
    display: flex;
    gap: var(--sp-3);
    align-items: center;
}
.lang-selector {
    background: rgba(255,255,255,0.1);
    color: var(--white);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: var(--radius-md);
    padding: 4px 8px;
    font-size: var(--text-xs);
    font-weight: 600;
    cursor: pointer;
    min-width: auto;
    width: auto;
}
.lang-selector option {
    background: var(--gray-800);
    color: var(--white);
}
.user-info {
    color: var(--gray-400);
    font-size: var(--text-sm);
}
.header .btn-secondary {
    background: rgba(255,255,255,0.1);
    color: var(--white);
    border: 1px solid rgba(255,255,255,0.2);
}
.header .btn-secondary:hover {
    background: rgba(255,255,255,0.2);
}
.header .form-select {
    background: rgba(255,255,255,0.1);
    color: var(--white);
    border: 1px solid rgba(255,255,255,0.2);
}

/* ========== NAVIGATION ========== */
.nav {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 0 var(--sp-6);
    display: flex;
    gap: var(--sp-2);
    overflow-x: auto;
}
.nav-item {
    padding: var(--sp-4) var(--sp-5);
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-base);
    font-size: var(--text-sm);
}
.nav-item:hover {
    color: var(--accent);
}
.nav-item.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ========== MAIN CONTENT ========== */
.main {
    padding: var(--sp-6);
    max-width: 1400px;
    margin: 0 auto;
}

/* ========== SECTIONS ========== */
.section { display: none; }
.section.active { display: block; }

/* ========== CARDS ========== */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: var(--sp-6);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--sp-6);
    border: 1px solid var(--gray-200);
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--sp-5);
}
.card-title {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--primary);
}

/* ========== FORMS ========== */
.form-group {
    margin-bottom: var(--sp-4);
}
.form-label {
    display: block;
    margin-bottom: var(--sp-2);
    font-weight: 500;
    color: var(--gray-700);
    font-size: var(--text-sm);
}
.form-input, .form-select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-family: inherit;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
    background: var(--white);
    color: var(--text);
}
.form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(202, 138, 4, 0.15);
}
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--sp-4);
}

/* ========== BUTTONS ========== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    font-size: var(--text-sm);
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
}
.btn-primary {
    background: var(--accent);
    color: var(--white);
}
.btn-primary:hover {
    background: var(--accent-hover);
}
.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
}
.btn-secondary:hover {
    background: var(--gray-200);
}
.btn-success {
    background: var(--success);
    color: var(--white);
}
.btn-success:hover { background: #047857; }
.btn-danger {
    background: var(--danger);
    color: var(--white);
}
.btn-danger:hover { background: #B91C1C; }
.btn-warning {
    background: var(--warning);
    color: var(--white);
}
.btn-warning:hover { background: #B45309; }
.btn-sm {
    padding: 6px 12px;
    font-size: var(--text-xs);
}
.btn-icon {
    padding: var(--sp-2);
    border-radius: var(--radius-sm);
}

/* ========== TABLES ========== */
.table-container {
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    padding: var(--sp-3) var(--sp-4);
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}
th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--text-muted);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
tr:hover td {
    background: var(--gray-50);
}

/* ========== CHIPS / BADGES ========== */
.chip {
    display: inline-block;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 500;
}
.chip-success {
    background: var(--success-bg);
    color: var(--success-text);
}
.chip-warning {
    background: var(--warning-bg);
    color: var(--warning-text);
}
.chip-danger {
    background: var(--danger-bg);
    color: var(--danger-text);
}
.chip-info {
    background: var(--info-bg);
    color: var(--info-text);
}
.chip-gray {
    background: var(--gray-200);
    color: var(--gray-700);
}
.chip-prova {
    background: var(--warning-bg);
    color: var(--warning-text);
    cursor: pointer;
    transition: all var(--transition-base);
    border: 1px solid transparent;
}
.chip-prova:hover {
    background: #FDE68A;
    border-color: var(--warning);
}

/* ========== SUB-TABS ========== */
.sub-tabs {
    display: flex;
    gap: 4px;
    background: var(--gray-100);
    border-radius: var(--radius-md);
    padding: 3px;
}
.sub-tab {
    padding: 6px 16px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--text-sm);
    font-weight: 500;
    font-family: inherit;
    color: var(--text-muted);
    transition: all var(--transition-base);
}
.sub-tab.active {
    background: var(--white);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}
.sub-tab:hover:not(.active) {
    color: var(--gray-700);
}

/* ========== STAT CARDS ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--sp-4);
    margin-bottom: var(--sp-6);
}
.stat-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
}
.stat-card-link {
    cursor: pointer;
    transition: all var(--transition-base);
}
.stat-card-link:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent);
}
.stat-label {
    color: var(--text-muted);
    font-size: var(--text-sm);
    margin-bottom: var(--sp-1);
}
.stat-value {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--primary);
}

/* ========== ROW STATUS ========== */
.row-warning {
    background: #FEF9C3 !important;
}
.row-danger {
    background: #FECACA !important;
}
.row-prova-completata {
    background: #EDE9FE !important;
    border-left: 4px solid #7C3AED;
}
.chip-prova-completata {
    background: #EDE9FE;
    color: #5B21B6;
    font-size: 0.7rem;
    font-weight: 600;
    animation: pulse-prova 2s ease-in-out infinite;
}
@keyframes pulse-prova {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ========== MODAL ========== */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15,23,42,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }
.modal-content {
    background: var(--white);
    padding: var(--sp-6);
    border-radius: var(--radius-xl);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--sp-5);
}
.modal-title {
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--primary);
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-400);
    transition: color var(--transition-fast);
}
.modal-close:hover {
    color: var(--gray-700);
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-3);
    margin-top: var(--sp-6);
    padding-top: var(--sp-4);
    border-top: 1px solid var(--gray-200);
}

/* ========== TOAST ========== */
.toast {
    position: fixed;
    bottom: var(--sp-6);
    right: var(--sp-6);
    padding: var(--sp-4) var(--sp-6);
    border-radius: var(--radius-lg);
    color: var(--white);
    font-weight: 500;
    z-index: 2000;
    animation: slideIn 0.3s ease;
    box-shadow: var(--shadow-lg);
}
.toast.hidden { display: none; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ========== UTILITIES ========== */
.hidden { display: none !important; }
.accordion-arrow { transition: transform var(--transition-base); }
.accordion-arrow.open { transform: rotate(90deg); }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: var(--sp-4);
    opacity: 0.5;
}

/* Loading */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--sp-10);
}
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--white);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Mobile elements - hidden by default on desktop */
.mobile-bottom-nav,
.mobile-more-sheet,
.mobile-more-overlay {
    display: none;
}

/* ========== REFERRAL STYLES ========== */
.chip-referral {
    display: inline-block;
    background: var(--info-bg);
    color: var(--info-text);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    margin-left: var(--sp-1);
}
.referral-credit-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    background: var(--success-bg);
    color: var(--success-text);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
}

/* ========== BONUS SYSTEM ========== */
.bonus-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--accent);
    margin-bottom: var(--sp-4);
    border-top: 1px solid var(--gray-200);
    border-right: 1px solid var(--gray-200);
    border-bottom: 1px solid var(--gray-200);
}
.bonus-card.achieved {
    border-left-color: var(--success);
    background: linear-gradient(135deg, #F0FDF4, var(--white));
}
.bonus-card.confirmed {
    border-left-color: #8B5CF6;
    background: linear-gradient(135deg, #F5F3FF, var(--white));
}
.bonus-progress-bar {
    background: var(--gray-200);
    border-radius: var(--radius-md);
    height: 12px;
    overflow: hidden;
    margin: var(--sp-3) 0;
}
.bonus-progress-fill {
    height: 100%;
    border-radius: var(--radius-md);
    transition: width 0.5s ease;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
}
.bonus-progress-fill.achieved {
    background: linear-gradient(90deg, var(--success), #34D399);
}
.bonus-tier-indicator {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    margin: 2px;
}
.bonus-tier-active {
    background: var(--info-bg);
    color: var(--info-text);
}
.bonus-tier-inactive {
    background: var(--gray-100);
    color: var(--gray-400);
}
.bonus-rule-card {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: var(--sp-4);
    margin-bottom: var(--sp-3);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
@keyframes celebrationPop {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}
.bonus-celebration-toast {
    animation: celebrationPop 0.5s ease-out;
}

/* Bonus dashboard components */
.bonus-section-title {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--primary);
    margin-bottom: var(--sp-4);
}
.bonus-stat {
    text-align: center;
    padding: var(--sp-4);
}
.bonus-stat-value {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--primary);
}
.bonus-stat-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: var(--sp-1);
}
.bonus-tier-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius-sm);
    margin-bottom: var(--sp-1);
}
.bonus-settings-group {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: var(--sp-4);
    margin-bottom: var(--sp-4);
}

/* Toggle card (settings) */
.toggle-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--sp-4);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    margin-bottom: var(--sp-3);
}

/* Commission sections */
.comm-section {
    margin-bottom: var(--sp-6);
}
.comm-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--sp-3);
    background: var(--gray-50);
    border-radius: var(--radius-md);
    margin-bottom: var(--sp-3);
}

/* Impersonation banner */
.impersonation-banner {
    display: none;
    background: linear-gradient(135deg, var(--warning-bg), #FDE68A);
    padding: var(--sp-2) var(--sp-6);
    text-align: center;
    font-size: var(--text-sm);
    color: var(--warning-text);
    font-weight: 500;
    position: sticky;
    top: 56px;
    z-index: 99;
    border-bottom: 2px solid var(--warning);
}

/* Filter bar */
.filter-bar {
    display: flex;
    gap: var(--sp-3);
    flex-wrap: wrap;
    padding: 0 0 var(--sp-4) 0;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: var(--sp-4);
}

/* Push notification banner */
.push-banner {
    position: fixed;
    bottom: var(--sp-6);
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: var(--white);
    padding: var(--sp-4) var(--sp-6);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    z-index: 500;
    display: flex;
    align-items: center;
    gap: var(--sp-4);
}

/* Calendar */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--sp-2);
    padding: var(--sp-4);
}
.cal-cell {
    border-radius: var(--radius-md);
    padding: var(--sp-3);
    cursor: pointer;
    transition: all var(--transition-base);
}
.cal-cell:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
.cal-month-label {
    font-weight: 600;
    font-size: var(--text-sm);
    margin-bottom: var(--sp-2);
}
.cal-amount {
    font-size: var(--text-xs);
    font-weight: 600;
}

/* Accordion */
.accordion-header {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--sp-3) 0;
}
.accordion-content {
    overflow: hidden;
    transition: max-height var(--transition-slow);
}

/* Nav icon (SVG in mobile nav) */
.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}
.nav-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ========== UTILITY CLASSES ========== */
/* Layout */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--sp-1); }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.gap-6 { gap: var(--sp-6); }

/* Spacing */
.m-0 { margin: 0; }
.mb-1 { margin-bottom: var(--sp-1); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.ml-3 { margin-left: var(--sp-3); }
.p-0 { padding: 0; }
.p-2 { padding: var(--sp-2); }
.p-3 { padding: var(--sp-3); }
.p-4 { padding: var(--sp-4); }
.p-5 { padding: var(--sp-5); }
.px-4 { padding-left: var(--sp-4); padding-right: var(--sp-4); }
.px-6 { padding-left: var(--sp-6); padding-right: var(--sp-6); }
.py-2 { padding-top: var(--sp-2); padding-bottom: var(--sp-2); }
.py-3 { padding-top: var(--sp-3); padding-bottom: var(--sp-3); }

/* Width */
.w-full { width: 100%; }
.w-auto { width: auto; }

/* Text */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-white { color: var(--white); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

/* Display */
.block { display: block; }
.inline-block { display: inline-block; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }
.hidden-el { display: none; }

/* Borders */
.border-t { border-top: 1px solid var(--gray-200); }
.border-b { border-bottom: 1px solid var(--gray-200); }
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }

/* Effects */
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.cursor-pointer { cursor: pointer; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ========== RESPONSIVE MOBILE ========== */
@media (max-width: 768px) {
    /* Header */
    .header {
        padding: 10px var(--sp-4);
        gap: var(--sp-2);
    }
    .header .header-logo img {
        height: 28px !important;
    }
    .user-info {
        display: none;
    }
    .header .header-actions .btn-sm {
        padding: var(--sp-2) 14px;
        min-height: 40px;
    }

    /* Top Nav Hidden, Bottom Nav Shown */
    .nav {
        display: none !important;
    }
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        background: var(--white);
        border-top: 1px solid var(--gray-200);
        z-index: 200;
        padding: var(--sp-1) 0;
        padding-bottom: env(safe-area-inset-bottom, 0);
        box-shadow: 0 -2px 10px rgba(15,23,42,0.05);
    }
    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 6px 2px;
        font-size: 0.6rem;
        color: var(--text-muted);
        text-decoration: none;
        cursor: pointer;
        transition: color var(--transition-base);
        min-height: 50px;
        gap: 3px;
        border: none;
        background: none;
        font-family: inherit;
    }
    .mobile-nav-item.active {
        color: var(--accent);
    }
    .mobile-nav-item .nav-icon {
        font-size: 1.25rem;
        line-height: 1;
    }

    /* More Sheet */
    .mobile-more-overlay {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(15,23,42,0.3);
        z-index: 250;
    }
    .mobile-more-overlay.open {
        display: block;
    }
    .mobile-more-sheet {
        display: none;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        background: var(--white);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        padding: var(--sp-4);
        padding-bottom: calc(var(--sp-4) + env(safe-area-inset-bottom, 0));
        z-index: 300;
        box-shadow: 0 -4px 20px rgba(15,23,42,0.15);
    }
    .mobile-more-sheet.open {
        display: block;
    }
    .more-sheet-handle {
        width: 40px;
        height: 4px;
        background: var(--gray-300);
        border-radius: 2px;
        margin: 0 auto var(--sp-4);
    }
    .more-item {
        display: flex;
        align-items: center;
        gap: var(--sp-3);
        padding: 14px var(--sp-3);
        border-radius: 10px;
        color: var(--gray-700);
        font-weight: 500;
        font-size: var(--text-sm);
        cursor: pointer;
        transition: background var(--transition-fast);
        border: none;
        background: none;
        width: 100%;
        text-align: left;
        font-family: inherit;
    }
    .more-item:active {
        background: var(--gray-100);
    }
    .more-item.active {
        color: var(--accent);
        background: rgba(202, 138, 4, 0.06);
    }

    /* Main Content */
    .main {
        padding: var(--sp-3);
        padding-bottom: 80px;
    }

    /* Cards */
    .card {
        padding: 14px;
        margin-bottom: 14px;
        border-radius: 10px;
    }

    /* Card Headers: Stack */
    .card-header {
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px;
    }
    .card-header > div {
        flex-wrap: wrap !important;
        gap: var(--sp-2) !important;
    }
    .card-header > .flex {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    /* Sub-tabs */
    .sub-tabs {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .sub-tab {
        padding: 10px 14px;
        font-size: 0.82rem;
        min-height: 40px;
        white-space: nowrap;
    }

    /* Filter overrides */
    .filter-bar .form-select,
    .filter-bar .form-input,
    .form-select.w-auto,
    .form-input[style*="width: 200px"],
    .form-select[style*="width: auto"] {
        width: 100% !important;
    }

    /* Stats Grid */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .stat-card {
        padding: 14px;
    }
    .stat-value {
        font-size: 1.2rem;
    }
    .stat-label {
        font-size: var(--text-xs);
    }

    /* Calendar */
    .calendar-grid,
    #dashboardCalendario {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px !important;
        padding: 10px !important;
    }

    /* Forms */
    .form-row {
        grid-template-columns: 1fr;
    }
    .form-input, .form-select {
        font-size: 16px;
        padding: var(--sp-3) 14px;
        min-height: 44px;
    }
    .form-label {
        font-size: 0.82rem;
    }

    /* Touch-friendly buttons */
    .btn {
        padding: var(--sp-3) var(--sp-5);
        font-size: var(--text-sm);
    }
    .btn-sm {
        padding: 10px var(--sp-4);
        font-size: 0.82rem;
        min-height: 44px;
    }
    .btn-icon {
        padding: 10px;
        min-height: 44px;
        min-width: 44px;
    }

    /* Chips */
    .chip {
        padding: 5px 12px;
        font-size: 0.78rem;
    }

    /* Tables -> Card Mobile */
    .table-container table {
        display: block;
    }
    .table-container thead {
        display: none;
    }
    .table-container tbody {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    .table-container tbody tr {
        display: flex;
        flex-direction: column;
        background: var(--white);
        border: 1px solid var(--gray-200);
        border-radius: 10px;
        padding: 14px;
        gap: 4px;
        position: relative;
    }
    .table-container tbody tr:hover td {
        background: transparent;
    }
    .table-container tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 3px 0;
        border-bottom: none;
        font-size: 0.85rem;
    }
    .table-container tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        flex-shrink: 0;
        margin-right: var(--sp-2);
    }
    .table-container tbody td:first-child {
        font-size: 0.95rem;
        padding-bottom: var(--sp-2);
        margin-bottom: var(--sp-1);
        border-bottom: 1px solid var(--gray-100);
    }
    .table-container tbody td:last-child {
        display: flex;
        gap: var(--sp-2);
        padding-top: var(--sp-2);
        border-top: 1px solid var(--gray-100);
        margin-top: var(--sp-1);
        flex-wrap: wrap;
        justify-content: flex-start;
    }
    /* Row status as card left border */
    .table-container tbody tr.row-warning {
        border-left: 4px solid var(--warning) !important;
    }
    .table-container tbody tr.row-danger {
        border-left: 4px solid var(--danger) !important;
    }
    .table-container tbody tr.row-prova-completata {
        border-left: 4px solid #7C3AED !important;
    }
    /* Table footer */
    .table-container tfoot {
        display: block;
        margin-top: 10px;
    }
    .table-container tfoot tr {
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        padding: var(--sp-3) 14px;
        background: var(--gray-50);
        border-radius: 10px;
    }
    .table-container tfoot td {
        padding: 0;
        border-bottom: none;
    }

    /* Modals */
    .modal-content {
        width: 95%;
        max-height: 85vh;
        padding: var(--sp-4);
        border-radius: var(--radius-lg);
    }
    .modal-title {
        font-size: 1.1rem;
    }
    .modal-close {
        font-size: 1.8rem;
        padding: var(--sp-2);
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .modal-footer {
        flex-direction: column;
        gap: var(--sp-2);
    }
    .modal-footer .btn {
        width: 100%;
        justify-content: center;
    }

    /* Toast */
    .toast {
        left: var(--sp-4);
        right: var(--sp-4);
        bottom: 80px;
        text-align: center;
        border-radius: 10px;
        font-size: 0.85rem;
        padding: 14px var(--sp-4);
    }

    /* Empty State */
    .empty-state {
        padding: var(--sp-10) var(--sp-4);
    }

    /* Login */
    .login-box {
        padding: var(--sp-6);
        margin: var(--sp-4);
        max-width: none;
        width: calc(100% - 32px);
    }

    /* Impersonation */
    .impersonation-banner {
        top: 46px;
        padding: 6px var(--sp-4);
        font-size: 0.8rem;
    }
    #impersonationSelector select {
        max-width: 140px;
        font-size: var(--text-xs);
    }
    .commissioni-main-tabs .sub-tab {
        padding: 8px 16px;
        font-size: 0.85rem;
    }
    .bonus-member-grid {
        grid-template-columns: 1fr;
    }
    #bonusChartContainer {
        height: 250px !important;
    }
}

/* ==================== SEARCHABLE SELECT (Autocomplete) ==================== */
.searchable-select {
    position: relative;
    width: 100%;
}

.searchable-select-input {
    width: 100%;
    padding: 10px 36px 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-family: inherit;
    background: white;
    color: var(--text);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.searchable-select-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(202, 138, 4, 0.15);
}

.searchable-select-input::placeholder {
    color: var(--gray-400);
}

.searchable-select-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--gray-400);
}

.searchable-select-icon svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

.searchable-select-clear {
    position: absolute;
    right: 32px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-400);
    padding: 2px;
    line-height: 1;
    font-size: 1.1rem;
    display: none;
    transition: color var(--transition-fast);
}

.searchable-select-clear:hover {
    color: var(--danger);
}

.searchable-select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    max-height: 200px;
    overflow-y: auto;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    margin-top: 4px;
    display: none;
}

.searchable-select-dropdown.open {
    display: block;
}

.searchable-select-option {
    padding: 10px 12px;
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--text);
    transition: background var(--transition-fast);
}

.searchable-select-option:hover,
.searchable-select-option.highlighted {
    background: var(--gray-50);
}

.searchable-select-option.selected {
    background: rgba(202, 138, 4, 0.08);
    color: var(--accent-hover);
    font-weight: 600;
}

.searchable-select-option mark {
    background: rgba(202, 138, 4, 0.2);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

.searchable-select-empty {
    padding: 12px;
    text-align: center;
    color: var(--gray-400);
    font-size: var(--text-sm);
    font-style: italic;
}

/* ==================== COMMISSIONI MAIN TABS ==================== */
.commissioni-main-tabs {
    display: inline-flex;
    background: var(--primary-light);
    border-radius: var(--radius-md);
    padding: 3px;
}

.commissioni-main-tabs .sub-tab {
    color: var(--gray-300);
    font-weight: 600;
    padding: 10px 24px;
    font-size: var(--text-base);
    border-radius: calc(var(--radius-md) - 2px);
    transition: all var(--transition-fast);
}

.commissioni-main-tabs .sub-tab.active {
    background: var(--white);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.commissioni-main-tabs .sub-tab:hover:not(.active) {
    color: var(--white);
    background: rgba(255, 255, 255, 0.1);
}

/* ==================== BONUS MEMBER GRID ==================== */
.bonus-member-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--sp-4);
}

.bonus-member-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: var(--sp-4);
    cursor: pointer;
    transition: all var(--transition-base);
}

.bonus-member-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.bonus-detail-panel {
    border: 2px solid var(--accent);
    border-radius: var(--radius-lg);
    background: var(--gray-50);
    padding: var(--sp-6);
    margin-top: var(--sp-4);
}

/* ==================== PRICE OVERRIDE FIELD ==================== */
.price-override-field {
    position: relative;
}

.price-override-field .form-input {
    padding-left: 28px;
}

.price-override-field::before {
    content: '\20AC';
    position: absolute;
    left: 10px;
    top: 11px;
    color: var(--gray-400);
    font-weight: 600;
    font-size: var(--text-sm);
    pointer-events: none;
}

/* Extra small screens */
@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .stat-value {
        font-size: 1.1rem;
    }
}

/* ========== SAAS DASHBOARD ========== */
.saas-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: var(--sp-4);
}

.saas-summary-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--sp-4);
}

.saas-summary-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: var(--sp-4);
}

.saas-activity-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--gray-100);
}

.saas-activity-item:last-child {
    border-bottom: none;
}

@media (max-width: 768px) {
    .saas-summary-grid {
        grid-template-columns: 1fr;
    }
    #saasAgenzieTable {
        overflow-x: auto;
    }
}

/* ========== UPGRADE PROMPT (Feature Gating) ========== */
.upgrade-prompt {
    text-align: center;
    padding: 32px 24px;
    background: var(--gray-50);
    border: 2px dashed var(--gray-300);
    border-radius: 12px;
    margin: 8px 0;
}
.upgrade-prompt p {
    color: var(--text-muted);
    font-size: var(--text-sm);
    margin-bottom: 16px;
    line-height: 1.5;
}

/* ========== TENANT BLOCKED OVERLAY ========== */
.tenant-blocked-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(15, 23, 42, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.tenant-blocked-card {
    background: white;
    border-radius: 16px;
    padding: 40px;
    max-width: 440px;
    width: 90%;
    text-align: center;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
}
.tenant-blocked-card .blocked-icon {
    font-size: 48px;
    margin-bottom: 16px;
}
.tenant-blocked-card h2 {
    color: var(--primary);
    margin-bottom: 8px;
    font-size: 1.4rem;
}
.tenant-blocked-card p {
    color: var(--text-muted);
    margin-bottom: 24px;
    line-height: 1.5;
}
.tenant-blocked-card .btn {
    width: 100%;
    margin-bottom: 12px;
}
