/* ── Variables ───────────────────────────────────────────────────────────────── */
:root {
  --primary:        #1e3a5f;
  --primary-h:      #2d5a8e;
  --expense:        #dc3545;
  --expense-bg:     #fde8e8;
  --income:         #198754;
  --income-bg:      #d1e7dd;
  --pointed:    #1a73e8;
  --pointed-bg: #dbeafe;
  --bg:             #f4f6f8;
  --card:           #ffffff;
  --text:           #212529;
  --muted:          #6c757d;
  --border:         #dee2e6;
}

/* ── Reset & Base ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ──────────────────────────────────────────────────────────────────── */
.navbar {
  background: var(--primary); padding: 0 1.5rem;
  display: flex; align-items: center; gap: 2rem; height: 52px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.nav-brand { color: #fff; font-size: 1.1rem; font-weight: 700; letter-spacing: -0.01em; }
.nav-brand:hover { text-decoration: none; color: #fff; }
.nav-links { display: flex; gap: 0.25rem; }
.nav-links a {
  color: rgba(255,255,255,0.75); padding: 0.3rem 0.75rem;
  border-radius: 5px; font-size: 0.875rem; transition: all 0.15s;
}
.nav-links a:hover, .nav-links a.active {
  color: #fff; background: rgba(255,255,255,0.18); text-decoration: none;
}
.nav-logout {
  margin-left: auto; color: rgba(255,255,255,0.65); font-size: 0.8rem;
  padding: 0.25rem 0.65rem; border: 1px solid rgba(255,255,255,0.25);
  border-radius: 4px; transition: all 0.15s; white-space: nowrap;
}
.nav-logout:hover { color: #fff; border-color: rgba(255,255,255,0.6); text-decoration: none; }

/* ── Layout ──────────────────────────────────────────────────────────────────── */
.main-content { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }
.page-header { margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.4rem; font-weight: 700; color: var(--primary); }

/* ── Card ────────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card); border-radius: 8px; padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 8px rgba(0,0,0,0.04);
  margin-bottom: 1.25rem;
}
.card h2 { font-size: 0.95rem; font-weight: 700; color: var(--primary); margin-bottom: 1rem; }
.card-header-row {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;
}
.card-header-row h2 { margin-bottom: 0; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.4rem 0.9rem; border: none; border-radius: 5px;
  font-size: 0.875rem; font-weight: 500; cursor: pointer;
  transition: background 0.15s, filter 0.15s; white-space: nowrap; line-height: 1.4;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); color: #fff; text-decoration: none; }
.btn-secondary { background: #e9ecef; color: var(--text); }
.btn-secondary:hover { background: #d1d5db; color: var(--text); text-decoration: none; }
.btn-secondary.disabled { opacity: 0.45; pointer-events: none; }
.btn-unpoint  { background: #f8d7da; color: var(--expense); }
.btn-unpoint:hover { background: #f5c2c7; }
.btn-icon {
  background: none; border: none; cursor: pointer; font-size: 1rem;
  padding: 0.2rem 0.4rem; border-radius: 4px; transition: background 0.15s;
}
.btn-icon:hover { background: #f0f0f0; }
.btn-danger { background: var(--expense); color: #fff; }
.btn-danger:hover { background: #b02a37; }
.btn-icon.btn-danger { color: var(--expense); }
.btn-icon.btn-danger:hover { background: var(--expense-bg); }

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.form-config label, .form-grid label, .modal-field {
  display: flex; flex-direction: column; gap: 0.3rem;
  font-weight: 500; font-size: 0.875rem;
}
.form-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.75rem; margin-bottom: 0.75rem;
}
input[type="text"], input[type="number"], input[type="date"], select {
  padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: 4px;
  font-size: 0.875rem; width: 100%; background: #fff; color: var(--text);
}
input:focus, select:focus {
  outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent;
}
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 0.5rem !important; }
.checkbox-label input { width: auto; }
.op-form {
  background: #f8f9fa; border-radius: 6px; padding: 1rem; margin-bottom: 1rem;
  border: 1px solid var(--border);
}
.op-form h3 { font-size: 0.875rem; font-weight: 700; color: var(--primary); margin-bottom: 0.75rem; }

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em;
}
.badge-expense { background: var(--expense-bg); color: var(--expense); }
.badge-income  { background: var(--income-bg);  color: var(--income); }

/* ── Tables (général) ────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
th {
  font-weight: 700; font-size: 0.75rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); background: #f8f9fa;
}
tr:last-child td { border-bottom: none; }
.table-ops tbody tr:hover td { background: #f8f9fa; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.expense { color: var(--expense); }
.income  { color: var(--income); }
.positive { color: var(--income); font-weight: 600; }
.negative { color: var(--expense); font-weight: 600; }
tr.inactive td { opacity: 0.45; }
.actions { white-space: nowrap; text-align: right; }

/* ── Dashboard recap table ───────────────────────────────────────────────────── */
.table-recap .year-separator td {
  font-size: 0.72rem; font-weight: 700; color: var(--muted);
  background: #f0f4f8; padding: 0.3rem 0.75rem; letter-spacing: 0.1em;
  text-align: center;
}
.table-recap .balance-real { font-weight: 700; }
.month-link { color: var(--primary); font-weight: 600; }
.month-link:hover { text-decoration: underline; }

/* ── Generate card ───────────────────────────────────────────────────────────── */
.generate-card {
  display: flex; justify-content: space-between; align-items: center; padding: 0.9rem 1.25rem;
}
.generate-info { font-size: 0.9rem; color: var(--muted); }
.generate-info strong { color: var(--text); font-weight: 600; }
.generate-buttons { display: flex; gap: 0.5rem; }

/* ── Month page header ───────────────────────────────────────────────────────── */
.month-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; }
.month-nav { display: flex; align-items: center; gap: 0.75rem; }
.month-nav h1 { font-size: 1.25rem; min-width: 180px; text-align: center; }
.month-summary { display: flex; gap: 1.5rem; }
.month-summary span {
  display: flex; flex-direction: column; align-items: flex-end;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted); gap: 0.1rem;
}
.month-summary strong { font-size: 1rem; font-weight: 700; color: var(--text); }
.month-summary strong.positive { color: var(--income); }
.month-summary strong.negative { color: var(--expense); }
.btn-regen {
  background: #f0f4f8; color: var(--muted); border: 1px solid var(--border);
  font-size: 0.78rem; padding: 0.3rem 0.7rem; border-radius: 5px; cursor: pointer;
  transition: background 0.15s, color 0.15s; align-self: center;
}
.btn-regen:hover { background: #e2e8f0; color: var(--text); }

/* ── Month grid ──────────────────────────────────────────────────────────────── */
.month-grid-card { padding: 0.75rem; }
.table-scroll { overflow-x: auto; }
.month-grid { border-collapse: collapse; width: 100%; min-width: 860px; }
.month-grid th, .month-grid td { padding: 0; border: 1px solid var(--border); }
.month-grid thead th {
  text-align: center; font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; padding: 0.35rem 0.25rem;
}
.month-grid thead th.col-day     { background: #4a5568; color: #fff; width: 32px; }
.month-grid thead th.col-expense { background: #b91c1c; color: #fff; }
.month-grid thead th.col-income  { background: #166534; color: #fff; }
.month-grid thead th.col-balance { background: #1e3a5f; color: #fff; width: 86px; }

/* Entry cells */
.entry-cell { width: 80px; height: 42px; vertical-align: middle; padding: 0.15rem 0.3rem; }
.entry-cell.empty {
  background: #fafafa; cursor: pointer;
  position: relative; transition: background 0.12s;
}
.entry-cell.empty:hover { background: #eef2f7; }
.entry-cell.empty::after {
  content: '+'; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%); pointer-events: none;
  opacity: 0; color: var(--muted); font-size: 14px; font-weight: 600;
  transition: opacity 0.12s;
}
.entry-cell.empty:hover::after { opacity: 0.4; }
.entry-cell:not(.empty) { cursor: pointer; transition: filter 0.1s; }
.entry-cell:not(.empty):hover { filter: brightness(0.93); }
.entry-cell.expense         { background: var(--expense-bg); }
.entry-cell.income          { background: var(--income-bg); }
.entry-cell.pointed { background: var(--pointed-bg); border-left: 3px solid var(--pointed); }
.entry-label {
  display: block; font-size: 10px; font-weight: 600; color: #374151;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 100%;
}
.entry-amount {
  display: block; font-size: 11px; font-weight: 700; margin-top: 1px;
}
.entry-cell.expense .entry-amount { color: var(--expense); }
.entry-cell.income  .entry-amount { color: var(--income); }
.entry-cell.pointed .entry-label  { color: #1e40af; }
.entry-cell.pointed .entry-amount { color: var(--pointed); }

/* Day number + balance cells */
.day-num {
  text-align: center; font-size: 0.8rem; font-weight: 700;
  color: var(--muted); vertical-align: middle; width: 32px;
}
.balance-pred {
  text-align: right; font-size: 11px; padding: 0 0.4rem;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  vertical-align: middle; width: 86px; font-weight: 700;
}
.pred-neg  { color: var(--expense); }
.pred-warn { color: #d97706; }
.pred-ok   { color: var(--income); }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 999;
}
.modal {
  background: #fff; border-radius: 10px; width: 360px; max-width: 95vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.qa-modal { width: 500px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
}
.modal-header span { font-weight: 700; font-size: 0.9rem; color: var(--primary); }
.modal-close {
  background: none; border: none; cursor: pointer; font-size: 1.1rem;
  color: var(--muted); padding: 0.2rem 0.4rem; border-radius: 4px;
}
.modal-close:hover { background: #f0f0f0; color: var(--text); }
.modal-body { padding: 1rem; }
.modal-info {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem;
}
.modal-label { font-weight: 700; font-size: 0.95rem; }
.modal-amount-planned { font-size: 0.85rem; color: var(--muted); }
.modal-field { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

/* ── Toast ───────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999;
  background: #2d3748; color: #fff; padding: 0.6rem 1.2rem;
  border-radius: 6px; font-size: 0.875rem; font-weight: 500;
  transform: translateY(80px); opacity: 0; transition: all 0.25s ease;
  pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.toast-error { background: var(--expense); }

/* ── Alert ───────────────────────────────────────────────────────────────────── */
.alert { padding: 0.6rem 1rem; border-radius: 6px; margin-top: 0.5rem; font-size: 0.875rem; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffc107; }
.alert-warning a { color: #664d03; font-weight: 600; }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); font-size: 0.95rem; }

/* ── Tri / filtre / pagination tableau opérations ───────────────────────────── */
.table-filter-bar {
  margin-bottom: 0.75rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.table-filter-bar input { max-width: 280px; }
.page-size-select { display: flex; align-items: center; gap: 0.4rem; font-size: 0.875rem; color: var(--muted); }
.page-size-select select { width: auto; padding: 0.3rem 0.5rem; }

.pagination-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.5rem 0; margin-top: 0.5rem; flex-wrap: wrap; gap: 0.5rem;
}
.pagination-info { font-size: 0.825rem; color: var(--muted); }
.pagination-nav  { display: flex; gap: 0.4rem; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

th[data-col] { cursor: pointer; user-select: none; white-space: nowrap; }
th[data-col]:hover { background: #e8ecf0; }
th[data-col]::after { content: " ⇅"; opacity: 0.3; font-size: 0.7em; }
th[data-col].sort-asc::after  { content: " ↑"; opacity: 0.8; }
th[data-col].sort-desc::after { content: " ↓"; opacity: 0.8; }

/* ── Séparateur dépenses / recettes ──────────────────────────────────────────── */
.sep-left { border-left: 3px solid #64748b !important; }

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
