:root {
  --navy: #0a1f44;
  --navy-2: #12305f;
  --accent: #e8553f;
  --ink: #1a2233;
  --muted: #64748b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.spacer { flex: 1; }

/* --- Login --- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(135deg, var(--navy), var(--navy-2)); }
.login-card { background: var(--card); padding: 32px; border-radius: 14px;
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card label { display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; color: var(--muted); }

/* --- Brand --- */
.brand { font-size: 20px; font-weight: 800; color: var(--navy); letter-spacing: -.02em; }
.brand span { color: var(--accent); }

/* --- Header --- */
header { display: flex; align-items: center; gap: 16px; background: var(--card);
  padding: 10px 20px; border-bottom: 1px solid var(--line); position: sticky;
  top: 0; z-index: 10; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { border: 0; background: transparent; padding: 8px 14px; border-radius: 8px;
  cursor: pointer; font-size: 14px; color: var(--muted); font-weight: 600; }
.tab:hover { background: var(--bg); }
.tab.active { background: var(--navy); color: #fff; }
.who { font-size: 13px; color: var(--muted); }

main { padding: 20px; max-width: 1200px; margin: 0 auto; }
.view { animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.bar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
  flex-wrap: wrap; }
.bar h2 { margin: 0; font-size: 18px; color: var(--navy); }
.admin-users { margin-top: 32px; }

/* --- Buttons --- */
.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 9px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
  font-weight: 600; text-decoration: none; display: inline-flex; align-items: center;
  min-height: 40px; }
.btn:hover { border-color: var(--navy); }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }

input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink); min-height: 40px; width: 100%; }
input[type=month], input[type=date] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--navy); border-color: var(--navy); }

/* --- Tables --- */
.grid { width: 100%; border-collapse: collapse; background: var(--card);
  border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.grid th, .grid td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line);
  font-size: 14px; }
.grid th { background: var(--navy); color: #fff; font-size: 12px; text-transform: uppercase;
  letter-spacing: .04em; }
.grid tr:last-child td { border-bottom: 0; }
.grid td.num, .grid th.num { text-align: right; white-space: nowrap; }
.grid tr:hover td { background: #f8fafc; }

/* --- Badges --- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px;
  font-weight: 700; }
.badge.brouillon { background: #e2e8f0; color: #475569; }
.badge.soumis { background: #fef3c7; color: #92400e; }
.badge.valide, .badge.active, .badge.payee { background: #dcfce7; color: #166534; }
.badge.rejete, .badge.close { background: #fee2e2; color: #991b1b; }
.badge.envoyee { background: #dbeafe; color: #1e40af; }

/* --- Summary / cards --- */
.summary { display: flex; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.summary .kpi { background: var(--card); border-radius: var(--radius); padding: 12px 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); min-width: 120px; }
.summary .kpi b { font-size: 22px; color: var(--navy); display: block; }
.summary .kpi span { font-size: 12px; color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px; }
.pcard { background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); border-left: 4px solid var(--navy); }
.pcard.over { border-left-color: var(--danger); }
.pcard h4 { margin: 0 0 2px; color: var(--navy); }
.pcard .sub { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.progress { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.progress > i { display: block; height: 100%; background: var(--ok); }
.progress > i.warn { background: var(--warn); }
.progress > i.over { background: var(--danger); }
.pcard .row { display: flex; justify-content: space-between; font-size: 13px; margin: 3px 0; }

/* --- Modal --- */
.modal { position: fixed; inset: 0; background: rgba(10,31,68,.5); display: grid;
  place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--card); border-radius: 14px; padding: 24px; width: 100%;
  max-width: 480px; max-height: 90vh; overflow: auto; }
.modal-card h3 { margin: 0 0 16px; color: var(--navy); }
.modal-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.modal-card label > span { display: block; margin-bottom: 5px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* --- Toast --- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 12px 20px; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.3); z-index: 60; font-weight: 600; }
.toast.err { background: var(--danger); }

.validate-bar { margin-top: 14px; display: flex; gap: 10px; }

/* --- CRA grille mensuelle --- */
.cra-legend { display: flex; gap: 14px; align-items: center; margin-bottom: 10px;
  flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.cra-legend .lg { display: inline-flex; align-items: center; gap: 5px; }
.cra-legend .badge { width: 14px; height: 14px; padding: 0; border-radius: 4px; }
.cal-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.cal { border-collapse: collapse; width: 100%; font-size: 13px; }
.cal th, .cal td { border: 1px solid var(--line); text-align: center; padding: 0; }
.cal th.day { min-width: 30px; padding: 4px 0; color: var(--navy); font-weight: 700;
  background: #f8fafc; line-height: 1.1; }
.cal th.day span { display: block; font-size: 10px; color: var(--muted); font-weight: 600; }
.cal th.day.we, .cal td.cell.we { background: #eef1f5; }
.cal th.aff, .cal td.aff { text-align: left; padding: 8px 10px; min-width: 190px;
  position: sticky; left: 0; background: var(--card); z-index: 1; }
.cal th.aff { background: var(--navy); color: #fff; }
.cal td.aff { border-right: 2px solid var(--line); }
.cal th.tot, .cal td.tot { min-width: 42px; font-weight: 700; background: #f8fafc; }
.cal td.cell { height: 34px; cursor: default; font-weight: 600; }
.cal td.cell:not(.lock) { cursor: pointer; }
.cal td.cell:not(.lock):hover { outline: 2px solid var(--navy); outline-offset: -2px; }
.cal td.cell.brouillon { background: #e2e8f0; color: #334155; }
.cal td.cell.soumis { background: #fef3c7; color: #92400e; }
.cal td.cell.valide { background: #dcfce7; color: #166534; }
.cal td.cell.rejete { background: #fee2e2; color: #991b1b; }
.cal td.cell.lock { cursor: not-allowed; opacity: .85; }
.cal tr.dtot td { background: #f1f5f9; font-weight: 700; color: var(--navy); }
.cal tr.dtot td.over { background: #fee2e2; color: var(--danger); }
.fillbtn { border: 0; background: transparent; cursor: pointer; font-size: 14px;
  padding: 0 4px; float: right; line-height: 1.4; }
.fillbtn:hover { transform: scale(1.2); }

@media (max-width: 640px) {
  main { padding: 12px; }
  .grid th:nth-child(n+5), .grid td:nth-child(n+5) { display: none; }
}
