/* Socle responsive commun : navigation, ancres, interactions et préférences système. */

/* Les ancres restent visibles sous l'en-tête sticky. */
html {
  scroll-padding-top: 76px;
}

:target {
  scroll-margin-block-start: 76px;
}

/* Cibles tactiles cohérentes dans la navigation mobile. */
.ts-nav__links a {
  min-height: 44px;
  display: flex;
  align-items: center;
}

.ts-nav__cats a {
  min-height: 44px;
}

/* Respect des encoches et zones système des appareils mobiles. */
@media (max-width: 575px) {
  .share-menu {
    bottom: max(18px, calc(env(safe-area-inset-bottom, 0px) + 10px));
    right: max(16px, calc(env(safe-area-inset-right, 0px) + 10px));
  }

  .share-toast {
    bottom: max(78px, calc(env(safe-area-inset-bottom, 0px) + 70px));
    right: max(16px, calc(env(safe-area-inset-right, 0px) + 10px));
    max-width: calc(100vw - 32px);
    white-space: normal;
  }
}

/* Les animations non essentielles sont désactivées à la demande du système. */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto !important;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Ergonomie des contrôles et des résultats sur petits écrans. */
@media (max-width: 767.98px) {
  /* Évite le zoom automatique iOS et conserve des champs confortables au toucher. */
  .form-control,
  .form-select,
  .form-control-sm,
  .form-select-sm {
    font-size: 16px;
  }

  .form-control,
  .form-select {
    min-height: 44px;
  }

  .form-control-sm,
  .form-select-sm {
    min-height: 40px;
  }

  .btn {
    min-height: 40px;
  }

  .table-responsive {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
  }

  .table-responsive th,
  .table-responsive td {
    overflow-wrap: anywhere;
  }

  /* Les champs intégrés aux phrases de calcul restent lisibles sans déborder. */
  .pcard input.form-control {
    width: min(6.5rem, 24vw) !important;
    min-width: 4.5rem;
    max-width: 100%;
    vertical-align: middle !important;
  }
}

/* Visualiseur HTML : commandes et panneaux adaptés au format mobile. */
@media (max-width: 991.98px) {
  #workspace .btn-group {
    flex-wrap: wrap;
  }

  #workspace .btn-group .btn {
    min-height: 40px;
  }

  #workspace .editor-container {
    height: min(52vh, 420px);
    height: clamp(280px, 52svh, 420px);
  }

  #workspace #editorPanel,
  #workspace #previewPanel {
    min-height: 0;
  }

  #workspace #previewContainer,
  #workspace #previewFrame {
    min-height: 320px;
  }
}

@media (max-width: 575.98px) {
  #workspace .btn-group {
    margin-inline: 0 !important;
  }

  #workspace .btn-group .btn {
    padding-inline: .55rem;
  }

  #workspace .card-body {
    padding: .75rem;
  }
}


/* Graphiques : empêcher les canvas à taille intrinsèque de déborder de leur carte. */
canvas {
  max-width: 100%;
}

#chartContainer {
  min-width: 0;
  width: 100%;
}

/* Modales : conserver l'en-tête et les actions accessibles, faire défiler le contenu. */
@media (max-width: 767.98px) {
  .modal-dialog {
    margin: .5rem;
  }

  .modal-content {
    max-height: calc(100vh - 1rem);
    max-height: calc(100dvh - 1rem);
  }

  .modal-header,
  .modal-footer {
    flex-shrink: 0;
  }

  .modal-body {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}


/* Les tableaux larges du portefeuille restent atteignables au clavier. */
.ts-table-scroll[tabindex="0"]:focus-visible {
  outline: 2px solid var(--bs-primary, #0d6efd);
  outline-offset: 2px;
}


/* Les commandes de suppression des photos doivent rester utilisables au toucher. */
.inv-thumb button {
  min-width: 44px;
  min-height: 44px;
  z-index: 1;
}


/* Parcours mobile des outils Airbnb : cibles tactiles et focus des tableaux. */
@media (max-width: 767.98px) {
  #invoiceForm .btn,
  #resultCard .btn,
  #simResults .btn {
    min-height: 44px;
  }

  #invoiceForm .extra-line > div:last-child button {
    min-width: 44px;
    min-height: 44px;
  }
}


/* Navigation principale : langage visuel unifié sur desktop et mobile. */
.ts-header {
  background: var(--bs-body-bg, #fff);
  border-bottom-color: var(--bs-border-color, #e2e8f0);
  box-shadow: 0 2px 12px rgba(15, 23, 42, .035);
}

.ts-header__bar {
  min-height: 64px;
  height: auto;
  gap: .75rem;
}

.ts-brand {
  min-height: 44px;
  padding: .2rem .35rem;
  margin-left: -.35rem;
  transition: background-color .18s ease;
}

.ts-brand:hover {
  background: var(--bs-tertiary-bg, #f8f9fa);
}

.ts-header__actions {
  gap: .25rem;
}

.ts-iconbtn,
.ts-lang {
  flex: 0 0 44px;
  width: 44px;
  min-width: 44px;
  height: 44px;
  border: 1px solid transparent;
  border-radius: .7rem;
  transition: color .18s ease, background-color .18s ease, border-color .18s ease;
}

.ts-iconbtn:hover,
.ts-lang:hover {
  background: var(--bs-tertiary-bg, #f8f9fa);
  border-color: var(--bs-border-color, #e2e8f0);
}

.ts-burger {
  background: var(--bs-tertiary-bg, #f8f9fa);
  border-color: var(--bs-border-color, #e2e8f0);
}

.ts-header.is-open .ts-burger {
  color: var(--bs-primary, #4f46e5);
  background: var(--bs-primary-bg-subtle, #eef2ff);
  border-color: var(--bs-primary-border-subtle, #c7d2fe);
}

.ts-nav {
  top: 100%;
  padding: 1rem max(1rem, calc((100vw - 720px) / 2)) 1.25rem;
  border-top: 1px solid var(--bs-border-color, #e2e8f0);
  border-bottom: 1px solid var(--bs-border-color, #e2e8f0);
  box-shadow: 0 16px 30px rgba(15, 23, 42, .1);
}

.ts-nav__search {
  min-height: 46px;
  border-color: var(--bs-border-color, #cbd5e1);
  border-radius: .75rem;
  background: var(--bs-body-bg, #fff);
}

.ts-nav__search input {
  min-height: 44px;
  padding-inline: .9rem;
}

.ts-nav__search button {
  min-width: 48px;
  background: var(--bs-primary, #4f46e5);
}

.ts-nav__links {
  display: grid;
  gap: .25rem;
}

.ts-nav__links a {
  min-height: 46px;
  padding: .7rem .85rem;
  border: 1px solid transparent;
  border-radius: .7rem;
  color: var(--bs-emphasis-color, #0f172a);
  font-size: .96rem;
  font-weight: 600;
  line-height: 1.35;
  transition: color .18s ease, background-color .18s ease, border-color .18s ease;
}

.ts-nav__links a:hover {
  color: var(--bs-primary, #4338ca);
  background: var(--bs-tertiary-bg, #f8f9fa);
  border-color: var(--bs-border-color, #e2e8f0);
}

.ts-nav__links a[aria-current="page"] {
  color: var(--bs-primary-text-emphasis, #3730a3);
  background: var(--bs-primary-bg-subtle, #eef2ff);
  border-color: var(--bs-primary-border-subtle, #c7d2fe);
}

.ts-nav__title {
  margin: 1.35rem 0 .65rem;
  color: var(--bs-secondary-color, #64748b);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
}

.ts-nav__cats ul {
  gap: .25rem .5rem;
}

.ts-nav__cats a {
  min-height: 44px;
  padding: .55rem .65rem;
  border: 1px solid transparent;
  border-radius: .65rem;
  color: var(--bs-body-color, #334155);
  line-height: 1.35;
  transition: color .18s ease, background-color .18s ease, border-color .18s ease;
}

.ts-nav__cats a:hover {
  color: var(--bs-primary, #4338ca);
  background: var(--bs-tertiary-bg, #f8f9fa);
  border-color: var(--bs-border-color, #e2e8f0);
}

.ts-nav__cats .ts-icon {
  color: var(--bs-primary, #4f46e5);
}

@media (min-width: 992px) {
  .ts-header__bar {
    min-height: 68px;
  }

  .ts-nav {
    top: auto;
    margin-left: auto;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .ts-nav__links {
    display: flex;
    align-items: center;
    gap: .25rem;
  }

  .ts-nav__links a {
    min-height: 42px;
    padding: .55rem .8rem;
    border-radius: .7rem;
    font-size: .9rem;
    white-space: nowrap;
  }

  .ts-nav__links a[aria-current="page"] {
    box-shadow: inset 0 0 0 1px var(--bs-primary-border-subtle, #c7d2fe);
  }

  .ts-header__actions {
    margin-left: .5rem;
  }
}

@media (max-width: 991.98px) {
  .ts-header__bar {
    min-height: 60px;
  }

  .ts-nav {
    max-height: calc(100dvh - 60px);
  }
}

@media (max-width: 575.98px) {
  .ts-nav {
    padding: .85rem 1rem 1.1rem;
  }

  .ts-nav__cats ul {
    grid-template-columns: 1fr;
    gap: .1rem;
  }

  .ts-nav__cats a {
    padding-inline: .75rem;
  }

  .ts-header__actions {
    gap: .1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ts-brand,
  .ts-iconbtn,
  .ts-lang,
  .ts-nav__links a,
  .ts-nav__cats a {
    transition: none;
  }
}
