:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1e21;
  --muted: #8a8f98;
  --border: #ececef;
  --accent: #3d7dfc;
  --accent-soft: #eaf1ff;
  --good: #34c77b;
  --good-soft: #e7f8ee;
  --warn: #f5a524;
  --warn-soft: #fef3e2;
  --bad: #f1503d;
  --bad-soft: #fdeae7;
  --purple-soft: #f1ecff;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.04), 0 6px 20px rgba(20, 20, 30, 0.05);
}

* { 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;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 18px) 18px 14px;
}

.topbar h1 {
  margin: 0 0 14px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

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

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

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

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

/* ---------- Layout / pages ---------- */
main {
  padding: 4px 18px 100px;
  max-width: 640px;
  margin: 0 auto;
}

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

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

.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
  margin: 0 0 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); }

/* ---------- Access gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  background: rgba(28, 30, 33, 0.5);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.gate.hidden { display: none; }

.gate-box {
  background: var(--card);
  box-shadow: var(--shadow);
  padding: 30px 26px;
  border-radius: 22px;
  width: 90%;
  max-width: 320px;
  text-align: center;
}

.gate-box h2 { margin: 0 0 4px; font-size: 19px; }
.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: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 14px;
}

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

/* ---------- Bottom nav ---------- */
.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
}

.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;
}

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

.bottomnav a.active { color: var(--accent); }

/* ---------- Floating action button ---------- */
.fab {
  position: fixed;
  right: 18px;
  bottom: 84px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 28px;
  line-height: 56px;
  z-index: 11;
  box-shadow: 0 8px 20px rgba(61, 125, 252, 0.35);
  transition: transform 0.15s ease;
}

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

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

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

.kanban-tab.active {
  background: var(--accent);
  color: #fff;
}

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

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

.kanban-col h3 {
  font-size: 12.5px;
  font-weight: 700;
  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-radius: var(--radius-md);
  padding: 12px;
  font-size: 13.5px;
}

.kanban-card .title {
  font-weight: 600;
  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: none;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 1px 2px rgba(20, 20, 30, 0.06);
}

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

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(28, 30, 33, 0.45);
  display: flex;
  align-items: flex-end;
  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;
}

@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: 700; }

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

.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;
}

.form-actions .save { background: var(--accent); 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: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 6px 10px;
  font-size: 12px;
}

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: #2f9e6e; }
.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; }
