/* =========================================================
   Espoir Café — Compta : design system partagé
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f7f4f0;
  --surface:   #ffffff;
  --border:    #e2d9ce;
  --brun:      #8B4513;
  --brun-l:    #f5deb3;
  --brun-d:    #5a2d0c;
  --text:      #1a1a1a;
  --text-muted:#6b6b6b;
  --green:     #1E8449;
  --green-l:   #d5f5e3;
  --green-d:   #145a32;
  --red:       #C0392B;
  --red-l:     #fadbd8;
  --blue:      #1A5276;
  --blue-l:    #d6eaf8;
  --orange:    #CA6F1E;
  --orange-l:  #fae5d3;
  --purple:    #6C3483;
  --purple-l:  #ebdef0;
  --grey-l:    #f4f1ed;
  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 1px 4px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 18px rgba(0,0,0,0.12);
  --sidebar-w: 230px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ---------- Shell : sidebar + main ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--brun-d);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  padding: 18px 20px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .3px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.sidebar-brand i { font-size: 24px; color: var(--brun-l); }
.sidebar-nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 14px; margin-bottom: 3px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.82);
  text-decoration: none;
  font-size: 14.5px; font-weight: 500;
  transition: background .12s, color .12s;
}
.nav-link i { font-size: 19px; width: 20px; text-align: center; }
.nav-link:hover { background: rgba(255,255,255,.10); color: #fff; }
.nav-link.active { background: var(--brun); color: #fff; box-shadow: var(--shadow); }
.sidebar-foot {
  padding: 14px 20px;
  font-size: 11.5px;
  color: rgba(255,255,255,.55);
  border-top: 1px solid rgba(255,255,255,.12);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 26px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  position: sticky; top: 0; z-index: 9;
}
.topbar h1 { font-size: 19px; font-weight: 700; color: var(--brun-d); display: flex; align-items: center; gap: 9px; }
.topbar h1 i { color: var(--brun); }
.topbar .clock { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.content { padding: 24px 26px 40px; max-width: 1200px; width: 100%; margin: 0 auto; }

@media (max-width: 820px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: column; }
  .sidebar-nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-link { margin-bottom: 0; }
  .sidebar-foot { display: none; }
}

/* ---------- Cartes ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-title {
  font-size: 13px; font-weight: 600; color: var(--brun);
  text-transform: uppercase; letter-spacing: .6px;
  margin-bottom: 14px; display: flex; align-items: center; gap: 7px;
}
.card-title i { font-size: 16px; }
.card-title .right { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-main { grid-template-columns: 1fr 360px; }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4, .grid-main { grid-template-columns: 1fr; } }

/* ---------- Stat cards ---------- */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-ico { width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 19px; }
.stat-val { font-size: 28px; font-weight: 800; margin-top: 8px; letter-spacing: -.5px; }
.stat-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }
.i-green  { background: var(--green-l);  color: var(--green-d); }
.i-red    { background: var(--red-l);    color: var(--red); }
.i-blue   { background: var(--blue-l);   color: var(--blue); }
.i-orange { background: var(--orange-l); color: var(--orange); }
.i-brun   { background: var(--brun-l);   color: var(--brun-d); }
.i-purple { background: var(--purple-l); color: var(--purple); }
.t-green { color: var(--green); } .t-red { color: var(--red); } .t-muted { color: var(--text-muted); }

/* ---------- Formulaires ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
select, input[type=date], input[type=number], input[type=text], input[type=time] {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text); background: var(--surface);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
select:focus, input:focus { border-color: var(--brun); box-shadow: 0 0 0 3px rgba(139,69,19,.12); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 130px; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; font-size: 14px; font-weight: 600;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  transition: opacity .15s, transform .1s, background .12s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brun); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brun-d); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover:not(:disabled) { opacity: .9; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; }
.btn-ghost { background: none; border: 1px solid var(--border); color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--grey-l); }
.btn-sm { padding: 6px 11px; font-size: 13px; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table thead th {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table tbody tr { border-bottom: 1px solid var(--grey-l); }
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: var(--grey-l); }
.table td { padding: 9px 10px; vertical-align: middle; font-size: 14px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .bold { font-weight: 700; }

.del-btn { background: none; border: none; cursor: pointer; color: var(--red); padding: 4px 8px; border-radius: 4px; font-size: 17px; line-height: 1; transition: background .1s; }
.del-btn:hover { background: var(--red-l); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 20px; }
.b-green { background: var(--green-l); color: var(--green-d); }
.b-red { background: var(--red-l); color: var(--red); }
.b-blue { background: var(--blue-l); color: var(--blue); }
.b-orange { background: var(--orange-l); color: var(--orange); }
.b-brun { background: var(--brun-l); color: var(--brun-d); }
.b-grey { background: var(--grey-l); color: var(--text-muted); }
.count-badge { display: inline-flex; align-items: center; justify-content: center; background: var(--brun); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; margin-left: 6px; }

/* ---------- Bar chart maison ---------- */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 180px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar { width: 100%; max-width: 42px; background: var(--brun); border-radius: 5px 5px 0 0; transition: height .4s ease; min-height: 2px; position: relative; }
.bar:hover { background: var(--brun-d); }
.bar-val { font-size: 11px; font-weight: 700; color: var(--brun-d); }
.bar-lab { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* mini barre de progression (stock, répartition) */
.pbar { height: 8px; border-radius: 5px; background: var(--grey-l); overflow: hidden; }
.pbar > i { display: block; height: 100%; border-radius: 5px; }

/* ---------- Divers ---------- */
.empty-msg { text-align: center; color: var(--text-muted); font-size: 14px; padding: 30px 0; }
.empty-msg i { font-size: 32px; display: block; margin-bottom: 8px; opacity: .4; }
.flash { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--green-d); color: #fff; padding: 11px 20px; border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 600; z-index: 100; opacity: 0; transition: opacity .25s, transform .25s; display: flex; align-items: center; gap: 8px; pointer-events: none; }
.flash.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.section-h { font-size: 15px; font-weight: 700; color: var(--brun-d); margin: 4px 0 14px; }
.hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12.5px; color: var(--text-muted); margin-top: 12px; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Modale de confirmation ---------- */
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a5281c; }

.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(40, 25, 10, .45); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; transition: opacity .18s ease;
}
.modal-overlay.show { opacity: 1; }
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 390px; padding: 28px 26px; text-align: center;
  transform: translateY(10px) scale(.97); transition: transform .18s ease;
}
.modal-overlay.show .modal { transform: none; }
.modal-ico { width: 56px; height: 56px; border-radius: 15px; display: flex;
  align-items: center; justify-content: center; font-size: 29px; margin: 0 auto 15px; }
.modal-title { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 7px; }
.modal-msg { font-size: 14px; color: var(--text-muted); margin-bottom: 22px; line-height: 1.55; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.modal-actions .btn { min-width: 124px; }
@media (max-width: 440px) { .modal-actions { flex-direction: column-reverse; } .modal-actions .btn { width: 100%; } }

/* ---------- Visibilité selon le rôle ---------- */
/* Par défaut on suppose "employé" (le plus restrictif) jusqu'à confirmation du rôle. */
body.role-employe .patron-only { display: none !important; }

/* ---------- Champs invalides ---------- */
.invalid, .invalid:focus { border-color: var(--red) !important; box-shadow: 0 0 0 3px rgba(192,57,43,.14) !important; }
@keyframes shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-5px); } 40%,80% { transform: translateX(5px); } }
.shake { animation: shake .32s ease; }
