/* ============================================
   BUDGET & TÂCHES — PWA
   Direction : éditorial sombre, accent vert profond
   ============================================ */

:root {
  /* Palette */
  --bg: #0f1419;
  --bg-elev: #161d24;
  --bg-elev-2: #1d262f;
  --border: #243038;
  --text: #e8ecef;
  --text-muted: #8a98a4;
  --text-dim: #5d6b75;

  --accent: #1B5E3B;
  --accent-bright: #2d8a5a;
  --accent-glow: rgba(45, 138, 90, 0.25);

  --danger: #d4574a;
  --warning: #e3a857;
  --success: #4ea874;

  /* Typo */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, sans-serif;

  /* Espacements */
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;

  /* Safe areas */
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; }

.hidden { display: none !important; }

.screen { min-height: 100vh; padding-bottom: var(--safe-bottom); }

/* ============================================
   ÉCRAN AUTH
   ============================================ */
#auth-screen {
  background:
    radial-gradient(circle at 20% 10%, rgba(45, 138, 90, 0.15), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(45, 138, 90, 0.08), transparent 40%),
    var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
}

.auth-wrap { width: 100%; max-width: 380px; }

.brand { text-align: center; margin-bottom: 36px; }

.brand-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 20px;
  background: linear-gradient(135deg, var(--accent-bright), var(--accent));
  border-radius: 16px;
  position: relative;
  box-shadow: 0 8px 32px var(--accent-glow);
}
.brand-mark::before {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  color: white;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 32px;
  letter-spacing: -0.02em;
  font-style: italic;
}
.brand-title span { color: var(--accent-bright); font-style: normal; font-weight: 400; }

.brand-tag {
  color: var(--text-muted);
  margin-top: 6px;
  font-size: 14px;
}

.auth-form { display: flex; flex-direction: column; gap: 14px; }

.auth-msg {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
}
.auth-msg.error { color: var(--danger); }
.auth-msg.success { color: var(--success); }

/* ============================================
   FORMULAIRES
   ============================================ */
.field { display: flex; flex-direction: column; gap: 6px; }

.field label, .field legend {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field input, .field select, .field textarea {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  transition: border-color 0.15s, background 0.15s;
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent-bright);
  background: var(--bg-elev-2);
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.input-with-suffix { position: relative; }
.input-with-suffix input { width: 100%; padding-right: 56px; }
.input-with-suffix .suffix {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
}

.check-row { display: flex; gap: 16px; flex-wrap: wrap; }
.check {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.check input { accent-color: var(--accent-bright); width: 18px; height: 18px; }

/* ============================================
   BOUTONS
   ============================================ */
.btn {
  padding: 13px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 15px;
  transition: transform 0.1s, opacity 0.15s, background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-bright), var(--accent));
  color: white;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-ghost { background: var(--bg-elev); color: var(--text); border: 1px solid var(--border); }
.btn-link { background: transparent; color: var(--text-muted); text-decoration: underline; font-weight: 500; }
.btn-danger { background: rgba(212, 87, 74, 0.15); color: var(--danger); border: 1px solid rgba(212, 87, 74, 0.3); }

/* ============================================
   HEADER APP
   ============================================ */
.app-header {
  padding: calc(20px + var(--safe-top)) 20px 16px;
  background: linear-gradient(180deg, var(--bg-elev) 0%, var(--bg) 100%);
  position: relative;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.header-greet { color: var(--text-muted); font-size: 13px; }
.header-month {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: -0.02em;
  margin-top: 2px;
  text-transform: capitalize;
}

.icon-btn {
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-elev-2);
  border-radius: 12px;
  color: var(--text);
  transition: background 0.15s;
}
.icon-btn:active { background: var(--border); }

/* ============================================
   CARTE BUDGET
   ============================================ */
.budget-card {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.budget-card::before {
  content: '';
  position: absolute;
  top: -50px;
  right: -50px;
  width: 150px;
  height: 150px;
  background: radial-gradient(circle, var(--accent-glow), transparent 70%);
  pointer-events: none;
}

.budget-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
}
.budget-label { color: var(--text-muted); font-size: 13px; }
.budget-amount {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: -0.02em;
}

.budget-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 14px;
}
.budget-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  width: 0%;
  transition: width 0.4s ease;
  border-radius: 3px;
}

.budget-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 15px; font-weight: 600; }
.stat-value.paid { color: var(--success); }
.stat-value.pending { color: var(--warning); }
.stat-value.late { color: var(--danger); }

/* ============================================
   FILTRES
   ============================================ */
.filters {
  display: flex;
  gap: 8px;
  padding: 14px 20px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }

.filter-chip {
  padding: 8px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.15s;
}
.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent-bright);
  color: white;
}

/* ============================================
   LISTE DES TÂCHES
   ============================================ */
.task-list {
  padding: 4px 20px 100px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-item {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--cat-color, var(--accent));
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.1s, background 0.15s;
}
.task-item:active { transform: scale(0.99); background: var(--bg-elev-2); }
.task-item.late { border-color: rgba(212, 87, 74, 0.3); }
.task-item.paid { opacity: 0.55; }
.task-item.paid .task-title-text { text-decoration: line-through; }

.task-check {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.task-check.checked {
  background: var(--accent-bright);
  border-color: var(--accent-bright);
}
.task-check.checked::after {
  content: '✓';
  color: white;
  font-size: 14px;
  font-weight: 700;
}

.task-body { flex: 1; min-width: 0; }
.task-title-text {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.task-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.task-meta .cat-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.task-meta .cat-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--cat-color, var(--accent));
}
.task-due { color: var(--text-muted); }
.task-due.late { color: var(--danger); font-weight: 600; }
.task-due.today { color: var(--warning); font-weight: 600; }

.task-amount {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
}
.task-amount.zero { color: var(--text-dim); font-weight: 400; }

.task-recur-icon {
  color: var(--text-dim);
  font-size: 11px;
}

/* ============================================
   ÉTAT VIDE
   ============================================ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-icon {
  font-size: 48px;
  color: var(--text-dim);
  margin-bottom: 12px;
  font-family: var(--font-display);
}
.empty-hint { font-size: 13px; color: var(--text-dim); margin-top: 4px; }

/* ============================================
   FAB
   ============================================ */
.fab {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-bright), var(--accent));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px var(--accent-glow), 0 4px 12px rgba(0,0,0,0.3);
  transition: transform 0.15s;
  z-index: 50;
}
.fab:active { transform: scale(0.92); }

/* ============================================
   SYNC STATUS
   ============================================ */
.sync-status {
  position: fixed;
  top: calc(8px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-muted);
  transition: transform 0.3s;
  z-index: 100;
}
.sync-status.show { transform: translateX(-50%) translateY(0); }
.sync-status.success { color: var(--success); border-color: rgba(78, 168, 116, 0.3); }
.sync-status.error { color: var(--danger); border-color: rgba(212, 87, 74, 0.3); }

/* ============================================
   MODAL
   ============================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}
.modal-content {
  position: relative;
  background: var(--bg-elev);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  animation: slideUp 0.25s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.modal-header h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.task-form { display: flex; flex-direction: column; gap: 14px; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}
.modal-actions .btn-danger { margin-right: auto; }

/* ============================================
   MENU
   ============================================ */
.menu-items { display: flex; flex-direction: column; gap: 4px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--bg-elev-2);
  border-radius: var(--radius-sm);
  text-align: left;
  transition: background 0.15s;
}
.menu-item:active { background: var(--border); }
.menu-item.danger { color: var(--danger); }

.menu-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  border-radius: 10px;
  font-size: 18px;
  flex-shrink: 0;
}
.menu-item strong { display: block; font-size: 15px; font-weight: 600; }
.menu-item small { display: block; color: var(--text-muted); font-size: 12px; }

/* ============================================
   CATÉGORIES
   ============================================ */
.cat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  max-height: 50vh;
  overflow-y: auto;
}
.cat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-elev-2);
  border-radius: var(--radius-sm);
}
.cat-swatch { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.cat-row span { flex: 1; font-size: 14px; }
.cat-delete {
  width: 28px; height: 28px;
  color: var(--danger);
  display: flex; align-items: center; justify-content: center;
}

.cat-form { display: flex; gap: 8px; }
.cat-form input[type="text"] {
  flex: 1;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
}
.cat-form input[type="color"] {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  cursor: pointer;
}

/* ============================================
   TOAST
   ============================================ */
.toast {
  position: fixed;
  bottom: calc(90px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 300;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: slideUp 0.2s ease;
}
.toast.error { border-color: rgba(212, 87, 74, 0.4); color: var(--danger); }
.toast.success { border-color: rgba(78, 168, 116, 0.4); color: var(--success); }
