/* ILC BL/CAT en ligne — couche spécifique de la charte ILC Pro (après ilc-pro.css).
   Formulaire long : une carte centrée, sections aérées ; sur mobile une seule
   colonne, cibles tactiles de 44 px et barre d'actions collée en bas.
   Pas de display en !important sur les éléments basculés par .hide. */

:root:not(#ilc-a):not(#ilc-b) body.ilc-pro.ilc-bl {

  /* :not(#ilc-c) : passe devant la règle générique « margin: 0 » des cartes (ilc-pro.css) */
  & .appMain > :is(.appHeader, .card):not(#ilc-c) { width: 100% !important; max-width: 960px !important; margin-inline: auto !important; }
  & .appMain > .card { padding: 22px 24px !important; }
  & .form { display: flex; flex-direction: column; gap: 10px; }

  /* Icônes SVG intégrées */
  & .ilc-svg { width: 16px; height: 16px; flex: 0 0 auto; color: var(--ux-brand-text); vertical-align: -3px; }
  & :is(.btn.primary, .btn.danger, .sideFootActions .btn) .ilc-svg { color: inherit; }

  & .lbl { display: flex; align-items: center; gap: 7px; margin: 10px 0 0 !important; }
  & .lbl .ilc-svg { color: var(--ux-brand-text) !important; }
  & .inp { width: 100%; }
  & .inp.upper { text-transform: uppercase; }
  & textarea.inp, & .ta { min-height: 110px; }
  & .muted.small, & .small { color: var(--ux-muted) !important; font-size: 12.5px !important; }

  /* Case « client sous CAT » + type de facturation (segmenté) */
  & .chkline {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 40px;
    margin: 0 !important;
    padding: 8px 12px !important;
    border: 1px solid var(--ux-border) !important;
    border-radius: var(--ux-r) !important;
    background: var(--ux-surface-2) !important;
    color: var(--ux-text) !important;
    font: 500 13.5px/1.3 var(--ux-font) !important;
    cursor: pointer;
  }
  & .chkline input { width: 17px; height: 17px; margin: 0; accent-color: var(--ux-brand); }
  & .seg {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    padding: 4px !important;
    border: 1px solid var(--ux-border) !important;
    border-radius: var(--ux-r) !important;
    background: var(--ux-surface-2) !important;
  }
  & .segitem {
    display: grid;
    place-items: center;
    min-height: 34px;
    margin: 0 !important;
    padding: 4px 8px !important;
    border: 1px solid transparent !important;
    border-radius: var(--ux-r-sm) !important;
    background: transparent !important;
    color: var(--ux-text-2) !important;
    font: 500 13px/1.2 var(--ux-font) !important;
    text-align: center;
    box-shadow: none !important;
    cursor: pointer;
  }
  & .segitem:hover { color: var(--ux-text) !important; }
  & .segitem:has(input:checked) {
    border-color: var(--ux-brand-ring) !important;
    background: var(--ux-surface) !important;
    color: var(--ux-brand-text) !important;
    font-weight: 600 !important;
    box-shadow: var(--ux-shadow-sm) !important;
  }
  & .segitem:has(input:focus-visible) { outline: 2px solid var(--ux-brand); outline-offset: 1px; }

  /* Lien vers un ticket ILC Ticketing */
  & .ticket-link {
    display: grid;
    gap: 10px;
    margin: 4px 0 0 !important;
    padding: 14px !important;
    border: 1px dashed var(--ux-border-strong) !important;
    border-radius: var(--ux-r-lg) !important;
    background: var(--ux-surface-2) !important;
    box-shadow: none !important;
  }
  & .ticket-link-head { display: flex; gap: 10px; align-items: flex-start; }
  & .ticket-ico { display: grid; place-items: center; width: 30px; height: 30px; flex: 0 0 30px; border-radius: 8px; background: var(--ux-brand-soft) !important; color: var(--ux-brand-text) !important; border: 0 !important; box-shadow: none !important; }
  & .ticket-link-title { color: var(--ux-text) !important; font: 600 14px/1.3 var(--ux-font) !important; }
  & .ticket-link-head p { margin: 2px 0 0 !important; }
  & .ticket-opt { margin-left: 6px; padding: 1px 7px; border: 1px solid var(--ux-border); border-radius: 999px; color: var(--ux-muted) !important; font: 500 11px/1.4 var(--ux-font) !important; background: var(--ux-surface) !important; }
  & .ticket-open { justify-self: start; }
  & .ticket-card { border: 1px solid var(--ux-border) !important; border-radius: var(--ux-r) !important; background: var(--ux-surface) !important; }
  & .ticket-card strong { color: var(--ux-text) !important; }

  /* Techniciens et plages horaires */
  & .stack { display: flex; flex-direction: column; gap: 10px; }
  & .tech-row {
    display: grid;
    gap: 10px;
    padding: 12px !important;
    border: 1px solid var(--ux-border) !important;
    border-radius: var(--ux-r-lg) !important;
    background: var(--ux-surface-2) !important;
    box-shadow: none !important;
  }
  & .tech-period { padding: 0 !important; border: 0 !important; background: none !important; }
  & .tech-times { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
  & .tech-time { display: flex; flex-direction: column; gap: 4px; flex: 1 1 140px; color: var(--ux-text-2) !important; font-size: 12.5px !important; }
  & .tech-time-label { display: flex; align-items: center; gap: 6px; }
  & .tech-time-label svg { width: 14px; height: 14px; color: var(--ux-brand-text); }
  & .tech-dur { min-width: 64px; padding-bottom: 10px; color: var(--ux-text) !important; font-weight: 600; font-variant-numeric: tabular-nums; }
  & .tech-subtotal, & .tech-total { margin: 0 !important; color: var(--ux-text-2) !important; font-size: 13px !important; font-weight: 600; }
  & .btn-add-period, & #btnAddTech { justify-self: start; align-self: flex-start; }

  /* Boutons d'ajout / suppression (classe .ghost dans le JS) : actions explicites */
  & :is(.btn-add-period, #btnAddTech):not(#ilc-c) {
    min-height: 34px !important;
    border: 1px dashed var(--ux-brand-ring) !important;
    background: var(--ux-brand-soft) !important;
    color: var(--ux-brand-text) !important;
    font-weight: 600 !important;
    box-shadow: none !important;
  }
  & :is(.btn-add-period, #btnAddTech):not(#ilc-c):hover {
    border-style: solid !important;
    border-color: var(--ux-brand) !important;
    background: color-mix(in srgb, var(--ux-brand) 18%, transparent) !important;
  }
  & #btnAddTech:not(#ilc-c) { min-height: 38px !important; padding: 0 16px !important; }
  & :is(.btn-add-period, #btnAddTech) svg { color: currentColor !important; }
  & :is(.btn-del-tech, .btn-del-period):not(#ilc-c) {
    min-height: 34px !important;
    border: 1px solid var(--ux-red-bd) !important;
    background: var(--ux-surface) !important;
    color: var(--ux-red) !important;
    font-weight: 600 !important;
    box-shadow: none !important;
  }
  & :is(.btn-del-tech, .btn-del-period):not(#ilc-c):hover { border-color: var(--ux-red) !important; background: var(--ux-red-bg) !important; }
  & :is(.btn-del-tech, .btn-del-period) svg { color: currentColor !important; width: 15px; height: 15px; }
  & .btn-del-period { justify-self: start; margin-top: 4px; }
  /* Ticket lié : « Changer de ticket » (secondaire) et « Retirer » (rouge) bien visibles comme boutons */
  & .ticket-card-actions { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--ux-border); }
  & .ticket-card-actions .ticket-action:not(#ilc-c) {
    min-height: 36px !important;
    padding: 0 14px !important;
    border: 1px solid var(--ux-border-strong) !important;
    border-radius: var(--ux-r) !important;
    background: var(--ux-surface-2) !important;
    color: var(--ux-text) !important;
    font-weight: 600 !important;
    box-shadow: var(--ux-shadow-sm) !important;
    cursor: pointer;
  }
  & .ticket-card-actions .ticket-action:not(#ilc-c):hover { border-color: var(--ux-brand) !important; background: var(--ux-brand-soft) !important; color: var(--ux-brand-text) !important; }
  & .ticket-card-actions .ticket-action:not(.ticket-remove) svg { color: var(--ux-brand-text) !important; }
  & .ticket-card-actions .ticket-remove:not(#ilc-c) { border-color: var(--ux-red-bd) !important; background: var(--ux-surface) !important; color: var(--ux-red) !important; }
  & .ticket-card-actions .ticket-remove:not(#ilc-c):hover { border-color: var(--ux-red) !important; background: var(--ux-red-bg) !important; color: var(--ux-red) !important; }
  & .ticket-card-actions .ticket-action svg { color: currentColor; }
  & .ticket-card-actions .ticket-action:focus-visible { outline: 0 !important; box-shadow: 0 0 0 3px var(--ux-brand-ring) !important; }

  /* Signature : bloc encadré, option « signature manuelle », bouton Effacer explicite.
     Le canvas (taille, encre) reste piloté par ilc-bl.js. */
  & .sig {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px !important;
    border: 1px solid var(--ux-border) !important;
    border-radius: var(--ux-r-lg) !important;
    background: var(--ux-surface-2) !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
  }
  & .signature-manual-option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px !important;
    border: 1px solid var(--ux-border) !important;
    border-radius: var(--ux-r) !important;
    background: var(--ux-surface) !important;
    cursor: pointer;
  }
  & .signature-manual-option { margin: 0 !important; }
  & .signature-manual-option:has(input:checked) { border-color: var(--ux-brand-ring) !important; background: var(--ux-brand-soft) !important; box-shadow: none !important; }
  & .signature-manual-option input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--ux-brand); }
  & .signature-manual-copy strong { display: flex; align-items: center; gap: 6px; color: var(--ux-text) !important; font: 600 13.5px/1.3 var(--ux-font) !important; }
  & .signature-manual-copy small { display: block; margin-top: 2px; color: var(--ux-muted) !important; font-size: 12.5px !important; }
  & #sigCanvas { border: 1px dashed var(--ux-border-strong) !important; border-radius: var(--ux-r) !important; }
  & .sigbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
  & #sigClear:not(#ilc-c) {
    min-height: 34px !important;
    border: 1px solid var(--ux-red-bd) !important;
    background: var(--ux-surface) !important;
    color: var(--ux-red) !important;
    font-weight: 600 !important;
    box-shadow: none !important;
  }
  & #sigClear:not(#ilc-c):hover { border-color: var(--ux-red) !important; background: var(--ux-red-bg) !important; }
  & #sigClear .ilc-svg { color: currentColor !important; }
  & #sigModeHint { display: inline-flex; align-items: center; gap: 6px; }
  & .btn svg:not(.ilc-svg) { width: 15px; height: 15px; }

  /* Boutons d'action du formulaire */
  & .actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px !important;
    padding-top: 16px !important;
    border-top: 1px solid var(--ux-border) !important;
    background: transparent !important;
  }
  & .btn-stock { align-self: flex-start; }

  /* Modales (classes à tirets propres à BL/CAT) */
  & .modal-overlay { background: var(--ux-overlay) !important; backdrop-filter: blur(3px) !important; }
  & .modal-overlay .modal { padding: 0 !important; overflow: hidden; }
  & .modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px !important;
    border-bottom: 1px solid var(--ux-border) !important;
    background: var(--ux-surface) !important;
  }
  & .modal-title { display: flex; align-items: center; gap: 8px; color: var(--ux-text) !important; font: 650 16px/1.3 var(--ux-font) !important; }
  & .modal-body { padding: 16px 20px !important; }
  & .modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px !important;
    border-top: 1px solid var(--ux-border) !important;
    background: var(--ux-surface-2) !important;
  }
  & .modal-close { width: 32px; min-height: 32px !important; padding: 0 !important; }
  /* Bouton secondaire des modales (.ghost) : contour visible */
  & .modal-footer .btn.ghost:not(#ilc-c) {
    border: 1px solid var(--ux-border-strong) !important;
    background: var(--ux-surface) !important;
    color: var(--ux-text) !important;
    box-shadow: var(--ux-shadow-sm) !important;
  }
  & .modal-footer .btn.ghost:not(#ilc-c):hover { background: var(--ux-surface-3) !important; }
  /* Confirmation destructive : icône d'alerte en rouge */
  & .modal-confirm .modal-title .ilc-svg { color: var(--ux-red) !important; }
  & .reset-confirm-body p { margin: 0 0 6px !important; color: var(--ux-text) !important; }
  & .reset-confirm-body p.muted { color: var(--ux-muted) !important; }

  & .alert { margin-bottom: 12px !important; }
}

/* ---------- Grand écran : champs côte à côte ---------- */
@media (min-width: 900px) {
  :root:not(#ilc-a):not(#ilc-b) body.ilc-pro.ilc-bl .grid2 { grid-template-columns: 1fr 1fr; gap: 14px; }
}

/* ---------- Mobile (Android / iOS) ---------- */
@media (max-width: 760px) {
  :root:not(#ilc-a):not(#ilc-b) body.ilc-pro.ilc-bl {
    & .appMain > .card { padding: 16px 14px 0 !important; border-radius: var(--ux-r-lg) !important; }
    & .seg { grid-template-columns: 1fr 1fr; }
    & .segitem { min-height: 42px; }
    & .chkline { min-height: 46px; }
    & .tech-time { flex: 1 1 120px; }
    & .ticket-open, & .btn-add-period, & #btnAddTech, & .btn-stock { width: 100%; justify-self: stretch; align-self: stretch; }
    /* Cibles tactiles de 44 px pour les boutons d'ajout / suppression / signature */
    & :is(.btn-add-period, #btnAddTech, .btn-del-tech, .btn-del-period, #sigClear):not(#ilc-c) { min-height: 44px !important; }
    & .ticket-card-actions .ticket-action:not(#ilc-c) { min-height: 44px !important; flex: 1 1 140px; justify-content: center; }
    & #sigClear:not(#ilc-c) { width: 100%; }

    /* Barre d'actions collée en bas de l'écran */
    & .actions {
      position: sticky;
      bottom: 0;
      z-index: 20;
      margin: 14px -14px 0 !important;
      padding: 12px 14px calc(12px + var(--ux-safe-b)) !important;
      background: var(--ux-surface) !important;
      box-shadow: 0 -8px 20px -12px rgba(0, 0, 0, .35);
    }
    & .actions .btn { flex: 1 1 0; }
    /* ilc-bl.css empile le pied en colonne : la base de 140 px devenait une hauteur */
    & .modal-footer { flex-direction: row !important; flex-wrap: wrap; padding-bottom: calc(12px + var(--ux-safe-b)) !important; }
    & .modal-footer .btn { flex: 1 1 0 !important; width: auto !important; height: auto !important; min-height: 44px !important; }
  }
}

/* ---------- Page de résultat (BL enregistré) ---------- */
:root:not(#ilc-a):not(#ilc-b) body.ilc-pro-auth.bl-result {
  & .wrap .card { display: block !important; width: 480px !important; max-width: 100% !important; padding: 30px 32px !important; text-align: center; }
  & .wrap .card::before {
    content: "" !important;
    display: block !important;
    width: 48px;
    height: 48px;
    margin: 0 auto 14px;
    border-radius: 50%;
    background: var(--ux-brand-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12l5 5L20 7' fill='none' stroke='%2322c55e' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 24px no-repeat;
  }
  & .h1 { margin: 0 0 8px !important; color: var(--ux-text) !important; font: 700 21px/1.3 var(--ux-font) !important; }
  & .card p { margin: 0 0 10px !important; color: var(--ux-text-2) !important; font-size: 14px; }
  & .ticket-result { padding: 9px 12px; border: 1px solid var(--ux-border); border-radius: var(--ux-r); background: var(--ux-surface-2) !important; }
  /* Statuts renvoyés par backend/ticketing_bridge.php */
  & .ticket-result:is(.is-closed, .is-already_resolved) { border-color: var(--ux-green-bd) !important; background: var(--ux-green-bg) !important; color: var(--ux-green) !important; }
  & .ticket-result.is-pending { border-color: var(--ux-orange-bd) !important; background: var(--ux-orange-bg) !important; color: var(--ux-orange) !important; }
  & .actions { display: flex; gap: 8px; margin-top: 18px; }
  & .actions .btn { flex: 1 1 0; }
  & .actions .btn.ghost { border: 1px solid var(--ux-border-strong) !important; background: var(--ux-surface) !important; color: var(--ux-text) !important; }
}
@media (max-width: 520px) {
  :root:not(#ilc-a):not(#ilc-b) body.ilc-pro-auth.bl-result {
    & .wrap .card { padding: 24px 20px !important; }
    & .actions { flex-direction: column; }
  }
}
