/* ============================================================
   Budget App — CSS principal
   Variables, reset, layout, composants
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --color-bg:          #F9FAFB;
  --color-surface:     #FFFFFF;
  --color-border:      #E5E7EB;
  --color-border-light:#F3F4F6;

  --color-text:        #111827;
  --color-text-muted:  #6B7280;
  --color-text-light:  #9CA3AF;

  --color-primary:     #3B82F6;
  --color-primary-dark:#2563EB;
  --color-primary-light:#EFF6FF;

  --color-success:     #10B981;
  --color-success-light:#ECFDF5;
  --color-warning:     #F59E0B;
  --color-warning-light:#FFFBEB;
  --color-danger:      #EF4444;
  --color-danger-light:#FEF2F2;
  --color-info:        #3B82F6;
  --color-info-light:  #EFF6FF;

  --color-positive:    #10B981;
  --color-negative:    #EF4444;

  --font:              -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:         'SF Mono', SFMono-Regular, ui-monospace, monospace;

  --radius:            0.5rem;
  --radius-sm:         0.25rem;
  --radius-lg:         0.75rem;

  --shadow-sm:         0 1px 2px rgba(0,0,0,.05);
  --shadow:            0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:         0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);

  --sidebar-width:     240px;
  --topbar-height:     56px;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--color-bg); color: var(--color-text); line-height: 1.5; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ── Layout principal ──────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 1.25rem 1rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-primary);
  border-bottom: 1px solid var(--color-border);
  text-decoration: none;
}
.sidebar-logo:hover { text-decoration: none; }
.sidebar-logo svg { flex-shrink: 0; }

.sidebar-nav {
  padding: .75rem 0;
  flex: 1;
}
.nav-section {
  padding: .25rem 0;
}
.nav-section-title {
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--color-text-light);
  padding: .5rem 1rem .25rem;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .5rem 1rem;
  color: var(--color-text-muted);
  font-size: .875rem;
  border-radius: 0;
  transition: background .15s, color .15s;
  text-decoration: none;
  position: relative;
}
.nav-link:hover { background: var(--color-border-light); color: var(--color-text); text-decoration: none; }
.nav-link.active { background: var(--color-primary-light); color: var(--color-primary); font-weight: 500; }
.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--color-primary);
  border-radius: 0 2px 2px 0;
}
.nav-link svg { flex-shrink: 0; opacity: .7; }
.nav-link.active svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--color-danger);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  padding: .1rem .4rem;
  border-radius: 999px;
  min-width: 1.2rem;
  text-align: center;
}

.sidebar-footer {
  padding: .75rem 1rem;
  border-top: 1px solid var(--color-border);
  font-size: .8rem;
  color: var(--color-text-muted);
}
.sidebar-footer .user-name { font-weight: 500; color: var(--color-text); }

/* Main content */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-weight: 600; font-size: 1rem; }
.topbar-actions { margin-left: auto; display: flex; gap: .5rem; align-items: center; }

.page-content {
  padding: 1.5rem;
  flex: 1;
}

/* ── Cartes / Sections ──────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: .75rem;
}
.card-title { font-weight: 600; font-size: .9375rem; }
.card-actions { margin-left: auto; display: flex; gap: .5rem; }
.card-body { padding: 1.25rem; }
.card-footer {
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-border-light);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ── Grille stats ───────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--color-text-muted); font-weight: 500; margin-bottom: .25rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-sub { font-size: .75rem; color: var(--color-text-muted); margin-top: .25rem; }

/* ── Boutons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary   { background: var(--color-primary);  color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }

.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-border-light); }

.btn-danger    { background: var(--color-danger);   color: #fff; border-color: var(--color-danger); }
.btn-danger:hover { opacity: .85; }

.btn-success   { background: var(--color-success);  color: #fff; border-color: var(--color-success); }
.btn-ghost     { background: transparent; color: var(--color-text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--color-border-light); color: var(--color-text); }

.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-lg { padding: .75rem 1.5rem; font-size: 1rem; }

/* ── Formulaires ────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .375rem; color: var(--color-text); }
.form-label .required { color: var(--color-danger); margin-left: .2rem; }

.form-control {
  display: block;
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: .875rem;
  line-height: 1.5;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.form-control.is-invalid { border-color: var(--color-danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px rgba(239,68,68,.15); }

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-hint { font-size: .75rem; color: var(--color-text-muted); margin-top: .25rem; }
.form-error { font-size: .75rem; color: var(--color-danger); margin-top: .25rem; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

.form-check { display: flex; align-items: center; gap: .5rem; }
.form-check input[type=checkbox] { width: 1rem; height: 1rem; cursor: pointer; }
.form-check-label { font-size: .875rem; cursor: pointer; }

/* ── Tableaux ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead tr { background: var(--color-border-light); }
th {
  text-align: left;
  padding: .625rem 1rem;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--color-border-light); }
.table-actions { display: flex; gap: .375rem; justify-content: flex-end; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-primary { background: var(--color-primary-light); color: var(--color-primary); }
.badge-success { background: var(--color-success-light); color: var(--color-success); }
.badge-warning { background: var(--color-warning-light); color: var(--color-warning); }
.badge-danger  { background: var(--color-danger-light);  color: var(--color-danger); }
.badge-muted   { background: var(--color-border);        color: var(--color-text-muted); }

/* ── Montants ───────────────────────────────────────────────── */
.amount-positive { color: var(--color-positive); font-weight: 600; font-family: var(--font-mono); }
.amount-negative { color: var(--color-negative); font-weight: 600; font-family: var(--font-mono); }
.amount-zero     { color: var(--color-text-muted); font-family: var(--font-mono); }

/* ── Alertes / Flash ────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .875rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.alert-success { background: var(--color-success-light); color: #065F46; border-color: #A7F3D0; }
.alert-error   { background: var(--color-danger-light);  color: #991B1B; border-color: #FECACA; }
.alert-warning { background: var(--color-warning-light); color: #92400E; border-color: #FDE68A; }
.alert-info    { background: var(--color-info-light);    color: #1E40AF; border-color: #BFDBFE; }

/* ── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: .25rem;
  justify-content: center;
  padding: 1rem 0;
}
.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 .5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  color: var(--color-text-muted);
  background: var(--color-surface);
  text-decoration: none;
}
.page-link:hover { background: var(--color-border-light); text-decoration: none; }
.page-link.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.page-link.disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }

/* ── Filtres / Barre de recherche ───────────────────────────── */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: flex-end;
  padding: 1rem;
  background: var(--color-border-light);
  border-bottom: 1px solid var(--color-border);
  border-radius: var(--radius) var(--radius) 0 0;
}
.filters-bar .form-group { margin-bottom: 0; }
.filters-bar .form-label { font-size: .75rem; }
.filters-bar .form-control { font-size: .8125rem; padding: .375rem .625rem; }

/* ── Catégorie color dot ────────────────────────────────────── */
.cat-dot {
  width: .625rem;
  height: .625rem;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.cat-label {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  font-size: .8125rem;
}

/* ── Vide / Empty state ─────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
}
.empty-state svg { margin: 0 auto 1rem; opacity: .3; }
.empty-state h3 { font-size: 1rem; font-weight: 600; margin-bottom: .5rem; color: var(--color-text); }
.empty-state p { font-size: .875rem; }

/* ── Page header ────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.375rem; font-weight: 700; }

/* ── Utilitaires ────────────────────────────────────────────── */
.text-muted  { color: var(--color-text-muted); }
.text-small  { font-size: .8125rem; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.font-mono   { font-family: var(--font-mono); }
.font-bold   { font-weight: 700; }
.mt-1 { margin-top: .25rem; } .mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; } .mt-4 { margin-top: 1rem; }
.mb-1 { margin-bottom: .25rem; } .mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: .75rem; } .mb-4 { margin-bottom: 1rem; }
.gap-1 { gap: .25rem; } .gap-2 { gap: .5rem; }
.flex { display: flex; } .items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ── Responsive mobile ──────────────────────────────────────── */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text);
  padding: .25rem;
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .main-content { margin-left: 0; }

  .menu-toggle { display: flex; align-items: center; }

  .overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
  }
  .overlay.open { display: block; }

  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .page-content { padding: 1rem; }

  th, td { padding: .5rem .75rem; }
  .table-responsive-hide { display: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}
