/* ============================================================
   Inspection Toiture — styles
   Palette: fond clair, accent rouille/sécurité, vert ardoise
   ============================================================ */

:root {
  --bg: #F7F8F6;
  --surface: #FFFFFF;
  --surface-sunken: #EFF2EE;
  --ink: #1A1F1C;
  --ink-soft: #55605A;
  --ink-faint: #8A948E;
  --line: #DCE1DA;
  --line-strong: #B7C0B9;

  --slate: #2E4034;
  --slate-dark: #202D25;
  --rust: #C6551F;
  --rust-dark: #A8440F;
  --rust-tint: #FBEBE0;

  --ok: #3C7A4E;
  --warn: #C6551F;
  --danger: #B3261E;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(26,31,22,0.06), 0 4px 12px rgba(26,31,22,0.06);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  font-size: 17px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
  height: 100%;
}

#app { min-height: 100dvh; display: flex; flex-direction: column; }

button, input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ---------- Layout shells ---------- */

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.topbar {
  background: var(--slate);
  color: white;
  padding: calc(14px + var(--safe-top)) 18px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.topbar-eyebrow {
  display: block;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.68);
  margin-bottom: 2px;
  font-weight: 500;
}

.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1, .topbar-title .topbar-eyebrow {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-back { padding-left: 8px; }

.btn-icon {
  background: rgba(255,255,255,0.12);
  border: none;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}
.btn-icon:active { background: rgba(255,255,255,0.22); }
.btn-icon-danger { background: rgba(179,38,30,0.35); margin-left: auto; }
.btn-icon-danger:active { background: rgba(179,38,30,0.5); }

.icon { width: 26px; height: 26px; display: block; }

/* ---------- Home ---------- */

.home-body {
  padding: 22px 18px 40px;
  display: flex;
  flex-direction: column;
  gap: 30px;
  flex: 1;
}

.home-section h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin: 0 0 12px;
}

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

.draft-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

.draft-card-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.draft-card-info strong { font-size: 1rem; }
.draft-card-info span { font-size: 0.85rem; color: var(--ink-faint); }

.status-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  margin-top: 3px;
}
.status-sent { background: #E3F1E6; color: var(--ok); }
.status-pending { background: var(--rust-tint); color: var(--rust-dark); }

.draft-card-arrow { color: var(--ink-faint); flex-shrink: 0; margin-left: 12px; }

.empty-note { color: var(--ink-faint); font-size: 0.92rem; margin: 0; }

/* ---------- Buttons ---------- */

.btn-primary, .btn-secondary {
  border: none;
  border-radius: var(--radius);
  padding: 16px 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  text-decoration: none;
}

.btn-primary {
  background: var(--rust);
  color: white;
  box-shadow: 0 2px 0 var(--rust-dark);
}
.btn-primary:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--rust-dark); }
.btn-primary:disabled { background: var(--line-strong); box-shadow: none; color: var(--ink-faint); }

.btn-secondary {
  background: var(--surface);
  color: var(--slate);
  border: 1.5px solid var(--line-strong);
}
.btn-secondary:active { background: var(--surface-sunken); }
.btn-secondary:disabled { color: var(--ink-faint); border-color: var(--line); }

.btn-huge { padding: 22px 20px; font-size: 1.08rem; border-radius: 16px; }

.btn-tertiary {
  border: none;
  border-radius: var(--radius);
  padding: 16px 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  text-decoration: none;
  background: var(--slate);
  color: white;
  box-shadow: 0 2px 0 var(--slate-dark);
  margin-top: 4px;
}
.btn-tertiary:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--slate-dark); }
.btn-large { font-size: 1rem; }

.btn-link { display: block; text-align: center; }

.badge {
  background: rgba(255,255,255,0.25);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 0.85rem;
  margin-left: 4px;
}
.btn-secondary .badge { background: var(--rust-tint); color: var(--rust-dark); }

/* ---------- Forms ---------- */

.form-body {
  padding: 22px 18px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex: 1;
}

.field { display: flex; flex-direction: column; gap: 6px; position: relative; }
.field-block { display: flex; flex-direction: column; gap: 10px; }
.field-row { display: flex; flex-wrap: wrap; gap: 12px; }
.field-row .field { flex: 1 1 140px; min-width: 0; }

.field-label {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.field-label-sub { font-weight: 500; color: var(--ink-faint); }

.field-input {
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 1rem;
  width: 100%;
}
.field-input:focus { outline: none; border-color: var(--rust); }
.field-input-lg { font-size: 1.3rem; font-weight: 700; text-align: center; }

.field-textarea { min-height: 110px; resize: vertical; }

.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  margin-top: 4px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: var(--shadow);
  display: none;
}
.suggestions.open { display: block; }
.suggestion-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:active { background: var(--surface-sunken); }

.segmented {
  display: flex;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.segmented-btn {
  flex: 1;
  background: var(--surface);
  border: none;
  padding: 13px 10px;
  font-weight: 600;
  color: var(--ink-soft);
  border-left: 1.5px solid var(--line-strong);
}
.segmented-btn:first-child { border-left: none; }
.segmented-btn.active { background: var(--slate); color: white; }

/* ---------- Checklist ---------- */

.checklist-body {
  padding: 18px 18px 140px;
  flex: 1;
  overflow-y: auto;
}

.checklist-section {
  margin-bottom: 24px;
}
.checklist-section h3 {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--slate);
  text-transform: none;
  margin: 0 0 10px;
  padding-bottom: 6px;
  border-bottom: 1.5px solid var(--line);
}

.checklist-columns-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0 10px;
  border-bottom: 1.5px solid var(--line-strong);
  margin-bottom: 4px;
}
.checklist-columns-header .spacer { flex: 1; }
.checklist-columns-header .col-label {
  width: 40px;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-soft);
  line-height: 1.15;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 10px;
  margin: 0 -10px;
  border-radius: 8px;
}
.check-row:nth-child(even) { background: var(--surface-sunken); }

.check-label { flex: 1; font-size: 0.95rem; }

.check-box-group { display: flex; gap: 12px; flex-shrink: 0; }
.check-box {
  width: 44px;
  height: 44px;
  border-radius: 9px;
  border: 1.5px solid var(--line-strong);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.check-box svg { width: 26px; height: 26px; color: white; opacity: 0; }
.check-box.active-oui { background: var(--ok); border-color: var(--ok); }
.check-box.active-non { background: var(--rust); border-color: var(--rust); }
.check-box.active-oui svg, .check-box.active-non svg { opacity: 1; }

.bottom-bar {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding: 14px 18px calc(14px + var(--safe-bottom));
  display: flex;
  gap: 10px;
}
.bottom-bar-single { justify-content: stretch; }
.bottom-bar .btn-secondary, .bottom-bar .btn-primary { flex: 1; }

/* ---------- Bassin list ---------- */

.bassin-list {
  padding: 18px 18px 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.bassin-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}

.bassin-num {
  background: var(--slate);
  color: white;
  font-weight: 700;
  min-width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.bassin-info { flex: 1; min-width: 0; }
.bassin-info strong { display: block; font-size: 0.95rem; }
.bassin-info span { font-size: 0.83rem; color: var(--ink-faint); }

.bassin-photos-count {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.83rem;
  color: var(--ink-faint);
  flex-shrink: 0;
}

/* ---------- Problem chips ---------- */

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: 20px;
  padding: 9px 15px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.chip.active {
  background: var(--rust-tint);
  border-color: var(--rust);
  color: var(--rust-dark);
}

/* ---------- Photos ---------- */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.photo-slot {
  aspect-ratio: 3/4;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-sunken);
  position: relative;
  overflow: hidden;
  color: var(--ink-faint);
}
.photo-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-slot input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.photo-slot-empty { flex-direction: column; gap: 6px; }
.photo-slot-empty .icon { width: 26px; height: 26px; }
.photo-slot-empty span { font-size: 0.72rem; font-weight: 600; }

.photo-remove {
  position: absolute;
  top: 5px;
  right: 5px;
  background: rgba(26,31,22,0.65);
  color: white;
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

/* ---------- Summary / Finish ---------- */

.summary-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 16px;
}
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.94rem;
}
.summary-row:last-child { border-bottom: none; }
.summary-row span { color: var(--ink-soft); }

.note-inline {
  font-size: 0.85rem;
  color: var(--ink-faint);
  text-align: center;
  margin: -6px 0 0;
  min-height: 1.2em;
}

.note-instructions {
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  text-align: left;
  color: var(--ink-soft);
  line-height: 1.45;
  margin-top: 4px;
}
.note-instructions strong { color: var(--ink); }

.field-email-fallback {
  opacity: 0.75;
  margin-top: 4px;
}

.numero-warning {
  background: var(--rust-tint);
  color: var(--rust-dark);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin: -8px 0 0;
}
.numero-warning-range {
  background: #FFF6DA;
  color: #8A6416;
}

.field-error {
  background: var(--rust-tint);
  color: var(--rust-dark);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin: 6px 0 0;
}

/* ---------- Annotation photo ---------- */

.annotate-overlay {
  position: fixed;
  inset: 0;
  background: #14171291;
  background: rgba(10, 12, 9, 0.96);
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.annotate-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 16px 12px;
}

.annotate-colors { display: flex; gap: 12px; }
.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  padding: 0;
}
.color-swatch.active { border-color: white; }
.color-red { background: #E03131; }
.color-yellow { background: #F5C400; }

.annotate-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 8px 12px;
  min-height: 0;
}
#annotate-canvas {
  touch-action: none;
  max-width: 100%;
  max-height: 100%;
  background: #000;
  border-radius: 10px;
}

.annotate-hint {
  text-align: center;
  color: rgba(255,255,255,0.6);
  font-size: 0.82rem;
  margin: 0 0 10px;
}

.annotate-bottom {
  display: flex;
  gap: 10px;
  padding: 0 16px calc(16px + var(--safe-bottom));
}
.annotate-bottom .btn-secondary, .annotate-bottom .btn-primary { flex: 1; }
.annotate-bottom .btn-secondary {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.25);
  color: white;
}
