/* =====================================================================
 * sit_styles.css — Styles pour la facture de situation (V1.1)
 * ---------------------------------------------------------------------
 * Composants :
 *   .sit-sheet-*         — bottom sheet de saisie
 *   .sit-slider          — slider custom 0-100%
 *   .sit-recap           — panneau récap live
 *   .sit-progress-*      — barre de progression
 *   .sit-timeline        — historique des situations
 *   .sit-badge           — pastilles statut
 *   .sit-suivi-*         — vue suivi chantier dans detail-overlay
 *   .sit-picker-*        — modal "Quelle facture ?" + sélecteur de devis
 *   .sit-convert-btn     — 3e bouton dans openConvertModal
 *
 * Utilise les variables existantes de index.html :
 *   --brand, --brand-l, --brand-m, --bg, --card, --ink, --border
 * Dark mode via html.dark : hérité.
 * ===================================================================== */

/* ---------- Reset local ---------- */
.sit-sheet-backdrop *,
.sit-picker-backdrop *,
.sit-suivi-wrap * { box-sizing: border-box; }

body.sit-lock { overflow: hidden; }

/* ===== Bouton 3e choix dans openConvertModal ========================= */
.sit-convert-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 16px;
  margin-top: 8px;
  border: 2px solid var(--brand);
  border-radius: 14px;
  background: var(--card);
  color: var(--brand);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: background .15s, transform .15s;
}
.sit-convert-btn:hover { background: var(--brand-l); }
.sit-convert-btn:active { transform: scale(.98); }

/* ===== Bottom sheet de saisie ======================================== */
.sit-sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; visibility: hidden;
  transition: opacity .22s, visibility .22s;
}
.sit-sheet-backdrop.sit-on { opacity: 1; visibility: visible; }

.sit-sheet-panel {
  width: 100%; max-width: 540px;
  background: var(--card);
  color: var(--ink);
  border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(24px + env(safe-area-inset-bottom, 0px));
  max-height: 92vh;
  max-height: 92dvh; /* évite coupe sous la barre mobile (iOS/Android) */
  overflow-y: auto;
  overscroll-behavior: contain; /* stoppe le scroll du body */
  -webkit-overflow-scrolling: touch;
  transform: translateY(24px);
  transition: transform .22s;
  box-shadow: 0 -8px 24px rgba(0,0,0,.25);
}
.sit-sheet-backdrop.sit-on .sit-sheet-panel { transform: translateY(0); }

/* Head */
.sit-sheet-head {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.sit-sheet-emoji {
  width: 48px; height: 48px;
  border-radius: 14px;
  background: var(--brand-l);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}
.sit-sheet-title { margin: 0; font-size: 18px; font-weight: 700; }
.sit-sheet-sub   { margin: 2px 0 0; font-size: 13px; opacity: .7; }
.sit-sheet-num   { margin: 3px 0 0; font-size: 12px; font-family: ui-monospace, monospace; color: var(--brand); font-weight: 600; }
.sit-close {
  background: transparent; border: 0; color: var(--ink);
  font-size: 20px; cursor: pointer; opacity: .6;
  width: 36px; height: 36px; border-radius: 10px;
}
.sit-close:hover { background: var(--border); opacity: 1; }

/* Mode toggle */
.sit-mode-toggle {
  display: flex; gap: 6px;
  background: var(--bg);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 14px;
}
.sit-tgl {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  opacity: .65;
}
.sit-tgl.on { background: var(--card); color: var(--brand); opacity: 1; box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* Sliders */
.sit-sliders { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.sit-slider-row {
  display: grid;
  grid-template-columns: 1fr auto;
  row-gap: 6px;
  align-items: center;
}
.sit-slider-label { font-size: 13px; font-weight: 600; }
.sit-slider-label small { font-weight: 400; opacity: .6; font-size: 11px; }
.sit-slider-pct  {
  font-size: 13px; font-weight: 700; color: var(--brand);
  background: var(--brand-l); padding: 3px 8px; border-radius: 8px;
  min-width: 44px; text-align: center;
}
.sit-slider {
  grid-column: 1 / -1;
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--brand) 0%, var(--brand) var(--sit-val,0%), var(--border) var(--sit-val,0%));
  outline: none;
  cursor: pointer;
}
/* Pour MAJ live du gradient : on remet via JS si besoin. Fallback simple : */
.sit-slider { background: var(--border); position: relative; }
.sit-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--brand);
  border: 3px solid var(--card);
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  cursor: pointer;
}
.sit-slider::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--brand);
  border: 3px solid var(--card);
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  cursor: pointer;
}

/* Récap */
.sit-recap {
  background: var(--bg);
  border-radius: 14px;
  padding: 14px 14px 10px;
  margin-bottom: 14px;
}
.sit-recap-progress { margin-bottom: 14px; }
.sit-progress-track {
  position: relative;
  width: 100%; height: 10px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.sit-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand), var(--brand));
  transition: width .25s;
}
.sit-progress-label {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  color: var(--ink);
  opacity: .8;
}

.sit-recap-list {
  list-style: none;
  margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.sit-recap-list li {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px;
}
.sit-recap-list li span { opacity: .7; }
.sit-recap-list li b { font-variant-numeric: tabular-nums; }
.sit-recap-highlight {
  background: var(--brand-l);
  margin: 4px -10px;
  padding: 8px 10px;
  border-radius: 10px;
  font-weight: 600;
}
.sit-recap-highlight b { color: var(--brand); }
.sit-recap-total {
  border-top: 1px dashed var(--border);
  padding-top: 8px; margin-top: 4px;
  font-weight: 700; font-size: 14px;
}
.sit-recap-total b { color: var(--brand); font-size: 15px; }

/* Notes */
.sit-notes-wrap {
  display: block;
  margin-bottom: 16px;
}
.sit-notes-wrap span {
  display: block; font-size: 12px; opacity: .7; margin-bottom: 4px;
}
.sit-notes {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card); color: var(--ink);
  padding: 8px 10px;
  font-size: 13px;
  resize: vertical;
  font-family: inherit;
}
.sit-notes:focus { outline: none; border-color: var(--brand); }

/* Actions */
.sit-actions { display: flex; flex-direction: column; gap: 8px; }
.sit-actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sit-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px;
  padding: 13px 14px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: transform .1s, background .15s;
  font-family: inherit;
}
.sit-btn:active { transform: scale(.98); }
.sit-btn-primary {
  background: var(--brand); color: #fff;
}
.sit-btn-primary:hover { filter: brightness(1.05); }
.sit-btn-secondary {
  background: var(--card); color: var(--brand);
  border: 1.5px solid var(--brand);
}
.sit-btn-secondary:hover { background: var(--brand-l); }
.sit-btn-ghost {
  background: var(--bg); color: var(--ink);
}
.sit-btn-ghost:hover { background: var(--border); }
.sit-btn-link {
  background: transparent;
  color: var(--ink);
  opacity: .6;
  padding: 10px;
  font-weight: 500;
}
.sit-btn-link:hover { opacity: 1; }

/* ===== Vue suivi chantier (injectée dans openDetail) ================ */
.sit-suivi-wrap { padding: 0; }
.sit-suivi { padding: 16px; }
.sit-suivi-head { margin-bottom: 14px; }
.sit-suivi-head h3 { margin: 0; font-size: 18px; }
.sit-suivi-sub { margin-top: 3px; font-size: 13px; opacity: .7; }

.sit-suivi-progress { margin-bottom: 16px; }
.sit-suivi-progress .sit-progress-track { height: 12px; }

.sit-suivi-kpi {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 0 0 16px;
  padding: 0;
}
.sit-suivi-kpi li {
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.sit-suivi-kpi li span { font-size: 11px; opacity: .7; text-transform: uppercase; letter-spacing: .5px; }
.sit-suivi-kpi li b { font-size: 15px; font-variant-numeric: tabular-nums; }
.sit-kpi-solde {
  grid-column: 1 / -1;
  background: var(--brand-l) !important;
}
.sit-kpi-solde b { color: var(--brand); }

.sit-suivi-cta { margin-bottom: 18px; }
.sit-suivi-cta .sit-btn { width: 100%; }

.sit-suivi-tl-title { font-size: 14px; margin: 0 0 10px; opacity: .8; }

.sit-timeline {
  list-style: none; margin: 0; padding: 0 0 0 20px;
  position: relative;
}
.sit-timeline::before {
  content: '';
  position: absolute; top: 4px; bottom: 4px;
  left: 6px; width: 2px;
  background: var(--border);
}
.sit-timeline-item { position: relative; margin-bottom: 12px; }
.sit-timeline-dot {
  position: absolute; left: -20px; top: 8px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--brand);
  border: 3px solid var(--card);
  box-shadow: 0 0 0 2px var(--brand-l);
}
.sit-timeline-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}
.sit-timeline-row {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px;
}
.sit-timeline-meta { font-size: 12px; opacity: .7; }
.sit-timeline-amounts {
  display: flex; justify-content: space-between;
  margin-top: 6px; font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.sit-timeline-amounts b { color: var(--brand); }
.sit-timeline-actions { margin-top: 6px; }
.sit-link {
  background: transparent; border: 0; color: var(--brand);
  cursor: pointer; padding: 4px 0; font-size: 12px; font-weight: 600;
}
.sit-link:hover { text-decoration: underline; }

.sit-empty { opacity: .6; text-align: center; padding: 20px; font-size: 13px; }
.sit-loading { padding: 24px; text-align: center; opacity: .6; }

/* ===== Badges statut ================================================ */
.sit-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.sit-badge-brouillon { background: var(--border); color: var(--ink); opacity: .8; }
.sit-badge-envoyee   { background: var(--brand-l); color: var(--brand); }
.sit-badge-payee     { background: rgba(40,170,80,.15); color: #1f9a4a; }
.sit-badge-annulee   { background: rgba(200,60,60,.15); color: #c03030; text-decoration: line-through; }

/* Onglet suivi dans detail-overlay */
.sit-detail-tab::before { content: ''; margin: 0; }

/* ===== Pickers ====================================================== */
.sit-picker-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9998;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden;
  transition: opacity .2s, visibility .2s;
}
.sit-picker-backdrop.sit-on { opacity: 1; visibility: visible; }
.sit-picker-panel {
  width: 92%; max-width: 420px;
  background: var(--card);
  color: var(--ink);
  border-radius: 20px;
  padding: 22px 18px;
  max-height: 86vh; overflow-y: auto;
}
.sit-picker-panel h3 {
  margin: 0 0 14px;
  font-size: 16px;
  text-align: center;
}
.sit-picker-big {
  width: 100%;
  background: var(--brand); color: #fff;
  border: 0; border-radius: 14px;
  padding: 18px;
  font-size: 17px; font-weight: 700;
  margin-bottom: 10px;
  cursor: pointer;
}
.sit-picker-small {
  width: 100%;
  background: var(--card); color: var(--ink);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 13px; font-weight: 600;
  margin-bottom: 8px;
  cursor: pointer;
}
.sit-picker-small:hover { border-color: var(--brand); color: var(--brand); }
.sit-picker-cancel {
  width: 100%;
  background: transparent; color: var(--ink);
  border: 0; padding: 12px;
  opacity: .6; cursor: pointer;
  font-family: inherit;
}
.sit-picker-cancel:hover { opacity: 1; }

/* Liste devis sélecteur */
.sit-devis-list {
  list-style: none; margin: 0 0 12px; padding: 0;
  max-height: 50vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
}
.sit-devis-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
}
.sit-devis-item:hover { background: var(--brand-l); }
.sit-devis-sub { font-size: 12px; opacity: .7; margin-top: 2px; }
.sit-devis-amt { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ===== Dark mode tweaks (variables déjà gérées, mais quelques overrides) ===== */
html.dark .sit-sheet-panel { box-shadow: 0 -8px 24px rgba(0,0,0,.5); }
html.dark .sit-convert-btn { background: var(--card); }
html.dark .sit-badge-payee { background: rgba(40,170,80,.25); color: #4ecb78; }
html.dark .sit-badge-annulee { background: rgba(200,60,60,.25); color: #ff6060; }

/* ===== Récap situation dans le détail facture ======================= */
.sit-fact-recap {
  margin: 0 16px 12px;
  padding: 14px;
  background: var(--card);
  border: 1.5px solid var(--brand-m);
  border-left: 4px solid var(--brand);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.sit-fact-recap-head {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}
.sit-fact-recap-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--brand);
}
.sit-fact-recap-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.sit-fact-recap-sub b { color: var(--ink); }
.sit-fact-recap-progress { margin: 10px 0 12px; }
.sit-fact-recap .sit-recap-list { margin: 0; }
.sit-fact-recap-cta { margin-top: 12px; }
.sit-fact-recap-cta .sit-btn { width: 100%; }

/* ===== Panneau d'édition sur mesure (Modifier avant l'envoi) ======== */
.sit-edit-panel {
  margin: 12px 0 14px;
  padding: 14px;
  background: var(--card);
  border: 1.5px dashed var(--brand);
  border-radius: 14px;
  animation: sit-edit-slide .22s ease-out;
}
@keyframes sit-edit-slide {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.sit-edit-head {
  display: flex; flex-direction: column; gap: 2px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}
.sit-edit-head > span {
  font-size: 13px;
  font-weight: 700;
  color: var(--brand);
}
.sit-edit-head > small {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
  line-height: 1.4;
}
.sit-edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.sit-edit-field {
  display: flex; flex-direction: column; gap: 4px;
}
.sit-edit-field > span {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .3px;
}
.sit-edit-field input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
  -moz-appearance: textfield;
}
.sit-edit-field input::-webkit-outer-spin-button,
.sit-edit-field input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.sit-edit-field input:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--card);
  box-shadow: 0 0 0 3px var(--brand-l);
}

@media (max-width: 480px) {
  .sit-edit-grid { grid-template-columns: 1fr; }
}

/* ===== Email preview (Envoyer la situation) ========================= */
.sit-ep-panel { max-width: 560px; }
.sit-ep-form {
  display: flex; flex-direction: column; gap: 12px;
  margin-bottom: 16px;
}
.sit-ep-field { display: flex; flex-direction: column; gap: 4px; }
.sit-ep-field span {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--ink);
  opacity: .6;
}
.sit-ep-field input,
.sit-ep-field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
}
.sit-ep-field textarea {
  min-height: 160px;
  resize: vertical;
  line-height: 1.5;
}
.sit-ep-field input:focus,
.sit-ep-field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-l);
}
.sit-ep-pdf {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px;
  background: var(--brand-l);
  color: var(--brand);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
}
.sit-ep-pdf em {
  font-style: normal;
  opacity: .7;
  font-weight: 400;
  margin-left: 4px;
}

.sit-btn[disabled] {
  opacity: .55;
  cursor: not-allowed;
}

/* ===== Responsive ==================================================== */
@media (max-width: 480px) {
  .sit-sheet-panel { padding: 14px 14px 20px; }
  .sit-suivi-kpi { grid-template-columns: 1fr; }
  .sit-actions-row { grid-template-columns: 1fr; }
  .sit-ep-field textarea { min-height: 140px; }
}
