/* ==========================================================================
   GKL - Interface web
   Crée par Z.Ahcene Graphikey Agency @ 2026
   ========================================================================== */

:root {
  --bg: #f2f5f9;        /* fond général : blanc cassé / gris très clair */
  --bg2: #ffffff;       /* cartes / panneaux : blanc */
  --bg3: #e9eef6;       /* survol / champs : gris clair */
  --line: #d8e0ec;      /* bordures gris clair */
  --txt: #0291F1;       /* écriture principale : bleu */
  --muted: #7b8aa3;     /* texte secondaire : gris-bleu */
  --brand: #0291F1;     /* bleu principal */
  --brand2: #0270c5;    /* bleu appuyé */
  --green: #16a34a;
  --red: #dc2626;
  --orange: #d97706;
  --purple: #7c3aed;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(13, 34, 63, .12);
  --navBg: #0291F1;     /* barre de navigation : bleu */
  --headBg: #071B40;    /* entête : bleu nuit */
}

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

html, body { height: 100%; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--txt);
  font-size: 14px;
}

a { color: var(--brand); text-decoration: none; }

/* ------------------------------- Login ---------------------------------- */
#loginScreen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: url('../img/BG.png') center / cover no-repeat fixed;
  padding: 20px;
}

.loginCard {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 18px;
  width: 400px;
  padding: 36px;
  box-shadow: var(--shadow);
}

.loginLogo { font-size: 34px; font-weight: 800; letter-spacing: 2px; text-align: center; margin-bottom: 4px; }
.loginLogo b { color: var(--brand); }
.loginSub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 26px; }
.loginBrand { display: flex; justify-content: center; margin-bottom: 4px; }
.loginImg { max-height: 64px; max-width: 220px; object-fit: contain; border-radius: 10px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--txt);
  font-size: 14px;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); }
.field textarea { resize: vertical; min-height: 70px; }

.btn {
  display: inline-block;
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg3);
  color: var(--txt);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand2)); border: 0; }
.btn-success { background: linear-gradient(135deg, #16a34a, #15803d); border: 0; }
.btn-danger { background: linear-gradient(135deg, #dc2626, #b91c1c); border: 0; }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-block { width: 100%; }

/* ------------------------------ App layout ------------------------------ */
#app { display: none; height: 100vh; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  height: 56px;
  background: var(--headBg);
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  color: #fff;
}
.topbar .brand { font-size: 20px; font-weight: 800; letter-spacing: 1.5px; color: #fff; }
.topbar .brand b { color: #5cc9ff; }
.topbar .right { display: flex; align-items: center; gap: 14px; color: #eaf2ff; }
.topbar .left { display: flex; align-items: center; gap: 10px; }
.userChip { display: flex; align-items: center; gap: 9px; color: #eaf2ff; }
.brand { display: flex; align-items: center; gap: 10px; }
.brandLogo { height: 30px; max-width: 150px; object-fit: contain; border-radius: 6px; }

/* Barre de chargement fine centrée en haut */
#loader {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  z-index: 400; pointer-events: none; opacity: 0;
  transition: opacity .15s;
}
#loader.on { opacity: 1; }
.loaderBar {
  display: block; height: 100%; width: 26%; margin: 0 auto;
  background: linear-gradient(90deg, transparent, var(--brand), var(--purple), transparent);
  border-radius: 3px;
  animation: loadSlide 1s ease-in-out infinite;
}
@keyframes loadSlide { 0% { transform: translateX(-140%); } 100% { transform: translateX(385%); } }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}

.body { display: flex; flex: 1; overflow: hidden; }

.sidebar {
  width: 232px;
  background: var(--navBg);
  border-right: 1px solid rgba(255, 255, 255, .12);
  padding: 10px;
  overflow-y: auto;
  transition: width .18s ease;
  flex-shrink: 0;
}
.sidebar.collapsed { width: 56px; }
.sidebar.collapsed .navText { display: none; }

.navItem {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: 9px;
  cursor: pointer;
  color: rgba(255, 255, 255, .9);
  margin-bottom: 2px;
  font-size: 13.5px;
  transition: background .12s, color .12s;
}
.navItem:hover { background: rgba(0, 0, 0, .18); color: #fff; }
.navItem.active { background: rgba(7, 27, 64, .5); color: #fff; font-weight: 600; }
.navItem .ico { width: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.navItem .ico svg { width: 18px; height: 18px; }
.navItem .ico svg, .navItem.active .ico svg { stroke: #fff; }
.navSep { height: 1px; background: rgba(255, 255, 255, .25); margin: 10px 8px; }
.navFoot { margin-top: auto; padding: 14px 11px 4px; font-size: 10.5px; color: rgba(255, 255, 255, .75); line-height: 1.5; text-align: center; }

.miniIco { display: inline-flex; color: var(--brand); }
.miniIco svg { width: 15px; height: 15px; }
.modLabel { display: flex; align-items: center; gap: 7px; }
.card.blue .miniIco { color: var(--brand); }
.card.green .miniIco { color: var(--green); }
.card.red .miniIco { color: var(--red); }
.card.orange .miniIco { color: var(--orange); }
.card.purple .miniIco { color: var(--purple); }

#content { flex: 1; overflow-y: auto; padding: 22px; }
.section { display: none; }
.section.active { display: block; animation: fade .15s; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.sectionHead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.sectionTitle { font-size: 21px; font-weight: 700; }
.sectionTools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--txt);
  font-size: 13px;
}

/* ------------------------------- Cards ----------------------------------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.card .value { font-size: 26px; font-weight: 800; margin-top: 6px; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card.blue .value { color: var(--brand); }
.card.green .value { color: var(--green); }
.card.red .value { color: var(--red); }
.card.orange .value { color: var(--orange); }
.card.purple .value { color: var(--purple); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 1000px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.panel {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
.panelTitle { font-size: 14px; font-weight: 700; margin-bottom: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

.barRow { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.barRow .lbl { width: 70px; font-size: 12px; color: var(--muted); text-align: right; flex-shrink: 0; }
.barTrack { flex: 1; height: 10px; border-radius: 6px; background: var(--bg3); overflow: hidden; }
.barFill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--brand), var(--purple)); }
.barRow .val { width: 52px; font-size: 12px; font-weight: 700; }

/* ------------------------------- Tables ----------------------------------- */
.tblWrap { overflow-x: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left;
  padding: 11px 14px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--bg3); }
.tbl .empty { text-align: center; color: var(--muted); padding: 30px; }

/* ---------------------- Lignes de facture (édition) ---------------------- */
.facTable .tbl td { padding: 7px 9px; vertical-align: middle; }
.facTable .tbl th { padding: 9px 10px; }
.facTable .tbl th.facRight, .facTable .tbl td.facRight { text-align: right; }
.facTable input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--txt);
  font-size: 13.5px;
}
.facTable input:focus { outline: none; border-color: var(--brand); }
.facTable .fiDesc { min-width: 220px; }
.facTable .fiQte { width: 74px; }
.facTable .fiPu { width: 120px; }
.facTable .fiMnt { font-weight: 600; text-align: right; white-space: nowrap; }
.facTable .facDel { width: 46px; text-align: center; }
.facTable .facTotalRow td { border-top: 1px solid var(--line); padding-top: 12px; font-size: 15px; }
.facTable .facTotTxt { text-align: right; font-weight: 600; }

.apiError { max-width: 620px; margin: 24px auto; padding: 26px 28px; border: 1px solid rgba(220, 38, 38, .35); border-radius: 12px; background: rgba(220, 38, 38, .07); }
.apiErrorMsg { font-size: 14.5px; font-weight: 600; color: #fca5a5; }
.apiErrorHint { font-size: 13px; color: var(--muted); line-height: 1.6; margin: 10px 0 16px; }
.apiErrorHint code { background: rgba(255, 255, 255, .08); padding: 1px 6px; border-radius: 5px; }
.apiError .btn { margin-top: 2px; }

/* ------- Sélection de membres d'une zone (wilayas / communes) ------- */
.zmRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg3);
}
.zmRow .zmLabel { font-size: 13px; font-weight: 600; color: var(--txt); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.zmRow .zmLabel .zmSub { font-size: 12px; font-weight: 500; color: var(--muted); }
.zmSelRow { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: start; margin-bottom: 10px; }
.zmSelRow .field { margin-bottom: 0; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.b-en_attente { background: rgba(245, 158, 11, .15); color: #fbbf24; }
.b-pris_en_charge { background: rgba(46, 123, 255, .15); color: #7ab3ff; }
.b-en_cours { background: rgba(167, 139, 250, .15); color: #c4b5fd; }
.b-livre { background: rgba(34, 197, 94, .15); color: #4ade80; }
.b-retourne { background: rgba(239, 68, 68, .15); color: #f87171; }
.b-annule { background: rgba(148, 163, 184, .15); color: #94a3b8; }

.statusBar {
  padding: 16px 22px;
  background: var(--bg2);
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: #6b7d9e;
  text-align: center;
}

/* -------------------------------- Modal ----------------------------------- */
.modalBackdrop {
  position: fixed; inset: 0;
  background: rgba(5, 8, 16, .7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 16px;
  width: 560px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal.wide { width: 780px; }
.modalHead { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.modalTitle { font-size: 16px; font-weight: 700; }
.modalBody { padding: 18px 20px; }
.modalFoot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.closeX { cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1; }

/* ------------------------------ Notifications ----------------------------- */
.toast {
  position: fixed;
  top: 18px; right: 18px;
  background: var(--bg3);
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  padding: 13px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-width: 340px;
  z-index: 200;
  animation: slideIn .2s;
}
.toast.error { border-left-color: var(--red); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.spin {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: rot .7s linear infinite;
  vertical-align: middle;
}
@keyframes rot { to { transform: rotate(360deg); } }

.formGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.formGrid .full { grid-column: 1 / -1; }

.chkRow { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.chkPill {
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  user-select: none;
}
.chkPill.on { border-color: var(--brand); background: rgba(46, 123, 255, .12); color: var(--brand); }

.dashDates { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; padding-left: 8px; border-left: 1px solid var(--line); }
.dashDates input[type="date"] {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--txt);
  font: inherit;
  font-size: 12.5px;
}
.dashDates input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(.6); cursor: pointer; }

.mini { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.money { font-weight: 700; }
.money.pos { color: var(--green); }
.money.neg { color: var(--red); }

/* ---------- BY-Scan : lecteur QR colis ---------- */
.scanBox {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  aspect-ratio: 4 / 3;
  background: #0b101c;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.scanBox video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanBox::after {
  content: '';
  position: absolute;
  left: 10%; right: 10%;
  top: 42%; height: 16%;
  border: 2px solid rgba(78, 155, 255, .95);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(11, 16, 28, .35);
  pointer-events: none;
}
.scanBox.scanOk::after { border-color: #2fd47b; box-shadow: 0 0 0 9999px rgba(11, 16, 28, .35), 0 0 18px rgba(47, 212, 123, .7); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #24334f; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }