/* ─────────────────────────────────────────────────────────────
   Fiche Découverte — feuille de style commune
   Palette et typographie reprises de la maquette d'origine.
   ───────────────────────────────────────────────────────────── */

:root {
  --cream: #f5f0e8;
  --warm-white: #fdfaf4;
  --charcoal: #1c1c1e;
  --charcoal-soft: #2c2c2e;
  --stone: #8a8178;
  --gold: #c9a84c;
  --gold-light: #e8d5a3;
  --terracotta: #c4714f;
  --sage: #6b8f71;
  --border: #e0d8cc;
  --shadow: rgba(28, 28, 30, 0.08);
  --radius: 12px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--cream);
  color: var(--charcoal);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.serif {
  font-family: 'DM Serif Display', Georgia, serif;
}

a {
  color: inherit;
}

/* ── Header ───────────────────────────────────────────────── */

.app-header {
  background: var(--charcoal);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-family: 'DM Serif Display', Georgia, serif;
  color: var(--gold);
  font-size: 1.25rem;
  letter-spacing: 0.02em;
  text-decoration: none;
  white-space: nowrap;
}
.logo span {
  color: #fff;
  font-style: italic;
}

.header-spacer {
  flex: 1;
}

.header-meta {
  color: var(--stone);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.header-title {
  color: #fff;
  font-size: 0.88rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40vw;
}

/* ── Boutons ──────────────────────────────────────────────── */

.btn {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: var(--charcoal);
  color: var(--gold);
}
.btn-primary:hover {
  background: #333;
}
.btn-gold {
  background: var(--gold);
  color: var(--charcoal);
}
.btn-gold:hover {
  background: #b8933a;
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--stone);
}
.btn-ghost:hover {
  border-color: var(--charcoal);
  color: var(--charcoal);
}
.btn-ghost-dark {
  background: transparent;
  border-color: #47474a;
  color: #cfc9c1;
}
.btn-ghost-dark:hover {
  border-color: var(--gold);
  color: var(--gold);
}
.btn-danger:hover {
  border-color: var(--terracotta);
  color: var(--terracotta);
}
.btn-generate {
  background: linear-gradient(135deg, var(--gold), var(--terracotta));
  color: #fff;
  padding: 13px 28px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  box-shadow: 0 4px 16px rgba(196, 113, 79, 0.28);
}
.btn-generate:hover {
  box-shadow: 0 8px 22px rgba(196, 113, 79, 0.38);
}
.btn-sm {
  padding: 7px 12px;
  font-size: 0.78rem;
}

/* ── Layout ───────────────────────────────────────────────── */

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 20px 140px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.page-title {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 2rem;
  line-height: 1.15;
}
.page-subtitle {
  color: var(--stone);
  font-weight: 300;
  font-size: 0.95rem;
  margin-top: 6px;
}

/* ── Progression & onglets ────────────────────────────────── */

.progress-bar {
  background: var(--charcoal-soft);
  height: 3px;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gold), var(--terracotta));
  transition: width 0.4s ease;
}

.steps-nav {
  background: var(--warm-white);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  position: sticky;
  top: 56px;
  z-index: 90;
}
.steps-nav::-webkit-scrollbar {
  display: none;
}
.step-tab {
  padding: 14px 20px;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--stone);
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s;
}
.step-tab.active {
  color: var(--charcoal);
  border-bottom-color: var(--gold);
}
.step-tab.filled:not(.active) {
  color: var(--sage);
}

/* ── Sections & cartes ────────────────────────────────────── */

.section {
  display: none;
}
.section.active {
  display: block;
  animation: fade-in 0.35s ease;
}
@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.section-label {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
  margin-bottom: 6px;
}

.card {
  background: var(--warm-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 18px;
}
.card-title {
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--stone);
  font-weight: 600;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Champs ───────────────────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}
/* Le bloc regroupe un champ et ses sous-questions sans casser la grille. */
.field-block {
  display: contents;
}
.field {
  grid-column: span var(--col, 12);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field > label,
.field-label {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--charcoal);
  text-transform: uppercase;
}
.field-hint {
  font-size: 0.75rem;
  color: var(--stone);
  font-weight: 300;
}

input[type='text'],
input[type='tel'],
input[type='email'],
input[type='number'],
input[type='password'],
input[type='search'],
select,
textarea {
  font-family: inherit;
  font-size: 0.92rem;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--cream);
  color: var(--charcoal);
  outline: none;
  width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238A8178' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 34px;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.14);
  background: #fff;
}
textarea {
  resize: vertical;
  min-height: 84px;
  line-height: 1.5;
}
.notes-area {
  background: #fffdf5;
  border: 1px solid var(--gold-light);
  border-left: 3px solid var(--gold);
  border-radius: 0 8px 8px 0;
}
.notes-area:focus {
  border-left-color: var(--terracotta);
}

.input-with-unit {
  display: flex;
  align-items: center;
  gap: 8px;
}
.input-unit {
  font-size: 0.85rem;
  color: var(--stone);
  font-weight: 500;
  white-space: nowrap;
}

/* Pastilles radio / cases à cocher */
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pill {
  font-size: 0.86rem;
  font-weight: 400;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--cream);
  user-select: none;
  display: inline-flex;
  align-items: center;
}
.pill:hover {
  border-color: var(--stone);
}
.pill input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.pill:has(input:checked) {
  background: var(--charcoal);
  color: var(--gold);
  border-color: var(--charcoal);
  font-weight: 500;
}
.pill:has(input:focus-visible) {
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.3);
}

/* Sous-questions conditionnelles */
.follow {
  grid-column: span 12;
  margin-top: 2px;
  padding: 16px;
  background: rgba(28, 28, 30, 0.035);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold-light);
  border-radius: 0 10px 10px 0;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}

/* ── Sélecteur DPE / GES ──────────────────────────────────── */

.dpe-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.dpe-btn {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  border: 2px solid transparent;
  font-family: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  color: #fff;
  transition: transform 0.15s, box-shadow 0.15s;
}
.dpe-btn[data-dpe='A'] { background: #00a550; }
.dpe-btn[data-dpe='B'] { background: #51b747; }
.dpe-btn[data-dpe='C'] { background: #b2d235; }
.dpe-btn[data-dpe='D'] { background: #ffcc00; color: #333; }
.dpe-btn[data-dpe='E'] { background: #f7941d; }
.dpe-btn[data-dpe='F'] { background: #ee1c25; }
.dpe-btn[data-dpe='G'] { background: #963025; }
.dpe-btn.selected {
  border-color: var(--charcoal);
  box-shadow: 0 0 0 3px rgba(28, 28, 30, 0.2);
  transform: scale(1.08);
}

/* ── Pièces ───────────────────────────────────────────────── */

.piece {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 12px;
  background: var(--cream);
}
.piece-head {
  display: grid;
  grid-template-columns: 1fr 120px 80px 36px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
}
.piece-name {
  font-weight: 500;
  padding: 7px 10px;
}
.piece-m2 {
  padding: 7px 10px;
  font-size: 0.88rem;
}
.piece-total {
  font-size: 0.82rem;
  color: var(--sage);
  font-weight: 600;
  text-align: center;
}
.piece-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 9px 12px;
  background: var(--warm-white);
  border-top: 1px solid var(--border);
}
.piece-sub-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--stone);
  margin-right: 4px;
}
.chip {
  padding: 5px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--cream);
  color: var(--stone);
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
}
.chip.on {
  background: var(--charcoal);
  border-color: var(--charcoal);
  color: var(--gold);
  font-weight: 600;
}
.chip-square {
  width: 38px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
}
.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--stone);
  font-size: 1rem;
  padding: 6px;
  border-radius: 6px;
  line-height: 1;
}
.icon-btn:hover {
  color: var(--terracotta);
  background: rgba(196, 113, 79, 0.1);
}

.add-piece {
  display: grid;
  grid-template-columns: 1fr 120px auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  background: rgba(201, 168, 76, 0.06);
  border: 1px dashed var(--gold-light);
  border-radius: 10px;
  margin-top: 14px;
}
/* Ces champs vivent dans leur propre grille : ils ne doivent pas hériter du
   « span 12 » de la grille principale du formulaire. */
.add-piece .field {
  grid-column: auto;
}
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.total-surface {
  background: var(--charcoal);
  color: var(--gold);
  padding: 13px 18px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  font-weight: 500;
  font-size: 0.9rem;
}
.total-surface strong {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.4rem;
  font-weight: 400;
}

/* ── Photos ───────────────────────────────────────────────── */

.dropzone {
  border: 2px dashed var(--gold-light);
  border-radius: 10px;
  padding: 26px 20px;
  text-align: center;
  cursor: pointer;
  background: rgba(201, 168, 76, 0.04);
  transition: background 0.2s, border-color 0.2s;
}
.dropzone:hover,
.dropzone.over {
  background: rgba(201, 168, 76, 0.12);
  border-color: var(--gold);
}
.dropzone-title {
  font-weight: 600;
  font-size: 0.9rem;
}
.dropzone-hint {
  color: var(--stone);
  font-size: 0.78rem;
  margin-top: 4px;
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.photo {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
  background: var(--border);
}
.photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo button {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(28, 28, 30, 0.75);
  color: #fff;
  cursor: pointer;
  font-size: 0.72rem;
  line-height: 1;
}

/* ── Récapitulatif ────────────────────────────────────────── */

.recap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  align-items: start;
}
.recap-card {
  background: var(--warm-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.recap-card h3 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.05rem;
  font-weight: 400;
  margin-bottom: 12px;
}
.recap-group {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
  margin: 14px 0 6px;
}
.recap-group:first-of-type {
  margin-top: 0;
}
.recap-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.recap-row:last-child {
  border-bottom: none;
}
.recap-key {
  color: var(--stone);
  flex-shrink: 0;
}
.recap-val {
  font-weight: 500;
  text-align: right;
  word-break: break-word;
}
.recap-note {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.recap-note .recap-key {
  display: block;
  margin-bottom: 4px;
}
.recap-note p {
  white-space: pre-wrap;
  line-height: 1.5;
}
.recap-empty {
  color: var(--stone);
  font-style: italic;
}

/* ── Pied de page fixe ────────────────────────────────────── */

.nav-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--warm-white);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  z-index: 100;
}
.save-state {
  font-size: 0.76rem;
  color: var(--stone);
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.save-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sage);
  flex-shrink: 0;
}
.save-state.pending .save-dot {
  background: var(--gold);
}
.save-state.error {
  color: var(--terracotta);
}
.save-state.error .save-dot {
  background: var(--terracotta);
}

/* ── Tableau de bord ──────────────────────────────────────── */

.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.toolbar input[type='search'] {
  flex: 1;
  min-width: 200px;
}

.fiche-list {
  display: grid;
  gap: 12px;
}
.fiche-card {
  background: var(--warm-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.fiche-card:hover {
  border-color: var(--gold);
  box-shadow: 0 4px 14px var(--shadow);
}
.fiche-title {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.15rem;
  margin-bottom: 4px;
}
.fiche-title a {
  text-decoration: none;
}
.fiche-title a:hover {
  color: var(--terracotta);
}
.fiche-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 0.8rem;
  color: var(--stone);
}
.fiche-meta strong {
  color: var(--charcoal);
  font-weight: 600;
}
.fiche-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 3px 9px;
  border-radius: 12px;
  background: rgba(107, 143, 113, 0.14);
  color: var(--sage);
}
.badge.low {
  background: rgba(196, 113, 79, 0.14);
  color: var(--terracotta);
}
.badge.mid {
  background: rgba(201, 168, 76, 0.18);
  color: #9a7d23;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--stone);
}
.empty-state .serif {
  font-size: 1.4rem;
  color: var(--charcoal);
  margin-bottom: 8px;
}

/* ── Écran de connexion ───────────────────────────────────── */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 15%, #fffdf7 0%, var(--cream) 55%, #ece4d8 100%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--warm-white);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 34px;
  box-shadow: 0 20px 50px rgba(28, 28, 30, 0.1);
}
.login-card .logo {
  font-size: 1.6rem;
  display: block;
  margin-bottom: 6px;
}
/* Le logo vit normalement sur le bandeau sombre : sur fond clair, on inverse. */
.login-card .logo span {
  color: var(--charcoal);
}
.login-card .page-subtitle {
  margin-bottom: 26px;
}
.login-card .field {
  margin-bottom: 16px;
}
.login-error {
  background: rgba(196, 113, 79, 0.1);
  border: 1px solid rgba(196, 113, 79, 0.35);
  color: #9a4a2c;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.85rem;
  margin-bottom: 16px;
}

/* ── Toasts ───────────────────────────────────────────────── */

.toasts {
  position: fixed;
  bottom: 86px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
}
.toast {
  background: var(--charcoal);
  color: var(--warm-white);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 0.85rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.25s ease;
}
.toast.error {
  background: var(--terracotta);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 720px) {
  .app-header {
    padding: 12px 16px;
  }
  .header-title {
    display: none;
  }
  .steps-nav {
    top: 52px;
    padding: 0 8px;
  }
  .step-tab {
    padding: 13px 14px;
  }
  main {
    padding: 28px 14px 130px;
  }
  .card {
    padding: 18px 16px;
  }
  .field {
    grid-column: span 12 !important;
  }
  .page-title {
    font-size: 1.6rem;
  }
  .piece-head {
    grid-template-columns: 1fr 92px 34px;
  }
  .piece-total {
    display: none;
  }
  .fiche-card {
    grid-template-columns: 1fr;
  }
  .fiche-actions {
    justify-content: flex-start;
  }
  .nav-footer {
    padding: 10px 14px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .save-state span:not(.save-dot) {
    display: none;
  }
}
