/* Budget YNAB — thème inspiré de YNAB4 (barre latérale bleu foncé). */
:root {
  --navy: #2c4a68;
  --navy-dark: #1e3448;
  --navy-light: #3d5f80;
  --accent: #2e86c1;
  --bg: #eef3f7;
  --card: #ffffff;
  --text: #22303c;
  --muted: #6b7d8d;
  --border: #d5dde4;
  --green: #2e7d32;
  --red: #c0392b;
  --amber: #b7791f;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--text); background: var(--bg); font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app { display: flex; min-height: 100vh; }

/* --- Barre latérale --- */
.sidebar { width: 250px; flex-shrink: 0; background: linear-gradient(180deg, var(--navy), var(--navy-dark)); color: #dbe7f0; display: flex; flex-direction: column; }
.brand { padding: 16px 18px; font-size: 20px; font-weight: 700; color: #fff; border-bottom: 1px solid rgba(255,255,255,.12); }
.nav { padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.12); }
.nav a { display: block; padding: 9px 18px; color: #cfe0ee; font-weight: 600; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.16); color: #fff; border-left: 3px solid #7fb3d5; }
.nav-total { float: right; font-weight: 400; color: #9db8cc; }
.side-accounts { flex: 1; padding: 10px 0; overflow-y: auto; }
.side-group { padding: 12px 18px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #8fa9bf; }
.side-account { display: flex; justify-content: space-between; gap: 8px; padding: 6px 18px; color: #dbe7f0; }
.side-account:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.side-account .amt { color: #b9cfe0; white-space: nowrap; }
.side-account .amt.neg { color: #f0a8a0; }
.side-add { display: block; padding: 8px 18px; color: #8fb8d8; }
.side-footer { padding: 12px 18px; font-size: 12px; color: #8fa9bf; border-top: 1px solid rgba(255,255,255,.12); }
.side-footer a { color: #b9cfe0; }

/* --- Contenu --- */
.main { flex: 1; padding: 20px 28px; max-width: 1180px; }
h2 { margin: 0 0 4px; }
h3 { margin: 0 0 10px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; margin: 16px 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.two-col .card { margin: 0; }
.hint { color: var(--muted); font-size: 12px; }
.neg { color: var(--red); }
.pos { color: var(--green); }

/* --- Onglets de mois --- */
.month-tabs { display: flex; gap: 4px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px 6px 0 0; background: #fff; color: var(--text); font-weight: 600; }
.tab.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.account-tabs { display: flex; gap: 4px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.account-tabs a { padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); font-weight: 600; text-decoration: none; }
/* Codes couleur : pastille par type de compte / groupe de catégories. */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; flex-shrink: 0; }
.dot-sm { width: 8px; height: 8px; margin-right: 5px; }

/* Infobulle instantanée (JS, remplace title=). */
.tooltip-bubble { position: fixed; z-index: 100; max-width: 320px; background: #1e3a52; color: #fff; padding: 7px 10px; border-radius: 6px; font-size: 13px; line-height: 1.4; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3); pointer-events: none; }

/* Éditeur d'objectif (crayon ✎) — visible seulement au survol de la catégorie. */
.goal-edit-btn { background: none; border: none; padding: 0 2px; cursor: pointer; color: var(--muted); font-size: 13px; line-height: 1; opacity: 0; transition: opacity .15s; }
/* Crayon + infobulle : seulement sur le texte du nom, pas sur toute la cellule. */
.cat-name-wrap:hover .goal-edit-btn, .cat-name-wrap:focus-within .goal-edit-btn { opacity: 1; }
.goal-edit-btn:hover { color: var(--navy); }
.goal-form { display: inline-flex; gap: 4px; align-items: center; }
.goal-form .goal-input { width: 80px; padding: 2px 4px; }
.goal-form select { padding: 2px 4px; }

/* Bandeau d'alerte : enveloppe(s) en négatif (dépensé en trop). */
.overspent-warning { background: #fdecea; border: 1px solid #e57373; color: #7f1d1d; border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; }
.overspent-warning ul { margin: 6px 0; padding-left: 20px; }
.overspent-warning .hint { color: #7f1d1d; }

/* Cellule d'assignation : champ + boutons calculette. */
.assign-cell { display: flex; gap: 4px; align-items: center; justify-content: flex-end; }
.assign-cell .assign-form { display: flex; }
.assign-cell .money-input { width: 90px; }

/* Calculette flottante (style YNAB4). */
.calc-popup { position: fixed; z-index: 50; width: 232px; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25); padding: 10px; }
.calc-display { text-align: right; font-size: 22px; font-weight: 700; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: #f7f7f7; margin-bottom: 8px; min-height: 42px; }
.calc-display #calc-op { color: var(--navy); margin-right: 6px; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.calc-keys button { padding: 10px 0; font-size: 16px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; }
.calc-keys button:hover { background: #eef2f7; }
.calc-keys .calc-ok { background: var(--navy); color: #fff; border-color: var(--navy); }
.calc-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* Toast de confirmation AJAX. */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; background: #1e3a52; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3); font-weight: 600; }
.toast-error { background: #a33; }
.tab-arrow { font-size: 20px; padding: 2px 10px; color: var(--navy); }

/* --- Prêt à assigner --- */
.atb-box { background: var(--navy); color: #fff; border-radius: 8px; padding: 16px 20px; margin-bottom: 14px; }
.atb-box.neg { background: #7b2d26; }
.atb-label { font-size: 13px; opacity: .85; }
.atb-amount { font-size: 34px; font-weight: 700; line-height: 1.1; }
.atb-sub { opacity: .85; margin-top: 4px; }
.atb-note { margin-top: 8px; font-size: 12px; background: rgba(255,255,255,.12); border-radius: 6px; padding: 8px 10px; }

.quick-actions { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.inline-form { display: inline; }

/* --- Tableaux --- */
table { width: 100%; border-collapse: collapse; background: #fff; }
.budget-table, .tx-table { border: 1px solid var(--border); border-radius: 8px; }
.tx-table { overflow: hidden; }
.budget-table thead th { position: sticky; top: 0; z-index: 5; box-shadow: 0 1px 0 var(--border); }
/* Totaux toujours visibles quand on défile : en-tête en haut, totaux en bas. */
.budget-table tfoot td { position: sticky; bottom: 0; z-index: 5; box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.08); }
.atb-mini { font-weight: 600; color: var(--navy); white-space: nowrap; }
.budget-table th, .budget-table td, .tx-table th, .tx-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.budget-table thead th, .tx-table thead th { background: #f2f6f9; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.col-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.col-cat { min-width: 220px; }
.col-act { white-space: nowrap; text-align: right; }
.group-row td { background: #e8eef3; font-weight: 700; }
.cat-row:hover, .tx-table tbody tr:hover { background: #f6f9fb; }
.budget-table tfoot td { font-weight: 700; background: #f2f6f9; }
tr.overdue td { background: #fdf3e7; }
tr.dupe td { background: #f9ecec; color: var(--muted); }
.goal { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }
.tag { font-size: 10px; background: #dbe7f0; color: var(--navy); border-radius: 4px; padding: 1px 5px; vertical-align: middle; }
.tag-warn { background: #fde8c8; color: var(--amber); }

/* --- Formulaires --- */
label { display: block; margin-bottom: 10px; font-weight: 600; font-size: 13px; }
label .hint { font-weight: 400; }
input[type="text"], input[type="number"], input[type="date"], input[type="password"], input[type="file"], select { width: 100%; padding: 8px 10px; margin-top: 4px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; background: #fff; }
input[type="checkbox"] { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.form-grid button { grid-column: 1 / -1; }
.money-input { width: 110px; text-align: right; }
.assign-form { margin: 0; }

.btn { display: inline-block; padding: 8px 14px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); font-size: 14px; cursor: pointer; }
.btn:hover { background: #f2f6f9; text-decoration: none; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-light); }
.btn-danger { color: var(--red); }
.btn-small { padding: 3px 8px; font-size: 13px; }
.btn-block { width: 100%; }

/* --- Divers --- */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.flash-success { background: #e6f4ea; color: #1e5c26; border: 1px solid #b7dfc0; }
.flash-error { background: #fdecea; color: #7b1f16; border: 1px solid #f5c6c0; }
.account-header { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: baseline; }
.account-balance { font-size: 26px; font-weight: 700; margin-left: auto; }
.badge { font-size: 11px; background: #dbe7f0; color: var(--navy); border-radius: 4px; padding: 2px 6px; vertical-align: middle; }
.blackbox-note { background: #fff8e1; border: 1px solid #ffe08a; border-radius: 6px; padding: 10px 12px; width: 100%; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 6px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 700; margin: 4px 0; }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { width: 240px; flex-shrink: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; background: #eef3f7; border-radius: 4px; height: 18px; overflow: hidden; }
.bar { height: 100%; border-radius: 4px; }
.bar-income { background: #4caf7d; }
.bar-spending { background: #d97b6c; }
.bar-val { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.legend { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; }
.legend-income { background: #4caf7d; }
.legend-spending { background: #d97b6c; }
.info-list { line-height: 1.7; }

/* --- Connexion --- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(160deg, var(--navy), var(--navy-dark)); }
.login-card { background: #fff; border-radius: 10px; padding: 28px 32px; width: 380px; max-width: 92vw; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.login-card h1 { margin: 0 0 4px; color: var(--navy); }
.login-sub { color: var(--muted); margin-top: 0; }
.login-hint { font-size: 12px; color: var(--muted); }

@media (max-width: 800px) {
  .sidebar { width: 200px; }
  .main { padding: 14px; }
  .two-col { grid-template-columns: 1fr; }
  .bar-label { width: 140px; }
}
