/* components/tables.css
   Tabelle (.table, .table-custom), dropdown nelle tabelle e override finali (ex table.css).
*/

.table-custom {
    min-width: 100%;
}

.table-custom th,
.table-custom td {
    white-space: nowrap;
    padding: 0.75rem;
    vertical-align: middle;
}

.table-custom th {
    background-color: var(--light-color);
    position: sticky;
    top: 0;
    z-index: 1;
}

/* ============================================
   TABELLE - Componente standardizzato
   ============================================ */
.table {
    width: 100%;
    margin-bottom: 1rem;
    border-radius: var(--border-radius);
    overflow: hidden;
    border-collapse: separate;
    border-spacing: 0;
}

.table th {
    background-color: var(--primary-color);
    color: white;
    border-bottom: none;
    padding: 1rem;
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
}

.table td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.table tbody tr {
    transition: background-color 0.15s ease-in-out;
}

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

.table-primary {
    background-color: var(--primary-color);
    color: white;
}

.table-primary td {
    color: white;
    border-top-color: rgba(255, 255, 255, 0.2);
}

/* Tabella con bordi */
.table-bordered {
    border: 1px solid var(--border-color);
}

.table-bordered th,
.table-bordered td {
    border: 1px solid var(--border-color);
}

/* ============================================
   TABLE-CUSTOM - Componente standardizzato per liste
   Usato in: anagrafica, associazioni, manage_accounts, ecc.
   ============================================ */
.table-custom {
    width: 100%;
    background-color: var(--card-bg);
    border-collapse: separate;
    border-spacing: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border-radius: var(--border-radius, 0.375rem);
    overflow: hidden;
}

.table-custom thead th {
    white-space: nowrap;
    padding: 12px 12px;
    font-size: 0.9rem;
    text-align: left;
    vertical-align: middle;
    position: relative;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease-in-out;
}

/* Colonne centrate (ID, azioni, numeri) */
.table-custom thead th.col-id,
.table-custom thead th.col-tessera,
.table-custom thead th.col-azioni,
.table-custom thead th.col-numero,
.table-custom thead th.col-regione,
.table-custom thead th.col-tipo,
.table-custom thead th.col-matricola,
.table-custom thead th.col-data {
    text-align: center;
}

/* Icone di ordinamento */
.table-custom thead th.sortable {
    padding-right: 28px;
}

.table-custom thead th.sortable:not(.col-id):not(.col-tessera):not(.col-azioni):not(.col-numero):not(.col-regione):not(.col-comitato):not(.col-tipo):not(.col-matricola) {
    padding-right: 28px;
}

.table-custom thead th .sort-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    opacity: 0.7;
    transition: opacity 0.2s ease-in-out;
    display: inline-block;
    width: 12px;
    text-align: center;
}

.table-custom thead th:hover .sort-icon,
.table-custom thead th.sorted .sort-icon {
    opacity: 1;
}

.table-custom thead th.sorted-asc .sort-icon::before {
    content: "▲";
    opacity: 1;
}

.table-custom thead th.sorted-desc .sort-icon::before {
    content: "▼";
    opacity: 1;
}

.table-custom thead th:not(.sorted) .sort-icon::before {
    content: "⇅";
}

.table-custom td {
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    text-align: left;
}

/* Prima colonna - padding sinistro maggiore per distanza dal bordo */
.table-custom td:first-child,
.table-custom thead th:first-child {
    padding-left: 16px;
}

/* Colonne centrate (ID, azioni, numeri) */
.table-custom td.col-id,
.table-custom td.col-tessera,
.table-custom td.col-azioni,
.table-custom td.col-numero,
.table-custom td.col-regione,
.table-custom td.col-tipo,
.table-custom td.col-matricola,
.table-custom td.col-data {
    text-align: center;
}

.table-custom tbody tr {
    position: relative;
}

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

/* Colonne standardizzate - si adattano al contenuto */
.table-custom .col-id,
.table-custom .col-tessera {
    width: 80px;
}

.table-custom .col-azioni {
    width: 80px;
}

.table-custom .col-regione {
    width: 100px;
}

/* Colonne con testo che può essere lungo - si adattano al contenuto */
.table-custom .col-denominazione,
.table-custom .col-associazione,
.table-custom .col-contatti,
.table-custom .col-indirizzo {
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
    min-width: 150px;
}

/* Truncate text per celle con testo molto lungo */
.truncate-text {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* Container per tabelle responsive */
.table-responsive {
    display: block;
    width: 100%;
    max-width: 100%; /* Assicura che non superi il contenitore */
    -webkit-overflow-scrolling: touch;
}

.table-responsive .table,
.table-responsive .table-custom {
    margin-bottom: 0;
}

/* Responsive adjustments per table-custom */
@media (max-width: 992px) {
    .table-custom {
        font-size: 0.875rem;
    }
    
    .table-custom thead th {
        padding: 10px 6px;
    }
    
    .table-custom td {
        padding: 8px 6px;
    }
    
    .table-custom .col-denominazione,
    .table-custom .col-associazione,
    .table-custom .col-contatti,
    .table-custom .col-indirizzo {
        min-width: 120px;
        max-width: 150px;
    }
}

@media (max-width: 768px) {
    .table-custom {
        font-size: 0.8rem;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    }
    
    
    
    .table-custom .col-denominazione,
    .table-custom .col-associazione,
    .table-custom .col-contatti,
    .table-custom .col-indirizzo {
        min-width: 100px;
        max-width: 120px;
    }
    
    .truncate-text {
        max-width: 120px;
    }
    
    .table-custom thead th .sort-icon {
        font-size: 0.7rem;
        right: 4px;
    }
}

/* Responsive table styles */
@media (max-width: 768px) {
    .table th {
        padding: 0.75rem 0.5rem;
        font-size: 13px;
        white-space: nowrap;
    }
    
    .table td {
        padding: 0.5rem 0.5rem;
        font-size: 12px;
        word-wrap: break-word;
    }
    
    /* Container per scroll orizzontale */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 5px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    .table-responsive::-webkit-scrollbar {
        height: 8px;
    }
    
    .table-responsive::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 4px;
    }
    
    .table-responsive::-webkit-scrollbar-thumb {
        background: var(--primary-color);
        border-radius: 4px;
    }
    
    .table-responsive::-webkit-scrollbar-thumb:hover {
        background: #45a049;
    }
}

@media (max-width: 480px) {
    .table th {
        padding: 0.5rem 0.25rem;
        font-size: 12px;
    }
    
    .table td {
        padding: 0.4rem 0.25rem;
        font-size: 11px;
    }
    
}

/* ============================================
   DROPDOWN IN TABELLA - Gestione overflow
   ============================================ */

/* Container per dropdown nella tabella - permette overflow visibile di default */
.table-responsive {
    overflow-x: auto;
    overflow-y: visible !important;
}

/* Quando il dropdown è aperto, assicura overflow visibile su tutti i container */
.table-responsive.dropdown-open {
    overflow: visible !important;
}

.card-body.dropdown-open {
    overflow: visible !important;
}

.card.dropdown-open {
    overflow: visible !important;
}

/* Alternativa con :has() per browser che lo supportano */
.table-responsive:has(.dropdown.show) {
    overflow: visible !important;
}

.card-body:has(.table-responsive .dropdown.show) {
    overflow: visible !important;
}

.card:has(.table-responsive .dropdown.show) {
    overflow: visible !important;
}

/* Quando il dropdown è aperto, espandi la riga */
.table-custom tbody tr.dropdown-expanded {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

/* Dropdown menu nella tabella - posizionamento migliorato */
.table-custom .dropdown-menu {
    min-width: 200px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    position: absolute;
    z-index: 1050;
}

/* Assicura che il menu sia sempre sopra gli altri elementi quando aperto */
.table-custom .dropdown.show .dropdown-menu {
    display: block;
    z-index: 1050;
}

/* Badge con icona */
.badge i {
    margin-right: 0.3em;
}

/* Rimuovi grassetti da tutto nella tabella */
.table-custom td strong {
    font-weight: normal;
}

/* Colonne specifiche per manage_accounts */
.col-username {
    min-width: 150px;
}

.col-tipo {
    min-width: 120px;
}

.col-associazione {
    min-width: 200px;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.col-matricola {
    min-width: 100px;
}

/* ============================================
   FIX DROPDOWN IN TABELLE SCROLLABILI
   Usa la configurazione nativa di Bootstrap 5 + Popper.js
   Gestito da table-dropdown-fix.js
   ============================================ */

/* Contenitori di tabelle - mantieni la struttura */
.table-responsive,
.table-container {
    position: relative;
    /* overflow sarà gestito dinamicamente da JS quando necessario */
}

/* Quando un dropdown è aperto, aumenta lo z-index del contenitore */
.table-responsive:has(.dropdown.show),
.table-container:has(.dropdown.show) {
    z-index: 1050;
    position: relative;
}

/* Dropdown nelle tabelle - miglioramenti visuali */
.table .dropdown-menu,
.table-responsive .dropdown-menu,
.table-container .dropdown-menu {
    z-index: 1060 !important;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
    min-width: 10rem;
    max-width: 20rem;
}

/* Migliora lo stile del dropdown toggle nei bottoni piccoli */
.table .btn-sm.dropdown-toggle {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

.table .btn-sm.dropdown-toggle::after {
    margin-left: 0.25em;
}

/* Responsive - dropdown più largo su desktop */
@media (min-width: 768px) {
    .table .dropdown-menu,
    .table-responsive .dropdown-menu,
    .table-container .dropdown-menu {
        min-width: 12rem;
    }
}

/* ============================================
   OVERRIDE FINALI (ex table.css): superfici bianche, header scuro
   ============================================ */
.table-custom {
  margin-bottom: 0;
  font-size: 14px;
  text-align: left;
}

/* Keep table surfaces white across all modules */
.table,
.table-responsive,
.table-container,
.table td,
.table tbody tr,
.table-custom td,
.table-custom tbody tr {
  background-color: #fff;
}

.table-hover tbody tr:hover,
.table tbody tr:hover,
.table-custom tbody tr:hover,
.table-striped tbody tr:nth-of-type(odd),
.table-striped tbody tr:nth-of-type(odd):hover {
  background-color: #fff;
}

.table-custom thead {
  background-color: var(--table-header-color) !important;
  color: #fff !important;
}

.table-custom thead th {
  background-color: var(--table-header-color) !important;
  color: #fff !important;
  font-weight: 600;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.table-custom thead th:hover {
  background-color: var(--table-header-color-hover, var(--hover-color)) !important;
}

.table-custom tbody tr {
  background-color: #fff;
  transition: background-color var(--transition-time) ease;
}

.table-custom tbody tr:hover {
  background-color: var(--table-row-hover, var(--secondary-color));
}

.table-custom td {
  vertical-align: middle;
  padding: 0.625rem 0.75rem;
}

.table-custom tbody tr:not(:last-child) td {
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

/* Sort icon contrast on dark headers */
.table-custom thead th .sort-icon,
.table-custom thead th.sorted-asc .sort-icon::before,
.table-custom thead th.sorted-desc .sort-icon::before,
.table-custom thead th:not(.sorted) .sort-icon::before {
  color: rgba(255, 255, 255, 0.9) !important;
}

/* Scrollbar personalizzata per tabelle */
.table-container::-webkit-scrollbar,
.table-responsive::-webkit-scrollbar {
  height: 8px;
}

.table-container::-webkit-scrollbar-track,
.table-responsive::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb,
.table-responsive::-webkit-scrollbar-thumb {
  background: var(--primary-color);
  border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover,
.table-responsive::-webkit-scrollbar-thumb:hover {
  background: var(--hover-color);
}

.hidden-column {
  display: none;
}

@media (max-width: 768px) {
  .table-custom thead th {
    padding: 0.75rem 0.5rem;
    font-size: 13px;
    white-space: nowrap;
  }

  .table-custom td {
    padding: 0.5rem;
    font-size: 12px;
    word-wrap: break-word;
  }

  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--border-radius);
  }
}

@media (max-width: 480px) {
  .table-custom thead th {
    padding: 0.5rem 0.25rem;
    font-size: 12px;
  }

  .table-custom td {
    padding: 0.4rem 0.25rem;
    font-size: 11px;
  }
}
