/* ============================================================
   ASIITEC — Feuille de style (mobile first)
   Cibles tactiles >= 44px, statuts colorés, lisible sur vieux tél.
   ============================================================ */

:root {
  --bleu: #1d4ed8;
  --bleu-fonce: #1e40af;
  --bleu-clair: #eef2fb;
  --vert: #16a34a;
  --orange: #f59e0b;
  --rouge: #dc2626;
  --gris-bg: #f4f6fb;
  --gris-bord: #e2e8f0;
  --gris-txt: #475569;
  --gris-clair: #94a3b8;
  --noir: #0f172a;
  --blanc: #ffffff;
  --radius: 12px;
  --ombre: 0 2px 8px rgba(15, 23, 42, 0.08);
  --ombre-fort: 0 6px 20px rgba(15, 23, 42, 0.18);
  --touch: 44px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--gris-bg);
  color: var(--noir);
  font-size: 16px;
  line-height: 1.45;
}

.hidden { display: none !important; }

/* ---------- Boutons ---------- */
.btn {
  min-height: var(--touch);
  padding: 0 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: filter .15s, transform .05s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--bleu); color: #fff; }
.btn-primary:active { filter: brightness(0.92); }
.btn-secondary { background: #fff; color: var(--bleu); border: 1.5px solid var(--bleu); }
.btn-success { background: var(--vert); color: #fff; }
.btn-danger { background: var(--rouge); color: #fff; }
.btn-ghost { background: transparent; color: var(--gris-txt); }
.btn-block { width: 100%; margin-top: 8px; }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 14px; }

.btn-icon {
  min-width: var(--touch); min-height: var(--touch);
  border: none; background: transparent; color: #fff;
  font-size: 22px; cursor: pointer; border-radius: 10px;
}

/* ============================================================
   ÉCRAN DE CONNEXION
   ============================================================ */
.login-screen {
  position: fixed; inset: 0;
  background: linear-gradient(160deg, var(--bleu) 0%, var(--bleu-fonce) 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 100;
}
.login-card {
  background: #fff; border-radius: 18px; padding: 28px 22px;
  width: 100%; max-width: 380px; box-shadow: var(--ombre-fort);
}
.login-logo {
  font-size: 38px; font-weight: 800; color: var(--bleu);
  text-align: center; letter-spacing: 1px;
}
.login-sub { text-align: center; color: var(--gris-clair); margin: 2px 0 22px; }

.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--gris-txt); margin-bottom: 6px; }

.select-big, .input, .textarea, select, input[type="text"], input[type="date"],
input[type="time"], input[type="email"], input[type="tel"], input[type="number"], input[type="password"] {
  width: 100%; min-height: var(--touch);
  padding: 10px 12px; font-size: 16px;
  border: 1.5px solid var(--gris-bord); border-radius: 10px;
  background: #fff; color: var(--noir);
}
.textarea { min-height: 90px; resize: vertical; font-family: inherit; }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--bleu); }

.pin-display { display: flex; justify-content: center; gap: 16px; margin: 22px 0 18px; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--bleu); }
.pin-dot.filled { background: var(--bleu); }

.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-key {
  min-height: 60px; font-size: 24px; font-weight: 600;
  border: none; border-radius: 14px; background: var(--bleu-clair);
  color: var(--noir); cursor: pointer;
}
.pin-key:active { background: #dde6fa; transform: scale(0.97); }
.pin-key-action { background: #f1f5f9; color: var(--gris-txt); font-size: 22px; }

.login-error { color: var(--rouge); text-align: center; min-height: 20px; margin: 12px 0 0; font-size: 14px; }

/* ============================================================
   STRUCTURE APPLICATION
   ============================================================ */
.app-shell { min-height: 100vh; padding-bottom: 72px; }

.app-header {
  position: sticky; top: 0; z-index: 30;
  background: var(--bleu); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; height: 56px;
}
.app-header-title { font-size: 20px; font-weight: 800; letter-spacing: .5px; cursor: pointer; }
.app-header-user { display: flex; align-items: center; gap: 8px; font-size: 14px; }

.view { padding: 16px; max-width: 900px; margin: 0 auto; }

/* Barre de navigation basse */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--gris-bord);
  display: flex; height: 64px;
}
.nav-item {
  flex: 1; border: none; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--gris-clair); font-weight: 600;
}
.nav-item .nav-ico { font-size: 20px; }
.nav-item.active { color: var(--bleu); }

/* Bouton flottant + */
.fab {
  position: fixed; right: 18px; bottom: 80px; z-index: 31;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--bleu); color: #fff; border: none;
  font-size: 32px; line-height: 1; cursor: pointer;
  box-shadow: var(--ombre-fort);
}
.fab:active { transform: scale(0.95); }

/* ============================================================
   COMPOSANTS
   ============================================================ */
.page-title { font-size: 22px; font-weight: 800; margin: 4px 0 16px; }
.section-title { font-size: 15px; font-weight: 700; color: var(--gris-txt); margin: 20px 0 10px; text-transform: uppercase; letter-spacing: .4px; }

.card {
  background: #fff; border-radius: var(--radius);
  box-shadow: var(--ombre); padding: 16px; margin-bottom: 12px;
  border: 1px solid var(--gris-bord);
}
.card-clickable { cursor: pointer; }
.card-clickable:active { background: #fafbff; }

/* Grille de compteurs dashboard */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.stat-card {
  background: #fff; border-radius: var(--radius); padding: 16px;
  box-shadow: var(--ombre); border-left: 5px solid var(--bleu);
}
.stat-card .stat-num { font-size: 30px; font-weight: 800; line-height: 1; }
.stat-card .stat-label { font-size: 13px; color: var(--gris-txt); margin-top: 4px; }
.stat-card.is-total { border-left-color: var(--bleu); }
.stat-card.is-done { border-left-color: var(--vert); }
.stat-card.is-plan { border-left-color: var(--bleu); }
.stat-card.is-incident { border-left-color: var(--rouge); }

/* Badges de statut */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; color: #fff; white-space: nowrap;
}
.badge-terminee { background: var(--vert); }
.badge-planifiee { background: var(--bleu); }
.badge-encours  { background: var(--orange); }
.badge-incident { background: var(--rouge); }

/* Ligne intervention */
.inter-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.inter-main { min-width: 0; }
.inter-ref { font-weight: 700; color: var(--bleu); font-size: 14px; }
.inter-client { font-weight: 600; }
.inter-meta { font-size: 13px; color: var(--gris-txt); }

/* Alertes stock */
.alert-box {
  background: #fff7ed; border: 1px solid #fed7aa; border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px;
}
.alert-box.empty { background: #f0fdf4; border-color: #bbf7d0; }
.alert-title { font-weight: 700; color: #b45309; display: flex; align-items: center; gap: 6px; }
.alert-item { font-size: 14px; padding: 4px 0; display: flex; justify-content: space-between; }

/* Formulaires */
.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checks-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.check-item {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--touch); padding: 6px 12px;
  border: 1.5px solid var(--gris-bord); border-radius: 10px; cursor: pointer;
  font-size: 15px; background: #fff;
}
.check-item input { width: 22px; height: 22px; margin: 0; accent-color: var(--bleu); }
.check-item.checked { border-color: var(--vert); background: #f0fdf4; }

/* Lignes matériel dans le formulaire */
.materiel-line {
  display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px;
  align-items: start; margin-bottom: 8px;
  padding: 10px; border: 1px solid var(--gris-bord); border-radius: 10px; background: #fafbff;
}
.materiel-line .full { grid-column: 1 / -1; }
.materiel-line .row2 { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Stock : barre de progression */
.stock-item { }
.stock-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.stock-name { font-weight: 700; }
.stock-loc { font-size: 12px; color: var(--gris-clair); }
.stock-bar { height: 12px; border-radius: 999px; background: #eef2f7; overflow: hidden; }
.stock-bar-fill { height: 100%; border-radius: 999px; transition: width .3s; }
.stock-bar-fill.ok { background: var(--vert); }
.stock-bar-fill.low { background: var(--rouge); }
.stock-qty-row { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; gap: 10px; }
.qty-controls { display: flex; align-items: center; gap: 10px; }
.qty-btn {
  width: var(--touch); height: var(--touch); border-radius: 12px;
  border: 1.5px solid var(--bleu); background: #fff; color: var(--bleu);
  font-size: 24px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.qty-btn:active { background: var(--bleu-clair); }
.qty-val { font-size: 22px; font-weight: 800; min-width: 38px; text-align: center; }

/* Barre de recherche / filtres */
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-row select { flex: 1; min-width: 120px; }

/* Détail intervention */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.detail-item .detail-label { font-size: 12px; color: var(--gris-clair); font-weight: 600; }
.detail-item .detail-val { font-weight: 600; }
.detail-full { grid-column: 1 / -1; }

table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th { text-align: left; color: var(--gris-txt); font-size: 12px; padding: 6px 8px; border-bottom: 2px solid var(--gris-bord); }
table.simple td { padding: 8px; border-bottom: 1px solid var(--gris-bord); }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.row-actions .btn { flex: 1; min-width: 120px; }

.empty-state { text-align: center; color: var(--gris-clair); padding: 40px 16px; }
.empty-state .big { font-size: 42px; }

.muted { color: var(--gris-clair); }
.text-right { text-align: right; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.spinner { text-align: center; padding: 40px; color: var(--gris-clair); }

/* Notifications toast */
.toast-container { position: fixed; left: 0; right: 0; bottom: 80px; z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--noir); color: #fff; padding: 12px 18px; border-radius: 10px;
  font-size: 14px; font-weight: 600; box-shadow: var(--ombre-fort);
  max-width: 90%; animation: toastIn .2s ease;
}
.toast.success { background: var(--vert); }
.toast.error { background: var(--rouge); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Bandeau hors-ligne */
.offline-banner {
  position: fixed; top: 56px; left: 0; right: 0; z-index: 40;
  background: var(--orange); color: #fff; text-align: center;
  padding: 6px; font-size: 13px; font-weight: 600;
}

/* ---------- Statut matériel (en stock / à créer) ---------- */
.mat-status { font-size: 12px; font-weight: 600; margin-top: 2px; min-height: 16px; }
.mat-status.ok { color: var(--vert); }
.mat-status.warn { color: #b45309; }

/* ---------- Bandeau signature (détail) ---------- */
.sig-banner { margin-top: 12px; padding: 8px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; }
.sig-banner.signed { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.sig-banner.unsigned { background: #fff7ed; color: #b45309; border: 1px solid #fed7aa; }

/* ---------- Pavé de signature ---------- */
.sig-canvas {
  width: 100%; height: 180px; display: block;
  background: #fff; border: 2px dashed var(--gris-bord); border-radius: 10px;
  touch-action: none; cursor: crosshair;
}

/* ---------- Fenêtre modale ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  background: #fff; border-radius: 16px; padding: 20px;
  width: 100%; max-width: 460px; max-height: 88vh; overflow-y: auto;
  box-shadow: var(--ombre-fort);
}
.modal-title { font-size: 18px; font-weight: 800; margin: 0 0 8px; }
.modal-art {
  border: 1px solid var(--gris-bord); border-radius: 10px;
  padding: 12px; margin-bottom: 12px; background: #fafbff;
}
.modal-art-name { font-weight: 700; color: var(--bleu); margin-bottom: 8px; }

/* ---------- Sélecteur + bouton "Nouveau" sur la même ligne ---------- */
.inline-add { display: flex; gap: 8px; align-items: stretch; }
.inline-add select { flex: 1; min-width: 0; }
.inline-add .btn { white-space: nowrap; }

/* ---------- Boutons d'accès rapide (dashboard) ---------- */
.quick-actions { display: flex; gap: 10px; margin-bottom: 12px; }
.quick-actions .btn { flex: 1; }

/* ---------- Écrans plus larges (PC bureau) ---------- */
@media (min-width: 720px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .checks-grid { grid-template-columns: 1fr 1fr; }
  .fab { bottom: 24px; }
}
