/* ══════════════════════════════════════════════════════
   Design tokens — Bons de Paiement HASDI
   Palette inspirée du drapeau et de l'écusson de la Police
   ══════════════════════════════════════════════════════ */
:root {
  --ink: #16191B;
  --paper: #F4F3EF;
  --surface: #FFFFFF;
  --line: #E7E5DF;
  --line-strong: #D8D5CC;
  --orange: #EA5B0C;
  --orange-dark: #C24A09;
  --orange-light: #FFF1E8;
  --green: #108252;
  --green-dark: #0B5E39;
  --green-light: #E9F7F0;
  --red-accent: #C1272D;
  --muted: #71756F;
  --muted-light: #A4A79E;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(22,25,27,0.04);
  --shadow-md: 0 4px 16px rgba(22,25,27,0.06), 0 1px 2px rgba(22,25,27,0.05);
  --shadow-lg: 0 16px 40px rgba(22,25,27,0.10), 0 2px 8px rgba(22,25,27,0.06);
  --ease: cubic-bezier(.4,0,.2,1);
  --font-ui: 'IBM Plex Sans', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
::selection { background: var(--orange-light); color: var(--orange-dark); }

body {
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: var(--font-ui); cursor: pointer; transition: transform .12s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease), opacity .15s var(--ease); }
button:active:not(:disabled) { transform: scale(0.97); }
input, select { font-family: var(--font-ui); }

/* ══════════════════════════════════════════════════════
   Page de connexion
   ══════════════════════════════════════════════════════ */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 15%, rgba(232,89,12,0.06), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(15,123,75,0.07), transparent 45%),
    var(--paper);
}

.login-wrap { width: 100%; max-width: 380px; padding: 24px; text-align: center; }

.login-stub {
  height: 4px;
  width: 60px;
  margin: 0 auto 28px;
  background: repeating-linear-gradient(90deg, var(--orange) 0 8px, transparent 8px 14px);
  border-radius: 2px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 36px 32px 28px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 12px 32px rgba(27,31,29,0.06);
}

.login-logo { width: 92px; height: auto; object-fit: contain; margin-bottom: 14px; }

.login-card h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.login-sub { font-size: 13px; color: var(--muted); margin-top: 4px; margin-bottom: 26px; }

.login-card form { text-align: left; }
.login-card label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 14px 0 6px;
}
.login-card input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font-size: 14px;
  background: var(--paper);
  outline: none;
  transition: border-color .15s, background .15s;
}
.login-card input:focus { border-color: var(--orange); background: var(--surface); }

.login-card button {
  width: 100%;
  margin-top: 22px;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.login-card button:disabled { opacity: 0.6; }
.login-card button:hover:not(:disabled) { background: #000; }

.login-error { color: var(--red-accent); font-size: 12.5px; margin-top: 10px; min-height: 16px; }
.login-footer { font-size: 11.5px; color: var(--muted-light); margin-top: 22px; letter-spacing: 0.02em; }
.login-credit { margin-top: 4px; font-weight: 600; }

/* ══════════════════════════════════════════════════════
   Structure principale (shell)
   ══════════════════════════════════════════════════════ */
/* ══════════════════════════════════════════════════════
   Barre mobile (visible uniquement < 860px)
   ══════════════════════════════════════════════════════ */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}
#btn-hamburger {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--surface); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; flex-shrink: 0;
}
#btn-hamburger span { display: block; width: 18px; height: 2px; background: var(--ink); border-radius: 2px; }
.mobile-topbar-title { font-weight: 700; font-size: 15px; flex: 1; }
.mobile-topbar-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--orange); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12.5px;
}

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(22,25,27,0.45);
  z-index: 39; opacity: 0; transition: opacity .2s var(--ease);
}
.sidebar-overlay.visible { display: block; opacity: 1; }

/* ══════════════════════════════════════════════════════
   Structure principale (shell)
   ══════════════════════════════════════════════════════ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 252px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
}

.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 6px; }
.sidebar-brand img { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; }
.brand-title { font-size: 14.5px; font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--muted); }

.stub-line {
  height: 1px;
  margin: 20px 6px 18px;
  background: repeating-linear-gradient(90deg, var(--line-strong) 0 6px, transparent 6px 11px);
}

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  border: none;
  background: none;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  transition: background .15s var(--ease), color .15s var(--ease);
}
.nav-item:hover { background: var(--paper); }
.nav-item.active {
  background: linear-gradient(135deg, var(--ink) 0%, #2A302C 100%);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.nav-badge {
  background: var(--orange);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
}
.nav-item.active .nav-badge { background: #fff; color: var(--ink); }

.nav-sep {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted-light);
  margin: 18px 13px 6px;
}

.sidebar-footer { padding-top: 14px; border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px; margin-bottom: 8px; }
.user-avatar {
  width: 33px; height: 33px; border-radius: 50%;
  background: linear-gradient(135deg, var(--orange), var(--orange-dark)); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--muted); }
.btn-logout {
  width: 100%; border: 1px solid var(--line-strong); background: none;
  padding: 9px; border-radius: var(--radius-sm); font-size: 12.5px; color: var(--muted); font-weight: 500;
}
.btn-logout:hover { background: var(--paper); color: var(--ink); border-color: var(--line-strong); }
.sidebar-credit { text-align: center; font-size: 10.5px; color: var(--muted-light); margin-top: 10px; font-weight: 600; letter-spacing: 0.02em; }


/* ══════════════════════════════════════════════════════
   Contenu
   ══════════════════════════════════════════════════════ */
.content { flex: 1; padding: 40px 46px; max-width: 1120px; }
.view { display: none; animation: fadeSlideIn .3s var(--ease); }
.view.active { display: block; }
@keyframes fadeSlideIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.content h1 { font-size: 25px; font-weight: 700; letter-spacing: -0.015em; }
.view-sub { font-size: 13.5px; color: var(--muted); margin-top: 5px; margin-bottom: 30px; }
.section-h2 { font-size: 15px; font-weight: 700; margin: 32px 0 14px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 8px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow-sm); transition: box-shadow .2s var(--ease), transform .2s var(--ease);
  position: relative; overflow: hidden;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 3px;
}
.stat-card.accent-orange::before { background: linear-gradient(90deg, var(--orange), #FFB27A); }
.stat-card.accent-green::before { background: linear-gradient(90deg, var(--green), #7BD9AC); }
.stat-card .stat-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.stat-card .stat-value { font-size: 27px; font-weight: 700; margin-top: 7px; font-family: var(--font-mono); letter-spacing: -0.02em; }
.stat-card.accent-orange .stat-value { color: var(--orange-dark); }
.stat-card.accent-green .stat-value { color: var(--green-dark); }

/* Panels (formulaires) */
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow-sm); transition: box-shadow .2s var(--ease);
}
.panel:hover { box-shadow: var(--shadow-md); }
.panel-narrow { max-width: 420px; }
.panel h3 { font-size: 15.5px; font-weight: 700; margin-bottom: 18px; letter-spacing: -0.01em; }
.panel-hint { font-size: 12px; color: var(--muted); margin-top: 14px; line-height: 1.55; }

label {
  display: block; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); margin: 13px 0 6px;
}
label:first-of-type { margin-top: 0; }

input[type="text"], input[type="date"], input[type="number"], input[type="password"], select {
  width: 100%; padding: 11px 13px; border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
  font-size: 13.5px; background: var(--paper); outline: none; transition: border-color .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease);
}
input:focus, select:focus { border-color: var(--orange); background: var(--surface); box-shadow: 0 0 0 3px var(--orange-light); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn-row { display: flex; gap: 10px; margin-top: 20px; }
.btn-primary, .btn-secondary, .btn-accent {
  padding: 11px 16px; border: none; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600; flex: 1;
}
.btn-primary { background: linear-gradient(135deg, var(--ink), #2A302C); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { box-shadow: var(--shadow-md); }
.btn-accent { background: linear-gradient(135deg, var(--orange), var(--orange-dark)); color: #fff; box-shadow: var(--shadow-sm); }
.btn-accent:hover { box-shadow: 0 6px 18px rgba(234,91,12,0.28); }
.btn-secondary { background: var(--surface); color: var(--ink); border: 1.5px solid var(--line-strong); }
.btn-secondary:hover { background: var(--paper); border-color: var(--muted-light); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

.code-preview {
  margin-top: 16px; text-align: center; font-family: var(--font-mono); font-weight: 700;
  font-size: 18px; color: var(--green-dark); background: var(--green-light); border: 1px solid #CFEBDC;
  border-radius: var(--radius-sm); padding: 12px;
}


/* Lots */
.batch-item {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 17px 19px; margin-bottom: 12px; box-shadow: var(--shadow-sm); transition: box-shadow .2s var(--ease);
}
.batch-item:hover { box-shadow: var(--shadow-md); }
.batch-item-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.batch-code { font-family: var(--font-mono); font-weight: 700; font-size: 14.5px; }
.batch-meta { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.batch-progress-bar { height: 7px; background: var(--paper); border-radius: 6px; overflow: hidden; margin-bottom: 12px; }
.batch-progress-fill { height: 100%; background: linear-gradient(90deg, var(--green), #4FBE86); border-radius: 6px; transition: width .3s var(--ease); }
.batch-actions { display: flex; gap: 8px; }
.batch-actions .btn-accent, .batch-actions .btn-secondary { flex: 1; }
.btn-danger-outline { background: #FDEEEE; color: var(--red-accent); border: none; border-radius: var(--radius-sm); padding: 11px 14px; font-size: 13px; font-weight: 600; }
.btn-danger-outline:hover { background: #FBDCDC; }

.empty-state { text-align: center; padding: 56px 20px; color: var(--muted-light); font-size: 13.5px; }

/* Historique */
.hist-toolbar { display: flex; gap: 10px; margin-bottom: 18px; }
.hist-toolbar input[type="text"] { flex: 1; }
.hist-toolbar select { width: 220px; }

.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.data-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 600; padding: 11px 15px; background: var(--paper); border-bottom: 1px solid var(--line);
}
.data-table td { padding: 11px 15px; font-size: 13px; border-bottom: 1px solid var(--line); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr { transition: background .12s var(--ease); }
.data-table tbody tr:hover { background: var(--paper); }
.data-table td.mono { font-family: var(--font-mono); font-weight: 600; }

/* Badges statut */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-admin { background: var(--orange-light); color: var(--orange-dark); }
.badge-agent { background: var(--green-light); color: var(--green-dark); }
.badge-actif { background: var(--green-light); color: var(--green-dark); }
.badge-inactif { background: #F1F0EC; color: var(--muted); }

.link-action { background: none; border: none; color: var(--muted); font-size: 12.5px; text-decoration: underline; padding: 0; }
.link-action:hover { color: var(--ink); }

/* Journal d'activité */
.log-details-cell { font-size: 12.5px; color: var(--ink); line-height: 1.7; white-space: normal; }
.log-detail-key { color: var(--muted); font-weight: 600; }

/* ══════════════════════════════════════════════════════
   Impression du bon
   ══════════════════════════════════════════════════════ */
.print-zone { display: none; }

.bon {
  border: 2px dashed var(--red-accent);
  padding: 6px 10px;
  background: #fff;
  font-family: Arial, sans-serif;
  page-break-inside: avoid;
  margin-bottom: 4mm;
}
.bon-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px; }
.bon-title { font-size: 14px; font-weight: 900; color: #000; }
.bon-title span { font-weight: 400; font-style: italic; color: var(--red-accent); font-size: 12px; }
.bon-code-line { text-align: center; font-size: 12px; font-weight: 700; letter-spacing: 1px; margin-bottom: 4px; font-family: var(--font-mono); color: #000; }
.bon-code-line .lbl { font-weight: 400; font-family: Arial, sans-serif; }
.bon-body { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid #999; border-left: 1px solid #999; margin-bottom: 3px; }
.bon-cell { border-right: 1px solid #999; border-bottom: 1px solid #999; padding: 3px 6px; font-size: 10px; }
.bon-cell .lbl { font-weight: 700; display: block; }
.bon-cell .val { display: block; font-size: 11px; min-height: 13px; }
.bon-paiement-logos { display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; }
.bon-paiement-logos img { height: 18px; width: auto; object-fit: contain; }
.bon-lettres { border: 1px solid #999; padding: 3px 6px; font-size: 10px; margin-bottom: 3px; }
.bon-lettres b { font-size: 13px; }
.bon-footer { display: grid; grid-template-columns: 1fr 1fr 1fr; border-top: 1px solid #999; border-left: 1px solid #999; }
.bon-footer-cell { border-right: 1px solid #999; border-bottom: 1px solid #999; padding: 3px 6px; font-size: 9px; font-weight: 700; min-height: 22px; }
.bon-footer-cell .val { font-weight: 400; font-size: 11px; display: block; margin-top: 2px; }
.bon-date-row { border: 1px solid #999; border-top: none; padding: 3px 6px; font-size: 9px; font-weight: 700; }
.bon-date-row .val { font-weight: 400; font-size: 11px; }

@media print {
  body * { visibility: hidden; }
  .print-zone, .print-zone * { visibility: visible; }
  .print-zone { display: block; position: absolute; top: 0; left: 0; width: 100%; }
  .shell { display: none; }
  @page { size: A4 portrait; margin: 6mm 10mm; }
}

/* ══════════════════════════════════════════════════════
   Responsive
   ══════════════════════════════════════════════════════ */
/* ══════════════════════════════════════════════════════
   Responsive — tiroir mobile
   ══════════════════════════════════════════════════════ */
@media (max-width: 860px) {
  .mobile-topbar { display: flex; }

  .shell { flex-direction: column; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 78vw;
    max-width: 300px;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .25s var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }

  .content { padding: 20px 16px 40px; }
  .content h1 { font-size: 21px; }

  .panel-grid { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }

  .hist-toolbar { flex-wrap: wrap; }
  .hist-toolbar select, .hist-toolbar input[type="text"] { width: 100%; }

  .data-table { display: block; overflow-x: auto; white-space: nowrap; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 15px 16px; }
  .stat-card .stat-value { font-size: 22px; }
  .btn-row { flex-direction: column; }
}
