/* Typographies de la charte MLOCTET+ : DIN Pro (textes), Roketto (titre principal, avec parcimonie) */
@font-face { font-family: "DIN Pro"; src: url("/fonts/dinpro-300.woff2") format("woff2"); font-weight: 300; font-display: swap; }
@font-face { font-family: "DIN Pro"; src: url("/fonts/dinpro-400.woff2") format("woff2"); font-weight: 400 500; font-display: swap; }
@font-face { font-family: "DIN Pro"; src: url("/fonts/dinpro-700.woff2") format("woff2"); font-weight: 600 800; font-display: swap; }
@font-face { font-family: "Roketto"; src: url("/fonts/roketto.woff2") format("woff2"); font-display: swap; }
.brand-title { font-family: "Roketto", "DIN Pro", system-ui, sans-serif; font-weight: 400; letter-spacing: .01em; }

:root {
  /* Charte MLOCTET+ : bleu #16417b, crème #fff0db, blanc */
  --blue: #16417b;
  --cream: #fff0db;
  --bg: #fdf8f0;
  --surface: #ffffff;
  --surface-2: #fff4e4;
  --text: #0f2747;
  --muted: #5d6c83;
  --border: #eadfcc;
  --brand: #16417b;
  --brand-ink: #fff0db;
  --brand-soft: #fff0db;
  --nav-bg: #16417b;
  --nav-ink: #fff0db;
  --ok: #18794e;
  --ok-soft: #e3f4ea;
  --warn: #a35200;
  --warn-soft: #fde9cf;
  --bad: #c42b2b;
  --bad-soft: #fbe5e5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(22, 65, 123, .06), 0 2px 6px rgba(22, 65, 123, .06);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a182c;
    --surface: #10243f;
    --surface-2: #17304f;
    --text: #fff6ea;
    --muted: #a9b6cb;
    --border: #213d63;
    --brand: #fff0db;
    --brand-ink: #16417b;
    --brand-soft: #1b3a63;
    --nav-bg: #0d1f38;
    --nav-ink: #fff0db;
    --ok: #4cc38a;
    --ok-soft: #12301f;
    --warn: #f0a548;
    --warn-soft: #33240f;
    --bad: #ff7b7b;
    --bad-soft: #3a1a1d;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15.5px/1.45 "DIN Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 24px; font-weight: 700; margin: 0 0 4px; color: var(--brand); }
@media (prefers-color-scheme: dark) { h1 { color: var(--text); } }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13.5px; }

/* --- layout --- */
.app { display: flex; min-height: 100vh; }
.nav {
  /* La zone de la barre d'accueil iPhone s'AJOUTE à la hauteur de la barre (elle ne doit pas l'écraser). */
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 20;
  display: flex; background: var(--nav-bg); border-top: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav .brand { display: none; }
.nav .brand img { width: 168px; display: block; }
.topbar { display: flex; align-items: center; justify-content: center; background: var(--nav-bg); padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); }
.topbar img { height: 34px; }
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--nav-ink); opacity: .72; font-size: 11.5px; font-weight: 600; position: relative;
}
.nav a svg { width: 24px; height: 24px; flex-shrink: 0; }
.nav a.active { color: var(--nav-ink); opacity: 1; }
.nav a.active svg { stroke-width: 2.4; }
.nav .badge { position: absolute; top: 6px; left: calc(50% + 6px); }
main { flex: 1; min-width: 0; padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); max-width: 1100px; margin: 0 auto; }
@media (min-width: 900px) {
  .nav { position: sticky; top: 0; height: 100vh; width: 220px; flex-direction: column; border-top: 0; border-right: 1px solid var(--border); padding: 16px 10px; gap: 2px; }
  .nav .brand { display: block; padding: 8px 10px 26px; }
  .topbar { display: none; }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 10px; font-size: 14.5px; padding: 10px 12px; border-radius: 8px; }
  .nav a:hover { opacity: 1; background: rgba(255, 240, 219, .08); }
  .nav a.active { background: rgba(255, 240, 219, .16); }
  .nav .who { margin-top: auto; color: var(--nav-ink); opacity: .7; font-size: 12.5px; padding: 8px 12px; }
  .nav .badge { position: static; margin-left: auto; }
  main { padding: 28px 32px 40px; }
}

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

/* --- surfaces --- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card, .stack > * + * { margin-top: 12px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 12px; }
.grid.kpis { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 700px) { .grid.kpis { grid-template-columns: repeat(4, 1fr); } .grid.two { grid-template-columns: 1fr 1fr; } }
.kpi { padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 13px; }
.kpi.alert { border-color: var(--warn); background: var(--warn-soft); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.list a.row { display: flex; align-items: center; gap: 12px; color: inherit; width: 100%; }
.qty { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 17px; text-align: right; white-space: nowrap; }

/* --- controls --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; cursor: pointer; min-height: 44px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions.end { justify-content: flex-end; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }


.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); padding: 6px 12px; border-radius: 99px; font: inherit; font-size: 13.5px; cursor: pointer; color: var(--text); }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; font-size: 11.5px; font-weight: 700; background: var(--bad); color: #fff; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.brand { background: var(--brand-soft); color: var(--brand); }

.notice { padding: 12px 14px; border-radius: 10px; background: var(--brand-soft); font-size: 14px; }
.notice.warn { background: var(--warn-soft); }


/* --- toast / modal --- */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 60; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
@media (min-width: 900px) { #toasts { bottom: 24px; } }
.toast { padding: 12px 14px; border-radius: 10px; background: var(--text); color: var(--bg); font-weight: 500; box-shadow: 0 6px 24px rgba(0,0,0,.2); animation: pop .15s ease-out; }
.toast.ok { background: var(--ok); color: #fff; } .toast.bad { background: var(--bad); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 18px; }
@media (min-width: 700px) { .modal { align-items: center; } .modal .sheet { border-radius: 16px; } }

.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.skeleton { color: var(--muted); padding: 30px; text-align: center; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12.5px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.t td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.scroll-x { overflow-x: auto; }
.login { max-width: 380px; margin: 14vh auto 0; text-align: center; }
.login img { width: 240px; margin: 4px auto 14px; display: block; }
.login form { text-align: left; }
.nav .who { display: none; }
@media (min-width: 900px) { .nav .who { display: block; } }
.kpi .v { color: var(--brand); }
@media (prefers-color-scheme: dark) { .kpi .v { color: var(--text); } }
.nav:empty { display: none; }

/* ================================================================ Compta */
:root { --s-cur: #2a5ea8; --s-prev: #c8742a; --grid: #ece3d4; }
@media (prefers-color-scheme: dark) { :root { --s-cur: #5b8fe0; --s-prev: #d07f28; --grid: #213d63; } }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--bad); }
.pos { color: var(--ok); }
.kpi .d { font-size: 12.5px; margin-top: 2px; color: var(--muted); }
.kpi .d b { font-weight: 700; }
.kpi .v.neg { color: var(--bad); }
.yearbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sub { color: var(--muted); font-size: 13px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 22px 0 10px; flex-wrap: wrap; }
.section-title h2 { margin: 0; }

/* encart objectif en attente */
.placeholder { border: 1.5px dashed var(--border); background: transparent; box-shadow: none; display: flex; gap: 14px; align-items: center; }
.placeholder .ic { width: 40px; height: 40px; border-radius: 10px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--muted); flex: none; }
.placeholder .ic svg { width: 22px; height: 22px; }

/* tableau mensuel */
table.months { min-width: 860px; }
table.months th, table.months td { padding: 9px 10px; }
table.months th { text-align: right; white-space: nowrap; }
table.months th:first-child, table.months td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; }
table.months tbody tr.clickable { cursor: pointer; }
table.months tbody tr.clickable:hover td { background: var(--surface-2); }
table.months tr.current td { font-style: italic; }
table.months tr.off td { color: var(--muted); opacity: .6; }
table.months tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }
table.months td.result { font-weight: 700; }
table.t td.wrap { white-space: normal; min-width: 160px; }

/* graphiques */
.charts { display: grid; gap: 12px; }
@media (min-width: 980px) { .charts { grid-template-columns: 3fr 2fr; } }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--muted); stroke-width: 1; opacity: .5; }
.chart .label { fill: var(--text); font-size: 11.5px; font-weight: 700; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.legend i.sq { width: 10px; height: 10px; border-radius: 3px; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12.5px; padding: 8px 10px; border-radius: 8px; white-space: nowrap; z-index: 5; box-shadow: 0 4px 16px rgba(0,0,0,.18); transform: translate(-50%, calc(-100% - 10px)); }
.tip b { font-weight: 700; }
.tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

/* compte de résultat du mois */
.pl { list-style: none; margin: 0; padding: 0; }
.pl li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); }
.pl li:first-child { border-top: 0; }
.pl li.total { font-weight: 700; border-top: 2px solid var(--border); }
.pl li .k { color: var(--muted); }
.pl li.total .k { color: var(--text); }
.pl li.sub-line { padding-left: 16px; font-size: 13.5px; }
.monthnav { display: flex; gap: 6px; align-items: center; }
.monthnav .btn { min-width: 44px; padding: 8px; }
select.sm { min-height: 34px; padding: 4px 8px; font-size: 13.5px; width: auto; }

/* connexion et double authentification */
.login .card { text-align: left; }
.login h2 { margin-top: 0; }
.qr { background: #fff; padding: 12px; border-radius: 12px; width: 220px; margin: 8px auto 12px; }
.qr img { width: 100%; display: block; image-rendering: pixelated; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 16px; background: var(--surface-2); padding: 14px; border-radius: 10px; margin: 10px 0; }
input.otp { font-size: 24px; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.linkbtn { background: none; border: 0; color: var(--brand); font: inherit; cursor: pointer; padding: 6px 0; text-decoration: underline; }
.steps { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.form-grid { display: grid; gap: 0 12px; }
@media (min-width: 600px) { .form-grid { grid-template-columns: 1fr 1fr; } }
table.t th.num { text-align: right; }
@media (prefers-color-scheme: dark) { .login img.logo-light { content: url("/icons/logo-cream.svg"); } }

/* tableau des charges */
:root { --cat-0: #2a5ea8; --cat-1: #c8742a; --cat-2: #2f8f83; --cat-3: #8a5bb8; --cat-4: #c2477a; --cat-5: #7a8a2e; --cat-6: #5d6c83; }
@media (prefers-color-scheme: dark) { :root { --cat-0: #5b8fe0; --cat-1: #d07f28; --cat-2: #3fae9f; --cat-3: #a57ad6; --cat-4: #df6b98; --cat-5: #9cad44; --cat-6: #8d9bb0; } }
.stackbar { display: flex; gap: 2px; height: 14px; border-radius: 4px; overflow: hidden; }
.stackbar span { min-width: 3px; }
table.charges { min-width: 1080px; font-size: 13px; }
table.charges th, table.charges td.num { padding-left: 4px; padding-right: 6px; }
table.charges th, table.charges td { padding: 7px 7px; }
table.charges th:first-child, table.charges td.lbl { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 190px; max-width: 230px; text-align: left; }
table.charges tr.cat { cursor: pointer; }
table.charges tr.cat td { background: var(--surface-2); }
table.charges tr.cat[data-empty] { cursor: default; opacity: .6; }
table.charges tr.line td.lbl { padding-left: 22px; }
table.charges tr.ca td { font-weight: 700; }
table.charges .curcol { font-style: italic; color: var(--muted); }
table.charges tfoot td { font-weight: 700; border-top: 2px solid var(--border); }
table.charges .caret { display: inline-block; width: 12px; color: var(--muted); }
