/* Frugal Goals — violet/teal accent. Light & dark themes follow the system
 * (prefers-color-scheme), with a manual override via html[data-theme].
 * All colors are semantic tokens; components never hardcode hex values. */
:root {
  /* Dark palette (default). */
  --bg: #0b0d14;
  --bg-soft: #12151f;
  --line: #232838;
  --nav-bg: rgba(11, 13, 20, 0.92);
  --accent: #8b5cf6;
  --accent-soft: #a78bfa;
  --accent-a15: rgba(139, 92, 246, 0.15);
  --accent-a20: rgba(139, 92, 246, 0.2);
  --accent-a25: rgba(139, 92, 246, 0.25);
  --accent-a40: rgba(139, 92, 246, 0.4);
  --accent-a50: rgba(139, 92, 246, 0.5);
  --mint: #2dd4bf;
  --mint-soft: #5eead4;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --danger: #f87171;
  --danger-a10: rgba(248, 113, 113, 0.1);
  --danger-a40: rgba(248, 113, 113, 0.4);
  --amber: #fcd34d;
  --amber-a06: rgba(252, 211, 77, 0.06);
  --amber-a50: rgba(252, 211, 77, 0.5);
  --cell: rgba(35, 40, 56, 0.5);
  --shadow: rgba(0, 0, 0, 0.4);
  --on-accent: #ffffff;
  color-scheme: dark;
}

/* Light theme: system-level. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f7fb;
    --bg-soft: #ffffff;
    --line: #e2e6ef;
    --nav-bg: rgba(255, 255, 255, 0.92);
    --accent: #7c3aed;
    --accent-soft: #6d28d9;
    --accent-a15: rgba(124, 58, 237, 0.1);
    --accent-a20: rgba(124, 58, 237, 0.16);
    --accent-a25: rgba(124, 58, 237, 0.2);
    --accent-a40: rgba(124, 58, 237, 0.35);
    --accent-a50: rgba(124, 58, 237, 0.45);
    --mint: #0d9488;
    --mint-soft: #0f766e;
    --text: #1e293b;
    --muted: #64748b;
    --danger: #dc2626;
    --danger-a10: rgba(220, 38, 38, 0.08);
    --danger-a40: rgba(220, 38, 38, 0.35);
    --amber: #b45309;
    --amber-a06: rgba(180, 83, 9, 0.07);
    --amber-a50: rgba(180, 83, 9, 0.4);
    --cell: rgba(15, 23, 42, 0.08);
    --shadow: rgba(15, 23, 42, 0.12);
    --on-accent: #ffffff;
    color-scheme: light;
  }
}

/* Manual override (from the Gérer screen): html[data-theme="light|dark"].
   Declared last so it wins over the media query. */
:root[data-theme="light"] {
  --bg: #f6f7fb;
  --bg-soft: #ffffff;
  --line: #e2e6ef;
  --nav-bg: rgba(255, 255, 255, 0.92);
  --accent: #7c3aed;
  --accent-soft: #6d28d9;
  --accent-a15: rgba(124, 58, 237, 0.1);
  --accent-a20: rgba(124, 58, 237, 0.16);
  --accent-a25: rgba(124, 58, 237, 0.2);
  --accent-a40: rgba(124, 58, 237, 0.35);
  --accent-a50: rgba(124, 58, 237, 0.45);
  --mint: #0d9488;
  --mint-soft: #0f766e;
  --text: #1e293b;
  --muted: #64748b;
  --danger: #dc2626;
  --danger-a10: rgba(220, 38, 38, 0.08);
  --danger-a40: rgba(220, 38, 38, 0.35);
  --amber: #b45309;
  --amber-a06: rgba(180, 83, 9, 0.07);
  --amber-a50: rgba(180, 83, 9, 0.4);
  --cell: rgba(15, 23, 42, 0.08);
  --shadow: rgba(15, 23, 42, 0.12);
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

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

html { color-scheme: dark; }

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

.hidden { display: none !important; }
.accent { color: var(--accent-soft); }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 0.85rem; margin-top: 0.4rem; }
.w-full { width: 100%; }

/* --- Cards & buttons --- */
.card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 1rem;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border-radius: 0.75rem; padding: 0.5rem 1rem; font-size: 0.875rem; font-weight: 600;
  border: none; cursor: pointer; transition: opacity 0.15s, background 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-soft); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn-ghost:hover { background: var(--line); }
.btn-danger { background: transparent; border: 1px solid var(--danger-a40); color: var(--danger); }
.btn-danger:hover { background: var(--danger-a10); }

.input {
  width: 100%; border-radius: 0.75rem; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); padding: 0.5rem 0.75rem; font-size: 0.875rem;
}
.input:focus { outline: none; border-color: var(--accent); }
.input::placeholder { color: #64748b; }

.chip {
  display: inline-flex; align-items: center; gap: 0.25rem;
  border-radius: 9999px; padding: 0.15rem 0.6rem; font-size: 0.75rem; font-weight: 500;
}
.chip-accent { background: var(--accent-a15); color: var(--accent-soft); }

/* --- Layout --- */
.app { max-width: 42rem; margin: 0 auto; padding: 1rem 0.75rem 6rem; }
.app-header h1 { font-size: 1.25rem; font-weight: 700; padding: 0.5rem 0 1rem; }
.view { display: flex; flex-direction: column; gap: 1rem; }

/* --- Login --- */
.login-screen {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.login-card { width: 100%; max-width: 22rem; }
.login-card h1 { font-size: 1.25rem; margin-bottom: 0.25rem; }
.login-card p { margin-bottom: 1rem; }
.login-card form { display: flex; flex-direction: column; gap: 0.75rem; }

/* --- Bottom nav --- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--nav-bg); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-between;
}
.bottom-nav .nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  background: none; border: none; color: var(--muted); font-size: 0.7rem; font-weight: 500;
  padding: 0.6rem 0.25rem; cursor: pointer;
}
.bottom-nav .nav-btn span { font-size: 1.25rem; }
.bottom-nav .nav-btn.active { color: var(--accent-soft); }

/* --- Progress bar --- */
.progress-track { height: 0.75rem; background: var(--line); border-radius: 9999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 9999px; transition: width 0.7s ease-out; }
.progress-fill.mint { background: var(--mint); }

/* --- Stat tiles --- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
.stat-tile { display: flex; align-items: center; gap: 0.75rem; }
.stat-tile .icon { font-size: 1.5rem; }
.stat-tile .value { font-size: 1rem; font-weight: 700; }
.stat-tile .label { font-size: 0.75rem; color: var(--muted); }

/* --- Check-in list --- */
.checkin-list { display: flex; flex-direction: column; gap: 0.6rem; }
.checkin-item {
  display: flex; align-items: center; gap: 0.75rem; width: 100%; text-align: left;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 1rem; padding: 0.75rem;
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.checkin-item.done { border-color: var(--accent-a50); background: var(--accent-a15); }
.checkin-item:disabled { opacity: 0.6; cursor: not-allowed; }
.checkin-item .h-icon {
  width: 2.75rem; height: 2.75rem; display: flex; align-items: center; justify-content: center;
  background: var(--bg); border-radius: 0.75rem; font-size: 1.5rem; flex-shrink: 0;
}
.checkin-item.done .h-icon { background: var(--accent-a20); }
.checkin-item .h-body { flex: 1; min-width: 0; }
.checkin-item .h-name { font-size: 0.875rem; font-weight: 600; }
.checkin-item .h-sub { font-size: 0.75rem; color: var(--muted); }
.checkin-item .h-check {
  width: 1.5rem; height: 1.5rem; border-radius: 9999px; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 0.75rem; color: transparent; flex-shrink: 0;
}
.checkin-item.done .h-check { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Floating "+amount" animation */
.float-up {
  position: absolute; right: 0.75rem; top: -0.25rem; font-weight: 700; color: var(--mint);
  animation: floatUp 1.2s ease-out forwards; pointer-events: none;
}
@keyframes floatUp {
  0% { transform: translateY(0); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateY(-40px); opacity: 0; }
}

/* --- Heatmap --- */
.heatmap { display: flex; gap: 0.3rem; overflow-x: auto; padding: 0.25rem 0.75rem 0.25rem 0.25rem; }
.heatmap-col { display: flex; flex-direction: column; gap: 0.3rem; }
.heatmap-cell { width: 1.15rem; height: 1.15rem; border-radius: 4px; background: var(--cell); }
.heatmap-dow {
  display: grid; grid-template-rows: repeat(7, 1.15rem); gap: 0.3rem;
  font-size: 0.6rem; color: var(--muted); text-align: center; line-height: 1.15rem;
  margin-right: 0.15rem;
}
.heatmap-cell.l1 { background: var(--accent-a40); }
.heatmap-cell.l2 { background: var(--accent-a50); }
.heatmap-cell.l3 { background: var(--accent); }
.heatmap-cell.l4 { background: var(--mint); }
.heatmap-legend { display: flex; align-items: center; gap: 0.25rem; font-size: 0.65rem; color: var(--muted); margin-top: 0.5rem; }
.heatmap-legend .cell { width: 0.6rem; height: 0.6rem; border-radius: 2px; }

/* --- Badges --- */
.badge-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
.badge-card { display: flex; flex-direction: column; align-items: center; text-align: center; }
.badge-card .b-icon { font-size: 2.5rem; }
.badge-card .b-label { font-weight: 700; margin-top: 0.5rem; }
.badge-card .b-desc { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }
.badge-card.locked { opacity: 0.45; filter: grayscale(1); }
.badge-card.earned { border-color: var(--accent-a40); background: var(--accent-a15); }

/* --- Manage --- */
.manage-list { display: flex; flex-direction: column; gap: 0.5rem; }
.manage-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  background: var(--bg); border: 1px solid var(--line); border-radius: 0.75rem; padding: 0.5rem 0.75rem;
}
.manage-row .row-main { min-width: 0; }
.manage-row .row-title { font-weight: 600; font-size: 0.875rem; }
.manage-row .row-sub { font-size: 0.75rem; color: var(--muted); }
.manage-row .row-actions { display: flex; align-items: center; gap: 0.25rem; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 1rem; padding: 0.3rem; border-radius: 0.4rem; }
.icon-btn:hover { background: var(--danger-a10); }

.form { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.75rem; }
.form-title { font-size: 0.875rem; font-weight: 600; color: var(--text); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.emoji-picker { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.emoji-picker button {
  background: none; border: 1px solid transparent; border-radius: 0.5rem; font-size: 1.25rem; padding: 0.3rem; cursor: pointer;
}
.emoji-picker button.selected { background: var(--accent-a25); border-color: var(--accent); }

/* --- Toast --- */
.toast {
  position: fixed; top: 1rem; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--bg-soft); border: 1px solid var(--accent); border-radius: 0.75rem;
  padding: 0.6rem 1rem; font-size: 0.875rem; box-shadow: 0 4px 20px var(--shadow);
  animation: toastIn 0.3s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(-10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* --- Section headers --- */
.section-title { font-size: 1.1rem; font-weight: 700; }
.section-sub { font-size: 0.8rem; color: var(--muted); margin-top: 0.2rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; }
.link { color: var(--accent-soft); font-size: 0.8rem; text-decoration: none; }
.link:hover { text-decoration: underline; }
