/* Tablet portrait band (768–992px): home form, editor DB, admin_db filters/table */

/* ── Home: stack col-md-* (Bootstrap md kicks in at 768 and squeezes fields) ── */
@media (min-width: 768px) and (max-width: 991.98px) {
  #main-inserimento-form [class*="col-md-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }

  #main-inserimento-form .col-md-3,
  #main-inserimento-form .row.g-2.p-2.rounded-3 .col-md-6 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  #main-inserimento-form .form-control,
  #main-inserimento-form .form-select,
  #main-inserimento-form .form-control-lg {
    min-height: 42px;
    font-size: 0.95rem;
  }

  #main-inserimento-form .input-group-text {
    min-width: 2.4rem;
    justify-content: center;
  }

  .attivita-panel-col {
    width: 100%;
  }
}

/* ── Editor DB: collapsible create forms (desktop ≥992 always expanded) ── */
@media (min-width: 992px) {
  .registry-create-toggle {
    display: none !important;
  }

  .registry-create-body.collapse {
    display: block !important;
    height: auto !important;
    visibility: visible !important;
  }
}

@media (min-width: 768px) and (max-width: 991.98px) {
  .registry-create-title {
    display: none !important;
  }

  .registry-create-toggle {
    text-align: left;
  }

  .registry-create-toggle .registry-create-chevron {
    transition: transform 0.2s ease;
  }

  .registry-create-toggle[aria-expanded="true"] .registry-create-chevron {
    transform: rotate(180deg);
  }

  .registry-create-col.border-end {
    border-right: 0 !important;
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 0.5rem;
    margin-bottom: 0.65rem;
  }

  #adminTabsContent .table-has-actions-col {
    --tk-actions-col-width: 4.35rem;
  }

  #adminTabsContent .table-actions-col .btn span.d-none,
  #adminTabsContent .table-actions-col .btn span.d-xl-inline {
    display: none !important;
  }

  #adminTabsContent .table-actions-col .btn {
    padding-left: 0.35rem !important;
    padding-right: 0.35rem !important;
  }
}

/* ── Admin DB: tablet table — hide extra columns (visibility collapse, not display:none) ── */
@media (min-width: 577px) and (max-width: 991.98px) {
  #tabella_tot .table-has-actions-col {
    --tk-actions-col-width: 3.85rem;
  }

  #tabella_tot .tabella-rapportini .hide-xs {
    width: 0 !important;
    max-width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    overflow: hidden !important;
    white-space: nowrap !important;
    font-size: 0 !important;
    line-height: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: collapse;
  }

  #tabella_tot .tabella-rapportini col.hide-xs-col {
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
  }

  #tabella_tot .tabella-rapportini col.tabella-col-svolgimento {
    min-width: 30%;
  }

  #tabella_tot .table-actions-col .btn span.d-xl-inline {
    display: none !important;
  }

  #tabella_tot .tabella-rapportini {
    font-size: 0.9rem !important;
  }

  #tabella_tot .tabella-rapportini thead th {
    font-size: var(--tk-font-th, 0.84rem) !important;
    padding-top: var(--tk-th-pad-v-display, 0.24rem) !important;
    padding-bottom: var(--tk-th-pad-v-display, 0.24rem) !important;
    padding-left: var(--tk-cell-pad-h, 0.5rem) !important;
    padding-right: var(--tk-cell-pad-h, 0.5rem) !important;
  }

  #tabella_tot .tabella-rapportini tbody td {
    padding: 0.48rem 0.42rem !important;
  }

  #tabella_tot .tabella-rapportini td.ps-4.cell-compact .fw-bold {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    font-size: 0.88rem;
    line-height: 1.2;
  }

  #tabella_tot .table-responsive,
  #tabella_tot .table-responsive-fixed {
    overflow-x: hidden !important;
  }
}

/* ── Admin DB filters: clean single-column grid (overrides 769–991 flex-wrap mess) ── */
@media (min-width: 768px) and (max-width: 991.98px) {
  #filter-container .filters-card {
    border-radius: 0.8rem !important;
    margin-bottom: 0.35rem !important;
  }

  #filter-container .filters-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.58rem !important;
    flex-wrap: unset !important;
  }

  #filter-container .filters-grid > * {
    order: initial !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    flex: unset !important;
  }

  #filter-container .filters-row-2 {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.5rem !important;
    width: 100% !important;
  }

  #filter-container .filters-row-2 .filter-field-stack,
  #filter-container .filters-row-2 .input-group {
    background: var(--bg-light);
    border-radius: 0.55rem;
    padding: 0.12rem;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
  }

  #filter-container .filters-entity-cluster {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
    width: 100% !important;
  }

  #filtri-avanzati {
    width: 100% !important;
    max-width: none !important;
  }

  #container-filtri-dinamici {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
  }

  #container-filtri-dinamici > * {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    margin: 0 !important;
  }

  #container-filtri-dinamici .filter-field-stack,
  #container-filtri-dinamici .filtro-dyn {
    border-radius: 0.55rem;
    background: var(--bg-light);
    padding: 0.12rem;
    width: 100% !important;
  }

  #container-filtri-dinamici .filter-field-stack .form-control,
  #container-filtri-dinamici .filter-field-stack .form-select,
  #container-filtri-dinamici .filtro-dyn .form-control,
  #container-filtri-dinamici .filtro-dyn .form-select {
    width: 100% !important;
    min-width: 0 !important;
    background: var(--bg-light) !important;
  }

  #search-commessa,
  #q_global,
  #f_utente,
  #f_data_dal,
  #f_data_al,
  #f_reparto,
  #f_commessa,
  #f_attivita {
    min-height: 38px !important;
    font-size: 0.86rem !important;
  }

  #filter-container .filters-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.45rem !important;
    width: 100% !important;
    margin-left: 0 !important;
  }

  #filter-container .filters-actions > :nth-child(3) {
    grid-column: 1 / -1;
  }

  #filter-container .filters-actions .btn,
  #filter-container .filters-actions a.btn {
    min-height: 38px !important;
    font-size: 0.82rem !important;
  }

  #tabella_tot {
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
  }

  #tabella_tot .table-responsive,
  #tabella_tot .table-responsive-fixed {
    max-height: 52dvh !important;
    overflow-y: auto !important;
  }
}
