:root {
  /* Couleurs du Groupe Etoile Formation */
  --bg: #eef2f6;
  --surface: #ffffff;
  --ink: #0c2740;
  --muted: #5a6b7d;
  --line: #d5dde6;
  --accent: #0b5f96;
  --accent-hover: #084b77;
  --accent-ink: #ffffff;
  --ok: #157a52;
  --warn: #9a6210;
  --danger: #c8202a;
  --font: "Instrument Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.5; }
a { color: var(--accent); text-underline-offset: 2px; }
h1 { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.01em; margin: 0; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
h2 { font-size: 1rem; font-weight: 600; margin: 0 0 1rem; }
small { font-size: .85rem; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Structure */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; background: linear-gradient(90deg, var(--ink) 220px, var(--bg) 220px); }
.side { background: var(--ink); color: #d4e0ec; padding: 1.5rem 1rem; display: flex; flex-direction: column; gap: 2rem; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: .6rem; color: #fff; text-decoration: none; padding: 0 .6rem; }
.brand-logo { background: #fff; border-radius: 10px; padding: .55rem .7rem; display: block; width: 100%; }
.brand-logo img { display: block; max-width: 100%; max-height: 110px; margin: 0 auto; }
.brand-name { font-size: 1.05rem; font-weight: 600; letter-spacing: .01em; color: #d4e0ec; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: inherit; text-decoration: none; padding: .55rem .6rem; border-radius: 6px; }
.side nav a:hover { background: rgba(255,255,255,.07); }
.side nav a.on { background: rgba(255,255,255,.13); color: #fff; font-weight: 600; }
.me { margin-top: auto; padding: 0 .6rem; display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
.me .link { color: #9fb6cc; }
.main { padding: 2rem 2.5rem 4rem; max-width: 1240px; width: 100%; }
.bare { max-width: 760px; margin: 0 auto; padding: 3rem 1.25rem; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.head p { margin: .35rem 0 0; }
.head-actions { display: flex; gap: .5rem; }
.cols { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.25rem; align-items: start; margin-bottom: 1.25rem; }
.stack { display: flex; flex-direction: column; gap: 1.25rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 1.25rem 1.4rem; margin-bottom: 1.25rem; }
.cols > .panel, .stack > .panel { margin-bottom: 0; }

/* Chiffres clés : montants en grand, chiffres tabulaires */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); border: 1px solid var(--line); border-radius: 10px; background: var(--surface); margin-bottom: 1.25rem; overflow: hidden; }
.figures > div { padding: 1.1rem 1.4rem; border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.figures > div:first-child { border-left: 0; }
.figures strong { font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.figures span { color: var(--muted); font-size: .9rem; }
.figures .alert strong { color: var(--danger); }

/* Histogramme */
.chart { display: flex; align-items: flex-end; gap: .75rem; height: 200px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: .3rem; }
.chart .stick { width: 100%; max-width: 46px; background: var(--accent); border-radius: 4px 4px 0 0; }
.chart .val { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart .lbl { font-size: .8rem; color: var(--muted); }

/* Tableaux */
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: .85rem; padding: .5rem .6rem; border-bottom: 1px solid var(--line); }
.tbl td { padding: .65rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
body > .shell .main > .tbl { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.num, .tbl .num { text-align: right; white-space: nowrap; }
tr.voided td, li.voided { color: var(--muted); text-decoration: line-through; }

/* Barre d'encaissement : l'élément signature */
.bar { display: inline-block; width: 110px; height: 8px; background: #e2e8e5; border-radius: 4px; overflow: hidden; vertical-align: middle; }
.bar > span { display: block; height: 100%; background: var(--accent); }

.badge { font-size: .78rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; white-space: nowrap; }
.badge-pending { background: #e7ecea; color: var(--muted); }
.badge-partial { background: #fbefd9; color: var(--warn); }
.badge-paid { background: #d8efe5; color: var(--ok); }
.badge-overdue { background: #fbe0dd; color: var(--danger); }
.badge-cancelled { background: #e7ecea; color: var(--muted); text-decoration: line-through; }

/* Formulaires */
.form { display: flex; flex-direction: column; gap: .9rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: .55rem .65rem; width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(11,95,150,.18); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.grid4 { display: grid; grid-template-columns: 2fr 1fr 1fr .7fr; gap: .9rem; }
.items td { padding: .35rem .3rem; }
.items .w-qty { width: 80px; } .items .w-price { width: 150px; }
.actions { display: flex; gap: .6rem; justify-content: flex-end; }
.filters { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1.25rem; }
.filters input[type=search] { width: 260px; } .filters select, .filters input[type=date] { width: auto; }
.filters label { flex-direction: row; align-items: center; }
.copy { display: flex; gap: .5rem; }

.btn { font: inherit; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; padding: .55rem 1rem; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #efc4bf; background: #fff; }
.btn.big { font-size: 1.1rem; padding: .8rem 1.4rem; width: 100%; }
.link { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link.danger { color: var(--danger); font-size: .85rem; }

/* Facture */
.totals { display: grid; grid-template-columns: auto auto; justify-content: end; gap: .3rem 2rem; margin: 1.25rem 0 0; font-variant-numeric: tabular-nums; }
.totals dt { color: var(--muted); } .totals dd { margin: 0; text-align: right; }
.totals .due { font-weight: 700; font-size: 1.15rem; color: var(--ink); padding-top: .4rem; border-top: 1px solid var(--line); }
.parties { margin-bottom: 1.25rem; }
.notes { white-space: pre-line; color: var(--muted); border-top: 1px solid var(--line); padding-top: 1rem; margin-top: 1.25rem; }
.public h1 { margin-bottom: .25rem; }
.public form { margin-top: 1.5rem; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .7rem 0 .7rem 1rem; border-left: 2px solid var(--accent); display: flex; flex-direction: column; gap: .15rem; }
.timeline li.voided { border-left-color: var(--line); }
.timeline form { margin-top: .2rem; }

.flash { padding: .7rem 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid; }
.flash-success { background: #e4f4ec; border-color: #b6dfca; color: #0b5c43; }
.flash-error { background: #fdecea; border-color: #f2c2bc; color: var(--danger); }
.flash-info { background: #eef1f0; border-color: var(--line); }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: 10px; padding: 2rem; text-align: center; color: var(--muted); }
.pager { display: flex; gap: .3rem; margin-top: 1rem; }
.pager a { padding: .3rem .65rem; border-radius: 6px; text-decoration: none; }
.pager a.on { background: var(--ink); color: #fff; }

.login { max-width: 380px; margin: 8vh auto 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 2rem; display: flex; flex-direction: column; gap: 1rem; }
.login h1 { font-size: 1.4rem; text-align: center; justify-content: center; }
.login-logo { display: block; width: 150px; margin: 0 auto -.25rem; }
.login p { text-align: center; }
.login p { margin: -.5rem 0 .25rem; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; background: var(--bg); }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 1rem; padding: 1rem; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .me { margin: 0 0 0 auto; flex-direction: row; gap: .75rem; }
  .main { padding: 1.25rem 1rem 3rem; }
  .cols, .grid2, .grid4 { grid-template-columns: 1fr; }
  .tbl { display: block; overflow-x: auto; }
}

@media print {
  .side, .no-print, .flash, .head-actions { display: none !important; }
  .shell { display: block; } .main { padding: 0; }
  .cols { display: block; } .panel { border: 0; padding: 0; }
  body { background: #fff; }
}
#add-line { align-self: flex-start; }

/* ---------- Scolarité ---------- */
.lvl { display: inline-block; font-size: .72rem; font-weight: 700; padding: .05rem .4rem; border-radius: 4px; vertical-align: 1px; }
.lvl-BTP { background: #e3ecf7; color: #1f4f8a; }
.lvl-BTS { background: #efe6f6; color: #6a3d8f; }
.badge-a_jour { background: #e7ecea; color: var(--muted); }
.badge-en_retard { background: #fbe0dd; color: var(--danger); }
.badge-solde { background: #d8efe5; color: var(--ok); }
.badge-abandon { background: #e7ecea; color: var(--muted); text-decoration: line-through; }
.state { font-size: .85rem; font-weight: 500; }
.state-payee { color: var(--ok); }
.state-retard { color: var(--danger); font-weight: 600; }
.state-partielle { color: var(--warn); }
.state-a_venir { color: var(--muted); }
.late, a.late { color: var(--danger); font-weight: 600; }
.totals.left { justify-content: start; }
.totals .late { color: var(--danger); font-weight: 600; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .9rem; }
h2.sep { margin-top: .75rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.form h2 { margin-bottom: 0; }
.tabs { display: flex; gap: .25rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; }
.big-input { font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.quick { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: -.4rem; }
.chip { font: inherit; font-size: .82rem; border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: .2rem .7rem; cursor: pointer; color: var(--ink); }
.chip:hover { border-color: var(--accent); }
.panel.done { border-color: #b6dfca; background: #f2faf6; }
.stack-sm { display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; }
.receipt-cta { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.inline-select { margin-top: .4rem; }
.inline-select label { flex-direction: row; align-items: center; gap: .5rem; }
.inline-select select { width: auto; padding: .25rem .5rem; }
label.check { flex-direction: row; align-items: center; gap: .4rem; }
label.check input { width: auto; }
.items .w-date { width: 170px; }
.fees input { padding: .4rem .5rem; }
.fees td { padding: .35rem .4rem; }
.sum-check { margin: 0; font-variant-numeric: tabular-nums; }
.sum-check.ok { color: var(--ok); } .sum-check.ko { color: var(--danger); }
small.muted a, a.small { font-size: .85rem; }

/* Reçu imprimable : deux exemplaires sur une page A4 */
.receipt-page { background: #fff; }
.receipt-tools { display: flex; gap: .5rem; padding: 1rem; justify-content: center; }
.receipt { max-width: 760px; margin: 0 auto 1.5rem; border: 1px solid var(--ink); padding: 1.25rem 1.5rem; position: relative; page-break-inside: avoid; }
.receipt + .receipt { border-top: 1px dashed var(--ink); }
.receipt header { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 2px solid var(--ink); padding-bottom: .75rem; margin-bottom: .75rem; }
.receipt .rnum { text-align: right; display: flex; flex-direction: column; }
.receipt .rnum strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.receipt .rnum small, .receipt .rnum span { color: var(--muted); font-size: .8rem; }
.rtbl { width: 100%; border-collapse: collapse; }
.rtbl th { text-align: left; font-weight: 500; color: var(--muted); width: 130px; padding: .3rem 0; vertical-align: top; }
.rtbl td { padding: .3rem 0; }
.rtbl .amount { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.receipt footer { display: flex; justify-content: space-between; margin-top: 1rem; font-size: .9rem; }
.receipt .sign { width: 200px; height: 60px; border-bottom: 1px solid var(--muted); color: var(--muted); font-size: .8rem; }
.void-stamp { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-12deg); font-size: 3.5rem; font-weight: 700; color: rgba(180,35,24,.25); border: 4px solid rgba(180,35,24,.25); padding: 0 1rem; margin: 0; }
@media print { .receipt { margin: 0 0 8mm; } @page { size: A4; margin: 10mm; } }
@media (max-width: 900px) { .grid3 { grid-template-columns: 1fr; } }

/* Logo sur les reçus et dans les paramètres */
.receipt header { align-items: center; }
.r-logo { width: 70px; height: auto; }
.r-center { flex: 1; }
.logo-row { display: flex; gap: 1rem; align-items: center; }
.logo-row img { width: 90px; height: auto; border: 1px solid var(--line); border-radius: 8px; padding: .4rem; background: #fff; }

/* Import Excel */
.cols.even { grid-template-columns: 1fr 1fr; }
.import-card { display: flex; flex-direction: column; gap: .75rem; }
.import-card p { margin: 0; }
.import-card .btn { align-self: flex-start; }
.small { font-size: .85rem; }
.drop { border: 2px dashed var(--line); border-radius: 10px; padding: 1.4rem; text-align: center; cursor: pointer; color: var(--accent); font-weight: 600; }
.drop:hover, .drop:focus-within { border-color: var(--accent); background: #f3f8fc; }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.import-status { margin: .5rem 0 0; min-height: 1.2em; }
.import-summary { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-bottom: 1rem; font-weight: 500; }
.import-summary .ok { color: var(--ok); } .import-summary .ko { color: var(--danger); }
.scroll-x { overflow-x: auto; max-height: 60vh; overflow-y: auto; margin-bottom: 1rem; }
.preview tr.row-ko td { background: #fdf3f2; }
@media (max-width: 900px) { .cols.even { grid-template-columns: 1fr; } }

/* Actions groupées */
.bulk-bar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .6rem 1rem; margin-bottom: .75rem; }
.bulk-bar .bulk-delete { margin-left: auto; }
.bulk-bar .bulk-delete:disabled { opacity: .45; cursor: not-allowed; }
.tbl .w-check { width: 34px; }
.tbl input[type=checkbox] { width: 16px; height: 16px; }
tr.selected td { background: #f3f8fc; }
.row-actions form { display: flex; gap: .75rem; justify-content: flex-end; }
.danger-zone { border-color: #efc4bf; }
.danger-zone h2 { color: var(--danger); }
.danger-zone .grid2 > div { display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; }
.danger-zone p { margin: 0; }

/* Frais par année scolaire */
.year-tabs { flex-wrap: wrap; }
.year-tabs a { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.25; }
.year-tabs small { font-size: .72rem; font-weight: 400; }
.year-tabs small.todo, .fees small.todo { color: var(--warn); font-weight: 600; }
.fees tr.undefined td { background: #fff8ec; }
.fees small.todo { display: block; font-size: .75rem; margin-top: .15rem; }
small.late { color: var(--danger); font-weight: 600; }
.flash-warn { background: #fff4e0; border-color: #f0d29b; color: #7a4d06; }
.fees .w-name { width: 34%; }
.fees .w-price { width: 120px; }
.fees .w-qty { width: 72px; }

/* Ajouter / supprimer une année scolaire */
.add-year { margin-left: auto; align-self: center; position: relative; }
.add-year summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: .5rem .9rem; list-style: none; border: 1px dashed var(--accent); border-radius: 8px; }
.add-year summary::-webkit-details-marker { display: none; }
.add-year[open] summary { background: #f3f8fc; }
.add-year-form { position: absolute; right: 0; top: calc(100% + .4rem); z-index: 5; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; display: flex; flex-direction: column; gap: .6rem; width: 260px; box-shadow: 0 8px 24px rgba(12,39,64,.12); }
.add-year-form select { width: 100%; }
.delete-year { display: flex; gap: .75rem; align-items: baseline; margin: -.5rem 0 1.25rem; }
@media (max-width: 900px) { .add-year { margin-left: 0; } .add-year-form { position: static; width: auto; box-shadow: none; } }
.preview tr.row-done td { color: var(--muted); }

/* Reçus en PDF */
.pdf-page { background: var(--bg); }
.pdf-box { max-width: 520px; margin: 8vh auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 2rem; text-align: center; }
.pdf-box h1 { justify-content: center; font-size: 1.35rem; margin-top: .75rem; }
.pdf-logo { width: 110px; height: auto; }
.pdf-count { font-size: 1.05rem; margin: .5rem 0 1.25rem; }
.pdf-layout { border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem; text-align: left; display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1.25rem; }
.pdf-layout legend { font-size: .85rem; color: var(--muted); padding: 0 .3rem; }
.pdf-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.pdf-status { min-height: 1.4em; margin-top: 1rem; }
.panel-head .btn { padding: .35rem .75rem; font-size: .9rem; }
.list-note { margin: -.25rem 0 .75rem; font-size: .9rem; }

/* Utilisateurs par spécialité */
.spec-fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem; display: flex; flex-direction: column; gap: .6rem; }
.spec-fieldset legend { font-size: .9rem; color: var(--muted); padding: 0 .3rem; }
.spec-group { display: flex; flex-direction: column; gap: .3rem; }
.spec-group .lvl { align-self: flex-start; margin-bottom: .1rem; }
.spec-group label.check { color: var(--ink); font-size: .9rem; }
.user-specs { max-width: 320px; }
.spec-chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .85rem; margin: 0 .5rem .3rem 0; }
.spec-edit summary { cursor: pointer; color: var(--accent); font-size: .85rem; margin-top: .2rem; }
.spec-edit form { margin-top: .6rem; padding: .75rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.spec-fieldset[hidden] { display: none; }
.me-scope { color: #9fb6cc; font-size: .8rem; }
