/* =========================================================
   Budget — feuille de style (responsive, clair/sombre)
   ========================================================= */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e3e8ee;
  --text: #16202c;
  --muted: #65727f;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3f1;
  --pos: #15803d;
  --neg: #c2410c;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --ok-soft: #dcfce7;
  --info-soft: #e0ecff;
  --needs: #2563eb;
  --wants: #d97706;
  --savings: #059669;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --sidebar: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1419;
    --surface: #161e25;
    --surface-2: #1b252d;
    --border: #26323c;
    --text: #e7edf2;
    --muted: #93a1ad;
    --accent: #2dd4bf;
    --accent-ink: #062521;
    --accent-soft: #123a36;
    --pos: #4ade80;
    --neg: #fb923c;
    --warn: #fbbf24;
    --warn-soft: #3a2e0f;
    --danger: #f87171;
    --danger-soft: #3b1414;
    --ok-soft: #10301d;
    --info-soft: #14243f;
    --needs: #60a5fa;
    --wants: #fbbf24;
    --savings: #34d399;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
.ico { width: 18px; height: 18px; flex: none; }
.num, td.num, .amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- Structure ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 40; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; padding: 20px 20px 12px; }
.brand-lg { font-size: 1.4rem; justify-content: center; padding: 0 0 18px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  -webkit-mask: none; position: relative; flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 7px 6px 8px;
  border-left: 3px solid var(--accent-ink); border-bottom: 3px solid var(--accent-ink);
  transform: skewY(-25deg); opacity: .9;
}
.sidebar nav { padding: 4px 10px 12px; flex: 1; }
.nav-group { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 6px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 9px;
  color: var(--text); font-weight: 500;
}
.sidebar nav a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar nav a .badge { margin-left: auto; background: var(--danger); color: #fff; border-radius: 99px; font-size: .72rem; padding: 0 7px; }
.sidebar-user { padding: 14px 20px; border-top: 1px solid var(--border); font-weight: 600; display: flex; justify-content: space-between; }
.sidebar-user small { color: var(--muted); font-weight: 500; }

.main { margin-left: var(--sidebar); min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 14px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid transparent;
}
.topbar h1 { font-size: 1.35rem; flex: 1; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.content { padding: 8px 28px 48px; max-width: 1280px; }
.icon-btn.menu-btn { display: none; }
.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-btn:hover { text-decoration: none; background: var(--surface-2); }
.bell .dot {
  position: absolute; top: -5px; right: -5px; background: var(--danger); color: #fff;
  font-size: .68rem; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px;
}
.fab { display: none; }
.backdrop { display: none; }

/* ---------- Cartes & grilles ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; min-width: 0;
}
.card + .card { margin-top: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head .muted { font-size: .85rem; }
.grid { display: grid; gap: 18px; margin-bottom: 18px; }
.grid > .card + .card { margin-top: 0; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.span-2 { grid-column: span 2; }

.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi-label { color: var(--muted); font-size: .85rem; font-weight: 500; }
.kpi-value { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.kpi-sub { color: var(--muted); font-size: .82rem; }
.kpi-hero { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #1e3a8a)); color: #fff; border: 0; }
.kpi-hero .kpi-label, .kpi-hero .kpi-sub { color: rgba(255,255,255,.85); }
@media (prefers-color-scheme: dark) { .kpi-hero { color: var(--accent-ink); } .kpi-hero .kpi-label, .kpi-hero .kpi-sub { color: rgba(6,37,33,.8); } }

/* Détail du reste à vivre */
.breakdown { list-style: none; padding: 0; margin: 0; }
.breakdown li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.breakdown li:last-child { border-bottom: 0; }
.breakdown li.total { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; margin-top: 4px; padding-top: 10px; }

/* ---------- Barres de progression ---------- */
.progress { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.progress.warn > span { background: var(--warn); }
.progress.over > span { background: var(--danger); }
.progress-lg { height: 12px; }
.env { padding: 12px 0; border-bottom: 1px solid var(--border); }
.env:last-child { border-bottom: 0; }
.env-top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 7px; align-items: baseline; flex-wrap: wrap; }
.env-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.env-meta { display: flex; justify-content: space-between; margin-top: 5px; font-size: .82rem; color: var(--muted); }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
.tag {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: .8rem; white-space: nowrap;
}
.tag-besoin { color: var(--needs); }
.tag-envie { color: var(--wants); }
.tag-epargne { color: var(--savings); }
.tag-revenu { color: var(--pos); }

/* ---------- Formulaires ---------- */
form.inline { display: inline; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 14px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label, .label { font-size: .82rem; font-weight: 600; color: var(--muted); }
.field.wide { grid-column: 1 / -1; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=month], input[type=color], input[type=file], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text); font: inherit; min-height: 40px;
}
input[type=color] { padding: 3px; width: 56px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-size: .92rem; }
.check input { width: 18px; height: 18px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg label { padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--muted); }
.seg input { display: none; }
.seg input:checked + span { color: var(--accent); }
.seg label:has(input:checked) { background: var(--accent-soft); color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 15px;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; min-height: 40px; white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn-link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 4px 6px; }
.btn-link.danger { color: var(--danger); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.toolbar .field { min-width: 150px; }
.month-nav { display: inline-flex; align-items: center; gap: 6px; }
.month-nav strong { min-width: 140px; text-align: center; text-transform: capitalize; }

details.panel { margin-bottom: 18px; }
details.panel > summary { list-style: none; cursor: pointer; }
details.panel > summary::-webkit-details-marker { display: none; }

/* ---------- Messages ---------- */
.flash { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; }
.flash-success { background: var(--ok-soft); color: var(--pos); }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-warning { background: var(--warn-soft); color: var(--warn); }
.flash-info { background: var(--info-soft); color: var(--text); }
.alert-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.alert-item:last-child { border-bottom: 0; }
.alert-item.unread .alert-msg { font-weight: 600; }
.alert-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; flex: none; }
.lvl-warning { background: var(--warn); } .lvl-danger { background: var(--danger); }
.lvl-success { background: var(--pos); } .lvl-info { background: var(--needs); }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }

/* ---------- Graphiques ---------- */
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }
.legend { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.legend li .amount { margin-left: auto; font-weight: 600; }

/* 50/30/20 */
.rule-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.rule-card { border-top: 4px solid var(--c); }
.rule-card .big { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stack { display: flex; height: 18px; border-radius: 99px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.stack span { display: block; height: 100%; }
.stack-labels { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); margin-top: 6px; }

/* Projets */
.goal-card { border-left: 5px solid var(--c); }
.goal-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.goal-stats div { background: var(--surface-2); border-radius: 10px; padding: 9px 11px; }
.goal-stats b { display: block; font-variant-numeric: tabular-nums; }
.goal-stats small { color: var(--muted); font-size: .76rem; }

/* ---------- Connexion ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 30px 26px; box-shadow: var(--shadow); }
.auth-card form { display: grid; gap: 14px; }
.auth-card .btn { width: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-main { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
  .main { margin-left: 0; }
  .icon-btn.menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .topbar h1 { font-size: 1.15rem; }
  .content { padding: 6px 16px 96px; }
  .hide-sm { display: none !important; }
  .g-2, .g-3, .rule-cols { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .fab {
    display: grid; place-items: center; position: fixed; right: 18px; bottom: 20px; width: 56px; height: 56px;
    border-radius: 50%; background: var(--accent); color: var(--accent-ink); box-shadow: 0 8px 20px rgba(0,0,0,.25); z-index: 25;
  }
  .fab .ico { width: 26px; height: 26px; }
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }

  /* Tableaux → listes de cartes */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { padding: 10px 0; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; }
  table.responsive tr:last-child { border-bottom: 0; }
  table.responsive td { border: 0; padding: 0; }
  table.responsive td[data-l]::before { content: attr(data-l) " : "; color: var(--muted); font-size: .8rem; }
  table.responsive td.primary { font-weight: 600; grid-column: 1; }
  table.responsive td.num { grid-column: 2; grid-row: 1; text-align: right; font-weight: 600; }
  table.responsive td.meta { grid-column: 1 / -1; font-size: .84rem; color: var(--muted); }
  table.responsive td.actions { grid-column: 1 / -1; text-align: left; }
  table.responsive td.actions::before { content: none; }
  .goal-stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) {
  .g-4 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
  .kpi-value { font-size: 1.25rem; }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar .field { min-width: 0; flex: 1 1 140px; }
}

/* ---------- v2 : sélecteur de budget, membres, sécurité ---------- */
.ledger-switch { padding: 0 20px 6px; display: grid; gap: 4px; }
.ledger-switch .nav-group { padding: 4px 0 0; }
.ledger-switch select { min-height: 36px; padding: 6px 8px; font-weight: 600; }
.ledger-name { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.nav-btn {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 9px; width: 100%;
  background: none; border: 0; color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-align: left;
}
.nav-btn:hover { background: var(--surface-2); }
.topbar-ledger { font-size: .8rem; font-weight: 500; margin-left: 6px; }
.balance-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.balance-row:last-child { border-bottom: 0; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.settle { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px dashed var(--border); border-radius: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.settle .arrow { color: var(--muted); }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1rem; }
.codes span { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px; text-align: center; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .08em; word-break: break-all; background: var(--surface-2); padding: 10px; border-radius: 8px; }
.qr { background: #fff; padding: 12px; border-radius: 12px; display: inline-block; }
.qr svg { display: block; width: 180px; height: 180px; }
.danger-zone { border-color: var(--danger); }
.pill-ok { color: var(--pos); font-weight: 600; }
.pill-no { color: var(--neg); font-weight: 600; }
@media (max-width: 860px) { .topbar-ledger { display: none; } }
.check.field { flex-direction: row; align-items: center; }
.check.field input { flex: none; }
