/* ── Reset & Base ────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f0f13;
  --surface:   #1a1a24;
  --surface2:  #24243a;
  --border:    #2e2e44;
  --text:      #e2e2f0;
  --text-dim:  #8989a8;
  --accent:    #6366f1;
  --accent-h:  #5457e5;
  --green:     #22c55e;
  --red:       #ef4444;
  --orange:    #f59e0b;
  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 2px 8px rgba(0,0,0,.3);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100dvh; display: flex; flex-direction: column; }

/* ── Header ─────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1;
}
header .back {
  display: none;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
}
header .back.show { display: block; }

/* ── App Grid (Dashboard) ────────────────────────────── */
#dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px;
  flex: 1;
}
.app-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: background .15s, transform .1s;
  text-decoration: none;
  color: var(--text);
}
.app-card:active { transform: scale(.96); }
.app-card .icon { font-size: 2rem; margin-bottom: 8px; }
.app-card .name { font-size: .95rem; font-weight: 500; }
.app-card .desc { font-size: .8rem; color: var(--text-dim); margin-top: 4px; }

/* ── Micro App Container ─────────────────────────────── */
#app-container {
  display: none;
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}
#app-container.active { display: block; }

/* ── Shared Components ───────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card.compact { padding: 12px; }

input, select, button {
  font-family: inherit;
  font-size: 1rem;
}
input[type="text"],
input[type="number"],
input[type="date"],
input[type="time"],
select {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border .15s;
}
input:focus, select:focus { border-color: var(--accent); }

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-primary:active { transform: scale(.97); }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface2); }

.row { display: flex; gap: 8px; align-items: center; }
.row .grow { flex: 1; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-6  { margin-bottom: 6px; }
.mb-8  { margin-bottom: 8px; }
.text-dim  { color: var(--text-dim); }
.text-sm   { font-size: .85rem; }
.text-xs   { font-size: .72rem; }
.stat-val  { font-size: 1.1rem; font-weight: 600; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-8 { gap: 8px; }
.gap-4 { gap: 4px; }

/* ── Charts / Canvas ─────────────────────────────────── */
canvas {
  width: 100% !important;
  max-height: 180px;
  border-radius: var(--radius-sm);
}

/* ── Progress Bar ─────────────────────────────────────── */
.bar-track {
  width: 100%;
  height: 8px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width .3s ease, background .3s ease;
}

/* ── Grocery List ────────────────────────────────────── */
.grocery-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.grocery-item:last-child { border-bottom: none; }
.grocery-item .cat-badge {
  font-size: .7rem;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--surface2);
  color: var(--text-dim);
}
.grocery-item.checked .name { text-decoration: line-through; color: var(--text-dim); }

/* ── Calendar ────────────────────────────────────────── */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  text-align: center;
}
.cal-grid .day {
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  cursor: pointer;
}
.cal-grid .day:hover { background: var(--surface2); }
.cal-grid .day.today { background: var(--accent); color: #fff; }
.cal-grid .day.other { color: var(--text-dim); }
.cal-grid .day.has-events { font-weight: 600; }
.cal-grid .dow { font-size: .75rem; color: var(--text-dim); padding: 4px; }

/* ── Responsive ──────────────────────────────────────── */
@media (min-width: 480px) {
  #dashboard { grid-template-columns: repeat(4, 1fr); }
  #app-container { max-width: 480px; margin: 0 auto; }
}
