/* ============================================================
   Protection Civile — Inventaire sacs de secours
   Mobile-first · Bleu #004080 · Orange #F08700
   ============================================================ */

:root {
  --blue:       #004080;
  --blue-light: #1a6a8a;
  --blue-dark:  #002d5c;
  --orange:     #F08700;
  --orange-bg:  #fff3e0;
  --red:        #c62828;
  --green:      #2e7d32;
  --purple:     #7b3f8f;
  --grey:       #f5f5f5;
  --border:     #d0d0d0;
  --text:       #1a1a1a;
  --text-muted: #666;
  --white:      #ffffff;
  --radius:     6px;
  --shadow:     0 2px 8px rgba(0,0,0,.12);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, .btn-block, .btn-icon, .btn-back, .qty-btn { user-select: none; }

html { font-size: 16px; scroll-padding-top: 80px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--grey);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────── */
.app-header {
  background: var(--white);
  border-bottom: 3px solid var(--orange);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.app-header .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.app-header .logo img { height: 48px; }
.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Breadcrumb / back nav ───────────────────────────────── */
.page-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 4px;
}
.page-nav h1 {
  font-size: 1.1rem;
  color: var(--blue);
  font-weight: 600;
}
.page-nav .sub {
  font-size: .85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Main content ────────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 16px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

/* ── Boutons principaux (blocs) ──────────────────────────── */
.btn-block {
  display: block;
  width: 100%;
  padding: 18px 16px;
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, transform .1s;
  margin-bottom: 12px;
}
.btn-block:hover  { background: var(--blue-light); }
.btn-block:active { transform: scale(.98); }
.btn-block.orange { background: var(--orange); color: var(--white); }
.btn-block.orange:hover { background: #d97700; }
.btn-block.grey   { background: #888; }
.btn-block.purple { background: var(--purple); color: var(--white); }
.btn-block.purple:hover { background: #642f75; }
.btn-block.green  { background: var(--green); color: var(--white); }
.btn-block.green:hover { background: #245a26; }
.btn-block.has-missing { background: var(--orange); }
.btn-block.has-missing:hover { background: #d97700; }

/* ── Boutons icônes (header) ─────────────────────────────── */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  text-decoration: none;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background .15s;
}
.btn-icon:hover { background: var(--blue-light); }

/* ── Bouton retour ───────────────────────────────────────── */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: .9rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn-back:hover { background: var(--blue-light); }

/* ── Grille sacs (photos) ────────────────────────────────── */
.bag-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px 0;
}
.bag-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
  transition: transform .15s, box-shadow .15s;
}
.bag-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,.15); }
.bag-card img { width: 100%; max-height: 120px; object-fit: contain; }
.bag-card .bag-name {
  margin-top: 8px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--blue);
  text-align: center;
}
.bag-card.has-missing { border: 2px solid var(--orange); }

/* ── Quantité +/- ────────────────────────────────────────── */
.qty-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.qty-row:last-child { border-bottom: none; }
.qty-label {
  flex: 1;
  font-size: .95rem;
  padding-right: 12px;
}
.qty-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}
.qty-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius);
  background: var(--blue);
  color: var(--white);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qty-btn:hover:not(:disabled) { background: var(--blue-light); }
.qty-btn:disabled { background: #ccc; cursor: not-allowed; }
.qty-value {
  min-width: 48px;
  height: 36px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--white);
  transition: background .2s, border-color .2s;
}
.qty-value.missing {
  background: var(--orange);
  color: var(--white);
  border-color: var(--orange);
}
.qty-max { color: var(--text-muted); font-size: .9rem; display: inline-block; min-width: 2.7em; }

/* ── Navigation pochette ─────────────────────────────────── */
.pocket-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 8px 0 16px;
}
.pocket-nav-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--blue);
  min-width: 120px;
  text-align: center;
}

/* ── Vue zone intérieure (CSS Grid cliquable) ────────────── */
.zone-canvas {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  margin-top: 8px;
  overflow: auto;
}
.zone-grid {
  display: grid;
  gap: 6px;
}
.zone-cell {
  border: 4px solid var(--item-color, var(--blue));
  border-radius: 4px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--item-color, var(--blue));
  cursor: pointer;
  text-decoration: none;
  padding: 8px;
  text-align: center;
  font-size: 1.125rem;
  transition: background .15s;
}
.zone-cell:hover { background: #e8f0f8; }
.zone-cell.has-missing {
  border-color: var(--orange);
  color: var(--orange);
  background: var(--orange-bg);
}
.zone-separator-h {
  grid-column: 1 / -1;
  align-self: center;
  height: 6px;
  background: repeating-linear-gradient(
    90deg, var(--blue) 0, var(--blue) 6px, transparent 6px, transparent 12px
  );
  border-radius: 3px;
  cursor: default;
}
.zone-separator-v {
  justify-self: center;
  width: 6px;
  background: repeating-linear-gradient(
    180deg, var(--blue) 0, var(--blue) 6px, transparent 6px, transparent 12px
  );
  border-radius: 3px;
  cursor: default;
}

/* ── Vue extérieure (sac principal + sous-sacs) ──────────── */
.exterior-canvas-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; display: flex; justify-content: center; }
@media (max-width: 639px) {
  .exterior-canvas-wrap { margin-left: -16px; margin-right: -16px; }
  .exterior-canvas { margin-left: 0; margin-right: 0; border-radius: 0; }
}
.exterior-canvas {
  position: relative;
  margin: 16px 0;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-height: 320px;
  min-width: 500px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.exterior-main-bag {
  max-width: calc(100% - 10px);
  max-height: calc(100% - 10px);
  object-fit: contain;
  display: block;
}
.exterior-sub-bag {
  position: absolute;
  background: var(--zone-color, var(--blue));
  color: var(--white);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: .85rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, transform .1s;
  z-index: 2;
  max-width: 100%;
  word-break: break-word;
  overflow: hidden;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.exterior-sub-bag:hover { filter: brightness(1.15); transform: scale(1.04); }
.exterior-sub-bag.has-missing { background: var(--orange); }

/* ── Page Manquants ──────────────────────────────────────── */
.missing-section { margin-bottom: 24px; }
.missing-section h2 { color: var(--blue); font-size: 1rem; margin-bottom: 8px; }
.missing-bag-title    { font-weight: 700; color: var(--blue-light); font-size: .95rem; margin: 10px 0 4px; padding-left: 8px; }
.missing-view-title   { font-weight: 600; color: var(--text-muted); font-size: .82rem; margin: 6px 0 2px; padding-left: 12px; text-transform: uppercase; letter-spacing: .04em; }
.missing-subbag-title { font-weight: 600; color: var(--blue); font-size: .85rem; margin: 6px 0 2px; padding-left: 8px; }
.missing-indent { padding-left: 20px; }
.missing-pocket {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  overflow: hidden;
}
.missing-pocket-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  background: var(--white);
}
.missing-pocket-header:hover { background: var(--grey); }
.missing-pocket-header .title { font-weight: 600; color: var(--blue); }
.missing-pocket-body { padding: 8px 16px 12px; border-top: 1px solid var(--border); display: none; }
.missing-pocket-body.open { display: block; }
.missing-restock-btn {
  margin-top: 10px;
  background: var(--green);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.missing-restock-btn:hover { background: #1b5e20; }

/* ── Recherche directe ───────────────────────────────────── */
.search-link       { color: inherit; text-decoration: none; border-bottom: 1px solid currentColor; }
.search-link:hover { opacity: .75; }
.search-link-muted { color: var(--text-muted); text-decoration: none; border-bottom: 1px dashed currentColor; }
.search-link-muted:hover { opacity: .75; }
.search-pocket {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  overflow: hidden;
}
.search-pocket-title {
  display: block;
  font-weight: 600;
  color: var(--blue);
  padding: 12px 16px;
  text-decoration: none;
}
.search-pocket-title:hover { background: var(--grey); }
.search-pocket-body { padding: 0 16px 12px; }
.search-missing .qty-value { color: var(--red); }
.search-missing .qty-label { color: var(--red); }

/* ── Alertes / Toast ─────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--blue-dark);
  color: var(--white);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: .9rem;
  z-index: 999;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ── Overlay de nouvelle tentative (fetchJsonRetry) ──────────── */
.retry-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.retry-overlay.show { display: flex; }
.retry-box {
  background: var(--white);
  border-radius: 12px;
  padding: 24px 32px;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 280px;
}
.retry-spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: retry-spin .8s linear infinite;
}
@keyframes retry-spin { to { transform: rotate(360deg); } }
.retry-box p { font-size: .9rem; color: var(--text); margin: 0; }

/* ── Formulaires ─────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 4px; font-size: .9rem; }
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--white);
}
.form-control:focus { outline: 2px solid var(--blue); border-color: var(--blue); }

/* ── Card générique ──────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

/* ── Indicateur "RAS" ────────────────────────────────────── */
.ras {
  color: var(--text-muted);
  font-style: italic;
  padding: 8px 0;
}

/* ── Utilitaires ─────────────────────────────────────────── */
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-blue   { color: var(--blue); }

/* ── Login page ──────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--grey);
  padding: 24px;
}
.login-card {
  background: var(--white);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,.15);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-card img { height: 64px; margin-bottom: 8px; }
.login-card h1 { font-size: 1.15rem; color: var(--blue); margin-bottom: 4px; }
.login-card p  { font-size: .85rem; color: var(--text-muted); margin-bottom: 24px; }
.login-card .form-group { text-align: left; }
.login-error {
  background: #fee;
  color: var(--red);
  border: 1px solid #f8b5b5;
  border-radius: var(--radius);
  padding: 10px;
  font-size: .9rem;
  margin-bottom: 16px;
}

/* ── Vue niveaux / Lot B ─────────────────────────────────── */
.levels-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 8px 0;
  align-items: start;
}
@media (min-width: 640px) {
  .levels-grid { grid-template-columns: repeat(4, 1fr); }
}
.level-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
  border: 2px solid transparent;
}
.level-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,.15); }
.level-card.has-missing { border-color: var(--orange); }
.level-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: var(--blue);
  color: var(--white);
  font-size: .78rem;
  font-weight: 600;
  gap: 4px;
  min-height: 30px;
}
.level-card.has-missing .level-card-header { background: var(--orange); }
.level-card-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.level-card-badge { font-size: .7rem; white-space: nowrap; }
.level-preview {
  padding: 5px;
  display: flex;
}
.level-preview-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 1.2rem;
}
.level-preview-grid {
  display: grid;
  gap: 2px;
  width: 100%;
}
.lp-cell {
  border: 1.5px solid var(--blue);
  border-radius: 2px;
  font-size: .55rem;
  font-weight: 600;
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2px;
  overflow: hidden;
  word-break: break-word;
}
.lp-cell.has-missing {
  border-color: var(--orange);
  color: var(--orange);
  background: var(--orange-bg);
}
.lp-sep-h {
  grid-column: 1 / -1;
  height: 3px;
  background: var(--blue);
  opacity: .4;
  align-self: center;
  border-radius: 1px;
}
.lp-sep-v {
  width: 3px;
  background: var(--blue);
  opacity: .4;
  justify-self: center;
  border-radius: 1px;
}

/* ── Admin : liste niveaux (bag_edit) ────────────────────── */
.levels-admin-list {
  list-style: none;
  padding: 0;
  margin: 8px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.level-admin-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}
.level-admin-item:last-child { border-bottom: none; }
.level-admin-name { flex: 1; font-weight: 600; color: var(--blue); font-size: .9rem; }
.level-admin-actions { display: flex; gap: 4px; }
