:root {
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-2: #f0f2ee;
  --border: #e2e5df;
  --text: #1b1f1c;
  --muted: #69716b;
  --primary: #166534;
  --primary-hover: #14532d;
  --primary-soft: #dcfce7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --warn: #a16207;
  --warn-soft: #fef3c7;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --violet: #6d28d9;
  --violet-soft: #ede9fe;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 16, .05), 0 4px 16px rgba(16, 24, 16, .05);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- boutons & champs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 13px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer;
  transition: background .12s, border-color .12s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: #fca5a5; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn.block { width: 100%; }

label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; }
label.field span.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #86efac; border-color: var(--primary); }
textarea { resize: vertical; min-height: 60px; }
.form-grid { display: grid; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 8px 10px; border-radius: 8px; font-size: 13px; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; }
.brand-mark svg { width: 18px; height: 18px; }
.auth-card .brand { margin-bottom: 22px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card p.muted { margin: 0 0 22px; }

/* ---------- layout ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1160px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 16px; }
.topbar .brand { color: var(--text); }
.topbar .brand:hover { text-decoration: none; }
.topbar .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
main { max-width: 1160px; margin: 0 auto; padding: 28px 20px 60px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.back { display: inline-flex; gap: 4px; align-items: center; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.between { justify-content: space-between; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.green { background: var(--primary-soft); color: var(--primary); }
.badge.amber { background: var(--warn-soft); color: var(--warn); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.blue { background: var(--info-soft); color: var(--info); }
.badge.violet { background: var(--violet-soft); color: var(--violet); }

/* ---------- clients ---------- */
.client-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.client-card { display: flex; flex-direction: column; gap: 10px; padding: 20px; color: inherit; transition: border-color .12s, transform .12s; }
.client-card:hover { border-color: #a7d7b6; text-decoration: none; transform: translateY(-1px); }
.client-card .logo { width: 40px; height: 40px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 16px; }
.client-card p { margin: 0; color: var(--muted); font-size: 13px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 6px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tab { padding: 10px 14px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab .count { background: var(--warn-soft); color: var(--warn); border-radius: 999px; padding: 0 7px; font-size: 11.5px; margin-left: 4px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 24px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 13px; color: var(--muted); font-weight: 500; }

/* ---------- calendrier ---------- */
.cal-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav h2 { min-width: 170px; text-align: center; text-transform: capitalize; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-head { font-size: 12px; color: var(--muted); font-weight: 600; text-align: center; padding: 4px 0; text-transform: uppercase; letter-spacing: .04em; }
.cell {
  min-height: 92px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 8px; display: flex; flex-direction: column; gap: 5px; position: relative; user-select: none;
}
.cell.blank { background: transparent; border-color: transparent; }
.cell.weekend, .cell.holiday { background: var(--surface-2); }
.cell.clickable { cursor: pointer; }
.cell.clickable:hover { border-color: #a7d7b6; }
.cell.selected { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); background: #f3fbf5; }
.cell.today .d { background: var(--primary); color: #fff; }
.cell-top { display: flex; align-items: center; gap: 6px; }
.cell .d { font-weight: 600; font-size: 13px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.cell .hol { font-size: 10.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry { font-size: 12px; font-weight: 600; border-radius: 6px; padding: 3px 7px; display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.entry.t-onsite { background: var(--primary-soft); color: var(--primary); }
.entry.t-remote { background: var(--info-soft); color: var(--info); }
.entry.t-half { background: #ccfbf1; color: #0f766e; }
.entry.t-absent { background: #e5e7eb; color: #4b5563; }
.entry.s-pending { box-shadow: inset 3px 0 0 #f59e0b; }
.entry.s-rejected { background: var(--danger-soft); color: var(--danger); text-decoration: line-through; }
.entry .st { font-size: 11px; text-decoration: none; display: inline-block; }
.leave-tag { font-size: 11.5px; font-weight: 600; border-radius: 6px; padding: 3px 7px; background: var(--violet-soft); color: var(--violet); }
.leave-tag.pending { background: repeating-linear-gradient(135deg, var(--violet-soft) 0 6px, #f5f3ff 6px 12px); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.action-bar {
  position: sticky; bottom: 16px; margin-top: 16px; z-index: 5;
  background: #102a1a; color: #fff; border-radius: 12px; padding: 10px 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.action-bar .sel { font-weight: 600; padding: 0 6px; }
.action-bar input { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.2); color: #fff; max-width: 240px; padding: 6px 10px; }
.action-bar input::placeholder { color: rgba(255,255,255,.55); }
.action-bar .btn { background: rgba(255,255,255,.1); border-color: transparent; color: #fff; }
.action-bar .btn:hover { background: rgba(255,255,255,.2); }
.action-bar .btn.primary { background: #22c55e; color: #052e16; }
.action-bar .btn.red { background: #ef4444; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--border); }

.two-col { display: grid; grid-template-columns: 310px 1fr; gap: 20px; align-items: start; }
.two-col > * { min-width: 0; }
td.nowrap { white-space: nowrap; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 17, .45); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .12s; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 480px; box-shadow: 0 20px 60px rgba(0,0,0,.25); max-height: calc(100vh - 32px); overflow: auto; }
.modal-head { padding: 18px 20px 0; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px 20px; }
.modal-foot { padding: 0 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }
.copy-box { display: flex; gap: 6px; }
.copy-box input { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
@keyframes fade { from { opacity: 0; } }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #102a1a; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-width: 360px; animation: fade .15s; }
.toast.error { background: var(--danger); }

.history-item { display: flex; gap: 14px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.history-item:last-child { border-bottom: none; }
.history-item time { color: var(--muted); font-size: 12.5px; min-width: 128px; font-variant-numeric: tabular-nums; }

@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  main { padding: 20px 16px 50px; }
  .topbar-inner { padding: 10px 16px; }
  .user-chip .who { display: none; }
  .form-row { grid-template-columns: 1fr; }
  .cal { gap: 3px; }
  .cell { min-height: 64px; padding: 4px; }
  .cell .hol { display: none; }
  .entry, .leave-tag { font-size: 10px; padding: 2px 4px; }
  .entry .lbl-long { display: none; }
  .cal-head { font-size: 10px; }
}
@media (min-width: 641px) { .lbl-short { display: none; } }
