/* Figtree — SIL Open Font License 1.1, voir fonts/OFL.txt */
@font-face {
  font-family: 'Figtree';
  src: url('fonts/figtree-latin-wght-normal.woff2') format('woff2');
  font-weight: 300 900;
  font-style: normal;
  font-display: swap;
}

/* ------------------------------------------------------------ tokens -- */
:root {
  --bg: #fafafa;
  --card: #ffffff;
  --raised: #f4f4f5;
  --text: #171717;
  --text-2: #525252;
  --muted: #737373;
  --line: rgba(23, 23, 23, .08);
  --line-strong: rgba(23, 23, 23, .14);

  --accent: #c2410c;        /* braise, assez foncée pour du texte blanc (5,2:1) */
  --on-accent: #ffffff;
  --accent-ink: #c2410c;    /* accent utilisé comme texte */
  --negative: #dc2626;

  --bar: #d9d9dc;
  --series-past: 115, 115, 115; /* gris des saisons passées (rgb) */

  /* pile de bûches */
  --wood-core: #efd2a4;
  --wood-edge: #c98f55;
  --wood-ring: rgba(120, 70, 30, .28);
  --bark: #6b4426;
  --slot: rgba(23, 23, 23, .06);

  --toast-bg: #171717;
  --toast-text: #fafafa;
  --toast-accent: #f59e66;

  --shadow-float: 0 8px 24px rgba(0, 0, 0, .10), 0 1px 2px rgba(0, 0, 0, .06);

  --ease: cubic-bezier(.22, 1, .36, 1);
  --tabbar-h: 64px;
  --font: 'Figtree', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141415;
    --card: #19191b;
    --raised: #232325;
    --text: #ededed;
    --text-2: #a1a1a6;
    --muted: #85858b;
    --line: rgba(237, 237, 237, .08);
    --line-strong: rgba(237, 237, 237, .14);

    --accent: #f0843f;
    --on-accent: #1a1007;
    --accent-ink: #f0843f;
    --negative: #e5484d;

    --bar: #3a3a3e;
    --series-past: 161, 161, 166;

    --wood-core: #e2c08e;
    --wood-edge: #b37a45;
    --wood-ring: rgba(90, 50, 20, .35);
    --bark: #4a2f1b;
    --slot: rgba(237, 237, 237, .06);

    --toast-bg: #ededed;
    --toast-text: #141415;
    --toast-accent: #c2410c;

    --shadow-float: 0 8px 24px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

/* -------------------------------------------------------------- base -- */
* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 22px;
  background: var(--bg);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 88px);
}

h2 { font-size: 15px; line-height: 20px; font-weight: 600; margin: 0 0 16px; }
dl, dd { margin: 0; }

.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
}
.hidden { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------- shell -- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px;
  padding: env(safe-area-inset-top) 16px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 600; }
.brand-mark { color: var(--accent-ink); }

.stock-meta { font-size: 13px; color: var(--muted); }
.stock-meta.low { color: var(--accent-ink); font-weight: 500; }
.stock-meta.out { color: var(--negative); font-weight: 500; }

main { max-width: 720px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.active { display: block; animation: enter 300ms var(--ease); }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 12px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head h2 { margin: 0; }
.meta { font-size: 13px; line-height: 16px; color: var(--muted); text-align: right; }
.note { font-size: 13px; line-height: 20px; color: var(--muted); margin: 16px 0 0; }
.version { font-size: 13px; color: var(--muted); text-align: center; margin: 24px 0 0; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 24px 0; margin: 0; list-style: none; }

/* --------------------------------------------------------- formulaires -- */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; line-height: 16px; color: var(--text-2); margin-bottom: 8px; }

input, select, button, .button { font: inherit; color: inherit; }
input[type=date], input[type=number], input[type=text], .field select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--raised);
  transition: border-color 150ms var(--ease);
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

.stepper { display: flex; gap: 8px; }
.stepper input { text-align: center; font-size: 28px; font-weight: 500; min-height: 56px; }
.step {
  width: 56px; flex: none; min-height: 56px; padding: 0;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--raised); color: var(--text);
}
.quick { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.quick button {
  flex: 1; min-width: 48px; min-height: 36px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: transparent; color: var(--text-2); font-size: 14px;
}
.quick button.on { border-color: var(--accent); color: var(--accent-ink); font-weight: 500; }

/* ----------------------------------------------------------- boutons -- */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 10px;
  background: transparent; cursor: pointer;
  font-size: 15px; font-weight: 500;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease), transform 150ms var(--ease);
}
button:active, .button:active { transform: scale(.98); }
.actions { display: flex; gap: 8px; }
.actions.wrap { flex-wrap: wrap; }
.actions.wrap > * { flex: 1 1 140px; }
.primary { flex: 1; background: var(--accent); color: var(--on-accent); }
.secondary { background: var(--raised); border-color: var(--line-strong); color: var(--text); }
.destructive { margin-top: 16px; border-color: var(--line-strong); color: var(--negative); }
@media (hover: hover) {
  .secondary:hover, .step:hover { border-color: var(--text-2); }
  .icon-btn:hover { color: var(--text); background: var(--raised); }
}

/* ------------------------------------------------- titres sélecteurs -- */
.title-select { position: relative; display: inline-flex; align-items: center; margin-bottom: 16px; }
.title-select select {
  appearance: none; -webkit-appearance: none;
  border: none; background: transparent;
  font-size: 22px; line-height: 28px; font-weight: 500;
  padding: 0 28px 0 0; cursor: pointer;
}
.title-select .icon { position: absolute; right: 0; pointer-events: none; color: var(--muted); }

/* -------------------------------------------------- chiffre principal -- */
.hero { display: flex; align-items: baseline; gap: 8px; }
.hero .v { font-size: 48px; line-height: 52px; font-weight: 500; letter-spacing: -.02em; }
.hero .u { font-size: 15px; color: var(--text-2); }
.hero-sub { font-size: 14px; line-height: 20px; color: var(--text-2); margin-top: 4px; }
.hero-sub .trend { color: var(--muted); }

.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 20px; }
.stat .v { font-size: 24px; line-height: 28px; font-weight: 500; }
.stat .l { font-size: 13px; line-height: 16px; color: var(--muted); margin-top: 4px; }

.details {
  display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px;
  margin-top: 20px; border-top: 1px solid var(--line);
}
.details > div {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  min-height: 40px; padding: 10px 0; border-bottom: 1px solid var(--line);
  font-size: 14px; line-height: 20px;
}
.details dt { color: var(--text-2); }
.details dd { font-weight: 500; text-align: right; white-space: nowrap; }
@media (max-width: 400px) { .details { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------ listes -- */
.list { list-style: none; margin: 0; padding: 0; }
.list li:not(.empty) {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 8px 0; border-bottom: 1px solid var(--line);
}
.list li:last-child { border-bottom: none; }
.list .info { flex: 1; min-width: 0; }
.list .d { font-size: 15px; }
.list .n { font-size: 13px; line-height: 16px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qty { display: flex; align-items: center; gap: 6px; font-weight: 500; white-space: nowrap; }
.qty .icon { width: 14px; height: 14px; color: var(--muted); }
.qty.neg { color: var(--negative); }
.btns { display: flex; }
.icon-btn { width: 40px; min-height: 40px; padding: 0; color: var(--muted); border-radius: 8px; }

.month-group + .month-group { margin-top: 24px; }
.month-group h3 {
  display: flex; justify-content: space-between;
  font-size: 13px; line-height: 16px; font-weight: 500; color: var(--text-2);
  margin: 0 0 4px; padding-bottom: 8px; border-bottom: 1px solid var(--line);
}
.month-group h3 span:last-child { color: var(--muted); font-weight: 400; }

/* ---------------------------------------------------------- graphiques -- */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 12px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .bar { fill: var(--bar); }
.chart .bar.hl { fill: var(--accent); }
.chart text.val { fill: var(--text-2); font-weight: 500; }
.chart text.val.hl { fill: var(--accent-ink); }
.chart .avg-line { stroke: var(--muted); stroke-dasharray: 3 4; stroke-width: 1; }
.chart .empty { padding: 32px 0; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 12px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.legend i { display: inline-block; width: 16px; height: 2px; border-radius: 1px; }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 4px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 400; font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr.sel td { font-weight: 500; }
tr.sel td:first-child { color: var(--accent-ink); }

/* ------------------------------------------------- pile de bûches (garage) -- */
.woodpile { margin: 0 0 20px; }
.woodpile svg { display: block; width: 100%; height: auto; }
.woodpile .slot { fill: none; stroke: var(--slot); stroke-width: 1.5; }
.woodpile .bark { fill: var(--bark); }
.woodpile .ring { fill: none; stroke: var(--wood-ring); stroke-width: 1; }
.woodpile .crack { stroke: var(--wood-ring); stroke-width: 1.2; stroke-linecap: round; }
.woodpile .ground { stroke: var(--line-strong); stroke-width: 1.5; }
.woodpile-caption { font-size: 13px; line-height: 16px; color: var(--muted); margin-top: 8px; }

/* ----------------------------------------------------------- tabbar -- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; flex-direction: column; gap: 4px;
  min-height: 0; padding: 0; border-radius: 0;
  font-size: 12px; line-height: 16px; font-weight: 400; color: var(--muted);
}
.tabbar button:active { transform: none; }
.tabbar button.active { color: var(--text); font-weight: 500; }
.tabbar button.active .icon { color: var(--accent-ink); }

/* ------------------------------------------------------------- FAB -- */
.fab {
  position: fixed; z-index: 11;
  right: 16px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  min-height: 52px; padding: 0 20px 0 16px;
  border-radius: 16px;
  background: var(--accent); color: var(--on-accent);
  font-size: 15px; font-weight: 600;
  box-shadow: var(--shadow-float);
}
body[data-view="view-add"] .fab { display: none; }

/* ------------------------------------------------------------ toast -- */
.toast {
  position: fixed; left: 16px; right: 16px; z-index: 12;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 84px);
  max-width: 420px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 48px; padding: 4px 8px 4px 16px;
  background: var(--toast-bg); color: var(--toast-text);
  border-radius: 12px; box-shadow: var(--shadow-float);
  font-size: 14px;
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
}
.toast.show { opacity: 1; transform: none; pointer-events: auto; }
.toast button { min-height: 40px; padding: 0 12px; color: var(--toast-accent); font-size: 14px; font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
