:root {
  color-scheme: light;
  --brand: #123b6d;
  --brand-2: #1d5aa3;
  --accent: #f4c542;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #dde2ea;
  --text: #16202e;
  --text-2: #4d5b6e;
  --muted: #7a8698;
  --ok: #157a3c;
  --ok-bg: #e5f4ea;
  --warn: #9a5b00;
  --warn-bg: #fff3d6;
  --danger: #b42318;
  --danger-bg: #fdeceb;
  --series-1: #2a78d6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 56, .06), 0 4px 16px rgba(16, 32, 56, .05);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.loading { padding: 4rem; text-align: center; color: var(--muted); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; background: linear-gradient(to right, var(--brand) 240px, transparent 240px); }
.sidebar { background: var(--brand); color: #dfe8f5; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 18px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.1); display: flex; gap: 10px; align-items: center; }
.brand-logo { width: 40px; height: 40px; border-radius: 10px; background: var(--accent); color: var(--brand); display: grid; place-items: center; font: 700 18px Georgia, serif; flex: none; }
.brand-logo.img { background: #fff; object-fit: contain; padding: 2px; }
.brand-name { font-weight: 700; font-size: .86rem; color: #fff; line-height: 1.2; }
.brand-sub { font-size: .75rem; opacity: .75; }
.nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #dfe8f5; font-size: .93rem; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.nav .sep { height: 1px; background: rgba(255,255,255,.1); margin: 8px 6px; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.sidebar-foot { padding: 12px 16px; font-size: .8rem; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-foot button { margin-top: 6px; width: 100%; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: .82rem; color: var(--text-2); white-space: nowrap; }
.content { padding: 22px 24px 48px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: .9rem; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards / grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card > h2:first-child { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: .8rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; }
.tile .value { font-size: 1.45rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .hint { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.tile.accent { border-left: 4px solid var(--brand-2); }
.tile.ok { border-left: 4px solid var(--ok); }
.tile.warn { border-left: 4px solid #d08700; }
.tile.danger { border-left: 4px solid var(--danger); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: var(--surface-2); font-weight: 600; color: var(--text-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
tbody tr:hover { background: #f6f9fd; }
tr.clickable { cursor: pointer; }
tr.annule td { color: var(--muted); text-decoration: line-through; }
tr.annule td.keep { text-decoration: none; }
tfoot td { font-weight: 700; background: var(--surface-2); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: #e6effb; color: var(--brand-2); }
.badge.neutral { background: #eef0f3; color: var(--text-2); }

/* ---------- Forms ---------- */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid #c8d0db; border-radius: 8px; background: #fff; color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(29, 90, 163, .35); border-color: var(--brand-2); }
input[type=checkbox] { width: auto; margin: 0 6px 0 0; vertical-align: middle; }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 14px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.check { display: flex; align-items: center; font-weight: 500; color: var(--text); margin: 4px 0; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 150px; }
.filters .grow { flex: 1; min-width: 220px; }
input.money { text-align: right; font-variant-numeric: tabular-nums; }

button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid #c8d0db; background: #fff; color: var(--text); font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap; text-decoration: none; }
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn-primary:hover { background: var(--brand); }
.btn-success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-success:hover { background: #0f5f2e; }
.btn-danger { color: var(--danger); border-color: #f0b8b3; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: 4px 10px; font-size: .82rem; }
.btn-ghost { border-color: transparent; background: transparent; }
.sidebar-foot .btn-ghost { color: #dfe8f5; border-color: rgba(255,255,255,.25); }
.sidebar-foot .btn-ghost:hover { background: rgba(255,255,255,.08); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; color: var(--text-2); border-bottom: 2px solid transparent; font-weight: 600; font-size: .9rem; }
.tabs a.active { color: var(--brand-2); border-bottom-color: var(--brand-2); }
.tabs a:hover { text-decoration: none; color: var(--brand); }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: .9rem; }
.alert.warn { background: var(--warn-bg); color: #6b4000; border: 1px solid #f1d58f; }
.alert.danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #f3c1bc; }
.alert.info { background: #e9f1fb; color: #1b4777; border: 1px solid #c4d8f1; }
.alert.ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #b9e0c6; }

/* ---------- Charts ---------- */
.meter { position: relative; height: 8px; background: #e9edf2; border-radius: 4px; min-width: 80px; overflow: hidden; }
.meter > span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--series-1); border-radius: 4px; }
.meter-row { display: flex; align-items: center; gap: 8px; }
.meter-row .pct { width: 44px; text-align: right; font-size: .82rem; font-variant-numeric: tabular-nums; color: var(--text-2); }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding: 8px 4px 0; border-bottom: 1px solid var(--border); position: relative; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; min-width: 0; }
.bar > span { display: block; width: 100%; max-width: 46px; background: var(--series-1); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar:hover > span { filter: brightness(.88); }
.bar .tip { position: absolute; bottom: calc(100% - 4px); left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 4px 8px; border-radius: 6px; font-size: .78rem; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .1s; z-index: 2; }
.bar:hover .tip, .bar:focus .tip { opacity: 1; }
.bar-labels { display: flex; gap: 6px; padding: 4px 4px 0; }
.bar-labels span { flex: 1; text-align: center; font-size: .74rem; color: var(--muted); min-width: 0; overflow: hidden; }

/* ---------- Modal / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(13, 24, 41, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.25); width: 100%; max-width: 640px; padding: 20px 22px; }
.modal.wide { max-width: 900px; }
.modal-head { display: flex; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; flex: 1; }
#toast-root { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; font-size: .9rem; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand) 0%, #0b2647 55%, #091d36 100%); }
.login-card { background: var(--surface); border-radius: 14px; padding: 28px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card .brand-logo { width: 56px; height: 56px; font-size: 24px; margin: 0 auto 12px; }
.login-card h1 { text-align: center; font-size: 1.15rem; margin-bottom: 2px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: .85rem; margin-bottom: 20px; }
.login-card button { width: 100%; margin-top: 6px; }

/* ---------- Search results ---------- */
.result-list { border: 1px solid var(--border); border-radius: 8px; max-height: 340px; overflow-y: auto; }
.result-list button { display: flex; width: 100%; justify-content: space-between; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: 10px 12px; font-weight: 500; text-align: left; }
.result-list button:last-child { border-bottom: 0; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; font-size: .92rem; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-weight: 600; }

/* ---------- Documents imprimables ---------- */
.print-only { display: none; }
.doc { background: #fff; color: #000; }
.doc-header { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: start; font-size: 10.5px; text-align: center; border-bottom: 2px solid #000; padding-bottom: 6px; margin-bottom: 8px; }
.doc-header .left, .doc-header .right { text-transform: uppercase; line-height: 1.3; }
.doc-logo { display: block; height: 52px; max-width: 120px; object-fit: contain; margin: 0 auto 3px; }
.doc-header .center .ecole { font-size: 15px; font-weight: 800; letter-spacing: .02em; }
.doc-header .center { line-height: 1.35; }
.doc-title { text-align: center; font-weight: 800; font-size: 15px; margin: 6px 0 8px; letter-spacing: .05em; }
.doc table { font-size: 12px; }
.doc th, .doc td { border: 1px solid #555; padding: 4px 6px; color: #000; background: none; text-transform: none; letter-spacing: 0; }
.doc th { background: #eee; font-size: 11px; }
.recu { position: relative; padding: 24px 18px 12px; border: 1px solid #999; margin-bottom: 0; font-size: 12.5px; }
.recu .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 16px; margin-bottom: 8px; }
.recu .meta b { font-weight: 700; }
.recu .lettres { margin: 8px 0; font-style: italic; }
.recu .signs { display: flex; justify-content: space-between; margin-top: 10px; font-size: 12px; }
.recu .signs div { width: 45%; text-align: center; min-height: 54px; }
.recu .foot { font-size: 10.5px; text-align: center; margin-top: 6px; color: #333; }
.recu .copy-label { position: absolute; top: 3px; right: 8px; font-size: 9px; line-height: 1.3; text-transform: uppercase; border: 1px solid #000; padding: 1px 6px; }
/* Logo en filigrane au fond des reçus */
.recu-fond { position: absolute; left: 50%; top: 56%; transform: translate(-50%, -50%); width: 42%; max-height: 78%; object-fit: contain; opacity: .09; pointer-events: none; z-index: 0; }
.recu > :not(.recu-fond):not(.copy-label):not(.watermark) { position: relative; z-index: 1; }
.watermark { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; pointer-events: none; font-size: 64px; font-weight: 900; color: rgba(180, 35, 24, .22); transform: rotate(-18deg); }
.cut { border-top: 1px dashed #888; margin: 14px 0; position: relative; text-align: center; }
.cut span { position: relative; top: -9px; background: #fff; padding: 0 8px; font-size: 10px; color: #666; }
.doc-preview { background: #fff; padding: 20px; border-radius: var(--radius); border: 1px solid var(--border); max-width: 820px; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; background: none; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .menu-btn { display: inline-flex; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .kv { grid-template-columns: 120px 1fr; }
}

@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; font-size: 12px; }
  .sidebar, .topbar, .no-print, .page-head, .filters, .tabs, #toast-root, .modal-backdrop { display: none !important; }
  .layout { display: block; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0; margin-bottom: 10px; }
  .print-only { display: block; }
  .doc-preview { border: 0; padding: 0; max-width: none; }
  table { font-size: 11px; }
  th, td { padding: 4px 6px; border: 1px solid #999; color: #000; }
  th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { color: #000; }
  .badge { border: 1px solid #999; background: none !important; color: #000 !important; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .tile { box-shadow: none; }
  tr { break-inside: avoid; }
  .recu { padding: 22px 10px 6px; font-size: 11px; border-color: #bbb; break-inside: avoid; }
  .recu .doc-header { font-size: 9px; padding-bottom: 4px; margin-bottom: 4px; }
  .recu .doc-header .center .ecole { font-size: 13px; }
  .recu .doc-logo { height: 40px; margin-bottom: 1px; }
  .recu .doc-title { font-size: 13px; margin: 3px 0 5px; }
  .recu table { font-size: 10.5px; margin-bottom: 4px; }
  .recu th, .recu td { padding: 2px 6px; }
  .recu .meta { margin-bottom: 5px; gap: 1px 16px; }
  .recu .lettres { margin: 4px 0; }
  .recu .signs { margin-top: 4px; }
  .recu .signs div { min-height: 42px; }
  .recu .foot { font-size: 9px; margin-top: 2px; }
  .cut { margin: 8px 0; }
}
