:root {
  color-scheme: light;
  --bg: #f5ecdd;
  --surface: #fffaf3;
  --surface-2: #efe3cf;
  --border: #e3d3b9;
  --ink: #3a2a18;
  --ink-2: #6b5640;
  --muted: #8a7560;
  --brand: #c79f6a;
  --brand-strong: #a86a1e;
  --brand-deep: #7a4c14;
  --on-brand: #ffffff;
  --green: #2e9e78;
  --danger: #b3412e;
  --bar: #a86a1e;
  --temp: #2f7bc8;
  --norm: #8f8a80;
  --grid: #eadcc6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s-other: #a8a196;
  --shadow: 0 1px 2px rgba(58, 42, 24, .06), 0 6px 20px rgba(58, 42, 24, .08);
  --radius: 18px;
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #17120d; --surface: #211b14; --surface-2: #2c241a; --border: #3a3024;
    --ink: #f3e9da; --ink-2: #cdbba2; --muted: #a08c72;
    --brand: #c79f6a; --brand-strong: #c4842f; --brand-deep: #e0b57a; --on-brand: #1b130a;
    --green: #3fb48c; --danger: #e0715c;
    --bar: #c4842f; --temp: #3f8ad6; --norm: #9a958b; --grid: #34291d;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s-other: #6f6a61;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #17120d; --surface: #211b14; --surface-2: #2c241a; --border: #3a3024;
  --ink: #f3e9da; --ink-2: #cdbba2; --muted: #a08c72;
  --brand: #c79f6a; --brand-strong: #c4842f; --brand-deep: #e0b57a; --on-brand: #1b130a;
  --green: #3fb48c; --danger: #e0715c;
  --bar: #c4842f; --temp: #3f8ad6; --norm: #9a958b; --grid: #34291d;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s-other: #6f6a61;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- structure ---- */
.app { max-width: 560px; margin: 0 auto; min-height: 100%;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.topbar h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
.topbar h1 small { display: block; font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  display: inline-grid; place-items: center; color: var(--ink-2); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn[aria-pressed="true"] { background: var(--brand-strong); border-color: var(--brand-strong); color: var(--on-brand); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; }
.card + .card { margin-top: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--ink-2); font-weight: 600; }

/* ---- onglet Poêle ---- */
.hero { display: flex; flex-direction: column; align-items: center; text-align: center; margin-top: 4px; }
.sac { height: min(34vh, 300px); width: auto; filter: drop-shadow(0 14px 18px rgba(90, 60, 25, .25)); user-select: none;
  -webkit-user-drag: none; transition: transform .25s cubic-bezier(.3, 1.6, .5, 1); }
.sac.bump { transform: scale(.94) rotate(-2deg); }
.remaining { margin-top: 10px; }
.remaining .big { font-size: 64px; font-weight: 800; line-height: 1; letter-spacing: -.03em; color: var(--brand-deep); }
.remaining .lbl { font-size: 17px; font-weight: 600; color: var(--ink-2); margin-top: 2px; }
.remaining .sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.gauge { width: min(280px, 80%); height: 8px; border-radius: 999px; background: var(--surface-2); margin: 12px auto 0; overflow: hidden;
  border: 1px solid var(--border); }
.gauge > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-strong)); border-radius: 999px;
  transition: width .4s ease; }
.gauge.low > span { background: var(--danger); }

.actions { display: grid; grid-template-columns: 64px 1fr; gap: 14px; align-items: center; margin: 22px 0 6px; }
.btn-minus { width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface);
  color: var(--ink-2); display: grid; place-items: center; }
.btn-minus svg { width: 26px; height: 26px; }
.btn-plus { height: 84px; border-radius: 26px; border: 0; color: var(--on-brand);
  background: linear-gradient(160deg, var(--brand) 0%, var(--brand-strong) 70%);
  box-shadow: 0 10px 24px rgba(168, 106, 30, .35), inset 0 1px 0 rgba(255, 255, 255, .25);
  display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 21px; font-weight: 700;
  transition: transform .08s ease; }
.btn-plus svg { width: 34px; height: 34px; }
.btn-plus:active, .btn-minus:active { transform: scale(.97); }
.btn-plus[disabled], .btn-minus[disabled] { opacity: .6; }
.later { display: block; margin: 6px auto 14px; background: none; border: 0; color: var(--brand-deep); font-size: 15px; padding: 8px 12px;
  text-decoration: underline; text-underline-offset: 3px; }

.facts { list-style: none; margin: 0; padding: 0; }
.facts li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); }
.facts li:first-child { border-top: 0; padding-top: 0; }
.facts li span:first-child { color: var(--ink-2); }
.facts li strong { text-align: right; }
.pending { margin-top: 10px; font-size: 14px; color: var(--danger); text-align: center; }

/* ---- onglet Analyse ---- */
.an-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 10px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 8px 14px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--ink-2); min-height: 38px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.views { display: inline-flex; gap: 6px; }
.views .icon-btn { width: 40px; height: 40px; }
.views .icon-btn svg { width: 20px; height: 20px; }
.period { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.period strong { font-size: 18px; text-transform: capitalize; }
.period .icon-btn[disabled] { visibility: hidden; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; }
.kpi .k { font-size: 13px; color: var(--muted); }
.kpi .v { font-size: 24px; font-weight: 750; letter-spacing: -.02em; margin-top: 2px; }
.kpi .v small { font-size: 14px; font-weight: 600; color: var(--ink-2); letter-spacing: 0; }
.kpi .d { font-size: 13px; color: var(--ink-2); margin-top: 2px; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--border); stroke-width: 1.5; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 13px; color: var(--ink-2); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; }
.legend i.line { height: 3px; border-radius: 2px; vertical-align: 3px; width: 16px; }
.legend i.dash { height: 0; border-top: 2px dashed var(--norm); vertical-align: 3px; width: 16px; border-radius: 0; }
.sw-bar { background: var(--bar); }
.sw-est { background: repeating-linear-gradient(135deg, var(--bar) 0 2px, transparent 2px 5px); border: 1px solid var(--bar); }
.sw-temp { background: var(--temp); }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--surface); font-size: 13px; padding: 8px 10px;
  border-radius: 10px; white-space: nowrap; transform: translate(-50%, -100%); margin-top: -8px; box-shadow: var(--shadow); z-index: 3; }
.tip b { display: block; font-size: 13px; text-transform: capitalize; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

.donut-wrap { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: center; }
.donut-wrap svg { width: 150px; height: 150px; }
.pie-legend { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.pie-legend li { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; padding: 4px 0; }
.pie-legend li i { width: 12px; height: 12px; border-radius: 3px; }
.pie-legend span { text-transform: capitalize; }

table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  padding: 0 6px 8px; }
table.list td { padding: 10px 6px; border-top: 1px solid var(--border); }
table.list td:first-child, table.list th:first-child { padding-left: 0; }
table.list td.r, table.list th.r { text-align: right; }
table.list td:first-child::first-letter { text-transform: uppercase; }
table.list tr.future td { color: var(--muted); }
.row-del { border: 0; background: none; color: var(--danger); padding: 6px; border-radius: 8px; }
.row-del svg { width: 18px; height: 18px; display: block; }

.advice { font-size: 15px; }
.advice p { margin: 6px 0; }
.note { font-size: 12.5px; color: var(--muted); margin-top: 10px; }

/* ---- barre d'onglets ---- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.tabbar nav { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr; height: var(--tabbar-h); }
.tabbar button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 12px; font-weight: 600; color: var(--muted); }
.tabbar button svg { width: 26px; height: 26px; }
.tabbar button[aria-selected="true"] { color: var(--brand-strong); }

/* ---- feuilles (modales) ---- */
.sheet-back { position: fixed; inset: 0; background: rgba(20, 12, 4, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 20px); box-shadow: 0 -10px 40px rgba(0, 0, 0, .25); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 10px; }
.sheet header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sheet header h2 { margin: 0; font-size: 19px; }
.field { display: block; margin: 10px 0; }
.field span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; }
.field input, .field select { width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-size: 16px; }
.field input:focus, .field select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { min-height: 48px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); padding: 10px 16px; font-weight: 600;
  width: 100%; }
.btn.primary { background: var(--brand-strong); border-color: var(--brand-strong); color: var(--on-brand); }
.btn.danger { color: var(--danger); }
.btn + .btn { margin-top: 8px; }
.msg { font-size: 14px; margin: 8px 0 0; min-height: 1em; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--green); }
.palettes { list-style: none; padding: 0; margin: 0 0 6px; }
.palettes li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); }
.palettes li:first-child { border-top: 0; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%);
  background: var(--ink); color: var(--surface); padding: 12px 14px 12px 16px; border-radius: 14px; box-shadow: var(--shadow); z-index: 30;
  display: flex; align-items: center; gap: 14px; font-size: 15px; max-width: calc(100% - 32px); width: max-content; }
.toast button { border: 0; background: none; color: var(--brand); font-weight: 700; padding: 6px 4px; }

/* ---- connexion ---- */
.login { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 380px; }
.login img { width: 160px; height: auto; margin-bottom: 4px; }
.login h1 { font-size: 26px; margin: 8px 0 2px; text-align: center; }
.login p.lead { text-align: center; color: var(--muted); margin: 0 0 18px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.card p.muted:first-of-type { margin-top: 0; }
.login-img { width: min(320px, 80%) !important; margin-bottom: 8px; mix-blend-mode: multiply; }
@media (prefers-color-scheme: dark) { .login-img { mix-blend-mode: normal; border-radius: 16px; } }
.chart text.d-total { fill: var(--ink); font-size: 24px; font-weight: 750; }
.chart text.d-unit { fill: var(--muted); font-size: 12px; }
/* iOS Safari : les champs date débordent de la grille et centrent leur texte */
.row2 > * { min-width: 0; }
.field input[type="date"], .field input[type="datetime-local"] {
  -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%;
  height: 46px; line-height: 24px; text-align: left;
}
.field input::-webkit-date-and-time-value { text-align: left; margin: 0; }
