/* Budget — site web. Mobile d'abord ; barre latérale à partir de 900 px. Jetons repris de Themes/Tokens.xaml. */
@font-face { font-family: Inter; src: url(/fonts/Inter-Regular.ttf) format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: Inter; src: url(/fonts/Inter-Medium.ttf) format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: Inter; src: url(/fonts/Inter-SemiBold.ttf) format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: Poppins; src: url(/fonts/Poppins-SemiBold.ttf) format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: Poppins; src: url(/fonts/Poppins-Bold.ttf) format("truetype"); font-weight: 700; font-display: swap; }

:root {
  color-scheme: light;
  --page: #F8F9FA; --card: #FFFFFF; --sunken: #F1F3F5;
  --text1: #1A1A2E; --text2: #4B5263; --text3: #6B7280;
  --border: #E5E8EC; --border2: #D0D5DC;
  --blue: #2E75B6; --blue-d: #255F95; --blue-soft: #EEF4FA;
  --green: #167340; --green-soft: #EAF7EF; --red: #A12F2F; --red-soft: #FCEDED; --amber: #8F6400; --amber-soft: #FFF7E0;
  --radius: 14px; --shadow: 0 1px 2px rgba(26,26,46,.06), 0 2px 8px rgba(26,26,46,.04);
  --tab-h: 64px; --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0F1420; --card: #171E2C; --sunken: #212A3B;
    --text1: #EDEFF3; --text2: #B7BECB; --text3: #8E97A7;
    --border: #283244; --border2: #364257;
    --blue: #5C9CDB; --blue-d: #7FB2E5; --blue-soft: #1B2B42;
    --green: #4CC47F; --green-soft: #15291F; --red: #F07B7B; --red-soft: #3A1C1F; --amber: #E6B84A; --amber-soft: #33290F;
    --shadow: none;
  }
  .chip, .cat-tile .chip { filter: saturate(.9); }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--text1); font: 400 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
h1, h2, h3 { font-family: Poppins, Inter, sans-serif; font-weight: 600; margin: 0; line-height: 1.25; }
h2 { font-size: 1.05rem; margin-bottom: .75rem; }
a { color: var(--blue); }
code { font-family: ui-monospace, Consolas, monospace; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text3); }
.small { font-size: .82rem; }
.center { text-align: center; margin: 1rem 0; }
.nowrap { white-space: nowrap; }
.ic { width: 22px; height: 22px; flex: none; vertical-align: middle; }
.ic.sm { width: 17px; height: 17px; }
.ic.big { width: 34px; height: 34px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 55%, transparent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Structure ---------- */
.app { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 16px); }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px; background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.top h1 { font-size: 1.25rem; }
.top p { margin: 0; color: var(--text3); font-size: .82rem; }
.top-title { min-width: 0; }
.acc-pick select { max-width: 46vw; font: 500 .85rem Inter, sans-serif; padding: 8px 28px 8px 10px; border-radius: 10px; }
.acc-one { font-size: .82rem; color: var(--text2); text-align: right; }
.main { padding: 16px; max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.side { display: none; }

.tabbar { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr); background: var(--card); border-top: 1px solid var(--border); }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--text3);
  text-decoration: none; font-size: .7rem; font-weight: 500; }
.tabbar a[aria-current="page"] { color: var(--blue); }
.tabbar .tab-add { align-self: center; justify-self: center; width: 52px; height: 52px; border-radius: 50%; background: var(--blue);
  color: #fff; box-shadow: 0 4px 14px rgba(46,117,182,.35); }
.tabbar .tab-add[aria-current="page"] { color: #fff; background: var(--blue-d); }
.tabbar .tab-add .ic { width: 26px; height: 26px; }

@media (min-width: 900px) {
  .app { padding: 0 0 0 240px; }
  .tabbar { display: none; }
  .side { display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; width: 240px; padding: 20px 14px;
    background: var(--card); border-right: 1px solid var(--border); }
  .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: var(--text1); text-decoration: none;
    font: 700 1.25rem Poppins, sans-serif; }
  .brand .ic { color: var(--blue); width: 28px; height: 28px; }
  .side-nav { display: flex; flex-direction: column; gap: 2px; }
  .side-nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--text2);
    text-decoration: none; font-weight: 500; }
  .side-nav a:hover { background: var(--sunken); }
  .side-nav a[aria-current="page"] { background: var(--blue-soft); color: var(--blue); }
  .side-out { margin-top: auto; }
  .side-out .link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; color: var(--text3); }
  .top { padding: 18px 28px; }
  .main { padding: 24px 28px; }
}

/* ---------- Composants ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.empty { text-align: center; padding: 32px 16px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-between.wrap { flex-wrap: wrap; }
.row-between h2 { margin: 0; }
.grid2 { display: grid; gap: 14px; }
@media (min-width: 700px) { .grid2 { grid-template-columns: 1fr 1fr; align-items: start; } .grid2.wide-first { grid-template-columns: 3fr 2fr; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--border2); border-radius: 12px; background: var(--card); color: var(--text1);
  font: 600 .92rem Inter, sans-serif; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--sunken); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-d); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .85rem; }
.btn.wide { width: 100%; }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, var(--border)); }
.btn.danger-link, .link { background: none; border: 0; color: var(--red); font: 500 .9rem Inter, sans-serif; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; padding: 10px; }
.link { color: var(--text3); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; }
.actions .btn { flex: 1; }
@media (min-width: 700px) { .actions .btn { flex: 0 0 auto; min-width: 160px; } }
.actions.sticky { position: sticky; bottom: calc(var(--tab-h) + var(--safe-b) + 8px); }
@media (min-width: 900px) { .actions.sticky { bottom: 16px; } }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; color: var(--text2); border: 0; background: none; }
.icon-btn:hover { background: var(--sunken); }
.icon-btn.off { opacity: .3; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: .85rem; font-weight: 500; color: var(--text2); }
.field.inline { flex-direction: row; align-items: center; gap: 10px; margin: 10px 0 0; }
input:not([type=radio]):not([type=checkbox]):not([type=color]), select {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--border2); border-radius: 12px;
  background: var(--card); color: var(--text1); font: 400 16px Inter, sans-serif; /* 16 px : pas de zoom automatique sur iPhone */ }
input:focus, select:focus { border-color: var(--blue); outline: 3px solid color-mix(in srgb, var(--blue) 25%, transparent); }
input[type=color] { width: 56px; height: 40px; border: 1px solid var(--border2); border-radius: 10px; background: none; padding: 2px; }
.check { display: flex; align-items: center; gap: 10px; margin: 10px 0 14px; font-size: .9rem; }
.check input { width: 20px; height: 20px; accent-color: var(--blue); }
fieldset { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
legend { font-size: .85rem; font-weight: 500; color: var(--text2); margin-bottom: 8px; padding: 0; }
.alert { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; background: var(--red-soft); color: var(--red); font-weight: 500; }
.toast { padding: 12px 14px; border-radius: 12px; background: var(--green-soft); color: var(--green); font-weight: 500; transition: opacity .4s; }
.toast.err { background: var(--red-soft); color: var(--red); }
.toast.hide { opacity: 0; pointer-events: none; }
.badge { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 99px; font-size: .72rem; font-weight: 600; background: var(--blue-soft); color: var(--blue); }
.badge.ok { background: var(--green-soft); color: var(--green); margin: 0; }
.badge.warn { background: var(--amber-soft); color: var(--amber); margin: 0; }
.badge.off { background: var(--sunken); color: var(--text3); margin: 0; }

/* Segments (onglets) : liens ou boutons radio */
.seg { display: flex; background: var(--sunken); border-radius: 12px; padding: 3px; gap: 2px; }
.seg a, .seg label { flex: 1; text-align: center; padding: 8px 10px; border-radius: 9px; color: var(--text2); text-decoration: none;
  font-weight: 500; font-size: .88rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.seg a[aria-current="true"], .seg input:checked + label { background: var(--card); color: var(--text1); box-shadow: var(--shadow); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:focus-visible + label { outline: 3px solid color-mix(in srgb, var(--blue) 55%, transparent); }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 99px; border: 1px solid var(--border2);
  background: var(--card); color: var(--text2); font: 500 .85rem Inter, sans-serif; text-decoration: none; cursor: pointer; }
.pill.on, .pill:has(input:checked) { background: var(--blue-soft); border-color: var(--blue); color: var(--blue); }
.pill input { accent-color: var(--blue); }

/* Période */
.period { display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 260px; }
.period-nav { display: flex; align-items: center; justify-content: space-between; }
.period-label { font: 600 1.05rem Poppins, sans-serif; }
.period-dates { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; }
.period-dates label { display: flex; flex-direction: column; font-size: .8rem; color: var(--text3); flex: 1; min-width: 130px; gap: 4px; }
@media (min-width: 700px) { .period { flex-direction: row; align-items: center; flex-wrap: wrap; } .period .seg { flex: 0 0 auto; } .period-nav { gap: 8px; } }

/* Chiffres clés */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { display: flex; flex-direction: column; gap: 4px; padding: 14px; }
.kpi.balance { grid-column: 1 / -1; background: var(--blue); border-color: var(--blue); color: #fff; }
.kpi.balance.neg { background: var(--red); border-color: var(--red); }
.kpi-label { font-size: .8rem; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi.in .kpi-label { color: var(--green); }
.kpi.out .kpi-label { color: var(--blue); }
.kpi-value { font: 700 1.25rem Poppins, sans-serif; }
.kpi.balance .kpi-value { font-size: 1.7rem; }
@media (min-width: 700px) { .kpis { grid-template-columns: 2fr 1fr 1fr; } .kpi.balance { grid-column: auto; } }

.bar { height: 10px; border-radius: 99px; background: var(--sunken); overflow: hidden; margin: 10px 0 6px; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--blue); }
.bar.warn > span { background: #E6A100; }
.bar.over > span { background: var(--red); }
.bar.thin { height: 6px; margin: 6px 0 0; }
.budget p { margin: 0; }

/* Listes d'opérations */
.day { font: 600 .78rem Inter, sans-serif; text-transform: uppercase; letter-spacing: .04em; color: var(--text3); margin: 14px 0 4px; }
.ops { list-style: none; margin: 0; padding: 0; }
.ops li + li { border-top: 1px solid var(--border); }
.op { display: flex; align-items: center; gap: 12px; padding: 10px 4px; color: inherit; text-decoration: none; border-radius: 10px; }
.op:hover { background: var(--sunken); }
.op-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.op-desc { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op-cat { font-size: .8rem; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op-amt { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.op-amt.in { color: var(--green); }
.op-date { width: 52px; flex: none; font-size: .82rem; color: var(--text3); }
.empty-line { padding: 12px 0; margin: 0; }
.chip { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--soft); color: var(--ink); flex: none; }
.chip.sm { width: 28px; height: 28px; border-radius: 8px; }
.chip.sm .ic { width: 16px; height: 16px; }

/* Saisie */
.amount { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 16px; }
.amount input:not([type=radio]) { font: 700 2.4rem Poppins, sans-serif; text-align: center; border: 0; min-height: 64px; max-width: 280px; background: none; padding: 0; }
.amount .cur { font: 600 1.8rem Poppins, sans-serif; color: var(--text3); }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.cat-grid > input { position: absolute; opacity: 0; pointer-events: none; }
.cat-tile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px; border-radius: 12px; border: 2px solid transparent;
  text-align: center; font-size: .78rem; font-weight: 500; color: var(--text2); cursor: pointer; line-height: 1.2; }
.cat-tile:hover { background: var(--sunken); }
.cat-grid > input:checked + .cat-tile { border-color: var(--c); background: var(--soft); color: var(--text1); }
.cat-grid > input:focus-visible + .cat-tile { outline: 3px solid color-mix(in srgb, var(--blue) 55%, transparent); }
.entry:has(#k-dep:checked) .cats-rev, .entry:has(#k-rev:checked) .cats-dep { display: none; }
.subs { display: none; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.entry .card + .card { margin-top: 14px; }
.entry .actions { margin-top: 14px; }

/* Statistiques */
.donut-wrap { position: relative; width: min(240px, 70vw); margin: 18px auto 8px; }
.donut { display: block; width: 100%; transform: rotate(0deg); }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.donut-center strong { font: 700 1.3rem Poppins, sans-serif; }
.slices { list-style: none; margin: 10px 0 0; padding: 0; }
.slice { display: flex; align-items: center; gap: 12px; padding: 10px 6px; color: inherit; text-decoration: none; border-radius: 12px; border: 2px solid transparent; }
.slice:hover { background: var(--sunken); }
.slice.on { border-color: var(--c); background: var(--soft); }
.slice-text { flex: 1; min-width: 0; }
.slice-name { font-weight: 500; }
.slice-num { display: flex; flex-direction: column; align-items: flex-end; white-space: nowrap; font-variant-numeric: tabular-nums; }
.detail { border: 2px solid var(--c); display: flex; flex-direction: column; gap: 12px; scroll-margin-top: 90px; }
.detail-head { display: flex; align-items: center; gap: 12px; }
.detail-head h2 { margin: 0; }
.detail-head p { margin: 0; }
.cmp { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .9rem; }
.cmp th, .cmp td { padding: 8px 4px; text-align: right; border-bottom: 1px solid var(--border); }
.cmp th:first-child, .cmp tbody th { text-align: left; font-weight: 500; color: var(--text2); }
.cmp thead th { font-size: .78rem; color: var(--text3); font-weight: 500; }

/* Catégories */
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; max-height: 260px; overflow: auto; padding: 2px; }
.icon-pick input, .color-pick input { position: absolute; opacity: 0; pointer-events: none; }
.icon-pick span { display: grid; place-items: center; height: 44px; border-radius: 10px; border: 2px solid var(--border); color: var(--text2); cursor: pointer; }
.icon-pick input:checked + span { border-color: var(--blue); background: var(--blue-soft); color: var(--blue); }
.icon-pick input:focus-visible + span, .color-pick input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--blue) 55%, transparent); }
.color-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 8px; }
.color-pick span { display: grid; place-items: center; height: 40px; border-radius: 50%; background: var(--c); border: 3px solid var(--card); box-shadow: 0 0 0 1px var(--border2); cursor: pointer; color: var(--text2); }
.color-pick input:checked + span { box-shadow: 0 0 0 3px var(--text1); }
.color-pick.other span { background: conic-gradient(#D64545, #E6A100, #1F9D55, #2E75B6, #8B5CF6, #D64545); color: #fff; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 99px; background: var(--sunken); font-size: .82rem; }
details summary { cursor: pointer; color: var(--text2); font-weight: 500; margin-top: 12px; }

/* Éditions */
.reports { display: flex; flex-direction: column; gap: 14px; }
.choice-list { display: grid; gap: 8px; }
@media (min-width: 700px) { .choice-list { grid-template-columns: 1fr 1fr; } }
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border: 2px solid var(--border); border-radius: 12px; cursor: pointer; }
.choice > span:last-child { display: flex; flex-direction: column; gap: 2px; }
.choice input { position: absolute; opacity: 0; }
.choice:has(input:checked) { border-color: var(--blue); background: var(--blue-soft); }
.choice:has(input:focus-visible) { outline: 3px solid color-mix(in srgb, var(--blue) 55%, transparent); }
.choice .ic { color: var(--blue); }
.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.check-tile { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 10px; border: 1px solid var(--border); font-size: .86rem; cursor: pointer; }
.check-tile input { width: 18px; height: 18px; accent-color: var(--blue); flex: none; }
.check-tile:has(input:not(:checked)) { opacity: .55; }

/* Compte, administration */
.menu { padding: 6px; display: flex; flex-direction: column; }
.menu a, .menu button { display: flex; align-items: center; gap: 12px; padding: 12px 10px; border-radius: 10px; color: var(--text1); text-decoration: none;
  font: 500 .95rem Inter, sans-serif; background: none; border: 0; width: 100%; cursor: pointer; text-align: left; }
.menu a span, .menu button span { flex: 1; }
.menu a:hover, .menu button:hover { background: var(--sunken); }
.menu button { color: var(--red); }
@media (min-width: 900px) { .menu { display: none; } }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 14px; font-size: .9rem; }
.facts dt { color: var(--text3); }
.facts dd { margin: 0; }
.inline-form { display: flex; gap: 10px; align-items: end; }
.inline-form .field { flex: 1; margin: 0; }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th { text-align: left; font-size: .75rem; color: var(--text3); font-weight: 500; padding: 6px; border-bottom: 1px solid var(--border); }
.table td { padding: 9px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr.on td { background: var(--blue-soft); }
.table tr.fail td { color: var(--red); }
.secret { border: 2px solid var(--amber); background: var(--amber-soft); }
.secret h2 { display: flex; align-items: center; gap: 8px; }
.secret-value code { font-size: 1.5rem; letter-spacing: .06em; user-select: all; word-break: break-all; }

/* Connexion */
.bare-main { min-height: 100dvh; display: grid; place-items: center; padding: 20px 16px; }
.login { width: 100%; max-width: 400px; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 18px; font: 700 1.6rem Poppins, sans-serif; }
.login-brand .ic { color: var(--blue); }
.login-card { padding: 22px; }
.login-card h1 { font-size: 1.3rem; margin-bottom: 16px; }
.login-foot { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--text3); font-size: .8rem; text-align: center; }
.bare .card.empty { max-width: 420px; }

/* Retouches */
.bar { display: block; }
.slice-text { display: flex; flex-direction: column; }
.badge { white-space: nowrap; }
.amount input#Amount { border: 0; outline: none; box-shadow: none; font: 700 2.4rem Poppins, sans-serif; text-align: center; min-height: 64px; max-width: 260px; padding: 0; background: none; }
.amount { border-bottom: 2px solid var(--border); padding-bottom: 4px; }
.amount:focus-within { border-bottom-color: var(--blue); }
