/* ========================================
   S51: Hover classes (sostituiscono onmouseover inline)
   ======================================== */

/* File trigger button (ticket tab) */
.btn-file-trigger {
    padding: 12px 24px;
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    cursor: pointer;
    color: var(--text-primary);
    font-weight: 600;
    transition: all 0.2s ease;
    font-size: 1em;
}

.btn-file-trigger:hover {
    border-color: var(--accent-primary);
    background: rgba(76, 175, 80, 0.1);
}

/* Submit ticket button */
.btn-ticket-submit {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    background: var(--accent-primary);
    color: white;
    cursor: pointer;
    font-weight: 600;
    font-size: 1em;
    transition: all 0.2s ease;
}

.btn-ticket-submit:hover {
    background: var(--accent-secondary);
    transform: scale(1.05);
}

/* Delete POS row button */
.btn-delete-pos {
    background: #757575;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    min-width: 40px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-delete-pos:hover {
    background: #616161;
    transform: scale(1.1);
}

/* Delete pareggio button (card overlay) */
.btn-delete-pareggio {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.1em;
    opacity: 0.6;
    transition: all 0.2s ease;
}

.btn-delete-pareggio:hover {
    opacity: 1;
    color: #d32f2f;
    background: rgba(211, 47, 47, 0.1);
}

/* ============================================
   RICONCILIAZIONE - File list + Controls (S60)
   ============================================ */

.spring-file-list {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    max-height: 140px;
    overflow-y: auto;
}

.spring-file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    color: var(--text-primary);
    transition: background 0.15s ease;
}

.spring-file-item:hover {
    background: var(--table-hover, rgba(0,0,0,0.04));
}

.spring-file-item input[type="checkbox"] {
    accent-color: var(--accent-primary, #2e7d32);
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.spring-file-item .file-size {
    color: var(--text-secondary);
    font-size: 0.85em;
    margin-left: auto;
    white-space: nowrap;
}

/* ============================================
   RICONCILIAZIONE - Sub-tab + Tabelle (S58)
   ============================================ */

.rc-sub-tab {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 10px 20px;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px 8px 0 0;
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.rc-sub-tab:hover {
    background: var(--table-hover, rgba(0,0,0,0.04));
    color: var(--text-primary);
}

.rc-sub-tab.active {
    color: var(--accent-primary, #2e7d32);
    border-bottom-color: var(--accent-primary, #2e7d32);
    font-weight: 600;
}

/* Tabelle riconciliazione - sticky header */
.rc-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    max-height: 500px;
    overflow-y: auto;
}

.rc-table-wrap thead {
    position: sticky;
    top: 0;
    z-index: 5;
}

.rc-table-wrap tbody tr:hover {
    background: var(--table-hover, rgba(0,0,0,0.04));
}

/* ========================================
   FASE J: Annullamento Caparre
   ======================================== */

/* Badge ANNULLATA */
.badge-annullata {
    display: inline-block;
    font-size: 0.65em;
    padding: 1px 6px;
    margin-left: 4px;
    background: var(--annullata-badge-bg);
    color: var(--annullata-badge-text);
    border-radius: 8px;
    font-weight: 600;
    vertical-align: middle;
    white-space: nowrap;
    letter-spacing: 0.3px;
}

/* Badge RESTITUZIONE */
.badge-restituzione {
    display: inline-block;
    font-size: 0.65em;
    padding: 1px 6px;
    margin-left: 4px;
    background: var(--restituzione-badge-bg);
    color: var(--restituzione-badge-text);
    border-radius: 8px;
    font-weight: 600;
    vertical-align: middle;
    white-space: nowrap;
    letter-spacing: 0.3px;
}

/* Riga annullata - opaca + barrata */
tr.row-annullata {
    opacity: var(--annullata-row-opacity);
    text-decoration: line-through;
    text-decoration-color: var(--text-secondary);
}

tr.row-annullata:hover {
    opacity: 0.75;
}

/* Riga restituzione - visibile, sfondo leggero indaco */
tr.row-restituzione {
    background: rgba(92, 107, 192, 0.06);
}

tr.row-restituzione:hover {
    background: rgba(92, 107, 192, 0.12);
}

[data-theme="dark"] tr.row-restituzione {
    background: rgba(92, 107, 192, 0.10);
}

[data-theme="dark"] tr.row-restituzione:hover {
    background: rgba(92, 107, 192, 0.18);
}

/* SPRING-018: Alert RES non collegata */
.res-pending-alert {
    display: inline-block;
    margin-left: 4px;
    color: #e65100;
    cursor: pointer;
    font-size: 0.9em;
    vertical-align: middle;
}

.res-pending-alert:hover {
    color: #bf360c;
}

[data-theme="dark"] .res-pending-alert {
    color: #ff9800;
}

[data-theme="dark"] .res-pending-alert:hover {
    color: #ffb74d;
}

/* SPRING-018: Link cross-reference annullamento */
.annullamento-ref-link {
    display: inline-block;
    margin-left: 4px;
    color: var(--restituzione-badge-bg, #5c6bc0);
    cursor: pointer;
    font-size: 0.75em;
    vertical-align: middle;
    white-space: nowrap;
}

.annullamento-ref-link:hover {
    text-decoration: underline;
}

/* SPRING-018: Highlight temporaneo riga (scroll target) */
@keyframes highlight-flash {
    0% { background: var(--color-nav-highlight); outline: 2px solid var(--color-nav-highlight-border); }
    100% { background: transparent; outline: 2px solid transparent; }
}

tr.row-highlight-temp {
    animation: highlight-flash 3s ease-out;
}

/* Override reduced-motion */
@media (prefers-reduced-motion: reduce) {
    tr.row-highlight-temp {
        animation: none;
    }
}

/* Pannello Cancellazioni Rilevate */
.annullamenti-panel {
    margin: 0 0 16px 0;
    background: var(--annullamenti-panel-bg);
    border: 1px solid var(--annullamenti-panel-border);
    border-radius: 10px;
    overflow: hidden;
}

.annullamenti-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s ease;
}

.annullamenti-header:hover {
    background: var(--hover-bg);
}

.annullamenti-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 0.95em;
    color: var(--text-primary);
}

.annullamenti-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    background: var(--annullata-badge-bg);
    color: white;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 700;
}

.annullamenti-chevron {
    transition: transform 0.3s ease;
    font-size: 0.9em;
    color: var(--text-secondary);
}

.annullamenti-panel.expanded .annullamenti-chevron {
    transform: rotate(180deg);
}

.annullamenti-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.annullamenti-panel.expanded .annullamenti-content {
    max-height: 2000px;
}

.annullamenti-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 16px 16px 16px;
}

/* Singola card coppia */
.annullamenti-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--annullamenti-card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: box-shadow 0.2s ease, transform 0.15s ease;
}

.annullamenti-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

.annullamenti-card.ambigua {
    border-left: 3px solid #ff9800;
}

.annullamenti-card-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.annullamenti-card-side {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.annullamenti-card-side .card-label {
    font-size: 0.7em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    font-weight: 600;
}

.annullamenti-card-side .card-nome {
    font-weight: 600;
    font-size: 0.95em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.annullamenti-card-side .card-detail {
    font-size: 0.8em;
    color: var(--text-secondary);
}

.annullamenti-card-importo {
    font-weight: 700;
    font-size: 1.05em;
    white-space: nowrap;
}

.annullamenti-card-importo.positivo {
    color: var(--annullamenti-confirm-bg);
}

.annullamenti-card-importo.negativo {
    color: var(--annullata-badge-bg);
}

.annullamenti-card-arrow {
    font-size: 1.3em;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.annullamenti-card-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.btn-conferma-annullamento {
    padding: 6px 14px;
    background: var(--annullamenti-confirm-bg);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
    white-space: nowrap;
}

.btn-conferma-annullamento:hover {
    background: var(--annullamenti-confirm-hover);
}

.btn-conferma-annullamento:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Toast Undo */
.undo-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: #323232;
    color: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    font-size: 0.9em;
    animation: toast-slide-in 0.3s ease;
}

.undo-toast.hiding {
    animation: toast-slide-out 0.3s ease forwards;
}

@keyframes toast-slide-in {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes toast-slide-out {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(100%);
        opacity: 0;
    }
}

.undo-toast-message {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-undo-toast {
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.15);
    color: #90caf9;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
    white-space: nowrap;
}

.btn-undo-toast:hover {
    background: rgba(255, 255, 255, 0.25);
}

.undo-countdown {
    font-size: 0.85em;
    color: rgba(255, 255, 255, 0.6);
    min-width: 24px;
    text-align: center;
}

/* Pannello vuoto */
.annullamenti-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 0.9em;
}

/* ========================================
   SPRING-019: Sezioni pannello esteso
   ======================================== */

/* Sotto-sezione nel pannello (exact / suggested / orphans) */
.annullamenti-subsection {
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
    margin-top: 8px;
}

.annullamenti-subsection:first-child {
    border-top: none;
    padding-top: 0;
    margin-top: 0;
}

.annullamenti-subsection-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    border-radius: 4px;
    transition: background 0.15s ease;
}

.annullamenti-subsection-header:hover {
    background: var(--hover-bg);
}

.annullamenti-subsection-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    font-size: 0.9em;
    font-weight: 700;
}

.annullamenti-subsection-count.exact {
    background: var(--annullamenti-confirm-bg);
    color: white;
}

.annullamenti-subsection-count.suggested {
    background: var(--suggested-badge-bg);
    color: var(--suggested-badge-text);
    border: 1px solid var(--suggested-badge-border);
}

.annullamenti-subsection-count.orphan {
    background: var(--bg-tertiary, #e0e0e0);
    color: var(--text-secondary);
}

.annullamenti-subsection-chevron {
    transition: transform 0.2s ease;
    font-size: 0.8em;
    color: var(--text-secondary);
}

.annullamenti-subsection.collapsed .annullamenti-subsection-chevron {
    transform: rotate(-90deg);
}

.annullamenti-subsection-body {
    overflow: hidden;
    transition: max-height 0.25s ease;
    max-height: 3000px; /* ceiling per collapse animation; backend caps risultati a 20 */
}

.annullamenti-subsection.collapsed .annullamenti-subsection-body {
    max-height: 0;
}

/* Card suggerimento (suggested) */
.annullamenti-card-suggested {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--annullamenti-card-bg);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--suggested-badge-border);
    border-radius: 8px;
    transition: box-shadow 0.2s ease, transform 0.15s ease;
}

.annullamenti-card-suggested:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

/* Badge tipo collegamento nel pannello */
.collegamento-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75em;
    font-weight: 600;
    white-space: nowrap;
}

.collegamento-badge.esatto {
    background: var(--status-success-bg, #e8f5e9);
    color: var(--annullamenti-confirm-bg);
}

.collegamento-badge.parziale {
    background: var(--suggested-badge-bg);
    color: var(--suggested-badge-text);
    border: 1px solid var(--suggested-badge-border);
}

.collegamento-badge.nessuno {
    background: var(--bg-tertiary, #e0e0e0);
    color: var(--text-secondary);
}

/* Card orfana (orphan) */
.annullamenti-card-orphan {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--annullamenti-card-bg);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--bg-tertiary, #e0e0e0);
    border-radius: 8px;
    transition: box-shadow 0.2s ease;
}

.annullamenti-card-orphan:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Bottone Vai alla Riga nel pannello */
.btn-vai-alla-riga {
    padding: 4px 10px;
    background: transparent;
    color: var(--accent-primary);
    border: 1px solid var(--accent-primary);
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
    white-space: nowrap;
}

.btn-vai-alla-riga:hover {
    background: var(--hover-bg);
}

@media (prefers-reduced-motion: reduce) {
    .annullamenti-subsection-chevron {
        transition: none;
    }
    .annullamenti-subsection-body {
        transition: none;
    }
    .annullamenti-card-suggested {
        transition: none;
    }
    .annullamenti-card-suggested:hover {
        transform: none;
    }
}

/* ========================================
   SPRING-019 Step 6: Pannello inline match
   ======================================== */

/* Riga inline nella tabella */
.inline-match-row td {
    padding: 0;
    border: none;
    background: transparent !important; /* Necessario: vince su color-coding circuiti !important */
}

.inline-match-cell {
    padding: 0;
}

/* Pannello inline */
.inline-match-panel {
    margin: 4px 16px 8px;
    padding: 16px;
    background: var(--inline-panel-bg);
    border: 1px solid var(--inline-panel-border);
    border-left: 3px solid var(--accent-primary);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.inline-match-panel.inline-match-orphan {
    border-left-color: var(--bg-tertiary, #e0e0e0);
}

/* Header pannello inline */
.inline-match-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.inline-match-title {
    font-size: 0.85em;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.inline-match-close {
    background: none;
    border: none;
    font-size: 1.4em;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
}

.inline-match-close:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

/* Body pannello inline */
.inline-match-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.inline-match-caparra {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.inline-match-hint {
    font-size: 0.9em;
    color: var(--text-secondary);
    margin: 0;
}
.inline-match-error {
    color: var(--status-danger-text, red);
}

/* Nota obbligatoria */
.inline-match-nota-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.inline-match-nota-label {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--text-secondary);
}

.inline-match-nota {
    width: 100%;
    max-width: 400px;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9em;
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
    resize: vertical;
}

.inline-match-nota:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 1px;
    border-color: var(--accent-primary);
}

.inline-match-nota-counter {
    font-size: 0.75em;
    color: var(--text-secondary);
    text-align: right;
    max-width: 400px;
}

/* Azioni pannello inline */
.inline-match-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-collega-annulla {
    padding: 6px 16px;
    background: var(--annullamenti-confirm-bg);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.btn-collega-annulla:hover:not(:disabled) {
    background: var(--annullamenti-confirm-hover);
}

.btn-collega-annulla:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-collega-parziale {
    padding: 6px 16px;
    background: var(--partial-btn-bg);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.btn-collega-parziale:hover:not(:disabled) {
    background: var(--partial-btn-hover);
}

.btn-collega-parziale:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-cerca-altra, .btn-cerca-caparra {
    padding: 6px 14px;
    background: transparent;
    color: var(--accent-primary);
    border: 1px solid var(--accent-primary);
    border-radius: 6px;
    font-size: 0.85em;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
}

.btn-cerca-altra:hover, .btn-cerca-caparra:hover {
    background: var(--hover-bg);
}

.btn-chiudi-inline {
    padding: 6px 12px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.85em;
    cursor: pointer;
}

.btn-chiudi-inline:hover {
    background: var(--hover-bg);
}

/* Riga RES con pannello inline attivo */
tr.row-inline-active {
    outline: 2px solid var(--accent-primary);
    outline-offset: -2px;
}

@media (prefers-reduced-motion: reduce) {
    .inline-match-panel,
    .annullamenti-card-orphan,
    .inline-search-result-card {
        transition: none;
    }
}

/* Responsive: pannello inline su mobile */
@media (max-width: 600px) {
    .inline-match-panel {
        margin: 4px 4px 8px;
        padding: 12px;
    }
    .inline-match-nota {
        max-width: 100%;
    }
    .inline-match-nota-counter {
        max-width: 100%;
    }
    .inline-search-row {
        flex-direction: column;
        align-items: stretch;
    }
    .inline-search-input {
        max-width: 100%;
    }
    .inline-match-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .inline-match-actions button {
        text-align: center;
    }
}

/* ========================================
   SPRING-019 Step 7: Ricerca caparra inline
   ======================================== */

.inline-search-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.inline-search-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.inline-search-input {
    flex: 1;
    max-width: 300px;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9em;
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.inline-search-input:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 1px;
    border-color: var(--accent-primary);
}

.inline-search-results-header {
    font-size: 0.85em;
    color: var(--text-secondary);
    font-weight: 600;
    margin: 4px 0;
}

.inline-search-result-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--annullamenti-card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.inline-search-result-card:hover {
    background: var(--search-result-hover);
}

.inline-search-result-card.selected {
    background: var(--search-result-selected);
    border-color: var(--accent-primary);
    outline: 2px solid var(--accent-primary);
    outline-offset: -2px;
}

.inline-search-result-card.selected:focus-visible {
    outline: 3px solid var(--accent-primary);
    outline-offset: 1px;
}

.inline-search-confirm {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}
