:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #15181d;
  --muted: #6b7280;
  --line: #e3e6ea;
  --brand: #1f9bd1;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3fb;
  --warn-bg: #fff4d6; --warn-ink: #7a5300;
  --info-bg: #e3f3fb; --info-ink: #0b5575;
  --danger: #c2372b;
  --ok: #1d8a4e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --card: #181c22; --ink: #eceff3; --muted: #9aa3ad; --line: #2a3038;
    --brand: #3db2e6; --brand-ink: #06121a; --brand-soft: #13303f;
    --warn-bg: #3a2e0c; --warn-ink: #ffd88a; --info-bg: #13303f; --info-ink: #9fdcf7;
    --danger: #ff7b6e; --ok: #5fd08f;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 1.4rem 0 .6rem; }
.muted { color: var(--muted); }
.tiny { font-size: .78rem; }
.err { color: var(--danger); font-size: .9rem; margin: .4rem 0; }
.pad { padding: 16px; }

.view { max-width: 640px; margin: 0 auto; min-height: 100vh; }
.center { display: grid; place-items: center; padding: 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.login-card { width: 100%; max-width: 380px; }

.brand { font-weight: 700; font-size: 1.35rem; display: flex; align-items: center; gap: 8px; }
.brand.small { font-size: 1.05rem; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--brand); display: inline-block; }

label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 0; }
label em { font-style: normal; color: var(--danger); }
input:not([type=checkbox]):not([type=file]), select {
  display: block; width: 100%; margin-top: 5px;
  font: inherit; font-size: 16px; color: var(--ink);
  background: var(--card); border: 1.5px solid var(--line); border-radius: 10px;
  padding: 12px; min-height: 48px;
}
input:focus { outline: none; border-color: var(--brand); }
input[type=date] { -webkit-appearance: none; appearance: none; }
.check { display: flex; gap: 10px; align-items: flex-start; color: var(--ink); font-size: .95rem; margin-top: 16px; }
.check input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--brand); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; border: 0; border-radius: 12px;
  padding: 12px 16px; min-height: 46px; cursor: pointer; text-decoration: none;
  background: var(--brand-soft); color: var(--ink);
}
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.secondary { background: var(--brand-soft); color: var(--info-ink); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { color: var(--danger); }
.btn.big { width: 100%; min-height: 52px; margin-top: 18px; font-size: 1.05rem; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: .88rem; }
.btn:disabled { opacity: .5; }
form .btn.ghost { width: 100%; margin-top: 6px; }
.icon-btn { background: none; border: 0; color: var(--ink); font-size: 1.5rem; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; }

/* En-tête */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
}
.who { font-size: .82rem; color: var(--muted); }
.menu {
  position: fixed; right: 12px; top: calc(58px + env(safe-area-inset-top)); z-index: 20;
  background: var(--card); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.18);
  display: flex; flex-direction: column; min-width: 230px; overflow: hidden;
}
.menu button { font: inherit; background: none; border: 0; color: var(--ink); text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.menu button:last-child { border-bottom: 0; color: var(--danger); }

.banner { margin: 0 16px 8px; padding: 10px 12px; border-radius: 10px; font-size: .88rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner.info { background: var(--info-bg); color: var(--info-ink); }

/* Onglets */
.tabs { display: flex; gap: 6px; padding: 0 16px 10px; }
.tab { flex: 1; font: inherit; font-weight: 600; border: 0; background: transparent; color: var(--muted); padding: 10px; border-radius: 10px; cursor: pointer; }
.tab.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.badge { display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 11px; background: var(--brand); color: var(--brand-ink); font-size: .78rem; line-height: 22px; }
.tab-pane { padding: 0 16px 170px; }

/* Listes */
.month { margin: 14px 0 6px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.month h4 { margin: 0; font-size: .95rem; }
.month .sel-month { font: inherit; font-size: .85rem; color: var(--brand); background: none; border: 0; padding: 4px 0; cursor: pointer; }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); min-height: 64px; }
.item:last-child { border-bottom: 0; }
.item .sel { width: 24px; height: 24px; flex: none; accent-color: var(--brand); }
.item .ico { width: 38px; height: 38px; flex: none; border-radius: 10px; background: var(--brand-soft); display: grid; place-items: center; font-size: 1.15rem; }
.item .main { flex: 1; min-width: 0; cursor: pointer; }
.item .l1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .l2 { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .amt { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: .7rem; font-weight: 600; padding: 1px 6px; border-radius: 6px; background: var(--brand-soft); color: var(--info-ink); margin-left: 4px; vertical-align: 1px; }
.tag.pending { background: var(--warn-bg); color: var(--warn-ink); }
.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty .big { font-size: 2.4rem; }

.note { padding: 14px; }
.note .l1 { display: flex; justify-content: space-between; font-weight: 600; }
.note .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* Barre export */
.export-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  max-width: 640px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 96px 12px 16px; padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.export-bar .muted { display: block; font-size: .8rem; }
.fab {
  position: fixed; z-index: 7; right: max(16px, calc(50vw - 304px)); bottom: calc(84px + env(safe-area-inset-bottom));
  width: 62px; height: 62px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--brand); color: var(--brand-ink); font-size: 2rem; line-height: 1;
  box-shadow: 0 6px 20px rgba(31,155,209,.45);
}

/* Feuille (formulaire) */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 94vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
.sheet.small { max-height: 80vh; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-head { position: sticky; top: 0; background: var(--bg); display: flex; align-items: center; justify-content: space-between; padding: 8px 0; z-index: 2; }
.sheet-head h2 { margin: 0; }
.sheet-head span { width: 44px; }
.field .lbl { display: block; font-size: .85rem; color: var(--muted); margin: 14px 0 6px; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.chip {
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 12px; padding: 10px 6px; min-height: 64px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.chip .e { font-size: 1.3rem; }
.chip.on { border-color: var(--brand); background: var(--brand-soft); }
.photo-zone { background: var(--card); border-radius: var(--radius); padding: 12px; text-align: center; }
.photo-zone img { max-width: 100%; max-height: 220px; border-radius: 10px; display: block; margin: 0 auto 10px; }
.photo-actions { display: flex; gap: 8px; justify-content: center; }
.photo-zone .tiny { margin: 8px 0 0; }

.secret { margin-top: 12px; border: 2px dashed var(--brand); }
.secret code { font-size: 1.2rem; font-weight: 700; user-select: all; }
.uline { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.uline:last-child { border-bottom: 0; }
.uline .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.off { opacity: .5; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(160px + env(safe-area-inset-bottom)); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-size: .92rem;
  max-width: calc(100% - 32px); text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.sum-line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }

select { -webkit-appearance: none; appearance: none; padding-right: 36px !important;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
select:focus { outline: none; border-color: var(--brand); }
/* Aperçu de note */
.note .l1 { cursor: pointer; }
.pv-head { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.pv-head .muted { font-size: .82rem; }
.pv-line { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.pv-line:last-child { border-bottom: 0; }
.pv-line .d { font-size: .8rem; color: var(--muted); }
.pv-line .m { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.pv-line .c { font-size: .75rem; color: var(--info-ink); text-align: right; }
.pv-line a { color: var(--brand); font-size: .8rem; text-decoration: none; }
.pv-tot { margin-top: 12px; }
.pv-tot .sum-line.grand { font-weight: 700; border-bottom: 0; font-size: 1.05rem; }
.pv-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 4px; }
