/* ============================================================
   Design tokens
   ============================================================ */
:root{
  --ink:        #16212c;
  --muted:      #5b6b7c;
  --line:       #dde3e8;
  --bg-page:    #eef1f4;
  --surface:    #ffffff;
  --nav-bg:     #101826;
  --nav-ink:    #c7d2dc;
  --accent:     #1C4374;
  --accent-dark:#152f52;
  --accent-soft:#e7edf4;
  --highlight:      #D0004F;
  --highlight-soft: #fbe3ec;
  --warn:       #b8791e;
  --warn-soft:  #fbedd6;
  --danger:     #c94444;
  --danger-soft:#fbe9e9;
  --success:    #2f8f4e;
  --success-soft:#e6f4ea;
  --radius:     10px;
  --shadow:     0 1px 3px rgba(16,24,38,.08), 0 1px 2px rgba(16,24,38,.06);
  --nav-h: 60px;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  background:var(--bg-page);
  color:var(--ink);
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  font-size:15px;
  line-height:1.45;
  -webkit-tap-highlight-color:transparent;
}
h1,h2,h3{ margin:0 0 6px; line-height:1.25; }
h1{ font-size:1.3rem; }
h2{ font-size:1.05rem; }
h3{
  font-size:1.05rem; color:var(--ink); font-weight:700;
  padding-bottom:8px; margin-bottom:14px; border-bottom:2px solid var(--accent-soft);
}
p{ margin:0 0 8px; }
a{ color:var(--accent-dark); }
button{ font-family:inherit; }
input,textarea,select{ font-family:inherit; font-size:.95rem; }

.hidden{ display:none !important; }

/* ============================================================
   App shell
   ============================================================ */
#app{ min-height:100%; display:flex; flex-direction:column; }

.topbar{
  background:var(--nav-bg); color:#fff;
  padding:14px 16px; display:flex; align-items:center; justify-content:space-between;
  position:sticky; top:0; z-index:20;
}
.topbar .brand{ font-weight:700; font-size:1.05rem; display:flex; align-items:center; gap:8px; }
.topbar .brand .dot{ width:9px; height:9px; border-radius:50%; background:var(--accent); }
.topbar .who{ font-size:.8rem; color:var(--nav-ink); text-align:right; }
.topbar .who button{
  background:none; border:1px solid #2b3a4a; color:var(--nav-ink); border-radius:6px;
  padding:4px 10px; font-size:.78rem; margin-top:2px; cursor:pointer;
}
.topbar .who button:hover{ border-color:var(--accent); color:#fff; }

main{ flex:1; padding:16px; padding-bottom:calc(var(--nav-h) + 20px); max-width:960px; width:100%; margin:0 auto; }

/* Bottom nav (mobile/tablette) */
.bottom-nav{
  position:fixed; bottom:0; left:0; right:0; height:var(--nav-h);
  background:var(--nav-bg); display:flex; z-index:30;
  box-shadow:0 -2px 10px rgba(0,0,0,.2);
}
.bottom-nav button{
  flex:1; background:none; border:none; color:var(--nav-ink);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:2px; font-size:.68rem; cursor:pointer;
}
.bottom-nav button .icon{ font-size:1.25rem; }
.bottom-nav button.active{ color:#fff; }
.bottom-nav button.active .icon{ filter:drop-shadow(0 0 6px rgba(15,139,141,.7)); }
.bottom-nav .brand-desktop, .bottom-nav .who-desktop{ display:none; }

/* Desktop layout : sidebar instead of bottom nav */
@media (min-width:860px){
  #app{ flex-direction:row; }
  .topbar{ display:none; }
  .bottom-nav{
    position:sticky; top:0; height:100vh; width:220px; flex-direction:column;
    box-shadow:2px 0 10px rgba(0,0,0,.15);
    padding:20px 0;
  }
  .bottom-nav .brand-desktop{
    display:flex; color:#fff; font-weight:700; font-size:1.05rem; padding:0 20px 20px; align-items:center; gap:8px;
  }
  .bottom-nav .brand-desktop .dot{ width:9px; height:9px; border-radius:50%; background:var(--accent); }
  .bottom-nav button{
    flex-direction:row; justify-content:flex-start; gap:12px; padding:12px 20px; font-size:.88rem;
  }
  .bottom-nav .who-desktop{ display:block; margin-top:auto; padding:16px 20px; color:var(--nav-ink); font-size:.8rem; }
  .bottom-nav .who-desktop button{
    background:none; border:1px solid #2b3a4a; color:var(--nav-ink); border-radius:6px;
    padding:6px 10px; font-size:.78rem; margin-top:8px; cursor:pointer; width:100%;
  }
  main{ padding:28px; margin:0; max-width:none; }
}

/* ============================================================
   Composants génériques
   ============================================================ */
.card{
  background:var(--surface); border-radius:var(--radius); box-shadow:var(--shadow);
  padding:18px; margin-bottom:16px;
}

.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  background:var(--accent); color:#fff; border:none; border-radius:8px;
  padding:11px 18px; font-size:.92rem; font-weight:600; cursor:pointer;
}
.btn:hover{ background:var(--accent-dark); }
.btn-highlight{ background:var(--highlight); border-color:var(--highlight); }
.btn-highlight:hover{ background:#a8003d; border-color:#a8003d; }
.btn:disabled{ opacity:.5; cursor:not-allowed; }
.sn-lien-materiel{ cursor:pointer; text-decoration:underline dotted; text-underline-offset:2px; }
.sn-lien-materiel:hover{ color:var(--accent-dark); text-decoration-style:solid; }
.btn.secondary{ background:var(--surface); color:var(--ink); border:1px solid var(--line); }
.btn.secondary:hover{ border-color:var(--accent); color:var(--accent-dark); }
.btn.danger{ background:var(--danger); }
.btn.danger:hover{ background:#a93636; }
.btn.success{ background:var(--success); }
.btn.success:hover{ background:#2f7d4f; }
.btn.block{ width:100%; }
.btn.small{ padding:7px 12px; font-size:.82rem; }

.field{ margin-bottom:14px; }
.field label{ display:block; font-size:.8rem; color:var(--muted); margin-bottom:4px; font-weight:600; }
.field input[type=text], .field input[type=tel], .field input[type=email],
.field input[type=number], .field input[type=datetime-local], .field input[type=password],
.field select, .field textarea{
  width:100%; padding:10px 12px; border:1px solid var(--line); border-radius:8px; background:#fff; color:var(--ink);
}
.field textarea{ min-height:80px; resize:vertical; }
.field input:focus, .field select:focus, .field textarea:focus{ outline:2px solid var(--accent); outline-offset:1px; }
.field .hint{ font-size:.76rem; color:var(--muted); margin-top:4px; }
.grid-2{ display:grid; grid-template-columns:1fr; gap:0 14px; }
@media (min-width:600px){ .grid-2{ grid-template-columns:1fr 1fr; } }

.grid-3{ display:grid; grid-template-columns:1fr; gap:0 12px; }
@media (min-width:700px){ .grid-3{ grid-template-columns:1fr 1fr 1fr; } }

/* Carte compacte : resserre les champs pour les cartes très denses
   (ex: Infos & matériel), sans affecter les autres cartes de l'app. */
.compact-card h3{ margin-bottom:8px; }
.compact-card .field{ margin-bottom:8px; }
.compact-card .field label{ margin-bottom:2px; font-size:.74rem; }
.compact-card .field textarea{ min-height:50px; }
.compact-card .checkbox-row{ margin-bottom:8px; }
.compact-card .photo-grid{ margin-bottom:4px; }

.checkbox-row{ display:flex; align-items:center; gap:8px; margin-bottom:14px; }
.checkbox-row input{ width:18px; height:18px; }
.checkbox-row label{ font-size:.88rem; color:var(--ink); }

/* Badges de statut */
.badge{
  display:inline-block; padding:3px 10px; border-radius:20px; font-size:.72rem; font-weight:700;
  white-space:nowrap;
}
.badge.st-nouveau{ background:#e7ebee; color:var(--muted); }
.badge.st-en_diagnostic{ background:#e0ecfb; color:#2361c9; }
.badge.st-devis_envoye{ background:var(--warn-soft); color:var(--warn); }
.badge.st-attente_accord_client{ background:var(--warn-soft); color:var(--warn); }
.badge.st-attente_pieces{ background:var(--warn-soft); color:var(--warn); }
.badge.st-en_reparation{ background:var(--accent-soft); color:var(--accent-dark); }
.badge.st-teste{ background:#e0ecfb; color:#2361c9; }
.badge.st-termine{ background:var(--success-soft); color:var(--success); }
.badge.st-restitue{ background:var(--success-soft); color:var(--success); }
.badge.st-annule{ background:var(--danger-soft); color:var(--danger); }
.badge.st-programme{ background:var(--warn-soft); color:var(--warn); }
.badge.st-en_cours{ background:var(--accent-soft); color:var(--accent-dark); }
.badge.st-pause{ background:#e7ebee; color:var(--muted); }

/* Badges cliquables (fiches d'intervention programmées) : même look que les
   badges de statut de l'Atelier, mais sélectionnables — les options non
   retenues restent visibles en estompé, seule celle active ressort. */
.badge-clickable{ border:none; cursor:pointer; font:inherit; opacity:.4; }
.badge-clickable.active{ opacity:1; }

/* Bulles de statut cliquables (pièces à commander + stock à commander, même classe) */
.statut-piece-pills{ display:flex; gap:6px; flex-wrap:wrap; margin:4px 0 2px; }
.statut-piece-pill{
  display:inline-flex; align-items:center; gap:4px; padding:4px 10px; border-radius:20px;
  font-size:.74rem; font-weight:700; border:1px solid var(--line); background:var(--surface);
  color:var(--muted); cursor:pointer;
}
.statut-piece-pill.active[data-statut="a_commander"]{ background:var(--warn-soft); color:var(--warn); border-color:var(--warn); }
.statut-piece-pill.active[data-statut="commande"]{ background:#e0ecfb; color:#2361c9; border-color:#2361c9; }
.statut-piece-pill.active[data-statut="recu"]{ background:var(--accent-soft); color:var(--accent-dark); border-color:var(--accent); }
.statut-piece-pill.active[data-statut="pose"]{ background:var(--success-soft); color:var(--success); border-color:var(--success); }
.badge.st-mise_a_disposition{ background:var(--accent-soft); color:var(--accent-dark); }
.badge.st-a_facturer{ background:var(--warn-soft); color:var(--warn); }
.badge.st-cloture{ background:var(--success-soft); color:var(--success); }

/* Ligne de temps du workflow d'intervention */
.status-timeline{ display:flex; overflow-x:auto; padding:16px 4px 8px; -webkit-overflow-scrolling:touch; margin-bottom:12px; }
.status-timeline .tl-step{ display:flex; flex-direction:column; align-items:center; flex:0 0 auto; width:104px; position:relative; }
.status-timeline .tl-step .tl-connector{ position:absolute; top:13px; left:-52px; width:104px; height:2px; background:var(--line); z-index:0; }
.status-timeline .tl-step:first-child .tl-connector{ display:none; }
.status-timeline .tl-step .tl-dot{
  width:26px; height:26px; border-radius:50%; display:flex; align-items:center; justify-content:center;
  font-size:.72rem; font-weight:700; background:var(--surface); color:var(--muted); border:2px solid var(--line); z-index:1;
}
.status-timeline .tl-step .tl-label{ font-size:.66rem; text-align:center; margin-top:6px; color:var(--muted); line-height:1.25; padding:0 2px; }
.status-timeline .tl-step.done .tl-dot{ background:var(--success); border-color:var(--success); color:#fff; }
.status-timeline .tl-step.done .tl-connector{ background:var(--success); }
.status-timeline .tl-step.done .tl-label{ color:var(--success); }
.status-timeline .tl-step.sav-actif .tl-dot{ background:var(--danger); border-color:var(--danger); color:#fff; }
.status-timeline .tl-step.sav-actif .tl-connector{ background:var(--danger); }
.status-timeline .tl-step.sav-actif .tl-label{ color:var(--danger); font-weight:700; }
.status-timeline .tl-step.current .tl-dot{ background:var(--accent); border-color:var(--accent); color:#fff; box-shadow:0 0 0 4px var(--accent-soft); }
.status-timeline .tl-step.current .tl-connector{ background:var(--accent); }
.status-timeline .tl-step.current .tl-label{ color:var(--accent-dark); font-weight:700; }
.status-timeline .tl-step.clickable{ cursor:pointer; }
.status-timeline .tl-step.clickable .tl-dot{ transition:transform .15s ease, box-shadow .15s ease; }
.status-timeline .tl-step.clickable:hover .tl-dot{ transform:scale(1.18); box-shadow:0 0 0 5px var(--accent-soft); }
.status-timeline .tl-step.clickable:hover .tl-label{ color:var(--accent-dark); }

.badge.prio-urgente{ background:var(--danger-soft); color:var(--danger); }
.badge.prio-haute{ background:var(--warn-soft); color:var(--warn); }
.badge.prio-normale{ background:#e7ebee; color:var(--muted); }
.badge.prio-basse{ background:#e7ebee; color:var(--muted); }

.badge.sync-synchronise{ background:var(--success-soft); color:var(--success); }
.badge.sync-non_synchronise{ background:#e7ebee; color:var(--muted); }
.badge.sync-erreur{ background:var(--danger-soft); color:var(--danger); }

/* Liste des interventions */
.filters{ display:flex; gap:8px; overflow-x:auto; padding-bottom:6px; margin-bottom:14px; -webkit-overflow-scrolling:touch; }
.filters button{
  background:var(--surface); border:1px solid var(--line); border-radius:20px; padding:7px 14px;
  font-size:.82rem; color:var(--muted); white-space:nowrap; cursor:pointer;
}
.filters button.active{ background:var(--highlight); color:#fff; border-color:var(--highlight); font-weight:700; }
.filters button.active .tab-count{ background:#fff; color:var(--highlight); }

.search-bar{ display:flex; gap:8px; margin-bottom:14px; }
.search-bar input{ flex:1; padding:11px 14px; border:1px solid var(--line); border-radius:8px; }

.ticket-list{ display:flex; flex-direction:column; gap:10px; }
.ticket{
  background:var(--surface); border-radius:var(--radius); box-shadow:var(--shadow);
  padding:14px 16px; cursor:pointer; display:flex; flex-direction:column; gap:6px;
}
.ticket:hover{ box-shadow:0 2px 8px rgba(16,24,38,.14); }
.ticket .row1{ display:flex; justify-content:space-between; align-items:flex-start; gap:10px; }
.ticket .ref{ font-size:.72rem; color:var(--muted); font-variant-numeric:tabular-nums; }
.ticket .client{ font-weight:700; font-size:1rem; }
.ticket .materiel{ color:var(--muted); font-size:.85rem; }
.ticket .badges{ display:flex; gap:6px; flex-wrap:wrap; margin-top:2px; }
.ticket .meta{ font-size:.76rem; color:var(--muted); }

.empty-state{ text-align:center; padding:48px 16px; color:var(--muted); }
.empty-state .icon{ font-size:2.4rem; margin-bottom:10px; }

/* Fiche détail */
.detail-header{ display:flex; justify-content:space-between; align-items:flex-start; gap:10px; margin-bottom:14px; }
.detail-header .titles h1{ margin-bottom:2px; }
.detail-header .titles .ref{ color:var(--muted); font-size:.82rem; }
.back-link{ background:none; border:none; color:var(--accent-dark); font-size:.88rem; cursor:pointer; padding:0; margin-bottom:12px; display:inline-flex; align-items:center; gap:4px; }

.status-actions{ display:flex; flex-wrap:wrap; gap:8px; margin-bottom:16px; }

.tabs{ display:flex; gap:4px; border-bottom:1px solid var(--line); margin-bottom:16px; overflow-x:auto; }
.tabs button{
  background:none; border:none; padding:10px 14px; font-size:.85rem; color:var(--muted); cursor:pointer;
  border-bottom:2px solid transparent; white-space:nowrap;
}
.tabs button.active{ color:var(--accent-dark); border-color:var(--accent); font-weight:600; }
.tab-count{ display:inline-block; min-width:20px; height:20px; padding:0 6px; border-radius:10px; background:var(--accent); color:#fff; font-size:.75rem; font-weight:700; line-height:20px; text-align:center; vertical-align:middle; }

.pieces-table{ width:100%; border-collapse:collapse; margin-bottom:12px; }
.pieces-table th{ text-align:left; font-size:.72rem; color:var(--muted); padding:6px 8px; border-bottom:1px solid var(--line); }

/* Paires problème -> solution (carte "Diagnostic et préconisations") */
.probleme-solution-row{
  position:relative; border:1px solid var(--line); border-radius:10px; overflow:hidden; margin-bottom:16px;
}
.probleme-solution-row .ps-col{ padding:12px; }
.probleme-solution-row .ps-col.probleme{ background:var(--danger-soft); }
.probleme-solution-row .ps-col.solution{ background:var(--success-soft); }
.probleme-solution-row .ps-col label{ display:block; font-size:.68rem; font-weight:700; text-transform:uppercase; letter-spacing:.03em; margin-bottom:6px; }
.probleme-solution-row .ps-col.probleme label{ color:var(--danger); }
.probleme-solution-row .ps-col.solution label{ color:var(--success); }
.probleme-solution-row textarea{ width:100%; min-height:64px; border:1px solid var(--line); border-radius:8px; padding:8px 10px; background:#fff; resize:vertical; }
.probleme-solution-row .ps-arrow{ position:relative; height:16px; background:var(--accent); flex-shrink:0; }
.probleme-solution-row .ps-arrow::after{
  content:''; position:absolute; left:50%; top:50%; width:0; height:0;
  transform:translate(-50%,-50%);
  border-style:solid; border-width:6px 5px 0 5px; border-color:#fff transparent transparent transparent;
}
@media (min-width:640px){
  .probleme-solution-row{ display:flex; align-items:stretch; }
  .probleme-solution-row .ps-col{ flex:1; }
  .probleme-solution-row .ps-arrow{ width:16px; height:auto; }
  .probleme-solution-row .ps-arrow::after{ transform:translate(-50%,-50%) rotate(-90deg); }
}
.pieces-table td{ padding:6px 8px; border-bottom:1px solid var(--line); font-size:.88rem; }
.pieces-table input{ width:100%; padding:6px 8px; border:1px solid var(--line); border-radius:6px; }
.pieces-table .qty-price{ width:70px; }

.photo-grid{ display:grid; grid-template-columns:repeat(auto-fill,minmax(90px,1fr)); gap:8px; margin-bottom:12px; }
.photo-grid figure{ margin:0; position:relative; }
.photo-grid img{ width:100%; aspect-ratio:1; object-fit:cover; border-radius:8px; border:1px solid var(--line); }
.photo-grid figcaption{ font-size:.65rem; color:var(--muted); text-align:center; margin-top:2px; }

.upload-btn{ display:inline-flex; align-items:center; gap:6px; background:var(--accent-soft); color:var(--accent-dark); border:1px dashed var(--accent); border-radius:8px; padding:10px 14px; font-size:.85rem; cursor:pointer; margin-bottom:14px; }
.upload-btn input{ display:none; }

.history-item{ display:flex; gap:10px; padding:10px 0; border-bottom:1px solid var(--line); font-size:.85rem; }
.history-item:last-child{ border-bottom:none; }
.history-item .when{ color:var(--muted); font-size:.72rem; white-space:nowrap; min-width:120px; }

.signature-pad{ border:1px dashed var(--line); border-radius:8px; background:#fff; touch-action:none; width:100%; height:160px; }
.signature-actions{ display:flex; gap:8px; margin-top:8px; }

.client-suggestions{ border:1px solid var(--line); border-radius:8px; margin-top:6px; background:#fff; overflow:hidden; }
.client-suggestions .suggestion{ padding:10px 12px; cursor:pointer; border-bottom:1px solid var(--line); font-size:.88rem; }
.client-suggestions .suggestion:last-child{ border-bottom:none; }
.client-suggestions .suggestion:hover{ background:var(--accent-soft); }
.client-suggestions .suggestion .name{ font-weight:600; }
.client-suggestions .suggestion .sub{ color:var(--muted); font-size:.76rem; }

.selected-client{ background:var(--accent-soft); border:1px solid var(--accent); border-radius:8px; padding:10px 12px; display:flex; justify-content:space-between; align-items:center; margin-top:8px; }
.selected-client button{ background:none; border:none; color:var(--accent-dark); cursor:pointer; font-size:.8rem; }

.toast-wrap{ position:fixed; bottom:calc(var(--nav-h) + 14px); left:0; right:0; display:flex; flex-direction:column; align-items:center; gap:8px; z-index:100; pointer-events:none; }
@media (min-width:860px){ .toast-wrap{ bottom:20px; } }
.toast{ background:var(--nav-bg); color:#fff; padding:10px 18px; border-radius:8px; font-size:.85rem; box-shadow:var(--shadow); max-width:90vw; }
.toast.err{ background:var(--danger); }
.toast.ok{ background:var(--success); }

.login-wrap{ min-height:100vh; display:flex; align-items:center; justify-content:center; padding:20px; }
.login-card{ width:100%; max-width:380px; background:var(--surface); border-radius:14px; box-shadow:var(--shadow); padding:32px 26px; }
.login-card .brand{ display:flex; align-items:center; gap:8px; font-weight:700; font-size:1.2rem; margin-bottom:4px; }
.login-card .brand .dot{ width:10px; height:10px; border-radius:50%; background:var(--accent); }
.login-card p.sub{ color:var(--muted); font-size:.85rem; margin-bottom:22px; }
.login-error{ background:var(--danger-soft); color:var(--danger); padding:10px 12px; border-radius:8px; font-size:.85rem; margin-bottom:14px; }

.spinner{ display:inline-block; width:16px; height:16px; border:2px solid rgba(255,255,255,.4); border-top-color:#fff; border-radius:50%; animation:spin .7s linear infinite; }
@keyframes spin{ to{ transform:rotate(360deg); } }

.section-title{ display:flex; justify-content:space-between; align-items:center; padding-bottom:8px; margin-bottom:14px; border-bottom:2px solid var(--accent-soft); }
.section-title h3{ border-bottom:none; margin-bottom:0; padding-bottom:0; }

/* Modale */
.modal-overlay{
  position:fixed; inset:0; background:rgba(16,24,38,.55); z-index:200;
  display:flex; align-items:center; justify-content:center; padding:16px;
}
.modal-box{
  background:var(--surface); border-radius:var(--radius); box-shadow:var(--shadow);
  width:100%; max-width:440px; padding:20px; max-height:90vh; overflow-y:auto;
}
.modal-box h2{ margin-bottom:12px; text-align:center; }
.modal-actions{ display:flex; gap:8px; margin-top:16px; justify-content:flex-end; }

