:root {
    color-scheme: dark;
    --bg: #0f1115;
    --card: #171a21;
    --line: #262a33;
    --text: #e6e8ec;
    --muted: #8a919e;
    --dim: #5c6370;
    --accent: #6ea8fe;
    --danger: #ff6b6b;
    --warn: #ffb454;
    --ok: #4cd964;
    --nav-w: 200px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* --- navigation --- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
    border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); letter-spacing: .02em; font-size: 18px; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--nav-w);
    display: flex; flex-direction: column; gap: 18px;
    padding: calc(18px + env(safe-area-inset-top)) 14px 18px;
    background: #121419; border-right: 1px solid var(--line);
}
.menu { display: flex; flex-direction: column; gap: 4px; }
.menu a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 10px; color: var(--muted); font-weight: 500;
}
.menu a:hover { background: #1b1f27; color: var(--text); }
.menu a.active { background: #1f2735; color: var(--text); }
.menu a.soon { opacity: .45; cursor: default; }
.menu .ico { width: 20px; text-align: center; font-size: 15px; }
.sidebar .user { margin-top: auto; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.who { color: var(--muted); }
body.with-nav .page { margin-left: var(--nav-w); }
.page { max-width: 860px; padding: 20px 20px 40px; display: grid; gap: 14px; margin: 0 auto; }
body.with-nav .page { margin-right: auto; }

@media (max-width: 720px) {
    :root { --nav-w: 0px; }
    .sidebar {
        inset: auto 0 0 0; width: auto; height: auto;
        flex-direction: row; align-items: center; gap: 0;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
        border-right: 0; border-top: 1px solid var(--line);
        background: rgba(18,20,25,.96); backdrop-filter: blur(8px);
    }
    .sidebar .brand, .sidebar .user { display: none; }
    .menu { flex: 1; flex-direction: row; justify-content: space-around; }
    .menu a { flex-direction: column; gap: 2px; padding: 6px 10px; font-size: 12px; }
    .menu .ico { font-size: 18px; width: auto; }
    body.with-nav .page { margin-left: 0; padding-bottom: 90px; }
    .page { padding: 14px 14px 40px; }
}

/* --- layout --- */
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; justify-content: space-between; }
.page-head p { margin: 4px 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.card h1 { font-size: 22px; margin: 0 0 8px; }
.count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px; background: var(--line); color: var(--text); font-size: 12px; text-align: center; text-transform: none; letter-spacing: 0; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 12px; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.neg { color: var(--danger); }

.btn {
    appearance: none; border: 1px solid var(--line); background: #1f2430; color: var(--text);
    border-radius: 10px; padding: 10px 14px; font-size: 15px; cursor: pointer; display: inline-block;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0b1220; font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 13px; }
.link.danger { color: var(--danger); }

.auth { max-width: 440px; margin: 40px auto 0; display: grid; gap: 12px; }
.auth .btn { width: 100%; padding: 14px; font-size: 16px; }

.flash { margin: 0; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.flash-error { background: rgba(255,107,107,.12); color: #ffb3b3; }
.flash-info { background: rgba(110,168,254,.12); color: #bcd4ff; }
.flash-success { background: rgba(76,217,100,.12); color: #b8f0c4; }

input, select, textarea {
    font: inherit; color: var(--text); background: #0f1115; border: 1px solid var(--line);
    border-radius: 8px; padding: 9px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { width: 100%; resize: vertical; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea { font-size: 15px; color: var(--text); }
.inline-field { grid-template-columns: auto auto; align-items: center; justify-content: start; gap: 10px; margin-bottom: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span2 { grid-column: 1 / -1; }
fieldset.sub { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0; }
fieldset.sub legend { color: var(--muted); font-size: 13px; padding: 0 6px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row .field { flex: 1 1 140px; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* --- tables --- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 6px; border-top: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table thead th { border-top: 0; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.table tbody tr:first-child td { border-top: 0; }
.table .group-row th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding-top: 14px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num-input { text-align: right; width: 150px; }
.num-input input { width: 100%; text-align: right; font-variant-numeric: tabular-nums; }
tr.missing td { color: var(--muted); }

/* --- finance --- */
.hero { display: grid; gap: 8px; }
.big { font-size: 40px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.hero-sub { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 14px; }
.hero-sub strong { color: var(--text); font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { display: grid; gap: 2px; padding: 12px 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); color: var(--text); }
.tile:hover { border-color: #3a4150; }
.tile-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.tile-value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-count { font-size: 12px; color: var(--dim); }
.tile-immobilier { border-left: 3px solid #b48cff; }
.tile-liquidites { border-left: 3px solid var(--accent); }
.tile-epargne { border-left: 3px solid var(--ok); }
.tile-crypto { border-left: 3px solid var(--warn); }
.tile-dettes { border-left: 3px solid var(--danger); }
.chart { width: 100%; height: 180px; display: block; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart .dot { fill: var(--accent); }
.chart .zero { stroke: var(--line); stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
.chart-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 4px; }

/* --- accueil --- */
h2 .more { float: right; font-size: 12px; text-transform: none; letter-spacing: 0; font-weight: 500; margin-left: 10px; }
.home-tiles .tile-value { font-size: 18px; }
.notes.compact .note-row { padding: 6px 0; }
.card form.add { margin-top: 10px; }

/* --- notes --- */
.search input { width: 100%; }
.notes { list-style: none; margin: 0; padding: 0; }
.note-row { padding: 10px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: baseline; }
.note-row:first-child { border-top: 0; }
.note-title { font-weight: 600; color: var(--text); }
.excerpt { grid-column: 1 / -1; margin: 0; }
.pin { color: var(--warn); }
.note-form { display: grid; gap: 10px; }
.note-title-input { font-size: 20px; font-weight: 600; }
.note-form textarea { font: 15px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; min-height: 320px; }
.between { justify-content: space-between; align-items: center; }
.check-label { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.chip { display: inline-block; padding: 4px 10px; border-radius: 999px; background: #1f2735; color: var(--text); font-size: 13px; }
.chip.missing, a.missing { border: 1px dashed var(--muted); background: transparent; color: var(--muted); }
.prose { line-height: 1.6; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose h1, .prose h2, .prose h3 { color: var(--text); text-transform: none; letter-spacing: 0; margin: 22px 0 8px; }
.prose h1 { font-size: 22px; } .prose h2 { font-size: 18px; } .prose h3 { font-size: 16px; }
.prose p, .prose ul, .prose ol { margin: 0 0 12px; }
.prose li { margin: 3px 0; }
.prose code { background: #0f1115; border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-size: 13px; }
.prose pre { background: #0f1115; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.prose pre code { border: 0; padding: 0; }
.prose blockquote { margin: 0 0 12px; padding: 4px 14px; border-left: 3px solid var(--line); color: var(--muted); }
.prose table { border-collapse: collapse; width: 100%; margin: 0 0 12px; font-size: 14px; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.prose th { background: #1b1f27; }
.prose a.missing { text-decoration: underline dotted; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.prose img { max-width: 100%; }
.graph-card { padding: 6px; overflow: hidden; }
.graph { width: 100%; height: auto; display: block; }
.graph line { stroke: #3a4150; stroke-width: 1.2; }
.graph .node circle { fill: var(--accent); stroke: #0f1115; stroke-width: 2; }
.graph .node.isolated circle { fill: #3a4150; }
.graph .node.pinned circle { fill: var(--warn); }
.graph .node text { fill: var(--muted); font-size: 12px; pointer-events: none; }
.graph .node:hover circle { fill: #fff; }
.graph .node:hover text { fill: var(--text); }

/* --- todo --- */
.add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.add .grow { flex: 1 1 240px; }
.add input[name="section"] { flex: 0 1 160px; }
.todos { list-style: none; margin: 0; padding: 0; }
.todo { display: flex; align-items: flex-start; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.todo:first-child { border-top: 0; }
.inline { display: inline; margin: 0; }
.check {
    width: 22px; height: 22px; margin-top: 2px; border-radius: 50%; border: 2px solid var(--muted);
    background: transparent; cursor: pointer; flex: 0 0 22px;
}
.check.checked { background: var(--ok); border-color: var(--ok); }
.todo.p1 .check { border-color: var(--danger); }
.todo.p3 .check { border-color: var(--line); }
.body { flex: 1; min-width: 0; }
.body > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.body > summary::-webkit-details-marker { display: none; }
.title { overflow-wrap: anywhere; }
.is-done .title { color: var(--muted); text-decoration: line-through; }
.due { color: var(--muted); font-size: 13px; white-space: nowrap; }
.due.today { color: var(--warn); font-weight: 600; }
.overdue .due { color: var(--danger); font-weight: 600; }
.edit { display: grid; gap: 8px; margin-top: 10px; }
.edit .row { display: flex; flex-wrap: wrap; gap: 8px; }
.edit .row input[name="section"] { flex: 1 1 140px; }
.done > summary { cursor: pointer; color: var(--muted); font-size: 14px; }
