:root {
  --bg: #0e1220;
  --surface: #171d2e;
  --surface-2: #202940;
  --border: #2e3a55;
  --text: #eaf0f7;
  --muted: #95a3bd;
  --accent: #4ade80;
  --accent-dim: #22c55e;
  --danger: #f87171;
  --warn: #f59e0b;
  --info: #60a5fa;
  --violet: #a78bfa;
  --pink: #f472b6;
  --cyan: #38bdf8;
  /* Signature gradients */
  --grad-brand: linear-gradient(135deg, #4ade80, #38bdf8);
  --grad-primary: linear-gradient(135deg, #22c55e, #06b6d4);
  --grad-violet: linear-gradient(135deg, #a78bfa, #f472b6);
  --grad-warm: linear-gradient(135deg, #f59e0b, #f472b6);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --maxw: 1040px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(900px 500px at 12% -8%, rgba(74, 222, 128, 0.10), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(56, 189, 248, 0.10), transparent 55%),
    radial-gradient(1000px 700px at 50% 120%, rgba(167, 139, 250, 0.08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 24px;
  background: linear-gradient(180deg, rgba(32, 41, 64, 0.75), rgba(23, 29, 46, 0.9));
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 {
  font-size: 1.35rem; font-weight: 800; letter-spacing: -0.5px;
  background: var(--grad-brand);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.logo { font-size: 1.6rem; filter: drop-shadow(0 2px 6px rgba(74, 222, 128, 0.35)); }

.date-nav { display: flex; align-items: center; gap: 8px; }

/* ===== Tab bar ===== */
.tabbar {
  display: flex;
  gap: 4px;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 24px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.15s ease, background 0.15s ease;
}
.tab-btn:hover { color: var(--text); background: var(--surface); }
.tab-btn.active { color: var(--cyan); border-bottom-color: var(--cyan); background: var(--surface); }
.tab-ico { font-size: 1rem; }

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px;
}

/* ===== Tab panels ===== */
.tab-panel { display: none; flex-direction: column; gap: 24px; }
.tab-panel.active { display: flex; }

/* ===== Cards ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.card {
  position: relative;
  background: linear-gradient(160deg, var(--surface), rgba(23, 29, 46, 0.7));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.18s ease, border-color 0.18s ease;
}
.card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--grad-brand);
}
.card:hover { transform: translateY(-2px); border-color: #3c4c6f; }
/* Distinct accent per summary card */
.card:nth-child(1)::before { background: var(--grad-primary); }
.card:nth-child(2)::before { background: var(--grad-violet); }
.card:nth-child(3)::before { background: var(--grad-warm); }
.card:nth-child(4)::before { background: linear-gradient(135deg, #38bdf8, #4ade80); }
.card:nth-child(2) .card-value { color: var(--violet); }
.card:nth-child(3) .card-value { color: var(--warn); }
.card-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }
.card-value { font-size: 1.8rem; font-weight: 700; margin-top: 6px; }
.card-value .unit { font-size: 0.9rem; color: var(--muted); font-weight: 500; margin-left: 4px; }

.progress-card { display: flex; flex-direction: column; }
.progress-track { height: 10px; background: var(--surface-2); border-radius: 6px; margin: 14px 0 8px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #22c55e, #38bdf8); border-radius: 6px; transition: width 0.4s ease; box-shadow: 0 0 12px rgba(56, 189, 248, 0.5); }
.progress-fill.over { background: linear-gradient(90deg, var(--warn), var(--danger)); }
.progress-text { font-size: 0.85rem; color: var(--muted); }

/* ===== Layout columns ===== */
.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.panel h2 {
  font-size: 1.05rem; margin-bottom: 16px; font-weight: 700;
  display: flex; align-items: center; gap: 10px;
}
.panel h2::before {
  content: ""; width: 4px; height: 1.05rem; border-radius: 3px;
  background: var(--grad-brand);
}

/* ===== Forms ===== */
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
input, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  outline: none;
}
input:focus, select:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18); }
#foodName { flex: 1 1 140px; }
#foodCals, #weightValue { width: 90px; }
input[type="date"] { color-scheme: dark; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.field input { color: var(--text); }

/* ===== Buttons ===== */
button { cursor: pointer; font-size: 0.95rem; border-radius: var(--radius-sm); border: none; font-family: inherit; }
.primary-btn {
  background: var(--grad-primary); color: #04210f; font-weight: 700; padding: 10px 18px;
  box-shadow: 0 4px 14px rgba(6, 182, 212, 0.28);
  transition: filter 0.15s ease, transform 0.15s ease;
}
.primary-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.primary-btn:active { transform: translateY(0); }
.ghost-btn { background: transparent; color: var(--text); border: 1px solid var(--border); padding: 9px 14px; }
.ghost-btn:hover { background: var(--surface-2); }
.danger-btn { background: transparent; color: var(--danger); border: 1px solid var(--danger); padding: 9px 14px; }
.danger-btn:hover { background: rgba(248, 113, 113, 0.12); }
.icon-btn { background: var(--surface-2); color: var(--text); width: 34px; height: 34px; font-size: 1.2rem; line-height: 1; }
.icon-btn:hover { background: var(--border); }

/* ===== Entry list ===== */
.entry-list { list-style: none; margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.entry {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 14px;
}
.entry-name { font-weight: 500; }
.entry-cals { color: var(--muted); margin-left: auto; margin-right: 12px; }
.entry-del { background: transparent; color: var(--muted); font-size: 1.1rem; padding: 0 4px; }
.entry-del:hover { color: var(--danger); }

.empty { color: var(--muted); font-size: 0.88rem; margin-top: 14px; font-style: italic; }

/* ===== Weight stats ===== */
.weight-stats { display: flex; gap: 28px; margin: 16px 0; }
.weight-stats div { display: flex; flex-direction: column; }
.stat-num { font-size: 1.4rem; font-weight: 700; }
.stat-cap { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.up { color: var(--danger); }
.down { color: var(--accent); }

/* ===== BMI gauge ===== */
.bmi-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 4px 0 18px;
}
.bmi-head { display: flex; align-items: center; justify-content: space-between; }
.bmi-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); font-weight: 600; }
.bmi-cat-badge {
  font-size: 0.75rem; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  background: var(--border); color: var(--muted);
}
.bmi-cat-badge.under  { background: rgba(96, 165, 250, 0.18); color: #60a5fa; }
.bmi-cat-badge.normal { background: rgba(74, 222, 128, 0.18); color: var(--accent); }
.bmi-cat-badge.over   { background: rgba(245, 158, 11, 0.18); color: var(--warn); }
.bmi-cat-badge.obese  { background: rgba(248, 113, 113, 0.18); color: var(--danger); }

.bmi-num { font-size: 2.2rem; font-weight: 800; line-height: 1.1; margin: 6px 0 14px; letter-spacing: -1px; }

.bmi-scale { position: relative; display: flex; height: 8px; border-radius: 6px; overflow: hidden; }
.bmi-zone { height: 100%; }
.bmi-zone.under  { width: 14%; background: #60a5fa; }
.bmi-zone.normal { width: 26%; background: var(--accent); }
.bmi-zone.over   { width: 20%; background: var(--warn); }
.bmi-zone.obese  { width: 40%; background: var(--danger); }
.bmi-marker {
  position: absolute; top: 50%; left: 0;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 2px solid var(--bg);
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
  transition: left 0.4s ease;
  display: none;
}
.bmi-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 0.72rem; color: var(--muted); }
.bmi-legend span { display: inline-flex; align-items: center; gap: 5px; }
.bmi-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-under  { background: #60a5fa; }
.dot-normal { background: var(--accent); }
.dot-over   { background: var(--warn); }
.dot-obese  { background: var(--danger); }

/* ===== Charts ===== */
.chart-wrap { position: relative; }
#weightChart { width: 100%; height: 180px; display: block; }
#weightChart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; }
#weightChart .area { fill: rgba(74, 222, 128, 0.12); }
#weightChart .dot { fill: var(--accent); }
#weightChart .grid { stroke: var(--border); stroke-width: 1; }

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

/* ===== Auth screen ===== */
.auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(700px 420px at 25% 10%, rgba(74, 222, 128, 0.18), transparent 60%),
    radial-gradient(700px 420px at 80% 90%, rgba(167, 139, 250, 0.18), transparent 60%),
    radial-gradient(900px 500px at 50% -10%, #16223a, var(--bg));
}
.auth-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: linear-gradient(160deg, var(--surface), rgba(23, 29, 46, 0.85));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.auth-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: var(--grad-brand);
}
.auth-brand { display: flex; align-items: center; gap: 10px; justify-content: center; }
.auth-brand h1 {
  font-size: 1.4rem; font-weight: 800;
  background: var(--grad-brand);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.auth-tagline { text-align: center; color: var(--muted); font-size: 0.9rem; margin: 8px 0 22px; }

.auth-tabs { display: flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 18px; }
.auth-tab {
  flex: 1; background: transparent; color: var(--muted);
  padding: 9px; font-weight: 600; border-radius: 7px;
}
.auth-tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.3); }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input { width: 100%; }
.wide { width: 100%; padding: 12px; }
.auth-error { color: var(--danger); font-size: 0.85rem; min-height: 1em; text-align: center; }
.auth-note { color: var(--muted); font-size: 0.75rem; text-align: center; margin-top: 18px; }

/* ===== User chip ===== */
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--grad-violet); color: #1a0b2e;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.95rem;
  box-shadow: 0 2px 10px rgba(167, 139, 250, 0.4);
}
#userName { font-weight: 600; font-size: 0.9rem; }

/* ===== Analytics ===== */
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-head h2 { margin-bottom: 0; }
.range-toggle { display: flex; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.range-toggle button { background: transparent; color: var(--muted); padding: 6px 12px; font-size: 0.8rem; font-weight: 600; }
.range-toggle button.active { background: var(--surface); color: var(--text); }

.sub { font-size: 0.9rem; font-weight: 600; color: var(--text); margin: 22px 0 10px; }
.muted-inline { color: var(--muted); font-weight: 400; font-size: 0.78rem; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat-tile {
  position: relative; background: var(--surface-2); border-radius: 11px; padding: 14px;
  border: 1px solid var(--border); overflow: hidden;
}
.stat-tile::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--grad-brand); }
.stat-tile:nth-child(3n+1)::before { background: linear-gradient(180deg, #4ade80, #22c55e); }
.stat-tile:nth-child(3n+2)::before { background: linear-gradient(180deg, #38bdf8, #60a5fa); }
.stat-tile:nth-child(3n+3)::before { background: linear-gradient(180deg, #a78bfa, #f472b6); }
.stat-tile-val { font-size: 1.5rem; font-weight: 700; }
.stat-tile-unit { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.stat-tile-lbl { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-top: 4px; }

#calorieChart, #weightTrendChart { width: 100%; height: 220px; display: block; }
.bar { fill: var(--cyan); }
.bar.over { fill: var(--pink); }
.goal-line { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.goal-text { fill: var(--muted); }
.axis { fill: var(--muted); font-size: 10px; }
.ma-line { fill: none; stroke: #facc15; stroke-width: 2; stroke-dasharray: 5 4; }

/* ===== Settings ===== */
.settings-form { display: flex; flex-direction: column; gap: 18px; }
.settings-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.settings-grid .field input { width: 100%; }
.settings-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.danger-zone {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-top: 20px; padding: 16px; flex-wrap: wrap;
  border: 1px solid rgba(248, 113, 113, 0.35); border-radius: var(--radius);
  background: rgba(248, 113, 113, 0.05);
}
.danger-title { font-weight: 600; font-size: 0.95rem; }
.danger-desc { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }

/* ===== Responsive ===== */
@media (max-width: 760px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .columns { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; }
  .date-nav { justify-content: center; }
  .user-chip { justify-content: center; }
  main { padding: 18px; }
  .tabbar { padding: 12px 18px 0; }
}

@media (max-width: 420px) {
  .cards { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr; }
}

/* ===== Welcome toast ===== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 32px);
  padding: 12px 14px 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  transform: translateX(-50%) translateY(-12px);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.hidden { display: none; }
.toast.error { border-left-color: var(--danger); }
.toast-ico { font-size: 1.2rem; }
.toast-text { font-size: 0.92rem; font-weight: 600; }
.toast-close {
  margin-left: 4px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.toast-close:hover { color: var(--text); }
