:root {
  --bg: #f5f6fb;
  --bg-elevated: #ffffff;
  --card: #ffffff;
  --text: #171923;
  --muted: #8a8fa3;
  --border: #e9eaf2;
  --accent: #6857ff;
  --accent-2: #ff5ea0;
  --accent-soft: #eeecff;
  --good: #22c58e;
  --good-soft: #e5f9f1;
  --warn: #f5a524;
  --warn-soft: #fef3e2;
  --bad: #f1503d;
  --bad-soft: #fdeae7;
  --purple-soft: #f1ecff;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(23, 20, 60, 0.04), 0 10px 30px rgba(23, 20, 60, 0.06);
  --shadow-lift: 0 12px 32px rgba(104, 87, 255, 0.18);
  --nav-w: 244px;
}

[data-theme="dark"] {
  --bg: #0e0f14;
  --bg-elevated: #16171e;
  --card: #181a22;
  --text: #f0f1f6;
  --muted: #8d92a6;
  --border: #262832;
  --accent: #8b7bff;
  --accent-2: #ff6fae;
  --accent-soft: #221f3d;
  --good: #2fd99d;
  --good-soft: #163a2d;
  --warn: #f5a524;
  --warn-soft: #3a2c0f;
  --bad: #ff6656;
  --bad-soft: #3a1c17;
  --purple-soft: #211c38;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lift: 0 12px 32px rgba(139, 123, 255, 0.28);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

a { text-decoration: none; }

/* ---------- Shell layout ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.content-col {
  flex: 1;
  min-width: 0;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  padding: calc(env(safe-area-inset-top) + 18px) 18px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid transparent;
}

.topbar-heading h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(120deg, var(--text), var(--accent) 140%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.topbar-sub {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(84px, 1fr));
  gap: 10px;
}

.stat-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  text-align: center;
}

.stat-value {
  font-size: 19px;
  font-weight: 800;
  color: var(--text);
}

.stat-label {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 3px;
  font-weight: 600;
}

/* ---------- Layout / pages ---------- */
main {
  padding: 12px 18px 110px;
  max-width: 900px;
  margin: 0 auto;
}

.page { display: none; }
.page.active { display: block; animation: fadeIn 0.25s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.span-2 { grid-column: span 1; }

@media (min-width: 760px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .span-2 { grid-column: span 2; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.grid-2 .card { margin-bottom: 0; }

.card h2 {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--text);
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--accent-soft);
  font-size: 14px;
}

/* ---------- Lists ---------- */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.list li {
  padding: 12px 2px;
  font-size: 14.5px;
  line-height: 1.45;
  border-bottom: 1px solid var(--border);
}

.list li:last-child {
  border-bottom: none;
  padding-bottom: 2px;
}

.badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  margin-left: 6px;
  letter-spacing: 0.01em;
}

.badge.overdue { background: var(--bad-soft); color: var(--bad); }
.badge.today { background: var(--warn-soft); color: var(--warn); }
.badge.upcoming { background: var(--border); color: var(--muted); }

/* ---------- Habits ---------- */
.habit-row { margin-bottom: 16px; }
.habit-row:last-child { margin-bottom: 0; }

.habit-row .name {
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
}

.heatmap {
  display: grid;
  grid-template-columns: repeat(30, 1fr);
  gap: 3px;
}

.heatmap div {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--border);
}

.heatmap div.done { background: var(--good); }
.heatmap div.partial { background: var(--warn); }

/* ---------- Access gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 30% 20%, rgba(104, 87, 255, 0.35), rgba(14, 15, 20, 0.75));
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.gate.hidden { display: none; }

.gate-box {
  background: var(--card);
  box-shadow: var(--shadow-lift);
  padding: 34px 28px;
  border-radius: 24px;
  width: 90%;
  max-width: 320px;
  text-align: center;
}

.gate-mark {
  width: 44px;
  height: 44px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 20px;
}

.gate-box h2 { margin: 0 0 4px; font-size: 19px; font-weight: 800; }
.gate-box p { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

.gate-box input {
  width: 100%;
  padding: 13px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.gate-box button {
  width: 100%;
  padding: 13px;
  border-radius: var(--radius-sm);
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

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

/* ---------- Nav (bottom on mobile, sidebar on desktop) ---------- */
.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-brand, .nav-footer { display: none; }

.bottomnav a {
  flex: 1;
  text-align: center;
  padding: 10px 0 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 19px;
  transition: color 0.15s ease, transform 0.15s ease;
  position: relative;
}

.bottomnav a .nav-icon { display: block; }

.bottomnav a span:last-child {
  display: block;
  font-size: 10.5px;
  margin-top: 3px;
  font-weight: 600;
}

.bottomnav a.active { color: var(--accent); transform: translateY(-1px); }

@media (min-width: 900px) {
  .bottomnav {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: var(--nav-w);
    flex-direction: column;
    align-items: stretch;
    border-top: none;
    border-right: 1px solid var(--border);
    padding: 24px 14px;
    gap: 4px;
    backdrop-filter: none;
    background: var(--bg-elevated);
  }

  .nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px 22px;
    font-weight: 800;
    font-size: 17px;
    letter-spacing: -0.01em;
  }

  .nav-brand-mark {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
    font-size: 15px;
  }

  .bottomnav a {
    flex: none;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    padding: 11px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
  }

  .bottomnav a .nav-icon { font-size: 17px; }
  .bottomnav a span:last-child { margin-top: 0; font-size: 14px; font-weight: 600; }

  .bottomnav a:hover { background: var(--accent-soft); color: var(--accent); }

  .bottomnav a.active {
    background: var(--accent-soft);
    color: var(--accent);
    transform: none;
  }

  .nav-footer {
    display: flex;
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--border);
  }

  .content-col { margin-left: var(--nav-w); }

  .topbar .theme-toggle { display: none; }
}

/* ---------- Floating action button ---------- */
.fab {
  position: fixed;
  right: 18px;
  bottom: 84px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-size: 28px;
  line-height: 56px;
  z-index: 11;
  box-shadow: var(--shadow-lift);
  transition: transform 0.15s ease;
  cursor: pointer;
}

.fab:active { transform: scale(0.92); }

@media (min-width: 900px) {
  .fab { right: 28px; bottom: 28px; }
}

/* ---------- Kanban ---------- */
.kanban-tabs {
  display: flex;
  gap: 6px;
  padding: 4px 0 0;
  overflow-x: auto;
}

.kanban-tab {
  flex: 1;
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-weight: 700;
  font-size: 12.5px;
  padding: 10px 10px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.kanban-tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
}

.kanban {
  display: flex;
  gap: 14px;
  padding: 10px 0 0;
  overflow-x: auto;
  scroll-snap-type: x proximity;
}

.kanban-col {
  flex: 1;
  min-width: 250px;
  scroll-snap-align: start;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 14px;
}

.kanban-col h3 {
  font-size: 12.5px;
  font-weight: 800;
  margin: 0 0 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Mobile: show one full-width column at a time, switched via the tabs above.
   The column heading is redundant with the active tab, so it's hidden here. */
@media (max-width: 720px) {
  .kanban-col { display: none; min-width: 0; }
  .kanban-col.active { display: block; flex: 1 1 100%; }
  .kanban-col h3 { display: none; }
}

/* Desktop/tablet: all 3 columns side-by-side as before; tabs aren't needed. */
@media (min-width: 721px) {
  .kanban-tabs { display: none; }
}

.kanban-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 40px;
}

.kanban-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 13.5px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kanban-card:hover { box-shadow: var(--shadow); }

.kanban-card .title {
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.kanban-card .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 10px;
}

.score-pill {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10.5px;
}

.kanban-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.move-actions, .edit-actions { display: flex; gap: 6px; }

.kanban-actions button {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

.kanban-actions button.danger { color: var(--bad); }
.kanban-actions button:active { transform: scale(0.9); }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(14, 15, 20, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal.hidden { display: none; }

.modal-box {
  background: var(--card);
  width: 100%;
  border-radius: 22px 22px 0 0;
  padding: 20px;
  padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
  max-height: 82vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}

@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal-box { max-width: 460px; border-radius: 22px; }
}

@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0.7; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 { margin: 0; font-size: 17px; font-weight: 800; }

.modal-header button {
  background: var(--bg);
  border: none;
  color: var(--muted);
  font-size: 15px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
}

.form-field { margin-bottom: 14px; }

.form-field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-actions { display: flex; gap: 10px; margin-top: 8px; }

.form-actions button {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 700;
  font-size: 14.5px;
  cursor: pointer;
}

.form-actions .save { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; }
.form-actions .delete { background: var(--bad-soft); color: var(--bad); }

/* ---------- Item rows (finance/journal lists) ---------- */
.item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.item-row .item-actions { display: flex; gap: 6px; flex-shrink: 0; }

.item-row .item-actions button {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

canvas { margin-bottom: 10px; }

/* ---------- Toast notifications ---------- */
#toastHost {
  position: fixed;
  top: env(safe-area-inset-top, 12px);
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-top: 12px;
  z-index: 200;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  max-width: 90%;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  color: #fff;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #e5484d; }
.toast.success { background: #17b17a; }
.toast.info { background: #4a5568; }

/* ---------- Form field helpers ---------- */
.form-field small.hint { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }
.form-actions .save[disabled] { opacity: 0.6; pointer-events: none; }
.form-actions .save.saving::after { content: "…"; }

input.field-error, select.field-error, textarea.field-error { border-color: #e5484d !important; }

/* ---------- Habit progress bar ---------- */
.habit-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 6px;
}
.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  min-width: 60px;
}
.progress-fill {
  height: 100%;
  background: var(--good);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.progress-fill.behind { background: var(--warn); }
.progress-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  padding: 0;
  cursor: pointer;
}

/* ---------- Search / toolbar ---------- */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.toolbar input[type="search"],
.toolbar select {
  flex: 1;
  min-width: 120px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
}
.toolbar button {
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 18px;
  width: 40px;
  height: 40px;
  cursor: pointer;
}

@media (max-width: 899px) {
  .theme-toggle {
    position: absolute;
    top: calc(env(safe-area-inset-top) + 18px);
    right: 18px;
  }
}

/* ---------- Work/Home filter + badges ---------- */
.area-filter {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.area-filter-btn {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.area-filter-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
}
.area-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.area-badge.work { background: var(--purple-soft); color: #6b46c1; }
.area-badge.home { background: var(--good-soft); color: #1f8a52; }

/* ---------- Ideas ---------- */
.idea-tags {
  font-size: 12px;
  color: var(--accent);
}
.idea-status-badge {
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--border);
  color: var(--muted);
}

/* ---------- Gut health checklist ---------- */
.gut-item {
  cursor: pointer;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}
.gut-item:last-child { border-bottom: none; }
.gut-item.done span { color: var(--good); font-weight: 600; }
.gut-item:active { background: var(--accent-soft); }
.gut-streak { margin-bottom: 10px; font-size: 15px; }

/* ---------- Gut health guide ---------- */
.guide-intro {
  margin: -4px 0 16px;
  font-size: 12.5px;
  color: var(--muted);
}

.food-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 18px;
}

@media (min-width: 640px) {
  .food-grid { grid-template-columns: 1fr 1fr; }
}

.food-col h4 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
}

.food-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.food-chip {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.food-chip.good { background: var(--good-soft); color: var(--good); }
.food-chip.bad { background: var(--bad-soft); color: var(--bad); }

.food-note {
  margin: 10px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.5;
}

.guide-subhead {
  margin: 4px 0 8px;
  font-size: 13px;
  font-weight: 700;
}

.guide-list li {
  font-size: 13.5px;
  padding: 9px 2px;
}

.guide-disclaimer {
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 12px;
  line-height: 1.5;
  font-weight: 600;
}

/* ---------- Meal & symptom log ---------- */
.symptom-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.symptom-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.symptom-chip input { margin: 0; }

.symptom-freq {
  margin-bottom: 14px;
}

.freq-title {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 10px;
}

.freq-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.freq-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.freq-label {
  font-size: 12.5px;
  min-width: 130px;
  flex-shrink: 0;
}
