/*
 * PROTRACKER — Componenti UI
 * Tutti gli stili dei componenti riutilizzabili.
 */

a span { cursor:pointer; }
button span { cursor:pointer; }

/* ═══════════════════════════════════════════════════════════════════════════
   BOTTONI
   ═══════════════════════════════════════════════════════════════════════════ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /*gap: var(--space-2);*/
    padding: var(--space-2) var(--space-2);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    line-height: 1;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--transition-fast),
                border-color var(--transition-fast),
                color var(--transition-fast),
                box-shadow var(--transition-fast),
                transform var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
    min-height: 36px;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* Varianti */
.btn-primary {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
}
.btn-primary:hover {
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
    box-shadow: var(--shadow-accent);
}

.btn-secondary {
    background: var(--color-bg-elevated);
    color: var(--color-text-secondary);
    border-color: var(--color-border-default);
}
.btn-secondary:hover {
    background: var(--color-bg-overlay);
    color: var(--color-text-primary);
    border-color: var(--color-border-strong);
}

.btn-danger {
    background: var(--color-danger-subtle);
    color: var(--color-danger);
    border-color: transparent;
}
.btn-danger:hover {
    background: var(--color-danger);
    color: #fff;
}

.btn-success {
    background: var(--color-success-subtle);
    color: var(--color-success);
    border-color: transparent;
}
.btn-success:hover {
    background: var(--color-success);
    color: #fff;
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
    border-color: transparent;
}
.btn-ghost:hover {
    background: var(--color-bg-overlay);
    color: var(--color-text-primary);
}

.btn-outline {
    background: transparent;
    color: var(--color-accent);
    border-color: var(--color-accent);
}
.btn-outline:hover {
    background: var(--color-accent-subtle);
}

/* Dimensioni */
.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
    min-height: 28px;
    border-radius: var(--radius-sm);
}

.btn-lg {
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-base);
    min-height: 44px;
}

/* Icon-only */
.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-md);
}

.btn-icon.btn-sm {
    width: 28px;
    height: 28px;
}

/* Variante danger su btn-icon (ghost) — usata in tutte le tabelle per il delete */
.btn.btn-ghost.btn-icon.danger {
    color: var(--color-danger);
}

.btn.btn-ghost.btn-icon.danger:hover {
    background: var(--color-danger-subtle);
    color: var(--color-danger);
}

/* Variante standalone btn-icon--danger — usata in Eventi e PromotionEventsGrid */
.btn-icon--danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-danger);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.btn-icon--danger:hover {
    background: var(--color-danger-subtle);
    color: var(--color-danger);
}

.btn-icon--danger:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   FORM / INPUT
   ═══════════════════════════════════════════════════════════════════════════ */

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.form-label {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--color-text-secondary);
}

.form-label.required::after {
    content: ' *';
    color: var(--color-danger);
}

.form-control {
    width: 100%;
    padding: var(--space-2) var(--space-2);
    background: var(--color-bg-input);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    color: var(--color-text-primary);
    font-size: var(--text-sm);
    min-height: 36px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:hover {
    border-color: var(--color-border-strong);
}

.form-control:focus {
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px var(--color-accent-subtle);
    background: var(--color-bg-elevated);
}

.form-control::placeholder {
    color: var(--color-text-muted);
}

.form-control.is-invalid {
    border-color: var(--color-danger);
    box-shadow: 0 0 0 3px var(--color-danger-subtle);
}

.form-control.is-valid {
    border-color: var(--color-success);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238b93a8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    padding-right: var(--space-8);
    cursor: pointer;
}

select.form-control option {
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
}

/* #ANCORA-SEARCHABLE-SELECT: select custom con ricerca testuale nel menu. */
.searchable-select {
    position: relative;
    width: 100%;
    min-width: 0;
}

.searchable-select__control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    text-align: left;
    cursor: pointer;
}

.searchable-select__control::after {
    content: "";
    width: 8px;
    height: 8px;
    margin: -3px var(--space-1) 0 var(--space-2);
    border-right: 1.5px solid var(--color-text-muted);
    border-bottom: 1.5px solid var(--color-text-muted);
    transform: rotate(45deg);
    flex: 0 0 auto;
}

.searchable-select--clearable.searchable-select--has-value .searchable-select__control {
    padding: 0;
    padding-right: 34px;
}

.searchable-select--clearable.searchable-select--has-value .searchable-select__control::after {
    display: none;
}

.searchable-select__clear {
    position: absolute;
    top: 50%;
    right: 0px;
    width: 26px;
    height: calc(100% + 3px);
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    transform: translateY(-50%);
}

.searchable-select__clear::before,
.searchable-select__clear::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 1.5px;
    border-radius: 999px;
    background: currentColor;
}

.searchable-select__clear::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.searchable-select__clear::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

.searchable-select__clear:hover,
.searchable-select__clear:focus {
    color: var(--color-text-primary);
    background: var(--color-bg-surface);
    outline: none;
    height: calc(100% + 3px);
    border-radius: 0;
    opacity: 0.8;
}

.searchable-select__control:disabled {
    opacity: 0.55;
    cursor: default;
}

.searchable-select__value {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.searchable-select--with-images .searchable-select__value,
.searchable-select__selected-content,
.searchable-select__option-content {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.searchable-select--with-images .searchable-select__value,
.searchable-select__selected-content {
    width: 100%;
}

.searchable-select__selected-content--image-only {
    justify-content: center;
}

.searchable-select__selected-logo {
    display: block;
    width: var(--searchable-select-selected-logo-width, 64px);
    max-width: 100%;
    height: var(--searchable-select-selected-logo-height, 20px);
    aspect-ratio: auto;
    /* #ANCORA-BOOKMAKER-LOGO-CROP: fallback compatibile per eventuali loghi storici non ancora rigenerati. */
    object-fit: cover;
    object-position: center;
    flex: 0 0 var(--searchable-select-selected-logo-width, 64px);
    border-radius: 7px;
    border: 1px solid #404361;
}

.searchable-select--clearable.searchable-select--has-value.searchable-select--with-images {
    --searchable-select-selected-logo-width: 54px;
}

.searchable-select__option-logo {
    display: block;
    width: var(--searchable-select-option-logo-width, 38px);
    height: var(--searchable-select-option-logo-height, 18px);
    aspect-ratio: auto;
    object-fit: var(--searchable-select-option-logo-fit, contain);
    object-position: center;
    flex: 0 0 var(--searchable-select-option-logo-width, 38px);
    /* #ANCORA-BOOKMAKER-LOGO-SELECT: anche i loghi nel menu hanno i bordi arrotondati come il book selezionato. */
    border-radius: 7px;
}

.searchable-select__text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.searchable-select__control--empty .searchable-select__value {
    color: var(--color-text-muted);
}

.searchable-select__dropdown {
    position: fixed;
    z-index: calc(var(--z-modal) + 30);
    padding: var(--space-2);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.searchable-select__search {
    min-height: 32px;
    margin-bottom: var(--space-2);
}

.searchable-select__options {
    max-height: var(--searchable-select-max-height, 260px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.searchable-select__option {
    width: 100%;
    min-height: 30px;
    padding: var(--space-2);
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-primary);
    text-align: left;
    cursor: pointer;
}

.searchable-select__option:hover,
.searchable-select__option:focus,
.searchable-select__option.is-active,
.searchable-select__option.is-selected {
    background: var(--color-accent-subtle);
    color: var(--color-text-primary);
}

.searchable-select__option.is-active {
    outline: 1px solid var(--color-accent);
    outline-offset: -1px;
}

.searchable-select__empty {
    padding: var(--space-3) var(--space-2);
    color: var(--color-text-muted);
    font-size: var(--text-sm);
}

/* #ANCORA-BOOKMAKER-LOGO-COMMON: resa compatta condivisa per bookmaker in select e sola lettura. */
.bookmaker-select.searchable-select--with-images {
    --searchable-select-selected-logo-width: 65px;
    --searchable-select-selected-logo-height: 30px;
    --searchable-select-option-logo-width: 50px;
    --searchable-select-option-logo-height: 23px;
    --searchable-select-option-logo-fit: cover;
}

.bookmaker-select.searchable-select--clearable.searchable-select--has-value.searchable-select--with-images {
    --searchable-select-selected-logo-width: 65px;
}

/* Le immagini bookmaker non vengono ristrette in modo indipendente dall'altezza. */
.bookmaker-select .searchable-select__selected-logo {
    min-width: var(--searchable-select-selected-logo-width);
    max-width: var(--searchable-select-selected-logo-width);
}

.bookmaker-select .searchable-select__option-logo {
    min-width: var(--searchable-select-option-logo-width);
    max-width: var(--searchable-select-option-logo-width);
}

.bookmaker-select .searchable-select__control {
    min-height: 35px;
}

/* #ANCORA-BOOKMAKER-SELECT-LOGO-NOME: usa la larghezza del campo, anche nei modal su mobile. */
.bookmaker-select--adaptive-label {
    container-type: inline-size;
    container-name: bookmaker-selection;
}

@container bookmaker-selection (max-width: 199px) {
    .bookmaker-select--adaptive-label .searchable-select__selected-content {
        justify-content: center;
        gap: 0;
    }

    .bookmaker-select--adaptive-label .searchable-select__selected-content > .searchable-select__text {
        display: none;
    }
}

.bookmaker-select .searchable-select__options {
    gap: 4px;
}

.bookmaker-select .searchable-select__option {
    padding: 4px 8px;
}

.bookmaker-select--event-cell {
    width: 95px;
    min-width: 95px;
    max-width: 95px;
}

.bookmaker-select--event-cell .searchable-select__control {
    position: relative;
    min-height: 35px;
    padding: 0 21px 0 6px !important;
    gap: 0;
}

.bookmaker-select--event-cell .searchable-select__control::after {
    position: absolute;
    top: 50%;
    right: 8px;
    margin: -5px 0 0;
}

.bookmaker-logo-display {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    vertical-align: middle;
}

.bookmaker-logo-display--compact {
    width: 50px;
    min-width: 50px;
    max-width: 50px;
    height: 23px;
}

.bookmaker-logo-display--65x30.bookmaker-logo-display--compact {
    width: 65px;
    min-width: 65px;
    max-width: 65px;
    height: 30px;
}

.bookmaker-logo-display--75x35.bookmaker-logo-display--compact {
    width: 75px;
    min-width: 75px;
    max-width: 75px;
    height: 35px;
}

.bookmaker-logo-display--with-label {
    gap: var(--space-2);
    justify-content: flex-start;
    max-width: 100%;
}

.bookmaker-logo-display__image {
    display: block;
    width: 50px;
    max-width: 100%;
    height: 23px;
    aspect-ratio: auto;
    object-fit: cover;
    object-position: center;
    border-radius: 7px;
    border: 1px solid #404361;
}

.bookmaker-logo-display--65x30 .bookmaker-logo-display__image {
    width: 65px;
    height: 30px;
}

.bookmaker-logo-display--75x35 .bookmaker-logo-display__image {
    width: 75px;
    height: 35px;
    border-radius: 9px;
}

.bookmaker-logo-display__fallback {
    display: block;
    max-width: 100%;
    overflow: hidden;
    color: var(--color-text-primary);
    font-size: var(--text-xs);
    /*font-weight: var(--font-semibold);*/
    line-height: 1.1;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bookmaker-logo-display--50x23 .bookmaker-logo-display__fallback {
    width: 50px;
}

.bookmaker-logo-display--65x30 .bookmaker-logo-display__fallback {
    width: 65px;
    height: 30px;
}

.bookmaker-logo-display--75x35 .bookmaker-logo-display__fallback {
    width: 75px;
    height: 35px;
}

.bookmaker-logo-display__label {
    min-width: 0;
    overflow: hidden;
    color: var(--color-text-primary);
    font-size: var(--text-xs);
    /*font-weight: var(--font-semibold);*/
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bookmaker-logo-display--inline-small {
    width: 50px;
    min-width: 50px;
    max-width: 50px;
    height: 23px;
}

.bookmaker-logo-display--inline-small .bookmaker-logo-display__image {
    width: 50px;
    height: 23px;
    border-radius: 5px;
}

.bookmaker-logo-display--inline-small .bookmaker-logo-display__fallback {
    font-size: 10px;
}

.coverage-calculator-bookmaker-field {
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: var(--space-2);
}

.form-hint {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

.form-error {
    font-size: var(--text-xs);
    color: var(--color-danger);
}

/* Form layout helpers */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-4);
}

.form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border-subtle);
    margin-top: var(--space-4);
}

/* ═══════════════════════════════════════════════════════════════════════════
   CARD
   ═══════════════════════════════════════════════════════════════════════════ */

.card {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border-subtle);
    gap: var(--space-3);
}

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

.card-subtitle {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    margin-top: 2px;
}

.card-body {
    padding: var(--space-1) var(--space-5);
}

.card-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border-subtle);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
}

/* Stat card (per KPI/metriche) */
.stat-card {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    position: relative;
    overflow: hidden;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.stat-card:hover {
    border-color: var(--color-border-default);
    box-shadow: var(--shadow-md);
}

.stat-card__label {
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: var(--space-2);
}

.stat-card__value {
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
    color: var(--color-text-primary);
    letter-spacing: -0.03em;
    font-family: var(--font-mono);
}

.stat-card__value.positive { color: var(--color-profit); }
.stat-card__value.negative { color: var(--color-loss); }
.stat-card__value.pending  { color: var(--color-pending); }

.stat-card__delta {
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    margin-top: var(--space-1);
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-card__delta.up   { color: var(--color-profit); }
.stat-card__delta.down { color: var(--color-loss); }

/* ═══════════════════════════════════════════════════════════════════════════
   TABELLA
   ═══════════════════════════════════════════════════════════════════════════ */

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border-subtle);
}

/* Tabella a altezza fissa: scrolla sia verticalmente che orizzontalmente
   senza mai superare il viewport. thead rimane sticky in cima grazie alla
   regola esistente (.table thead { position: sticky; top: 0 }).
   Usa questa classe su .table-wrapper quando la tabella può essere
   sia molto lunga che molto larga contemporaneamente.
   --table-header-offset: sovrascrivibile inline per pagine con tab bar o filtri aggiuntivi */
.table-wrapper--scrollable {
    --table-header-offset: 0px;
    max-height: calc(
        100vh
        - var(--topbar-height)       /* 56px  — topbar fissa */
        - var(--space-6)             /* 24px  — padding-top content-inner */
        - var(--space-6)             /* 24px  — padding-bottom content-inner */
        - 80px                       /* ~page-header (titolo + sottotitolo) */
        - var(--table-header-offset) /* extra per tab bar, filtri, card-header, ecc. */
    );
    overflow-y: auto;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
    overflow: clip;
}

.table thead {
    background: var(--color-bg-elevated);
    position: sticky;
    top: 0;
    z-index: 1;
}

.table thead th {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--color-text-primary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--color-border-default);
    white-space: nowrap;
    min-height: var(--table-header-height);
    user-select: none;
}

.table thead th.sortable {
    cursor: pointer;
    transition: color var(--transition-fast);
}

.table thead th.sortable:hover {
    color: var(--color-text-primary);
}

.table thead th.th-right,
.table td.td-right  { text-align: right; }

.table thead th.th-center,
.table td.td-center { text-align: center; }

/*.table thead th.th-date {width:152px;}*/

.table tbody tr {
    border-bottom: 1px solid var(--color-border-subtle);
    transition: background var(--transition-fast);
    height: 37px;
}

.table tbody tr:last-child {
    border-bottom: none;
}

.table tbody tr:hover {
    background: var(--color-bg-overlay);
}

.table tbody tr.selected {
    background: var(--color-accent-subtle);
}

.table td {
    padding: var(--space-3) var(--space-4);
    color: var(--color-text-secondary);
    min-height: var(--table-row-height);
    white-space: nowrap;
    vertical-align: middle;
}

.table td.td-primary {
    color: var(--color-text-primary);
    font-weight: var(--font-medium);
}

.table td.td-mono {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
}

/* #ANCORA-GRIGLIA-BONUS-CONDIVISA: Bonus e confronto piani usano gli stessi bordi e colori. */
.table.bonus-grid { font-size:var(--text-sm); }
.table.bonus-grid > thead > tr > th { background:var(--color-bg-elevated); color:var(--color-text-primary); border-bottom:1px solid var(--color-border-default); }
.table.bonus-grid > tbody > tr { height:42px; border-top:1px solid var(--color-border-subtle); border-bottom:0; }
.table.bonus-grid > tbody > tr > td { color:var(--color-text-primary); border-bottom:0; }
.table.bonus-grid > thead > tr > th:not(:first-child),
.table.bonus-grid > tbody > tr > td:not(:first-child) { border-left:1px solid var(--color-border); }

/* Valore finanziario in tabella */
.money {
    font-family: var(--font-mono);
    font-weight: var(--font-medium);
    font-size: var(--text-sm);
}
.money.positive { color: var(--color-profit); }
.money.negative { color: var(--color-loss); }
.money.neutral  { color: var(--color-neutral); }
.money.pending  { color: var(--color-pending); }
.money.masked   { color: var(--color-text-muted); }

/* #ANCORA-GRID-NUMERIC-TYPOGRAPHY: sans di base, mono solo con classi esplicite sui valori numerici/date. */
:where(
    .table,
    .pivot,
    .sc-pivot,
    [role="grid"],
    [role="table"],
    [role="list"],
    [class*="table"],
    [class*="grid"],
    [class*="list"],
    [class*="pivot"]
) {
    font-family: var(--font-sans);
}

:where(
    .table,
    .pivot,
    .sc-pivot,
    [role="grid"],
    [role="table"],
    [role="list"],
    [class*="table"],
    [class*="grid"],
    [class*="list"],
    [class*="pivot"]
) :where(th, td, div, span, label, small, strong, input, select, textarea, button) {
    font-family: var(--font-sans);
}

.numeric-value,
.date-value,
.time-value,
.integer-value,
.decimal-value,
.percent-value,
.bonus-summary__value,
.bonus-filter-badge,
.coverage-split-table__money,
.calculated-event-split-table__money,
.payroll-money,
.report-cell--money,
.advanced-report-kpi__number,
.advanced-report-rank-row__money,
.locked-balance-candidate-row__amount,
.promo-money,
.promo-money--positive,
.promo-money--negative,
.promo-money--zero,
.money:not(.masked),
.td-mono,
.mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

.money.masked {
    font-family: var(--font-sans);
}

/* ═══════════════════════════════════════════════════════════════════════════
   BADGE
   ═══════════════════════════════════════════════════════════════════════════ */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px var(--space-2);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    border-radius: var(--radius-full);
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.badge-success { background: var(--color-success-subtle); color: var(--color-success); }
.badge-danger  { background: var(--color-danger-subtle);  color: var(--color-danger); }
.badge-warning { background: var(--color-warning-subtle); color: var(--color-warning); }
.badge-info    { background: var(--color-info-subtle);    color: var(--color-info); }
.badge-neutral { background: var(--color-bg-elevated);    color: var(--color-text-muted); }
.badge-accent  { background: var(--color-accent-subtle);  color: var(--color-accent); }

/* ═══════════════════════════════════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════════════════════════════════ */

.modal--hidden { display: none; }

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

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

/* #ANCORA-CALCULATED-EVENT-WIZARD */
.modal-overlay.calculated-event-nested-overlay {
    z-index: calc(var(--z-modal) + 20);
}

.modal {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 560px;
    max-height: calc(100dvh - (var(--space-6) * 2));
    min-height: 0;
    overflow: hidden;
    background-color: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    animation: slideInDown var(--transition-normal);
    isolation: isolate;
}

.modal--sm { max-width: 400px; }
.modal--md { max-width: 640px; }
.modal--lg { max-width: 860px; }
.modal--xl { max-width: 1100px; }

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--color-border-subtle);
    gap: var(--space-4);
    flex: 0 0 auto;
    background-color: var(--color-bg-surface);
    position: relative;
    z-index: 1;
}

.modal-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--color-text-primary);
    letter-spacing: -0.02em;
}

.modal-close {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-subtle);
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.modal-close:hover {
    background: var(--color-danger-subtle);
    color: var(--color-danger);
    border-color: var(--color-danger);
}

.modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: var(--space-6);
    background-color: var(--color-bg-surface);
}

.modal-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--color-border-subtle);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
    flex: 0 0 auto;
    background-color: var(--color-bg-surface);
    position: relative;
    z-index: 1;
}
.modal--sm { max-width: 400px; }
.modal--md { max-width: 640px; }
.modal--lg { max-width: 860px; }
.modal--xl { max-width: 1100px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px var(--space-5);
    border-bottom: 1px solid var(--color-border-subtle);
    gap: var(--space-4);
}

.modal-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--color-text-primary);
    letter-spacing: -0.02em;
}

.modal-close {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-subtle);
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.modal-close:hover {
    background: var(--color-danger-subtle);
    color: var(--color-danger);
    border-color: var(--color-danger);
}

.modal-body {
    padding: var(--space-6);
}

.modal-footer {
    padding: 8px var(--space-5);
    border-top: 1px solid var(--color-border-subtle);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.modal-footer .btn {
    width: 80px;
}
.modal-footer .btn.btn-ghost {
    border: 1px solid;
}

.modal-footer .btn.btn-wide {
    width: auto;
    padding-left: var(--space-4);
    padding-right: var(--space-4);
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOAST / NOTIFICHE
   ═══════════════════════════════════════════════════════════════════════════ */

.toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    z-index: var(--z-toast);
    pointer-events: none;
    max-width: 380px;
    width: 100%;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    pointer-events: all;
    animation: slideInRight var(--transition-normal);
    transition: opacity var(--transition-normal), transform var(--transition-normal);
    border-left-width: 3px;
}

.toast.exiting {
    opacity: 0;
    transform: translateX(20px);
}

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

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    margin-top: 1px;
}

.toast-success .toast-icon { color: var(--color-success); }
.toast-error   .toast-icon { color: var(--color-danger); }
.toast-warning .toast-icon { color: var(--color-warning); }
.toast-info    .toast-icon { color: var(--color-info); }

.toast-message {
    flex: 1;
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    line-height: var(--leading-normal);
}

.toast-close {
    width: 20px;
    height: 20px;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color var(--transition-fast);
}

.toast-close:hover { color: var(--color-text-primary); }

/* ═══════════════════════════════════════════════════════════════════════════
   LOADING
   ═══════════════════════════════════════════════════════════════════════════ */

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-border-default);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.spinner--sm  { width: 14px; height: 14px; border-width: 2px; }
.spinner--lg  { width: 32px; height: 32px; border-width: 3px; }

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(13, 15, 20, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
    z-index: 10;
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--color-bg-elevated) 25%,
        var(--color-bg-overlay) 50%,
        var(--color-bg-elevated) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

/* ═══════════════════════════════════════════════════════════════════════════
   TABS (sottopagine tipo DashBook)
   ═══════════════════════════════════════════════════════════════════════════ */

.tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border-subtle);
    gap: 30px;
    overflow-x: auto;   /* scorrimento orizzontale se i tab non ci stanno */
    overflow-y: hidden; /* niente scroll verticale */
    background: var(--color-bg-base);
    flex-shrink: 0;     /* non si comprime mai in altezza */
}

/* Nasconde la scrollbar orizzontale dei tab ma mantiene la funzionalità */
/*.tabs::-webkit-scrollbar { display: none; }
.tabs { scrollbar-width: none; }*/

/* Tab bar sticky — .content è lo scroll container, sticky funziona rispetto a lui.
   margin-top negativo = compensa il padding-top del content-inner
   così i tab partono visivamente a filo col bordo, ma hanno ancora spazio
   nel flusso per attivare lo sticky quando si scrolla */
.tabs--sticky {
    position: sticky;
    top: 0;
    z-index: var(--z-dropdown);
    background: var(--color-bg-base);
    margin-top: calc(-1 * var(--space-6));   /* sale su di padding-top */
    margin-left: calc(-1 * var(--space-6));
    margin-right: calc(-1 * var(--space-6));
    /*padding-top: var(--space-6);*/             /* ripristina lo spazio sopra il bordo tab */
    padding-left: var(--space-6);
    padding-right: var(--space-6);
}

.tab-item {
    display: flex;
    align-items: center;
    /*justify-content: center;*/  /* testo centrato */
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--transition-fast), border-color var(--transition-fast);
    text-decoration: none;
    margin-bottom: -1px;
    /* Preoccupa già lo spazio del testo in bold tramite ::after invisibile,
       così quando diventa active il layout non si sposta */
   /* flex: 1; */                 /* tutti i tab si dividono lo spazio equamente */
   /* min-width: 0;  */           /* evita overflow su tab con testo lungo */
    position: relative;
}

/* Pseudo-elemento con il testo bold "prenotato" — invisibile, serve solo per la larghezza */
/*.tab-item::after {*/
    /*content: attr(data-label);*/
    /*font-weight: var(--font-semibold);
    visibility: hidden;
    overflow: hidden;
    height: 0;
    display: block;
    pointer-events: none;
    user-select: none;
}*/

.tab-item:hover {
    color: var(--color-text-secondary);
}

.tab-item.active,
.tab-item:global(.active) {
    color: var(--color-accent);
    border-bottom-color: var(--color-accent);
    font-weight: var(--font-semibold);
}

/* ═══════════════════════════════════════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════════════════════════════════════ */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-16) var(--space-8);
    text-align: center;
    color: var(--color-text-muted);
    gap: var(--space-3);
}

.empty-state__icon {
    width: 48px;
    height: 48px;
    opacity: 0.4;
    margin-bottom: var(--space-2);
}

.empty-state__title {
    font-size: var(--text-base);
    font-weight: var(--font-medium);
    color: var(--color-text-secondary);
}

.empty-state__desc {
    font-size: var(--text-sm);
    max-width: 360px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   FILTER BAR (barra di filtri sopra le tabelle)
   ═══════════════════════════════════════════════════════════════════════════ */

.filter-bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    padding: var(--space-4) 0 var(--space-4);
}

.filter-bar .form-control {
    min-width: 160px;
    max-width: 220px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   DIVIDER
   ═══════════════════════════════════════════════════════════════════════════ */

.divider {
    height: 1px;
    background: var(--color-border-subtle);
    margin: var(--space-4) 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOOLTIP
   ═══════════════════════════════════════════════════════════════════════════ */

[data-tooltip] {
    position: relative;
}

/* #ANCORA-TOOLTIP-PUNTATORE-CONDIVISO: Saldi Conti e Dashbook, stile del Comparatore. */
.pt-pointer-tooltip {
    --pointer-tooltip-color: var(--color-warning);
    position: fixed;
    z-index: 9998;
    display: none;
    max-width: calc(100vw - 16px);
    padding: var(--space-1) var(--space-2);
    pointer-events: none;
    border: 1px solid var(--pointer-tooltip-color);
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--pointer-tooltip-color) 14%, var(--color-bg-elevated));
    box-shadow: var(--shadow-md);
    color: var(--pointer-tooltip-color);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.3;
}
.pt-pointer-tooltip[data-tone="danger"] {
    --pointer-tooltip-color: var(--color-loss);
}
.pt-pointer-tooltip[data-tone="accent"] {
    --pointer-tooltip-color: var(--color-accent);
}
.pt-pointer-tooltip.is-visible { display: block; }

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-default);
    color: var(--color-text-primary);
    font-size: var(--text-xs);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: var(--z-dropdown);
    box-shadow: var(--shadow-md);
}

[data-tooltip]:hover::after {
    opacity: 1;
}

/* ═══════════════════════════════════════════════════════════════════════════
   ALERT (per messaggi inline in pagina)
   ═══════════════════════════════════════════════════════════════════════════ */

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid;
    font-size: var(--text-sm);
}

.alert-success { background: var(--color-success-subtle); border-color: var(--color-success); color: var(--color-success); }
.alert-error   { background: var(--color-danger-subtle);  border-color: var(--color-danger);  color: var(--color-danger); }
.alert-warning { background: var(--color-warning-subtle); border-color: var(--color-warning); color: var(--color-warning); }
.alert-info    { background: var(--color-info-subtle);    border-color: var(--color-info);    color: var(--color-info); }

/* ═══════════════════════════════════════════════════════════════════════════
   GRID DI CARD (responsive)
   ═══════════════════════════════════════════════════════════════════════════ */

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--space-4);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-4);
}

/* ═══════════════════════════════════════════════════════════════════════════
   BLAZOR ERROR UI override
   ═══════════════════════════════════════════════════════════════════════════ */

#blazor-error-ui {
    background: var(--color-danger);
    color: #fff;
    padding: var(--space-3) var(--space-5);
    font-size: var(--text-sm);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-toast);
    display: none;
}

#blazor-error-ui .reload { color: #fff; margin-left: var(--space-4); font-weight: var(--font-semibold); }
#blazor-error-ui .dismiss { float: right; cursor: pointer; }

/* ═══════════════════════════════════════════════════════════════════════════
   AI CHAT PANEL
   ═══════════════════════════════════════════════════════════════════════════ */

/* Pulsante trigger attivo */
.ai-trigger--active {
    background: var(--color-accent-subtle);
    color: var(--color-accent);
}

/* Overlay scuro dietro il pannello */
.ai-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: calc(var(--z-modal) - 1);
    animation: fadeIn var(--transition-fast);
}

/* Pannello slide-in dalla destra */
.ai-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 380px;
    max-width: 100vw;
    background: var(--color-bg-surface);
    border-left: 1px solid var(--color-border-default);
    display: flex;
    flex-direction: column;
    z-index: var(--z-modal);
    transform: translateX(100%);
    transition: transform var(--transition-normal);
    box-shadow: var(--shadow-xl);
}

.ai-panel--open {
    transform: translateX(0);
}

/* #ANCORA-AI-CHAT-SEPARATE-UI: controlli ed editor hanno scroll interno esplicito. */
.ai-panel--conversations { width: 620px; height: 100dvh; }
.ai-panel--conversations .ai-panel__messages { min-height: 0; overflow-wrap: anywhere; }
.ai-conversation-toolbar { max-height: 30dvh; overflow-y: auto; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-subtle); flex-shrink: 0; }
.ai-conversation-toolbar label, .ai-conversation-editor label { display: block; margin-bottom: var(--space-2); font-size: var(--text-xs); }
.ai-conversation-toolbar select { width: 100%; min-width: 0; }
.ai-conversation-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-2) 0; }
.ai-conversation-actions button { white-space: normal; }
.ai-conversation-note { display: block; color: var(--color-text-muted); font-size: var(--text-xs); white-space: normal; }
.ai-conversation-notice { padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--color-border-subtle); color: var(--color-text-primary); font-size: var(--text-xs); max-height: 100px; overflow-y: auto; flex-shrink: 0; }
.ai-conversation-editor { padding: var(--space-3) var(--space-4); max-height: 48dvh; overflow-y: auto; flex-shrink: 1; min-height: 100px; border-bottom: 1px solid var(--color-border-subtle); }
.ai-conversation-editor h3 { font-size: var(--text-sm); }
.ai-conversation-editor textarea { resize: vertical; min-height: 70px; width: 100%; }
.ai-memory-fact { padding: var(--space-2); margin: var(--space-2) 0; border: 1px solid var(--color-border-subtle); border-radius: var(--radius-sm); }
.ai-panel--conversations .ai-panel__input { flex-shrink: 0; }
@media (max-width: 600px), (max-height: 650px) {
    .ai-panel--conversations { width: 100vw; }
    .ai-conversation-toolbar { max-height: 28dvh; overflow-y: auto; flex-shrink: 1; }
    .ai-conversation-editor { max-height: 42dvh; }
}

/* Header pannello */
.ai-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border-subtle);
    flex-shrink: 0;
    height: var(--topbar-height);
}

.ai-panel__avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: var(--color-accent-subtle);
    border: 1px solid var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-accent);
    flex-shrink: 0;
}

/* Area messaggi */
.ai-panel__messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4) var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

/* Welcome screen */
.ai-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: var(--space-8) var(--space-4);
    gap: var(--space-3);
    color: var(--color-text-muted);
    margin-top: auto;
    margin-bottom: auto;
}

.ai-welcome__icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-xl);
    background: var(--color-accent-subtle);
    border: 1px solid var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-accent);
    margin-bottom: var(--space-2);
}

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

.ai-welcome__desc {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    line-height: var(--leading-relaxed);
}

.ai-suggestions {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: 100%;
    margin-top: var(--space-2);
}

.ai-suggestion {
    text-align: left;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-default);
    background: var(--color-bg-elevated);
    color: var(--color-text-secondary);
    font-size: var(--text-xs);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
    line-height: var(--leading-normal);
}

.ai-suggestion:hover {
    background: var(--color-bg-overlay);
    border-color: var(--color-accent);
    color: var(--color-text-primary);
}

/* Singolo messaggio */
.ai-msg {
    display: flex;
    gap: var(--space-3);
    align-items: flex-end;
}

.ai-msg--user {
    justify-content: flex-end;
}

.ai-msg__avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    background: var(--color-accent-subtle);
    border: 1px solid var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    color: var(--color-accent);
    flex-shrink: 0;
}

.ai-msg__avatar--user {
    background: var(--color-bg-overlay);
    border-color: var(--color-border-strong);
    color: var(--color-text-secondary);
}

.ai-msg__bubble {
    max-width: 85%;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-subtle);
    color: var(--color-text-primary);
}

.ai-msg--user .ai-msg__bubble {
    background: var(--color-accent-subtle);
    border-color: var(--color-accent);
    color: var(--color-text-primary);
}

/* Badge azione eseguita */
.ai-msg__action-badge {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--color-success);
    margin-bottom: var(--space-2);
}

/* Indicatore di digitazione */
.ai-msg__bubble--thinking {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: var(--space-3) var(--space-4);
    min-width: 56px;
}

.ai-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-text-muted);
    animation: aiDotBounce 1.2s infinite ease-in-out;
}

.ai-dot:nth-child(1) { animation-delay: 0s; }
.ai-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiDotBounce {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1; }
}

/* Input area */
.ai-panel__input {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border-subtle);
    flex-shrink: 0;
}

.ai-input {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg-input);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    color: var(--color-text-primary);
    font-size: var(--text-sm);
    resize: none;
    min-height: 36px;
    max-height: 120px;
    line-height: var(--leading-normal);
    transition: border-color var(--transition-fast);
    font-family: var(--font-sans);
}

.ai-input:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

.ai-input::placeholder {
    color: var(--color-text-muted);
}

.ai-send {
    width: 36px;
    height: 36px;
    padding: 0;
    flex-shrink: 0;
    border-radius: var(--radius-md);
}

/* Pulsante microfono */
.ai-mic {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    transition: color var(--transition-fast), background var(--transition-fast);
}

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

/* Stato attivo — rosso pulsante */
.ai-mic--active {
    color: var(--color-danger) !important;
    background: var(--color-danger-subtle) !important;
    animation: micPulse 1.2s ease-in-out infinite;
}

@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(242, 92, 92, 0.4); }
    50%       { box-shadow: 0 0 0 6px rgba(242, 92, 92, 0); }
}

/* ═══════════════════════════════════════════════════════════════════════════
   INLINE EDIT — input/select trasparenti nelle celle tabella
   Usati da Impostazioni, TransazioniConti e tutte le pagine con RowAutoSaveService
   ═══════════════════════════════════════════════════════════════════════════ */

/* Input/select inline: trasparente di default, bordo appare solo su hover/focus */
.form-control--inline {
    background:    transparent;
    border:        1px solid transparent;
    border-radius: var(--radius-sm);
    padding:       var(--space-1) var(--space-2);
    font-size:     var(--text-sm);
    min-height:    30px;
    color:         var(--color-text-primary);
    transition:    border-color var(--transition-fast), background var(--transition-fast);
    width:         100%;
    box-sizing:    border-box;
}

.form-control--inline:hover:not(:disabled) {
    border-color: var(--color-border-default);
    background:   var(--color-bg-input);
}

.form-control--inline:focus {
    border-color: var(--color-border-focus);
    background:   var(--color-bg-input);
    box-shadow:   0 0 0 3px var(--color-accent-subtle);
    outline:      none;
}

.form-control--inline:disabled {
    opacity: .4;
    cursor:  not-allowed;
}

/* #ANCORA-CALENDAR-TIME-ICON-WHITE: icone native calendario/orologio bianche in tutta l'app. */
input[type="date"],
input[type="datetime-local"],
input[type="time"] {
    color-scheme: dark;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
    filter: brightness(0) invert(1);
    cursor: pointer;
}

.form-control--inline.form-date { width:100px; position:relative; }
.form-control--inline.form-date-time { width:145px; position:relative; }
.form-control--inline.form-date::-webkit-calendar-picker-indicator,
.form-control--inline.form-date-time::-webkit-calendar-picker-indicator { filter: brightness(0) invert(1); opacity: 0; display:none; }
.form-control--inline.form-date:hover::-webkit-calendar-picker-indicator,
.form-control--inline.form-date-time:hover::-webkit-calendar-picker-indicator { filter: brightness(0) invert(1); opacity: 0.8; display:block; position:relative; margin-right:-2px; }

.form-control.form-date::-webkit-calendar-picker-indicator,
.form-control.form-date-time::-webkit-calendar-picker-indicator{ filter: brightness(0) invert(1); opacity: 0.8; cursor:pointer; }

/* Select inline: mantiene la freccia */
select.form-control--inline {
    appearance:          none;
    background-image:    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238b93a8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat:   no-repeat;
    background-position: right var(--space-3) center;
    padding-right:       var(--space-8);
    cursor:              pointer;
}

select.form-control--inline:hover:not(:disabled) {
    background-color: var(--color-bg-input);
}

/* ── Input group (input + addon €, %, gg…) ─────────────────────────────── */

.input-group {
    display:     flex;
    align-items: stretch;
}

.input-group .form-control {
    flex:              1;
    -moz-appearance:   textfield;
}

/* Taglia gli angoli destri solo quando l'addon è fisicamente presente */
.input-group:has(.input-addon) .form-control {
    border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.input-group:has(.input-addon) .form-control--inline {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.input-group .form-control::-webkit-outer-spin-button,
.input-group .form-control::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Variante compatta (righe tabella) */
.input-group--compact .form-control,
.input-group--compact .form-control--inline {
    min-height:  30px;
    padding:     var(--space-1) var(--space-2);
    font-size:   var(--text-sm);
}

/* Addon (suffisso testuale: €, %, gg…) — invisibile di default */
.input-addon {
    display:        flex;
    align-items:    center;
    padding:        0 var(--space-3);
    background:     transparent;
    border:         1px solid transparent;
    border-left:    none;
    border-radius:  0 var(--radius-md) var(--radius-md) 0;
    font-size:      var(--text-xs);
    color:          var(--color-text-muted);
    white-space:    nowrap;
    user-select:    none;
    transition:     border-color var(--transition-fast), background var(--transition-fast);
    min-width:      36px;
    justify-content:center;
}

/* Bordo addon coordinato con l'input vicino */
.input-group:has(.form-control--inline:hover) .input-addon {
    border-color: var(--color-border-default);
    background:   var(--color-bg-elevated);
}

.input-group:has(.form-control--inline:focus) .input-addon {
    border-color: var(--color-border-focus);
    background:   var(--color-bg-input);
}

/* ── Pallino stato save (RowAutoSaveService) ────────────────────────────── */

.td-save-status {
    width:         20px;
    text-align:    center;
    /*padding-left:  var(--space-3) !important;
    padding-right: 0 !important;*/
}

.save-dot {
    display:        inline-block;
    width:          8px;
    height:         8px;
    border-radius:  50%;
    vertical-align: middle;
    transition:     background var(--transition-fast);
}

.save-dot--idle   { background: transparent; border: 1px solid var(--color-border-default); }
.save-dot--dirty  { background: var(--color-warning); border: none; }
.save-dot--saving { background: var(--color-accent);  border: none; animation: pulse-dot 1s ease-in-out infinite; }
.save-dot--error  {
    background: var(--color-danger);
    border: none;
    cursor: pointer;
    width: 10px;
    height: 10px;
    box-shadow: 0 0 0 2px var(--color-danger-subtle);
}

.save-dot--error:hover {
    opacity: .85;
    transform: scale(1.08);
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1;  transform: scale(1); }
    50%      { opacity: .4; transform: scale(.7); }
}

/* ── Helpers generici usati nelle tabelle editabili ─────────────────────── */

.text-right  { text-align: right; }
.mono        { font-family: var(--font-mono); }
.text-danger { color: var(--color-danger) !important; }
.row-dimmed  { opacity: .5; }
.row-dimmed:hover { opacity: .75; }

.date-width{
    width: 100px;
    min-width: 100px;
    max-width: 100px
}

/* ── Backdrop chiusura dropdown filtri ──────────────────────────────────── */
.filter-backdrop {
    position: fixed;
    inset: 0;
    z-index: 199;
}


.bonus-filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.bonus-filter-group {
    position: relative;
}

.bonus-filter-trigger {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) 7px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.bonus-filter-trigger:hover {
    border-color: var(--color-border-hover);
    color: var(--color-text-primary);
}

.bonus-filter-trigger--active {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: color-mix(in srgb, var(--color-primary) 8%, transparent);
}

.bonus-filter-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--color-primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

.bonus-filter-badge--muted {
    background: var(--color-border-strong);
    color: var(--color-text-primary);
}

.bonus-filter-badge--danger {
    background: var(--color-danger);
    color: #fff;
}


.bonus-filter-dropdown {
    position: absolute;
    top: calc(100% + var(--space-1));
    left: 0;
    z-index: 200;
    min-width: 150px;
    max-height: 280px;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 0 5px;
}

.bonus-filter-dropdown__actions {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-1);
}

.bonus-filter-option {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background 0.1s;
}

.bonus-filter-option:hover {
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
}

.bonus-filter-option input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--color-primary);
}
.cursor-pointer { cursor:pointer; }

/* #ANCORA-NUMERIC-AFFIX-INPUT */
.numeric-affix-input {
    position: relative;
    display: block;
    min-width: 0;
}

.numeric-affix-input .form-control,
.numeric-affix-input .calc-input {
    width: 100%;
    padding-right: 24px;
}

.numeric-affix-input__symbol {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    line-height: 1;
    pointer-events: none;
}

.numeric-affix-input--currency .form-control,
.numeric-affix-input--currency .calc-input {
    padding-right: 21px;
}

/* #ANCORA-AI-GUIDE-RUNTIME */
.ai-guide-steps {
    margin: var(--space-3) 0 0;
    padding-left: var(--space-5);
    display: grid;
    gap: var(--space-2);
}

.ai-guide-steps li {
    padding-left: var(--space-1);
}

.ai-guide-step-target {
    margin-left: var(--space-2);
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--color-accent);
    font: inherit;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    cursor: pointer;
}

.ai-guide-step-target:hover {
    text-decoration: underline;
}

.ai-guide-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.ai-guide-action {
    max-width: 100%;
    white-space: normal;
    text-align: left;
}

.pt-guide-highlight {
    --pt-guide-ring: #f97316;
    outline: 3px solid var(--pt-guide-ring);
    outline-offset: 3px;
    box-shadow:
        0 0 0 7px color-mix(in srgb, var(--pt-guide-ring) 34%, transparent),
        0 0 28px color-mix(in srgb, var(--pt-guide-ring) 32%, transparent);
    border-radius: var(--radius-md);
    animation: pt-guide-pulse 1.15s ease-in-out infinite;
}

/* #ANCORA-GUIDE-RUNTIME-OVERLAY: layer globale per guide AI step-by-step. */
.pt-guide-runtime {
    position: fixed;
    inset: 0;
    z-index: 10000;
    pointer-events: none;
}

.pt-guide-shield {
    position: fixed;
    z-index: 10000;
    background: rgba(2, 8, 23, 0.36);
    pointer-events: none;
}

.pt-guide-shield--top {
    left: 0;
    top: 0;
    width: 100vw;
    height: var(--pt-guide-y, 100vh);
}

.pt-guide-shield--left {
    left: 0;
    top: var(--pt-guide-y, 0);
    width: var(--pt-guide-x, 100vw);
    height: var(--pt-guide-h, 100vh);
}

.pt-guide-shield--right {
    left: calc(var(--pt-guide-x, 0px) + var(--pt-guide-w, 0px));
    top: var(--pt-guide-y, 0);
    right: 0;
    height: var(--pt-guide-h, 100vh);
}

.pt-guide-shield--bottom {
    left: 0;
    top: calc(var(--pt-guide-y, 0px) + var(--pt-guide-h, 0px));
    width: 100vw;
    bottom: 0;
}

.pt-guide-runtime--missing .pt-guide-shield {
    background: rgba(2, 8, 23, 0.42);
}

.pt-guide-active-target {
    --pt-guide-ring: #f97316;
    position: relative !important;
    z-index: 10003 !important;
    outline: 3px solid var(--pt-guide-ring);
    outline-offset: 3px;
    box-shadow:
        0 0 0 8px color-mix(in srgb, var(--pt-guide-ring) 34%, transparent),
        0 0 30px color-mix(in srgb, var(--pt-guide-ring) 34%, transparent),
        0 8px 24px rgba(0, 0, 0, 0.26);
    border-radius: var(--radius-md);
    animation: pt-guide-pulse 1.15s ease-in-out infinite;
}

@keyframes pt-guide-pulse {
    0%, 100% {
        outline-offset: 3px;
        box-shadow:
            0 0 0 7px color-mix(in srgb, var(--pt-guide-ring) 28%, transparent),
            0 0 20px color-mix(in srgb, var(--pt-guide-ring) 28%, transparent),
            0 8px 24px rgba(0, 0, 0, 0.22);
    }

    50% {
        outline-offset: 6px;
        box-shadow:
            0 0 0 11px color-mix(in srgb, var(--pt-guide-ring) 42%, transparent),
            0 0 36px color-mix(in srgb, var(--pt-guide-ring) 38%, transparent),
            0 10px 28px rgba(0, 0, 0, 0.28);
    }
}

@media (prefers-reduced-motion: reduce) {
    .pt-guide-highlight,
    .pt-guide-active-target {
        animation: none;
    }
}

.pt-guide-card {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 10004;
    width: min(420px, calc(100vw - 32px));
    display: grid;
    gap: var(--space-3);
    padding: var(--space-4);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
    box-shadow: var(--shadow-xl);
    pointer-events: auto;
}

.pt-guide-card__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.pt-guide-card__eyebrow {
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
}

.pt-guide-card h2 {
    margin: 2px 0 0;
    color: var(--color-text-primary);
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    line-height: 1.25;
}

.pt-guide-card p {
    margin: 0;
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    line-height: 1.45;
}

.pt-guide-progress {
    display: grid;
    gap: var(--space-2);
    color: var(--color-text-muted);
    font-size: var(--text-xs);
}

.pt-guide-progress__bar {
    height: 6px;
    overflow: hidden;
    border-radius: var(--radius-full);
    background: var(--color-bg-elevated);
}

.pt-guide-progress__bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--color-accent);
    transition: width 160ms ease;
}

.pt-guide-card__notice {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm);
    background: var(--color-bg-elevated);
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    line-height: 1.35;
}

.pt-guide-card__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    flex-wrap: wrap;
}

@media (max-width: 760px) {
    .pt-guide-card {
        left: 12px;
        right: 12px;
        bottom: 12px;
        width: auto;
    }

    .pt-guide-card__actions .btn {
        flex: 1 1 auto;
    }
}
.sidebar__brand-text .sidebar__brand-version {margin-top:-5px;}
/* #ANCORA-ESITO-AUTOCOMPLETE-GLOBALE */
.pt-outcome-autocomplete {
    position: fixed;
    z-index: 2147483000;
    display: none;
    max-height: 260px;
    overflow-y: auto;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
}

.pt-outcome-autocomplete.is-open { display: block; }

.pt-outcome-autocomplete__option {
    display: block;
    width: 100%;
    padding: 6px var(--space-3);
    border: 0;
    border-bottom: 1px solid color-mix(in srgb, var(--color-border) 50%, transparent);
    border-radius: 0;
    color: var(--color-text-primary);
    background: transparent;
    font-family: inherit;
    font-size: var(--font-size-sm);
    font-weight: 500;
    line-height: normal;
    text-align: left;
    cursor: pointer;
    transition: background .1s;
}

.pt-outcome-autocomplete__option:last-child { border-bottom: none; }

/* #ANCORA-AI-PHASE-C-RESULTS: scroll esplicito per tabelle e registro consumi. */
.ai-calculation-table { max-width: 100%; overflow-x: auto; }
.ai-calculation { border-top: 1px solid var(--color-border-subtle); margin-top: var(--space-2); padding-top: var(--space-2); overflow-wrap: anywhere; }
.ai-calculation summary { cursor: pointer; }

/* #ANCORA-AI-CHAT-VISUAL: conversazione leggibile, controlli secondari e scroll indipendenti. */
.ai-panel--conversations { --space-3: .75rem; --space-4: 1rem; }
.ai-panel--conversations .ai-msg__bubble { font-size: 14px; }
.ai-panel--conversations .ai-msg__author, .ai-panel--conversations .ai-chat-picker__field label,
.ai-panel--conversations .ai-msg__usage, .ai-panel--conversations .ai-composer-hint { color: var(--color-text-secondary); }
.ai-panel--expanded { width: min(960px, 94vw); }
/* #ANCORA-AI-CHAT-HISTORY-DRAWER: elenco e conferme rimangono scrollabili anche su mobile. */
.ai-panel--conversations .ai-panel__header { position: relative; z-index: 5; }
.ai-current-chat-title { display: flex; align-items: flex-start; gap: var(--space-2); font-weight: var(--font-semibold); font-size: var(--text-sm); color: var(--color-text-primary); overflow-wrap: anywhere; }
.ai-current-chat-title__icon { flex-shrink: 0; margin-top: 2px; color: var(--color-text-secondary); }
.ai-current-chat-title > span { min-width: 0; }
.ai-history-backdrop { position: absolute; inset: var(--topbar-height) 0 0; z-index: 3; background: color-mix(in srgb, var(--color-bg-surface) 65%, transparent); }
.ai-history { position: absolute; top: var(--topbar-height); left: 0; bottom: 0; width: min(320px, calc(100% - 32px)); z-index: 4; display: flex; flex-direction: column; min-height: 0; background: var(--color-bg-elevated); border-right: 1px solid var(--color-border-default); box-shadow: var(--shadow-xl); }
.ai-history__header { display: flex; align-items: center; gap: var(--space-1); padding: var(--space-3); border-bottom: 1px solid var(--color-border-subtle); flex-shrink: 0; }
.ai-history__header strong { flex: 1; font-size: var(--text-sm); }
.ai-history__list { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--space-2); scrollbar-gutter: stable; }
.ai-history__row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: var(--space-1); padding: var(--space-2); border-radius: var(--radius-md); }
.ai-history__row:hover, .ai-history__row.is-active { background: var(--color-bg-overlay); }
.ai-history__select { min-width: 0; padding: 0; border: 0; background: transparent; color: var(--color-text-primary); text-align: left; font: inherit; cursor: pointer; }
.ai-history__select span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; font-size: var(--text-sm); }
.ai-history__select small { display: block; margin-top: var(--space-1); color: var(--color-text-secondary); font-size: var(--text-xs); }
.ai-history__select:disabled { cursor: wait; }
.ai-history__delete:hover { color: var(--color-danger); }
.ai-history__rename { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--space-1); min-width: 0; }
.ai-history__rename input { min-width: 0; flex: 1; font-size: var(--text-sm); }
.ai-chat-delete-modal .modal-body { overflow-wrap: anywhere; }
.ai-chat-delete-modal__error { color: var(--color-danger); }
.ai-history__error { padding: var(--space-3); margin: 0; font-size: var(--text-xs); color: var(--color-danger); overflow-wrap: anywhere; }
.ai-history__more { margin: var(--space-3) 0; width: 100%; }
.ai-history button:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.ai-conversation-toolbar > label { margin-top: var(--space-2); }
.ai-panel--conversations .ai-panel__messages { padding: var(--space-5); gap: var(--space-5); overscroll-behavior: contain; scrollbar-gutter: stable; }
.ai-panel--conversations .ai-msg { min-width: 0; align-items: flex-start; }
.ai-panel--conversations .ai-msg__bubble { min-width: 0; max-width: calc(100% - 40px); line-height: 1.65; }
.ai-panel--conversations .ai-msg--assistant .ai-msg__bubble { flex: 1; background: transparent; border-color: transparent; padding: 0 var(--space-1); }
.ai-msg--user .ai-msg__avatar { display: none; }
.ai-msg__author { font-size: var(--text-xs); font-weight: var(--font-semibold); color: var(--color-text-muted); margin-bottom: var(--space-2); }
.ai-msg__text { white-space: pre-wrap; }
.ai-message-line { white-space: pre-wrap; }
.ai-message-gap { height: var(--space-3); }
.ai-message-heading { font-weight: var(--font-semibold); margin: var(--space-3) 0 var(--space-2); }
.ai-message-list-item { display: grid; grid-template-columns: 10px minmax(0, 1fr); gap: var(--space-2); margin: var(--space-1) 0; }
.ai-message-content code { font-size: .9em; background: var(--color-bg-elevated); border-radius: var(--radius-sm); padding: 1px 4px; overflow-wrap: anywhere; }
.ai-msg__usage { margin-top: var(--space-3); color: var(--color-text-muted); font-size: var(--text-xs); }
.ai-msg__usage > summary { cursor: pointer; }
.ai-msg__usage[open] { padding: var(--space-2); border: 1px solid var(--color-border-subtle); border-radius: var(--radius-md); }
.ai-panel--conversations .ai-calculation { margin-top: var(--space-3); border: 1px solid var(--color-border-subtle); border-radius: var(--radius-md); padding: var(--space-3); background: var(--color-bg-elevated); font-size: var(--text-xs); }
.ai-calculation > summary { color: var(--color-text-primary); font-weight: var(--font-semibold); }
.ai-calculation[open] > summary { margin-bottom: var(--space-3); }
.ai-calculation details { margin-top: var(--space-3); }
.ai-calculation li { margin: var(--space-2) 0; }
.ai-calculation-input { white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--text-xs); max-height: 180px; overflow-y: auto; }
.ai-calculation .table { font-size: var(--text-xs); }
.ai-calculation .table td:last-child { font-variant-numeric: tabular-nums; }
.ai-conversation-editor { background: var(--color-bg-elevated); scrollbar-gutter: stable; }
.ai-editor-close { margin-bottom: var(--space-3); }
.ai-panel--conversations .ai-panel__input { padding: var(--space-3) var(--space-4) var(--space-2); align-items: flex-end; }
.ai-panel--conversations .ai-input { min-width: 0; min-height: 64px; }
.ai-composer-hint { flex-shrink: 0; padding: 0 var(--space-4) max(var(--space-3), env(safe-area-inset-bottom)); color: var(--color-text-muted); font-size: 11px; }
/* #ANCORA-AI-COMPOSER-POPOVER: composer alto, selettore compatto e pannelli con scroll. */
.ai-panel--conversations .ai-composer { display: block; margin: var(--space-3) var(--space-4) var(--space-2); padding: var(--space-3); border: 1px solid var(--color-border-default); border-radius: var(--radius-xl); background: var(--color-bg-elevated); }
.ai-composer:focus-within { border-color: var(--color-border-focus); }
.ai-panel--conversations .ai-composer .ai-input { display: block; width: 100%; min-height: 88px; max-height: 180px; padding: var(--space-1); border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.ai-composer__footer, .ai-composer__actions { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.ai-composer__footer { margin-top: var(--space-2); flex-wrap: wrap; }
.ai-composer__actions { flex: 1; justify-content: flex-end; }
/* #ANCORA-AI-COMPOSER-CHAT-OPTIONS: menu ancorato a sinistra, senza descrizioni e con scroll interno. */
.ai-composer-options { position: relative; flex-shrink: 0; }
.ai-composer-options__trigger { position: relative; display: flex; align-items: center; gap: var(--space-2); min-height: 36px; padding: var(--space-1) var(--space-2); border: 0; border-radius: var(--radius-md); background: transparent; color: var(--color-text-primary); font: inherit; font-size: var(--text-sm); cursor: pointer; }
.ai-composer-options__trigger > span:first-child { font-size: 24px; line-height: 1; }
.ai-composer-options__trigger:hover, .ai-composer-options__trigger[aria-expanded="true"] { background: var(--color-bg-overlay); }
.ai-composer-options__trigger[aria-expanded="true"] { z-index: 2; }
.ai-composer-options__active { color: var(--color-accent); }
.ai-composer-options__popover { position: absolute; bottom: calc(100% + var(--space-3)); left: 0; z-index: 2; width: 288px; max-width: calc(100vw - 64px); max-height: min(420px, 50dvh); overflow-y: auto; overscroll-behavior: contain; padding: var(--space-2); background: var(--color-bg-elevated); color: var(--color-text-primary); border: 1px solid var(--color-border-default); border-radius: var(--radius-xl); box-shadow: var(--shadow-xl); font-size: var(--text-sm); }
.ai-composer-options__item, .ai-composer-options__command { display: flex; align-items: center; gap: var(--space-2); width: 100%; min-height: 42px; margin: 0; padding: var(--space-2); border: 0; border-radius: var(--radius-md); background: transparent; color: var(--color-text-primary); font: inherit; line-height: 1.5; text-align: left; cursor: pointer; }
.ai-composer-options__item:hover, .ai-composer-options__command:hover { background: var(--color-bg-overlay); }
.ai-composer-options__command input { flex-shrink: 0; accent-color: var(--color-accent); }
/* #ANCORA-AI-PROMOTION-PICKER-MODAL: sopra il pannello chat, corpo con scroll anche su mobile. */
/* #ANCORA-AI-SELECTION-PANEL-CENTER: modali contenuti e centrati nel pannello anche espanso. */
.ai-panel > .ai-selection-overlay { position: absolute; inset: 0; z-index: 6; padding: var(--space-4); }
.ai-selection-overlay > .modal { max-height: calc(100% - var(--space-4) * 2); }
.ai-promotion-picker__body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.ai-promotion-picker__list { display: grid; gap: var(--space-1); margin-top: var(--space-3); }
.ai-promotion-picker__option { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); width: 100%; min-height: 44px; padding: var(--space-3); border: 0; border-radius: var(--radius-md); background: transparent; color: var(--color-text-primary); font: inherit; text-align: left; overflow-wrap: anywhere; cursor: pointer; }
.ai-promotion-picker__option span:first-child { min-width: 0; }
.ai-promotion-picker__option:hover, .ai-promotion-picker__option[aria-pressed="true"] { background: var(--color-bg-elevated); }
.ai-promotion-picker__option:focus-visible { outline: 2px solid var(--color-accent); outline-offset: -2px; }
.ai-composer-options__item:disabled { opacity: .5; cursor: not-allowed; }
.ai-composer-options button:focus-visible, .ai-composer-options input:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.ai-composer .ai-send, .ai-composer .ai-mic { border-radius: 50%; }
.ai-composer-picker { position: relative; min-width: 0; }
.ai-composer-picker__trigger { position: relative; display: flex; align-items: center; gap: var(--space-1); min-width: 0; max-width: 100%; min-height: 36px; padding: var(--space-1) var(--space-2); border: 0; border-radius: var(--radius-md); background: transparent; color: var(--color-text-primary); font: inherit; font-size: var(--text-sm); line-height: 1.35; cursor: pointer; }
.ai-composer-picker__trigger:hover, .ai-composer-picker__trigger[aria-expanded="true"] { background: var(--color-bg-overlay); }
.ai-composer-picker__trigger[aria-expanded="true"] { z-index: 2; }
.ai-composer-picker__model { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-composer-picker__effort { color: var(--color-text-secondary); font: inherit; white-space: nowrap; }
.ai-composer-picker__dismiss { position: fixed; inset: 0; z-index: 1; }
.ai-composer-picker__popover { position: absolute; bottom: calc(100% + var(--space-3)); right: calc(-72px - var(--space-2) - var(--space-2)); z-index: 2; width: 288px; max-width: calc(100vw - 48px); max-height: min(420px, 55dvh); overflow-y: auto; overscroll-behavior: contain; padding: var(--space-3); background: var(--color-bg-elevated); color: var(--color-text-primary); border: 1px solid var(--color-border-default); border-radius: var(--radius-xl); box-shadow: var(--shadow-xl); font-size: var(--text-sm); }
.ai-composer-picker__heading { margin: 0; padding: var(--space-2); color: var(--color-text-primary); font-size: var(--text-md); font-weight: var(--font-semibold); text-align: left; }
.ai-composer-picker__effort-heading { text-align: center; color: var(--color-text-primary); font: inherit; font-size: var(--text-base); line-height: 1.5; }
.ai-composer-picker__model-link { display: block; width: 100%; padding: var(--space-1) var(--space-2); border: 0; background: transparent; color: var(--color-text-primary); font: inherit; font-size: var(--text-base); line-height: 1.5; text-align: center; cursor: pointer; overflow-wrap: anywhere; }
.ai-composer-picker__model-link:hover { color: var(--color-text-primary); }
.ai-composer-picker__range { appearance: none; display: block; width: 100%; height: 28px; margin: var(--space-3) 0 0; background: transparent; accent-color: var(--color-accent); cursor: pointer; }
.ai-composer-picker__range::-webkit-slider-runnable-track { height: 20px; border-radius: var(--radius-full); background: linear-gradient(to right, var(--color-accent) var(--ai-effort-position), var(--color-border-default) var(--ai-effort-position)); }
.ai-composer-picker__range::-webkit-slider-thumb { appearance: none; width: 26px; height: 26px; margin-top: -3px; border: 2px solid var(--color-bg-elevated); border-radius: 50%; background: var(--color-text-primary); }
.ai-composer-picker__range::-moz-range-track { height: 20px; border-radius: var(--radius-full); background: var(--color-border-default); }
.ai-composer-picker__range::-moz-range-progress { height: 20px; border-radius: var(--radius-full); background: var(--color-accent); }
.ai-composer-picker__range::-moz-range-thumb { width: 24px; height: 24px; border: 2px solid var(--color-bg-elevated); border-radius: 50%; background: var(--color-text-primary); }
.ai-composer-picker__ticks, .ai-composer-picker__ends { display: flex; justify-content: space-between; padding-inline: var(--space-2); color: var(--color-text-muted); font-size: var(--text-xs); }
.ai-composer-picker__ticks .is-selected { color: var(--color-accent); }
.ai-composer-picker__note { margin: var(--space-3) 0 0; color: var(--color-text-muted); font-size: var(--text-xs); line-height: var(--leading-normal); }
.ai-composer-picker__models { display: grid; gap: var(--space-1); margin-top: var(--space-2); }
.ai-composer-picker__option { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); width: 100%; min-height: 40px; padding: var(--space-2); border: 0; border-radius: var(--radius-md); background: transparent; color: var(--color-text-primary); font-size: var(--text-base); text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.ai-composer-picker__option:hover, .ai-composer-picker__option[aria-pressed="true"] { background: var(--color-bg-overlay); }
.ai-composer-picker__option small { display: block; margin-top: var(--space-1); color: var(--color-text-muted); font-size: var(--text-xs); }
.ai-composer-picker__option:disabled, .ai-composer-picker__trigger:disabled { opacity: .5; cursor: not-allowed; }
.ai-composer-picker button:focus-visible, .ai-composer-picker__range:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
@media (max-width: 600px) {
    .ai-panel--expanded { width: 100vw; }
    .ai-expand { display: none; }
    .ai-panel--conversations .ai-panel__header { padding: var(--space-3); }
    .ai-panel--conversations .ai-panel__messages { padding: var(--space-4) var(--space-3); }
    .ai-panel--conversations .ai-msg { gap: var(--space-2); }
    .ai-panel--conversations .ai-msg__bubble { max-width: calc(100% - 34px); }
    .ai-panel--conversations .ai-input { font-size: 16px; }
    .ai-composer__actions { flex-basis: 100%; }
    .ai-conversation-editor { max-height: 38dvh; }
}
.ai-budget label { display: block; margin-bottom: var(--space-2); }
.ai-budget-modal__body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.ai-budget-modal .ai-budget { min-width: 0; overflow-wrap: anywhere; }
.ai-budget-modal .ai-memory-fact { min-width: 0; }
.ai-budget-modal input, .ai-budget-modal select { max-width: 100%; min-width: 0; }
.ai-budget-modal .ai-conversation-actions { flex-wrap: wrap; }
.ai-budget p { margin-bottom: var(--space-2); }

.pt-outcome-autocomplete__option:hover,
.pt-outcome-autocomplete__option.is-active {
    background: var(--color-bg-overlay);
}
