/* Lucas's EP: warm paper, night-blue ink, brass accent. Instrument Serif for the big
   figures and titles, Inter for everything read. One spacing rhythm: the page spaces its
   blocks (#view is a column with a gap), blocks never add their own outer margins. */

:root {
  color-scheme: light;
  --paper: #f4f1ea;
  --sheet: #fffdf9;
  --sunk: #efeadf;
  --ink: #17213a;
  --muted: #626a7c;
  --rule: #e3dccd;
  --seal: #1d3461;
  --seal-strong: #142647;
  --on-seal: #ffffff;
  --brass: #a8823a;
  --pos: #1d6b4f;
  --neg: #b3372f;
  --s1: #2a78d6;
  --s2: #eb6834;
  --grid: #ebe5d8;
  --shadow: 0 1px 0 rgba(23, 33, 58, 0.04), 0 12px 30px -24px rgba(23, 33, 58, 0.35);
  --radius: 14px;
  --gap: 18px;
  --serif: "Instrument Serif", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #11141c;
    --sheet: #191d27;
    --sunk: #151922;
    --ink: #ece9e1;
    --muted: #a3a7b3;
    --rule: #2b3040;
    --seal: #d4b26a;
    --seal-strong: #e3c684;
    --on-seal: #11141c;
    --brass: #d4b26a;
    --pos: #6cc59a;
    --neg: #e0786f;
    --s1: #3987e5;
    --s2: #d95926;
    --grid: #252a37;
    --shadow: 0 12px 30px -24px rgba(0, 0, 0, 0.8);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; }
h1, h2 { margin: 0; font-weight: 400; }
h1 { font: 400 34px/1.1 var(--serif); letter-spacing: -0.01em; }
h2 { font: 600 15px/1.3 var(--sans); }
h2.sub { font-size: 13px; color: var(--muted); }
p { margin: 0; }
.quiet { color: var(--muted); }
.small { font-size: 13px; }
.block { display: block; }
.center { text-align: center; }
.neg { color: var(--neg); }
.pos { color: var(--pos); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; z-index: 20; background: var(--sheet); padding: 8px 12px; border-radius: 8px; }
:focus-visible { outline: 2px solid var(--s1); outline-offset: 2px; }

/* ---- shell ---- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 12px max(20px, calc((100vw - 980px) / 2));
  padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-name { font: 400 24px/1 var(--serif); }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a {
  position: relative; display: flex; align-items: center; gap: 7px;
  padding: 8px 12px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 500;
}
.nav a:hover { color: var(--ink); background: var(--sunk); }
.nav a[aria-current] { color: var(--ink); background: var(--sheet); box-shadow: inset 0 0 0 1px var(--rule); }
.nav svg, .icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--neg); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
#view {
  display: flex; flex-direction: column; gap: var(--gap);
  max-width: 980px; margin: 0 auto; padding: 26px 20px 60px;
}
#view:focus { outline: none; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

@media (max-width: 720px) {
  /* A backdrop filter would make the header the frame of the fixed bottom bar. */
  .top { padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); backdrop-filter: none; background: var(--paper); }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; margin: 0;
    justify-content: space-around; padding: 6px 6px max(8px, env(safe-area-inset-bottom));
    background: var(--sheet); border-top: 1px solid var(--rule);
  }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 10px; }
  .nav a[aria-current] { box-shadow: none; background: var(--sunk); }
  .nav .badge { position: absolute; top: 0; right: 4px; }
  #view { padding: 20px 14px calc(96px + env(safe-area-inset-bottom)); --gap: 14px; }
  h1 { font-size: 30px; }
}

/* ---- buttons and forms ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border: 0; border-radius: 10px;
  background: var(--seal); color: var(--on-seal); font: 600 14px/1 var(--sans);
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--seal-strong); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.small { min-height: 32px; padding: 0 11px; font-size: 13px; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--rule); }
.btn.ghost:hover { background: var(--sunk); }
.btn.danger { color: var(--neg); }
.btn.armed { background: var(--neg); color: #fff; box-shadow: none; }
.icon-btn { border: 0; background: transparent; color: var(--muted); padding: 6px; border-radius: 8px; cursor: pointer; display: grid; }
.icon-btn:hover { background: var(--sunk); color: var(--ink); }

.form { display: flex; flex-direction: column; gap: 12px; }
.form.inline { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
.form.inline label { flex: 1 1 160px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: var(--muted); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row2 > * { min-width: 0; }
input, select, textarea {
  width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid var(--rule); border-radius: 10px;
  background: var(--sheet); color: var(--ink); font: 15px/1.4 var(--sans); font-variant-numeric: tabular-nums;
}
input[type=checkbox] { width: 18px; min-height: 18px; accent-color: var(--seal); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--s1) 55%, transparent); outline-offset: 0; border-color: var(--s1); }
.hint { font-size: 13px; margin-top: -6px; }
.add-box { border-top: 1px dashed var(--rule); padding-top: 12px; }
.add-box summary, .others summary { cursor: pointer; font-weight: 600; color: var(--seal); }
@media (prefers-color-scheme: dark) { .add-box summary, .others summary { color: var(--brass); } }
.add-box[open] summary { margin-bottom: 12px; }
@media (max-width: 520px) { .row2 { grid-template-columns: 1fr; } }

/* ---- blocks ---- */
.panel {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); min-width: 0;
}
.panel.tight { gap: 6px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.panel-total { font-weight: 600; }
.page-head { display: flex; flex-direction: column; gap: 8px; }
.page-head.row { flex-direction: row; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.empty { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 28px 22px; border: 1px dashed var(--rule); border-radius: var(--radius); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.note { white-space: pre-wrap; padding: 12px 14px; background: var(--sunk); border-radius: 10px; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; }
.back::before { content: "\2039\00a0"; }
.head-value { display: flex; flex-direction: column; align-items: flex-end; }
.head-value strong { font: 400 30px/1.1 var(--serif); }

.hello { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; padding: 30px 4px; max-width: 560px; }
.hello h1 { font-size: 44px; }

.hero { display: flex; flex-direction: column; gap: 4px; padding: 6px 2px 2px; }
.hero-label { color: var(--muted); }
.hero-num { font: 400 clamp(44px, 9vw, 68px)/1 var(--serif); letter-spacing: -0.015em; }
.hero-sub { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; color: var(--muted); }
.chg { font-weight: 600; }
.chg.pos { color: var(--pos); }
.chg.neg { color: var(--neg); }
.sep { width: 3px; height: 3px; border-radius: 50%; background: var(--rule); }

.due-card {
  display: flex; align-items: center; gap: 6px 14px; flex-wrap: wrap;
  padding: 14px 16px; border-radius: var(--radius); text-decoration: none;
  background: color-mix(in srgb, var(--brass) 14%, var(--sheet)); border: 1px solid color-mix(in srgb, var(--brass) 40%, var(--rule));
}
.due-card .due-names { color: var(--muted); flex: 1 1 200px; min-width: 0; }

.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--sunk); }
.seg button { border: 0; background: transparent; color: var(--muted); font: 500 13px/1 var(--sans); padding: 7px 10px; border-radius: 8px; cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--sheet); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.kpis > div { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 10px; background: var(--sunk); min-width: 0; }
.kpis span { font-size: 13px; color: var(--muted); }
.kpis strong { font: 400 26px/1.15 var(--serif); }
.kpis em { font-style: normal; font-size: 12px; color: var(--muted); }
@media (max-width: 520px) { .kpis { grid-template-columns: 1fr 1fr; } .kpis > div:last-child { grid-column: span 2; } }

/* ---- charts ---- */
.chart-box { position: relative; min-height: 220px; }
.chart { display: block; overflow: visible; touch-action: pan-y; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .grid.zero { stroke: var(--muted); stroke-opacity: 0.5; }
.chart .axis { fill: var(--muted); font: 11px var(--sans); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.s1 { stroke: var(--s1); }
.chart .dot.s1 { fill: var(--s1); stroke: var(--sheet); stroke-width: 2; }
.chart .bar.s1 { fill: var(--s1); }
.chart .bar.s2 { fill: var(--s2); }
.chart .cross { stroke: var(--muted); stroke-opacity: 0.6; stroke-dasharray: 3 3; }
.chart .band { fill: var(--ink); fill-opacity: 0.05; }
.tip {
  position: absolute; top: -6px; transform: translateY(-100%); pointer-events: none; z-index: 2;
  display: flex; flex-direction: column; gap: 3px; min-width: 180px; padding: 9px 11px;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px; box-shadow: var(--shadow); font-size: 13px;
}
.tip[hidden] { display: none; }
.tip-row { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.tip-row b { margin-left: auto; padding-left: 12px; color: var(--ink); font-weight: 600; }
.tip-note { color: var(--muted); font-size: 12px; max-width: 240px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.key.s1 { background: var(--s1); }
.key.s2 { background: var(--s2); }

.split { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.split li { display: grid; grid-template-columns: minmax(110px, 180px) 1fr auto 52px; align-items: center; gap: 12px; }
.split-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.split-bar { height: 10px; border-radius: 4px; background: var(--sunk); overflow: hidden; }
.split-bar i { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--s1); }
.split-value { font-weight: 600; text-align: right; }
.split-pct { color: var(--muted); text-align: right; }
.split-foot { color: var(--muted); border-top: 1px solid var(--rule); padding-top: 10px; }
.split-foot strong { color: var(--ink); }
@media (max-width: 520px) {
  .split li { grid-template-columns: 1fr auto 46px; row-gap: 4px; }
  .split-bar { grid-column: 1 / -1; grid-row: 2; }
}

/* ---- relevé ---- */
.month-pick { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.month-pick input { width: auto; }
.read-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.read-row { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); }
.read-row.done { background: color-mix(in srgb, var(--pos) 5%, var(--sheet)); }
.read-head { display: flex; flex-direction: column; }
.read-name { font-weight: 600; text-decoration: none; }
.read-meta { color: var(--muted); font-size: 13px; }
.read-done { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.read-done strong { font-size: 17px; }
.read-done .btn { margin-left: auto; }
.tick { width: 18px; height: 18px; border-radius: 50%; background: var(--pos); position: relative; flex: none; }
.tick::after { content: ""; position: absolute; left: 6px; top: 3px; width: 4px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.read-form { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; }
.read-form[hidden] { display: none; }
.read-last, .chips { grid-column: 1 / -1; }
.money-box { position: relative; display: block; }
.money-box input { padding-right: 28px; font-size: 17px; }
.money-box > span[aria-hidden] { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.file-btn { position: relative; }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chips[hidden] { display: none; }
.chip { border: 1px solid var(--rule); background: var(--sheet); color: var(--ink); border-radius: 999px; padding: 5px 11px; font: 500 14px var(--sans); cursor: pointer; }
.chip.best { border-color: var(--s1); box-shadow: inset 0 0 0 1px var(--s1); }
.others { display: flex; flex-direction: column; gap: 10px; }
.others[open] summary { margin-bottom: 10px; }
@media (max-width: 520px) {
  .read-form { grid-template-columns: 1fr 1fr; }
  .read-form .money-box { grid-column: 1 / -1; }
}

/* ---- patrimoine ---- */
.lines { list-style: none; margin: 0; padding: 0; }
.lines li + li { border-top: 1px solid var(--rule); }
.line-row { display: flex; justify-content: space-between; gap: 14px; padding: 11px 0; text-decoration: none; }
.line-row:hover .line-name { text-decoration: underline; }
.line-main, .line-side { display: flex; flex-direction: column; min-width: 0; }
.line-side { align-items: flex-end; text-align: right; flex: none; }
.line-name { font-weight: 600; display: inline-flex; align-items: center; gap: 7px; }
.line-meta, .line-when { color: var(--muted); font-size: 13px; }
.line-when.carried { color: var(--brass); }
.line-value { font-weight: 600; }
.dot-due { width: 7px; height: 7px; border-radius: 50%; background: var(--brass); }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 4px; border-bottom: 1px solid var(--rule); }
.table td { padding: 8px 4px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.table .num { text-align: right; white-space: nowrap; }
.table .actions { text-align: right; width: 1%; white-space: nowrap; }
.carried-row td { color: var(--muted); }
@media (max-width: 560px) {
  .table thead { display: none; }
  .table tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
  .table td { border: 0; padding: 0; }
  .table td.num { text-align: right; }
  .table td:empty { display: none; }
}

.flows { list-style: none; margin: 0; padding: 0; }
.flows li { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.flows li > * { min-width: 0; }
@media (max-width: 520px) { .flows li { grid-template-columns: 1fr auto; } }

/* ---- documents ---- */
.docs { list-style: none; margin: 0; padding: 0; }
.docs li { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--rule); }
.doc-open { display: flex; align-items: center; gap: 11px; flex: 1; min-width: 0; text-decoration: none; }
.doc-icon { flex: none; width: 38px; height: 38px; border-radius: 8px; display: grid; place-items: center; font: 700 10px var(--sans); letter-spacing: 0.04em; background: var(--sunk); color: var(--muted); }
.doc-text { display: flex; flex-direction: column; min-width: 0; }
.doc-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.filter select { width: auto; max-width: 60vw; }
@media (max-width: 520px) { .docs li { flex-wrap: wrap; } .doc-open { flex-basis: 100%; } }

/* ---- sheet and toast ---- */
.sheet {
  width: min(560px, 100vw); max-height: 92vh; padding: 0; border: 1px solid var(--rule); border-radius: 18px;
  background: var(--sheet); color: var(--ink); box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.5);
}
.sheet::backdrop { background: rgba(17, 20, 28, 0.45); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 4px; }
.sheet-head h2 { font: 400 26px/1.1 var(--serif); }
.sheet-body { padding: 12px 18px 22px; }
@media (max-width: 720px) {
  .sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30; max-width: calc(100vw - 32px);
  padding: 11px 16px; border-radius: 10px; background: var(--ink); color: var(--paper); font-weight: 500; box-shadow: var(--shadow);
}
.toast[data-tone=error] { background: var(--neg); color: #fff; }
@media (max-width: 720px) { .toast { bottom: calc(84px + env(safe-area-inset-bottom)); } }
