/* ---- Connexion / création de mot de passe ---- */
.auth {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.auth-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.auth-box h1 { font-size: 1.6rem; margin-bottom: 20px; text-align: center; }
.auth-box h2 { font-size: 1rem; margin-bottom: 8px; text-align: center; }
.auth-error { color: var(--danger); font-size: 0.85rem; text-align: center; margin-top: 8px; }

.logout {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}
.logout:hover { background: rgba(255, 255, 255, 0.25); }

.theme-toggle {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 8px;
  min-width: 36px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.25); }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.hidden { display: none !important; }

:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --positive: #059669;
  --negative: #dc2626;
  --danger: #dc2626;
  --warn: #eab308;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --topbar: #111827;
  --field-bg: #ffffff;
  --preview-bg: #fef9c3;
  --preview-text: #854d0e;
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #1b1f27;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #2b3040;
  --primary: #818cf8;
  --primary-dark: #6366f1;
  --positive: #34d399;
  --negative: #f87171;
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  --topbar: #0d0f13;
  --field-bg: #262b36;
  --preview-bg: #3b3414;
  --preview-text: #fde68a;
}

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: var(--topbar);
  color: #fff;
}

.brand { font-weight: 700; font-size: 1.1rem; }

.month-nav { display: flex; align-items: center; gap: 4px; }

.month-nav button {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}
.month-nav button:hover { background: rgba(255, 255, 255, 0.25); }
.month-nav .month-label { font-size: 0.95rem; font-weight: 600; min-width: 130px; }

/* ---- Tabs ---- */
.tabs {
  display: flex;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 52px;
  z-index: 9;
}

.tab {
  flex: 1;
  min-width: max-content;
  padding: 12px 16px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---- Layout ---- */
main { max-width: 1400px; margin: 0 auto; padding: 16px; padding-bottom: 64px; }

/* Onglets dédiés (hors accueil) : colonne étroite centrée */
#view-categories, #view-payments, #view-todos { max-width: 760px; margin: 0 auto; }

.view { display: none; }
.view.active { display: block; animation: fade 0.15s ease; }
@keyframes fade { from { opacity: 0; } }

/* ---- Cards ---- */
.cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card-balance { grid-column: 1 / -1; background: var(--primary); color: #fff; }
.card-label { font-size: 0.8rem; color: var(--muted); }
.card-balance .card-label { color: rgba(255, 255, 255, 0.8); }
.card-value { font-size: 1.5rem; font-weight: 700; margin-top: 2px; }
.card-value.positive { color: var(--positive); }
.card-value.negative { color: var(--negative); }

/* ---- Panels ---- */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  margin-bottom: 16px;
}
.panel h2 { font-size: 0.95rem; margin-bottom: 8px; }
.panel h2 .panel-total {
  float: right;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--negative);
}
.panel h2 .panel-total.positive { color: var(--positive); }

/* ---- Forms ---- */
.form { display: grid; gap: 10px; }
@media (min-width: 560px) {
  .form { grid-template-columns: repeat(2, 1fr); }
  .form .btn, .form .check { grid-column: 1 / -1; }
}
input, select, button {
  font: inherit;
  color: inherit;
}
input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--field-bg);
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
input[type="color"] { padding: 2px; height: 42px; cursor: pointer; }
input[type="checkbox"] { width: auto; }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--muted); }

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: none; color: var(--primary); padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.btn-ghost:hover { background: var(--surface-alt, rgba(99, 102, 241, 0.08)); }
.btn-danger { background: none; color: var(--danger); padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.1); }

/* ---- Lists / rows ---- */
.list { display: flex; flex-direction: column; gap: 6px; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}
.row.planned { border-style: dashed; opacity: 0.85; }
.row.done { opacity: 0.5; }
.row-main { min-width: 0; }
.row-label { font-weight: 600; font-size: 0.9rem; word-break: break-word; }
.row-sub { font-size: 0.72rem; color: var(--muted); }
.row-side { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.row-amount { font-weight: 600; white-space: nowrap; }
.row-amount.positive { color: var(--positive); }
.row-amount.negative { color: var(--negative); }
.row-actions { display: flex; gap: 2px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* ---- Accueil : trois colonnes (opérations | prévisions | récurrentes) ---- */
.home-grid {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 16px;
  align-items: start;
}
.home-col { display: flex; flex-direction: column; gap: 12px; }
.home-col .panel { margin-bottom: 0; }
@media (max-width: 1100px) {
  .home-grid { grid-template-columns: 1fr; }
  .home-col .panel { margin-bottom: 16px; }
}

/* ---- Récurrentes attendues ---- */
.rec-day {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.7rem;
  border: 1px solid var(--border);
  color: var(--text);
  flex-shrink: 0;
}
.rec-day.past { background: var(--bg); color: var(--muted); }
.rec-day.today { background: var(--warn); border-color: var(--warn); color: #fff; }

.rec-future .row-label,
.rec-future .row-sub { color: var(--text); }
.rec-past { opacity: 0.55; }
.rec-past .row-label,
.rec-past .row-sub,
.rec-past .row-amount { color: var(--muted); }
.rec-today { border-color: var(--warn); }

.rec { padding: 4px 10px; }

.empty { color: var(--muted); font-size: 0.9rem; text-align: center; padding: 10px 0; }

/* ---- Prévisions ---- */
.previsions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.prevision-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.prevision-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: var(--text);
}
.prevision-icon { font-size: 1rem; }
.prevision-input-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.prevision-input-row input {
  flex: 1 1 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  box-sizing: border-box;
}
.prevision-input-row input[type="date"] { flex: 1 1 100%; }

/* Date prévue du salaire à la ligne, sous le montant */
.prev-salary-date-label { align-items: center; margin-top: -2px; }
.prev-salary-date-caption {
  font-size: 0.75rem;
  color: var(--muted, #6b7280);
  white-space: nowrap;
}
.prevision-card .prev-salary-date-label input[type="date"] { width: 100%; flex: 1 1 auto; min-width: 0; }

@media (min-width: 620px) {
  .prevision-input-row { flex-wrap: nowrap; }
  .prevision-input-row input { flex: 1 1 auto; min-width: 0; }
  .prevision-input-row input[type="date"] { flex: 0 0 150px; }
}
.prevision-value {
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--primary);
}
.prevision-value.negative { color: var(--negative); }
.prevision-value.positive { color: var(--positive); }

/* ---- Flux de calcul ---- */
.calculation-flow {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.calculation-flow h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--muted);
  text-align: center;
}
.flow-diagram { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.flow-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.flow-row-previsions { margin-top: 4px; }
.flow-result-row { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.flow-arrow { color: var(--muted); font-weight: 700; font-size: 1.2rem; }
.flow-arrow-vertical {
  color: var(--muted);
  font-size: 1.2rem;
  margin: 4px 0;
}
.flow-bubble {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  min-width: 140px;
  text-align: center;
  transition: all 0.2s;
}
.flow-bubble.preview { background: var(--preview-bg); border-color: var(--warn); }
.flow-bubble.result {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  min-width: 180px;
}
.flow-bubble.result .bubble-label { color: rgba(255,255,255,0.9); }
.flow-bubble.result .bubble-value { color: #fff; font-size: 1.2rem; }
.bubble-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.flow-bubble.preview .bubble-label { color: var(--preview-text); }
.bubble-value {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}
.bubble-value.positive { color: var(--positive); }
.bubble-value.negative { color: var(--negative); }

@media (max-width: 600px) {
  .flow-row { flex-direction: column; gap: 6px; }
  .flow-arrow { transform: rotate(90deg); }
  .flow-row-previsions .flow-arrow { display: none; }
  .flow-bubble { min-width: 0; width: 100%; }
}

/* ---- Todos ---- */
.todo-toggle {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

@media (min-width: 560px) {
  .cards { grid-template-columns: repeat(3, 1fr); }
  .card-balance { grid-column: 1 / -1; }
}
