:root {
  --navy: #1B3A5C;
  --navy-dark: #12293F;
  --emerald: #0E6E5A;
  --emerald-light: #E4F3EF;
  --gold: #C9A227;
  --gold-light: #FBF3DC;
  --danger: #C0392B;
  --bg: #F5F7FA;
  --card: #FFFFFF;
  --text: #1F2937;
  --muted: #6B7280;
  --border: #E5E9F0;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

/* Barre mobile (logo + hamburger) — masquée par défaut, montrée sous 640px */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--navy-dark);
  color: #fff;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 60;
}
.mobile-topbar .brand { margin-bottom: 0; }
.mobile-toggle {
  background: none; border: none; color: #fff; font-size: 24px;
  line-height: 1; cursor: pointer; padding: 6px 8px; border-radius: 8px;
}
.mobile-toggle:hover { background: rgba(255,255,255,.08); }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(10,20,32,.5);
  z-index: 65;
}
.sidebar-overlay.open { display: block; }

/* Sidebar — position FIXE (pas sticky) : le bouton déconnexion reste
   toujours visible à l'écran, quelle que soit la hauteur du contenu. */
.sidebar {
  width: 230px;
  background: var(--navy-dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 70;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; margin-bottom: 32px; padding: 0 8px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gold); display: inline-block; flex-shrink: 0; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar nav a {
  color: #C7D2E0;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 10px;
  font-weight: 500;
  font-size: 14.5px;
  transition: background .15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); }
.sidebar nav a.active { background: var(--emerald); color: #fff; }
.sidebar-footer {
  font-size: 12px;
  color: #7C8DA6;
  padding: 12px 8px 4px;
  border-top: 1px solid rgba(255,255,255,.08);
  margin-top: 12px;
  flex-shrink: 0;
}
.sidebar-footer a { display: inline-block; margin-top: 2px; }

/* Content — décalé de la largeur de la sidebar fixe */
.content { flex: 1; padding: 32px 40px; max-width: 1200px; margin-left: 230px; }

.page-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 26px; font-weight: 800; color: var(--navy); }
.page-header p { color: var(--muted); font-size: 14px; margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--emerald); color: #fff; border: none;
  padding: 10px 18px; border-radius: 10px; font-weight: 600; font-size: 14px;
  cursor: pointer; text-decoration: none; transition: opacity .15s;
}
.btn:hover { opacity: .9; }
.btn.secondary { background: #fff; color: var(--navy); border: 1px solid var(--border); }
.btn.gold { background: var(--gold); color: var(--navy-dark); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 12.5px; }

/* Cards */
.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; margin-bottom: 28px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
}
.card-label { font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.card-value { font-size: 24px; font-weight: 800; color: var(--navy); margin-top: 6px; }
.card-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }

.pilier-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 4px 12px; border-radius: 20px; }

.progress-track { width: 100%; height: 9px; background: #EEF1F5; border-radius: 20px; overflow: hidden; margin-top: 10px; }
.progress-fill { height: 100%; border-radius: 20px; transition: width .4s; }

.preset-row { display: flex; flex-wrap: wrap; gap: 10px; }
.preset-btn { font-weight: 700; }

.pilier-block { border-left: 4px solid var(--border); padding: 16px 0 16px 18px; margin-bottom: 22px; }
.pilier-block:last-child { margin-bottom: 0; }

.hidden { display: none !important; }
.edit-row td { background: var(--bg); border-radius: 10px; padding: 14px 10px !important; }

/* Grille historique des budgets */
.records-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.record-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column;
}
.record-card.active { border-color: var(--emerald); box-shadow: 0 0 0 2px var(--emerald-light); }
.record-card-header { display: flex; justify-content: space-between; align-items: center; font-size: 15px; }
.record-card-line { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 8px; }
.record-card-line b { color: var(--text); font-weight: 700; }

.grid-2 { display: grid; grid-template-columns: 1.1fr .9fr; gap: 24px; align-items: start; }

/* ===================== Responsive ===================== */

/* Tablette / petit desktop : sidebar plus étroite mais toujours en texte complet */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 24px; margin-left: 200px; }
  .sidebar { width: 200px; }
}

/* Mobile : la sidebar devient un tiroir masqué, ouvert via le bouton hamburger */
@media (max-width: 640px) {
  .mobile-topbar { display: flex; }
  .app-shell { display: block; }

  .sidebar {
    width: 260px;
    max-width: 82vw;
    transform: translateX(-100%);
    transition: transform .25s ease;
    padding-top: 24px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 6px 0 28px rgba(0,0,0,.3); }

  .content { margin-left: 0; margin-top: 56px; padding: 16px; }
  .page-header { align-items: flex-start; }
  .page-header h1 { font-size: 21px; }
  .cards-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 14px; }
  .card-value { font-size: 19px; }
  .panel { padding: 16px; }
  form.form-grid { grid-template-columns: 1fr; }
  .btn { width: 100%; justify-content: center; }
  .preset-row .btn, .cat-row .btn, table .btn, .record-card .btn { width: auto; }
}

/* Très petit écran */
@media (max-width: 380px) {
  .cards-row { grid-template-columns: 1fr; }
}

/* Tableaux : scroll horizontal plutôt que d'écraser le contenu */
.panel { overflow-x: auto; }
@media (max-width: 640px) {
  table { min-width: 480px; }
}

.panel { background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); padding: 22px; margin-bottom: 20px; }
.panel h2 { font-size: 16px; font-weight: 700; color: var(--navy); margin-bottom: 16px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 12px; text-transform: uppercase; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }

.cat-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); }
.cat-row:last-child { border-bottom: none; }
.cat-name { font-weight: 600; font-size: 14px; }
.cat-amounts { font-size: 12.5px; color: var(--muted); }
.cat-amounts b { color: var(--text); }

form.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field input, .field select {
  padding: 10px 12px; border-radius: 9px; border: 1px solid var(--border);
  font-family: inherit; font-size: 14px; background: #fff;
}
.field input:focus, .field select:focus { outline: 2px solid var(--emerald); border-color: transparent; }

/* "Input group" : le cadre visuel (bordure/fond/radius) est porté par
   .password-wrap ; le champ et le bouton sont deux éléments flex côte à
   côte à l'intérieur, donc aucun chevauchement possible et le bouton garde
   toujours sa propre taille, quoi qu'il arrive ailleurs dans la cascade. */
.password-wrap {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  overflow: hidden;
}
.password-wrap:focus-within { outline: 2px solid var(--emerald); }
.password-wrap input {
  flex: 1 1 auto;
  min-width: 0;
  width: auto !important;
  border: none !important;
  border-radius: 0 !important;
  background: transparent !important;
  outline: none !important;
}
.password-toggle {
  flex: 0 0 42px;
  width: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--muted);
}
.password-toggle:hover { color: var(--text); }

.pct-warning { font-size: 13px; padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }
.pct-warning.ok { background: var(--emerald-light); color: var(--emerald); }
.pct-warning.bad { background: #FCEAE8; color: var(--danger); }

.chart-wrap { position: relative; height: 260px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state a { color: var(--emerald); font-weight: 600; }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-size: 14px; font-weight: 500; }
.flash.success { background: var(--emerald-light); color: var(--emerald); }
.flash.error { background: #FCEAE8; color: var(--danger); }

.icon-btn { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 14px; }
.icon-btn:hover { color: var(--danger); }
