/* ============================================================
   Candlestick — Modern Theme (2026)
   Design System: Glassmorphism + Gradients + Smooth Animations
   ============================================================ */

/* --- Design Tokens --- */
:root {
    --primary-50: #eef2ff;
    --primary-100: #e0e7ff;
    --primary-200: #c7d2fe;
    --primary-400: #818cf8;
    --primary-500: #6366f1;
    --primary-600: #4f46e5;
    --primary-700: #4338ca;
    --primary-800: #3730a3;

    --surface-50: #f8fafc;
    --surface-100: #f1f5f9;
    --surface-200: #e2e8f0;
    --surface-300: #cbd5e1;
    --surface-400: #94a3b8;
    --surface-500: #64748b;
    --surface-600: #475569;
    --surface-700: #334155;
    --surface-800: #1e293b;
    --surface-900: #0f172a;

    --success: #10b981;
    --success-light: #d1fae5;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --info: #3b82f6;

    --glass-bg: rgba(255, 255, 255, 0.72);
    --glass-border: rgba(255, 255, 255, 0.18);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    --glass-blur: 12px;

    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --card-shadow-hover: 0 10px 40px rgba(99, 102, 241, 0.12), 0 4px 12px rgba(0, 0, 0, 0.08);
    --card-radius: 16px;

    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

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

body {
    font-family: var(--font-sans);
    background: linear-gradient(135deg, var(--surface-50) 0%, #eef2ff 50%, var(--surface-50) 100%);
    background-attachment: fixed;
    color: var(--surface-800);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-300); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--surface-400); }

/* ============================================================
   Main Container
   ============================================================ */
.main-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.5rem 2rem 3rem;
    min-height: 100vh;
}

/* ============================================================
   Glass Card Base
   ============================================================ */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal), border-color var(--transition-normal);
}

.glass-card:hover {
    box-shadow: var(--card-shadow-hover);
    border-color: rgba(99, 102, 241, 0.2);
}

/* ============================================================
   Header
   ============================================================ */
.app-header {
    margin-bottom: 2rem;
    position: relative;
    z-index: 10000; /* Superiore a tutto il resto della pagina */
}

.app-header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
}

.main-title {
    font-size: 1.75rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-600), var(--primary-400));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.03em;
    margin: 0;
}

.subtitle {
    color: var(--surface-400);
    font-size: 0.875rem;
    margin-top: 2px;
    font-weight: 400;
}

.header-user-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.875rem;
    background: var(--primary-50);
    border: 1px solid var(--primary-200);
    border-radius: 100px;
    color: var(--primary-700);
    font-size: 0.85rem;
    font-weight: 500;
}

.user-badge .avatar-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    display: inline-block;
}

.btn-logout {
    padding: 0.5rem 1.125rem;
    background: transparent;
    color: var(--surface-500);
    border: 1px solid var(--surface-200);
    border-radius: 100px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
}

.btn-logout:hover {
    background: var(--danger-light);
    color: var(--danger);
    border-color: var(--danger);
}

/* User Dropdown */
.user-dropdown-container {
    position: relative;
    display: inline-block;
}

.user-badge {
    cursor: pointer;
    user-select: none;
    transition: all var(--transition-fast);
}

.user-badge:hover {
    border-color: var(--primary-500);
    background: var(--primary-100);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: white;
    min-width: 200px;
    width: max-content;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    border: 1px solid var(--surface-200);
    z-index: 9999;
    padding: 6px 0;
    /* Rimosso overflow: hidden per evitare tagli */
}

.dropdown-item {
    display: block;
    padding: 10px 16px;
    color: var(--surface-700);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background var(--transition-fast);
    cursor: pointer;
}

.dropdown-item:hover {
    background: var(--surface-50);
    color: var(--primary-600);
}

.dropdown-divider {
    height: 1px;
    background: var(--surface-100);
    margin: 4px 0;
    border: none;
}

.logout-item:hover {
    background: var(--danger-light);
    color: var(--danger);
}

/* Modal System */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20000;
}

.modal-content {
    width: 100%;
    max-width: 450px;
    margin: auto;
    background: white;
    padding: 0;
    overflow: hidden;
    animation: modal-fade-in 0.3s ease-out;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--surface-100);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--surface-800);
}

.modal-body {
    padding: 1.5rem;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--surface-400);
    cursor: pointer;
    line-height: 1;
}

.btn-close:hover {
    color: var(--danger);
}

@keyframes modal-fade-in {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Accordion / Sections
   ============================================================ */
.section-accordion {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--card-radius);
    margin-bottom: 1.25rem;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal), border-color var(--transition-normal);
}

.section-accordion[open] {
    box-shadow: var(--card-shadow-hover);
    border-color: rgba(99, 102, 241, 0.25);
}

.accordion-summary {
    padding: 1.125rem 1.5rem;
    cursor: pointer;
    list-style: none;
    outline: none;
    display: flex;
    align-items: center;
    position: relative;
    transition: background var(--transition-fast);
    user-select: none;
}

.accordion-summary::-webkit-details-marker {
    display: none;
}

.accordion-summary::marker {
    display: none;
    content: "";
}

.accordion-summary:hover {
    background: var(--primary-50);
}

.accordion-summary::after {
    content: "▼";
    position: absolute;
    right: 1.5rem;
    font-size: 0.75rem;
    color: var(--surface-400);
    transition: transform var(--transition-normal);
}

.section-accordion[open] .accordion-summary::after {
    transform: rotate(180deg);
}

/* Sub-Accordion Layout */
.sub-accordion {
    background: rgba(255, 255, 255, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    margin-bottom: 0.75rem;
    overflow: visible !important;
    position: relative;
    box-shadow: none;
    transition: all var(--transition-normal);
}

.sub-accordion[open] {
    background: white;
    border-color: rgba(99, 102, 241, 0.2);
    box-shadow: var(--card-shadow);
}

.sub-accordion .sub-summary {
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--surface-800);
    cursor: pointer;
    list-style: none;
    outline: none;
    display: flex;
    align-items: center;
    position: relative;
    transition: background var(--transition-fast);
    user-select: none;
}

.sub-accordion .sub-summary::-webkit-details-marker {
    display: none;
}

.sub-accordion .sub-summary::marker {
    display: none;
    content: "";
}

.sub-accordion .sub-summary:hover {
    background: var(--surface-50);
}

.sub-accordion .sub-summary::after {
    content: "▼";
    position: absolute;
    right: 1.25rem;
    font-size: 0.7rem;
    color: var(--surface-400);
    transition: transform var(--transition-normal);
}

.sub-accordion[open] .sub-summary::after {
    transform: rotate(180deg);
}

.sub-content {
    padding: 1rem 1.25rem 1.25rem;
    border-top: 1px solid rgba(0, 0, 0, 0.04);
}

/* Sub-accordions specifiche per i 3 gruppi */
.sub-accordion.sub-dati {
    border-left: 4px solid var(--primary-500) !important;
}
.sub-accordion.sub-dati[open] {
    background: rgba(99, 102, 241, 0.02) !important;
    border-color: rgba(99, 102, 241, 0.15) !important;
    border-left-color: var(--primary-500) !important;
}
.sub-accordion.sub-dati .sub-summary {
    color: var(--primary-700) !important;
}

.sub-accordion.sub-regole {
    border-left: 4px solid var(--success) !important;
}
.sub-accordion.sub-regole[open] {
    background: rgba(16, 185, 129, 0.02) !important;
    border-color: rgba(16, 185, 129, 0.15) !important;
    border-left-color: var(--success) !important;
}
.sub-accordion.sub-regole .sub-summary {
    color: var(--success) !important;
}

.sub-accordion.sub-stop {
    border-left: 4px solid var(--warning) !important;
}
.sub-accordion.sub-stop[open] {
    background: rgba(245, 158, 11, 0.02) !important;
    border-color: rgba(245, 158, 11, 0.15) !important;
    border-left-color: var(--warning) !important;
}
.sub-accordion.sub-stop .sub-summary {
    color: var(--warning) !important;
}

.section-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--surface-800);
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin: 0;
}

.accordion-summary .section-title {
    margin-bottom: 0;
}

.section-content {
    padding: 0 1.5rem 1.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    padding-top: 1.25rem;
}

/* ============================================================
   Form Elements
   ============================================================ */
.form-label {
    display: block;
    font-weight: 700;
    color: var(--surface-800);
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.form-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    margin-bottom: 0.875rem;
}

.form-group {
    flex: 1;
}

.form-group-sm {
    flex: 0 0 auto;
}

/* Input fields */
.input-modern {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1.5px solid var(--surface-200);
    border-radius: 10px;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    background: white;
    color: var(--surface-800);
    transition: all var(--transition-fast);
    outline: none;
    box-sizing: border-box;
}

.input-modern:focus {
    border-color: var(--primary-400);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.input-modern::placeholder {
    color: var(--surface-400);
}

/* Buttons */
.btn-modern {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-sans);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-600), var(--primary-500));
    color: white;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(79, 70, 229, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-success {
    background: linear-gradient(135deg, #059669, var(--success));
    color: white;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
}

.btn-success:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1.5px solid var(--danger);
}

.btn-danger:hover {
    background: var(--danger-light);
    transform: translateY(-1px);
}

/* Button Loading State (Dash automatic) */
.btn-modern[data-dash-is-loading="true"] {
    position: relative;
    color: transparent !important;
    pointer-events: none;
    opacity: 0.8;
}

.btn-modern[data-dash-is-loading="true"]::after {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    top: calc(50% - 10px);
    left: calc(50% - 10px);
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: btn-spinner 0.6s linear infinite;
}

.btn-danger[data-dash-is-loading="true"]::after {
    border-top-color: var(--danger);
}

@keyframes btn-spinner {
    to { transform: rotate(360deg); }
}

.btn-ghost {
    background: transparent;
    color: var(--surface-500);
    border: 1.5px solid var(--surface-200);
}

.btn-ghost:hover {
    background: var(--surface-100);
    border-color: var(--surface-300);
}

/* Dropdown (Dash) overrides */
.dash-dropdown .Select-control {
    border: 1.5px solid var(--surface-200) !important;
    border-radius: 10px !important;
    box-shadow: none !important;
    height: auto !important;
    min-height: 40px !important;
}

.dash-dropdown .Select-control:hover {
    border-color: var(--primary-400) !important;
}

.dash-dropdown.is-focused .Select-control {
    border-color: var(--primary-400) !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15) !important;
}

.dash-dropdown .Select-placeholder,
.dash-dropdown .Select-value {
    line-height: 38px !important;
    padding-left: 12px !important;
    padding-right: 30px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
}

.dash-dropdown .Select-option,
.dash-dropdown .VirtualizedSelectOption,
.dash-dropdown div[class*="-option"] {
    padding: 10px 16px !important;
    font-size: 0.95rem !important;
    line-height: 1.3 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    border-bottom: 1px solid var(--surface-100) !important;
}

.dash-dropdown .Select-option:last-child,
.dash-dropdown .VirtualizedSelectOption:last-child,
.dash-dropdown div[class*="-option"]:last-child {
    border-bottom: none !important;
}

.dash-dropdown .Select-option.is-focused,
.dash-dropdown .VirtualizedSelectFocusedOption,
.dash-dropdown .VirtualizedSelectOption.is-focused,
.dash-dropdown div[class*="-option"]:hover,
.dash-dropdown div[class*="-option"][class*="--is-focused"] {
    background: var(--primary-50) !important;
    color: var(--primary-700) !important;
}

.dash-dropdown .Select-menu-outer,
.dash-dropdown div[class*="-menu"] {
    z-index: 11000 !important; /* Molto alto per coprire sia i calendari che i ticker */
    border: 1px solid var(--surface-200) !important;
    border-radius: 12px !important;
    box-shadow: var(--card-shadow-hover) !important;
    margin-top: 4px !important;
    min-width: 100% !important;
    width: max-content !important;
    max-width: 450px !important;
}

.dash-dropdown .Select-menu,
.dash-dropdown div[class*="-MenuList"],
.dash-dropdown div[class*="-menu"] > div {
    min-width: 100% !important;
    width: 100% !important;
}

/* DatePicker overrides */
.DateInput_input {
    border: 1.5px solid var(--surface-200) !important;
    border-radius: 10px !important;
    padding: 0.5rem 0.75rem !important;
    font-size: 0.875rem !important;
    font-family: var(--font-sans) !important;
    line-height: 1.4 !important;
}

.DateInput_input:focus {
    border-color: var(--primary-400) !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15) !important;
}

.SingleDatePickerInput,
.DateRangePickerInput {
    z-index: auto;
}

/* Solo il calendario aperto deve stare sopra tutto */
.SingleDatePicker_picker, 
.DateRangePicker_picker,
.SingleDatePicker_pickerPortal {
    z-index: 20000 !important;
}

.SingleDatePickerInput,
.DateRangePickerInput {
    border: 1.5px solid var(--surface-200) !important;
    border-radius: 10px !important;
    background: white !important;
    position: relative;
    z-index: 1001 !important;
}

/* Evita che le sezioni taglino i calendari e gestisce la profondità */
.section-accordion {
    overflow: visible !important;
    position: relative;
}

/* La prima sezione (filtri) deve stare sopra a quella sotto (upload/tabella) */
.section-accordion:first-of-type {
    z-index: 50;
}

.section-content,
.form-row,
.form-group,
.custom-tab,
.tab-content,
.section-accordion {
    overflow: visible !important;
    position: relative;
    z-index: auto; /* Evita di creare nuovi stacking contexts che bloccano i calendari */
}

.js-plotly-plot {
    z-index: 1 !important;
}

#range-bar-chart {
    height: 900px;
}

/* ============================================================
   Status Messages
   ============================================================ */
.status-box {
    padding: 0.625rem 1rem;
    border-radius: 10px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    color: var(--surface-500);
}

.status-success {
    color: var(--success);
    background: var(--success-light);
    border-color: rgba(16, 185, 129, 0.2);
}

.status-error {
    color: var(--danger);
    background: var(--danger-light);
    border-color: rgba(239, 68, 68, 0.2);
}

.status-info {
    color: var(--info);
    background: #eff6ff;
    border-color: rgba(59, 130, 246, 0.2);
}

/* ============================================================
   Upload Zone
   ============================================================ */
.upload-box {
    width: 100%;
    padding: 2.5rem !important;
    border: 2px dashed var(--surface-300) !important;
    border-radius: var(--card-radius) !important;
    text-align: center;
    cursor: pointer;
    background: white !important;
    transition: all var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px !important;
    line-height: 1.5 !important;
}

.upload-box:hover {
    border-color: var(--primary-400) !important;
    background: var(--primary-50) !important;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.upload-box:active {
    transform: scale(0.99);
}

.upload-text {
    font-size: 1rem;
    font-weight: 500;
    color: var(--surface-500);
}

.upload-link {
    color: var(--primary-600);
    font-weight: 600;
    text-decoration: none;
}

.upload-link:hover {
    text-decoration: underline;
}

/* ============================================================
    AI Agent Chat
    ============================================================ */
.ai-chat-box {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--surface-50);
    border-radius: 12px;
    border: 1px solid var(--surface-200);
    min-height: 400px;
    max-height: 600px;
    overflow-y: auto !important;
    overflow-x: hidden;
    flex: 1;
    /* Ensure scrollbar is always visible when needed */
    scrollbar-width: thin;
    scrollbar-color: var(--surface-300) transparent;
}

/* Webkit scrollbar for AI chat box */
.ai-chat-box::-webkit-scrollbar {
    width: 8px;
}

.ai-chat-box::-webkit-scrollbar-track {
    background: transparent;
    margin: 4px 0;
}

.ai-chat-box::-webkit-scrollbar-thumb {
    background: var(--surface-300);
    border-radius: 4px;
}

.ai-chat-box::-webkit-scrollbar-thumb:hover {
    background: var(--surface-400);
}

.ai-message {
    animation: message-slide-in 0.3s ease-out;
    flex-shrink: 0;
}

@keyframes message-slide-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-message-user {
    align-self: flex-end;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    max-width: 80%;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.ai-message-assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--surface-200);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    max-width: 90%;
    font-size: 0.95rem;
    line-height: 1.5;
    flex-shrink: 0;
}

.ai-message-system {
    padding: 1rem;
    border-radius: 12px;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.2);
    font-size: 0.95rem;
    line-height: 1.5;
    flex-shrink: 0;
}

.ai-message-error {
    align-self: flex-start;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    max-width: 90%;
    font-size: 0.9rem;
    color: var(--danger);
    flex-shrink: 0;
}

/* ── AI Chat Button (fixed width to prevent flickering) ── */
.ai-chat-btn {
    min-width: 120px !important;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

/* Disable Dash loading spinner on the AI chat button — keep text visible */
.ai-chat-btn[data-dash-is-loading="true"] {
    color: inherit !important;
    pointer-events: auto !important;
    opacity: 1 !important;
}

.ai-chat-btn[data-dash-is-loading="true"]::after {
    display: none !important;
    content: none !important;
    animation: none !important;
}

/* ── AI Status Panel ── */
.ai-status-panel {
    padding: 0.625rem 0.875rem;
    background: var(--surface-50);
    border: 1px solid var(--surface-200);
    border-radius: 10px;
    font-size: 0.82rem;
    color: var(--surface-600);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-height: 48px;
}

.ai-status-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.ai-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
    font-size: 0.78rem;
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    background: white;
    border: 1px solid var(--surface-200);
    white-space: nowrap;
}

.ai-status-badge.status-queued { color: var(--warning); border-color: rgba(245, 158, 11, 0.3); }
.ai-status-badge.status-started { color: var(--primary-600); border-color: rgba(99, 102, 241, 0.3); }
.ai-status-badge.status-finished { color: var(--success); border-color: rgba(16, 185, 129, 0.3); }
.ai-status-badge.status-failed { color: var(--danger); border-color: rgba(239, 68, 68, 0.3); }

.ai-status-timer {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--surface-400);
    white-space: nowrap;
}

.ai-status-message {
    font-size: 0.8rem;
    color: var(--surface-600);
    line-height: 1.4;
    font-style: italic;
}

.ai-status-job-id {
    font-size: 0.7rem;
    color: var(--surface-400);
    font-family: var(--font-mono);
}

/* ── Indeterminate Progress Bar ── */
.ai-progress-track {
    width: 100%;
    height: 4px;
    background: var(--surface-200);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 0.25rem;
}

.ai-progress-bar {
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, var(--primary-400), var(--primary-600));
    border-radius: 2px;
    animation: indeterminate-slide 1.5s ease-in-out infinite;
}

@keyframes indeterminate-slide {
    0% { transform: translateX(-100%); }
    50% { transform: translateX(150%); }
    100% { transform: translateX(-100%); }
}

/* ── Loading Dots Animation ── */
.ai-loading-dots::after {
    content: "";
    animation: loading-dots 1.5s steps(4, end) infinite;
}

@keyframes loading-dots {
    0% { content: ""; }
    25% { content: "."; }
    50% { content: ".."; }
    75% { content: "..."; }
    100% { content: ""; }
}

.control-section {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.control-section-title {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--surface-400);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin: 0 0 0.5rem 0;
    border-bottom: 1px solid var(--surface-100);
    padding-bottom: 0.5rem;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-item .control-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--surface-700);
    text-transform: none;
    letter-spacing: normal;
}

.switch-wrapper {
    padding: 0.5rem 0;
}

.btn-stack {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn-row {
    display: flex;
    gap: 0.5rem;
}

@media (max-width: 1100px) {
    .controls-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

.gann-origins-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.gann-origin-item {
    display: flex;
    align-items: center;
    background: white;
    border: 1px solid var(--surface-200);
    padding: 0.375rem 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--surface-700);
    box-shadow: 0 2px 4px rgba(0,0,0,0.04);
    transition: all var(--transition-fast);
}

.gann-origin-item:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.08);
    border-color: var(--primary-300);
}

.btn-remove-gann {
    background: none;
    border: none;
    color: var(--surface-400);
    margin-left: 10px;
    cursor: pointer;
    font-weight: bold;
    padding: 0 4px;
    transition: color var(--transition-fast);
}

.btn-remove-gann:hover {
    color: var(--danger);
}

/* ============================================================
   Utility Text Classes
   ============================================================ */
.text-error {
    color: var(--danger) !important;
    font-weight: 500;
}

.text-success {
    color: var(--success) !important;
    font-weight: 500;
}

.text-info {
    color: var(--info) !important;
    font-weight: 500;
}

/* ============================================================
   Toast Notifications
   ============================================================ */
.toast-container {
    position: fixed;
    top: 2rem;
    right: 2rem;
    z-index: 999999 !important;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast-notification {
    pointer-events: auto;
    min-width: 300px;
    padding: 1rem 1.25rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    border-left: 4px solid var(--primary-500);
    display: flex;
    align-items: center;
    gap: 0.875rem;
    animation: toast-enter 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    transition: all 0.3s ease;
}

.toast-notification.success { border-left-color: var(--success); }
.toast-notification.error { border-left-color: var(--danger); }
.toast-notification.info { border-left-color: var(--info); }

@keyframes toast-enter {
    from { transform: translateX(100%) scale(0.9); opacity: 0; }
    to { transform: translateX(0) scale(1); opacity: 1; }
}

.toast-exit {
    transform: translateX(100%);
    opacity: 0;
}

/* ============================================================
   Data Table
   ============================================================ */
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner table {
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 12px;
    overflow: hidden;
}

.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner th {
    background: linear-gradient(180deg, var(--surface-50), var(--surface-100)) !important;
    font-weight: 700 !important;
    color: var(--surface-700) !important;
    border-bottom: 2px solid var(--surface-200) !important;
    padding: 0.75rem 1rem !important;
    font-size: 0.8rem !important;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner td {
    padding: 0.625rem 1rem !important;
    border-bottom: 1px solid var(--surface-100) !important;
    color: var(--surface-700) !important;
    font-size: 0.85rem !important;
}

.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr:nth-child(even) td {
    background-color: var(--surface-50) !important;
}

.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr:hover td {
    background-color: var(--primary-50) !important;
}

/* Evidenziazione della riga selezionata (quando contiene una cella attiva/selezionata) */
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr:has(td.focused) td,
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr:has(td.cell--selected) td {
    background-color: var(--primary-100) !important;
    border-top: 1px solid var(--primary-300) !important;
    border-bottom: 1px solid var(--primary-300) !important;
}

/* Bordi laterali (sinistro e destro) per chiudere visivamente il rettangolo della riga selezionata */
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr:has(td.focused) td:first-child,
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr:has(td.cell--selected) td:first-child {
    border-left: 4px solid var(--primary-500) !important;
}

.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr:has(td.focused) td:last-child,
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr:has(td.cell--selected) td:last-child {
    border-right: 4px solid var(--primary-500) !important;
}

/* Rimuove le due sottili linee verticali rosa/blu della singola cella attiva focalizzata */
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner td.focused {
    outline: none !important;
}


/* ============================================================
   Modern Switch (Toggle)
   ============================================================ */
.switch-container {
    display: flex;
    align-items: center;
}

.modern-switch label {
    display: flex !important;
    align-items: center !important;
    cursor: pointer;
    gap: 12px;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--surface-700);
    line-height: 1;
    margin: 0 !important;
    padding: 4px 0;
}

.main-title {
    font-size: 1.8rem;
    font-weight: 800;
    margin: 0;
    letter-spacing: -0.025em;
    color: var(--surface-900);
    display: flex;
    align-items: center;
}

.header-logo {
    height: 42px;
    width: auto;
    margin-right: 12px;
    object-fit: contain;
}

/* Nasconde il checkbox originale */
.modern-switch input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 42px;
    height: 22px;
    background: var(--surface-200);
    border-radius: 20px;
    position: relative;
    cursor: pointer;
    transition: all var(--transition-normal);
    border: 1px solid var(--surface-300);
}

.modern-switch input[type="checkbox"]:checked {
    background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
    border-color: var(--primary-600);
}

.modern-switch input[type="checkbox"]::before {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: all var(--transition-normal);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.modern-switch input[type="checkbox"]:checked::before {
    left: 22px;
}

.modern-switch input[type="checkbox"]:hover {
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

/* ============================================================
   Login Page
   ============================================================ */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: relative;
    overflow: hidden;
}

.login-wrapper::before {
    content: '';
    position: absolute;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 20% 50%, rgba(255,255,255,0.1) 0%, transparent 50%),
                radial-gradient(circle at 80% 50%, rgba(255,255,255,0.08) 0%, transparent 50%);
    animation: loginBgShift 20s ease-in-out infinite alternate;
}

@keyframes loginBgShift {
    0% { transform: translate(-5%, -5%) rotate(0deg); }
    100% { transform: translate(5%, 5%) rotate(5deg); }
}

.login-card {
    position: relative;
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    animation: loginCardEnter 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes loginCardEnter {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo {
    display: block;
    margin-bottom: 1.5rem;
}

.login-logo-img {
    width: 120px;
    height: auto;
    margin: 0 auto;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,0.1));
}

.login-card h1 {
    text-align: center;
    font-size: 2rem;
    font-weight: 800;
    margin: 0;
    background: linear-gradient(135deg, var(--primary-600), #7c3aed);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.login-subtitle {
    text-align: center;
    color: var(--surface-500);
    font-size: 0.95rem;
    margin-top: 0.5rem;
    font-weight: 500;
}

.login-input {
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    border: 1.5px solid var(--surface-200);
    border-radius: 12px;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    background: rgba(255, 255, 255, 0.8);
    color: var(--surface-800);
    transition: all var(--transition-fast);
    outline: none;
    box-sizing: border-box;
}

.login-input:focus {
    border-color: var(--primary-400);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.login-input::placeholder {
    color: var(--surface-400);
}

.login-btn {
    width: 100%;
    padding: 0.875rem;
    margin-top: 1rem;
    background: linear-gradient(135deg, var(--primary-600), #7c3aed);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: 0 4px 16px rgba(79, 70, 229, 0.35);
    font-family: var(--font-sans);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
}

.login-btn svg {
    transition: transform var(--transition-fast);
}

.login-btn:hover svg {
    transform: translateX(4px);
}

.login-footer {
    text-align: center;
    margin-top: 2rem;
    font-size: 0.8rem;
    color: var(--surface-400);
    border-top: 1px solid var(--surface-100);
    padding-top: 1.5rem;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(79, 70, 229, 0.4);
}

.login-btn:active {
    transform: translateY(0);
}

/* ============================================================
   Animations
   ============================================================ */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(99, 102, 241, 0); }
}

.fade-in-up {
    animation: fadeInUp 0.4s ease-out;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    .main-container {
        padding: 1rem;
    }

    .app-header-inner {
        flex-direction: column;
        gap: 0.75rem;
    }

    .form-row {
        flex-direction: column;
    }

    .form-group-sm {
        flex: 1;
        width: 100%;
    }

    .section-content {
        padding: 0 1rem 1rem;
    }

    .accordion-summary {
        padding: 1rem;
    }
}

/* ============================================================
   Plotly Hover / Tooltip Overrides (indaco)
   ============================================================ */
.js-plotly-plot .hoverlayer .spikeline {
    stroke: #6366f1 !important;
    stroke-width: 1.5px !important;
    stroke-dasharray: 3, 3 !important;
}

.js-plotly-plot .hoverlayer .hoverlabel {
    background-color: #6366f1 !important;
    border-color: #ffffff !important;
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.3) !important;
}

/* Transizione fluida sui marker del grafico */
.js-plotly-plot .plotly .scatterlayer .trace .points path {
    transition: all 0.15s ease;
}
/* ============================================================
   Tabs Styling - Modern Minimalist Edition
   ============================================================ */
.custom-tabs {
    display: block !important;
    border: none !important;
    margin-bottom: 0px !important;
    background: transparent !important;
}

.custom-tabs-container {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-items: flex-end !important;
    gap: 10px 12px !important;
    width: 100% !important;
    height: auto !important;
    margin-bottom: 1.5rem !important;
    background: var(--surface-100) !important;
    border-radius: 12px 12px 0 0 !important;
    padding: 6px 8px 6px 8px !important;
    border-bottom: 1.5px solid var(--surface-200) !important;
}

.custom-tab {
    background: transparent !important;
    border: 1px solid transparent !important;
    border-radius: 8px 8px 0 0 !important;
    padding: 10px 16px !important;
    font-weight: 600 !important;
    font-size: 0.8rem !important;
    text-transform: uppercase !important;
    letter-spacing: 0.03em !important;
    color: var(--surface-600) !important;
    transition: all var(--transition-fast) !important;
    cursor: pointer !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    min-height: 40px !important;
    white-space: nowrap !important;
    margin-bottom: -1.5px !important;
    flex: none !important;
    width: auto !important;
}

.custom-tab:hover {
    color: var(--primary-600) !important;
    background: rgba(255, 255, 255, 0.5) !important;
}

.custom-tab--selected {
    background: white !important;
    color: var(--primary-600) !important;
    font-weight: 700 !important;
    border: 1px solid var(--surface-200) !important;
    border-bottom: 1.5px solid white !important;
    box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.03) !important;
}



.tab-content {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-top: none;
    border-radius: 0 0 16px 16px;
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
}

/* ============================================================
   Date Presets
   ============================================================ */
.date-presets {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.btn-preset {
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: var(--surface-700);
    padding: 4px 12px;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.btn-preset:hover {
    background: var(--primary-600);
    border-color: var(--primary-700);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-preset:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.2);
}

/* ============================================================
   Bar Inspector Modal (popup a destra)
   ============================================================ */
.inspector-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    z-index: 30000;
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    animation: overlayFadeIn 0.2s ease-out;
    pointer-events: none;
}

.inspector-overlay-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.2);
    pointer-events: auto;
    cursor: pointer;
    z-index: 30001;
}

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

.inspector-panel {
    width: 400px;
    max-width: 90vw;
    height: 100vh;
    background: white;
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.12);
    padding: 1.5rem;
    overflow-y: auto;
    animation: panelSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    pointer-events: auto;
    position: relative;
    z-index: 30002;
}

@keyframes panelSlideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.inspector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.inspector-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--surface-800);
    margin: 0;
}

.inspector-close-btn {
    background: var(--surface-100);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--surface-500);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.inspector-close-btn:hover {
    background: var(--danger-light);
    color: var(--danger);
}

.inspector-bar-info {
    padding: 1rem;
    background: var(--surface-50);
    border-radius: 10px;
    border: 1px solid var(--surface-200);
    margin: 0 0 0.5rem 0;
}

.inspector-bar-info h4 {
    margin: 0 0 8px 0;
    font-size: 1rem;
    color: var(--surface-800);
}

.inspector-bar-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    font-size: 0.85rem;
}

.inspector-bar-info-grid .label {
    color: var(--surface-400);
    font-weight: 600;
}

.inspector-bar-info-grid .value {
    color: var(--surface-700);
    font-weight: 600;
    text-align: right;
    font-family: var(--font-mono);
}

.inspector-objects-list {
    flex: 1;
    overflow-y: auto;
}

.inspector-empty-hint {
    text-align: center;
    color: var(--surface-400);
    font-size: 0.9rem;
    padding: 2rem 1rem;
    font-style: italic;
}

/* Oggetto ispezionabile (riga toggle) */
.inspector-object-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 0.75rem;
    border-radius: 8px;
    margin-bottom: 4px;
    background: var(--surface-50);
    border: 1px solid transparent;
    transition: all var(--transition-fast);
    cursor: default;
}

.inspector-object-item:hover {
    border-color: var(--surface-200);
    background: white;
}

.inspector-object-item .object-icon {
    font-size: 1rem;
    margin-right: 8px;
}

.inspector-object-item .object-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.inspector-object-item .object-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--surface-700);
}

.inspector-object-item .object-detail {
    font-size: 0.75rem;
    color: var(--surface-400);
    font-family: var(--font-mono);
}

/* Toggle miniaturizzato (usa la classe modern-switch esistente) */
.inspector-object-item .inspector-toggle {
    flex-shrink: 0;
}

.inspector-object-item .inspector-toggle input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 34px;
    height: 18px;
    background: var(--surface-200);
    border-radius: 16px;
    position: relative;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid var(--surface-300);
}

.inspector-object-item .inspector-toggle input[type="checkbox"]:checked {
    background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
    border-color: var(--primary-600);
}

.inspector-object-item .inspector-toggle input[type="checkbox"]::before {
    content: "";
    position: absolute;
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: all var(--transition-fast);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.inspector-object-item .inspector-toggle input[type="checkbox"]:checked::before {
    left: 18px;
}

/* Info Pill - Bar Inspector */
/* Info Pill - Bar Inspector */
.info-pill {
    position: absolute;
    top: -8px;
    left: -8px;
    width: 20px;
    height: 20px;
    background: #6366f1;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    cursor: help;
    transition: all 0.2s ease;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 10;
}

.info-pill:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 8px rgba(99, 102, 241, 0.3);
}

.inspector-object-item {
    position: relative; 
    margin-bottom: 12px;
}

#inspector-objects-list {
    padding: 10px 15px; /* Aggiunto padding laterale per evitare tagli alle pillole info */
}

/* Modal per Spiegazione Algoritmica */
.guide-modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.9) !important; /* Nero quasi totale per bloccare tutto */
    backdrop-filter: blur(10px) !important;
    display: none; 
    align-items: center;
    justify-content: center;
    z-index: 100000 !important; /* Valore insuperabile */
    pointer-events: auto !important;
}

.guide-modal-content {
    background: white;
    width: 90%;
    max-width: 650px;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
    position: relative;
    pointer-events: auto;
    animation: modalScaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.guide-close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--surface-100);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--surface-600);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 100001 !important;
}

.guide-close-btn:hover {
    background: var(--danger-light);
    color: var(--danger);
    transform: rotate(90deg);
}

/* ============================================================
   App Layout — Sidebar + Main Area (ADR-010)
   ============================================================ */
.app-layout {
    display: flex;
    min-height: calc(100vh - 2rem);
    max-width: 1440px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    gap: 0;
    position: relative;
}

.main-area {
    flex: 1;
    min-width: 0;
    padding: 0 0 0 1.5rem;
    transition: margin-left var(--transition-normal);
}

/* ============================================================
   Sidebar (Watchlist collassabile)
   ============================================================ */
.app-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    position: relative;
    display: flex;
    flex-direction: column;
    transition: width var(--transition-normal), min-width var(--transition-normal), opacity var(--transition-normal);
    overflow: hidden;
    max-height: calc(100vh - 2rem);
    position: sticky;
    top: 1rem;
}

/* Collassato */
.app-sidebar.collapsed {
    width: 48px;
    min-width: 48px;
}

.app-sidebar.collapsed .sidebar-content {
    opacity: 0;
    pointer-events: none;
    width: 0;
    overflow: hidden;
}

/* Toggle button */
.sidebar-toggle {
    position: absolute;
    top: 0.75rem;
    right: 0.5rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--surface-400);
    border-radius: 8px;
    transition: all var(--transition-fast);
    z-index: 10;
    user-select: none;
    background: var(--surface-50);
    border: 1px solid var(--surface-200);
}

.sidebar-toggle:hover {
    background: var(--primary-50);
    color: var(--primary-600);
    border-color: var(--primary-300);
}

.app-sidebar.collapsed .sidebar-toggle {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
}

/* Contenuto sidebar */
.sidebar-content {
    padding: 0.75rem;
    padding-top: 3rem; /* spazio per il toggle button */
    flex: 1;
    overflow-y: auto;
    transition: opacity var(--transition-fast);
}

.sidebar-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--surface-200);
}

.sidebar-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--surface-700);
}

/* Bottone "Aggiorna tutti" nell'header sidebar */
.sidebar-refresh-all {
    font-size: 0.85rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all var(--transition-fast);
    opacity: 0.6;
    margin-left: auto;
    line-height: 1;
}

.sidebar-refresh-all:hover {
    opacity: 1;
    background: var(--primary-50);
    transform: rotate(90deg);
}


/* Watchlist items container */
.sidebar-watchlist-items {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Singolo item watchlist */
.watchlist-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.625rem;
    border-radius: 8px;
    transition: all var(--transition-fast);
    cursor: default;
    border: 1px solid transparent;
    gap: 0.5rem;
}

.watchlist-item:hover {
    background: var(--primary-50);
    border-color: var(--primary-100);
}

.watchlist-item.active {
    background: var(--primary-100);
    border-color: var(--primary-300);
    box-shadow: inset 0 1px 3px rgba(79, 70, 229, 0.1);
}

/* Icona/Fallback per ticker nella watchlist */
.watchlist-item-icon {
    font-size: 0.85rem;
    opacity: 0.6;
}

/* Letter Avatar — fallback quando il logo FMP non è disponibile */
.letter-avatar {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 800;
    color: white;
    flex-shrink: 0;
    line-height: 1;
    user-select: none;
}

/* Wrapper per logo reale del ticker (per risaltare su sfondi chiari/scuri) */
.watchlist-item-logo-wrapper {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background-color: #334155; /* Slate-700: elegante colore scuro/medio per far risaltare sia il bianco che il nero */
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    padding: 3px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Logo reale del ticker (da FMP in cache locale) */
.watchlist-item-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 3px;
}


.watchlist-item-symbol {
    flex: 1;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--surface-700);
    font-family: var(--font-mono);
}

.watchlist-item-symbol:hover {
    color: var(--primary-600);
}

/* Bottone Visualizza Grafico (🔍) per ogni item watchlist */
.watchlist-item-view {
    font-size: 0.8rem;
    color: var(--surface-400);
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 4px;
    transition: all var(--transition-fast);
    opacity: 0;
}

.watchlist-item:hover .watchlist-item-view {
    opacity: 1;
}

.watchlist-item-view:hover {
    color: var(--primary-600);
    background: var(--primary-50);
}


.watchlist-item-remove {
    font-size: 0.75rem;
    color: var(--surface-400);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all var(--transition-fast);
    opacity: 0;
}

.watchlist-item:hover .watchlist-item-remove {
    opacity: 1;
}

.watchlist-item-remove:hover {
    color: var(--danger);
    background: var(--danger-light);
}

/* Icona refresh a fianco di ogni ticker */
.watchlist-item-refresh {
    font-size: 0.75rem;
    color: var(--surface-400);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all var(--transition-fast);
    opacity: 0;
}

.watchlist-item:hover .watchlist-item-refresh {
    opacity: 1;
}

.watchlist-item-refresh:hover {
    color: var(--primary-600);
    background: var(--primary-50);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.watchlist-item.updating {
    opacity: 0.8;
    background-color: var(--surface-50);
}

.watchlist-item.updating .watchlist-item-logo-wrapper,
.watchlist-item.updating .letter-avatar {
    display: none !important;
}

.watchlist-item.updating::before {
    content: "";
    width: 28px;
    height: 28px;
    border: 3px solid rgba(249, 115, 22, 0.2);
    border-top-color: #f97316;
    border-radius: 50%;
    box-sizing: border-box;
    display: inline-block;
    flex-shrink: 0;
    animation: spin 1s linear infinite;
}

.watchlist-item.updating .watchlist-item-refresh {
    color: var(--primary-600) !important;
    pointer-events: none;
}



/* Icona analisi intraday a fianco di ogni ticker */
.watchlist-item-intraday {
    font-size: 0.8rem;
    color: var(--surface-400);
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 4px;
    transition: all var(--transition-fast);
    opacity: 0;
}

.watchlist-item:hover .watchlist-item-intraday {
    opacity: 1;
}

.watchlist-item-intraday:hover {
    color: var(--warning, #f59e0b);
    background: rgba(245, 158, 11, 0.1);
}


.watchlist-empty {
    color: var(--surface-400);
    font-size: 0.85rem;
    text-align: center;
    padding: 1.5rem 0.5rem;
    font-style: italic;
}

/* Bottone watchlist-add nell'action row */
.btn-outline {
    background: transparent;
    color: var(--surface-600);
    border: 1.5px solid var(--surface-300);
    font-size: 0.8rem;
    padding: 0.5rem 0.875rem;
}

.btn-outline:hover {
    border-color: var(--primary-400);
    color: var(--primary-600);
    background: var(--primary-50);
}

/* Responsive: sidebar si collassa su mobile */
@media (max-width: 900px) {
    .app-sidebar:not(.collapsed) {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 5000;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        box-shadow: 0 0 40px rgba(0,0,0,0.15);
    }

    .main-area {
        padding: 0;
    }
}

/* Toggle button miniaturizzato (usato nell'ispettore) */

.inspector-toggle-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1.5px solid var(--surface-200);
    background: white;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    color: var(--surface-400);
}

.inspector-toggle-btn:hover {
    border-color: var(--primary-400);
    background: var(--primary-50);
}

.inspector-toggle-btn.active {
    background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
    border-color: var(--primary-600);
    color: white;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
}

/* Sezione gap nel pannello */
.inspector-gap-section {
    margin-top: 8px;
    padding: 10px;
    background: rgba(16, 185, 129, 0.06);
    border: 1px solid rgba(16, 185, 129, 0.15);
    border-radius: 8px;
}

.inspector-gap-section.gap-down {
    background: rgba(239, 68, 68, 0.06);
    border-color: rgba(239, 68, 68, 0.15);
}

.inspector-gap-section h5 {
    margin: 0 0 4px 0;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--surface-600);
}

/* Accordion per Medie Mobili (SMA) */
.sma-accordion {
    margin-top: 0.75rem;
    border: 1px solid var(--surface-200);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.4);
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.sma-accordion:hover {
    border-color: rgba(99, 102, 241, 0.25);
    background: rgba(255, 255, 255, 0.6);
}

.sma-accordion summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--surface-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    outline: none;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

.sma-accordion summary::-webkit-details-marker {
    display: none;
}

.sma-accordion summary::marker {
    display: none;
    content: "";
}

.sma-accordion summary::after {
    content: "▼";
    font-size: 0.65rem;
    color: var(--surface-400);
    transition: transform var(--transition-normal);
}

.sma-accordion[open] summary::after {
    transform: rotate(180deg);
}

.sma-accordion[open] {
    border-color: rgba(99, 102, 241, 0.25);
    background: rgba(255, 255, 255, 0.8);
}

/* Sezione inside days nel pannello */
.inspector-inside-days-section {
    margin-top: 8px;
    padding: 10px;
    background: rgba(99, 102, 241, 0.06);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: 8px;
}

.inspector-inside-days-section.declassed {
    background: rgba(245, 158, 11, 0.06);
    border-color: rgba(245, 158, 11, 0.15);
}

.inspector-inside-days-section.explosion {
    background: rgba(239, 68, 68, 0.06);
    border-color: rgba(239, 68, 68, 0.15);
}

.inspector-inside-days-section h5 {
    margin: 0 0 4px 0;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--surface-600);
}




/* ============================================================
   AI Log Modal — Enterprise Report Layout
   ============================================================ */

/* Wrapper */
.ai-log-report { font-family: var(--font-sans); color: var(--surface-800); }

/* ── Verdict Banner ── */
.ai-verdict-banner { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.25rem; border-radius: 10px; margin-bottom: 1.25rem; border: 1px solid transparent; }
.ai-verdict-banner.verdict-promote  { background: rgba(16,185,129,0.08); border-color: rgba(16,185,129,0.25); }
.ai-verdict-banner.verdict-hold     { background: rgba(99,102,241,0.08); border-color: rgba(99,102,241,0.25); }
.ai-verdict-banner.verdict-review   { background: rgba(245,158,11,0.08); border-color: rgba(245,158,11,0.25); }
.ai-verdict-banner.verdict-reject   { background: rgba(239,68,68,0.08);  border-color: rgba(239,68,68,0.25); }
.ai-verdict-badge { font-size: 0.7rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; padding: 0.25rem 0.65rem; border-radius: 20px; white-space: nowrap; }
.verdict-promote  .ai-verdict-badge { background: var(--success);     color: white; }
.verdict-hold     .ai-verdict-badge { background: var(--primary-500); color: white; }
.verdict-review   .ai-verdict-badge { background: var(--warning);     color: white; }
.verdict-reject   .ai-verdict-badge { background: var(--danger);      color: white; }
.ai-verdict-score { font-size: 2rem; font-weight: 800; line-height: 1; }
.verdict-promote  .ai-verdict-score { color: var(--success); }
.verdict-hold     .ai-verdict-score { color: var(--primary-500); }
.verdict-review   .ai-verdict-score { color: var(--warning); }
.verdict-reject   .ai-verdict-score { color: var(--danger); }
.ai-verdict-label { font-size: 0.78rem; color: var(--surface-500); margin-top: 2px; }
.ai-verdict-desc  { font-size: 0.85rem; color: var(--surface-700); line-height: 1.5; }

/* ── Section title ── */
.ai-report-section-title { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--surface-400); margin: 0 0 0.65rem 0; padding-bottom: 0.4rem; border-bottom: 1px solid var(--surface-100); }

/* ── Metrics Pills ── */
.ai-metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 0.6rem; margin-bottom: 1.25rem; }
.ai-metric-pill { background: var(--surface-50); border: 1px solid var(--surface-200); border-radius: 8px; padding: 0.6rem 0.75rem; text-align: center; }
.ai-metric-pill .metric-label { font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--surface-400); margin-bottom: 4px; }
.ai-metric-pill .metric-value { font-size: 1.05rem; font-weight: 700; color: var(--surface-800); }
.ai-metric-pill.metric-bad  .metric-value { color: var(--danger); }
.ai-metric-pill.metric-warn .metric-value { color: var(--warning); }
.ai-metric-pill.metric-ok   .metric-value { color: var(--success); }

/* ── Risk Flags ── */
.ai-risk-flags { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1.25rem; }
.ai-risk-flag { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.82rem; color: var(--surface-700); background: rgba(239,68,68,0.04); border-left: 3px solid var(--danger); padding: 0.45rem 0.65rem; border-radius: 0 6px 6px 0; }

/* ── Compliance Checks ── */
.ai-compliance-list { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 1.25rem; }
.ai-compliance-item { font-size: 0.82rem; color: var(--surface-700); padding: 0.3rem 0.5rem; border-radius: 4px; }
.ai-compliance-item.ok   { background: rgba(16,185,129,0.06); }
.ai-compliance-item.warn { background: rgba(245,158,11,0.06);  }

/* ── Action Cards ── */
.ai-actions-list { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.25rem; }
.ai-action-card { background: white; border: 1px solid var(--surface-200); border-radius: 10px; overflow: hidden; box-shadow: var(--card-shadow); }
.ai-action-header { display: flex; align-items: center; justify-content: space-between; padding: 0.65rem 0.85rem; background: var(--surface-50); border-bottom: 1px solid var(--surface-100); gap: 0.5rem; flex-wrap: wrap; }
.ai-action-param { font-size: 0.8rem; font-weight: 700; color: var(--surface-800); font-family: var(--font-mono); }
.ai-action-change { font-size: 0.75rem; display: flex; align-items: center; gap: 0.4rem; color: var(--surface-500); }
.ai-action-change .val-from { background: var(--danger-light); color: var(--danger); padding: 1px 6px; border-radius: 4px; font-weight: 600; font-family: var(--font-mono); }
.ai-action-change .val-to   { background: var(--success-light); color: var(--success); padding: 1px 6px; border-radius: 4px; font-weight: 600; font-family: var(--font-mono); }
.ai-action-arrow { color: var(--surface-400); }
.ai-action-body { padding: 0.65rem 0.85rem; }
.ai-action-rationale { font-size: 0.8rem; color: var(--surface-600); line-height: 1.5; margin-bottom: 0.35rem; }
.ai-action-effect { font-size: 0.75rem; color: var(--success); font-style: italic; }

/* ── Accordion JSON ── */
.ai-accordion { border: 1px solid var(--surface-200); border-radius: 8px; overflow: hidden; }
.ai-accordion-toggle { width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 0.65rem 0.85rem; background: var(--surface-50); border: none; cursor: pointer; font-size: 0.8rem; font-weight: 600; color: var(--surface-600); text-align: left; transition: background var(--transition-fast); font-family: var(--font-sans); }
.ai-accordion-toggle:hover { background: var(--surface-100); }
.ai-accordion-body { background: #0f172a; overflow-x: auto; max-height: 320px; overflow-y: auto; }
.ai-json-code { display: block; padding: 1rem 1.25rem; font-family: var(--font-mono); font-size: 0.78rem; line-height: 1.65; color: #e2e8f0; white-space: pre; margin: 0; }

/* ── Empty State ── */
.ai-log-empty { text-align: center; padding: 2.5rem 1rem; color: var(--surface-400); font-size: 0.9rem; }
.ai-log-empty .empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; display: block; }

/* ── Key Findings ── */
.ai-findings-list { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1.25rem; }
.ai-finding-item { font-size: 0.82rem; color: var(--surface-700); padding: 0.4rem 0.65rem 0.4rem 0.75rem; background: rgba(99,102,241,0.04); border-left: 3px solid var(--primary-400); border-radius: 0 6px 6px 0; line-height: 1.5; }

/* ── Hidden Tab to override display: flex !important ── */
.hidden-tab {
    display: none !important;
}

