/* =====================================================================
   KerryLife Organizer — calming sage + cream palette
   Mobile-first, big-touch, motivating
   ===================================================================== */

:root, [data-theme="light"] {
  --bg:         #F5F2EB;        /* warm cream */
  --surface:    #FBFAF5;        /* card */
  --surface-2:  #EFEBE0;        /* nested card */
  --border:     #D8D2C2;
  --text:       #2E3A35;        /* deep evergreen */
  --text-muted: #6E7771;
  --text-faint: #A1A6A0;

  --sage:       #5A7A6A;        /* primary */
  --sage-dark:  #3F5A4D;
  --sage-light: #C7DDD0;
  --terra:      #B85A3F;        /* accent (sparingly) */
  --gold:       #C9A66B;
  --rose:       #C77B89;        /* Mom category */

  --status-ok-bg:    #e3f0e7;
  --status-ok-fg:    #2f5a3f;
  --status-warn-bg:  #faecd9;
  --status-warn-fg:  #8a5a1a;

  --radius:     14px;
  --radius-sm:  10px;
  --shadow-sm:  0 1px 2px rgba(46,58,53,0.06);
  --shadow-md:  0 4px 12px rgba(46,58,53,0.08);

  --space-1: 4px;  --space-2: 8px;  --space-3: 12px;
  --space-4: 16px; --space-5: 20px; --space-6: 24px;
  --space-7: 32px; --space-8: 48px;
}

/* --- Dark theme overrides --- */
[data-theme="dark"] {
  --bg:         #14181a;        /* near-black, slight cool */
  --surface:    #1c2225;        /* card */
  --surface-2:  #232a2d;        /* nested */
  --border:     #2e3639;
  --text:       #E6EAE3;
  --text-muted: #9AA39E;
  --text-faint: #6B736E;

  --sage:       #7FA590;        /* lifted so it pops on dark */
  --sage-dark:  #B6D1C2;        /* used for headlines/numbers — needs to be bright */
  --sage-light: #2b3a33;        /* used as soft-fill, must be DARK in dark mode */
  --terra:      #D17A5F;
  --gold:       #D8B97A;
  --rose:       #E69BAA;

  --status-ok-bg:    #1f3b2a;
  --status-ok-fg:    #b8e0c4;
  --status-warn-bg:  #3b2f1c;
  --status-warn-fg:  #f0c98d;

  --shadow-sm:  0 1px 2px rgba(0,0,0,0.4);
  --shadow-md:  0 6px 16px rgba(0,0,0,0.45);
}
[data-theme="dark"] body { color-scheme: dark; }
[data-theme="light"] body { color-scheme: light; }

/* Dark-mode targeted refinements (places where naive var-swap reads wrong) */
[data-theme="dark"] {
  --progress-from: #4a7560;       /* mid sage so the bar reads as a gradient */
}
[data-theme="dark"] .topbar { background: var(--surface); }
[data-theme="dark"] .hero { background: linear-gradient(135deg, #2c463a 0%, #1d3128 100%); }
[data-theme="dark"] .checkbox { background: #11181a; }
[data-theme="dark"] .task-row.done { color: var(--text-faint); }
[data-theme="dark"] .task-row:active { background: #2b3a33; }
[data-theme="dark"] .pill { background: var(--surface-2); color: var(--text-muted); }
[data-theme="dark"] input, [data-theme="dark"] textarea, [data-theme="dark"] select {
  background: var(--surface-2); color: var(--text); border-color: var(--border);
}
[data-theme="dark"] .toast { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: ui-rounded, -apple-system, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }
p  { margin: 0 0 var(--space-3) 0; }
.muted       { color: var(--text-muted); }
.muted.small { font-size: 0.85rem; }

/* ------------------------------ Top bar ------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: max(var(--space-4), env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: var(--space-2); color: var(--sage-dark); }
.brand-mark { width: 28px; height: 28px; }
.brand-name { font-weight: 800; font-size: 1.15rem; letter-spacing: -0.02em; }
.topbar-date { color: var(--text-muted); font-size: 0.9rem; }
.topbar-right { display: flex; align-items: center; gap: var(--space-3); }

/* Theme toggle (cycles auto → light → dark) */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.theme-toggle:hover { color: var(--text); background: var(--surface-2); }
.theme-toggle:active { transform: scale(0.95); }
.theme-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sage) 35%, transparent);
}
.theme-toggle svg { display: block; }

/* ------------------------------ Tabs --------------------------------- */
.tabs {
  display: flex; gap: var(--space-1);
  padding: var(--space-3) var(--space-3) 0;
  max-width: 720px;
  margin: 0 auto;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  padding: var(--space-2) var(--space-4);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--sage);
  color: white;
}
/* Tighten tab labels on narrow phones so all 5 fit */
@media (max-width: 420px) {
  .tab { padding: var(--space-2) 12px; font-size: 0.9rem; }
}

/* ------------------------- Billie status pill ----------------------- */
.billie-status {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 999px;
  background: var(--cream-2, #ece7d8);
  color: var(--text-muted);
  font-size: 0.9rem; font-weight: 500;
}
.billie-status.ok   { background: var(--status-ok-bg);   color: var(--status-ok-fg); }
.billie-status.warn { background: var(--status-warn-bg); color: var(--status-warn-fg); }
.billie-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #bbb; }
.billie-status .dot-ok { background: #4a9d6a; box-shadow: 0 0 0 3px rgba(74,157,106,0.18); }
.billie-status .dot-warn { background: #e2a447; box-shadow: 0 0 0 3px rgba(226,164,71,0.18); }

/* ------------------------------ Layout ------------------------------- */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) var(--space-8);
}
.view { display: none; }
.view.active { display: block; animation: fade 0.2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ------------------------------ Cards -------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.card-head h2 { flex: 1 1 auto; min-width: 0; }
.card-head .btn { flex: 0 0 auto; white-space: nowrap; padding: 8px 14px; }

/* ------------------------------ Hero (Today) ------------------------- */
.hero {
  background: linear-gradient(135deg, var(--sage) 0%, var(--sage-dark) 100%);
  color: white;
  border: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-5);
  align-items: center;
  justify-content: space-between;
}
.hero-greet { flex: 1 1 auto; min-width: 200px; }
.hero-hi { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; }
.hero-sub { color: rgba(255,255,255,0.85); font-size: 0.95rem; margin-top: 2px; }
.hero-stats { display: flex; gap: var(--space-5); }
.stat { text-align: center; min-width: 60px; }
.stat-val { font-size: 1.8rem; font-weight: 800; line-height: 1; }
.stat-lbl { font-size: 0.75rem; opacity: 0.85; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 4px; }

/* ------------------------------ Progress ----------------------------- */
.progress-card { padding: var(--space-4) var(--space-5); }
.progress-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: var(--space-2);
}
.progress-label { font-weight: 600; color: var(--text-muted); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.04em; }
.progress-pct   { font-size: 1.5rem; font-weight: 800; color: var(--sage-dark); }
.progress-bar {
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--progress-from, var(--sage-light)), var(--sage));
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(.2,.8,.2,1);
}
.progress-sub { margin-top: var(--space-2); color: var(--text-muted); font-size: 0.9rem; }

/* ------------------------------ Today list --------------------------- */
.today-list { display: flex; flex-direction: column; gap: var(--space-4); }

.cat-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) 0;
  box-shadow: var(--shadow-sm);
}
.cat-head {
  padding: var(--space-1) var(--space-5) var(--space-3);
  display: flex; align-items: center; gap: var(--space-2);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-2);
}
.cat-icon { font-size: 1.3rem; }
.cat-name { font-weight: 700; font-size: 1.05rem; }
.cat-count { margin-left: auto; color: var(--text-muted); font-size: 0.85rem; }

.task-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
}
.task-row:hover { background: var(--surface-2); }
.task-row:active { background: var(--sage-light); }
.task-row.done { color: var(--text-muted); }
.task-row.done .task-title { text-decoration: line-through; text-decoration-color: var(--text-faint); text-decoration-thickness: 1.5px; }

.task-check {
  flex: 0 0 28px; width: 28px; height: 28px;
  border: 2px solid var(--border);
  border-radius: 8px;
  display: grid; place-items: center;
  background: var(--surface);
  transition: all 0.15s ease;
}
.task-row.done .task-check {
  background: var(--sage);
  border-color: var(--sage);
  color: white;
}
.task-row.partial .task-check {
  background: var(--sage-light);
  border-color: var(--sage);
}
.task-check-icon { width: 16px; height: 16px; }

.task-body { flex: 1 1 auto; min-width: 0; }
.task-title { font-size: 1rem; font-weight: 500; }
.task-meta  { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

.task-counter {
  flex: 0 0 auto;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 4px 10px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------ Categories view ---------------------- */
.cat-section { margin-bottom: var(--space-5); }
.cat-section-head {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-3);
}
.cat-section-icon { font-size: 1.2rem; }
.cat-section-title { font-weight: 700; font-size: 1.05rem; }

.task-edit-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3); gap: var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.task-edit-row:hover { background: var(--surface-2); }
.task-edit-info { flex: 1; }
.task-edit-title { font-weight: 500; }
.task-edit-meta  { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.cadence-chip {
  font-size: 0.75rem;
  color: var(--sage-dark);
  background: var(--sage-light);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}

/* ------------------------------ To-do & Challenge lists -------------- */
.todo-row, .challenge-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
}
.todo-row:hover, .challenge-row:hover { background: var(--surface-2); border-color: var(--border); }
.todo-row.done .todo-title { text-decoration: line-through; color: var(--text-muted); }

.todo-info, .challenge-info { flex: 1; }
.todo-title, .challenge-title { font-weight: 500; }
.todo-meta, .challenge-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.challenge-bar {
  width: 100%; height: 6px; background: var(--surface-2);
  border-radius: 999px; overflow: hidden; margin-top: 6px;
}
.challenge-bar-fill {
  height: 100%; background: var(--gold);
  border-radius: 999px; transition: width 0.4s ease;
}

/* ------------------------------ Forms / buttons ---------------------- */
.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  background: var(--sage);
  color: white;
}
.btn-primary:hover { background: var(--sage-dark); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

input[type=text], input[type=number], input[type=date], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  color: var(--text);
  margin-bottom: var(--space-3);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(90,122,106,0.18);
}
label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.settings-row { margin-bottom: var(--space-4); }

/* ------------------------------ Modal -------------------------------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(46,58,53,0.4);
  display: grid; place-items: center;
  padding: var(--space-4);
  z-index: 100;
  animation: fade 0.18s ease;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--space-5);
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-md);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card h3 { margin-bottom: var(--space-4); }
.modal-actions {
  display: flex; align-items: center; gap: var(--space-2);
  margin-top: var(--space-4);
}
.grow { flex: 1; }

/* ------------------------------ Motivator toast ---------------------- */
.motivator {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: var(--sage-dark);
  color: white;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  z-index: 200;
  animation: pop 0.3s cubic-bezier(.2,.8,.2,1);
}
@keyframes pop {
  from { transform: translate(-50%, 20px) scale(0.9); opacity: 0; }
  to   { transform: translate(-50%, 0) scale(1); opacity: 1; }
}

/* ------------------------------ Responsive --------------------------- */
@media (min-width: 720px) {
  main { padding: var(--space-6); }
  .hero { padding: var(--space-6) var(--space-7); }
  .hero-hi { font-size: 1.6rem; }
}
