:root {
  --bg: #f4f4f6;
  --card: #ffffff;
  --text: #17181c;
  --muted: #6b6f7a;
  --line: #e6e7eb;
  --accent: #3159d6;
  --accent-soft: #e8edfb;
  --ok: #1f9d6b;
  --warn: #dd8a17;
  --bad: #d4453f;
  --shadow: 0 1px 2px rgba(20, 22, 30, .05), 0 6px 20px rgba(20, 22, 30, .05);
  --radius: 16px;
  --tabbar-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0e11;
    --card: #17181d;
    --text: #f1f2f4;
    --muted: #9a9ea9;
    --line: #262830;
    --accent: #7c9bff;
    --accent-soft: #1d2440;
    --ok: #3ccb92;
    --warn: #f0a93e;
    --bad: #ef6b65;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* En-tête */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px);
}
.topbar h1 { flex: 1; margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.back { border: 0; background: none; color: var(--accent); font-size: 16px; padding: 4px 0; margin-right: -4px; }
.pill {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; font-weight: 600;
}
select.pill { appearance: none; -webkit-appearance: none; padding-right: 12px; }
.iconbtn { border: 1px solid var(--line); background: var(--card); border-radius: 999px; width: 34px; height: 34px; display: grid; place-items: center; padding: 0; }
.iconbtn svg { width: 17px; height: 17px; stroke: var(--text); }
.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { padding: 4px 16px 24px; max-width: 720px; margin: 0 auto; }
#ptr { height: 0; overflow: hidden; text-align: center; color: var(--muted); font-size: 13px; transition: height .15s; }

/* Cartes */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 0 0 12px; border: 1px solid var(--line); }
@media (prefers-color-scheme: light) { .card { border-color: transparent; } }
.card h2 { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.section-title { margin: 22px 4px 10px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 .card { margin: 0; }
.big { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.mid { font-size: 18px; font-weight: 650; }
.pos { color: var(--bad); }   /* dépassement */
.neg { color: var(--ok); }    /* économie */
.freshness { margin: 2px 4px 14px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.dot.stale { background: var(--warn); }

/* Jauge */
.gauge { position: relative; width: 116px; height: 116px; margin: 4px auto 8px; }
.gauge svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge .track { stroke: var(--line); }
.gauge .val { transition: stroke-dashoffset .6s ease; }
.gauge .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.gauge .center b { font-size: 22px; letter-spacing: -.02em; }
.gauge .center span { font-size: 11px; color: var(--muted); }
.gauge-card { text-align: center; }
.gauge-card .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.gauge-card .amounts { font-size: 13px; }

/* Lignes de budget */
.list { padding: 4px 16px; }
.item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 13px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; margin-bottom: 7px; }
.item .name { font-weight: 600; min-width: 0; }
.item .head > span:last-child { white-space: nowrap; }
.item .sub { display: flex; justify-content: space-between; margin-top: 6px; font-size: 13px; color: var(--muted); }
.bar { height: 7px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--ok); }
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }
.tag { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; }
.chev { color: var(--muted); margin-left: 4px; }

/* Segmenté */
.seg { display: inline-flex; background: var(--line); border-radius: 10px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* Graphiques */
.chart { position: relative; height: 230px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Explication */
.why { margin: 0; padding: 0; list-style: none; }
.why li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.why li:last-child { border-bottom: 0; }
.why .lbl { min-width: 0; }
.why .lbl small { display: block; color: var(--muted); font-size: 12px; }
.callout { background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px; }
.flag { font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 6px; margin-left: 6px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.flag.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
h3 { margin: 16px 0 6px; font-size: 14px; }
h3:first-child { margin-top: 0; }

/* Opérations */
.op { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.op:last-child { border-bottom: 0; }
.op .l { min-width: 0; }
.op .l div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op .amt { font-weight: 600; white-space: nowrap; }
.op .amt.credit { color: var(--ok); }
.more { display: block; width: 100%; margin-top: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: none; font-weight: 600; color: var(--accent); }

/* Tableau annuel */
.tablewrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; -webkit-overflow-scrolling: touch; }
table.syn { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 13px; }
table.syn th, table.syn td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
table.syn th:first-child, table.syn td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); z-index: 1; padding-left: 0; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
table.syn thead th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.syn tr.sec td { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; border-bottom: 0; padding-top: 16px; }
table.syn tr.tot td { font-weight: 700; background: var(--accent-soft); }
table.syn tr.tot td:first-child { background: var(--accent-soft); padding-left: 8px; border-radius: 8px 0 0 8px; }
table.syn tr.tot td:last-child { border-radius: 0 8px 8px 0; }
table.syn tr.grand td { font-weight: 700; border-bottom: 0; }
.yoy-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.yoy-row:last-child { border-bottom: 0; }

/* Recherche */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.filters select, .filters input { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 10px; min-width: 0; }
.filters .full { grid-column: 1 / -1; }
input[type=search] { -webkit-appearance: none; appearance: none; }
.total { display: flex; justify-content: space-between; align-items: baseline; margin: 14px 4px 6px; }

/* Barre d'onglets */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 90%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; }
.tabbar button svg { width: 24px; height: 24px; stroke: currentColor; }
.tabbar button.on { color: var(--accent); }

/* États */
.state { text-align: center; padding: 60px 24px; color: var(--muted); }
.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--line), var(--card), var(--line)); background-size: 200% 100%; animation: sh 1.3s infinite; margin-bottom: 12px; }
@keyframes sh { to { background-position: -200% 0; } }
.err { color: var(--bad); }
.btn { border: 0; background: var(--accent); color: #fff; padding: 10px 18px; border-radius: 12px; font-weight: 600; margin-top: 12px; }
table.check { width: 100%; border-collapse: collapse; }
table.check td, table.check th { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: right; }
table.check td:first-child, table.check th:first-child { text-align: left; }
.okc { color: var(--ok); font-weight: 700; } .koc { color: var(--bad); font-weight: 700; }
/* Connexion */
.signin { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 24px; text-align: center; }
.signin h1 { margin: 14px 0 0; font-size: 28px; letter-spacing: -.02em; }
.signin .btn { margin-top: 22px; padding: 13px 22px; font-size: 16px; }
body { overscroll-behavior-y: none; }

/* Rythme du mois : repère de l'avancement dans le mois */
.bar.pace { position: relative; overflow: visible; }
.bar.pace > b { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text); opacity: .55; border-radius: 1px; }
.bar.pace > i { border-radius: 4px; }

/* Avatar (photo Google) sur le bouton de déconnexion */
.avatarbtn { position: relative; overflow: hidden; padding: 0; }
.avatarbtn .ini { font-size: 14px; font-weight: 700; color: var(--accent); }
.avatarbtn .avatar { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* Assistant : conversation */
.chat { padding: 4px 0 96px; }
.intro { padding: 8px 4px 4px; }
.intro h2 { margin: 6px 0 8px; font-size: 22px; letter-spacing: -.02em; color: var(--text); text-transform: none; font-weight: 700; }
.chips { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.chip { text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 12px 14px; font-weight: 600; color: var(--text); }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 18px; margin: 8px 0; line-height: 1.45; word-wrap: break-word; }
.msg.me { margin-left: auto; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.msg.bot { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; max-width: 94%; }
.msg.bot.err { color: var(--bad); }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin-bottom: 0; }
.msg ul { margin: 6px 0; padding-left: 18px; } .msg li { margin: 3px 0; }
.via { margin-top: 8px; font-size: 12px; color: var(--muted); }
.typing { display: inline-flex; gap: 5px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bl 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes bl { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.chatfoot { text-align: center; margin-top: 14px; }
.composer { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 25; padding: 8px 16px 10px;
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.composer-in { max-width: 720px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); background: var(--card); border-radius: 20px; padding: 10px 14px; line-height: 1.35; max-height: 120px; font-size: 16px; }
.send { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); display: grid; place-items: center; padding: 0; flex: none; }
.send svg { width: 20px; height: 20px; stroke: #fff; }
.send[disabled] { opacity: .45; }
