/* ============================================================
   DB2GEST - Custom Styles
   ERP Spring Boot + Thymeleaf + Tabulator + Bootstrap 5
   ============================================================ */

/* -----------------------------------------------
   1. BASE & TIPOGRAFIA
   ----------------------------------------------- */
body {
    font-size: 0.9rem;
    background-color: #f5f7fa;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.navbar-brand {
    font-size: 1.1rem;
    letter-spacing: 0.05em;
}

/* -----------------------------------------------
   2. CARD & CONTAINER
   ----------------------------------------------- */
.card {
    transition: transform 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    border: none;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.card:hover {
    transform: translateY(-3px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
}

.card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    font-weight: 600;
}

.footer {
    margin-top: auto;
}

/* -----------------------------------------------
   3. FORM COMPACT
   ----------------------------------------------- */
.form-compact .form-group {
    margin-bottom: 0.5rem;
}

.form-compact .form-label {
    margin-bottom: 0.15rem;
    font-size: 0.8rem;
    color: #6c757d;
    font-weight: 500;
}

.form-compact .form-control-sm,
.form-compact .form-select-sm {
    font-size: 0.85rem;
    padding: 0.25rem 0.5rem;
}

.table-sm th,
.table-sm td {
    padding: 0.3rem 0.5rem;
}

/* -----------------------------------------------
   4. TABULATOR - TEMA CUSTOM
   ----------------------------------------------- */

/* Contenitore tabella */
.tabulator {
    border: 1px solid #dee2e6;
    font-size: 0.875rem;
    border-radius: 0.375rem;
    overflow: hidden;
}

/* Intestazione */
.tabulator .tabulator-header {
    background-color: #0d6efd;
    color: white;
    font-weight: 600;
    border-bottom: 2px solid #0a58ca;
    user-select: none;
}

.tabulator .tabulator-header .tabulator-col {
    background-color: #0d6efd;
    color: white;
    border-color: #0a58ca;
    transition: background-color 0.15s ease;
}

.tabulator .tabulator-header .tabulator-col:hover {
    background-color: #0b5ed7;
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-content {
    padding: 0.5rem 0.75rem;
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-content .tabulator-header-sorter {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Header filter */
.tabulator .tabulator-header .tabulator-col .tabulator-header-filter input {
    font-size: 0.8rem;
    padding: 0.2rem 0.4rem;
    border: 1px solid #ced4da;
    border-radius: 0.2rem;
    background-color: rgba(255, 255, 255, 0.9);
    color: #212529;
}

.tabulator .tabulator-header .tabulator-col .tabulator-header-filter input:focus {
    outline: none;
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

/* Righe */
.tabulator .tabulator-row {
    border-bottom: 1px solid #dee2e6;
    transition: background-color 0.12s ease;
    min-height: 36px;
}

.tabulator .tabulator-row:nth-child(even) {
    background-color: #f8f9fa;
}

.tabulator .tabulator-row:hover {
    background-color: #e9ecef;
}

.tabulator .tabulator-row.tabulator-selected {
    background-color: #cfe2ff;
}

.tabulator .tabulator-row .tabulator-cell {
    padding: 0.4rem 0.75rem;
    border-right: 1px solid #f0f0f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tabulator .tabulator-row .tabulator-cell:last-child {
    border-right: none;
}

/* Footer */
.tabulator .tabulator-footer {
    background-color: #f8f9fa;
    border-top: 1px solid #dee2e6;
    padding: 0.5rem;
    font-size: 0.85rem;
}

.tabulator .tabulator-footer .tabulator-page-size {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    background-color: white;
}

.tabulator .tabulator-footer .tabulator-paginator {
    gap: 0.25rem;
}

.tabulator .tabulator-footer .tabulator-page {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    border: 1px solid #dee2e6;
    background-color: white;
    color: #0d6efd;
    border-radius: 0.25rem;
    margin: 0 0.125rem;
    cursor: pointer;
    transition: all 0.15s ease;
    min-width: 2rem;
    text-align: center;
}

.tabulator .tabulator-footer .tabulator-page:hover:not(.disabled) {
    background-color: #0d6efd;
    color: white;
    border-color: #0d6efd;
}

.tabulator .tabulator-footer .tabulator-page.active {
    background-color: #0d6efd;
    color: white;
    border-color: #0d6efd;
    font-weight: 600;
}

.tabulator .tabulator-footer .tabulator-page.disabled {
    color: #6c757d;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Placeholder (nessun dato) */
.tabulator .tabulator-tableholder .tabulator-placeholder {
    color: #6c757d;
    font-size: 0.9rem;
    padding: 2rem 1rem;
}

.tabulator .tabulator-tableholder .tabulator-placeholder span {
    font-weight: 500;
}

/* Loader */
.tabulator .tabulator-loader {
    background-color: rgba(255, 255, 255, 0.85);
}

.tabulator .tabulator-loader .tabulator-loader-msg {
    font-size: 0.9rem;
    color: #0d6efd;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    padding: 1rem 2rem;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
}

.tabulator .tabulator-loader .tabulator-loader-msg::before {
    content: '';
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    margin-right: 0.5rem;
    border: 0.2rem solid #0d6efd;
    border-right-color: transparent;
    border-radius: 50%;
    animation: tabulator-loader-spin 0.6s linear infinite;
    vertical-align: middle;
}

@keyframes tabulator-loader-spin {
    to { transform: rotate(360deg); }
}

/* Movimento scorrimento header (sticky) */
.tabulator .tabulator-header {
    position: sticky;
    top: 0;
    z-index: 10;
}

.tabulator .tabulator-headers {
    position: relative;
}

/* Tabulator: colonna azioni allineamento */
.tabulator .tabulator-row .tabulator-cell .btn-action {
    padding: 0.15rem 0.35rem;
    font-size: 0.8rem;
    line-height: 1.2;
}

.tabulator .tabulator-row .tabulator-cell .btn-action + .btn-action {
    margin-left: 0.15rem;
}

/* Colori alternativi per Tabulator rows in base a dati */
.tabulator .tabulator-row.row-danger {
    background-color: #fce4e4;
}

.tabulator .tabulator-row.row-warning {
    background-color: #fff3cd;
}

.tabulator .tabulator-row.row-success {
    background-color: #d1e7dd;
}

/* -----------------------------------------------
   5. BARRA DI RICERCA TABULATOR
   ----------------------------------------------- */
.tabulator-wrapper {
    position: relative;
}

.tabulator-search-bar {
    position: relative;
}

.tabulator-search-bar .input-group {
    max-width: 400px;
}

.tabulator-search-bar .input-group .input-group-text {
    background-color: #fff;
    border-right: none;
    color: #6c757d;
}

.tabulator-search-bar .input-group .form-control {
    border-left: none;
    font-size: 0.875rem;
}

.tabulator-search-bar .input-group .form-control:focus {
    box-shadow: none;
    border-color: #ced4da;
}

.tabulator-search-bar .input-group .form-control:focus + .input-group-text {
    border-color: #86b7fe;
}

.tabulator-search-bar .tabulator-search-clear {
    border-color: #ced4da;
    color: #6c757d;
}

.tabulator-search-bar .tabulator-search-clear:hover {
    color: #dc3545;
    background-color: #fff;
}

/* -----------------------------------------------
   6. BADGE E FORMATTER CUSTOM
   ----------------------------------------------- */

/* Badge generici */
.badge {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.3em 0.6em;
    vertical-align: middle;
}

/* Badge per formatters Tabulator */
.tabulator .badge {
    font-size: 0.75rem;
}

/* Badge Sì/No */
.badge.bg-success,
.badge.bg-info,
.badge.bg-warning,
.badge.bg-secondary {
    transition: opacity 0.15s ease;
}

/* Extra badge variants */
.badge-outline-success {
    color: #198754;
    border: 1px solid #198754;
    background-color: transparent;
}

.badge-outline-danger {
    color: #dc3545;
    border: 1px solid #dc3545;
    background-color: transparent;
}

.badge-outline-info {
    color: #0dcaf0;
    border: 1px solid #0dcaf0;
    background-color: transparent;
}

/* -----------------------------------------------
   7. HTMX TRANSAZIONI E ANIMAZIONI
   ----------------------------------------------- */

/* Transizione fade per swap HTMX */
.htmx-swapping {
    opacity: 0;
    transition: opacity 0.2s ease-out;
}

.htmx-added {
    opacity: 0;
}

.htmx-settling {
    opacity: 1;
    transition: opacity 0.2s ease-in;
}

/* Loading state */
.htmx-loading {
    position: relative;
    pointer-events: none;
}

.htmx-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.6);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.htmx-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2rem;
    height: 2rem;
    margin: -1rem 0 0 -1rem;
    border: 0.25rem solid #0d6efd;
    border-right-color: transparent;
    border-radius: 50%;
    animation: htmx-loader-spin 0.6s linear infinite;
    z-index: 101;
}

@keyframes htmx-loader-spin {
    to { transform: rotate(360deg); }
}

/* Indicatore di richiesta in corso (mostrato nell'elemento trigger) */
.htmx-request {
    opacity: 0.7;
    transition: opacity 0.15s ease;
}

/* Highlight elemento aggiornato */
.htmx-settling.htmx-added {
    animation: htmx-highlight 1.5s ease-out;
}

@keyframes htmx-highlight {
    0% {
        background-color: rgba(13, 110, 253, 0.15);
    }
    100% {
        background-color: transparent;
    }
}

/* Transizione per alert che scompaiono */
.alert-dismissible.fade.show {
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.alert-dismissible.fade:not(.show) {
    opacity: 0;
    transform: translateY(-0.5rem);
}

/* -----------------------------------------------
   8. RESPONSIVE UTILITIES
   ----------------------------------------------- */

/* Nascondi colonne Tabulator su mobile (< 768px) */
@media (max-width: 767.98px) {
    .tabulator .tabulator-row .tabulator-cell.tabulator-hide-mobile {
        display: none !important;
    }
    .tabulator .tabulator-header .tabulator-col.tabulator-hide-mobile {
        display: none !important;
    }
}

/* Nascondi colonne su tablet (< 992px) */
@media (max-width: 991.98px) {
    .tabulator .tabulator-row .tabulator-cell.tabulator-hide-tablet {
        display: none !important;
    }
    .tabulator .tabulator-header .tabulator-col.tabulator-hide-tablet {
        display: none !important;
    }
}

/* Helper generici responsive */
.d-mobile-only {
    display: none !important;
}

@media (max-width: 767.98px) {
    .d-mobile-only {
        display: initial !important;
    }
    .d-mobile-none {
        display: none !important;
    }
    /* Riduci padding celle su mobile */
    .tabulator .tabulator-row .tabulator-cell {
        padding: 0.3rem 0.4rem;
    }
    .tabulator .tabulator-header .tabulator-col .tabulator-col-content {
        padding: 0.3rem 0.4rem;
    }
    /* Titoli più compatti su mobile */
    h4 {
        font-size: 1.1rem;
    }
    .btn-sm {
        font-size: 0.75rem;
    }
    /* Search bar full width su mobile */
    .tabulator-search-bar .input-group {
        max-width: 100%;
    }
}

@media (max-width: 575.98px) {
    .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

/* -----------------------------------------------
   9. STAMPA
   ----------------------------------------------- */
@media print {
    .navbar,
    .footer,
    .btn,
    .tabulator-search-bar,
    .tabulator-paginator {
        display: none !important;
    }
    .tabulator {
        border: none !important;
    }
    .tabulator .tabulator-header {
        background-color: #f8f9fa !important;
        color: #000 !important;
        border-bottom: 2px solid #000 !important;
    }
    .tabulator .tabulator-header .tabulator-col {
        background-color: #f8f9fa !important;
        color: #000 !important;
    }
}

/* -----------------------------------------------
   10. VARIE
   ----------------------------------------------- */

/* Dropdown menu migliorato */
.dropdown-menu {
    font-size: 0.875rem;
    border: none;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
}

.dropdown-item {
    padding: 0.4rem 1rem;
}

.dropdown-item:hover {
    background-color: #f0f4ff;
}

/* Toast personalizzati */
#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#toast-container .toast {
    min-width: 250px;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.15);
}

/* Loading spinner generale */
.spinner-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

/* Card per sezione dettaglio */
.detail-section {
    background-color: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.detail-section h6 {
    color: #0d6efd;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
}

/* -----------------------------------------------
   11. SCHEDA CONTABILE (scheda.html)
   ----------------------------------------------- */
.scheda-summary {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: .5rem;
    padding: .75rem;
}
.scheda-row-selected {
    background: #e7f1ff;
}
.scheda-special {
    background: #f1f3f5;
    font-weight: 600;
}

/* -----------------------------------------------
   12. CARD DASHBOARD CONTABILE
   ----------------------------------------------- */
.border-left-primary {
    border-left: 0.25rem solid #4e72df !important;
}
.border-left-success {
    border-left: 0.25rem solid #1cc88a !important;
}
.border-left-info {
    border-left: 0.25rem solid #36b9cc !important;
}
.border-left-warning {
    border-left: 0.25rem solid #f6c23e !important;
}
.border-left-danger {
    border-left: 0.25rem solid #f6686d !important;
}

/* -----------------------------------------------
   13. ALBERO GERARCHICO CONTABILE
   ----------------------------------------------- */
#tree-container {
    overflow-y: auto;
    max-height: 700px;
}
.node-label.group {
    font-weight: bold;
    color: #4e72df;
}
.node-label.account {
    color: #36b9cc;
    font-weight: 500;
}
.node-label.subaccount {
    color: #1cc88a;
}
.jstree-anchor {
    padding: 5px 8px;
    border-radius: 4px;
}
.jstree-anchor:hover {
    background-color: #f0f0f0;
}
#stat-gruppi, #stat-conti, #stat-sottoconto {
    font-weight: bold;
    color: #4e72df;
}

/* -----------------------------------------------
   14. FORM SOTTOCONTO
   ----------------------------------------------- */
.form-section {
    background-color: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid #0d6efd;
}
.form-section h4 {
    color: #0d6efd;
    margin-bottom: 15px;
    font-weight: 600;
}
.form-section i {
    margin-right: 8px;
}
.preview-saldo {
    background-color: white;
    padding: 15px;
    border-radius: 6px;
    border: 2px solid #e9ecef;
}
.preview-saldo .label {
    font-weight: 500;
    color: #666;
    display: inline-block;
    width: 150px;
}
.preview-saldo .value {
    font-weight: bold;
    color: #0d6efd;
    font-size: 1.1rem;
}
.info-field {
    background-color: white;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 10px;
}
.info-field .label {
    font-weight: 500;
    color: #666;
    font-size: 0.9rem;
}
.info-field .value {
    color: #333;
    font-weight: 500;
}
.btn-section {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #dee2e6;
}
.loading-spinner {
    display: none;
    margin-left: 10px;
}
.spin {
    animation: spin-animation 1s linear infinite;
}
@keyframes spin-animation {
    to { transform: rotate(360deg); }
}

/* -----------------------------------------------
   15. LISTA SOTTOCONTI
   ----------------------------------------------- */
.filter-section {
    background-color: #f8f9fa;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    border: 1px solid #dee2e6;
}
.filter-group {
    margin-bottom: 12px;
}
.saldo-positivo {
    color: #198754;
    font-weight: bold;
}
.saldo-negativo {
    color: #dc3545;
    font-weight: bold;
}
.stato-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 500;
}
.stato-attivo {
    background-color: #d1e7dd;
    color: #0f5132;
}
.stato-cancellato {
    background-color: #f8d7da;
    color: #842029;
}
