:root {
  --bg: #0d0f0e;
  --bg1: #131716;
  --bg2: #1a1e1c;
  --bg3: #222825;
  --bg4: #2c3330;
  --bg5: #353d39;
  --border: rgba(255,255,255,.08);
  --border2: rgba(255,255,255,.12);
  --text: #e8ebe9;
  --text2: #9aada4;
  --text3: #5c6e67;
  --green: #4caf82;
  --green2: #2d7a55;
  --greendim: rgba(76,175,130,.15);
  --amber: #d4894a;
  --amberdim: rgba(212,137,74,.14);
  --red: #c0443a;
  --reddim: rgba(192,68,58,.15);
  --blue: #5b8def;
  --bluedim: rgba(91,141,239,.12);
  --pink: #e879a8;
  --pinkdim: rgba(232,121,168,.12);
  --purple: #a855f7;
  --purpledim: rgba(168,85,247,.12);
  --cyan: #22d3ee;
  --cyandim: rgba(34,211,238,.12);
  --orange: #f97316;
  --orangedim: rgba(249,115,22,.12);
  --r1: 6px;
  --r2: 12px;
  --r3: 18px;
  --nav-h: 58px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html,body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'Inter', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}

input,textarea,select,button { font: inherit; color: inherit; }

/* ── App Shell ─────────────────────── */
#app { height: 100%; display: flex; flex-direction: column; }

/* ── Top Bar ───────────────────────── */
.top-bar {
  padding: 12px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}
.top-bar h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -.02em;
}
.top-bar .date-badge {
  font-size: .75rem;
  color: var(--text2);
  font-weight: 500;
}
.top-actions { display: flex; gap: 8px; }
.top-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--bg3);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background .15s;
}
.top-btn:active { background: var(--bg4); }

/* ── Main Content ──────────────────── */
.main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 0 8px;
}
.screen { display: none; }
.screen.active { display: block; }

/* ── Bottom Nav ────────────────────── */
.bottom-nav {
  display: flex;
  align-items: stretch;
  height: var(--nav-h);
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg1);
  overflow-x: auto;
  gap: 0;
}
.nav-item {
  flex: 1;
  min-width: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: .6rem;
  color: var(--text3);
  cursor: pointer;
  transition: color .15s, background .15s;
  border: none;
  background: transparent;
  padding: 4px 0;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.nav-item .nav-icon { font-size: 1.25rem; line-height: 1; }
.nav-item.active { color: var(--text); }
.nav-item.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--green);
  border-radius: 0 0 2px 2px;
}
.nav-item:active { background: var(--bg2); }

/* ── Card ──────────────────────────── */
.card {
  background: var(--bg2);
  border-radius: var(--r2);
  padding: 14px;
  margin: 8px 16px;
  border: 1px solid var(--border);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.card-title {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.card-action {
  font-size: .72rem;
  color: var(--green);
  cursor: pointer;
  font-weight: 600;
}
.card-action:active { opacity: .7; }

/* ── Stats Row ─────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 4px 16px 0;
}
.stat-card {
  background: var(--bg2);
  border-radius: var(--r1);
  padding: 10px 8px;
  text-align: center;
  border: 1px solid var(--border);
}
.stat-num {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.2;
}
.stat-label {
  font-size: .62rem;
  color: var(--text2);
  margin-top: 2px;
}
.stat-card.green .stat-num { color: var(--green); }
.stat-card.amber .stat-num { color: var(--amber); }
.stat-card.blue .stat-num { color: var(--blue); }
.stat-card.pink .stat-num { color: var(--pink); }

/* ── Task Item ─────────────────────── */
.task-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.task-item:last-child { border-bottom: none; }
.task-check {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border2);
  flex-shrink: 0;
  margin-top: 1px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.task-check.done {
  background: var(--green);
  border-color: var(--green);
}
.task-check.done::after { content: '✓'; font-size: .65rem; color: #fff; font-weight: 700; }
.task-check:active { transform: scale(.85); }
.task-body { flex: 1; min-width: 0; }
.task-title { font-size: .85rem; font-weight: 500; }
.task-title.done { text-decoration: line-through; color: var(--text3); }
.task-meta {
  font-size: .7rem;
  color: var(--text2);
  margin-top: 2px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.priority-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  margin-right: 4px;
}
.prio-high { color: var(--red); }
.prio-medium { color: var(--amber); }
.prio-low { color: var(--text3); }
.tag {
  font-size: .62rem;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg3);
  color: var(--text2);
}

/* ── Event Item ────────────────────── */
.event-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.event-item:last-child { border-bottom: none; }
.event-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.event-time { font-size: .72rem; color: var(--text2); min-width: 42px; }
.event-title { font-size: .85rem; font-weight: 500; }

/* ── Shopping Item ─────────────────── */
.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.shop-item:last-child { border-bottom: none; }
.shop-check {
  width: 20px; height: 20px;
  border-radius: 4px;
  border: 2px solid var(--border2);
  flex-shrink: 0;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.shop-check.done { background: var(--green); border-color: var(--green); }
.shop-check.done::after { content: '✓'; font-size: .6rem; color: #fff; }
.shop-name { font-size: .85rem; flex: 1; }
.shop-name.done { text-decoration: line-through; color: var(--text3); }
.shop-qty { font-size: .72rem; color: var(--text2); }
.shop-urgent { font-size: .6rem; color: var(--red); font-weight: 600; }

/* ── Meal Card ─────────────────────── */
.meal-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
}
.meal-icon { font-size: 1.5rem; }
.meal-details { flex: 1; }
.meal-label { font-size: .68rem; color: var(--text2); }
.meal-title { font-size: .9rem; font-weight: 600; }
.meal-empty { font-size: .8rem; color: var(--text3); font-style: italic; }

/* ── Empty States ──────────────────── */
.empty-state {
  text-align: center;
  padding: 16px 0;
  color: var(--text3);
  font-size: .8rem;
}

/* ── Quick Add FAB ─────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  right: 16px;
  width: 50px; height: 50px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  border: none;
  font-size: 1.5rem;
  box-shadow: 0 4px 16px rgba(76,175,130,.3);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, box-shadow .15s;
  z-index: 10;
}
.fab:active { transform: scale(.92); box-shadow: none; }

/* ── Modal ─────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg1);
  border-radius: var(--r3) var(--r3) 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px 20px max(24px, env(safe-area-inset-bottom));
  animation: slideUp .25s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal h2 { font-size: 1rem; font-weight: 700; margin-bottom: 16px; }
.form-group { margin-bottom: 12px; }
.form-group label {
  display: block;
  font-size: .72rem;
  color: var(--text2);
  font-weight: 600;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--r1);
  outline: none;
  transition: border-color .15s;
  font-size: .85rem;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--green); }
.form-textarea { min-height: 60px; resize: vertical; }
.form-row { display: flex; gap: 8px; }
.form-row > * { flex: 1; }
.btn {
  padding: 10px 18px;
  border-radius: var(--r1);
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: .85rem;
  transition: opacity .15s;
}
.btn:active { opacity: .7; }
.btn-primary { background: var(--green); color: #fff; width: 100%; }
.btn-secondary { background: var(--bg3); color: var(--text); }
.btn-danger { background: var(--reddim); color: var(--red); }
.btn-sm { padding: 6px 12px; font-size: .75rem; }

/* ── Section Styles ────────────────── */
.section-pad { padding: 4px 0; }

/* ── Calendar Grid ─────────────────── */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7,1fr);
  gap: 2px;
  text-align: center;
  margin-top: 8px;
}
.cal-day-header { font-size: .65rem; color: var(--text3); padding: 4px 0; font-weight: 600; }
.cal-day {
  padding: 8px 0;
  font-size: .78rem;
  border-radius: var(--r1);
  cursor: pointer;
}
.cal-day.today { background: var(--greendim); color: var(--green); font-weight: 700; }
.cal-day.other { color: var(--text3); }
.cal-day.has-event { font-weight: 700; }

/* ── Project Card ──────────────────── */
.project-card {
  background: var(--bg2);
  border-radius: var(--r2);
  padding: 14px;
  margin: 8px 16px;
  border-left: 3px solid var(--purple);
}
.project-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.project-title { font-weight: 600; font-size: .9rem; }
.project-status { font-size: .65rem; padding: 2px 8px; border-radius: 10px; background: var(--bluedim); color: var(--blue); }
.progress-bar { height: 4px; background: var(--bg3); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 2px; transition: width .3s; }

/* ── Learning Session ──────────────── */
.learning-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.le-child { font-weight: 600; font-size: .8rem; min-width: 50px; }
.le-activity { flex: 1; font-size: .8rem; }
.le-duration { font-size: .68rem; color: var(--text2); }
.le-date { font-size: .65rem; color: var(--text3); }

/* ── Document Card ─────────────────── */
.doc-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg2);
  border-radius: var(--r1);
  margin: 6px 16px;
  border: 1px solid var(--border);
}
.doc-icon { font-size: 1.3rem; }
.doc-info { flex: 1; }
.doc-title { font-size: .82rem; font-weight: 500; }
.doc-meta { font-size: .65rem; color: var(--text2); }
.doc-expiry { font-size: .65rem; color: var(--red); }

/* ── Shopping Lists View ───────────────── */
.shopping-list-card {
  background: var(--bg2);
  border-radius: var(--r2);
  margin: 8px 16px;
  border: 1px solid var(--border);
  overflow: hidden;
}
.shopping-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.shopping-list-header:active { background: var(--bg3); }
.shopping-list-items { padding: 4px 14px 8px; }

/* ── / ── */
.hidden { display: none !important; }

/* ── Loading Spinner ────────────────── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 16px;
  color: var(--text3);
  gap: 12px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--bg3);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Screen transitions ─────────────── */
.screen { display: none; animation: fadeIn .2s ease; }
.screen.active { display: block; }
@keyframes fadeIn {
  from { opacity: .4; }
  to { opacity: 1; }
}

/* ── Responsive ────────────────────── */
@media (min-width: 600px) {
  .main { max-width: 480px; margin: 0 auto; }
  .fab { right: calc(50% - 240px + 16px); }
}
