:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #e2e4e9;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --positive: #16794e;
  --negative: #c0362c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

.screen { min-height: 100vh; }

/* ---- Login ---- */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--card);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: min(320px, 90vw);
}
.login-card h1 { margin: 0 0 0.5rem; font-size: 1.4rem; text-align: center; }
.login-card input {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}
.login-card button {
  padding: 0.6rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  cursor: pointer;
}
.login-card button:hover { background: var(--accent-hover); }
.error { color: var(--negative); min-height: 1.2em; margin: 0; font-size: 0.9rem; }

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.topbar h1 { font-size: 1.2rem; margin: 0; }
.tabs { display: flex; gap: 0.5rem; flex: 1; }
.tab-btn {
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--muted);
}
.tab-btn.active { background: var(--accent); color: white; }
.ghost {
  border: 1px solid var(--border);
  background: transparent;
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
}

main { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }
.tab-panel h2 { font-size: 1.05rem; margin: 1.5rem 0 0.5rem; }

.month-controls { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
select, input[type="date"], input[type="text"], input[type="number"], input[type="password"] {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
}

button {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
button:hover { background: var(--accent-hover); }
button.danger { background: transparent; border-color: var(--negative); color: var(--negative); }
button.danger:hover { background: var(--negative); color: white; }

.budget-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 700px) { .budget-grid { grid-template-columns: 1fr; } }

.table-scroll { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; background: var(--card); border-radius: 8px; overflow: hidden; }
th, td { padding: 0.5rem 0.7rem; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; }
thead th { background: #eef0f3; font-weight: 600; font-size: 0.85rem; color: var(--muted); }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }

.budget-table td input[type="number"] { width: 5.5rem; text-align: right; }
.diff-positive { color: var(--positive); }
.diff-negative { color: var(--negative); }

.inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.inline-form input, .inline-form select { flex: 1 1 auto; min-width: 8rem; }

tr.section-total td { background: #f0f2f5; font-weight: 600; }

.annual-table th, .annual-table td { font-size: 0.85rem; }

/* ---- Patrimoine ---- */
.patrimoine-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.net-worth { display: flex; flex-direction: column; }
.net-worth-label { font-size: 0.9rem; color: var(--muted); }
.net-worth-value { font-size: 2.2rem; font-weight: 700; }
.brut-field label { font-size: 0.9rem; color: var(--muted); display: flex; align-items: center; gap: 0.5rem; }
.patrimoine-actions { display: flex; gap: 0.5rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; color: var(--muted); flex: 0 0 auto; }

.patrimoine-section { margin-bottom: 1.5rem; }
.patrimoine-section h2 { display: flex; justify-content: space-between; align-items: baseline; }
.patrimoine-section h2 .section-total { font-weight: 700; font-size: 1rem; }
