/* Correctifs mobile — barre Aminia compacte, actions visibles, formulaires
   utilisables au pouce. Chargé après app.css et mobile-wizard.css. */

/* Desktop : le libellé « Terminer » suffit ; la croix est réservée au mobile. */
.agent-close-x {
  display: none;
}

@media (max-width: 768px) {
  /* ---------- Footer : Aminia devient un onglet, plus une pastille flottante ---------- */
  .m-footer {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .agent-fab {
    display: none !important;
  }

  .m-footer-agent .m-footer-ico {
    color: inherit;
  }

  body.agent-open .m-footer-agent .m-footer-ico {
    color: #fff;
    background: linear-gradient(135deg, var(--pink) 0%, #e0447f 100%);
    border-color: transparent;
  }

  .content {
    padding-bottom: calc(
      var(--space-5) + var(--m-footer-h) +
      env(safe-area-inset-bottom, 0px)
    );
  }

  .shell:has(details.page-actions) .content,
  .shell:has(a.btn.page-actions) .content {
    padding-bottom: calc(
      var(--space-5) + var(--m-footer-h) + var(--m-action-h) +
      env(safe-area-inset-bottom, 0px)
    );
  }

  .shell:has(div.page-actions) .content {
    padding-bottom: calc(
      var(--space-5) + var(--m-footer-h) + var(--m-action-bar-h) +
      env(safe-area-inset-bottom, 0px)
    );
  }

  /* ---------- Aminia : une barre compacte, pas un panneau ---------- */
  .agent-panel {
    /* Le padding bas de app.css réservait le footer *à l'intérieur* du panneau,
       ce qui créait un grand bloc vide et poussait la barre hors écran. */
    padding-bottom: 0;
    background: transparent;
  }

  .agent-dialog {
    /* Carte flottante au lieu d'une barre collée tout en bas :
       marges latérales, coins arrondis, posée au-dessus de la barre d'onglets. */
    min-height: 64px;
    padding: 10px 14px;
    gap: 10px;
    border-radius: 22px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.92);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.5),
      0 24px 54px -22px rgba(0, 20, 50, 0.6);
  }
  body.agent-open .agent-dialog {
    position: fixed;
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 0;
    margin-bottom: calc(
      var(--m-footer-h) + 10px + env(safe-area-inset-bottom, 0px)
    );
  }

  .agent-orb {
    width: 36px;
    height: 36px;
  }

  .agent-core {
    width: 32px;
    height: 32px;
  }

  .agent-wave {
    height: 14px;
    gap: 2px;
  }

  .agent-wave i {
    width: 2px;
    height: 6px;
  }

  .agent-dialog h2 {
    font-size: 13px;
    line-height: 1.2;
  }

  .agent-status {
    margin-top: 0;
    font-size: 12px;
    line-height: 1.25;
  }

  /* Durée, case « écran allumé » et transcript : inutiles sur un appel mobile. */
  .agent-meta,
  .agent-note {
    display: none !important;
  }

  .agent-actions {
    gap: 6px;
  }

  .agent-actions .btn {
    min-height: var(--tap);
    padding: 8px 10px;
    font-size: 12px;
  }

  .agent-mic {
    width: var(--tap);
    height: var(--tap);
  }

  .agent-close-x {
    display: inline;
    font-size: 22px;
    line-height: 1;
  }

  .agent-close-label {
    display: none;
  }

  .agent-actions [data-agent-close] {
    width: var(--tap);
    min-width: var(--tap);
    padding: 0;
    justify-content: center;
  }

  /* La barre vocale se pose juste au-dessus du footer, ou des actions. */
  body.agent-open .agent-panel {
    bottom: calc(
      var(--m-footer-h) + 6px +
      env(safe-area-inset-bottom, 0px)
    );
  }

  body.agent-open:has(details.page-actions) .agent-panel,
  body.agent-open:has(a.btn.page-actions) .agent-panel {
    bottom: calc(
      var(--m-footer-h) + var(--m-action-h) + var(--m-fab-gap) +
      env(safe-area-inset-bottom, 0px)
    );
  }

  body.agent-open:has(div.page-actions) .agent-panel {
    bottom: calc(
      var(--m-footer-h) + var(--m-action-bar-h) +
      env(safe-area-inset-bottom, 0px)
    );
  }

  /* Le panneau de résultats d'entreprises reste au-dessus de la barre vocale. */
  body.agent-open .agent-results {
    bottom: calc(
      var(--m-footer-h) + 66px +
      env(safe-area-inset-bottom, 0px)
    );
  }

  body.agent-open:has(details.page-actions) .agent-results,
  body.agent-open:has(a.btn.page-actions) .agent-results {
    bottom: calc(
      var(--m-footer-h) + var(--m-action-h) + var(--m-fab-gap) + 66px +
      env(safe-area-inset-bottom, 0px)
    );
  }

  body.agent-open:has(div.page-actions) .agent-results {
    bottom: calc(
      var(--m-footer-h) + var(--m-action-bar-h) + 66px +
      env(safe-area-inset-bottom, 0px)
    );
  }

  body.wizard-active.agent-open .agent-results {
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  }

  /* Le menu « Actions » doit passer au-dessus d'Aminia, sinon Valider est caché. */
  body.agent-open details.page-actions[open] {
    z-index: calc(var(--z-agent-panel) + 5);
  }

  details.page-actions[open] {
    z-index: calc(var(--z-agent-panel) + 5);
  }

  details.page-actions > .actions-list {
    max-height: min(62vh, 460px);
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  /* Contenu : réserve la barre Aminia (environ 68 px) quand elle est ouverte. */
  body.agent-open .content {
    padding-bottom: calc(
      var(--m-footer-h) + 68px + var(--m-fab-gap) +
      env(safe-area-inset-bottom, 0px)
    );
  }

  body.agent-open:has(details.page-actions) .content,
  body.agent-open:has(a.btn.page-actions) .content {
    padding-bottom: calc(
      var(--m-footer-h) + var(--m-action-h) + 68px + var(--m-fab-gap) +
      env(safe-area-inset-bottom, 0px)
    );
  }

  body.agent-open:has(div.page-actions) .content {
    padding-bottom: calc(
      var(--m-footer-h) + var(--m-action-bar-h) + 68px + var(--m-fab-gap) +
      env(safe-area-inset-bottom, 0px)
    );
  }

  /* ---------- Actions de page : action principale + menu court ---------- */
  details.page-actions.m-dock-split {
    left: auto;
    right: var(--space-3);
    width: 54px;
  }

  details.page-actions.m-dock-split > summary.actions-summary {
    width: 54px;
    min-width: 54px;
    padding: 0;
    font-size: 0;
    gap: 0;
    color: var(--ink-2);
    background: var(--surface);
    border: 1px solid var(--line);
  }

  details.page-actions.m-dock-split > summary.actions-summary::before {
    content: "⋯";
    font-size: 24px;
    line-height: 1;
    letter-spacing: 1px;
  }

  details.page-actions.m-dock-split > .actions-list {
    left: auto;
    right: 0;
    width: min(340px, calc(100vw - 24px));
  }

  details.page-actions.m-dock-single {
    display: none;
  }

  .m-dock-primary {
    position: fixed;
    left: var(--space-3);
    right: calc(var(--space-3) + 54px + 8px);
    bottom: calc(
      var(--space-3) + var(--m-footer-h) +
      env(safe-area-inset-bottom, 0px)
    );
    z-index: var(--z-page-actions);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 10px var(--space-2);
    font-size: var(--text-sm);
    box-shadow: var(--shadow);
  }

  .m-dock-primary--wide {
    right: var(--space-3);
  }

  /* Boutons multiples (cockpit) : défilement horizontal plutôt que compression. */
  div.page-actions {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }

  div.page-actions::-webkit-scrollbar {
    display: none;
  }

  div.page-actions .btn {
    flex: 0 0 auto;
    min-width: max-content;
    scroll-snap-align: start;
  }

  /* ---------- Cartes : le scroll reste dans le tableau, pas dans la page ---------- */
  .card,
  .card-tight {
    overflow-x: visible;
  }

  .card:has(> table),
  .card-tight:has(> table) {
    overflow-x: auto;
  }

  .table-wrap,
  .invoice-lines-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .invoice-form-card,
  .invoice-lines-card {
    overflow: visible !important;
  }

  /* ---------- Tableaux transformés en fiches ---------- */
  .card table.table-mobile-cards,
  .card-tight table.table-mobile-cards,
  .table-mobile-cards {
    display: block;
    width: 100%;
    min-width: 0 !important;
  }

  .table-mobile-cards thead {
    display: none;
  }

  .table-mobile-cards tbody {
    display: grid;
    gap: 10px;
  }

  .table-mobile-cards tr {
    display: block;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
  }

  .table-mobile-cards td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 0;
    border: 0;
    text-align: right;
    white-space: normal;
  }

  .table-mobile-cards td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .03em;
    text-align: left;
    text-transform: uppercase;
  }

  .card .table-mobile-cards td:first-child,
  .card-tight .table-mobile-cards td:first-child {
    position: static;
    z-index: auto;
    background: transparent;
    box-shadow: none;
  }

  .table-mobile-cards td:last-child:has(.btn) {
    padding-top: 8px;
  }

  .table-mobile-cards td:last-child:has(.btn)::before {
    display: none;
  }

  .table-mobile-cards td .btn {
    width: 100%;
    justify-content: center;
  }

  .table-mobile-cards tr.empty-row td {
    justify-content: center;
    text-align: center;
  }

  /* ---------- Lignes de facture / devis / avoir : une fiche par ligne ---------- */
  .card table.invoice-lines-table,
  .invoice-lines-table {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .invoice-lines-table thead {
    display: none;
  }

  .invoice-lines-table tbody {
    display: grid;
    gap: 12px;
  }

  .invoice-lines-table tr.invoice-line-row {
    display: block;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
  }

  .invoice-lines-table tr.invoice-line-row td {
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    width: auto;
    min-width: 0;
    padding: 6px 0;
    border: 0;
    vertical-align: middle;
  }

  .invoice-lines-table tr.invoice-line-row td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .03em;
    text-transform: uppercase;
  }

  .invoice-lines-table tr.invoice-line-row td.line-product,
  .invoice-lines-table tr.invoice-line-row td.line-description {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .invoice-lines-table tr.invoice-line-row td.line-product::before,
  .invoice-lines-table tr.invoice-line-row td.line-description::before {
    margin-bottom: 2px;
  }

  .invoice-lines-table tr.invoice-line-row td.line-total {
    font-size: 16px;
    font-weight: 800;
    text-align: right;
  }

  .invoice-lines-table tr.invoice-line-row td.line-remove {
    position: static;
    top: auto;
    right: auto;
    display: flex;
    justify-content: flex-end;
    width: auto;
    padding-top: 8px;
  }

  .invoice-lines-table tr.invoice-line-row td.line-remove::before {
    display: none;
  }

  .invoice-lines-table input,
  .invoice-lines-table select {
    width: 100%;
    min-width: 0;
    height: 42px;
    font-size: 16px;
  }

  .invoice-lines-table tr.is-deleted {
    opacity: .5;
  }

  .invoice-lines-table .line-remove-btn {
    min-width: var(--tap);
    min-height: var(--tap);
  }

  .invoice-lines-toolbar {
    display: grid;
    gap: 10px;
  }

  .invoice-preview-totals {
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
  }

  /* ---------- Assistant par étapes : la barre Précédent/Suivant remplace la tab bar ---------- */
  body.wizard-active .m-footer,
  body.wizard-active .agent-fab {
    display: none !important;
  }

  body.wizard-active .content {
    padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  }

  .wizard-mode .wizard-head {
    margin: 0 0 12px;
  }

  .wizard-mode .wizard-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: calc(var(--z-page-actions) + 1);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
    box-shadow: 0 -14px 34px -20px rgba(15, 23, 42, .5);
  }

  .wizard-mode .wizard-nav .wizard-submit,
  .wizard-mode .wizard-nav .wizard-cancel {
    grid-column: 1 / -1;
  }

  body.wizard-active.agent-open .agent-panel {
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  body.agent-open.wizard-active .wizard-nav {
    bottom: 0;
    z-index: calc(var(--z-agent-panel) + 5);
  }
}

@media (max-width: 360px) {
  .m-footer-btn {
    font-size: 9.5px;
  }

  .m-footer-ico {
    width: 34px;
    height: 34px;
  }
}

/* Wizard d'ajout de société : la carte officielle ne doit pas imposer sa
   largeur (tableau INSEE) ; la grille se resserre et le tableau défile. */
@media (max-width: 768px) {
  .grid.g2 > * {
    min-width: 0;
  }

  .grid.g2 .card table,
  .grid.g2 .card .table-wrap {
    display: block;
    max-width: 100%;
    overflow-x: auto;
  }
}


/* ---------- Assistant par étapes : pilule Liquid Glass fixée en bas ----------
   S'applique aussi au mode forcé sur desktop (data-wizard-mode="always"). */
.wizard-mode .wizard-nav,
.wizard-desktop.wizard-mode .wizard-nav {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: min(92%, 460px);
  z-index: 99999;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px 16px;
  background: rgba(255, 255, 255, .45);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  backdrop-filter: blur(20px) saturate(170%);
  border: 1px solid rgba(255, 255, 255, .55);
  border-radius: 999px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .15), inset 0 1px 0 rgba(255, 255, 255, .6);
}

html[data-theme="dark"] .wizard-mode .wizard-nav,
html[data-theme="dark"] .wizard-desktop.wizard-mode .wizard-nav {
  background: rgba(20, 22, 26, .55);
  border-color: rgba(255, 255, 255, .16);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .08);
}

.wizard-mode .wizard-nav .wizard-position {
  display: block !important;
  color: var(--muted, #64748b);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
}

.wizard-mode .wizard-nav .btn {
  margin: 0;
  min-height: 46px;
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 800;
  white-space: nowrap;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.wizard-mode .wizard-nav .btn-primary {
  background: linear-gradient(135deg, rgba(14, 165, 233, .9), rgba(2, 132, 199, .9));
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .3);
  box-shadow: 0 4px 12px rgba(14, 165, 233, .4);
}

.wizard-mode .wizard-nav .btn-ghost {
  background: rgba(255, 255, 255, .25);
  color: var(--ink, #0f172a);
  border: 1px solid rgba(255, 255, 255, .5);
}

html[data-theme="dark"] .wizard-mode .wizard-nav .btn-ghost {
  background: rgba(255, 255, 255, .08);
  color: var(--ink, #f6f6f4);
  border-color: rgba(255, 255, 255, .18);
}

.wizard-mode .wizard-nav .wizard-back {
  justify-self: start;
}

.wizard-mode .wizard-nav .wizard-next {
  justify-self: end;
  min-width: 132px;
}

.wizard-mode .wizard-nav .wizard-submit {
  grid-column: 1 / -1;
  width: 100%;
  justify-content: center;
}

.wizard-mode .wizard-nav [hidden] {
  display: none !important;
}

body.wizard-active .content {
  padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px));
}
