:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2430;
  --muted: #5d6878;
  --primary: #1f4e79;
  --primary-ink: #ffffff;
  --primary-soft: #e3edf7;
  --ok: #1d7a46;
  --ok-soft: #e1f3e8;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --info: #2b5d9b;
  --info-soft: #e5eefa;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1a2029;
    --surface-2: #222a35;
    --border: #2f3946;
    --text: #e6eaf0;
    --muted: #9aa5b4;
    --primary: #6ea8dc;
    --primary-ink: #0d1520;
    --primary-soft: #1c3047;
    --ok: #5cc28a;
    --ok-soft: #173326;
    --warn: #e0a84a;
    --warn-soft: #3a2c14;
    --bad: #f08b84;
    --bad-soft: #3d1d1b;
    --info: #8ab6e8;
    --info-soft: #1b2b40;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 14px 0 8px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }
.hidden { display: none !important; }

.demo-banner { background: var(--warn-soft); color: var(--warn); text-align: center; font-weight: 600; padding: 6px 12px; font-size: 13px; border-bottom: 1px solid var(--border); }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* Layout */
.app { display: flex; min-height: calc(100vh - 32px); }
.sidebar { width: 232px; flex: 0 0 232px; background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; padding: 4px 8px 14px; }
.brand-mark { width: 26px; height: 26px; border-radius: 6px; background: var(--primary); display: inline-block; position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 6px; right: 6px; top: 12px; height: 3px; background: var(--primary-ink); transform: rotate(-30deg); border-radius: 2px; }
.nav a { display: block; padding: 7px 10px; border-radius: 6px; color: var(--text); margin-bottom: 1px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav .nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 12px 10px 4px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.persona { display: flex; align-items: center; gap: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; }
.menu-btn { display: none; }
.content { padding: 20px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.card.flush { padding: 0; }
.card.flush > h2 { padding: 14px 16px 0; }
.grid { display: grid; gap: 12px; }
.grid.kpis { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .value button.link { font-size: 22px; font-weight: 700; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.accent-bad { border-left: 4px solid var(--bad); }
.kpi.accent-warn { border-left: 4px solid var(--warn); }
.kpi.accent-ok { border-left: 4px solid var(--ok); }
.kpi.accent-info { border-left: 4px solid var(--info); }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tfoot td { font-weight: 700; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }
.cond { display: block; font-size: 12px; }
.cond.ok::before { content: "✓ "; color: var(--ok); font-weight: 700; }
.cond.ko::before { content: "✗ "; color: var(--bad); font-weight: 700; }

/* Forms */
button, .btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 12px; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover { background: var(--surface-2); }
button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.small { padding: 3px 8px; font-size: 12px; }
button.link { border: none; background: none; padding: 0; color: var(--primary); text-decoration: underline dotted; text-underline-offset: 3px; cursor: pointer; }
button:disabled { opacity: .55; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; width: 100%; min-width: 0; }
textarea { min-height: 90px; resize: vertical; }
input[type=checkbox] { width: auto; }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
label.field.req > span::after { content: " *"; color: var(--bad); }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; min-width: 150px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* Messages */
.alert { padding: 10px 12px; border-radius: 6px; margin-bottom: 12px; border: 1px solid transparent; }
.alert.error { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.loading { padding: 28px; text-align: center; color: var(--muted); }
.denied { padding: 40px; text-align: center; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 6px; box-shadow: var(--shadow); }
.toast.error { background: var(--bad); color: #fff; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 20, .5); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 40; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 640px; box-shadow: 0 10px 30px rgba(0, 0, 0, .3); }
.modal.wide { max-width: 980px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--muted); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* Calendrier CRA */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { font-size: 11px; color: var(--muted); text-align: center; padding: 2px; }
.cal .day { border: 1px solid var(--border); border-radius: 6px; padding: 4px; min-height: 74px; background: var(--surface); display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal .day.off { background: var(--surface-2); }
.cal .day.out { visibility: hidden; }
.cal .day.over { border-color: var(--bad); }
.cal .day .d { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; }
.cal .day select, .cal .day input { padding: 2px 3px; font-size: 12px; border-radius: 4px; }
.cal .day .ro { font-size: 12px; font-weight: 600; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 8px 0; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 6px 0 6px 14px; border-left: 2px solid var(--border); position: relative; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 11px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.copy-box { display: flex; gap: 6px; }
.copy-box input { font-family: var(--mono); font-size: 12px; }

/* Login */
.login { max-width: 860px; margin: 40px auto; padding: 0 16px; width: 100%; }
.login .intro { margin-bottom: 20px; }
.persona-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.persona-card { text-align: left; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 14px; white-space: normal; }
.persona-card strong { font-size: 15px; }

/* Page publique de validation */
.public { max-width: 760px; margin: 30px auto; padding: 0 16px; }

@media (max-width: 900px) {
  .grid.two, .grid.three { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 20px rgba(0, 0, 0, .25); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 8px 16px; }
  .persona .who { display: none; }
}
@media (max-width: 600px) {
  .cal { gap: 2px; }
  .cal .day { min-height: 60px; padding: 2px; }
  .cal .dow { font-size: 10px; }
  .kpi .value { font-size: 19px; }
  .dl { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .dl dt { margin-top: 6px; }
}

/* ---------------------------------------------------------------- Bulle de retours utilisateurs */
.fb-bubble { position: fixed; right: 20px; bottom: 20px; z-index: 35; width: 52px; height: 52px; border-radius: 50%; padding: 0;
  display: grid; place-items: center; background: var(--primary); color: var(--primary-ink); border: none;
  box-shadow: 0 6px 18px rgba(16, 24, 40, .25); cursor: pointer; }
.fb-bubble:hover { filter: brightness(1.08); }
.fb-bubble:focus-visible { outline: 3px solid var(--primary-soft); outline-offset: 2px; }
.fb-panel { position: fixed; right: 20px; bottom: 20px; z-index: 950; width: min(420px, calc(100vw - 32px)); max-height: calc(100vh - 40px);
  overflow: auto; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 36px rgba(16, 24, 40, .28); padding: 16px; }
.fb-panel form { display: grid; gap: 10px; }
.fb-head { display: flex; align-items: center; justify-content: space-between; }
.fb-head h2 { margin: 0; font-size: 1.05rem; }
.fb-kinds { display: flex; gap: 6px; }
.fb-kind { flex: 1; border-radius: 999px; }
.fb-kind.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.fb-panel textarea { width: 100%; box-sizing: border-box; resize: vertical; font: inherit; }
.fb-target { display: flex; gap: 8px; align-items: center; justify-content: space-between; background: var(--primary-soft); border-radius: 6px; padding: 6px 8px; font-size: .9rem; }
.fb-target strong { overflow-wrap: anywhere; }
.fb-check { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .9rem; }
.fb-check label { display: flex; gap: 8px; align-items: center; }
.fb-shot img { display: block; width: 100%; max-height: 220px; object-fit: contain; object-position: top; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px; background: var(--surface-2); }
.fb-warn { color: var(--warn); font-size: .9rem; margin: 0; }
.fb-logs { max-height: 160px; overflow: auto; font-size: .78rem; background: var(--surface-2); border-radius: 6px; padding: 6px 6px 6px 28px; margin: 0; }
.fb-logs li { overflow-wrap: anywhere; }
.fb-actions { display: flex; justify-content: flex-end; gap: 8px; }
.fb-panel .small, .fb-panel p.small { font-size: .82rem; }
.fb-panel button.link { background: none; border: none; color: var(--primary); padding: 0; text-decoration: underline; cursor: pointer; }
.fb-pickbar { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 960; display: flex; gap: 12px; align-items: center;
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 999px; box-shadow: 0 6px 18px rgba(16, 24, 40, .3); }
.fb-hover { position: fixed; z-index: 955; pointer-events: none; border: 3px solid #0a6fd6; border-radius: 6px; background: rgba(10, 111, 214, .08); }
.fb-frame { position: absolute; z-index: 2147483000; pointer-events: none; border: 3px solid #0a6fd6; border-radius: 6px;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .85), 0 0 0 9999px rgba(22, 43, 57, .18); }
.fb-message { white-space: pre-wrap; font-size: 1rem; background: var(--surface-2); padding: 10px 12px; border-radius: 6px; }
.fb-detail-shot img { max-width: 100%; border: 1px solid var(--border); border-radius: 6px; margin: 8px 0; }
@media (max-width: 639px) {
  .fb-bubble { right: 14px; bottom: 14px; }
  .fb-panel { right: 0; left: 0; bottom: 0; width: auto; max-height: 88vh; border-radius: 14px 14px 0 0; }
}
@media print { .fb-bubble, .fb-panel { display: none; } }
.fb-bubble[hidden], .fb-panel[hidden], .fb-pickbar[hidden], .fb-hover[hidden], .fb-logs[hidden] { display: none !important; }

/* ---------------------------------------------------------------- Assistant IA */
.ai-btn { display: inline-flex; align-items: center; gap: 4px; border-color: var(--primary); color: var(--primary); font-weight: 600; }
.ai-spark { font-size: .95em; }
.ai-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: 45; display: flex; flex-direction: column;
  background: var(--surface); color: var(--text); border-left: 1px solid var(--border); box-shadow: -8px 0 28px rgba(16, 24, 40, .16); }
.ai-panel[hidden] { display: none !important; }
body.ai-open .main { margin-right: min(440px, 100vw); }
@media (max-width: 899px) { body.ai-open .main { margin-right: 0; } }
.ai-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.ai-head-actions { display: flex; gap: 6px; }
.ai-log { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.ai-msg { border-radius: 10px; padding: 10px 12px; max-width: 92%; line-height: 1.5; overflow-wrap: anywhere; }
.ai-user { align-self: flex-end; background: var(--primary); color: var(--primary-ink); white-space: pre-wrap; }
.ai-bot { align-self: flex-start; background: var(--surface-2); }
.ai-bot p { margin: 0 0 6px; } .ai-bot p:last-child { margin-bottom: 0; }
.ai-bot ul { margin: 0 0 6px; padding-left: 18px; }
.ai-busy { color: var(--muted); font-style: italic; }
.ai-error { background: var(--bad-soft); color: var(--bad); }
.ai-cite { display: inline-block; padding: 0 6px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); text-decoration: none; font-size: .9em; font-weight: 600; }
.ai-cite:hover { text-decoration: underline; }
.ai-sources { margin-top: 6px; }
.ai-empty p { margin: 0 0 10px; }
.ai-suggest { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.ai-chip { text-align: left; border-radius: 999px; font-size: .9rem; }
.ai-input { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); align-items: flex-end; }
.ai-input textarea { flex: 1; resize: none; font: inherit; }
.ai-foot { margin: 0; padding: 0 16px 12px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
@media print { .ai-panel, .ai-btn { display: none !important; } }

/* ---------------------------------------------------------------- Feuille de temps mensuelle */
a.button { display: inline-block; padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); text-decoration: none; font-size: .85rem; white-space: nowrap; }
a.button:hover { background: var(--surface-2); }
.ts-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.ts-head h2 { margin: 0 0 4px; }
.ts-status { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.ts-pill { border-radius: 999px; padding: 2px 10px; font-weight: 600; font-size: .85rem; }
.ts-pill.ok { background: var(--ok-soft); color: var(--ok); } .ts-pill.warn { background: var(--warn-soft); color: var(--warn); } .ts-pill.bad { background: var(--bad-soft); color: var(--bad); }
.ts-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.ts-table { border-collapse: separate; border-spacing: 0; font-size: .85rem; min-width: 100%; }
.ts-table th, .ts-table td { padding: 2px; border-bottom: 1px solid var(--border); text-align: center; }
.ts-table .ts-label { position: sticky; left: 0; z-index: 2; background: var(--surface); text-align: left; min-width: 210px; max-width: 260px; padding: 6px 10px; border-right: 1px solid var(--border); }
.ts-table thead .ts-label { z-index: 3; }
.ts-title { font-weight: 600; }
.ts-day { min-width: 34px; font-weight: 500; color: var(--muted); }
.ts-day span { display: block; line-height: 1.15; }
.ts-dow { font-size: .7rem; text-transform: uppercase; }
.off { background: var(--surface-2); }
.ts-cell { width: 32px; height: 28px; padding: 0; text-align: center; border: 1px solid var(--border); border-radius: 4px; font: inherit; background: var(--surface); color: var(--text); }
.ts-cell.off { background: var(--surface-2); }
.ts-cell:disabled { opacity: .45; cursor: not-allowed; }
.ts-cell:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.ts-total { min-width: 48px; font-weight: 600; padding: 0 8px !important; }
.ts-actions { padding: 2px 6px !important; }
.ts-row-actions { display: flex; gap: 4px; }
.ts-group td { text-align: left !important; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); padding: 4px 10px !important; position: sticky; left: 0; }
.ts-absence .ts-label { font-weight: 500; }
.ts-sum { font-weight: 600; font-size: .8rem; }
.ts-sum.ok { color: var(--ok); } .ts-sum.missing { background: var(--warn-soft); color: var(--warn); } .ts-sum.over { background: var(--bad-soft); color: var(--bad); }
.ts-table td { vertical-align: middle; }
.ts-table .ts-total { position: sticky; right: 0; z-index: 2; background: var(--surface); border-left: 1px solid var(--border); }
.ts-table thead .ts-total { z-index: 3; }
.ts-row-actions { display: flex; gap: 10px; margin-top: 2px; }
.ts-row-actions button.link { background: none; border: none; padding: 0; color: var(--primary); font-size: .78rem; cursor: pointer; text-decoration: underline; }
.ts-absence .ts-row-actions { display: inline-flex; margin-left: 8px; }
