*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f4f8;
  --card: #ffffff;
  --primary: #6c63ff;
  --primary-light: #ede9ff;
  --accent: #43c6ac;
  --danger: #ff6b6b;
  --text: #2d3748;
  --muted: #718096;
  --border: #e2e8f0;
  --radius: 16px;
  --shadow: 0 2px 16px rgba(108,99,255,0.08);
  --topbar-h: 56px;
  --tabnav-h: 52px;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --card: #1a1d27;
  --primary: #8b83ff;
  --primary-light: #2a2640;
  --accent: #38b2a0;
  --danger: #fc8181;
  --text: #e2e8f0;
  --muted: #718096;
  --border: #2d3748;
  --shadow: 0 2px 16px rgba(0,0,0,0.3);
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-top: calc(var(--topbar-h) + var(--tabnav-h));
  padding-bottom: 32px;
  transition: background 0.3s, color 0.3s;
}

/* ── Top bar ────────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 200;
  box-shadow: var(--shadow);
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.app-logo { font-size: 1.4rem; }
.app-name { font-size: 1.1rem; font-weight: 700; color: var(--primary); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.streak-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--primary-light);
  border-radius: 50px;
  padding: 4px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
}

.theme-toggle {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 34px; height: 34px;
  cursor: pointer;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, border-color 0.2s;
}
.theme-toggle:hover { border-color: var(--primary); background: var(--primary-light); }

/* ── Tab nav ────────────────────────────────────────────────────── */
.tab-nav {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  height: var(--tabnav-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  z-index: 190;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 6px 0;
  border-bottom: 3px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.tab-btn .tab-icon { font-size: 1.2rem; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Tab panels ─────────────────────────────────────────────────── */
.tab-panel {
  display: none;
  padding: 20px 16px;
  max-width: 680px;
  margin: 0 auto;
  animation: fadeIn 0.2s ease;
}
.tab-panel.active { display: block; }

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

/* ── Date nav ───────────────────────────────────────────────────── */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 20px;
}
.date-nav button {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 34px; height: 34px;
  font-size: 1rem;
  cursor: pointer;
  color: var(--primary);
  transition: background 0.2s;
}
.date-nav button:hover { background: var(--primary-light); }
#current-date {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  min-width: 140px;
  text-align: center;
}

/* ── Progress rings row ─────────────────────────────────────────── */
.progress-row {
  display: flex;
  justify-content: space-around;
  gap: 8px;
  margin-bottom: 24px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 8px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.progress-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  position: relative;
}
.ring {
  width: 64px; height: 64px;
  transform: rotate(-90deg);
}
.ring-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 5;
}
.ring-fill {
  fill: none;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 163.4; /* 2π×26 */
  stroke-dashoffset: 163.4;
  transition: stroke-dashoffset 0.5s ease;
}
.ring-emoji {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -60%);
  font-size: 1.1rem;
  line-height: 1;
}
.ring-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
}

/* ── Accordion cards ────────────────────────────────────────────── */
.cards-wrap { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.2s;
}
.card.open { box-shadow: 0 4px 24px rgba(108,99,255,0.14); border-color: var(--primary); }

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.card-header:hover { background: var(--primary-light); }
.card-header h2 {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  margin: 0;
}
.card-header h2 .icon { font-size: 1.2rem; }
.card-preview {
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chevron {
  font-size: 1.2rem;
  color: var(--muted);
  transition: transform 0.25s;
  line-height: 1;
}
.card.open .chevron { transform: rotate(90deg); }

.card-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, padding 0.2s;
  padding: 0 18px;
}
.card.open .card-body {
  max-height: 600px;
  padding: 4px 18px 18px;
}

/* ── Mood ───────────────────────────────────────────────────────── */
.mood-grid { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 8px; }
.mood-btn {
  flex: 1; min-width: 48px;
  padding: 10px 4px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: none;
  cursor: pointer;
  font-size: 1.5rem;
  text-align: center;
  transition: all 0.2s;
}
.mood-btn:hover { border-color: var(--primary); background: var(--primary-light); }
.mood-btn.selected { border-color: var(--primary); background: var(--primary-light); transform: scale(1.1); }
.mood-label { font-size: 0.6rem; color: var(--muted); display: block; margin-top: 2px; }

/* ── Water ──────────────────────────────────────────────────────── */
.water-display { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.water-count { font-size: 2.2rem; font-weight: 700; color: var(--accent); }
.water-unit { color: var(--muted); font-size: 0.85rem; }
.water-cups { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.cup {
  width: 26px; height: 26px;
  border-radius: 6px;
  border: 2px solid var(--accent);
  background: none;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 0;
}
.cup.filled { background: var(--accent); }
.water-controls { display: flex; gap: 10px; }
.btn-sm {
  padding: 7px 16px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: opacity 0.2s;
}
.btn-add { background: var(--accent); color: #fff; }
.btn-remove { background: var(--border); color: var(--text); }
.btn-sm:hover { opacity: 0.82; }

/* ── Sleep ──────────────────────────────────────────────────────── */
.sleep-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.sleep-row label { color: var(--muted); font-size: 0.85rem; min-width: 72px; }
input[type="time"], input[type="number"] {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.2s;
}
input[type="time"]:focus, input[type="number"]:focus { border-color: var(--primary); }
.sleep-duration { font-size: 1.3rem; font-weight: 700; color: var(--primary); margin-top: 4px; }

/* ── Exercise ───────────────────────────────────────────────────── */
.exercise-list { display: flex; flex-direction: column; gap: 8px; }
.exercise-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}
.exercise-item:hover { border-color: var(--primary); }
.exercise-item.done { border-color: var(--primary); background: var(--primary-light); }
.exercise-item .ex-icon { font-size: 1.2rem; }
.exercise-item .ex-name { flex: 1; font-size: 0.88rem; font-weight: 500; }
.exercise-item .ex-check {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem;
  color: transparent;
  transition: all 0.2s;
}
.exercise-item.done .ex-check { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Notes ──────────────────────────────────────────────────────── */
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.88rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  resize: vertical;
  min-height: 90px;
  outline: none;
  transition: border-color 0.2s;
}
textarea:focus { border-color: var(--primary); }

/* ── Stress ─────────────────────────────────────────────────────── */
.stress-value { font-size: 1.8rem; font-weight: 700; color: var(--danger); margin-bottom: 8px; }
input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  padding: 0; height: 6px;
  cursor: pointer;
  border: none; background: none;
}
.stress-labels { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--muted); margin-top: 6px; }

/* ── Save button ────────────────────────────────────────────────── */
.save-btn {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  box-shadow: 0 4px 16px rgba(108,99,255,0.3);
  letter-spacing: 0.3px;
}
.save-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.save-btn:active { transform: translateY(0); }

/* ── Panel header ───────────────────────────────────────────────── */
.panel-header { margin-bottom: 20px; }
.panel-header h2 { font-size: 1.2rem; font-weight: 700; }
.panel-sub { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }

/* ── Insights grid ──────────────────────────────────────────────── */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}
.insight-card {
  background: var(--card);
  border-radius: 12px;
  padding: 14px 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.insight-card .ic-label { font-size: 0.7rem; color: var(--muted); margin-bottom: 4px; }
.insight-card .ic-val { font-size: 1.3rem; font-weight: 700; color: var(--primary); }
.insight-card .ic-sub { font-size: 0.68rem; color: var(--muted); margin-top: 2px; }

/* ── Chart section ──────────────────────────────────────────────── */
.chart-section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.chart-title { font-size: 0.8rem; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.week-bars { display: flex; align-items: flex-end; gap: 6px; height: 60px; }
.week-bar-wrap {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; height: 100%; justify-content: flex-end;
}
.week-bar {
  width: 100%;
  border-radius: 4px 4px 0 0;
  background: var(--primary-light);
  transition: height 0.4s ease;
  min-height: 3px;
}
.week-bar.has-data { background: var(--primary); }
.week-bar-day { font-size: 0.62rem; color: var(--muted); font-weight: 600; }

/* ── Tips ───────────────────────────────────────────────────────── */
.insight-tips { display: flex; flex-direction: column; gap: 8px; }
.tip {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--card);
  border-left: 3px solid var(--primary);
  font-size: 0.83rem;
  color: var(--text);
  box-shadow: var(--shadow);
}
.tip.good { border-color: var(--accent); }
.tip.warn { border-color: #f6ad55; }
.tip .tip-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }

/* ── Streak banner ──────────────────────────────────────────────── */
.streak-banner {
  background: linear-gradient(135deg, #6c63ff 0%, #43c6ac 100%);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  box-shadow: 0 4px 20px rgba(108,99,255,0.25);
  color: #fff;
  margin-bottom: 20px;
}
.streak-fire { font-size: 2rem; line-height: 1; }
.streak-info { flex: 1; }
.streak-info .streak-num { font-size: 1.8rem; font-weight: 800; line-height: 1; }
.streak-info .streak-sub { font-size: 0.8rem; opacity: 0.85; margin-top: 2px; }
.streak-dots { display: flex; gap: 5px; align-items: center; }
.streak-dot {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.6rem; font-weight: 600;
  color: rgba(255,255,255,0.7);
}
.streak-dot.logged { background: rgba(255,255,255,0.9); color: #6c63ff; }
.streak-dot.today { background: #fff; color: #6c63ff; box-shadow: 0 0 0 3px rgba(255,255,255,0.4); }

/* ── History list ───────────────────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 0.9rem; }
.history-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}
.history-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.hc-date {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 8px;
}
.hc-key { font-size: 0.72rem; color: var(--muted); font-weight: 400; }
.hc-stats {
  display: flex; gap: 12px; flex-wrap: wrap;
  font-size: 0.82rem; color: var(--muted);
}
.hc-stats span { display: flex; align-items: center; gap: 3px; }
.hc-notes {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

/* ── Toast ──────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #2d3748;
  color: #fff;
  padding: 11px 24px;
  border-radius: 50px;
  font-size: 0.88rem;
  font-weight: 500;
  transition: transform 0.3s ease;
  z-index: 999;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── Dark mode input fix ────────────────────────────────────────── */
[data-theme="dark"] input[type="time"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] input[type="range"] { color-scheme: dark; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 400px) {
  .insights-grid { grid-template-columns: repeat(2, 1fr); }
  .streak-dots { display: none; }
  .progress-row { gap: 4px; }
  .ring { width: 54px; height: 54px; }
}
