/* CALIGEST UI — surfaces, tableaux, volets et états.
   Les grilles, largeurs de colonnes et comportements restent dans leurs modules. */

@media screen {
  /* Une même profondeur pour les blocs de contenu. */
  .dash-card,
  .form-panel,
  .table-card,
  .dashboard-summary,
  .card {
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-lg);
    box-shadow: var(--ui-shadow-sm);
  }

  .card {
    --bs-card-border-color: var(--ui-border);
    --bs-card-border-radius: var(--ui-radius-lg);
    --bs-card-inner-border-radius: calc(var(--ui-radius-lg) - 1px);
    --bs-card-bg: var(--ui-surface);
    --bs-card-color: var(--ui-text);
    --bs-card-cap-bg: var(--ui-surface-soft);
    --bs-card-cap-color: var(--ui-text);
  }

  .card-header {
    padding: 14px 20px;
    border-color: var(--ui-border-soft);
    background: var(--ui-surface-soft);
    color: var(--ui-text);
    font-size: 14px;
    font-weight: 600;
  }

  .card-footer {
    padding: 12px 20px;
    border-color: var(--ui-border-soft);
    background: var(--ui-surface-soft);
    color: var(--ui-muted);
    font-size: 13px;
  }

  .dash-card--quick {
    background: var(--ui-surface);
    border-top-width: 1px;
  }

  .dash-card--alert {
    border-color: color-mix(in srgb, var(--cg-red-tx) 22%, var(--ui-surface));
  }

  .dashboard-summary__track {
    border-radius: var(--ui-radius-sm);
    background: var(--ui-border-soft);
  }

  .dashboard-summary__head span,
  .dashboard-current,
  .dashboard-planning__summary,
  .dash-stat__over,
  .dash-stat__label,
  .dash-list__label,
  .dash-note {
    color: var(--ui-text);
  }

  .dashboard-summary__scale,
  .dashboard-summary__legend,
  .dashboard-chart figcaption,
  .dashboard-ce__message,
  .dashboard-planning__note,
  .sheet-summary,
  .page-count {
    color: var(--ui-muted);
  }

  .dash-card__title {
    font-weight: 600;
    letter-spacing: .04em;
  }

  .dashboard-card__head .dash-card__title {
    font-size: 12px;
  }

  .dash-card__title--blue,
  .dash-card--quick .dash-card__title {
    color: var(--ui-text);
  }

  .dash-stat__ico,
  .dash-hello__ico,
  .page-head__ico {
    border-radius: var(--ui-radius);
  }

  .dash-stat__ico--blue,
  .dash-hello__ico,
  .page-head__ico {
    color: var(--ui-primary);
    background: var(--ui-primary-soft);
  }

  .dash-stat__ico--red {
    color: var(--cg-red-tx);
    background: color-mix(in srgb, var(--cg-red-bg) 60%, var(--ui-surface));
  }

  .dash-stat__ico--green {
    color: var(--cg-green-tx);
    background: color-mix(in srgb, var(--cg-green-bg) 60%, var(--ui-surface));
  }

  .dash-stat__ico--purple {
    color: var(--ui-primary);
    background: var(--ui-primary-soft);
  }

  .dash-card__foot {
    border-color: var(--ui-border-soft);
    background: var(--ui-surface-soft);
    color: var(--ui-primary);
    font-size: 13px;
    font-weight: 500;
    transition: background-color var(--ui-transition), color var(--ui-transition);
  }

  .dash-card__foot:hover {
    background: var(--ui-primary-soft);
    color: var(--ui-primary-hover);
  }

  .dash-card__foot:focus-visible,
  .dash-quick__item:focus-visible,
  .dashboard-workflow__list a:focus-visible {
    outline: 2px solid var(--ui-focus);
    outline-offset: -3px;
  }

  .dash-quick__item,
  .dashboard-workflow__list a {
    background: var(--ui-surface-soft);
    border-color: var(--ui-border-soft);
    border-radius: var(--ui-radius);
    color: var(--ui-text);
    font-size: 13px;
    font-weight: 500;
    transition: background-color var(--ui-transition), border-color var(--ui-transition);
  }

  .dash-quick__item > i:first-child {
    color: var(--ui-muted);
  }

  .dash-quick__go,
  .dashboard-workflow__list a span {
    color: var(--ui-muted);
  }

  .dash-quick__item:hover,
  .dashboard-workflow__list a:hover {
    background: var(--ui-primary-soft);
    border-color: var(--ui-border);
    color: var(--ui-primary);
  }

  /* Les rubriques de fiche ne sont pas des statuts : en-têtes communs neutres. */
  .form-panel .form-panel__head {
    padding: 14px 20px;
    border-radius: calc(var(--ui-radius-lg) - 1px) calc(var(--ui-radius-lg) - 1px) 0 0;
    border-color: var(--ui-border-soft);
    background: var(--ui-surface-soft);
    color: var(--ui-text);
    font-size: 14px;
    font-weight: 600;
  }

  .form-panel .form-panel__head > i {
    color: var(--ui-muted);
    font-size: 16px;
  }

  .form-panel > .table-responsive:last-child {
    border-radius: 0 0 calc(var(--ui-radius-lg) - 1px) calc(var(--ui-radius-lg) - 1px);
  }

  .dashboard-current {
    border-color: var(--ui-border-soft);
  }

  /* Même lecture des données dans les listes, historiques et panier. */
  .cg-table,
  .cart-table {
    --bs-table-color: var(--ui-text);
    --bs-table-border-color: var(--ui-border-soft);
    color: var(--ui-text);
  }

  .cg-table thead th,
  .cart-table thead th {
    position: relative;
    background: var(--ui-surface-soft);
    border-bottom: 1px solid var(--ui-border);
    color: var(--ui-text);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.4;
  }

  .cg-table tbody td,
  .cart-table td {
    color: var(--ui-text);
    border-bottom-color: var(--ui-border-soft);
    font-size: 13px;
  }

  .cg-table tbody tr:nth-child(even) td,
  .cart-table tbody tr:nth-child(even) td {
    background: var(--ui-surface-soft);
  }

  .cg-table tbody tr:hover td,
  .cart-table tbody tr:hover td {
    background: var(--ui-primary-soft);
  }

  .cg-table tbody tr.row-alert td,
  .cg-table tbody tr.row-alert:nth-child(even) td {
    background: var(--cg-row-alert);
  }

  .cg-table tbody tr.row-alert:hover td {
    background: color-mix(in srgb, var(--cg-red-bg) 55%, var(--ui-surface));
  }

  .cg-table tbody tr.is-selected td,
  .cart-table .cart-item.is-selected td {
    background: var(--ui-primary-soft);
  }

  .instruments-table > :not(caption) > * > * + *,
  .cart-table th + th,
  .cart-table td + td {
    border-left-color: var(--ui-border-soft);
  }

  /* La dernière colonne reste opaque pendant le défilement horizontal. */
  .instruments-table tbody td.col-actions {
    background: var(--ui-surface);
  }

  .instruments-table tbody tr:nth-child(even) td.col-actions,
  .instruments-table thead th.col-actions {
    background: var(--ui-surface-soft);
  }

  .instruments-table tbody tr:hover td.col-actions,
  .instruments-table tbody tr.is-selected td.col-actions {
    background: var(--ui-primary-soft);
  }

  .instruments-table tbody tr.row-alert td.col-actions {
    background: var(--cg-row-alert);
  }

  .instruments-table tbody tr.row-alert:hover td.col-actions {
    background: color-mix(in srgb, var(--cg-red-bg) 55%, var(--ui-surface));
  }

  .cg-table tbody tr.row-alert.is-selected td,
  .cg-table tbody tr.row-alert.is-selected:nth-child(even) td,
  .instruments-table tbody tr.row-alert.is-selected td.col-actions {
    background: var(--ui-primary-soft);
  }

  .instruments-table tbody tr.row-alert.is-selected td.col-actions {
    background: var(--ui-primary-soft);
  }

  .th-sub,
  .certificate-date,
  .no-cert,
  .cart-meta,
  .dashboard-certificates .certificate-name {
    color: var(--ui-muted);
  }

  .code,
  .user-cell__id,
  .dashboard-bars__value {
    color: var(--ui-text);
    font-weight: 600;
  }

  .instrument-link,
  .cart-certificate,
  .cert {
    color: var(--ui-primary);
  }

  .instrument-link:hover,
  .cart-certificate:hover,
  .cert:hover {
    color: var(--ui-primary-hover);
  }

  .badge-cg,
  .cart-size {
    border-radius: var(--ui-radius-sm);
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.3;
  }

  .table-foot {
    border-color: var(--ui-border-soft);
    background: var(--ui-surface);
  }

  .table-foot__info,
  .table-foot__perpage {
    color: var(--ui-muted);
    font-size: 12px;
  }

  .pg {
    min-width: var(--ui-control-sm);
    height: var(--ui-control-sm);
    border-radius: var(--ui-radius-sm);
    color: var(--ui-muted);
    font-size: 13px;
    font-weight: 500;
  }

  .pg:hover {
    background: var(--ui-surface-soft);
    color: var(--ui-text);
  }

  .pg.is-active {
    background: var(--ui-primary);
    color: var(--ui-surface);
  }

  .pg.is-active:hover {
    background: var(--ui-primary-hover);
  }

  .pg:focus-visible {
    outline: 2px solid var(--ui-focus);
    outline-offset: 2px;
  }

  .pg--dots:hover {
    background: transparent;
  }

  /* Volets de travail blancs, indépendants des deux navigations sombres. */
  .offcanvas:not(.app-nav):not(.app-sidebar) {
    --bs-offcanvas-bg: var(--ui-surface);
    --bs-offcanvas-color: var(--ui-text);
    --bs-offcanvas-border-color: var(--ui-border);
    background: var(--ui-surface);
    color: var(--ui-text);
    box-shadow: var(--ui-shadow-floating);
  }

  .offcanvas:not(.app-nav):not(.app-sidebar) .offcanvas-header {
    padding: 20px 24px;
    gap: 16px;
    border-bottom: 1px solid var(--ui-border-soft);
    background: var(--ui-surface);
  }

  .offcanvas:not(.app-nav):not(.app-sidebar) .offcanvas-title,
  .cart-heading h2 {
    color: var(--ui-text);
    font-size: 18px;
    font-weight: 600;
  }

  .offcanvas:not(.app-nav):not(.app-sidebar) .btn-close {
    box-sizing: border-box;
    flex: 0 0 var(--ui-control-sm);
    width: var(--ui-control-sm);
    height: var(--ui-control-sm);
    padding: 9px;
    margin: 0 0 0 auto;
    border-radius: var(--ui-radius);
    background-color: var(--ui-surface-soft);
    background-size: 11px;
    opacity: .65;
  }

  .offcanvas:not(.app-nav):not(.app-sidebar) .btn-close:hover {
    background-color: var(--ui-primary-soft);
    opacity: 1;
  }

  .cart-heading__icon {
    border-color: var(--ui-border-soft);
    border-radius: var(--ui-radius);
    background: var(--ui-primary-soft);
    color: var(--ui-primary);
    font-size: 20px;
  }

  .cart-size {
    border-color: var(--ui-border-soft);
    background: var(--ui-surface-soft);
    color: var(--ui-muted);
  }

  .cart-table-wrap {
    border-color: var(--ui-border);
    border-radius: var(--ui-radius);
  }

  .cart-footer {
    border-color: var(--ui-border-soft);
    background: var(--ui-surface-soft);
  }

  .cart-footer > span {
    color: var(--ui-muted);
    font-size: 12px;
  }

  /* États vides et pièces jointes. Les couleurs métier restent sémantiques. */
  .cg-table__empty td {
    background: var(--ui-surface) !important;
    color: var(--ui-muted);
    font-size: 13px;
    font-style: normal;
    line-height: 1.6;
  }

  .cart-blank > i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    border-radius: var(--ui-radius-xl);
    background: var(--ui-surface-soft);
    color: var(--ui-muted);
    font-size: 32px;
  }

  .cart-blank h3 {
    color: var(--ui-text);
    font-size: 18px;
    font-weight: 600;
  }

  .cart-blank p {
    color: var(--ui-muted);
    font-size: 13px;
    line-height: 1.6;
  }

  .sheet-attachment {
    border-color: var(--ui-border);
    border-radius: var(--ui-radius);
    background: var(--ui-surface);
  }

  .sheet-attachment__preview {
    border-radius: var(--ui-radius-sm);
    background: var(--ui-surface-soft);
    color: var(--ui-muted);
  }

  .sheet-attachment__name {
    color: var(--ui-primary);
    font-weight: 500;
  }

  .sheet-attachment__download,
  .sheet-attachments h3 span {
    color: var(--ui-muted);
  }

  .sheet-attachment__preview:focus-visible,
  .sheet-attachment__name:focus-visible,
  .sheet-attachment__download:focus-visible {
    outline: 2px solid var(--ui-focus);
    outline-offset: 2px;
  }

  .sheet-attachments h3 {
    color: var(--ui-text);
    font-size: 13px;
    font-weight: 600;
  }

  .active-filter {
    border-color: var(--ui-border);
    border-radius: var(--ui-radius-sm);
    background: var(--ui-primary-soft);
    color: var(--ui-primary);
  }

  .alert {
    border-radius: var(--ui-radius);
    font-size: 13px;
    line-height: 1.6;
  }

  .alert-info {
    border-color: color-mix(in srgb, var(--ui-primary) 20%, var(--ui-surface));
    background: var(--ui-primary-soft);
    color: var(--ui-primary);
  }

  .alert-warning {
    border-color: color-mix(in srgb, var(--cg-orange-tx) 22%, var(--ui-surface));
    background: color-mix(in srgb, var(--cg-orange-bg) 60%, var(--ui-surface));
    color: var(--cg-orange-tx);
  }

  .alert-danger {
    border-color: color-mix(in srgb, var(--cg-red-tx) 22%, var(--ui-surface));
    background: color-mix(in srgb, var(--cg-red-bg) 60%, var(--ui-surface));
    color: var(--cg-red-tx);
  }

  .alert-success {
    border-color: color-mix(in srgb, var(--cg-green-tx) 22%, var(--ui-surface));
    background: color-mix(in srgb, var(--cg-green-bg) 60%, var(--ui-surface));
    color: var(--cg-green-tx);
  }

  .app-notice {
    border-radius: var(--ui-radius);
    box-shadow: var(--ui-shadow-floating);
    font-size: 13px;
    line-height: 1.5;
  }

  /* Volet des familles : mêmes rayons et focus, sans déplacer ses axes. */
  .app-sidebar .side-all {
    border-color: color-mix(in srgb, var(--cg-side-text) 22%, transparent);
    border-radius: var(--ui-radius);
    background: color-mix(in srgb, var(--cg-side-text) 7%, transparent);
  }

  .app-sidebar .side-all:hover,
  .app-sidebar .side-all.is-active {
    border-color: color-mix(in srgb, var(--cg-side-text) 35%, transparent);
    background: color-mix(in srgb, var(--cg-side-text) 13%, transparent);
  }

  .app-sidebar .side-filter {
    border-color: color-mix(in srgb, var(--cg-side-text) 22%, transparent);
    border-radius: var(--ui-radius);
    background: var(--cg-side-bg-2);
  }

  .app-sidebar .side-filter:focus-within {
    border-color: var(--ui-focus);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--ui-focus) 28%, transparent);
  }

  .app-sidebar .side-seg {
    border-radius: var(--ui-radius);
    background: var(--cg-side-bg-2);
  }

  .app-sidebar .side-seg__btn,
  .app-sidebar .side-seg__badge,
  .app-sidebar .side-cross,
  .app-sidebar .side-clear__btn,
  .app-sidebar .side-resources a,
  .app-sidebar .side-resources button {
    border-radius: var(--ui-radius-sm);
  }

  .app-sidebar .side-seg__btn {
    font-size: 13px;
  }

  .app-sidebar .side-seg__btn.is-active {
    background: var(--ui-surface);
    color: var(--cg-side-bg);
    box-shadow: var(--ui-shadow-sm);
  }

  .app-sidebar .side-seg__btn.is-active .side-seg__badge {
    background: var(--ui-primary-soft);
    color: var(--ui-primary);
  }

  .app-sidebar .side-row {
    border-radius: var(--ui-radius-sm);
    border-bottom-color: color-mix(in srgb, var(--cg-side-text) 8%, transparent);
    transition: background-color var(--ui-transition);
  }

  .app-sidebar .side-row:hover,
  .app-sidebar .side-row--group.is-open {
    background: color-mix(in srgb, var(--cg-side-text) 9%, transparent);
  }

  .app-sidebar .side-row.is-active {
    border-left-color: var(--ui-focus);
    background: var(--cg-side-active);
    box-shadow: none;
  }

  .app-sidebar .side-all:focus-visible,
  .app-sidebar .side-seg__btn:focus-visible,
  .app-sidebar .side-row:focus-visible,
  .app-sidebar .side-row__chev:focus-visible,
  .app-sidebar .side-listhead__toggle:focus-visible,
  .app-sidebar .side-cross:focus-visible,
  .app-sidebar .side-clear__btn:focus-visible,
  .app-sidebar .side-resources a:focus-visible,
  .app-sidebar .side-resources button:focus-visible {
    outline: 2px solid var(--ui-focus);
    outline-offset: -2px;
    box-shadow: none;
  }

  .app-sidebar .side-listhead__label {
    font-family: var(--cg-font);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .08em;
  }

  .app-sidebar .side-all__count,
  .app-sidebar .side-row__count {
    font-family: var(--cg-font);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0;
  }

  .app-sidebar .side-empty {
    color: var(--cg-side-muted);
    font-size: 13px;
    line-height: 1.6;
  }

  @media (max-width: 767.98px) {
    .offcanvas:not(.app-nav):not(.app-sidebar) .offcanvas-header {
      padding: 16px;
    }

    .cart-heading h2 {
      flex-wrap: wrap;
      gap: 6px;
      font-size: 16px;
      line-height: 1.35;
    }

    .cart-heading__icon {
      width: 36px;
      height: 36px;
      font-size: 18px;
    }

    .cart-footer {
      padding: 16px;
    }

    .cart-table .cart-item > td + td {
      border-left-color: var(--ui-border-soft);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .dash-card__foot,
    .dash-quick__item,
    .dashboard-workflow__list a,
    .app-sidebar .side-row {
      transition: none;
    }
  }
}

/* Lecture des tableaux : règles horizontales seules, plus d'air, chiffres alignés,
   commandes d'en-tête discrètes au repos et nettes au survol ou au clavier. */
@media screen {
  .cg-table tbody td,
  .cart-table td { padding: 10px 10px; line-height: 1.4; font-variant-numeric: tabular-nums; }
  .cg-table thead th,
  .cart-table thead th,
  .instruments-table .cg-table__head th,
  .users-table .cg-table__head th { padding: 11px 10px; }
  .instruments-table > :not(caption) > * > * + *,
  .cart-table th + th,
  .cart-table td + td,
  .cart-table .cart-item > td + td { border-left-color: transparent; }
  .instruments-table .col-actions { box-shadow: -1px 0 0 var(--ui-border), -8px 0 12px #17233b0a; }
  .th-filter, .th-sort, .column-search, .certificate-sort, .table-help { opacity: .55; transition: opacity var(--ui-transition), color var(--ui-transition), background-color var(--ui-transition); }
  th:hover :is(.th-filter, .th-sort, .column-search, .certificate-sort, .table-help),
  th:focus-within :is(.th-filter, .th-sort, .column-search, .certificate-sort, .table-help),
  .column-search.is-filtered,
  th[aria-sort] .th-sort { opacity: 1; }
  .no-cert, .cg-table__empty td { color: var(--ui-muted); }
}
@media screen {
  /* Les colonnes compactes à liste déroulante gardent leur libellé entier avec le nouveau rythme. */
  .users-table tbody td, .users-table .cg-table__head th { padding-inline: 8px; }
  .uc-type, .uc-rec, .uc-acc, .uc-day { width: auto; min-width: 150px; }
  .uc-day { min-width: 120px; }
  .uc-ses { width: auto; min-width: 176px; }
}

/* Filtre de colonne : surcouche flottante ancrée sur la loupe de l’en-tête, dans l’esprit du menu contextuel.
   L’en-tête du tableau garde sa hauteur ; la loupe colorée et la pastille signalent un filtre actif. */
.instruments-table .column-filter {
  position: fixed; z-index: 1020;
  display: flex; flex-direction: column; gap: 8px;
  width: 260px; min-width: 0; max-width: calc(100vw - 24px); margin: 0; padding: 10px;
  border: 1px solid var(--ui-border); border-radius: var(--ui-radius-lg);
  background: var(--ui-surface); box-shadow: var(--ui-shadow-floating);
  color: var(--ui-text); font-weight: 500; text-align: left; white-space: normal; cursor: default;
  animation: cg-filter-in .12s ease-out;
}
.instruments-table .column-filter[hidden] { display: none; }
.column-filter__title { margin: 0 0 2px; color: var(--ui-muted); font-size: 12px; font-weight: 600; letter-spacing: .05em; line-height: 1.3; text-transform: uppercase; }
.column-filter .column-filter-input { width: 100%; }
.column-filter__clear {
  display: inline-flex; align-items: center; align-self: flex-start; gap: 6px;
  padding: 4px 6px; margin: 2px 0 0 -6px; border: 0; border-radius: var(--ui-radius-sm);
  background: transparent; color: var(--ui-primary); font-size: 13px; font-weight: 600;
}
.column-filter__clear[hidden] { display: none; }
.column-filter__clear i { font-size: 11px; }
.column-filter__clear:hover { background: var(--ui-primary-soft); }
.column-filter__clear:focus-visible { outline: 2px solid var(--ui-focus); outline-offset: 2px; }
.column-search { position: relative; border-radius: var(--ui-radius-sm); }
.column-search.is-filtered,
.column-search[aria-expanded="true"] { color: var(--ui-primary); background: color-mix(in srgb, var(--ui-primary) 16%, transparent); opacity: 1; }
.column-search.is-filtered:hover { color: var(--ui-primary-hover); }
.column-search__count {
  position: absolute; top: -6px; right: -7px;
  min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px;
  background: var(--ui-primary); color: #fff; box-shadow: 0 0 0 2px var(--ui-surface);
  font-size: 10px; font-weight: 700; line-height: 15px; text-align: center;
}
.column-search__count[hidden] { display: none; }
@keyframes cg-filter-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .instruments-table .column-filter { animation: none; } }
