:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --text: #1c2230;
  --muted: #687083;
  --primary: #2a6df4;
  --primary-ink: #ffffff;
  --pos: #1f8a4c;
  --neg: #c9372c;
  --warn-bg: #fff4d6;
  --warn-ink: #7a5a00;
  --ok-bg: #e3f5ea;
  --ok-ink: #1d6b3d;
  --err-bg: #fde7e5;
  --err-ink: #a32a20;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1e26;
    --surface-2: #20252f;
    --border: #2d333f;
    --text: #e6e9ef;
    --muted: #9aa3b5;
    --primary: #5b8dff;
    --pos: #4cc685;
    --neg: #ff7a6e;
    --warn-bg: #3a3110;
    --warn-ink: #f3d36b;
    --ok-bg: #133524;
    --ok-ink: #8fe0b2;
    --err-bg: #3d1a17;
    --err-ink: #ffaaa2;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* Volet de navigation latéral */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; flex: 0 0 230px; width: 230px;
  display: flex; flex-direction: column; gap: .5rem; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border); padding: 1.1rem .75rem;
}
.brand { font-weight: 700; color: var(--text); font-size: 1.15rem; padding: 0 .6rem .6rem; }
.brand:hover { text-decoration: none; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-section { margin: 1rem .6rem .3rem; font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.side-nav a { display: flex; align-items: center; justify-content: space-between; padding: .45rem .6rem; border-radius: 6px; color: var(--text); }
.side-nav a:hover { background: var(--surface-2); text-decoration: none; }
.side-nav a.active { background: var(--primary); color: var(--primary-ink); }
.side-nav a.active .badge { background: var(--surface); }
.side-user { border-top: 1px solid var(--border); padding: .8rem .6rem 0; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.side-user-name { font-size: .9rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { flex: 1; min-width: 0; padding: 1.5rem 2rem 3rem; }
/* Écran étroit : le volet repasse au-dessus du contenu. */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { position: static; height: auto; width: auto; flex: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .side-section { display: none; }
  main { padding: 1.25rem 16px 3rem; }
}
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stack > * + * { margin-top: 1rem; }

.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .value { font-size: 1.45rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* Tableaux */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .45rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tfoot td, tr.total td { font-weight: 650; border-top: 2px solid var(--border); }
tbody tr:hover { background: var(--surface-2); }
td.label-cell { max-width: 640px; }
.details { color: var(--muted); font-size: .8rem; white-space: pre-line; }

.swatch { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; margin-right: .4rem; vertical-align: baseline; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar > span { display: block; height: 100%; background: var(--primary); width: 0; }

.badge { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }

/* Formulaires */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=file], select {
  width: 100%; padding: .45rem .55rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit;
}
input[type=color] { width: 2.6rem; height: 2.1rem; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; }
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 140px; }
.row > .shrink { flex: 0 0 auto; }
.check { display: inline-flex; gap: .35rem; align-items: center; color: var(--text); font-size: .9rem; margin: 0; }

.btn {
  display: inline-block; padding: .45rem .9rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--neg); }
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
.inline { display: inline; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash.err { background: var(--err-bg); color: var(--err-ink); }
.flash ul { margin: 0; padding-left: 1.2rem; }

.tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs a { padding: .3rem .65rem; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: .9rem; }
.tabs a.active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.tabs a:hover { text-decoration: none; }

.chart-box { position: relative; height: 280px; }

details.edit summary { cursor: pointer; color: var(--primary); font-size: .85rem; list-style: none; }
details.edit summary::-webkit-details-marker { display: none; }
details.edit[open] { background: var(--surface-2); padding: .5rem; border-radius: 6px; }
details.edit form { margin-top: .5rem; display: grid; gap: .4rem; min-width: 240px; }

/* Connexion */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login h1 { margin-bottom: 1rem; }
.login form > * + * { margin-top: .8rem; }
.login .btn { width: 100%; }

@media (max-width: 640px) {
  .hide-sm { display: none; }
  .kpi .value { font-size: 1.2rem; }
  main { padding-top: 1rem; }
}
.mt { margin-top: 1rem; }
a.inherit { color: inherit; }
a.card { color: inherit; }
a.card:hover { text-decoration: none; border-color: var(--primary); }
.cat-table .group-row td { font-weight: 600; }
.cat-table .group-row.muted td { font-weight: 400; }
.cat-table .child-row td { border-bottom-style: dashed; padding-top: .2rem; padding-bottom: .2rem; }
.cat-table .child-row td:first-child { padding-left: 1.6rem; font-weight: 400; }
.triage-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.triage-title { min-width: 0; overflow-wrap: anywhere; }
.triage-amount { font-size: 1.1rem; font-weight: 650; }
.row > .grow2 { flex: 2 1 220px; }
summary { cursor: pointer; color: var(--primary); }
.side-nav .badge { margin-left: .3rem; }
.entry-form { max-width: 720px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; padding: 3px; gap: 3px; margin: 0; }
.segmented label { margin: 0; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: .45rem 1.2rem; border-radius: 6px; color: var(--muted); font-size: .95rem; }
.segmented input:checked + span { background: var(--primary); color: var(--primary-ink); }
.segmented input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 1px; }
input.big { font-size: 1.3rem; font-weight: 600; }
.big-btn { padding: .6rem 1.4rem; font-size: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
td.actions { white-space: nowrap; }

/* Liste et fiche d'une opération */
.nowrap { white-space: nowrap; }
.pre { white-space: pre-line; }
.pager { align-items: center; justify-content: space-between; }
.amount-big { font-size: 1.8rem; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dl { display: grid; grid-template-columns: minmax(110px, max-content) 1fr; gap: .45rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-size: .85rem; padding-top: .1rem; }
.dl dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { .dl { grid-template-columns: 1fr; gap: .1rem; } .dl dd { margin-bottom: .5rem; } }

/* Prévisionnel */
.badge.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }
ul.plain { list-style: none; padding: 0; margin: .3rem 0 0; }
ul.plain li { padding: .1rem 0; }
.day-input { width: 4.5rem; }
details.edit.wide[open] { min-width: min(720px, 80vw); }
details.edit form.item-form { display: block; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }

/* Double authentification */
.side-user-info { min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.side-user-info a { color: var(--muted); }
.side-user-info a.active, .side-user-info a:hover { color: var(--primary); }
.qr { display: inline-block; background: #fff; padding: 8px; border-radius: 8px; border: 1px solid var(--border); line-height: 0; }
.qr svg { width: 220px; height: 220px; }
code.secret { font-size: 1rem; letter-spacing: .05em; word-break: break-all; }
.otp-input { font-size: 1.3rem; letter-spacing: .25em; font-variant-numeric: tabular-nums; max-width: 14rem; }
.code-list { list-style: none; padding: 0; margin: .75rem 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; }
.code-list code { display: block; padding: .4rem .6rem; background: var(--surface-2); border-radius: 6px; font-size: 1rem; text-align: center; }
.mfa-codes { border-color: var(--primary); }

.btn.block { display: block; width: 100%; margin: .75rem 0 .4rem; }
ol.steps { padding-left: 1.2rem; margin: .4rem 0 .8rem; }
form[data-webauthn-register] .flash { flex-basis: 100%; margin: .4rem 0 0; }
