/* ============================================================
   HARD DECO — Lot 9A-1 : fondations du design system
   Couche de compatibilite chargee apres les styles historiques.
   ============================================================ */

:root {
  color-scheme: light;

  /* Couleurs semantiques : les composants ne dependent plus d'une
     nuance brute et restent compatibles avec l'accent personnalisable. */
  --hd-color-canvas: var(--bg);
  --hd-color-surface: var(--panel);
  --hd-color-surface-subtle: var(--hover);
  --hd-color-text: var(--text);
  --hd-color-text-muted: var(--muted);
  --hd-color-border: var(--border);
  --hd-color-primary: var(--accent);
  --hd-color-primary-hover: color-mix(in srgb, var(--accent) 88%, #000000);
  --hd-color-on-primary: #ffffff;
  --hd-color-success: #14805f;
  --hd-color-warning: #a15c00;
  --hd-color-danger: #c93632;
  --hd-color-info: #2563eb;
  --hd-color-focus: color-mix(in srgb, var(--accent) 82%, #ffffff);

  --hd-surface-success: color-mix(in srgb, var(--panel) 88%, var(--hd-color-success));
  --hd-surface-warning: color-mix(in srgb, var(--panel) 86%, #f59e0b);
  --hd-surface-danger: color-mix(in srgb, var(--panel) 88%, var(--hd-color-danger));
  --hd-surface-info: color-mix(in srgb, var(--panel) 88%, var(--hd-color-info));

  /* Echelle commune de mise en page. */
  --hd-space-1: 4px;
  --hd-space-2: 8px;
  --hd-space-3: 12px;
  --hd-space-4: 16px;
  --hd-space-5: 20px;
  --hd-space-6: 24px;
  --hd-space-8: 32px;
  --hd-space-10: 40px;

  --hd-radius-sm: 6px;
  --hd-radius-md: 8px;
  --hd-radius-lg: var(--radius, 12px);
  --hd-radius-xl: 16px;
  --hd-radius-pill: 999px;

  --hd-shadow-sm: var(--shadow-soft, 0 1px 4px rgba(16, 24, 40, .06));
  --hd-shadow-md: 0 8px 24px rgba(16, 24, 40, .10);
  --hd-shadow-lg: var(--shadow-pop, 0 12px 28px rgba(16, 24, 40, .10));

  --hd-control-height-sm: 32px;
  --hd-control-height-md: 38px;
  --hd-control-height-lg: 44px;
  --hd-focus-ring: 0 0 0 3px color-mix(in srgb, var(--hd-color-focus) 34%, transparent);
  --hd-transition-fast: 140ms ease;
}

:root.dark {
  color-scheme: dark;
  --hd-color-primary-hover: color-mix(in srgb, var(--accent) 84%, #ffffff);
  --hd-color-success: #4fd1a5;
  --hd-color-warning: #f5b94c;
  --hd-color-danger: #ff8580;
  --hd-color-info: #76a6ff;
  --hd-color-focus: color-mix(in srgb, var(--accent) 70%, #ffffff);
  --hd-shadow-md: 0 10px 28px rgba(0, 0, 0, .32);
}

/* Utilitaires opt-in pour les nouveaux composants 9A+. */
.hd-surface {
  color: var(--hd-color-text);
  background: var(--hd-color-surface);
  border: 1px solid var(--hd-color-border);
  border-radius: var(--hd-radius-lg);
  box-shadow: var(--hd-shadow-sm);
}

.hd-stack { display: flex; flex-direction: column; gap: var(--hd-space-4); }
.hd-cluster { display: flex; align-items: center; flex-wrap: wrap; gap: var(--hd-space-2); }

/* Un focus clavier unique, visible et non intrusif au clic souris. */
:where(
  button,
  a[href],
  input,
  select,
  textarea,
  summary,
  [role="button"],
  [role="tab"],
  [tabindex]:not([tabindex="-1"])
):focus-visible {
  outline: 2px solid var(--hd-color-focus);
  outline-offset: 2px;
  box-shadow: var(--hd-focus-ring);
}

/* Boutons historiques : meme geometrie et memes etats, sans imposer
   de migration immediate a tous les modules. */
.btn,
.btn-primary,
.btn-accent,
.btn-secondary,
.btn-warning,
.btn-danger,
.btn-success,
.btn-ghost,
.btn-outline,
.btn-confirm,
.btn-cancel {
  min-height: var(--hd-control-height-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--hd-space-2);
  padding: 9px var(--hd-space-4);
  border: 1px solid transparent;
  border-radius: var(--hd-radius-sm);
  font: inherit;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition:
    color var(--hd-transition-fast),
    background-color var(--hd-transition-fast),
    border-color var(--hd-transition-fast),
    box-shadow var(--hd-transition-fast),
    transform var(--hd-transition-fast);
}

.btn,
.btn-primary,
.btn-accent,
.btn-confirm {
  color: var(--hd-color-on-primary);
  background: var(--hd-color-primary);
  border-color: var(--hd-color-primary);
}

.btn:hover,
.btn-primary:hover,
.btn-accent:hover,
.btn-confirm:hover {
  color: var(--hd-color-on-primary);
  background: var(--hd-color-primary-hover);
  border-color: var(--hd-color-primary-hover);
  filter: none;
}

.btn-secondary,
.btn-ghost,
.btn-outline,
.btn-cancel {
  color: var(--hd-color-text);
  background: var(--hd-color-surface);
  border-color: var(--hd-color-border) !important;
}

.btn-secondary:hover,
.btn-secondary.active,
.btn-ghost:hover,
.btn-outline:hover,
.btn-cancel:hover {
  color: var(--hd-color-primary);
  background: var(--hd-color-surface-subtle);
  border-color: var(--hd-color-primary) !important;
}

.btn-warning,
.btn-danger {
  color: var(--hd-color-danger);
  background: var(--hd-surface-danger);
  border-color: color-mix(in srgb, var(--hd-color-danger) 54%, transparent) !important;
}

.btn-warning:hover,
.btn-danger:hover {
  color: var(--hd-color-on-primary);
  background: var(--hd-color-danger);
  border-color: var(--hd-color-danger) !important;
}

.btn-success {
  color: var(--hd-color-on-primary);
  background: var(--hd-color-success);
  border-color: var(--hd-color-success);
}

.btn:active,
.btn-primary:active,
.btn-accent:active,
.btn-secondary:active,
.btn-warning:active,
.btn-danger:active,
.btn-success:active,
.btn-ghost:active,
.btn-outline:active,
.btn-confirm:active,
.btn-cancel:active {
  transform: translateY(1px);
}

.btn-sm,
.btn-small,
.btn-mini {
  min-height: var(--hd-control-height-sm);
  padding: 6px var(--hd-space-3);
}

.btn-icon,
.iconbtn,
.task-icon-button {
  min-width: var(--hd-control-height-md);
  min-height: var(--hd-control-height-md);
  display: inline-grid;
  place-items: center;
  border-radius: var(--hd-radius-md);
}

:where(
  .btn,
  .btn-primary,
  .btn-accent,
  .btn-secondary,
  .btn-warning,
  .btn-danger,
  .btn-success,
  .btn-ghost,
  .btn-outline,
  .btn-confirm,
  .btn-cancel,
  .btn-icon,
  .iconbtn,
  .task-icon-button
):where(:disabled, [disabled], [aria-disabled="true"]) {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none;
  transform: none;
}

:where(
  .btn,
  .btn-primary,
  .btn-accent,
  .btn-secondary,
  .btn-warning,
  .btn-danger,
  .btn-success
)[aria-busy="true"] {
  cursor: progress;
}

@media (forced-colors: active) {
  :where(button, a[href], input, select, textarea, [role="button"], [role="tab"]):focus-visible {
    outline-color: Highlight;
  }
}

/* ============================================================
   Lot 9A-2 : formulaires, validations et messages
   ============================================================ */

:root {
  --hd-control-padding-x: 12px;
  --hd-control-padding-y: 9px;
  --hd-control-placeholder: color-mix(in srgb, var(--hd-color-text-muted) 78%, transparent);
  --hd-control-disabled: color-mix(in srgb, var(--hd-color-surface) 80%, var(--hd-color-border));
}

:where(
  input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]),
  select,
  textarea
) {
  min-height: var(--hd-control-height-md);
  border: 1px solid var(--hd-color-border);
  border-radius: var(--hd-radius-md);
  background: var(--hd-color-surface);
  color: var(--hd-color-text);
  font: inherit;
}

:is(.field, .task-field, .champ-flex, .params-form .field, .connexion-form, .hd-field) :is(
  input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]),
  select,
  textarea
) {
  width: 100%;
  min-height: var(--hd-control-height-md);
  padding: var(--hd-control-padding-y) var(--hd-control-padding-x);
  border: 1px solid var(--hd-color-border);
  border-radius: var(--hd-radius-md);
  background: var(--hd-color-surface);
  color: var(--hd-color-text);
  line-height: 1.35;
  transition:
    color var(--hd-transition-fast),
    background-color var(--hd-transition-fast),
    border-color var(--hd-transition-fast),
    box-shadow var(--hd-transition-fast);
}

:is(.field, .task-field, .champ-flex, .params-form .field, .connexion-form, .hd-field) textarea {
  min-height: 88px;
  resize: vertical;
}

:where(input, textarea)::placeholder {
  color: var(--hd-control-placeholder);
  opacity: 1;
}

.field > :is(label, .lbl),
.task-field > span,
.champ-flex > label,
.hd-field > :is(label, .hd-label) {
  color: var(--hd-color-text-muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
}

:is(.field, .task-field, .champ-flex, .params-form .field, .connexion-form, .hd-field) :is(
  input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]),
  select,
  textarea
):hover:not(:disabled):not([readonly]):not([aria-invalid="true"]) {
  border-color: color-mix(in srgb, var(--hd-color-primary) 34%, var(--hd-color-border));
}

:is(.field, .task-field, .champ-flex, .params-form .field, .connexion-form, .hd-field) :is(
  input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]),
  select,
  textarea
):focus {
  outline: none;
  border-color: var(--hd-color-primary);
  background: var(--hd-color-surface);
  box-shadow: var(--hd-focus-ring);
}

:where(input, select, textarea):disabled {
  color: var(--hd-color-text-muted);
  background: var(--hd-control-disabled);
  cursor: not-allowed;
  opacity: .75;
}

:where(input, textarea)[readonly] {
  color: var(--hd-color-text-muted);
  background: var(--hd-color-surface-subtle);
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"],
input.is-invalid,
select.is-invalid,
textarea.is-invalid,
input.error,
select.error,
textarea.error {
  border-color: var(--hd-color-danger) !important;
  background: var(--hd-surface-danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hd-color-danger) 16%, transparent) !important;
}

input[aria-invalid="true"]:focus,
select[aria-invalid="true"]:focus,
textarea[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hd-color-danger) 28%, transparent) !important;
}

input.is-valid,
select.is-valid,
textarea.is-valid {
  border-color: var(--hd-color-success) !important;
  background: var(--hd-surface-success);
}

.field:has(> [aria-invalid="true"]) > :is(label, .lbl),
.task-field:has(> [aria-invalid="true"]) > span,
.hd-field:has(> [aria-invalid="true"]) > :is(label, .hd-label) {
  color: var(--hd-color-danger);
}

.hd-required,
.field .req {
  color: var(--hd-color-danger);
  font-weight: 700;
}

.hd-field-message,
.hd-help {
  display: flex;
  align-items: flex-start;
  gap: var(--hd-space-1);
  margin: 2px 0 0;
  font-size: 12px;
  line-height: 1.4;
}

.hd-help,
.hd-field-message--info { color: var(--hd-color-text-muted); }
.hd-field-message--error { color: var(--hd-color-danger); }
.hd-field-message--success { color: var(--hd-color-success); }
.hd-field-message--warning { color: var(--hd-color-warning); }

.hd-form-summary,
.message-erreur:not(:empty) {
  padding: var(--hd-space-3);
  border: 1px solid color-mix(in srgb, var(--hd-color-danger) 42%, transparent);
  border-radius: var(--hd-radius-md);
  background: var(--hd-surface-danger);
  color: var(--hd-color-danger);
  font-size: 13px;
  line-height: 1.45;
}

/* Notifications globales : meme vocabulaire semantique que les formulaires. */
#toaster {
  display: flex;
  width: min(390px, calc(100vw - 32px));
  flex-direction: column;
  gap: var(--hd-space-2);
}

.toast {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--hd-space-2);
  min-height: var(--hd-control-height-lg);
  padding: var(--hd-space-3) var(--hd-space-4);
  border: 1px solid transparent;
  border-radius: var(--hd-radius-lg);
  color: #ffffff;
  box-shadow: var(--hd-shadow-md);
}

.toast span { margin: 0; color: inherit; line-height: 1.4; }
.toast .icon-inline { transform: none; color: inherit; }
.toast.success { background: var(--hd-color-success); }
.toast.error { background: var(--hd-color-danger); }
.toast.warning { background: var(--hd-color-warning); }
.toast.info,
.toast.loading { background: var(--hd-color-info); }

@media (max-width: 600px) {
  #toaster {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}

/* ============================================================
   Lot 9B-3 : contrastes, zoom et retours accessibles
   ============================================================ */

:root {
  --hd-color-primary-readable: var(--hd-color-primary);
  --hd-color-on-success: #ffffff;
  --hd-color-on-warning: #ffffff;
  --hd-color-on-danger: #ffffff;
  --hd-color-on-info: #ffffff;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

:root.dark {
  --hd-color-on-success: #000000;
  --hd-color-on-warning: #000000;
  --hd-color-on-danger: #000000;
  --hd-color-on-info: #000000;
}

.hd-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

:where(.btn, .btn-primary, .btn-accent, .btn-confirm) {
  color: var(--hd-color-on-primary);
}

:where(.btn-secondary, .btn-ghost, .btn-outline, .btn-cancel):is(:hover, .active) {
  color: var(--hd-color-primary-readable);
}

:is(.tabs, .devis-tabs, .factures-tabs, .tabs-group) .tab:is(.active, [aria-selected="true"]) {
  color: var(--hd-color-primary-readable);
}

.btn-success,
.toast.success { color: var(--hd-color-on-success); }

:is(.btn-warning, .btn-danger):hover,
.toast.error { color: var(--hd-color-on-danger); }

.toast.warning { color: var(--hd-color-on-warning); }
.toast.info,
.toast.loading { color: var(--hd-color-on-info); }

[data-hd-feedback-ready] {
  overflow-wrap: anywhere;
}

[aria-busy="true"] {
  cursor: progress;
}

#main-content,
.main,
.modal,
.modal-body,
.app-dialog,
.dialog-body {
  min-width: 0;
}

:is(.modal-body, .dialog-body, .card, .panel, .pop) :is(p, li, dd, dt, label, a, button) {
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  :is(.modal, .modal.medium, .modal.large, .modal.xlarge, .app-dialog, .pop) {
    max-width: calc(100vw - (2 * var(--hd-mobile-gutter))) !important;
  }

  :is(.modal-header, .modal-actions, .dialog-header, .dialog-footer, .page-header, .card-header) {
    min-width: 0;
    flex-wrap: wrap;
  }

  :is(.truncate, .ellipsis, [data-hd-truncate]) {
    max-width: 100%;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  [data-hd-status] {
    height: auto;
    white-space: normal;
    text-align: center;
  }

  #toaster {
    max-width: calc(100vw - (2 * var(--hd-mobile-gutter)));
  }
}

@media (max-width: 600px) {
  .modal,
  .modal.medium,
  .modal.large,
  .modal.xlarge {
    max-height: 100dvh;
    overflow: hidden;
  }

  :is(.modal-body, .dialog-body) {
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

@media (prefers-contrast: more) {
  :root {
    --hd-color-border: currentColor;
    --hd-focus-ring: 0 0 0 4px color-mix(in srgb, var(--hd-color-focus) 55%, transparent);
  }

  :where(button, a[href], input, select, textarea, [role="button"], [role="tab"]):focus-visible {
    outline-width: 3px;
  }

  :where(input, select, textarea, button, .btn, [data-hd-status]) {
    border-width: 2px;
  }
}

@media (forced-colors: active) {
  :where(.btn, .toast, [data-hd-status], input, select, textarea, .modal, .app-dialog) {
    forced-color-adjust: auto;
    border-color: currentColor !important;
  }

  :where(.btn, .toast, [data-hd-status]) {
    color: ButtonText !important;
    background: ButtonFace !important;
  }

  :where(svg, .icon-inline) {
    color: currentColor;
  }

  svg { stroke: currentColor; }
}

/* ============================================================
   Lot 9B-2 : formulaires mobiles, tableaux adaptatifs et clavier
   ============================================================ */

[data-hd-mobile-form] :is(input, select, textarea) {
  max-width: 100%;
  scroll-margin-block: 96px;
}

[data-hd-mobile-form] :is(
  .form-grid,
  .form-row,
  .fields-grid,
  .grid-form,
  .row-form,
  .task-grid,
  .params-grid,
  .devis-grid,
  .facture-grid
) > * {
  min-width: 0;
}

[data-hd-form-invalid] :is(input, select, textarea):invalid {
  border-color: var(--hd-color-danger);
}

.hd-table-scroll,
:is(.table-wrapper, .table-responsive)[data-hd-table-region="9B-2"] {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-inline: contain;
  border-radius: var(--hd-radius-lg);
  scrollbar-color: color-mix(in srgb, var(--hd-color-primary) 45%, transparent) transparent;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.hd-table-scroll:focus-visible,
:is(.table-wrapper, .table-responsive)[data-hd-table-region="9B-2"]:focus-visible {
  outline: 2px solid var(--hd-color-focus);
  outline-offset: 2px;
  box-shadow: var(--hd-focus-ring);
}

[data-hd-table-mode="scroll"] > table {
  width: max(100%, max-content);
}

@media (max-width: 680px) {
  [data-hd-mobile-form] :is(
    .form-grid,
    .form-row,
    .fields-grid,
    .grid-form,
    .row-form,
    .task-grid,
    .params-grid,
    .devis-grid,
    .facture-grid
  ) {
    grid-template-columns: minmax(0, 1fr) !important;
    flex-direction: column;
    align-items: stretch;
    gap: var(--hd-space-3);
  }

  [data-hd-mobile-form] :is(.field, .task-field, .champ-flex, .form-group, .hd-field) {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  [data-hd-mobile-form] label:has(> :is(input[type="checkbox"], input[type="radio"])) {
    min-height: var(--hd-touch-target);
    display: flex;
    align-items: center;
    gap: var(--hd-space-2);
    padding-block: 6px;
  }

  [data-hd-mobile-form] :is(.form-actions, .actions-form, .button-row, .btn-row) {
    display: flex;
    flex-wrap: wrap;
    gap: var(--hd-space-2);
  }

  [data-hd-mobile-form] :is(.form-actions, .actions-form, .button-row, .btn-row) > :is(button, .btn) {
    flex: 1 1 150px;
  }

  [data-hd-table-mode="stack"] {
    overflow: visible;
  }

  [data-hd-table-mode="stack"] > table,
  table[data-hd-mobile-mode="stack"] {
    display: block;
    width: 100%;
    min-width: 0;
  }

  table[data-hd-mobile-mode="stack"] thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  table[data-hd-mobile-mode="stack"] tbody,
  table[data-hd-mobile-mode="stack"] tr,
  table[data-hd-mobile-mode="stack"] :is(td, th) {
    display: block;
    width: 100%;
  }

  table[data-hd-mobile-mode="stack"] tbody {
    display: grid;
    gap: var(--hd-space-3);
  }

  table[data-hd-mobile-mode="stack"] tbody tr {
    overflow: hidden;
    border: 1px solid var(--hd-color-border);
    border-radius: var(--hd-radius-lg);
    background: var(--hd-color-surface);
    box-shadow: var(--hd-shadow-sm);
  }

  table[data-hd-mobile-mode="stack"] tbody :is(td, th) {
    min-height: var(--hd-touch-target);
    display: grid;
    grid-template-columns: minmax(96px, 38%) minmax(0, 1fr);
    align-items: center;
    gap: var(--hd-space-3);
    padding: 10px 12px;
    border: 0;
    border-bottom: 1px solid var(--hd-color-border);
    overflow-wrap: anywhere;
    text-align: left;
  }

  table[data-hd-mobile-mode="stack"] tbody :is(td, th):last-child { border-bottom: 0; }

  table[data-hd-mobile-mode="stack"] tbody :is(td, th)::before {
    content: attr(data-hd-label);
    color: var(--hd-color-text-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .025em;
    line-height: 1.3;
    text-transform: uppercase;
  }

  [data-hd-table-mode="scroll"] > table {
    min-width: max(680px, 100%);
  }
}

@media (max-width: 480px) {
  [data-hd-mobile-form] :is(.form-actions, .actions-form, .button-row, .btn-row) > :is(button, .btn),
  .modal-actions > :is(button, .btn),
  .dialog-footer > :is(button, .btn) {
    flex: 1 1 100%;
    width: 100%;
  }

  .modal-actions,
  .dialog-footer {
    position: sticky;
    z-index: 2;
    bottom: 0;
  }
}

/* ============================================================
   Lot 9A-3 : modales, onglets, tableaux et statuts
   ============================================================ */

:root {
  --hd-modal-backdrop: rgba(15, 23, 42, .48);
  --hd-modal-header: color-mix(in srgb, var(--hd-color-surface) 91%, var(--hd-color-primary));
  --hd-table-header: color-mix(in srgb, var(--hd-color-surface) 78%, var(--hd-color-surface-subtle));
  --hd-table-row-hover: color-mix(in srgb, var(--hd-color-surface) 92%, var(--hd-color-primary));
  --hd-status-neutral: color-mix(in srgb, var(--hd-color-surface) 82%, #64748b);
}

:root.dark {
  --hd-modal-backdrop: rgba(2, 6, 23, .68);
  --hd-modal-header: color-mix(in srgb, var(--hd-color-surface) 88%, var(--hd-color-primary));
  --hd-table-header: color-mix(in srgb, var(--hd-color-surface) 84%, #64748b);
  --hd-table-row-hover: color-mix(in srgb, var(--hd-color-surface) 88%, var(--hd-color-primary));
}

/* Modales principales et confirmations : meme profondeur et meme contour. */
.modal-backdrop,
.app-dialog-overlay {
  background: var(--hd-modal-backdrop);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal,
.app-dialog {
  border: 1px solid var(--hd-color-border);
  border-radius: var(--hd-radius-xl);
  background: var(--hd-color-surface);
  color: var(--hd-color-text);
  box-shadow: var(--hd-shadow-lg);
}

.modal-header,
.dialog-header {
  min-height: 52px;
  border-bottom: 1px solid var(--hd-color-border);
  background: var(--hd-modal-header);
}

.modal-header h3,
.dialog-header h3 {
  color: var(--hd-color-text);
  font-weight: 650;
  line-height: 1.25;
}

.modal-body,
.dialog-body { color: var(--hd-color-text); }

.modal-actions,
.dialog-footer {
  border-top: 1px solid var(--hd-color-border);
  background: var(--hd-color-surface);
}

.app-dialog { padding: 0; overflow: hidden; }
.dialog-header { display: flex; align-items: center; padding: var(--hd-space-4) var(--hd-space-5); }
.dialog-body { margin: 0; padding: var(--hd-space-5); line-height: 1.5; }
.dialog-footer { padding: var(--hd-space-3) var(--hd-space-5); }

/* Onglets de navigation et filtres : une geometrie unique, sans toucher
   aux boutons d'action presents dans certaines barres mixtes. */
:is(.tabs, .devis-tabs, .factures-tabs, .tabs-group) {
  scrollbar-color: color-mix(in srgb, var(--hd-color-primary) 45%, transparent) transparent;
  scrollbar-width: thin;
}

:is(.tabs, .devis-tabs, .factures-tabs, .tabs-group) .tab {
  min-height: var(--hd-control-height-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--hd-space-2);
  padding: 8px 12px;
  border: 0;
  border-bottom: 2px solid transparent !important;
  border-radius: var(--hd-radius-md) var(--hd-radius-md) 0 0;
  background: transparent;
  color: var(--hd-color-text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  transition:
    color var(--hd-transition-fast),
    background-color var(--hd-transition-fast),
    border-color var(--hd-transition-fast);
}

:is(.tabs, .devis-tabs, .factures-tabs, .tabs-group) .tab:hover {
  border-bottom-color: color-mix(in srgb, var(--hd-color-primary) 28%, transparent) !important;
  background: var(--hd-color-surface-subtle);
  color: var(--hd-color-text);
  transform: none;
}

:is(.tabs, .devis-tabs, .factures-tabs, .tabs-group) .tab:is(.active, [aria-selected="true"]) {
  border-bottom-color: var(--hd-color-primary) !important;
  background: var(--hd-surface-info);
  color: var(--hd-color-primary);
}

.tabs.tabToolbar .tab[data-act],
.tabs.tabToolbar .tab-accent {
  border: 1px solid var(--hd-color-primary) !important;
  border-radius: var(--hd-radius-md);
}

.tabs.tabToolbar .tab-accent {
  background: var(--hd-color-primary);
  color: var(--hd-color-on-primary);
}

.tab-panel[role="tabpanel"]:focus-visible { outline-offset: 4px; }

/* Tableaux de donnees : hierarchie et survol communs. Les largeurs et
   dispositions mobiles specialisees restent gerees par chaque module. */
:is(.table, .recap-table, .charges-table, .factu-table, .table-prestas, table.lines) {
  width: 100%;
  color: var(--hd-color-text);
  border-color: var(--hd-color-border);
}

:is(.table, .recap-table, .charges-table, .factu-table, .table-prestas, table.lines) thead th {
  background: var(--hd-table-header);
  color: var(--hd-color-text-muted);
  border-color: var(--hd-color-border);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .035em;
  line-height: 1.3;
  text-transform: uppercase;
}

:is(.table, .recap-table, .charges-table, .factu-table, .table-prestas, table.lines) :is(td, th) {
  border-color: var(--hd-color-border);
}

:is(.table, .recap-table, .charges-table, .factu-table, .table-prestas, table.lines) tbody tr:hover > td {
  background: var(--hd-table-row-hover);
}

:is(.table-wrapper, .table-responsive)[data-hd-table-region] {
  border-radius: var(--hd-radius-lg);
  scrollbar-color: color-mix(in srgb, var(--hd-color-primary) 45%, transparent) transparent;
  scrollbar-width: thin;
}

:is(.table-wrapper, .table-responsive)[data-hd-table-region]:focus-visible {
  outline: 2px solid var(--hd-color-focus);
  outline-offset: 2px;
  box-shadow: var(--hd-focus-ring);
}

/* Pastilles semantiques : la couleur complete toujours le libelle texte. */
[data-hd-status] {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: max-content;
  max-width: 100%;
  padding: 4px 9px;
  border: 1px solid transparent;
  border-radius: var(--hd-radius-pill);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  text-transform: none;
  white-space: nowrap;
}

[data-hd-status-tone="success"] {
  color: var(--hd-color-success) !important;
  background: var(--hd-surface-success) !important;
  border-color: color-mix(in srgb, var(--hd-color-success) 34%, transparent) !important;
}

[data-hd-status-tone="warning"] {
  color: var(--hd-color-warning) !important;
  background: var(--hd-surface-warning) !important;
  border-color: color-mix(in srgb, var(--hd-color-warning) 34%, transparent) !important;
}

[data-hd-status-tone="danger"] {
  color: var(--hd-color-danger) !important;
  background: var(--hd-surface-danger) !important;
  border-color: color-mix(in srgb, var(--hd-color-danger) 34%, transparent) !important;
}

[data-hd-status-tone="info"] {
  color: var(--hd-color-info) !important;
  background: var(--hd-surface-info) !important;
  border-color: color-mix(in srgb, var(--hd-color-info) 34%, transparent) !important;
}

[data-hd-status-tone="neutral"] {
  color: var(--hd-color-text-muted) !important;
  background: var(--hd-status-neutral) !important;
  border-color: var(--hd-color-border) !important;
}

@media (max-width: 680px) {
  .app-dialog { width: calc(100% - 32px); }
  .dialog-footer { flex-wrap: wrap; }
  .dialog-footer > button { flex: 1 1 130px; }

  :is(.tabs, .devis-tabs, .factures-tabs) .tab {
    min-height: 42px;
    padding-inline: 11px;
  }
}

/* ============================================================
   Lot 9B-1 : navigation mobile, zones tactiles et responsive
   ============================================================ */

:root {
  --hd-touch-target: 44px;
  --hd-mobile-gutter: 16px;
  --hd-safe-bottom: env(safe-area-inset-bottom, 0px);
}

html.mobile-menu-open,
body.mobile-menu-open {
  overflow: hidden;
  overscroll-behavior: none;
}

#mobileSheet.sheet {
  bottom: 0;
  max-height: calc(100dvh - var(--header-h) - env(safe-area-inset-top, 0px));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: var(--hd-safe-bottom);
}

#mobileSheet.sheet[aria-hidden="true"] { pointer-events: none; }

#mobileSheet .list a {
  min-height: var(--hd-touch-target);
  align-items: center;
  padding: 10px 14px;
}

#mobileSheet .list a:focus-visible { outline-offset: -2px; }

@media (max-width: 900px), (pointer: coarse) {
  :where(
    .btn,
    .btn-primary,
    .btn-secondary,
    .btn-warning,
    .btn-danger,
    .btn-success,
    .btn-ghost,
    .btn-outline,
    .btn-confirm,
    .btn-cancel,
    .btn-icon,
    .iconbtn,
    .task-icon-button
  ) {
    min-height: var(--hd-touch-target);
  }

  :where(.btn-icon, .iconbtn, .task-icon-button) {
    min-width: var(--hd-touch-target);
    width: var(--hd-touch-target);
    height: var(--hd-touch-target);
  }

  :where(input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), select, textarea) {
    min-height: var(--hd-touch-target);
  }

  :is(.tabs, .devis-tabs, .factures-tabs, .tabs-group) {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    scroll-snap-type: inline proximity;
    -webkit-overflow-scrolling: touch;
  }

  :is(.tabs, .devis-tabs, .factures-tabs, .tabs-group) .tab {
    min-height: var(--hd-touch-target);
    scroll-snap-align: start;
  }

  .pop { max-width: calc(100vw - (2 * var(--hd-mobile-gutter))); }
}

@media (max-width: 600px) {
  .header .inner { padding-inline: 10px; }
  .header .actions { right: 10px; gap: 4px; }

  #mobileSheet .list {
    gap: 4px;
    padding: 12px var(--hd-mobile-gutter) calc(20px + var(--hd-safe-bottom));
  }

  #accountPop,
  #notificationPop {
    position: fixed;
    top: calc(var(--header-h) + env(safe-area-inset-top, 0px) + 8px);
    right: var(--hd-mobile-gutter);
    left: var(--hd-mobile-gutter);
    width: auto;
    min-width: 0;
    max-height: calc(100dvh - var(--header-h) - 24px - env(safe-area-inset-top, 0px));
    overflow-y: auto;
  }

  :where(input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), select, textarea) {
    font-size: 16px;
  }

  .modal,
  .modal.medium,
  .modal.large,
  .modal.xlarge {
    min-height: 100dvh;
    height: 100dvh;
  }

  .modal-header { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  .modal-actions { padding-bottom: calc(12px + var(--hd-safe-bottom)); }

  #main-content,
  .main {
    max-width: 100%;
    overflow-x: clip;
  }
}

/* 9B-3 reste la derniere couche de cascade pour les composants
   dont les styles historiques sont declares plus haut dans ce fichier. */
@media (max-width: 900px) {
  [data-hd-status] {
    height: auto;
    white-space: normal;
    text-align: center;
  }
}

:is(.tabs, .devis-tabs, .factures-tabs, .tabs-group) .tab:is(.active, [aria-selected="true"]) {
  color: var(--hd-color-primary-readable);
}
