/* ─── Google Fonts ────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ─── Reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── Design Tokens ──────────────────────────────────────────────────── */
:root {
  /* Base palette */
  --bg-base: #0c0c18;
  --bg-surface: #13132a;
  --bg-elevated: #1a1a3e;
  --bg-hover: #222250;
  --border: #2a2a55;
  --border-light: #35356a;

  /* Text */
  --text: #e8e8f0;
  --text-muted: #8888aa;
  --text-dim: #555577;

  /* Semantic */
  --positive: #34d399;
  --positive-dim: #34d39930;
  --negative: #f87171;
  --negative-dim: #f8717130;
  --warning: #fbbf24;
  --warning-dim: #fbbf2430;
  --info: #60a5fa;
  --info-dim: #60a5fa30;
  --epargne: #2dd4bf;
  --epargne-dim: #2dd4bf30;
  --accent: #818cf8;
  --accent-dim: #818cf830;

  /* Category colors */
  --cat-logement: #f87171;
  --cat-revenus: #34d399;
  --cat-credits: #fb923c;
  --cat-impots: #a78bfa;
  --cat-banque: #94a3b8;
  --cat-epargne: #2dd4bf;
  --cat-abonnements: #60a5fa;
  --cat-sante: #f472b6;
  --cat-auto: #fb923c;
  --cat-transport: #22d3ee;
  --cat-alimentation: #a3e635;
  --cat-restaurant: #ef4444;
  --cat-shopping: #facc15;
  --cat-loisirs: #c084fc;
  --cat-retrait: #64748b;
  --cat-divers: #78716c;

  /* Spacing (4px grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --fs-xs: 0.6875rem;
  --fs-sm: 0.75rem;
  --fs-base: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 2rem;

  /* Layout */
  --sidebar-width: 220px;
  --sidebar-collapsed: 60px;
  --topbar-height: 56px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  font-size: var(--fs-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Scrollbar ──────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ─── App Layout ─────────────────────────────────────────────────────── */

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  transition: grid-template-columns var(--transition-normal);
}

body.sidebar-collapsed .app-layout {
  grid-template-columns: var(--sidebar-collapsed) 1fr;
}

/* ─── Sidebar ────────────────────────────────────────────────────────── */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 30;
  transition: width var(--transition-normal);
  overflow: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-header {
  display: flex;
  align-items: center;
  height: var(--topbar-height);
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header .logo {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar .nav-list {
  list-style: none;
  padding: var(--space-3) 0;
  flex: 1;
  overflow-y: auto;
}

.sidebar .nav-item a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  color: var(--text-muted);
  font-size: var(--fs-base);
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.sidebar .nav-item a:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.sidebar .nav-item.active a {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-dim);
}

.sidebar .nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.sidebar .nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity var(--transition-fast);
}

.sidebar.collapsed .nav-label { opacity: 0; width: 0; }
.sidebar.collapsed .sidebar-header .logo { opacity: 0; }
.sidebar.collapsed .nav-item a { justify-content: center; padding: var(--space-3) 0; border-left: none; }
.sidebar.collapsed .nav-item.active a { background: var(--accent-dim); border-radius: var(--radius-sm); margin: 0 var(--space-2); }

.sidebar-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-footer .version {
  font-size: var(--fs-xs);
  color: var(--text-dim);
}

.sidebar.collapsed .sidebar-footer .version { display: none; }

/* ─── Main Wrapper ───────────────────────────────────────────────────── */

.main-wrapper {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* ─── Top Bar ────────────────────────────────────────────────────────── */

.top-bar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--topbar-height);
  padding: 0 var(--space-6);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.sidebar-toggle { display: none; }

.top-bar-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}

.search-bar input {
  background: var(--bg-base);
  color: var(--text);
  border: 1px solid var(--border);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  width: 260px;
  transition: border-color var(--transition-fast), width var(--transition-normal);
}
.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
  width: 320px;
}
.search-bar input::placeholder { color: var(--text-dim); }

/* ─── Select ─────────────────────────────────────────────────────────── */

select {
  background: var(--bg-base);
  color: var(--text);
  border: 1px solid var(--border);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}
select:focus { outline: none; border-color: var(--accent); }

/* ─── View Container ─────────────────────────────────────────────────── */

.view-container {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

/* ─── View Transitions ───────────────────────────────────────────────── */

.view-enter {
  animation: viewIn var(--transition-normal) forwards;
}
.view-exit {
  animation: viewOut var(--transition-fast) forwards;
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes viewOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-4px); }
}

/* ─── Card ───────────────────────────────────────────────────────────── */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-6);
}

.card h3 {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-4);
}

/* ─── KPI Card ───────────────────────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.kpi-card:hover {
  border-color: var(--border-light);
  background: var(--bg-elevated);
}

.kpi-value {
  font-size: var(--fs-xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.kpi-value.positive { color: var(--positive); }
.kpi-value.negative { color: var(--negative); }

.kpi-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-sparkline {
  height: 32px;
  margin-top: var(--space-2);
}

/* ─── Charts ─────────────────────────────────────────────────────────── */

.charts-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: var(--space-4);
}

.chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-6);
}

.chart-card h3 {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chart-wrapper {
  position: relative;
  height: 300px;
}

.chart-wrapper-sm {
  position: relative;
  height: 220px;
}

/* ─── Details Grid ───────────────────────────────────────────────────── */

.details-grid {
  display: grid;
  grid-template-columns: 0.4fr 0.6fr;
  gap: var(--space-4);
}

.detail-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-6);
}

.detail-card h3 {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ─── Top Payees ─────────────────────────────────────────────────────── */

.payee-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.payee-row:last-child { border-bottom: none; }
.payee-name {
  flex: 1;
  font-size: var(--fs-base);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.payee-count {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  flex-shrink: 0;
}
.payee-amount {
  font-size: var(--fs-base);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* ─── Table ──────────────────────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-base);
}

thead th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  color: var(--text-muted);
  font-weight: 500;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
}

tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

tbody tr { transition: background var(--transition-fast); }
tbody tr:hover { background: var(--bg-hover); }

.amount { font-variant-numeric: tabular-nums; font-weight: 500; text-align: right; }
.amount.positive { color: var(--positive); }
.amount.negative { color: var(--negative); }

th:last-child, td:last-child { text-align: right; }

/* ─── Badge ──────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: 500;
  white-space: nowrap;
}

.badge.clickable { cursor: pointer; transition: filter var(--transition-fast); }
.badge.clickable:hover { filter: brightness(1.3); }

/* Category badge colors */
.badge-logement      { background: #f8717120; color: var(--cat-logement); }
.badge-revenus       { background: #34d39920; color: var(--cat-revenus); }
.badge-credits       { background: #fb923c20; color: var(--cat-credits); }
.badge-impots        { background: #a78bfa20; color: var(--cat-impots); }
.badge-banque        { background: #94a3b820; color: var(--cat-banque); }
.badge-epargne       { background: #2dd4bf20; color: var(--cat-epargne); }
.badge-abonnements   { background: #60a5fa20; color: var(--cat-abonnements); }
.badge-sante         { background: #f472b620; color: var(--cat-sante); }
.badge-auto          { background: #fb923c20; color: var(--cat-auto); }
.badge-transport     { background: #22d3ee20; color: var(--cat-transport); }
.badge-alimentation  { background: #a3e63520; color: var(--cat-alimentation); }
.badge-restaurant    { background: #ef444420; color: var(--cat-restaurant); }
.badge-shopping      { background: #facc1520; color: var(--cat-shopping); }
.badge-loisirs       { background: #c084fc20; color: var(--cat-loisirs); }
.badge-retrait       { background: #64748b20; color: var(--cat-retrait); }
.badge-divers        { background: #78716c20; color: var(--cat-divers); }

/* ─── Pagination ─────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

#pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.btn-page {
  background: var(--bg-base);
  color: var(--accent);
  border: 1px solid var(--border);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  transition: all var(--transition-fast);
}
.btn-page:hover { background: var(--bg-hover); border-color: var(--border-light); }
.btn-page:disabled { opacity: 0.4; cursor: not-allowed; }

.page-info { font-size: var(--fs-sm); color: var(--text-muted); }

/* ─── Buttons ────────────────────────────────────────────────────────── */

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  font-weight: 500;
  transition: all var(--transition-fast);
}
.btn-primary:hover { filter: brightness(1.15); }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  font-weight: 500;
  transition: all var(--transition-fast);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-light); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }

.btn-danger {
  background: var(--negative);
  color: white;
  border: none;
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  font-weight: 500;
  transition: all var(--transition-fast);
}
.btn-danger:hover { filter: brightness(1.15); }

/* ─── Progress Bar ───────────────────────────────────────────────────── */

.progress-bar {
  height: 6px;
  background: var(--bg-base);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width var(--transition-normal);
  background: var(--accent);
}

.progress-bar-fill.positive { background: var(--positive); }
.progress-bar-fill.negative { background: var(--negative); }
.progress-bar-fill.warning { background: var(--warning); }

/* ─── Modal ──────────────────────────────────────────────────────────── */

.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 100;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.modal.open { display: flex; }

.modal-content {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  min-width: 320px;
  max-width: 420px;
  animation: modalIn var(--transition-normal) forwards;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-content h3 { font-size: var(--fs-md); margin-bottom: var(--space-4); font-weight: 600; }
.modal-content p { font-size: var(--fs-base); margin-bottom: var(--space-2); }
.modal-content .text-muted { color: var(--text-muted); font-size: var(--fs-sm); }

.modal-content select {
  width: 100%;
  margin: var(--space-4) 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

/* ─── Toast Notifications ────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-5);
  font-size: var(--fs-sm);
  color: var(--text);
  pointer-events: auto;
  opacity: 0;
  transform: translateX(100%);
  transition: all var(--transition-normal);
  max-width: 360px;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast-success { border-left: 3px solid var(--positive); }
.toast-error   { border-left: 3px solid var(--negative); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-info    { border-left: 3px solid var(--info); }

/* ─── Skeleton Loading ───────────────────────────────────────────────── */

.skeleton {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--bg-elevated) 50%,
    transparent 100%
  );
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.skeleton-kpi {
  height: 88px;
}

.skeleton-chart {
  height: 300px;
  margin-top: var(--space-4);
}

.skeleton-row {
  height: 40px;
  margin-bottom: var(--space-2);
}

.skeleton-text {
  height: 14px;
  width: 60%;
  margin-bottom: var(--space-2);
}

/* ─── Loading Screen ─────────────────────────────────────────────────── */

.loading-screen {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-6);
}

.error-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-16);
  text-align: center;
}
.error-screen h2 { color: var(--negative); font-size: var(--fs-xl); }
.error-screen p { color: var(--text-muted); }

/* ─── Patrimoine Section ─────────────────────────────────────────────── */

.patrimoine-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-6);
}
.patrimoine-section h3 {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.patrimoine-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

.patrimoine-card {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-5);
}
.patrimoine-card h4 {
  font-size: var(--fs-base);
  font-weight: 600;
  margin-bottom: var(--space-3);
}
.patrimoine-card .patrimoine-solde {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--positive);
  margin-bottom: var(--space-3);
}
.patrimoine-row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-1) 0;
  font-size: var(--fs-sm);
}
.patrimoine-row .patrimoine-label { color: var(--text-muted); }
.patrimoine-row .patrimoine-value { font-variant-numeric: tabular-nums; }

/* ─── Banking Costs ──────────────────────────────────────────────────── */

.banking-costs-section { max-width: 600px; }

/* ─── Heatmap ────────────────────────────────────────────────────────── */

.heatmap-container { overflow-x: auto; }

.heatmap-months {
  display: flex;
  gap: 0.25rem;
  margin-bottom: var(--space-2);
  padding-left: 2rem;
}
.heatmap-month-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-align: center;
}

.heatmap-grid { display: flex; gap: 3px; }
.heatmap-week { display: flex; flex-direction: column; gap: 3px; }

.heatmap-cell {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  cursor: default;
}
.heatmap-cell[data-level="0"] { background: var(--bg-base); }
.heatmap-cell[data-level="1"] { background: #0e4429; }
.heatmap-cell[data-level="2"] { background: #006d32; }
.heatmap-cell[data-level="3"] { background: #26a641; }
.heatmap-cell[data-level="4"] { background: #39d353; }

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: var(--space-2);
  justify-content: flex-end;
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

/* ─── Dropdown Multi-Select ──────────────────────────────────────────── */

.dropdown-multi { position: relative; }

.dropdown-toggle {
  background: var(--bg-base);
  color: var(--text);
  border: 1px solid var(--border);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color var(--transition-fast);
}
.dropdown-toggle:hover { border-color: var(--accent); }

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: var(--space-1);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  z-index: 20;
  min-width: 180px;
  max-height: 300px;
  overflow-y: auto;
}
.dropdown-menu.open { display: block; }

.dropdown-menu label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  font-size: var(--fs-sm);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.dropdown-menu label:hover { background: var(--bg-hover); }
.dropdown-menu input[type="checkbox"] { accent-color: var(--accent); }

/* ─── Search Count ───────────────────────────────────────────────────── */

.search-count {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-left: var(--space-2);
  white-space: nowrap;
}

/* ─── Footer ─────────────────────────────────────────────────────────── */

.app-footer {
  text-align: center;
  padding: var(--space-4) var(--space-6);
  color: var(--text-dim);
  font-size: var(--fs-xs);
  border-top: 1px solid var(--border);
}

/* ─── Mobile Bottom Nav ──────────────────────────────────────────────── */

.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  z-index: 30;
  justify-content: space-around;
  align-items: center;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: var(--fs-xs);
  padding: var(--space-2);
  transition: color var(--transition-fast);
}
.mobile-nav-item:hover,
.mobile-nav-item.active { color: var(--accent); text-decoration: none; }

/* ─── Depenses layout ────────────────────────────────────────────────── */

.depenses-layout {
  display: grid;
  grid-template-columns: 1fr 0.45fr;
  gap: var(--space-4);
}

/* ─── Responsive: 900–1199px — Collapsed sidebar ─────────────────────── */

@media (max-width: 1199px) and (min-width: 900px) {
  .sidebar { width: var(--sidebar-collapsed); }
  .sidebar .nav-label { opacity: 0; width: 0; }
  .sidebar .sidebar-header .logo { opacity: 0; }
  .sidebar .nav-item a { justify-content: center; padding: var(--space-3) 0; border-left: none; }
  .sidebar .nav-item.active a { background: var(--accent-dim); border-radius: var(--radius-sm); margin: 0 var(--space-2); }
  .sidebar .sidebar-footer .version { display: none; }
  .app-layout { grid-template-columns: var(--sidebar-collapsed) 1fr; }
}

/* ─── Responsive: < 900px — No sidebar, bottom nav ───────────────────── */

@media (max-width: 899px) {
  .sidebar { display: none; }
  .app-layout { grid-template-columns: 1fr; }
  .sidebar-toggle { display: flex; }
  .mobile-nav { display: flex; }

  body { padding-bottom: 56px; }

  .view-container { padding: var(--space-4); }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .details-grid { grid-template-columns: 1fr; }
  .patrimoine-grid { grid-template-columns: 1fr; }

  /* Show sidebar as overlay on toggle */
  .sidebar.open {
    display: flex;
    width: var(--sidebar-width);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }

  /* Depenses : single column, chart d'abord puis table */
  .depenses-layout { grid-template-columns: 1fr; }
  .depenses-layout > .card:last-child { order: -1; }

  /* Charts : scroll horizontal sur mobile */
  .chart-card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .chart-wrapper {
    min-width: 480px;
  }
  .chart-wrapper-sm {
    min-width: 360px;
  }

  /* Table cells : wrap text */
  tbody td {
    white-space: normal;
    max-width: none;
    overflow: visible;
    padding: var(--space-2) var(--space-3);
  }

  /* Heatmap scroll indicator */
  .heatmap-container {
    position: relative;
  }
  .heatmap-container::after {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, var(--bg-surface));
    pointer-events: none;
  }

  /* Mobile nav : bigger touch targets */
  .mobile-nav-item {
    font-size: var(--fs-sm);
    min-height: 44px;
  }
}

/* ─── Responsive: < 600px — Single column, stacked ───────────────────── */

@media (max-width: 599px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .top-bar { padding: 0 var(--space-3); gap: var(--space-2); }

  .search-bar input { width: 140px; }
  .search-bar input:focus { width: 180px; }

  .top-bar-center { justify-content: flex-start; }

  .view-container { padding: var(--space-3); gap: var(--space-4); }

  /* Top bar : allow wrap */
  .top-bar {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--topbar-height);
  }
}

/* ─── Utility classes ────────────────────────────────────────────────── */

.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-positive { color: var(--positive); }
.text-negative { color: var(--negative); }
.text-warning { color: var(--warning); }
.text-accent { color: var(--accent); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

.font-mono { font-variant-numeric: tabular-nums; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
