/* ============================================================
   Phil's Wellness Dashboard — Style System
   Warm editorial wellness aesthetic
   ============================================================ */

/* ── Fonts ─────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500;600;700&family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

/* ── Tokens ────────────────────────────────────────────── */
:root {
  --bg:            #F9F5EE;
  --surface:       #FFFFFF;
  --surface-alt:   #F3EDE3;
  --text-primary:  #1C1917;
  --text-secondary:#78716C;
  --accent:        #B5812A;
  --accent-light:  #F0DFB4;
  --accent-hover:  #9A6C1F;
  --sage:          #6B8C5F;
  --sage-light:    #D4E4CA;
  --terracotta:    #C1624A;
  --border:        #E7DDD0;
  --shadow-sm:     0 1px 3px rgba(28,25,23,0.06), 0 1px 2px rgba(28,25,23,0.04);
  --shadow-md:     0 4px 12px rgba(28,25,23,0.08), 0 2px 4px rgba(28,25,23,0.04);
  --shadow-lg:     0 8px 24px rgba(28,25,23,0.10), 0 4px 8px rgba(28,25,23,0.04);
  --radius-sm:     6px;
  --radius-md:     12px;
  --radius-lg:     16px;
  --font-serif:    'Playfair Display', Georgia, serif;
  --font-sans:    'DM Sans', system-ui, sans-serif;
  --font-mono:     'DM Mono', 'Courier New', monospace;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* Warm dot-grid hero background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: radial-gradient(circle, #D4C9B8 1px, transparent 1px);
  background-size: 28px 28px;
  opacity: 0.35;
  pointer-events: none;
  z-index: -1;
}

::selection { background: var(--accent-light); color: var(--text-primary); }

/* Custom scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #C4B9AB; }

/* ── Typography ────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  line-height: 1.25;
  color: var(--text-primary);
}
h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); font-weight: 600; }
h2 { font-size: clamp(1.25rem, 2.5vw, 1.5rem); font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 500; }
p  { color: var(--text-secondary); }

/* ── Layout ────────────────────────────────────────────── */
.page-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

.page-content {
  padding-top: 88px; /* nav height */
}

/* ── Nav ──────────────────────────────────────────────── */
.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: rgba(249,245,238,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  height: 64px;
  display: flex;
  align-items: center;
}
.nav .page-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.nav-wordmark {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-wordmark span {
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
}
.nav-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.nav-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}
.nav-refresh {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all 150ms ease;
}
.nav-refresh:hover { border-color: var(--accent); color: var(--accent); }
.nav-refresh.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Hero ──────────────────────────────────────────────── */
.hero {
  padding: 48px 0 32px;
}
.hero-greeting {
  font-size: 0.9rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 8px;
}
.hero-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

/* ── StatCard ──────────────────────────────────────────── */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: transform 150ms ease, box-shadow 150ms ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.1;
}
.stat-value.large { font-size: 2.25rem; }
.stat-unit {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-family: var(--font-sans);
}
.stat-delta {
  font-size: 0.8rem;
  font-weight: 500;
  margin-top: 2px;
}
.stat-delta.neg { color: var(--sage); }
.stat-delta.pos { color: var(--terracotta); }
.stat-delta.neu { color: var(--text-secondary); }
.stat-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}
.stat-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width 800ms cubic-bezier(0.16, 1, 0.3, 1);
}
.stat-bar-fill.sage { background: var(--sage); }
.stat-bar-fill.terracotta { background: var(--terracotta); }

/* Goal progress ring */
.stat-ring {
  position: relative;
  width: 80px; height: 80px;
  margin-bottom: 4px;
}
.stat-ring svg {
  transform: rotate(-90deg);
  width: 100%; height: 100%;
}
.stat-ring .ring-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 6;
}
.stat-ring .ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset 1000ms cubic-bezier(0.16, 1, 0.3, 1);
}
.stat-ring .ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 500;
}
.stat-ring-wrap { display: flex; flex-direction: column; }

/* ── Skeleton loading ──────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--surface-alt) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-stat { height: 100px; border-radius: var(--radius-md); }
.skel-hero { height: 48px; width: 60%; }

/* ── Prompts section ────────────────────────────────────── */
.prompts {
  padding: 24px 0 40px;
}
.section-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.prompts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.prompt-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: all 150ms ease;
  box-shadow: var(--shadow-sm);
}
.prompt-card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.prompt-card.done { opacity: 0.55; border-color: var(--border); cursor: default; pointer-events: none; }
.prompt-card.done:hover { transform: none; box-shadow: var(--shadow-sm); }
.prompt-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
}
.prompt-card.done .prompt-icon { background: var(--surface-alt); color: var(--sage); }
.prompt-body { flex: 1; min-width: 0; }
.prompt-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.prompt-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.prompt-arrow { color: var(--text-secondary); flex-shrink: 0; }

/* ── Chart section ────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 20px;
  margin-bottom: 40px;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}
.chart-header h2 { flex: 1; }
.chart-toggles {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.toggle-btn {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 120ms ease;
}
.toggle-btn:hover { border-color: var(--accent); color: var(--accent); }
.toggle-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chart-wrap {
  position: relative;
  height: 220px;
}
.chart-wrap canvas { width: 100% !important; height: 100% !important; }
.chart-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 180px;
  color: var(--text-secondary);
  font-size: 0.88rem;
  gap: 8px;
}

/* ── Nutrition today ───────────────────────────────────── */
.nutrition-today {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 20px;
  margin-bottom: 40px;
}
.macro-rings {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.rings-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 20px;
}
.ring-item { display: flex; align-items: center; gap: 12px; }
.ring-svg {
  width: 56px; height: 56px;
  flex-shrink: 0;
  transform: rotate(-90deg);
}
.ring-svg .ring-bg { fill: none; stroke: var(--border); stroke-width: 5; }
.ring-svg .ring-fill { fill: none; stroke-width: 5; stroke-linecap: round; transition: stroke-dashoffset 800ms cubic-bezier(0.16,1,0.3,1); }
.ring-info { flex: 1; }
.ring-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-secondary); }
.ring-nums { font-family: var(--font-mono); font-size: 1.05rem; font-weight: 500; }
.ring-goal { font-size: 0.75rem; color: var(--text-secondary); }

.meals-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.meals-list { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.meal-row {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}
.meal-row-header {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  gap: 10px;
  transition: background 120ms;
}
.meal-row-header:hover { background: var(--surface-alt); }
.meal-type {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  width: 70px;
  flex-shrink: 0;
}
.meal-name { flex: 1; font-size: 0.88rem; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal-cal  { font-family: var(--font-mono); font-size: 0.82rem; color: var(--text-secondary); }
.meal-macros {
  display: flex;
  gap: 8px;
  padding: 8px 14px;
  background: var(--surface-alt);
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.meal-macros span { font-family: var(--font-mono); font-size: 0.75rem; }
.meal-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 120px;
  color: var(--text-secondary);
  font-size: 0.88rem;
  gap: 8px;
}

/* ── Add Meal FAB ──────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 28px; right: 28px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 150ms ease;
  z-index: 90;
}
.fab:hover { background: var(--accent-hover); transform: scale(1.05); }
.fab-label {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--text-primary);
  color: #fff;
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms;
}
.fab:hover .fab-label { opacity: 1; }

/* ── Modal ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(28,25,23,0.45);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  transform: translateY(12px) scale(0.98);
  transition: transform 200ms ease;
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.modal-title { font-family: var(--font-serif); font-size: 1.25rem; font-weight: 600; }
.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--surface-alt);
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  transition: all 120ms;
}
.modal-close:hover { background: var(--border); color: var(--text-primary); }

/* ── Forms ────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color 150ms;
  outline: none;
  appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
}
.form-textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.form-select-wrap { position: relative; }
.form-select-wrap::after {
  content: '▼';
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  font-size: 0.6rem;
  color: var(--text-secondary);
  pointer-events: none;
}
.form-select { padding-right: 32px; cursor: pointer; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 24px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 150ms ease;
  width: 100%;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--surface-alt); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

.form-success {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--sage-light);
  border-radius: var(--radius-sm);
  color: var(--sage);
  font-size: 0.9rem;
  font-weight: 500;
  margin-top: 12px;
}
.form-error {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: #FDECEA;
  border-radius: var(--radius-sm);
  color: var(--terracotta);
  font-size: 0.9rem;
  font-weight: 500;
  margin-top: 12px;
}

/* ── Tabs (modal type switcher) ─────────────────────────── */
.log-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 12px;
}
.log-tab {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 120ms;
  text-decoration: none;
}
.log-tab:hover { border-color: var(--accent); color: var(--accent); }
.log-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Footer ────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 32px 0 48px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.footer-dot { width: 4px; height: 4px; background: var(--border); border-radius: 50%; display: inline-block; }

/* ── Error / offline banner ────────────────────────────── */
.offline-banner {
  background: #FEF3E2;
  border-bottom: 1px solid #F5D59B;
  padding: 10px 20px;
  font-size: 0.82rem;
  color: #8A5A1A;
  text-align: center;
  display: none;
}
.offline-banner.show { display: block; }

/* ── Entrance animations ───────────────────────────────── */
.fade-up {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 400ms ease-out, transform 400ms ease-out;
}
.fade-up.visible {
  opacity: 1;
  transform: translateY(0);
}
.stagger-1 { transition-delay: 80ms; }
.stagger-2 { transition-delay: 160ms; }
.stagger-3 { transition-delay: 240ms; }
.stagger-4 { transition-delay: 320ms; }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 900px) {
  .charts-row { grid-template-columns: 1fr; }
  .nutrition-today { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .hero-stats { grid-template-columns: 1fr 1fr; }
  .stat-value.large { font-size: 1.75rem; }
  .prompts-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .modal { padding: 24px 20px; }
}
@media (max-width: 400px) {
  .hero-stats { grid-template-columns: 1fr; }
}
