/* ─── Polices locales (téléchargées, pour un vrai fonctionnement hors-ligne) ─ */

@font-face {
  font-family: "Fraunces";
  src: url("../fonts/fraunces-variable.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../fonts/plexsans-variable.woff2") format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("../fonts/plexmono-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("../fonts/plexmono-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("../fonts/plexmono-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

/* ─── Palette ────────────────────────────────────────────────────────── */

:root {
  --bg: #100f0d;
  --surface: #1a1815;
  --surface-2: #221f1a;
  --border: #33302a;
  --text: #ece7dd;
  --text-dim: #a39c8e;
  --text-faint: #6f6a5f;

  --gold: #c9a961; /* sécurité / matelas / Livret A */
  --gold-dim: rgba(201, 169, 97, 0.14);
  --sage: #7fa98c; /* croissance / PEA */
  --sage-dim: rgba(127, 169, 140, 0.14);

  --danger: #d97757;
  --danger-dim: rgba(217, 119, 87, 0.14);

  --radius: 14px;
  --font-heading: "Fraunces", Georgia, serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

/* ─── Base ───────────────────────────────────────────────────────────── */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
  padding-bottom: 76px; /* place pour la barre de navigation fixe */
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  font-family: var(--font-heading);
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 1.5rem;
}
h2 {
  font-size: 1.15rem;
}
h3 {
  font-size: 1rem;
}

p {
  margin: 0;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.text-dim {
  color: var(--text-dim);
}
.text-faint {
  color: var(--text-faint);
  font-size: 0.8rem;
}

/* ─── Structure ──────────────────────────────────────────────────────── */

header.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: rgba(16, 15, 13, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

header.app-header h1 {
  font-size: 1.2rem;
}
header.app-header .brand-accent {
  color: var(--gold);
}

.header-actions {
  display: flex;
  gap: 8px;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.view {
  display: none;
  flex-direction: column;
  gap: 14px;
}
.view.active {
  display: flex;
}

nav.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

nav.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-faint);
  font-family: var(--font-body);
  font-size: 0.7rem;
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}

nav.bottom-nav button .nav-icon {
  font-size: 1.2rem;
}

nav.bottom-nav button.active {
  color: var(--gold);
}

/* ─── Cartes & sections ──────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card.accent-gold {
  border-color: rgba(201, 169, 97, 0.35);
}
.card.accent-sage {
  border-color: rgba(127, 169, 140, 0.35);
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.divider {
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* ─── Formulaires ────────────────────────────────────────────────────── */

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

input,
select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  width: 100%;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--gold);
}

input[type="date"] {
  font-family: var(--font-body);
}

.field-row {
  display: flex;
  gap: 8px;
}
.field-row > * {
  flex: 1;
}

fieldset {
  border: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ─── Boutons ────────────────────────────────────────────────────────── */

button {
  cursor: pointer;
  font-family: var(--font-body);
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
}
.btn:hover {
  border-color: var(--text-faint);
}

.btn-gold {
  background: var(--gold);
  border-color: var(--gold);
  color: #1a1204;
  font-weight: 600;
}
.btn-sage {
  background: var(--sage);
  border-color: var(--sage);
  color: #0e1b12;
  font-weight: 600;
}
.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn-icon {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 8px;
  line-height: 1;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, background-color 0.15s ease;
}
.btn-icon svg {
  width: 20px;
  height: 20px;
}
.btn-icon:hover,
.btn-icon:focus-visible {
  color: var(--gold);
  background: var(--gold-dim);
  outline: none;
}
.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ─── Listes de dépenses (Module 1) ──────────────────────────────────── */

.expense-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.expense-item input[type="text"] {
  flex: 2;
}
.expense-item input[type="number"] {
  flex: 1;
}

/* ─── Barres de comparaison (Module 1) ───────────────────────────────── */

.compare-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.compare-track {
  position: relative;
  height: 10px;
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
}
.compare-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 6px;
}
.compare-marker {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 16px;
  background: var(--text);
}

/* ─── Jauge circulaire (Module 2 / Dashboard) ────────────────────────── */

.gauge-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.gauge svg {
  transform: rotate(-90deg);
}
.gauge-value {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 600;
}

/* ─── Badges / verdicts ──────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.badge-gold {
  background: var(--gold-dim);
  color: var(--gold);
}
.badge-sage {
  background: var(--sage-dim);
  color: var(--sage);
}
.badge-danger {
  background: var(--danger-dim);
  color: var(--danger);
}

.verdict {
  font-family: var(--font-heading);
  font-size: 1.1rem;
}

/* ─── Tableaux (Module 3) ────────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
th,
td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
}
th {
  color: var(--text-faint);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
td.mono,
th.num {
  text-align: right;
}

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

/* ─── Graphique PRU (Module 3) ───────────────────────────────────────── */

.chart-wrap {
  width: 100%;
}
.chart-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}

/* ─── Messages ───────────────────────────────────────────────────────── */

.banner {
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.88rem;
  display: none;
}
.banner.show {
  display: block;
}
.banner-error {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(217, 119, 87, 0.35);
}
.banner-success {
  background: var(--sage-dim);
  color: var(--sage);
  border: 1px solid rgba(127, 169, 140, 0.35);
}

.empty-state {
  color: var(--text-faint);
  font-size: 0.85rem;
  text-align: center;
  padding: 12px 0;
}

/* ─── Grilles récap (Module 4) ───────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat .stat-value {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 600;
}
.stat .stat-label {
  font-size: 0.72rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

@media (min-width: 640px) {
  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
