/* ==========================================================
   Mes Dépenses — feuille de style
   ========================================================== */
:root {
  color-scheme: light;
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #f0efeb;
  --border: #e3e2dc;
  --grid: #e8e7e2;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e6f0fc;
  --good: #1a7f45;
  --good-soft: #e3f4ea;
  --bad: #c43c3b;
  --bad-soft: #fbe9e8;
  --tooltip-bg: #1f1f1e;
  --tooltip-text: #f5f4f0;
  --shadow: 0 1px 2px rgba(20, 20, 15, .05), 0 2px 8px rgba(20, 20, 15, .04);
  --radius: 12px;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --grid: #2a2a28;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #93928a;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-soft: #1b2b40;
    --good: #4cc27f;
    --good-soft: #17301f;
    --bad: #f07c7b;
    --bad-soft: #3a1d1c;
    --tooltip-bg: #f0efec;
    --tooltip-text: #1a1a19;
    --shadow: none;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font-sans); font-feature-settings: "tnum" 1;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.02rem; margin: 0 0 .9rem; letter-spacing: -.005em; }
p { margin: 0 0 .8rem; }
.muted { color: var(--text-3); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.h-sub { font-weight: 400; font-size: 1.05rem; margin-left: .4rem; }
kbd { font: inherit; font-size: .8em; padding: .05em .4em; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); }

/* ---------- Barre du haut ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: .6rem 1.5rem; display: flex; align-items: center; gap: 1.5rem; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); position: relative; flex: none;
  background-image: linear-gradient(#fff, #fff), linear-gradient(#fff, #fff), linear-gradient(#fff, #fff);
  background-size: 4px 8px, 4px 13px, 4px 17px; background-position: 6px 13px, 11px 8px, 16px 4px; background-repeat: no-repeat; }
.brand-mark.big { width: 52px; height: 52px; border-radius: 14px;
  background-size: 8px 16px, 8px 26px, 8px 34px; background-position: 12px 26px, 22px 16px, 32px 8px; }
.mainnav { display: flex; gap: .2rem; flex: 1; }
.mainnav a { color: var(--text-2); padding: .45rem .75rem; border-radius: 8px; font-weight: 500; white-space: nowrap; }
.mainnav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.mainnav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.usermenu { display: flex; align-items: center; gap: .8rem; font-size: .9rem; white-space: nowrap; }
.usermenu a { color: var(--text-2); }

/* ---------- Mise en page ---------- */
.container { max-width: 1240px; margin: 0 auto; padding: 1.6rem 1.5rem 4rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; }
.page-head + .muted { margin-top: -.4rem; max-width: 760px; }
.crumbs { margin: 0 0 .6rem; font-size: .9rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.35rem; margin-bottom: 1.1rem; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
.grid-2 > .card { margin-bottom: 1.1rem; }
.grid-side { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1.1rem; align-items: start; }
.stack { display: flex; flex-direction: column; gap: .85rem; }
.inline { display: inline; }
.empty { text-align: center; padding: 2.5rem 1rem; }
.empty p { color: var(--text-2); }

/* ---------- Formulaires ---------- */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; font-weight: 500; color: var(--text-2); }
label.check { flex-direction: row; align-items: center; gap: .45rem; font-weight: 400; }
input, select, textarea {
  font: inherit; font-size: .95rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .5rem .65rem; min-height: 38px; width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; accent-color: var(--accent); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input.num { text-align: right; }
input.big { font-size: 1.4rem; font-weight: 600; padding: .6rem .8rem; }
.w-xs { width: 64px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-size: .92rem; font-weight: 600;
  padding: .5rem .95rem; min-height: 38px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
@media (prefers-color-scheme: dark) { .btn-primary:hover { background: #256abf; border-color: #256abf; } }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--bad); border-color: var(--bad-soft); }
.btn-danger-ghost:hover { background: var(--bad-soft); }
.btn-small { min-height: 32px; padding: .3rem .7rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent-ink); cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }
.linkbtn.danger, summary.danger { color: var(--bad); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: var(--text-3); font-size: 1.25rem; cursor: pointer; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; background: var(--good-soft); color: var(--text); border: 1px solid transparent; }
.flash-error { background: var(--bad-soft); }
.flash ul { margin: .3rem 0 0; padding-left: 1.2rem; }

/* ---------- Connexion ---------- */
.auth-card { max-width: 380px; margin: 9vh auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2rem; box-shadow: var(--shadow); }
.auth-card h1 { text-align: center; margin-bottom: 1.3rem; font-size: 1.4rem; }
.auth-card .muted { text-align: center; }
.auth-logo { display: flex; justify-content: center; margin-bottom: .8rem; }
.auth-card .btn { margin-top: .3rem; }

/* ---------- Filtres ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; padding: .8rem 1rem; }
.filters input[type="search"] { flex: 1; min-width: 200px; }
.filters select { width: auto; }
.filters input[type="month"], .filters input[type="date"] { width: auto; }
.month-nav { display: flex; align-items: center; gap: .25rem; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; flex: 1; }
.chip { padding: .38rem .8rem; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); font-size: .88rem; font-weight: 500; white-space: nowrap; }
.chip:hover { background: var(--surface-2); text-decoration: none; }
.chip.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.custom-range { display: flex; align-items: center; gap: .4rem; }
.summary-line { display: flex; justify-content: space-between; align-items: baseline; margin: .2rem .3rem .7rem; color: var(--text-2); }
.summary-line strong { font-size: 1.25rem; color: var(--text); }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; padding: 0; }
.card.table-wrap { padding: .3rem 0; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
.data th { text-align: left; font-weight: 600; color: var(--text-3); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; padding: .6rem .9rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data td { padding: .62rem .9rem; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.data tbody tr:last-child td { border-bottom: 0; }
.data tbody tr:hover td { background: var(--surface-2); }
.data .num, .num { text-align: right; font-variant-numeric: tabular-nums; }
.data.compact td, .data.compact th { padding: .5rem .55rem; }
.card > .data.compact { margin: 0 -.55rem; width: calc(100% + 1.1rem); }
.data .actions { text-align: right; white-space: nowrap; }
.data .actions > * + * { margin-left: .8rem; }
.data tr.archived td { color: var(--text-3); }
.data tr.editing td { background: var(--accent-soft); }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.inline-form input:not([type]), .inline-form input[name="name"] { flex: 1; min-width: 140px; }
.inline-form select { width: auto; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: .5rem; vertical-align: 0; flex: none; }
.dot.big { width: 16px; height: 16px; border-radius: 4px; margin: 0; }
.tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .45rem; border-radius: 999px; background: var(--surface-2); color: var(--text-2); vertical-align: 1px; }
.tag-good { background: var(--good-soft); color: var(--good); }
.price-best { font-weight: 600; color: var(--good); }
details.del-cat { position: relative; display: inline-block; }
details.del-cat summary { list-style: none; cursor: pointer; }
details.del-cat summary::-webkit-details-marker { display: none; }
.small-pop { position: absolute; right: 0; top: 1.6rem; z-index: 5; width: 260px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .9rem; box-shadow: 0 8px 24px rgba(0,0,0,.12); text-align: left; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1.2rem; margin: 0 0 1rem; }
.facts dt { color: var(--text-3); }
.facts dd { margin: 0; font-weight: 600; text-align: right; }

/* ---------- Saisie d'une dépense ---------- */
.expense-form { display: flex; flex-direction: column; gap: 1rem; padding: 1.5rem; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.mode-opt { flex-direction: row; align-items: flex-start; gap: .7rem; padding: .85rem 1rem; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; color: var(--text); }
.mode-opt input { margin-top: .25rem; }
.mode-opt span { display: flex; flex-direction: column; }
.mode-opt small { color: var(--text-3); font-weight: 400; font-size: .84rem; }
.mode-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.form-row { display: grid; grid-template-columns: 180px 1fr 220px; gap: .8rem; }
.f-total { max-width: 280px; }
table.lines { width: 100%; border-collapse: separate; border-spacing: 0 .35rem; }
.lines th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 600; padding: 0 .3rem; }
.lines td { padding: 0 .3rem; vertical-align: top; }
.lines .c-unit { width: 120px; } .lines .c-qty { width: 110px; } .lines .c-price { width: 140px; }
.lines .c-total { width: 110px; padding-top: .55rem; font-weight: 600; }
.lines th.c-total, .lines th.c-qty, .lines th.c-price { text-align: right; }
.lines .c-del { width: 40px; padding-top: .2rem; }
.hint { font-size: .8rem; color: var(--text-3); min-height: 0; padding: .15rem .1rem 0; }
.hint:empty { display: none; }
.hint-new { color: var(--accent-ink); }
.hint-deal { color: var(--bad); }
.lines-foot { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.ticket-totals { margin-left: auto; width: 360px; max-width: 100%; display: flex; flex-direction: column; gap: .5rem; border-top: 1px solid var(--border); padding-top: .8rem; }
.ticket-totals > div, .ticket-totals > label { display: flex; flex-direction: row; justify-content: space-between; align-items: center; gap: 1rem; font-size: .92rem; color: var(--text-2); font-weight: 400; }
.ticket-totals .adj input { width: 120px; }
.ticket-totals .adj > span { display: flex; flex-direction: column; }
.ticket-totals .grand { font-size: 1.15rem; color: var(--text); font-weight: 600; }
.ticket-totals .grand strong { font-size: 1.35rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .6rem; border-top: 1px solid var(--border); padding-top: 1rem; }

/* ---------- Statistiques ---------- */
.kpis { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 1.1rem; margin-bottom: 1.1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; box-shadow: var(--shadow); }
.kpi-label { font-size: .85rem; color: var(--text-2); }
.kpi-value { font-size: 1.55rem; font-weight: 650; letter-spacing: -.015em; margin: .15rem 0 .1rem; white-space: nowrap; }
.kpi-value small { font-size: .8rem; font-weight: 500; color: var(--text-3); letter-spacing: 0; }
.kpi-main .kpi-value { font-size: 2rem; }
.kpi-delta { font-size: .84rem; }
.kpi-delta.is-up { color: var(--bad); }
.kpi-delta.is-down { color: var(--good); }
.kpi-delta .muted { color: var(--text-3); }

.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .35rem 1.1rem; margin-bottom: .8rem; font-size: .85rem; color: var(--text-2); }
.legend-item { display: inline-flex; align-items: center; gap: .4rem; }
.swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.swatch-line { width: 16px; height: 2px; border-radius: 2px; }
#monthly-table { margin-top: 1rem; }

.hbars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .7rem; }
.hbars li { display: grid; grid-template-columns: 110px 1fr 160px 64px; align-items: center; gap: .7rem; font-size: .92rem; }
.hbar-label { display: flex; align-items: center; min-width: 0; }
.hbar-label a { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 14px; }
.hbar { height: 100%; background: var(--c); border-radius: 0 4px 4px 0; min-width: 0; }
.hbar-value { display: flex; justify-content: flex-end; gap: .5rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.hbar-value .muted { width: 38px; text-align: right; }
.hbar-delta { text-align: right; white-space: nowrap; }
.minibar { height: 3px; background: var(--accent); border-radius: 0 2px 2px 0; margin-top: .3rem; opacity: .7; }

/* ---------- Écrans plus petits ---------- */
@media (max-width: 1080px) {
  .topbar-inner { flex-wrap: wrap; gap: .6rem 1rem; }
  .mainnav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .btn-new { margin-left: auto; }
  .kpis { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
  .grid-2, .grid-side { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .mode-switch { grid-template-columns: 1fr; }
  .hbars li { grid-template-columns: 100px 1fr 150px; }
  .hbar-delta { display: none; }
  .lines .c-unit { width: 90px; } .lines .c-qty, .lines .c-total { width: 70px; } .lines .c-price { width: 90px; }
  .container { padding: 1rem .8rem 3rem; }
}
