/*
 * Checkup Centre - sistema tabelle
 * Stili globali per tabelle Bootstrap e DataTables.
 * Le griglie tecniche (FullCalendar, editor e layout) restano escluse.
 */

:root {
  --cc-table-primary: #4663a9;
  --cc-table-primary-dark: #354e8c;
  --cc-table-primary-soft: #eef3ff;
  --cc-table-accent: #23b195;
  --cc-table-text: #25324a;
  --cc-table-muted: #738097;
  --cc-table-line: #e6ebf3;
  --cc-table-head: #f5f7fc;
  --cc-table-hover: #f1f5ff;
  --cc-table-surface: #ffffff;
  --cc-table-shadow: 0 10px 30px rgba(42, 55, 92, 0.08);
}

/* Contenitore */
.table-responsive {
  position: relative;
  margin-bottom: 22px;
  border: 1px solid var(--cc-table-line);
  border-radius: 16px;
  background: var(--cc-table-surface);
  box-shadow: var(--cc-table-shadow);
  -webkit-overflow-scrolling: touch;
}

.table-responsive::-webkit-scrollbar,
.dataTables_scrollBody::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.table-responsive::-webkit-scrollbar-track,
.dataTables_scrollBody::-webkit-scrollbar-track {
  background: #f1f4f9;
  border-radius: 999px;
}

.table-responsive::-webkit-scrollbar-thumb,
.dataTables_scrollBody::-webkit-scrollbar-thumb {
  border: 2px solid #f1f4f9;
  border-radius: 999px;
  background: #aab6cb;
}

/* Tabelle applicative: non intercetta le tabelle interne di FullCalendar */
table.table {
  width: 100%;
  margin: 0;
  border: 0;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--cc-table-surface);
  color: var(--cc-table-text);
  font-size: 14px;
}

/* Anche le tabelle semplici, prive di un wrapper responsive, hanno una card. */
table.table:not(.dataTable) {
  border: 1px solid var(--cc-table-line);
  border-radius: 16px;
  box-shadow: var(--cc-table-shadow);
  overflow: hidden;
}

.table-responsive > table.table:not(.dataTable) {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

table.table > thead > tr > th,
table.table > thead > tr > td {
  position: relative;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid #dfe5ef;
  background: var(--cc-table-head);
  color: #536078;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0.055em;
  text-transform: uppercase;
  vertical-align: middle;
  white-space: nowrap;
}

table.table > tbody > tr > td,
table.table > tbody > tr > th {
  padding: 13px 16px;
  border: 0;
  border-bottom: 1px solid var(--cc-table-line);
  background-color: transparent;
  color: var(--cc-table-text);
  line-height: 1.45;
  vertical-align: middle;
  transition: background-color 160ms ease, color 160ms ease;
}

table.table > tbody > tr:last-child > td,
table.table > tbody > tr:last-child > th {
  border-bottom: 0;
}

table.table.table-striped > tbody > tr:nth-of-type(odd),
table.table.table-striped > tbody > tr:nth-of-type(even) {
  background: transparent;
}

table.table.table-striped > tbody > tr:nth-of-type(even) > td,
table.table.table-striped > tbody > tr:nth-of-type(even) > th {
  background-color: #fbfcff;
}

table.table > tbody > tr:hover > td,
table.table > tbody > tr:hover > th,
table.table.table-striped > tbody > tr:hover > td,
table.table.table-striped > tbody > tr:hover > th {
  background-color: var(--cc-table-hover);
}

table.table > tbody > tr[onclick]:hover > td:first-child {
  box-shadow: inset 3px 0 0 var(--cc-table-primary);
}

table.table > tfoot > tr > th,
table.table > tfoot > tr > td {
  padding: 13px 16px;
  border: 0;
  border-top: 1px solid var(--cc-table-line);
  background: #f8faff;
  color: #536078;
  font-weight: 700;
}

/* I vecchi bordi Bootstrap diventano separatori più leggeri */
table.table-bordered > thead > tr > th,
table.table-bordered > thead > tr > td,
table.table-bordered > tbody > tr > th,
table.table-bordered > tbody > tr > td,
table.table-bordered > tfoot > tr > th,
table.table-bordered > tfoot > tr > td {
  border-right: 0;
  border-left: 0;
}

/* Contenuti frequenti nelle celle */
table.table td a:not(.btn) {
  color: var(--cc-table-primary);
  font-weight: 600;
  text-decoration: none;
}

table.table td a:not(.btn):hover,
table.table td a:not(.btn):focus {
  color: var(--cc-table-primary-dark);
  text-decoration: underline;
}

table.table td .btn {
  border-radius: 8px;
  font-weight: 600;
  box-shadow: none;
  transition: transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

table.table td .btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 12px rgba(42, 55, 92, 0.12);
}

table.table td .btn-xs {
  padding: 5px 9px;
  font-size: 11px;
}

table.table td .label {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.035em;
  line-height: 1;
}

table.table td .label-default {
  background: #e9edf4;
  color: #657187;
}

table.table td .label-success {
  background: #dcf7ef;
  color: #127b68;
}

table.table td .label-warning {
  background: #fff1d8;
  color: #a8640a;
}

table.table td .label-danger {
  background: #ffe5e8;
  color: #b93c4b;
}

/*
 * Pulsanti azione legacy
 * Intercetta soltanto i button senza classi che contengono un'icona.
 */
button:not([class]):has(i) {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  min-width: 36px;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  margin: 2px;
  padding: 7px 10px;
  gap: 6px;
  border: 1px solid #dce3ee;
  border-radius: 9px;
  outline: 0;
  background: #fff;
  color: #59677e;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
  box-shadow: 0 3px 9px rgba(42, 55, 92, 0.07);
  cursor: pointer;
  transition:
    border-color 150ms ease,
    background-color 150ms ease,
    color 150ms ease,
    box-shadow 150ms ease,
    transform 150ms ease;
}

button:not([class]):has(i) > i {
  margin: 0 !important;
  color: inherit !important;
  font-size: 13px;
  line-height: 1;
}

button:not([class]):has(i):hover {
  border-color: #c8d4e8;
  background: var(--cc-table-primary-soft);
  color: var(--cc-table-primary);
  box-shadow: 0 6px 14px rgba(42, 55, 92, 0.12);
  transform: translateY(-1px);
}

button:not([class]):has(i):focus-visible {
  border-color: var(--cc-table-primary);
  box-shadow: 0 0 0 3px rgba(70, 99, 169, 0.16);
}

button:not([class]):has(i):active {
  box-shadow: 0 2px 6px rgba(42, 55, 92, 0.1);
  transform: translateY(0);
}

button:not([class]):has(i):disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* Le varianti vengono riconosciute dagli attributi già presenti nel markup. */
button:not([class])[title*="Aggiungi"]:has(i),
button:not([class])[title*="Nuovo"]:has(i) {
  border-color: #bde7dc;
  background: #edfaf6;
  color: #16806c;
}

button:not([class])[title*="Aggiungi"]:has(i):hover,
button:not([class])[title*="Nuovo"]:has(i):hover {
  border-color: #8ed4c3;
  background: #dcf6ef;
  color: #106c5b;
}

button:not([class])[title*="Modifica"]:has(i) {
  border-color: #ccd8f2;
  background: #f0f4ff;
  color: var(--cc-table-primary);
}

button:not([class])[title*="Modifica"]:has(i):hover {
  border-color: #aabde4;
  background: #e2eaff;
  color: var(--cc-table-primary-dark);
}

button:not([class])[title*="Elimina"]:has(i),
button:not([class])[title*="Annulla"]:has(i) {
  border-color: #f1cbd0;
  background: #fff1f3;
  color: #b54150;
}

button:not([class])[title*="Elimina"]:has(i):hover,
button:not([class])[title*="Annulla"]:has(i):hover {
  border-color: #e6aeb6;
  background: #ffe2e6;
  color: #9f3240;
}

/* DataTables: barra comandi */
.dataTables_wrapper {
  color: var(--cc-table-text);
}

.dataTables_wrapper > .row:first-child {
  display: flex;
  min-height: 72px;
  align-items: center;
  margin: 0;
  padding: 14px 16px 12px;
  gap: 12px;
  border: 1px solid var(--cc-table-line);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  background: var(--cc-table-surface);
  box-shadow: 0 8px 24px rgba(42, 55, 92, 0.055);
}

.dataTables_wrapper > .row:first-child > [class*="col-"] {
  padding-right: 0;
  padding-left: 0;
}

.dataTables_wrapper > .row:first-child + .row {
  margin: 0;
  border-right: 1px solid var(--cc-table-line);
  border-left: 1px solid var(--cc-table-line);
  background: var(--cc-table-surface);
}

.dataTables_wrapper > .row:first-child + .row > [class*="col-"] {
  padding: 0;
}

.dataTables_wrapper > .row:last-child {
  display: flex;
  min-height: 66px;
  align-items: center;
  margin: 0 0 22px;
  padding: 12px 16px;
  border: 1px solid var(--cc-table-line);
  border-top: 0;
  border-radius: 0 0 16px 16px;
  background: var(--cc-table-surface);
  box-shadow: var(--cc-table-shadow);
}

.dataTables_wrapper > .row:last-child > [class*="col-"] {
  padding-right: 0;
  padding-left: 0;
}

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
  margin: 0;
  color: var(--cc-table-muted);
  font-size: 12px;
  font-weight: 600;
}

.dataTables_wrapper .dataTables_filter {
  text-align: right;
}

.dataTables_wrapper .dataTables_filter label {
  position: relative;
  margin: 0;
}

.dataTables_wrapper .dataTables_filter input {
  width: min(260px, 100%);
  height: 42px;
  margin-left: 8px;
  padding: 8px 14px;
  border: 1px solid #dce2ed;
  border-radius: 11px;
  outline: 0;
  background: #f8faff;
  color: var(--cc-table-text);
  font-size: 13px;
  font-weight: 500;
  box-shadow: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

.dataTables_wrapper .dataTables_filter input:focus {
  border-color: var(--cc-table-primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(70, 99, 169, 0.13);
}

.dataTables_wrapper .dataTables_length select {
  height: 38px;
  margin: 0 6px;
  padding: 6px 28px 6px 10px;
  border: 1px solid #dce2ed;
  border-radius: 9px;
  outline: 0;
  background-color: #f8faff;
  color: var(--cc-table-text);
  font-weight: 700;
}

.dataTables_wrapper .dataTables_info {
  padding-top: 0;
  color: var(--cc-table-muted);
  font-size: 12px;
  font-weight: 500;
}

/* DataTables: tabella e ordinamento */
.dataTables_wrapper table.dataTable {
  width: 100% !important;
  margin: 0 !important;
  border: 0;
  border-radius: 0;
  overflow: visible;
}

.dataTables_wrapper table.dataTable > thead > tr > th,
.dataTables_wrapper table.dataTable > thead > tr > td {
  padding-right: 34px;
  background: var(--cc-table-head);
  color: #536078;
}

.dataTables_wrapper table.dataTable thead th.sorting,
.dataTables_wrapper table.dataTable thead th.sorting_asc,
.dataTables_wrapper table.dataTable thead th.sorting_desc {
  cursor: pointer;
  transition: color 150ms ease, background-color 150ms ease;
}

.dataTables_wrapper table.dataTable thead th.sorting:hover,
.dataTables_wrapper table.dataTable thead th.sorting_asc,
.dataTables_wrapper table.dataTable thead th.sorting_desc {
  background: #edf2fc;
  color: var(--cc-table-primary-dark);
}

.dataTables_wrapper table.dataTable thead th.sorting::after,
.dataTables_wrapper table.dataTable thead th.sorting_asc::after,
.dataTables_wrapper table.dataTable thead th.sorting_desc::after {
  top: 50%;
  right: 13px;
  padding: 0;
  color: #9aa6ba;
  font-size: 12px;
  opacity: 1;
  transform: translateY(-50%);
}

.dataTables_wrapper table.dataTable thead th.sorting_asc::after,
.dataTables_wrapper table.dataTable thead th.sorting_desc::after {
  color: var(--cc-table-primary);
}

.dataTables_scroll {
  border-right: 1px solid var(--cc-table-line);
  border-left: 1px solid var(--cc-table-line);
  background: var(--cc-table-surface);
}

.dataTables_scrollHead {
  border-bottom: 0 !important;
  background: var(--cc-table-head);
}

.dataTables_scrollBody {
  border: 0 !important;
}

/* DataTables: paginazione */
.dataTables_wrapper .dataTables_paginate {
  padding-top: 0;
  text-align: right;
}

.dataTables_wrapper .pagination {
  display: inline-flex;
  align-items: center;
  margin: 0;
  gap: 5px;
}

.dataTables_wrapper .pagination > li {
  display: block;
}

.dataTables_wrapper .pagination > li > a,
.dataTables_wrapper .pagination > li > span {
  display: inline-flex;
  min-width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: #68758b;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  transition: background-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.dataTables_wrapper .pagination > li > a:hover,
.dataTables_wrapper .pagination > li > a:focus {
  border-color: #e0e6f0;
  background: var(--cc-table-primary-soft);
  color: var(--cc-table-primary);
  transform: translateY(-1px);
}

.dataTables_wrapper .pagination > .active > a,
.dataTables_wrapper .pagination > .active > span,
.dataTables_wrapper .pagination > .active > a:hover,
.dataTables_wrapper .pagination > .active > span:hover,
.dataTables_wrapper .pagination > .active > a:focus,
.dataTables_wrapper .pagination > .active > span:focus {
  border-color: var(--cc-table-primary) !important;
  background: var(--cc-table-primary) !important;
  color: #fff !important;
  box-shadow: 0 5px 12px rgba(70, 99, 169, 0.24);
}

.dataTables_wrapper .pagination > .disabled > a,
.dataTables_wrapper .pagination > .disabled > span,
.dataTables_wrapper .pagination > .disabled > a:hover,
.dataTables_wrapper .pagination > .disabled > span:hover {
  border-color: transparent;
  background: transparent;
  color: #c2c9d5;
  transform: none;
}

/* Stati e strumenti DataTables */
.dataTables_wrapper .dataTables_processing {
  top: 50%;
  left: 50%;
  width: auto;
  min-width: 160px;
  height: auto;
  margin: 0;
  padding: 14px 20px;
  border: 1px solid var(--cc-table-line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--cc-table-primary);
  font-weight: 700;
  box-shadow: 0 12px 32px rgba(42, 55, 92, 0.16);
  transform: translate(-50%, -50%);
}

.dataTables_wrapper .dataTables_empty {
  height: 110px;
  color: var(--cc-table-muted);
  font-weight: 600;
  text-align: center;
}

.dataTables_wrapper .dt-buttons {
  display: inline-flex;
  margin: 0 8px 8px 0;
  gap: 6px;
}

.dataTables_wrapper .dt-buttons .btn {
  border-radius: 9px;
  font-weight: 600;
}

table.dataTable.dtr-inline.collapsed > tbody > tr > td:first-child::before,
table.dataTable.dtr-inline.collapsed > tbody > tr > th:first-child::before {
  top: 50%;
  border: 0;
  border-radius: 7px;
  background: var(--cc-table-accent);
  box-shadow: 0 3px 8px rgba(35, 177, 149, 0.25);
  transform: translateY(-50%);
}

table.dataTable.dtr-inline.collapsed > tbody > tr.parent > td:first-child::before,
table.dataTable.dtr-inline.collapsed > tbody > tr.parent > th:first-child::before {
  background: var(--cc-table-primary);
}

table.dataTable > tbody > tr.child ul.dtr-details {
  width: 100%;
}

table.dataTable > tbody > tr.child span.dtr-title {
  min-width: 150px;
  color: #56637a;
  font-weight: 700;
}

/* Evita il doppio "contenitore card" quando DataTables nasce in table-responsive */
.table-responsive .dataTables_wrapper > .row:first-child {
  border-top: 0;
  border-right: 0;
  border-left: 0;
  border-radius: 0;
  box-shadow: none;
}

.table-responsive .dataTables_wrapper > .row:first-child + .row {
  border-right: 0;
  border-left: 0;
}

.table-responsive .dataTables_wrapper > .row:last-child {
  margin-bottom: 0;
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 0;
  box-shadow: none;
}

.table-responsive .dataTables_scroll {
  border-right: 0;
  border-left: 0;
}

/* Mobile */
@media (max-width: 767px) {
  .table-responsive {
    width: 100%;
    margin-bottom: 18px;
    border-radius: 13px;
  }

  table.table > thead > tr > th,
  table.table > thead > tr > td {
    padding: 12px;
  }

  table.table > tbody > tr > td,
  table.table > tbody > tr > th,
  table.table > tfoot > tr > td,
  table.table > tfoot > tr > th {
    padding: 11px 12px;
  }

  .dataTables_wrapper > .row:first-child,
  .dataTables_wrapper > .row:last-child {
    display: block;
    padding: 12px;
  }

  .dataTables_wrapper > .row:first-child > [class*="col-"],
  .dataTables_wrapper > .row:last-child > [class*="col-"] {
    width: 100%;
    float: none;
  }

  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    text-align: left;
  }

  .dataTables_wrapper .dataTables_filter {
    margin-top: 10px;
  }

  .dataTables_wrapper .dataTables_filter label,
  .dataTables_wrapper .dataTables_filter input {
    width: 100%;
  }

  .dataTables_wrapper .dataTables_filter input {
    margin: 6px 0 0;
  }

  .dataTables_wrapper .dataTables_info {
    margin-bottom: 12px;
  }

  .dataTables_wrapper .pagination {
    max-width: 100%;
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  table.table > tbody > tr > td,
  table.table > tbody > tr > th,
  table.table td .btn,
  .dataTables_wrapper input,
  .dataTables_wrapper .pagination > li > a {
    transition: none;
  }
}
