:root{
  --bg:#f2f5f8; --card:#ffffff; --ink:#1b2a3a; --muted:#7688a0;
  --line:#e2e9f1; --brand:#1f3a5f; --accent:#2e6e8e; --accent-2:#3a8fb0;
  --ok:#1f9d6b; --danger:#d64550; --yellow:#fff6cc;
  --radius:16px; --shadow:0 2px 10px rgba(28,52,84,.06);
}
*{box-sizing:border-box}
html,body{margin:0}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;
  background:var(--bg); color:var(--ink); -webkit-font-smoothing:antialiased;
}

/* ---------- Login ---------- */
.login-body{display:flex; min-height:100vh; align-items:center; justify-content:center; padding:24px}
.login-card{background:var(--card); padding:36px 28px; border-radius:var(--radius);
  box-shadow:var(--shadow); width:100%; max-width:360px; text-align:center}
.login-logo{width:56px;height:56px;line-height:56px;margin:0 auto 14px;border-radius:16px;
  background:var(--brand); color:#fff; font-size:26px; font-weight:700}
.login-card h1{font-size:20px; margin:0 0 4px}
.login-card form{display:flex; flex-direction:column; gap:12px; margin-top:18px}
.login-card input{padding:14px; border:1px solid var(--line); border-radius:12px; font-size:16px}
.login-card button{padding:14px; border:0; border-radius:12px; background:var(--brand);
  color:#fff; font-size:16px; font-weight:600; cursor:pointer}

/* ---------- Layout ---------- */
.topbar{position:sticky; top:0; z-index:5; display:flex; align-items:center; gap:12px;
  padding:12px 16px; padding-top:calc(12px + env(safe-area-inset-top));
  background:var(--brand); color:#fff}
.brand{font-weight:700; font-size:15px; white-space:nowrap}
.month-nav{margin-left:auto; display:flex; align-items:center; gap:6px}
.month-nav select{background:rgba(255,255,255,.12); color:#fff; border:0; border-radius:10px;
  padding:8px 10px; font-size:15px; font-weight:600}
.month-nav select option{color:#000}
.icon-btn{width:34px;height:34px;border:0;border-radius:10px;background:rgba(255,255,255,.14);
  color:#fff;font-size:20px;line-height:1;cursor:pointer}
.logout{color:#cfe0ee; text-decoration:none; font-size:13px; margin-left:4px}

.wrap{max-width:620px; margin:0 auto; padding:16px 16px 60px}
.card{background:var(--card); border-radius:var(--radius); box-shadow:var(--shadow);
  padding:18px; margin-bottom:16px}
.card h2{font-size:15px; margin:0 0 14px; color:var(--brand); display:flex; align-items:center; gap:8px}
.muted{color:var(--muted); font-size:14px}
.badge{background:var(--line); color:var(--muted); font-size:12px; font-weight:600;
  border-radius:20px; padding:2px 9px}

/* ---------- Summary ---------- */
.summary{background:linear-gradient(135deg,var(--brand),var(--accent)); color:#fff}
.summary-msg{font-size:18px; font-weight:700; margin-bottom:14px; min-height:24px}
.summary-grid{display:grid; grid-template-columns:1fr 1fr; gap:10px}
.stat{background:rgba(255,255,255,.12); border-radius:12px; padding:12px}
.stat-label{display:block; font-size:12px; opacity:.85}
.stat-val{display:block; font-size:20px; font-weight:700; margin-top:2px}
.settle-row{display:flex; align-items:center; gap:10px; margin-top:14px}
.settle-state{font-size:13px; opacity:.9}
.settle-state.done{font-weight:700; opacity:1}
.ghost-btn{margin-left:auto; background:rgba(255,255,255,.16); color:#fff; border:0;
  border-radius:10px; padding:9px 14px; font-size:14px; font-weight:600; cursor:pointer}

/* ---------- Forms ---------- */
.form-grid{display:grid; grid-template-columns:1fr 1fr; gap:12px}
.form-grid label{display:flex; flex-direction:column; gap:6px; font-size:13px; color:var(--muted); font-weight:600}
.form-grid .full{grid-column:1 / -1}
.form-grid input,.form-grid select{padding:12px; border:1px solid var(--line);
  border-radius:12px; font-size:16px; color:var(--ink); background:#fff}
button.primary{border:0; border-radius:12px; background:var(--accent); color:#fff;
  padding:13px; font-size:16px; font-weight:600; cursor:pointer}
.alert{background:#fdecee; color:var(--danger); border-radius:10px; padding:10px 12px;
  font-size:14px; margin-top:12px}

/* ---------- Vue annuelle ---------- */
.year-nav{margin-left:auto; display:inline-flex; align-items:center; gap:8px; font-size:15px; color:var(--ink)}
.icon-btn.small{width:28px;height:28px;font-size:16px;background:var(--line);color:var(--brand)}
.year-totals{display:grid; grid-template-columns:repeat(3,1fr); gap:10px; margin-bottom:16px}
.year-totals div{background:var(--bg); border-radius:12px; padding:10px 12px; text-align:center}
.year-totals span{display:block; font-size:11px; margin-bottom:2px}
.year-totals strong{font-size:16px; color:var(--brand)}
.year-totals strong.up{color:var(--danger)}
.year-totals strong.down{color:var(--ok)}
.bars{display:flex; align-items:flex-end; gap:6px; height:120px; padding-top:8px}
.bar-col{flex:1; display:flex; flex-direction:column; align-items:center; gap:4px; height:100%; justify-content:flex-end}
.bar{width:100%; max-width:22px; background:linear-gradient(180deg,var(--accent-2),var(--accent));
  border-radius:5px 5px 0 0; min-height:2px; transition:height .3s}
.bar-col.empty .bar{background:var(--line)}
.bar-label{font-size:10px; color:var(--muted)}
.bar-col.active .bar{background:linear-gradient(180deg,#f0a500,#e07b00)}

/* ---------- List ---------- */
.list{list-style:none; margin:0; padding:0}
.item{display:flex; align-items:center; gap:12px; padding:12px 4px; border-bottom:1px solid var(--line)}
.item:last-child{border-bottom:0}
.item-main{flex:1; min-width:0}
.item-label{font-weight:600; font-size:15px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis}
.item-sub{font-size:12px; color:var(--muted); margin-top:2px}
.chip{display:inline-block; background:var(--line); border-radius:20px; padding:1px 8px; margin-right:6px}
.chip.pa{background:#e2eefb; color:#1f5fa8}
.chip.pb{background:#fbe7e2; color:#b0532e}
.item-amount{font-weight:700; font-size:16px; white-space:nowrap}
.item-actions{display:flex; gap:4px}
.mini{width:32px;height:32px;border:0;border-radius:9px;background:#f0f4f8;cursor:pointer;font-size:15px}
.mini.del{color:var(--danger)}

/* ---------- Bilan par catégorie ---------- */
.cat-row{display:flex; align-items:center; gap:10px; margin-bottom:10px; font-size:14px}
.cat-name{width:130px; flex-shrink:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.cat-bar-track{flex:1; background:var(--bg); border-radius:8px; height:14px; overflow:hidden}
.cat-bar-fill{height:100%; background:linear-gradient(90deg,var(--accent-2),var(--accent))}
.cat-amount{width:90px; text-align:right; font-weight:600; flex-shrink:0}

.table-wrap{overflow-x:auto}
.cat-table{width:100%; border-collapse:collapse; font-size:12px; min-width:640px}
.cat-table th,.cat-table td{padding:6px 8px; text-align:right; border-bottom:1px solid var(--line); white-space:nowrap}
.cat-table th:first-child,.cat-table td:first-child{text-align:left}
.cat-table thead th{color:var(--muted); font-weight:600}

/* ---------- Impression ---------- */
@media print{
  .no-print{display:none !important}
  body{background:#fff}
  .wrap{padding:0; max-width:100%}
  .card{box-shadow:none; border:1px solid var(--line); break-inside:avoid}
  .table-wrap{overflow-x:visible}
  .cat-table{min-width:0; font-size:11px}
}

/* ---------- Modal ---------- */
.modal{position:fixed; inset:0; background:rgba(20,34,52,.45);
  align-items:flex-end; justify-content:center; z-index:20}
.modal:not([hidden]){display:flex}
.modal-box{width:100%; max-width:620px; margin:0; border-radius:20px 20px 0 0}
.modal-actions{display:flex; gap:10px; justify-content:flex-end}

@media(min-width:560px){
  .modal{align-items:center; padding:20px}
  .modal-box{border-radius:var(--radius)}
}
