/* ECAI Dashboard v5 — Allocator Styles */

/* ============ LEARN MODAL — Apple Glass ============ */
.learn-modal-card {
    background: white;
    border-radius: 20px;
    padding: 28px;
    width: 400px;
    max-width: 90vw;
    box-shadow: 0 24px 64px rgba(0,0,0,0.15), 0 8px 24px rgba(0,0,0,0.06);
    animation: learnModalIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes learnModalIn {
    0%   { opacity: 0; transform: scale(0.92) translateY(10px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.learn-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1.5px solid rgba(0,0,0,0.06);
    cursor: pointer;
    transition: all 0.15s ease;
    background: white;
}
.learn-option:hover {
    border-color: rgba(79,70,229,0.25);
    background: rgba(79,70,229,0.03);
}
.learn-option.selected {
    border-color: var(--primary);
    background: rgba(79,70,229,0.06);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.learn-option-radio {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,0.15);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}
.learn-option.selected .learn-option-radio {
    border-color: var(--primary);
    background: var(--primary);
}
.learn-option.selected .learn-option-radio::after {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: white;
}

.learn-option-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 18px;
}
.learn-option-icon.skip   { background: rgba(0,0,0,0.04); color: var(--text-muted); }
.learn-option-icon.exact  { background: rgba(79,70,229,0.08); color: var(--primary); }
.learn-option-icon.family { background: rgba(99,102,241,0.08); color: var(--primary-medium); }
.learn-option-icon.macro  { background: rgba(129,140,248,0.08); color: var(--primary-light); }

.learn-option-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
}
.learn-option-desc {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ============ VARIANCE TABLE — Apple Glass ============ */
.variance-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12.5px;
}
.variance-table th {
    padding: 10px 14px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    background: rgba(0,0,0,0.015);
    border-bottom: 1px solid rgba(0,0,0,0.06);
    white-space: nowrap;
    text-align: center;
}
.variance-table th:first-child {
    text-align: left;
    padding-left: 20px;
    position: sticky;
    left: 0;
    z-index: 2;
    background: rgba(247,248,252,0.98);
    backdrop-filter: blur(8px);
    min-width: 180px;
}
.variance-table th.var-ytd {
    background: rgba(79,70,229,0.04);
    color: var(--primary);
    font-weight: 800;
}
.variance-table td {
    padding: 12px 14px;
    text-align: center;
    border-bottom: 1px solid rgba(0,0,0,0.03);
    vertical-align: middle;
}
.variance-table td:first-child {
    text-align: left;
    padding-left: 20px;
    font-weight: 550;
    color: var(--text);
    position: sticky;
    left: 0;
    z-index: 1;
    background: rgba(255,255,255,0.96);
    backdrop-filter: blur(8px);
    min-width: 180px;
}
.variance-table .var-amount {
    font-weight: 600;
    font-size: 12px;
    color: var(--text);
}
.variance-table .var-pct {
    font-size: 10px;
    font-weight: 600;
    margin-top: 2px;
}
.variance-table .var-ytd-cell {
    background: rgba(79,70,229,0.02);
}
.variance-table .var-ytd-cell .var-amount {
    font-size: 13px;
    font-weight: 700;
}
.variance-table tbody tr:hover td {
    background: rgba(79,70,229,0.02);
}
.variance-table tbody tr:hover td:first-child {
    background: rgba(79,70,229,0.04);
}
.variance-table tfoot td {
    border-top: 2px solid rgba(0,0,0,0.06);
    border-bottom: none;
    font-weight: 700;
    background: rgba(0,0,0,0.015);
}
.variance-table tfoot td:first-child {
    background: rgba(0,0,0,0.025);
}
.variance-table tfoot .var-ytd-cell {
    background: rgba(79,70,229,0.05);
}
.variance-scroll::-webkit-scrollbar {
    height: 4px;
}
.variance-scroll::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
}
@media (max-width: 768px) {
    .variance-table th:first-child,
    .variance-table td:first-child {
        min-width: 140px;
        padding-left: 14px;
    }
    .variance-table th { padding: 8px 10px; font-size: 9px; }
    .variance-table td { padding: 10px 10px; }
    .variance-table .var-amount { font-size: 11px; }
    .variance-table .var-pct { font-size: 9px; }
}

/* ============ ALLOCATOR — BUDGET ENTRY ============ */

/* Header: mode selector + anno */
.budget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    gap: 16px;
    flex-wrap: wrap;
}

.budget-mode-selector {
    display: flex;
    gap: 4px;
    background: var(--glass-bg);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    min-height: 44px;
    border: none;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-muted);
    font-family: 'Montserrat', sans-serif;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}
.mode-btn .material-symbols-outlined {
    font-size: 16px;
}
.mode-btn:hover {
    color: var(--text-secondary);
    background: rgba(0,0,0,0.03);
}
.mode-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}

.budget-anno-selector {
    display: flex;
    align-items: center;
    gap: 4px;
}
.anno-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xs);
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-muted);
}
.anno-btn:hover {
    background: var(--glass-bg-strong);
    color: var(--text);
    box-shadow: var(--glass-shadow);
}
.anno-btn .material-symbols-outlined {
    font-size: 18px;
}
.anno-label {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    min-width: 52px;
    text-align: center;
}

/* Seasonality card */
.budget-seasonality-card {
    margin-bottom: 18px;
    padding: 20px 24px !important;
}
.seasonality-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    flex-wrap: wrap;
    gap: 8px;
}
.seasonality-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 6px;
}
.season-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.season-month {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.season-bar-track {
    width: 100%;
    height: 24px;
    background: rgba(0,0,0,0.03);
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
}
.season-bar-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, var(--primary-light), var(--primary));
    border-radius: 4px;
    transition: width 0.3s ease;
    min-height: 2px;
}
.season-input {
    width: 100%;
    text-align: center;
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 6px;
    padding: 8px 4px;
    min-height: 36px;
    font-family: 'Montserrat', sans-serif;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: rgba(255,255,255,0.6);
    transition: var(--transition);
}
.season-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.12);
}
.season-pct {
    font-size: 9px;
    color: var(--text-light);
}

/* Budget grid card */
.budget-grid-card {
    padding: 10px 4px !important;
    overflow: hidden;
}
.budget-grid-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Budget table */
.budget-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}
.budget-table th,
.budget-table td {
    padding: 0;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    white-space: nowrap;
}

.budget-th-sbu {
    text-align: left;
    padding: 14px 24px;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: rgba(0,0,0,0.015);
    position: sticky;
    left: 0;
    z-index: 2;
    backdrop-filter: blur(12px);
    min-width: 260px;
}
.budget-th-month,
.budget-th-quarter,
.budget-th-annual {
    text-align: center;
    padding: 12px 8px;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: rgba(0,0,0,0.015);
    min-width: 80px;
}
.budget-th-annual { min-width: 160px; }
.budget-th-quarter { min-width: 120px; }
.budget-th-total,
.budget-th-pct {
    text-align: right;
    padding: 14px 24px;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    background: rgba(0,0,0,0.025);
    min-width: 110px;
}

/* SBU name cell (sticky left) */
.budget-td-sbu {
    padding: 0 24px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
    height: 48px;
    position: sticky;
    left: 0;
    z-index: 1;
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(8px);
    min-width: 260px;
}
/* Fix: sticky td in table needs display:table-cell hack */
.budget-table tbody td:first-child,
.budget-table tfoot td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: rgba(255,255,255,0.95);
    min-width: 260px;
}

.sbu-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Input cells */
.budget-td-input {
    padding: 4px 3px;
}
.budget-input {
    width: 100%;
    text-align: right;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 10px 10px;
    min-height: 44px;
    font-family: 'Montserrat', sans-serif;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text);
    background: transparent;
    transition: var(--transition);
    min-width: 70px;
}
.budget-input:hover {
    background: rgba(0,0,0,0.02);
    border-color: rgba(0,0,0,0.06);
}
.budget-input:focus {
    outline: none;
    background: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.10);
}
.budget-input-annual,
.budget-input-quarter {
    font-size: 14px;
    font-weight: 600;
    padding: 10px 14px;
}

/* Totals */
.budget-td-total {
    text-align: right;
    padding: 10px 24px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
}
.budget-td-grand {
    text-align: right;
    padding: 10px 24px;
    font-size: 13px;
    font-weight: 700;
    color: var(--primary);
}
.budget-td-pct {
    text-align: center;
    padding: 10px 24px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
}

.budget-totals-row {
    background: rgba(0,0,0,0.02);
}
.budget-totals-row td {
    border-top: 2px solid rgba(0,0,0,0.08);
    border-bottom: none;
}

/* Row hover */
.budget-row:hover td {
    background: rgba(79, 70, 229, 0.02);
}
.budget-row:hover .budget-input {
    background: rgba(255,255,255,0.7);
    border-color: rgba(0,0,0,0.04);
}

/* Guide banner */
.budget-guide-banner {
    position: relative;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.04) 0%, rgba(129, 140, 248, 0.06) 100%);
    border: 1px solid rgba(79, 70, 229, 0.12);
    border-radius: var(--radius-md);
    padding: 24px 28px;
    margin-bottom: 18px;
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.guide-dismiss {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-light);
    cursor: pointer;
    transition: var(--transition);
}
.guide-dismiss:hover {
    background: rgba(0,0,0,0.06);
    color: var(--text);
}
.guide-dismiss .material-symbols-outlined {
    font-size: 16px;
}
.guide-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}
.guide-icon {
    font-size: 20px;
    color: var(--primary);
}
.guide-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}
.guide-steps {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}
.guide-step {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}
.guide-num {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    margin-top: 1px;
}
.guide-step strong {
    font-size: 12px;
    font-weight: 700;
    color: var(--text);
    display: block;
    margin-bottom: 3px;
}
.guide-step p {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 0;
}
.guide-highlight {
    display: inline-block;
    background: rgba(79, 70, 229, 0.08);
    border: 1px solid rgba(79, 70, 229, 0.15);
    border-radius: 4px;
    padding: 1px 6px;
    font-family: 'Montserrat', sans-serif;
    font-size: 10px;
    font-weight: 600;
    color: var(--primary);
}
@media (max-width: 1024px) {
    .guide-steps { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .guide-steps { grid-template-columns: 1fr; }
    .budget-guide-banner { padding: 18px 16px; }
}

/* Annual input cell — highlight for data entry */
.budget-td-annual-cell {
    background: rgba(79, 70, 229, 0.025) !important;
}
.budget-row:hover .budget-td-annual-cell {
    background: rgba(79, 70, 229, 0.05) !important;
}
.annual-input-wrap {
    display: flex;
    align-items: center;
    gap: 0;
    background: rgba(0,0,0,0.02);
    border: 1px dashed rgba(79, 70, 229, 0.18);
    border-radius: 8px;
    padding: 0 4px;
    transition: var(--transition);
}
.annual-input-wrap:focus-within {
    background: white;
    border-color: var(--primary);
    border-style: solid;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.10);
}
.annual-euro-sign {
    font-family: 'Montserrat', sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    padding-left: 10px;
    flex-shrink: 0;
    pointer-events: none;
}
.annual-input-wrap .budget-input-annual {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 10px 10px 6px;
}
.annual-input-wrap .budget-input-annual:focus {
    box-shadow: none !important;
}
.annual-input-wrap .budget-input-annual::placeholder {
    color: rgba(79, 70, 229, 0.25);
    font-weight: 400;
    font-size: 12px;
}

/* Consuntivo link banner */
.budget-link-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    margin-bottom: 14px;
    background: rgba(79, 70, 229, 0.04);
    border: 1px solid rgba(79, 70, 229, 0.10);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* SBU Link chips */
.sbu-link-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    font-family: 'Montserrat', sans-serif;
    font-size: 10px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    transition: var(--transition);
}
.sbu-link-chip .material-symbols-outlined {
    font-size: 12px;
}
.sbu-link-linked {
    background: rgba(5, 150, 105, 0.08);
    color: var(--success);
    cursor: default;
}
.sbu-link-new {
    background: rgba(0,0,0,0.03);
    color: var(--text-light);
    cursor: default;
}
.sbu-link-action {
    background: transparent;
    color: var(--primary);
    border: 1px dashed rgba(79, 70, 229, 0.25);
    cursor: pointer;
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 600;
}
.sbu-link-action:hover {
    background: rgba(79, 70, 229, 0.06);
    border-color: var(--primary);
}
.sbu-link-edit {
    display: inline-flex;
    align-items: center;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    margin-left: 2px;
    opacity: 0;
    transition: opacity 0.2s;
}
.sbu-link-edit .material-symbols-outlined {
    font-size: 11px;
    color: var(--text-light);
}
.sbu-link-chip:hover .sbu-link-edit {
    opacity: 0.6;
}
.sbu-link-edit:hover .material-symbols-outlined {
    color: var(--primary);
}

/* SBU Link dropdown */
.sbu-link-dropdown {
    position: fixed;
    z-index: 9999;
    min-width: 260px;
    background: white;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    overflow: hidden;
    animation: ddFadeIn 0.15s ease;
}
@keyframes ddFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.sbu-link-dd-header {
    padding: 10px 14px 6px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}
.sbu-link-dd-list {
    max-height: 220px;
    overflow-y: auto;
}
.sbu-link-dd-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 12px;
}
.sbu-link-dd-item:hover {
    background: rgba(79, 70, 229, 0.05);
}
.sbu-link-dd-name {
    flex: 1;
    font-weight: 600;
    color: var(--text);
}
.sbu-link-dd-ricavi {
    font-weight: 700;
    color: var(--primary);
    font-size: 11px;
}
.sbu-link-dd-badge {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 1px 6px;
    border-radius: 8px;
    background: rgba(79, 70, 229, 0.10);
    color: var(--primary);
}
.sbu-link-dd-auto {
    background: rgba(79, 70, 229, 0.06);
    border-left: 3px solid var(--primary);
}
.sbu-link-dd-used {
    opacity: 0.35;
}
.sbu-link-dd-used .sbu-link-dd-name {
    color: var(--text-muted);
    font-weight: 400;
}
.sbu-link-dd-used .sbu-link-dd-ricavi {
    color: var(--text-light);
    font-weight: 500;
}
.sbu-link-dd-new {
    border-top: 1px solid rgba(0,0,0,0.06);
    color: var(--text-muted);
}
.sbu-link-dd-new .sbu-link-dd-name {
    color: var(--text-muted);
    font-style: italic;
}

/* SBU name with link chip */
.sbu-name-wrap {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    position: relative;
}
.sbu-name-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
@media (max-width: 768px) {
    .sbu-name-wrap {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }
}

/* Actions bar */
.budget-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 18px;
    gap: 12px;
}

.budget-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Montserrat', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}
.budget-btn .material-symbols-outlined {
    font-size: 18px;
}
.budget-btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 16px rgba(79, 70, 229, 0.25);
}
.budget-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(79, 70, 229, 0.35);
}
.budget-btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}
.budget-btn-secondary {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    color: var(--text-muted);
    border: 1px solid var(--glass-border);
}
.budget-btn-secondary:hover {
    background: var(--glass-bg-strong);
    color: var(--text);
    box-shadow: var(--glass-shadow);
}

/* Toast notifications */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    background: var(--glass-bg-strong);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    box-shadow: var(--glass-shadow-elevated);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    transform: translateX(100%);
    opacity: 0;
    transition: all 0.3s cubic-bezier(.25,.46,.45,.94);
}
.toast .material-symbols-outlined {
    font-size: 20px;
}
.toast-show {
    transform: translateX(0);
    opacity: 1;
}
.toast-hide {
    transform: translateX(100%);
    opacity: 0;
}

/* Spin animation for save button */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.spin {
    animation: spin 1s linear infinite;
}

/* ============ ALLOCATOR — RULES PANEL (slide-in) ============ */

.rules-panel-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(0,0,0,0.2);
    backdrop-filter: blur(3px);
}
.rules-panel-overlay.show {
    display: block;
}

.rules-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 420px;
    max-width: 90vw;
    z-index: 510;
    background: var(--bg);
    box-shadow: -8px 0 40px rgba(0,0,0,0.12);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(.25,.46,.45,.94);
    display: flex;
    flex-direction: column;
}
.rules-panel.open {
    transform: translateX(0);
}

.rules-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    flex-shrink: 0;
}

.rules-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px;
}

.rules-panel-footer {
    flex-shrink: 0;
    padding: 12px 20px;
    border-top: 1px solid rgba(0,0,0,0.06);
    background: rgba(0,0,0,0.01);
}

.rule-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 12px;
    margin-bottom: 3px;
    transition: var(--transition);
}
.rule-item:hover {
    background: rgba(0,0,0,0.03);
}
.rule-item .rule-prefix {
    font-family: monospace;
    font-weight: 700;
    color: var(--text);
    min-width: 80px;
}
.rule-item .rule-sbu {
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 70px;
}
.rule-item .rule-note {
    flex: 1;
    font-size: 10.5px;
    color: var(--text-light);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rule-item .rule-delete {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}
.rule-item:hover .rule-delete {
    opacity: 1;
}

.rule-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 10px 0 4px;
    margin-top: 8px;
    border-top: 1px solid rgba(0,0,0,0.04);
}
.rule-section-label:first-child {
    margin-top: 0;
    border-top: none;
}

/* ============ ALLOCATOR — UPLOAD DROPZONE ============ */

.upload-dropzone {
    border: 2px dashed rgba(0,0,0,0.10);
    border-radius: var(--radius-lg);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: rgba(0,0,0,0.01);
}
.upload-dropzone:hover,
.upload-dropzone.dragover {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.03);
}

.hidden { display: none !important; }

/* ============ ALLOCATOR — REVIEW TABLE ============ */

.review-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}
.review-table th {
    padding: 10px 12px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: rgba(0,0,0,0.02);
    border-bottom: 1px solid rgba(0,0,0,0.06);
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 2;
}
.review-table td {
    padding: 6px 12px;
    border-bottom: 1px solid rgba(0,0,0,0.03);
    vertical-align: middle;
}
.review-row:hover td {
    background: rgba(79, 70, 229, 0.02);
}
.review-row[data-confidence="unclassified"] {
    background: rgba(245, 158, 11, 0.03);
}

.sbu-select {
    width: 100%;
    padding: 8px 8px;
    min-height: 36px;
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 6px;
    font-family: 'Montserrat', sans-serif;
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    background: white;
    cursor: pointer;
    transition: var(--transition);
}
.sbu-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
}

/* Confidence badges */
.conf-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 700;
}
.conf-prefix {
    background: rgba(37, 99, 235, 0.1);
    color: #2563eb;
}
.conf-keyword {
    background: rgba(5, 150, 105, 0.1);
    color: #059669;
}
.conf-description {
    background: rgba(8, 145, 178, 0.1);
    color: #0891b2;
}
.conf-manual {
    background: rgba(124, 58, 237, 0.1);
    color: #7c3aed;
}
.conf-unclassified {
    background: rgba(245, 158, 11, 0.15);
    color: #d97706;
}
.conf-learned {
    background: rgba(16, 185, 129, 0.12);
    color: #059669;
}
.conf-fallback {
    background: rgba(107, 114, 128, 0.12);
    color: #6b7280;
}
.conf-compound {
    background: rgba(124, 58, 237, 0.1);
    color: #7c3aed;
}

/* ============ ALLOCATOR RESPONSIVE ============ */
@media (max-width: 1024px) {
    .seasonality-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}
@media (max-width: 768px) {
    .budget-header {
        flex-direction: column;
        align-items: stretch;
    }
    .budget-mode-selector {
        justify-content: center;
    }
    .budget-anno-selector {
        justify-content: center;
    }
    .seasonality-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .budget-th-sbu,
    .budget-table tbody td:first-child,
    .budget-table tfoot td:first-child {
        min-width: 140px;
        font-size: 11px;
    }
    .budget-input {
        font-size: 12px;
        padding: 6px 6px;
        min-width: 60px;
    }
    .budget-actions {
        flex-direction: column;
    }
    .budget-actions > div {
        width: 100%;
    }
    .budget-btn {
        width: 100%;
        justify-content: center;
    }
    .toast-container {
        bottom: 16px;
        right: 16px;
        left: 16px;
    }
}
@media (max-width: 480px) {
    .mode-btn span:not(.material-symbols-outlined) {
        display: none;
    }
    .mode-btn {
        padding: 8px 12px;
    }
    .seasonality-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ============ CHART HEIGHTS MOBILE ============ */
@media (max-width: 768px) {
    #waterfall-chart,
    #gestioni-donut,
    #costi-bar,
    #sbu-revenue-chart,
    #sbu-margin-chart {
        height: 280px !important;
    }
    #sbuBarChart,
    #trendChart {
        height: 280px !important;
    }
    .data-table {
        font-size: 12px;
    }
    .data-table th,
    .data-table td {
        padding: 8px 6px;
    }

    /* Monitor KPI: 3 col → 1 col su mobile */
    #monitorKPI {
        grid-template-columns: 1fr !important;
    }
}

/* ============ ULTRA-SMALL PHONE (375px) ============ */
@media (max-width: 375px) {
    .kpi-grid {
        grid-template-columns: 1fr;
    }
    .kpi-value {
        font-size: 1.1rem;
    }
    .seasonality-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .budget-th-sbu,
    .budget-table tbody td:first-child,
    .budget-table tfoot td:first-child {
        min-width: 110px;
        font-size: 10px;
        padding: 8px 10px;
    }
    .budget-input {
        font-size: 11px;
        padding: 8px 6px;
        min-width: 55px;
    }
    .section-header h2 {
        font-size: 14px;
    }
    .topbar {
        padding-left: 54px;
        font-size: 12px;
    }
    .guide-steps {
        grid-template-columns: 1fr;
    }
}

/* ============ TABLE SCROLL WRAPPER ============ */
.table-scroll-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -14px;
    padding: 0 14px;
}

/* ============ SENSITIVITY MOBILE FIX ============ */
@media (max-width: 768px) {
    .sensitivity-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }
    .sensitivity-levers {
        position: static;
    }
    .sensitivity-kpi-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .sensitivity-slider {
        height: 8px;
    }
    .sensitivity-slider::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
        border-width: 3px;
    }
    .sensitivity-slider::-moz-range-thumb {
        width: 24px;
        height: 24px;
        border-width: 3px;
    }
    .sensitivity-slider-track {
        height: 36px;
    }
    #sensitivity-waterfall {
        height: 280px !important;
    }
}

/* ============ PRINT STYLES ============ */
@media print {
    body { overflow: visible !important; background: white !important; }
    .ambient-bg, .sidebar, .sidebar-toggle, .sidebar-overlay,
    .topbar, .export-dropdown, #sensitivity, .dash-footer { display: none !important; }
    .main-content {
        margin-left: 0 !important; margin-top: 0 !important;
        padding: 0 !important; height: auto !important;
        overflow: visible !important;
    }
    .content-inner { max-width: 100% !important; }
    .glass-card {
        background: white !important; backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
        break-inside: avoid; page-break-inside: avoid;
    }
    .glass-card::before { display: none !important; }
    .dash-section { break-inside: avoid; page-break-inside: avoid; }
    .kpi-card {
        background: white !important; backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
    }
    .animate-in { animation: none !important; opacity: 1 !important; }
    .section-tag { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; background: #f0f0f0 !important; }
    @page { margin: 1.5cm; size: A4; }
    /* Print header — set via JS before print */
    .print-header {
        display: block !important; font-size: 18px; font-weight: 700;
        margin-bottom: 16px; color: #1a1a1a;
        font-family: 'Montserrat', sans-serif;
    }
}

/* Hide export label on small topbars */
@media (max-width: 768px) {
    .export-btn-label { display: none; }
    .export-chevron { display: none; }
    .export-btn { padding: 8px 12px; min-height: 44px; }
}

/* ============ MANUAL ENTRY — Dati Manuali ============ */
.manual-entry-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    margin-left: auto;
    border: 1.5px solid #0EA5E9;
    border-radius: 10px;
    background: rgba(14, 165, 233, 0.06);
    color: #0284C7;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}
.manual-entry-btn:hover {
    background: rgba(14, 165, 233, 0.12);
    border-color: #0284C7;
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.15);
}
.manual-entry-btn.active {
    background: #0EA5E9;
    color: white;
    border-color: #0EA5E9;
    box-shadow: 0 2px 12px rgba(14, 165, 233, 0.3);
}

.manual-entry-panel {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s ease,
                margin-bottom 0.35s ease;
    margin-bottom: 0;
}
.manual-entry-panel.open {
    max-height: 400px;
    opacity: 1;
    margin-bottom: 20px;
}
.manual-entry-inner {
    padding: 18px 20px;
    background: rgba(14, 165, 233, 0.03);
    border: 1px solid rgba(14, 165, 233, 0.12);
    border-radius: 14px;
    backdrop-filter: blur(12px);
}
.manual-entry-fields {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 10px 14px;
}
.manual-entry-submit {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 20px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #B8860B, #DAA520, #C5941E);
    color: white;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 650;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(184, 134, 11, 0.3);
    transition: all 0.2s ease;
}
.manual-entry-submit:hover {
    box-shadow: 0 4px 16px rgba(184, 134, 11, 0.4);
    transform: translateY(-1px);
}
.manual-entry-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

@media (max-width: 768px) {
    .manual-entry-btn { margin-left: 0; width: 100%; justify-content: center; }
    .manual-entry-fields { grid-template-columns: 1fr; }
    .manual-entry-panel.open { max-height: 480px; }
}

/* ============ ADMIN MOBILE RESPONSIVE ============ */
@media (max-width: 768px) {
    /* Admin pages use inline styles — override for mobile */
    body[style*="overflow: auto"] .glass-card,
    .admin-container {
        padding: 16px 12px;
    }
}
@media (max-width: 600px) {
    /* Admin tables: horizontal scroll */
    .admin-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .admin-table-wrap table {
        min-width: 500px;
    }
}
