/* ============================================================
   MAD TRADING — Système d'aide contextuelle (Éléments B + D)
   Fichier: public/help-system.css
   Autonome — n'écrase pas le CSS existant
   ============================================================ */

/* ============================================================
   ÉLÉMENT B — TOOLTIPS SUR BOUTONS SENSIBLES
   ============================================================ */

.mt-tooltip {
  position: relative;
  display: inline-block;
}

.mt-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #0f1f38;
  color: #ffffff;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.4;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  text-align: left;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 10000;
  pointer-events: none;
}

.mt-tooltip::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #0f1f38;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 10000;
  pointer-events: none;
}

.mt-tooltip.mt-tooltip-visible::after,
.mt-tooltip.mt-tooltip-visible::before {
  opacity: 1;
  visibility: visible;
}

.mt-tooltip.mt-tooltip-right::after {
  bottom: 50%;
  left: calc(100% + 8px);
  transform: translateY(50%);
}
.mt-tooltip.mt-tooltip-right::before {
  bottom: 50%;
  left: calc(100% + 2px);
  transform: translateY(50%) rotate(90deg);
}
.mt-tooltip.mt-tooltip-left::after {
  left: auto;
  right: 0;
  transform: none;
}
.mt-tooltip.mt-tooltip-left::before {
  left: auto;
  right: 14px;
  transform: none;
}

/* ============================================================
   ÉLÉMENT D — MESSAGES D'ERREUR MÉTIER (TOASTS)
   ============================================================ */

#mt-toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 420px;
  pointer-events: none;
}

.mt-toast {
  pointer-events: auto;
  position: relative;
  border-radius: 8px;
  padding: 14px 18px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #1f2937;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  border-left: 4px solid #6b7280;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 320px;
  max-width: 420px;
  opacity: 0;
  transform: translateX(100%);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.mt-toast.mt-toast-visible {
  opacity: 1;
  transform: translateX(0);
}

.mt-toast.mt-toast-error {
  border-left-color: #d9483b;
  background: #fef2f2;
}

.mt-toast.mt-toast-warning {
  border-left-color: #d97706;
  background: #fffbeb;
}

.mt-toast.mt-toast-info {
  border-left-color: #1d637a;
  background: #eff6ff;
}

.mt-toast.mt-toast-success {
  border-left-color: #16a34a;
  background: #f0fdf4;
}

.mt-toast-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  font-size: 18px;
  line-height: 1;
}

.mt-toast-error .mt-toast-icon { color: #d9483b; }
.mt-toast-warning .mt-toast-icon { color: #d97706; }
.mt-toast-info .mt-toast-icon { color: #1d637a; }
.mt-toast-success .mt-toast-icon { color: #16a34a; }

.mt-toast-content {
  flex: 1;
  min-width: 0;
}

.mt-toast-title {
  font-weight: 600;
  margin: 0 0 4px 0;
  font-size: 14px;
}

.mt-toast-message {
  margin: 0;
  font-size: 13px;
  color: #4b5563;
  word-wrap: break-word;
}

.mt-toast-contact {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
}

.mt-toast-close {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 0;
  width: 20px;
  height: 20px;
  font-size: 16px;
  line-height: 1;
  border-radius: 4px;
  transition: background 0.15s ease, color 0.15s ease;
}

.mt-toast-close:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #374151;
}

.mt-toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 0 0 8px 8px;
  width: 100%;
  transform-origin: left;
  animation: mt-toast-progress 6s linear forwards;
}

@keyframes mt-toast-progress {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* ============================================================
   ÉLÉMENT D — BANNIÈRE D'ERREUR INLINE
   ============================================================ */

.mt-inline-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-left: 4px solid #d9483b;
  border-radius: 6px;
  padding: 12px 16px;
  margin: 12px 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #991b1b;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.mt-inline-error-icon {
  flex-shrink: 0;
  font-size: 18px;
  line-height: 1;
}

.mt-inline-error-content {
  flex: 1;
}

.mt-inline-error-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.mt-inline-error-contact {
  margin-top: 6px;
  font-size: 12px;
  color: #7f1d1d;
  font-style: italic;
}

/* ============================================================
   ADAPTATION MOBILE
   ============================================================ */

@media (max-width: 640px) {
  #mt-toast-container {
    top: 8px;
    right: 8px;
    left: 8px;
    max-width: none;
  }

  .mt-toast {
    min-width: 0;
    max-width: none;
    width: 100%;
  }

  .mt-tooltip::after {
    bottom: auto;
    top: calc(100% + 8px);
  }
  .mt-tooltip::before {
    bottom: auto;
    top: calc(100% + 2px);
    transform: translateX(-50%) rotate(180deg);
  }
  .mt-tooltip.mt-tooltip-left::before {
    transform: rotate(180deg);
  }
}

/* ============================================================
   ACCESSIBILITÉ
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .mt-toast,
  .mt-tooltip::after,
  .mt-tooltip::before {
    transition: none;
  }
  .mt-toast-progress {
    animation: none;
  }
}

.mt-tooltip:focus-visible {
  outline: 2px solid #1d637a;
  outline-offset: 2px;
}

/* ============================================================
   ÉLÉMENT A — PANNEAU D'AIDE CONTEXTUELLE
   ============================================================ */

#mt-help-panel[hidden] { display: none; }

.mt-help-panel {
  position: fixed;
  inset: 0;
  z-index: 10020;
  display: flex;
  justify-content: flex-end;
  color: #0f1f38;
}

.mt-help-panel__scrim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: rgba(15, 31, 56, 0.42);
  cursor: default;
}

.mt-help-panel__dialog {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(440px, 100vw);
  height: 100%;
  background: #fff;
  box-shadow: -8px 0 28px rgba(15, 31, 56, 0.18);
  outline: none;
  animation: mt-help-slide-in 0.22s ease-out;
}

.mt-help-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid #e5eaf0;
}

.mt-help-panel__header h2 {
  margin: 0;
  color: #0f1f38;
  font-size: 19px;
  line-height: 1.3;
}

.mt-help-panel__close,
.mt-help-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid #d6e2e8;
  border-radius: 50%;
  color: #1d637a;
  background: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.mt-help-panel__close { font-size: 24px; }
.mt-help-trigger:hover,.mt-help-trigger:focus-visible,.mt-help-panel__close:hover { background: #edf5f7; }
.mt-help-trigger:focus-visible,.mt-help-panel__close:focus-visible { outline: 2px solid #1d637a; outline-offset: 2px; }

.mt-help-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px 24px;
}

.mt-help-panel__section { margin: 0 0 18px; }
.mt-help-panel__section h3 { margin: 0 0 7px; color: #0f1f38; font-size: 14px; }
.mt-help-panel__section p,.mt-help-panel__section li { color: #435166; font-size: 13px; line-height: 1.55; }
.mt-help-panel__section p { margin: 0; }
.mt-help-panel__section ul { margin: 0; padding-left: 19px; }
.mt-help-panel__section li + li { margin-top: 5px; }
.mt-help-panel__contact { padding-top: 14px; border-top: 1px solid #e5eaf0; }
.mt-help-panel__loading { color: #59677c; font-size: 14px; }

@keyframes mt-help-slide-in {
  from { transform: translateX(24px); opacity: 0.75; }
  to { transform: translateX(0); opacity: 1; }
}

/* Formulaire de vente : client large / téléphone, puis devise / référence. */
.page-heading { display: flex; align-items: center; gap: 10px; min-width: 0; }
.page-heading-copy { min-width: 0; }
#saleForm.mt-form-optimized {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: start;
  gap: 12px;
}
#saleForm > .mt-sale-client { grid-column: span 8; }
#saleForm > .mt-sale-phone { grid-column: span 4; }
#saleForm > .mt-sale-currency,#saleForm > .mt-sale-reference { grid-column: span 6; }
#saleForm > .mt-sale-lines,#saleForm > .mt-sale-payment-row,
#saleForm > .mt-sale-credit,#saleForm > .mt-sale-note-field,#saleForm > .mt-sale-submit,
#saleForm > .mt-sale-expiry { grid-column: 1 / -1; }
.mt-sale-customer-picker { margin-top: 8px; }
.mt-sale-customer-picker .label { margin-bottom: 4px; color: #69788b; font-size: 11px; }
.mt-sale-note { display: flex; align-items: flex-start; gap: 7px; margin: 0 0 12px; color: #66758a; font-size: 12px; line-height: 1.45; }
.mt-sale-note span:first-child { color: #1d637a; font-size: 14px; font-weight: 700; }
.mt-sale-payment-row { display: grid; grid-template-columns: 1fr; gap: 12px; }
.mt-sale-payment-row:has(#saleDueReasonWrap:not([hidden])) { grid-template-columns: repeat(2,minmax(0,1fr)); }
.mt-sale-submit { justify-self: end; }
#saleAddLine { margin-top: 6px; }

@media (max-width: 767px) {
  .mt-help-panel__dialog { width: 100vw; }
  .mt-help-panel__header,.mt-help-panel__body { padding-left: 16px; padding-right: 16px; }
  #saleForm.mt-form-optimized { grid-template-columns: minmax(0,1fr); }
  #saleForm > .mt-sale-client,#saleForm > .mt-sale-phone,#saleForm > .mt-sale-currency,
  #saleForm > .mt-sale-reference,#saleForm > .mt-sale-lines,
  #saleForm > .mt-sale-payment-row,#saleForm > .mt-sale-credit,#saleForm > .mt-sale-note-field,
  #saleForm > .mt-sale-submit,#saleForm > .mt-sale-expiry { grid-column: 1 / -1; }
  .mt-sale-payment-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .mt-help-panel__dialog { animation: none; }
}
