/* ---------- Design tokens ---------- */
:root {
  --bg: #ffffff;
  --bg-alt: #f4f6fb;
  --text: #1a2233;
  --text-muted: #5b6577;
  --accent: #4f6df5;
  --accent-soft: rgba(79, 109, 245, 0.12);
  --card: #ffffff;
  --border: #e3e8f2;
  --shadow: 0 10px 30px -15px rgba(20, 30, 60, 0.25);
  --radius: 14px;
  --maxw: 1000px;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
}

[data-theme="dark"] {
  --bg: #0e1220;
  --bg-alt: #141a2e;
  --text: #e6ebf5;
  --text-muted: #9aa6bf;
  --accent: #7d95ff;
  --accent-soft: rgba(125, 149, 255, 0.15);
  --card: #161d31;
  --border: #26304a;
  --shadow: 0 10px 30px -15px rgba(0, 0, 0, 0.6);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; scroll-padding-top: 80px; }

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.3s ease, color 0.3s ease;
}

.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }

a { color: var(--accent); text-decoration: none; transition: opacity 0.2s ease; }
a:hover { opacity: 0.75; }

/* ---------- Header / nav ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  border-bottom: 1px solid var(--border);
}
.nav { display: flex; align-items: center; justify-content: space-between; min-height: 64px; gap: 16px; flex-wrap: wrap; }
.brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--accent);
  border: 2px solid var(--accent);
  border-radius: 8px;
  padding: 2px 10px;
}
.nav-links { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.nav-links a { color: var(--text); font-weight: 500; font-size: 0.9rem; }
.nav-links a.active { color: var(--accent); font-weight: 600; }
.theme-toggle {
  width: 34px; height: 34px; padding: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 2px solid var(--border);
  background: var(--accent-soft); color: var(--accent);
  transition: border-color 0.15s ease, transform 0.15s ease, color 0.15s ease;
}
.theme-toggle svg { width: 18px; height: 18px; display: block; }
.theme-toggle:hover { border-color: var(--accent); transform: scale(1.05); }

/* ---------- Sections ---------- */
.section { padding: 56px 24px; border-top: 1px solid var(--border); }
.section:first-of-type { border-top: none; }
.section-title { display: flex; align-items: baseline; gap: 12px; font-size: 1.6rem; margin-bottom: 32px; font-weight: 600; }
.page-title { font-family: var(--serif); font-size: clamp(2rem, 6vw, 2.8rem); margin: 24px 0 20px; }
.page-intro { max-width: 640px; color: var(--text-muted); font-size: 1.05rem; margin-bottom: 24px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 0.9rem;
  padding: 10px 18px; border-radius: 10px; border: 1px solid var(--border); cursor: pointer;
  background: var(--card); color: var(--text); transition: border-color 0.15s ease, transform 0.15s ease; }
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { opacity: 0.9; }

/* ---------- Cards (Health) ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 20px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow); transition: transform 0.2s ease;
}
.card:hover { transform: translateY(-4px); }
.card h4 { font-size: 1.1rem; margin-bottom: 8px; }
.card p { color: var(--text-muted); font-size: 0.92rem; }
.stat { font-family: var(--serif); font-size: 2rem; color: var(--accent); margin: 4px 0; }

/* ---------- Health tip tables ---------- */
.tips-group { margin-bottom: 40px; }
.tips-group:last-child { margin-bottom: 0; }
.tips-heading {
  font-size: 1.3rem; font-weight: 600; margin-bottom: 18px;
  padding-bottom: 10px; border-bottom: 1px solid var(--border);
  color: var(--text); cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 10px; transition: color 0.15s ease;
}
.tips-heading:hover { color: var(--accent); }
.tips-heading::before {
  content: "\25be"; color: var(--accent); font-size: 0.8em; transition: transform 0.15s ease;
}
.tips-group.collapsed .tips-heading { margin-bottom: 0; }
.tips-group.collapsed .tips-heading::before { transform: rotate(-90deg); }
.tips-group.collapsed .table-wrap { display: none; }

.table-wrap { overflow-x: auto; }
.tips-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.tips-table td {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  vertical-align: top; color: var(--text); line-height: 1.6;
}
.tips-table tbody tr { transition: background 0.15s ease; }
.tips-table tbody tr:last-child td { border-bottom: none; }
.tips-table tbody tr:hover { background: var(--accent-soft); }
.tips-table strong { color: var(--text); }
.tips-table ul { margin: 8px 0 0 20px; padding: 0; }
.tips-table ul li { margin: 4px 0; color: var(--text-muted); }
.tips-table .tip-lead { display: block; margin-bottom: 4px; }

/* Editable tip cells */
.tips-table td.tip-cell {
  border-radius: 8px; transition: box-shadow 0.15s ease, background 0.15s ease;
}
.tips-table td.tip-cell:hover { background: var(--accent-soft); }
.tips-table td.tip-cell:focus {
  outline: none; background: var(--bg-alt);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.tips-table td.tip-tools { width: 1%; white-space: nowrap; text-align: right; }
.tip-delete {
  border: none; background: transparent; cursor: pointer; color: var(--text-muted);
  font-size: 1rem; line-height: 1; padding: 4px 8px; border-radius: 8px; opacity: 0.5;
  transition: color 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}
tr:hover .tip-delete { opacity: 1; }
.tip-delete:hover { color: #e5484d; background: rgba(229, 72, 77, 0.12); }
.add-tip { margin-top: 14px; font-size: 0.82rem; padding: 7px 14px; }

/* Sign-in gate / user bar */
.user-bar { display: inline-flex; align-items: center; gap: 10px; }
.user-label { color: var(--text-muted); font-size: 0.82rem; }
#signin-gate .btn-primary { margin-top: 8px; }

/* ---------- Private Journal ---------- */
.journal-editor { display: flex; flex-direction: column; gap: 12px; margin-bottom: 40px; max-width: 720px; }
.journal-editor input[type="date"],
.journal-editor input[type="text"],
.journal-editor textarea {
  font-family: inherit; font-size: 1rem; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  transition: border-color 0.15s ease;
}
.journal-editor input:focus,
.journal-editor textarea:focus { outline: none; border-color: var(--accent); }
.journal-editor textarea { min-height: 160px; resize: vertical; line-height: 1.6; }
.journal-row { display: flex; gap: 12px; flex-wrap: wrap; }
.journal-row > * { flex: 1; min-width: 160px; }
.journal-actions { display: flex; gap: 12px; align-items: center; }

.entry-list { display: flex; flex-direction: column; gap: 20px; max-width: 720px; }
.entry {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow);
}
.entry-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.entry-title { font-family: var(--serif); font-size: 1.25rem; }
.entry-date { color: var(--text-muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.entry-body { color: var(--text); font-size: 0.98rem; white-space: pre-wrap; }
.entry-delete {
  border: none; background: transparent; cursor: pointer; color: var(--text-muted);
  font-size: 1.1rem; line-height: 1; padding: 2px 8px; border-radius: 8px;
  transition: color 0.15s ease, background 0.15s ease;
}
.entry-delete:hover { color: #e5484d; background: rgba(229, 72, 77, 0.12); }
.empty-note { color: var(--text-muted); font-style: italic; }

/* ---------- Footer ---------- */
.site-footer { text-align: center; padding: 40px 24px; color: var(--text-muted); font-size: 0.85rem; border-top: 1px solid var(--border); }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .nav-links { gap: 12px; }
  .nav-links a { font-size: 0.8rem; }
}
