/* =========================================================
   Fiche de visite — Thème UI
   - Moderne, lisible, accessible
   - Brand en "accents" (actions / focus / selected)
   ========================================================= */

* { box-sizing: border-box; }
html { 
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

:root{
  /* Layout */
  --container: 980px;
  --radius-card: 16px;
  --radius-field: 14px;
  --radius-chip: 16px;

  /* Brand (F1R) */
  --brand: #bf3f58; /* Rose plus dense */
  --brand-2: #D47D8A;
  --brand-ink: #8F2740;

  /* Neutrals */
  --bg: #f5f6f8;
  --card: #ffffff;
  --surface-1: #ffffff; /* Cards, inputs, thumbs */
  --surface-2: #f0f0f5; /* Control backgrounds */
  --text: rgba(0,0,0,.86);
  --muted: rgba(0,0,0,.62);
  --stroke: rgba(0,0,0,.1); /* Bordure plus discrète */
  --shadow: 0 10px 30px rgba(0,0,0,.08);

  /* States */
  --danger: #d7263d; 
  --focus: rgba(199,77,104,.22);

  /* Chips */
  --chip-bg: rgba(0,0,0,.02);
  --chip-border: rgba(0,0,0,.12);
  --chip-bg-on: rgba(199,77,104,.10);
  --chip-border-on: rgba(199,77,104,.45);
  
  /* Fields */
  --field-font-size: 15px;
  --field-line-height: 1.2;
}

body{
  margin: 0;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;              /* anti-zoom iPhone */
  line-height: 1.35;
  background: var(--bg);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
}

/* Impression : tout afficher */
@media print {
  body.print-all .page { display: block !important; }
}

/* =========================================================
   Core Layout & Pages (CRITICAL)
   ========================================================= */
.container{
  max-width: var(--container);
  margin: 0 auto; 
  padding: 14px 14px calc(80px + env(safe-area-inset-bottom)) 14px; /* Espace pour la bottom nav */
}

/* Gestion des Pages (A, B, C, D) */
.page { display: none !important; }
.page.active { display: block !important; animation: fadeIn 0.3s ease; }

/* Gestion des Sous-chapitres (Onglets Extérieurs, Toiture...) */
.sub-chapter { display: none !important; }
.sub-chapter.active { display: block !important; animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-header {
  display: none; /* Neutralisé comme demandé */
}

/* =========================================================
   Layout
   ========================================================= */
.card{
  background: var(--card);
  border: none;
  border-radius: var(--radius-card);
  padding: 14px;
  box-shadow: 0 10px 28px rgba(0,0,0,.06);
  margin: 12px 0;
}

/* Carte Assistant IA */
.card-ai {
  background: linear-gradient(180deg, #ffffff 0%, #fff5f7 100%);
  border: 1px solid rgba(191, 63, 88, 0.2);
}

.sub-chapter h4 {
  margin: 24px 0 10px;
  font-size: 15px;
  font-weight: 800;
}

.sub-group + .sub-group {
  margin-top: 28px; /* Use spacing for hierarchy */
  padding-top: 0;
  border-top: none; /* Remove visual divider */
}

.sub-group > * + * {
  margin-top: 10px;
}

/* =========================================================
   App Chrome (Main UI Shell)
   ========================================================= */
.topbar{
  position: sticky;
  top: 0;
  z-index: 50;
  background: #ffffff;
  padding: 8px 16px 8px 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* On supprime la ligne colorée */
.topbar::after{
  display: none;
}

.topbar-left {
  flex: 1;
  min-width: 0; /* Permet au text-overflow de fonctionner dans un flex item */
}

.header-main-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: var(--container);
  margin: 0;
}

.header-line2-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
  position: relative;
}

/* Bouton sélecteur de page (C — Constat ▾) */
.header-page-btn {
  background: #f2f2f7; /* Gris clair pill */
  border: none;
  padding: 6px 12px;
  border-radius: 20px;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.2s;
}
.header-page-btn:active { background: #e5e5ea; opacity: 1; }

.header-arrow {
  font-size: 10px;
  color: var(--muted);
  transform: translateY(-1px);
  transition: transform 0.2s ease;
}

.header-page-btn.open .header-arrow {
  transform: translateY(-1px) rotate(180deg);
}

/* Bouton Actions (Kebab) */
.btn-icon-header {
  background: none;
  border: none;
  padding: 8px;
  margin-right: -8px; /* Alignement optique à droite */
  color: var(--text);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon-header:active { background: rgba(0,0,0,0.05); }

.btn-help {
  background: none;
  border: none;
  padding: 4px;
  color: var(--muted);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  position: relative;
  z-index: 1;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}
.btn-help:active {
  background: rgba(0,0,0,0.05);
}
.btn-help svg {
  pointer-events: none;
}

.subnav-sticky {
  position: fixed;
  bottom: calc(12px + env(safe-area-inset-bottom));
  left: 50%;
  z-index: 88;
  
  height: 60px;
  background: #FFFFFF;
  border: 1px solid rgba(0,0,0,.05);
  box-shadow: 0 10px 30px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.08);
  border-radius: 18px;
  padding: 0 8px;
  margin: 0;
  max-width: calc(100vw - 24px);
  
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  overflow-x: auto;
  white-space: nowrap;

  transform: translateX(-50%) translateY(150%);
  transition: transform 0.3s ease-in-out;

  /* Cache la scrollbar */
  -ms-overflow-style: none; 
  scrollbar-width: none; 
}
.subnav-sticky::-webkit-scrollbar { display: none; }

.sec-c-active .subnav-sticky {
  transform: translateX(-50%) translateY(0);
}

/* Espace entre les "lignes" de contrôles */
.page-body > * + *{
  margin-top: 14px;
}

/* Resserre les couples "label -> contrôle" */
.page-body > .label + .chips,
.page-body > .label + .grid2,
.page-body > .label + .grid3,
.page-body > label + input,
.page-body > label + select,
.page-body > label + textarea,
.page-body > .field > .date-wrap {
  margin-top: 6px;
}

/* Confort de scroll lors des sauts de section */
#secA, #secB, #secC, #secD {
  scroll-margin-top: 70px; /* hauteur de la topbar + marge */
}

/* =========================================================
   Utilities
   ========================================================= */
.hidden{ display: none !important; }
.muted{ color: var(--muted); }

h3{
  margin: 12px 0 6px;
  font-size: 14px;
  font-weight: 900;
}

.card h2{
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: .1px;
}

.save-status{
  position: fixed;
  left: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 80;
  font-size: 12px;
  font-weight: 800;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,.12);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 25px rgba(0,0,0,.12);
}

.save-status.dirty{ border-color: rgba(185, 20, 41, .30); }
.save-status.saving{ border-color: rgba(199,77,104,.35); opacity: .96; }

/* =========================================================
   Forms (typo unified)
   - <label> = libellé de champ
   - .label = titre de bloc (chips / groupes)
   ========================================================= */
label{
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.label{
  font-size: 12.5px; /* Plus petit et discret */
  color: var(--muted); /* Plus gris */
  font-weight: 500; /* Normal */
  margin-bottom: 6px;
}

/* Ligne de titre avec valeur dynamique à droite */
.label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.label-row .label { margin-bottom: 0; }
.label-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted); /* Plus discret */
  transition: opacity 0.2s ease;
}

input, select, textarea{
  width: 100%;
  margin-top: 6px;
  padding: 12px 12px;
  border-radius: var(--radius-field);
  border: 1px solid var(--stroke);
  background: var(--surface-1);
  color: var(--text);
  font-size: var(--field-font-size);
  line-height: var(--field-line-height);
  min-height: 44px;
  font-family: inherit;
  /* Re-enable selection for inputs */
  -webkit-user-select: text;
  user-select: text;
}

/* Placeholder */
input::placeholder,
textarea::placeholder{
  color: rgba(0,0,0,.45);
  opacity: 1; /* Safari fix */
  font-size: var(--field-font-size);
  line-height: var(--field-line-height);
}


textarea{ min-height: 110px; }

/* Focus: cohérent marque + accessible */
input:focus, select:focus, textarea:focus{
  outline: none;
  border-color: rgba(199,77,104,.60);
  box-shadow: 0 0 0 3px var(--focus);
}

/* =========================================================
   Components
   ========================================================= */

/* =========================================================
   Help Accordion (Note block repliable)
   ========================================================= */
.help-accordion {
  background: rgba(0,0,0,.02);
  border-radius: 12px;
  margin-bottom: 14px;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,.06);
}

.help-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
}

.help-summary:active { background: rgba(0,0,0,.03); }

.help-icon {
  transition: transform 0.2s ease;
  opacity: 0.6;
}

.help-accordion[open] .help-icon { transform: rotate(180deg); }

.help-content {
  padding: 0 14px 14px 14px;
  font-size: 13px;
  color: var(--muted);
}

/* =========================================================
   Grids
   ========================================================= */
.grid2{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.grid3{
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.btn{
  appearance: none;
  border: 1px solid rgba(0,0,0,.06);
  background: linear-gradient(180deg, var(--brand), var(--brand-ink));
  color: #fff;
  padding: 12px 14px;
  border-radius: 12px;
  font-weight: 900;
  font-size: 14px;
  cursor: pointer;
  min-height: 44px;
  box-shadow: 0 10px 25px rgba(199,77,104,.18);
}

.btn:hover{ filter: brightness(.98); }
.btn:active{ transform: translateY(1px); }

.btn-secondary{
  background: #fff;
  border: 1px solid var(--stroke);
  color: var(--text);
  box-shadow: none;
  font-weight: 800;
}

.btn-secondary:hover{ background: rgba(0,0,0,.03); }
.btn-mini{
  padding: 8px 10px;
  min-height: 36px;
  border-radius: 10px;
  font-size: 13px;
}

.btn.btn-icon{
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

.btn-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.btn-pill .icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
  pointer-events: none;
}

.btn-pill-label {
  pointer-events: none;
}

.btn-pill.active {
  color: var(--brand);
}

.btn-pill:active {
  background-color: rgba(0,0,0,0.05);
}

/* Indicateurs d'état */
.btn-pill::after {
  content: '';
  position: absolute;
  top: 6px;
  right: calc(50% - 22px);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: transparent;
  transform: scale(0);
  transition: all .2s ease-in-out;
  
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  font-weight: 900;
}
.btn-pill.status-empty::after {
  transform: scale(0);
}
.btn-pill.status-in-progress::after {
  content: '';
  background-color: #aeaeb2; /* Gris neutre */
  width: 6px;
  height: 6px;
  transform: scale(1);
}
.btn-pill.status-completed::after {
  content: '✓';
  color: rgba(0,0,0,0.35); /* Neutre */
  transform: scale(1);
  width: auto;
  height: auto;
}

.btn-pill.active.status-completed::after {
  color: var(--brand);
}

/* =========================================================
   Popovers & Bottom Sheets
   ========================================================= */

/* Menus Popover */
.popover-menu {
  position: absolute;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid rgba(0,0,0,.1);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.15);
  min-width: 200px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 100;
}
.popover-menu[hidden] { display: none; }

.menu-left { left: 12px; }
.menu-right { right: 12px; }

.popover-menu button {
  background: none;
  border: none;
  text-align: left;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  border-bottom: 1px solid rgba(0,0,0,.05);
  cursor: pointer;
}
.popover-menu button:last-child { border-bottom: none; }
.popover-menu button:active { background: rgba(0,0,0,.03); }
.popover-menu button.active { color: var(--brand); font-weight: 700; }

.popover-sep {
  height: 1px;
  background: rgba(0,0,0,.08);
  margin: 6px 0;
}

/* Bottom Sheet (Photo Source) */
#sheetPhotoSource {
  position: fixed;
  top: auto;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  min-width: 0;
  border-radius: 24px 24px 0 0;
  border: none;
  box-shadow: 0 -10px 40px rgba(0,0,0,0.12);
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  animation: sheetSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  
  /* iOS style additions */
  max-height: 60vh;
  overflow-y: auto;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overscroll-behavior: contain;
}

#sheetPhotoSource[hidden] { display: none !important; }

/* Grabber (barre de manipulation) */

/* Items du bottom sheet (overrides) */
#sheetPhotoSource button {
  border-bottom: none;
  padding: 14px 24px;
  font-size: 17px;
  font-weight: 500;
  margin: 2px 12px;
  border-radius: 12px;
  width: auto;
}

#sheetPhotoSource button:active {
  background-color: #f2f2f7;
}

#sheetPhotoSource button.active {
  background-color: rgba(191, 63, 88, 0.08);
  color: var(--brand);
}

@keyframes sheetSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes sheetSlideDown {
  from { transform: translateY(0); }
  to { transform: translateY(100%); }
}

#sheetPhotoSource.closing {
  animation: sheetSlideDown 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Backdrop (fond sombre) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90; /* Sous le menu (100) mais au-dessus du reste */
  animation: fadeIn 0.2s ease;
}

/* --- iOS Bottom Sheet (Exemples) --- */
.help-sheet-wrapper {
  position: fixed;
  inset: 0;
  z-index: 2000;
  visibility: hidden;
  transition: visibility 0.3s;
}
.help-sheet-wrapper.active {
  visibility: visible;
}

.help-sheet-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  opacity: 0;
  transition: opacity 0.3s;
}
.help-sheet-wrapper.active .help-sheet-overlay {
  opacity: 1;
}

.examples-sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: min(calc(100vw - 32px), 560px);
  max-height: min(70vh, 520px);
  background: #fff;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
  padding: 16px 18px;
  transform: translate(-50%, 100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sheet-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  
  width: 44px; /* Zone tappable confortable */
  height: 44px;
  
  display: flex;
  align-items: center;
  justify-content: center;
  
  background: transparent; /* Ghost style */
  padding: 0;
  border: none;
  border-radius: 999px;
  
  color: #8E8E93; /* Gris iOS standard */
  cursor: pointer;
  
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s ease;
}
.sheet-close-btn:active {
  background: rgba(0,0,0,0.06);
  color: #8E8E93;
}
.sheet-close-btn svg {
  width: 20px;
  height: 20px;
}
.help-sheet-wrapper.active .examples-sheet {
  transform: translate(-50%, 0);
}

.sheet-drag-handle {
  width: 100%;
  padding: 10px 0; /* Zone tactile confortable */
  display: flex;
  justify-content: center;
  touch-action: none; /* Important pour le drag JS */
  cursor: grab;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: #e5e5ea;
  border-radius: 2px;
  margin: 0;
  flex-shrink: 0;
}

.sheet-scroll-content {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 20px;
}

.sheet-header-content {
  padding: 0 18px 8px 18px; /* Réduction padding bas pour plus d'espace photo */
  flex-shrink: 0;
  min-height: 46px; /* Hauteur minimale pour éviter les sauts */
}

/* Cohérence typo stricte avec .sub-chapter h4 */
.sheet-title {
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 4px;
  color: var(--text);
}
/* Cohérence typo stricte avec .label */
.sheet-subtitle {
  font-size: 12.5px; /* Plus petit et discret */
  color: var(--muted); /* Plus gris */
  font-weight: 500;
  margin-bottom: 6px;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sheet-subtitle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sheet-selection-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--brand);
}

/* --- Help Visual Grid --- */
.help-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
  padding-bottom: 8px;
  /* iOS protections */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.help-thumb.selected {
  border-color: var(--brand);
  background: rgba(191, 63, 88, 0.08);
}
.help-img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  background: #eee;
  margin-bottom: 6px;
}
.help-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  padding: 0 4px;
}
.help-thumb.selected .help-label {
  font-weight: 600;
  color: #000;
}

/* Wrapper pour positionner les flèches */
.carousel-wrapper {
  position: relative;
  flex: 1; /* Prend l'espace restant */
  display: flex;
  flex-direction: column; /* Important pour que le scroll content prenne la hauteur */
  min-height: 0; /* Fix flexbox overflow */
}

/* --- Help Carousel (for Dégradations) --- */
.help-carousel {
  display: flex;
  overflow-x: auto;
  touch-action: pan-x pan-y; /* Permet le scroll natif fluide */
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0 44px; /* Espace pour les flèches latérales */
  height: clamp(220px, 42vh, 360px); /* Hauteur explicite pour redonner de la place */
}
.help-carousel::-webkit-scrollbar { display: none; }

.carousel-slide {
  flex: 0 0 100%;
  scroll-snap-align: center;
  padding: 0 10px; /* Espacement entre slides réduit */
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.carousel-slide-content {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(0,0,0,0.05); /* Fond plus discret pour les placeholders */
  /* aspect-ratio: 4 / 3; Supprimé pour laisser flex-grow agir */
  height: 100%; /* Force la hauteur à 100% du conteneur parent */
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.2s ease;
}
.carousel-slide-content:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: none;
}

.carousel-slide-content.is-selected {
  border-color: var(--brand);
}

.carousel-slide-content .slide-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
}

.carousel-slide-content .slide-img-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f0f5;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 10px;
  z-index: 2;
}

.carousel-slide-content .slide-gradient {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60%;
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
  z-index: 3;
  pointer-events: none;
}

.carousel-slide-content .slide-checkmark {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  background: rgba(255,255,255,0.9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  transform: scale(0);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.carousel-slide-content.is-selected .slide-checkmark {
  transform: scale(1);
}
.carousel-slide-content .slide-checkmark svg {
  width: 20px;
  height: 20px;
  color: var(--brand);
}

.help-carousel-counter {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}

.carousel-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.6);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 999px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.carousel-nav-btn:active {
  transform: translateY(-50%) scale(0.95);
  background: rgba(0,0,0,0.05);
  color: var(--text);
}
.carousel-nav-btn svg {
  width: 20px;
  height: 20px;
}
.carousel-nav-btn.prev {
  left: 0; /* Collé au bord gauche du wrapper */
}
.carousel-nav-btn.next {
  right: 0; /* Collé au bord droit du wrapper */
}

/* =========================================================
   Chips (multi-select)
   ========================================================= */

.chips{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-text-action {
  /* Secondary action text link */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 0 12px;
  
  background: transparent;
  border: 1px dashed var(--stroke);
  border-radius: var(--radius-chip);
  
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-text-action:active {
  background: rgba(191, 63, 88, 0.05);
  border-color: var(--brand);
  color: var(--brand);
  opacity: 1;
}

.autre-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  
  background: rgba(191, 63, 88, 0.08);
  border: 1px solid var(--brand);
  border-radius: var(--radius-chip);
  
  padding: 0 16px;
  min-height: 52px;
  
  color: #000;
  font-weight: 600;
  box-shadow: none;
}
.autre-edit-btn {
  position: static;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-decoration: underline;
  cursor: pointer;
  padding: 8px;
  margin-left: auto;
}
.autre-edit-btn:active { color: var(--brand); }

.chip{
  touch-action: manipulation;
  width: 100%;
  border-radius: var(--radius-chip);
  padding: 9px 11px;
  box-shadow: none;
  
  border: 1px solid var(--chip-border);
  background: var(--surface-1);
  color: #888888;
  font-weight: 500;

  display: grid;
  place-items: center;
  text-align: center;
  user-select: none;

  line-height: 1.25; /* Améliore lisibilité multi-lignes */
  min-height: 52px; /* Hauteur unifiée */
  transition: background-color 120ms ease, border-color 120ms ease, transform 120ms ease;
  will-change: background-color, border-color, box-shadow, transform;
}

/* Petit "snap" au tap */
.chip:active{
  transform: scale(0.98);
}

/* Radio et Checkbox dans les chips : masqués + centrage (sélection par style de la carte uniquement) */
.chip input[type="radio"],
.chip input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}

/* Focus visible sur la chip, pas la checkbox interne */
/* On n'affiche l'indicateur de focus que pour la navigation clavier (:focus-visible),
   et non pour les clics souris/doigt.
   :has() est utilisé car le focus est sur l'input *dans* la chip. */
.chip:has(input:focus-visible) {
  border-color: rgba(199,77,104,.60);
  box-shadow: 0 0 0 3px var(--focus);
}

/* --- Style de sélection par type --- */

/* 1. Style de sélection unifié (rose) */
.chip:has(input:checked),
.chip.is-checked {
  background: var(--brand);
  color: #ffffff;
  border-color: var(--brand);
  font-weight: 600;
}

/* 2. Tags de dégradation (plus compacts) */
.chips-degradations {
  /* Force 2 columns everywhere (mobile & desktop) for symmetry */
  grid-template-columns: 1fr 1fr !important;
}

.chips-degradations .chip {
  min-height: 44px; /* Smaller height for tags */
  padding: 4px 10px;
  font-size: 13px;
  line-height: 1.3;
}

/* Pour une grille symétrique, le dernier élément impair prend toute la largeur */
.chips-degradations .chip:last-child:nth-child(odd) {
  grid-column: span 2;
}

/* 3. Chip "Action" (+ Autre) : style "secondary action" */
.chip--action {
  /* Ghost style when not checked */
  background: transparent;
  border: 1px dashed var(--stroke);
  color: var(--muted); /* Texte gris */
  font-weight: 500;
}
.chip--action:has(input:checked),
.chip--action.is-checked {
  /* Sélectionné : devient une chip normale */
  background: var(--brand);
  color: #ffffff;
  border-color: var(--brand);
  font-weight: 600;
  border-style: solid;
}
.chip--action:active { color: var(--brand); background: var(--chip-bg-on); }

/* =========================================================
   Segmented Control (iOS style)
   ========================= */
.segmented-control {
  --seg-padding: 4px; /* Padding interne confortable */

  position: relative;
  display: flex;
  align-items: stretch;
  width: 100%; 
  background: var(--surface-2); /* Fond gris clair */
  padding: var(--seg-padding);
  border: 1px solid rgba(0,0,0,0.08); /* Bordure fine */
  margin-top: 6px;
  isolation: isolate; /* Crée un contexte d'empilement */
  -webkit-tap-highlight-color: transparent;
}

/* --- SIZES --- */
/* Large (pour "État") - Default */
.segmented-control--lg,
.segmented-control:not(.segmented-control--sm) {
  height: 52px; /* Hauteur unifiée */
  border-radius: 18px;
}
.segmented-control--lg label,
.segmented-control:not(.segmented-control--sm) label {
  font-size: 13px;
  border-radius: 14px;
}
.segmented-control--lg .segmented-thumb,
.segmented-control:not(.segmented-control--sm) .segmented-thumb {
  border-radius: 14px;
}

/* Small (pour "Variante") */
.segmented-control--sm {
  --seg-padding: 3px;
  height: 44px; /* Plus compact que "État" */
  border-radius: 14px;
}
.segmented-control--sm label {
  font-size: 12px; /* Texte un peu plus petit */
  border-radius: 11px;
}
.segmented-control--sm .segmented-thumb {
  border-radius: 11px;
}

.modal{ display: none; }
.modal.open{ display: block; }

.modal-backdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 999;
}

.modal-panel{
  position: fixed;
  left: 50%;
  top: 64px;
  transform: translateX(-50%);
  width: min(var(--container), calc(100vw - 24px));
  max-height: calc(100vh - 96px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-card);
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
  z-index: 1000;
}

.modal-header{
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 10px 14px;
  border-bottom: 1px solid var(--stroke);
}

.modal-title{ font-weight: 900; }
.modal-subtitle{ color: var(--muted); font-size: 13px; margin-top: 4px; }
.modal-body{ padding: 14px; }

.visits-list{
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.visit-row{
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}

.visit-title{ font-weight: 800; }
.visit-sub{ color: var(--muted); font-size: 12px; margin-top: 4px; }
.visit-actions{
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* --- SHARED COMPONENTS --- */
/* Inputs radios cachés mais accessibles */
.segmented-control input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}

/* Le "Thumb" (pastille glissante) */
.segmented-thumb {
  position: absolute;
  top: var(--seg-padding);
  bottom: var(--seg-padding);
  left: var(--seg-padding);
  background: var(--brand);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  border: 1px solid var(--brand);
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.2s ease;
  z-index: 1;
  pointer-events: none;
}

/* Labels (Textes) */
.segmented-control label {
  flex: 1;
  z-index: 2; /* Au-dessus du thumb */
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 500; /* Poids normal pour inactif */
  color: #888888;
  cursor: pointer;
  user-select: none;
  transition: color 0.2s ease;
  padding: 0 4px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* --- STATES & INTERACTIONS --- */
.segmented-control:active .segmented-thumb {
  /* Pas de flash gris, juste une micro-interaction sur le thumb */
}

/* Changement de couleur du texte actif */
.segmented-control input:checked + label {
  color: #ffffff;
  font-weight: 600;
}

/* --- COLUMNS & POSITIONING --- */
.segmented-control--cols-2 .segmented-thumb { width: calc((100% - (var(--seg-padding) * 2)) / 2); }
.segmented-control--cols-4 .segmented-thumb { width: calc((100% - (var(--seg-padding) * 2)) / 4); }

.segmented-control--cols-2 input:nth-of-type(1):checked ~ .segmented-thumb { transform: translateX(0%); }
.segmented-control--cols-2 input:nth-of-type(2):checked ~ .segmented-thumb { transform: translateX(100%); }

.segmented-control--cols-4 input:nth-of-type(1):checked ~ .segmented-thumb { transform: translateX(0%); }
.segmented-control--cols-4 input:nth-of-type(2):checked ~ .segmented-thumb { transform: translateX(100%); }
.segmented-control--cols-4 input:nth-of-type(3):checked ~ .segmented-thumb { transform: translateX(200%); }
.segmented-control--cols-4 input:nth-of-type(4):checked ~ .segmented-thumb { transform: translateX(300%); }

/* =========================================================
   Champ Date (custom)
   ========================================================= */
.field{ display:block; }

.field-date .date-wrap{
  position: relative;
  width: 100%;
  cursor: pointer;
}

/* Input date : même look que vos inputs */
.field-date .date-wrap input[type="date"]{
  width: 100%;
  display: block;
  cursor: pointer;
  padding-right: 40px;

  /* Couleur du texte quand une date est choisie */
  color: rgba(0,0,0,.72);
  -webkit-text-fill-color: rgba(0,0,0,.72);

  -webkit-appearance: none;
  appearance: none;
}

/* Cache l’icône native mais garde la zone cliquable */
.field-date .date-wrap input[type="date"]::-webkit-calendar-picker-indicator{
  opacity: 0;
  position: absolute;
  right: 0;
  top: 0;
  width: 44px;
  height: 100%;
  cursor: pointer;
}

/* Icône calendrier décorative */
.field-date .date-wrap::after{
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  opacity: .55;
  pointer-events: none;

  background: rgba(0,0,0,.72);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 2a1 1 0 0 1 1 1v1h8V3a1 1 0 1 1 2 0v1h1.5A2.5 2.5 0 0 1 22 6.5v13A2.5 2.5 0 0 1 19.5 22h-15A2.5 2.5 0 0 1 2 19.5v-13A2.5 2.5 0 0 1 4.5 4H6V3a1 1 0 0 1 1-1Zm12.5 6h-15V19.5c0 .276.224.5.5.5h15a.5.5 0 0 0 .5-.5V8Z'/%3E%3C/svg%3E") no-repeat center / contain;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 2a1 1 0 0 1 1 1v1h8V3a1 1 0 1 1 2 0v1h1.5A2.5 2.5 0 0 1 22 6.5v13A2.5 2.5 0 0 1 19.5 22h-15A2.5 2.5 0 0 1 2 19.5v-13A2.5 2.5 0 0 1 4.5 4H6V3a1 1 0 0 1 1-1Zm12.5 6h-15V19.5c0 .276.224.5.5.5h15a.5.5 0 0 0 .5-.5V8Z'/%3E%3C/svg%3E") no-repeat center / contain;
}

/* Placeholder simulé */
.field-date .date-ph{
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(0,0,0,.45);
  pointer-events: none; /* non cliquable */
  font: inherit;
  opacity: 1;
}

/* Sans valeur: on masque le texte interne du date pour éviter le double rendu */
.field-date .date-wrap:not(.has-value) input[type="date"]{
  color: transparent !important;
  -webkit-text-fill-color: transparent !important;
}

/* Avec valeur: on masque le placeholder */
.field-date .date-wrap.has-value .date-ph{
  opacity: 0;
}

/* =========================================================
   Module Photos (Filmstrip)
   ========================================================= */
.photo-strip-wrapper {
  margin-top: 16px;
  margin-bottom: 8px;
  padding: 8px 0; /* Adds vertical safe zone */
}

.photo-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.photo-count {
  color: var(--muted);
  font-weight: 500;
}

.photo-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch; /* Inertie iOS */
  scrollbar-width: none; /* Firefox */
}
.photo-strip::-webkit-scrollbar { display: none; }

.photo-item {
  flex: 0 0 80px;
  width: 80px;
  height: 80px;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.08);
}

/* Specific override for the add button's container to allow hit-area expansion */
.photo-item--add {
  overflow: visible;
}

/* Bouton Ajouter (+ Caméra) */
.photo-add-btn {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.02);
  border: 1px dashed var(--stroke);
  color: var(--brand);
  cursor: pointer;
  border-radius: 12px;
  padding: 0;
  transition: background-color 0.1s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  position: relative; /* For the ::before pseudo-element */
}

/* Invisible hit area expansion */
.photo-add-btn::before {
  content: "";
  position: absolute;
  inset: -12px; /* Expands the tappable area by 12px on all sides */
}
.photo-add-btn:active {
  background: rgba(191, 63, 88, 0.05);
  transform: scale(0.98);
}

.photo-add-btn svg {
  width: 32px; /* Larger icon for larger button */
  height: 32px;
  stroke-width: 2.5;
  pointer-events: none; /* Ensures click goes to the button */
}

/* Miniature */
.photo-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}

/* Viewer Plein Écran */
.photo-viewer {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.2s ease;
}
.photo-viewer[hidden] { display: none; }

.photo-viewer img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
}

/* --- Global Gallery (Section D) --- */
.gallery-group {
  margin-bottom: 24px;
}
.gallery-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--brand);
  margin: 0 0 12px 0;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  padding-bottom: 4px;
}
.gallery-subsection {
  margin-bottom: 16px;
}
.gallery-subtitle {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}
.gallery-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.viewer-actions {
  position: absolute;
  bottom: 40px;
  display: flex;
  gap: 20px;
}
.viewer-btn {
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  backdrop-filter: blur(10px);
  padding: 10px 20px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.viewer-btn.danger { background: rgba(185, 20, 41, 0.6); border-color: transparent; }

/* =========================================================
   Utilities
   ========================================================= */
.hidden{ display: none !important; }
.muted{ color: var(--muted); }

/* =========================================================
   Responsive Adjustments (Mobile-only tweaks)
   ========================================================= */

/* Rétablit l'affichage des labels courts sur mobile */
@media (max-width: 420px) {
  .segmented-control--lg .label-long { display: none; }
  .segmented-control--lg .label-short { display: inline; font-size: 16px; font-weight: 600; }
}

@media (max-width: 720px){
  .grid2{ grid-template-columns: 1fr; }
  .grid3{ grid-template-columns: 1fr; }
}

@media (min-width: 900px){
  /* On desktop, standard chips can expand to 4 columns */
  .chips:not(.chips-material) { grid-template-columns: repeat(4, 1fr); }
}

.ai-result-block {
  min-height: 160px;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 14px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  background: var(--surface-1);
  white-space: pre-wrap;
}
.ai-result-empty {
  color: #aaa;
  font-size: 13px;
  margin: 0;
}
