/* Carnet — feuille de style. Un seul système : encre, papier, un accent. Pas de cartes partout. */

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef0ee;
  --line: #e2e5e1;
  --line-strong: #c9cec8;
  --ink: #15201d;
  --ink-2: #4a5955;
  --ink-3: #7c8984;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d9f0ec;
  --warn: #c2410c;
  --warn-soft: #fde8dc;
  --ok: #15803d;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgba(20, 32, 29, .06), 0 8px 24px -12px rgba(20, 32, 29, .18);
  --radius: 10px;
  --tab-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1215;
    --surface: #121b1e;
    --surface-2: #192428;
    --line: #223034;
    --line-strong: #33454a;
    --ink: #e8eeec;
    --ink-2: #a8b7b3;
    --ink-3: #6f7f7b;
    --accent: #2dd4bf;
    --accent-ink: #06201d;
    --accent-soft: #123b37;
    --warn: #fb923c;
    --warn-soft: #3b2113;
    --ok: #4ade80;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.4; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
h2 { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); margin: 0; }
.muted { color: var(--ink-3); font-size: 13px; }
.num, .tnum { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ───── Marque ───── */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: -.01em; font-size: 17px; }
.brand-mark { width: 12px; height: 12px; border-radius: 3px; background: var(--accent); transform: rotate(45deg); }

/* ───── Connexion ───── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.login-card .brand { font-size: 24px; }
.login-hint { margin: -6px 0 8px; color: var(--ink-2); }
.form-error { color: var(--danger); font-size: 13px; margin: 0; }

/* ───── Barre du haut ───── */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; height: 52px; padding: 0 12px 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(160%) blur(10px); border-bottom: 1px solid var(--line);
}
.topbar-center { flex: 1; text-align: center; color: var(--ink-3); font-size: 13px; }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn:active { background: var(--surface-2); }

/* ───── Mise en page ───── */
#main { padding: 14px 16px calc(var(--tab-h) + var(--safe-b) + 16px); max-width: 920px; margin: 0 auto; }
.view { display: grid; gap: 14px; align-content: start; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 8px; }

/* ───── Boutons et champs ───── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.field { display: grid; gap: 5px; font-size: 13px; color: var(--ink-2); }
.field input, .field select, .field textarea, textarea#capture-texte {
  width: 100%; height: 40px; padding: 0 11px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--ink); outline: none;
}
.field textarea { height: auto; padding: 9px 11px; }
.field input:focus, .field select:focus, .field textarea:focus, textarea#capture-texte:focus, .search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ───── Noter ───── */
.capture { display: grid; gap: 10px; }
textarea#capture-texte { height: auto; min-height: 84px; padding: 11px 12px; resize: vertical; font-size: 16px; line-height: 1.45; }
.where { position: relative; }
.where svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--ink-3); }
.where input { width: 100%; height: 40px; padding: 0 11px 0 36px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--ink); outline: none; font-size: 15px; }
.where input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.capture-actions { display: flex; gap: 8px; }
.capture-actions .btn-primary { margin-left: auto; min-width: 110px; }
@media (max-width: 380px) { .capture-actions .btn-ghost span { display: none; } }
.apercus { display: flex; gap: 8px; flex-wrap: wrap; }
.apercus img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.apercus .apercu { position: relative; }
.apercus .apercu button { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: var(--ink); color: var(--bg); font-size: 12px; line-height: 1; cursor: pointer; }

.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.list li { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.list .thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--surface-2); }
.thumb-wrap { position: relative; width: 44px; height: 44px; }
.thumb-n { position: absolute; right: -4px; bottom: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--ink); color: var(--bg); font-size: 11px; font-style: normal; font-weight: 700; display: grid; place-items: center; }
.tag.pic { background: transparent; padding: 0; font-size: 12px; }
.list .thumb-note { display: grid; place-items: center; color: var(--ink-3); background: var(--surface-2); }
.list .main { min-width: 0; }
.list .title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .amount { font-weight: 600; text-align: right; }
.list .amount small { display: block; font-weight: 400; font-size: 12px; color: var(--ink-3); }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 550; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.en_attente, .status.en_cours { color: var(--ink-3); }
.status.en_cours::before { animation: pulse 1.2s ease-in-out infinite; }
.status.traite { color: var(--ok); }
.status.a_verifier { color: var(--warn); }
.status.erreur { color: var(--danger); }
@keyframes pulse { 50% { opacity: .25; } }

/* ───── Statistiques ───── */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.stat { display: grid; gap: 2px; padding: 12px 14px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat-label { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); }
.stat-value { font-size: 22px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ───── Puces ───── */
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip.is-active { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip .n { font-variant-numeric: tabular-nums; color: inherit; opacity: .6; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

/* ───── Dépenses ───── */
.day { margin-top: 4px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 0 6px; font-size: 13px; color: var(--ink-3); border-bottom: 1px solid var(--line); }
.day-head b { color: var(--ink); font-weight: 600; }
.day-head .tnum { font-weight: 600; color: var(--ink-2); }
.dep { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.dep:active { background: var(--surface-2); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.dep .t { font-weight: 550; display: flex; align-items: center; gap: 8px; min-width: 0; }
.dep .t span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dep .s { font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dep .a { font-weight: 600; text-align: right; grid-row: span 2; align-self: center; }
.dep .a small { display: block; font-weight: 400; font-size: 12px; color: var(--ink-3); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none; }
.cat { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-weight: 550; white-space: nowrap; }

/* ───── Prix ───── */
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); width: 18px; height: 18px; }
.search input { width: 100%; height: 44px; padding: 0 12px 0 40px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); outline: none; font-size: 16px; -webkit-appearance: none; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); padding: 6px 0; border-bottom: 1px solid var(--line-strong); }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td { padding: 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.table td + td, .table th + th { padding-left: 10px; }
.table tbody tr { cursor: pointer; }
.table tbody tr:active { background: var(--surface-2); }
.table .art { font-weight: 500; }
.table .art small { display: block; color: var(--ink-3); font-weight: 400; font-size: 12px; }
.table .num { font-weight: 600; white-space: nowrap; }
.table .num small { display: block; font-weight: 400; color: var(--ink-3); font-size: 12px; }
.table .ou, .table .dt { color: var(--ink-2); font-size: 13px; white-space: nowrap; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 4px; background: var(--surface-2); color: var(--ink-2); vertical-align: 1px; margin-left: 4px; }
.tag.vu { background: var(--accent-soft); color: var(--accent); }
.tag.verif { background: var(--warn-soft); color: var(--warn); }
.table .sub-ou + .sub-rem::before { content: " · "; }
@media (max-width: 600px) {
  .col-ou, .col-date, .table .ou, .table .dt { display: none; }
}
@media (min-width: 601px) {
  .table .sub-ou { display: none; }
  .table .sub-ou + .sub-rem::before { content: none; }
}

/* ───── Barre d'onglets ───── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(3, 1fr); height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(160%) blur(10px); border-top: 1px solid var(--line);
}
.tab { position: relative; display: grid; justify-items: center; align-content: center; gap: 3px; border: 0; background: transparent; color: var(--ink-3); font-size: 11px; font-weight: 550; cursor: pointer; }
.tab svg { width: 22px; height: 22px; }
.tab.is-active { color: var(--accent); }
.tab-badge { position: absolute; top: 9px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--warn); color: #fff; font-size: 10px; font-style: normal; font-weight: 700; display: grid; place-items: center; }

/* ───── Feuille ───── */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92dvh; overflow: auto; padding: 8px 16px calc(20px + var(--safe-b)); border-radius: 16px 16px 0 0;
  background: var(--surface); box-shadow: var(--shadow); animation: up .22s cubic-bezier(.2, .8, .2, 1);
}
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 4px auto 14px; }
.sheet h3 { margin: 0 0 12px; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.sheet form { display: grid; gap: 12px; }
.sheet-actions { display: flex; gap: 8px; justify-content: space-between; margin-top: 6px; }
.sheet-actions .grow { flex: 1; }
.sheet .photo { width: 100%; max-height: 50dvh; object-fit: contain; border-radius: 8px; background: var(--surface-2); margin-bottom: 8px; }
.sheet .lignes { border-top: 1px solid var(--line); margin-top: 4px; }
.sheet .lignes div { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.sheet .lignes .tnum { font-weight: 600; }
.sheet .comptes div { align-items: center; }
.sheet .note { font-size: 13px; color: var(--ink-2); background: var(--surface-2); padding: 8px 10px; border-radius: 6px; }

/* ───── Toast ───── */
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 14px); transform: translateX(-50%); z-index: 30; padding: 9px 14px; border-radius: 8px; background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 550; box-shadow: var(--shadow); max-width: 90vw; }
.toast.err { background: var(--danger); color: #fff; }

.empty { display: block; padding: 28px 0; text-align: center; color: var(--ink-3); font-size: 14px; }
.sheet-h3-next { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }
.list li.empty { display: block; cursor: default; }
.mt-12 { margin-top: 12px; }

/* ───── Ordinateur : densité, pas d'onglets en bas ───── */
@media (min-width: 900px) {
  :root { --tab-h: 0px; }
  .tabbar { position: sticky; top: 52px; bottom: auto; grid-template-columns: repeat(3, auto); justify-content: start; gap: 4px; height: 44px; padding: 0 16px; border-top: 0; border-bottom: 1px solid var(--line); }
  .tab { grid-auto-flow: column; gap: 8px; padding: 0 12px; font-size: 13px; border-radius: 6px; }
  .tab svg { width: 18px; height: 18px; }
  .tab.is-active { background: var(--accent-soft); }
  .tab-badge { position: static; }
  #main { padding-top: 18px; }
  .sheet-panel { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: 560px; max-height: 86vh; border-radius: 14px; animation: none; }
  .sheet-handle { display: none; }
  .toast { bottom: 24px; }
}
