/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  --text-primary: #1c1917;
  --text-secondary: #78716c;
  --text-muted: #a8a29e;
  --brand: #2563eb;
  --brand-light: #eff6ff;
  --brand-hover: #1d4ed8;
  --ok: #16a34a;
  --ok-light: #f0fdf4;
  --warn: #ea580c;
  --warn-light: #fff7ed;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --nav-h: 60px;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Yu Gothic UI', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100dvh;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; border: none; background: none; }
input, textarea, select { font: inherit; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app_main {
  flex: 1;
  padding-bottom: calc(var(--nav-h) + 8px);
  overflow-y: auto;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ── Bottom Navigation ─────────────────────────────────────────────────────── */
.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  z-index: 100;
}

.nav_item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  padding: 6px 4px 8px;
  transition: color .15s;
}

.nav_item svg { width: 22px; height: 22px; }

.nav_item.is-active {
  color: var(--brand);
}

.nav_item:active { opacity: .7; }

/* ── Page Header ───────────────────────────────────────────────────────────── */
.page_header {
  padding: 20px 16px 12px;
  max-width: 640px;
  margin: 0 auto;
}

.page_title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.page_subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── Card ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card_header {
  padding: 14px 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card_title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.card_body {
  padding: 12px 16px 16px;
}

/* ── Summary Card ──────────────────────────────────────────────────────────── */
.summary_section {
  padding: 0 16px 12px;
  max-width: 640px;
  margin: 0 auto;
}

.summary_card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.summary_date {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: .04em;
  margin-bottom: 10px;
}

.summary_calorie {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 6px;
}

.summary_calorie_value {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1;
}

.summary_calorie_unit {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.summary_calorie_goal {
  font-size: 13px;
  color: var(--text-secondary);
  margin-left: auto;
}

/* ── Progress Bar ──────────────────────────────────────────────────────────── */
.progress {
  margin: 8px 0 14px;
}

.progress_bar {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress_bar_fill {
  height: 100%;
  border-radius: 99px;
  background: var(--brand);
  transition: width .3s ease;
  max-width: 100%;
}

.progress_bar_fill.is-ok   { background: var(--ok); }
.progress_bar_fill.is-warn { background: var(--warn); }
.progress_bar_fill.is-high { background: var(--danger); }

/* ── Nutrient Grid ─────────────────────────────────────────────────────────── */
.nutrient_grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.nutrient_item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  text-align: center;
}

.nutrient_item_label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: .03em;
  margin-bottom: 2px;
}

.nutrient_item_value {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.nutrient_item_diff {
  font-size: 11px;
  font-weight: 600;
  margin-top: 1px;
}

.nutrient_item_diff.is-ok   { color: var(--ok); }
.nutrient_item_diff.is-warn { color: var(--warn); }
.nutrient_item_diff.is-high { color: var(--danger); }

/* ── Day Section ───────────────────────────────────────────────────────────── */
.day_section {
  padding: 0 16px 16px;
  max-width: 640px;
  margin: 0 auto;
}

.day_section_header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.day_section_label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.day_section_total {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ── Log List ──────────────────────────────────────────────────────────────── */
.log_list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.log_list_empty {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  box-shadow: var(--shadow);
}

.log_item {
  background: var(--surface);
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 10px;
}

.log_item_time {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  min-width: 36px;
  flex-shrink: 0;
}

.log_item_name {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log_item_name_empty {
  color: var(--text-muted);
  font-style: italic;
}

.log_item_cal {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  flex-shrink: 0;
}

.log_item_cal_unit {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
}

.log_item_actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: background .15s, opacity .15s;
}

.btn--primary {
  background: var(--brand);
  color: #fff;
}
.btn--primary:hover { background: var(--brand-hover); }
.btn--primary:active { opacity: .85; }

.btn--secondary {
  background: var(--bg);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}
.btn--secondary:hover { background: var(--border); }

.btn--danger {
  background: var(--danger-light);
  color: var(--danger);
}
.btn--danger:hover { background: #fee2e2; }

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 6px;
  border-radius: 6px;
}
.btn--ghost:hover { background: var(--bg); color: var(--text-primary); }

.btn--sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 6px;
}

.btn--full { width: 100%; }

/* ── Form ──────────────────────────────────────────────────────────────────── */
.form_group {
  margin-bottom: 14px;
}

.form_label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
  letter-spacing: .03em;
}

.form_input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 15px;
  background: var(--surface);
  color: var(--text-primary);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}

.form_input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.form_input::placeholder { color: var(--text-muted); }

textarea.form_input {
  resize: vertical;
  min-height: 90px;
  line-height: 1.5;
}

.form_row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form_hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form_error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 4px;
}

/* ── Tabs ──────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
  margin-bottom: 14px;
}

.tab_item {
  flex: 1;
  padding: 7px 10px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 6px;
  transition: background .15s, color .15s;
}

.tab_item.is-active {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

/* ── Frequent Foods Grid ───────────────────────────────────────────────────── */
.food_grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.food_card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  text-align: left;
}

.food_card:hover {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

.food_card:active { opacity: .8; }

.food_card_name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.food_card_cal {
  font-size: 13px;
  font-weight: 700;
  color: var(--brand);
}

.food_card_cal_unit {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
}

.food_card_pfc {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── Settings / Frequent Foods List ───────────────────────────────────────── */
.list_item {
  background: var(--surface);
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 10px;
}

.list_item_body { flex: 1; overflow: hidden; }

.list_item_name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list_item_sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.list_item_actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal_overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  padding: 16px;
}

.modal_overlay.is-center { align-items: center; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px;
  max-height: 90dvh;
  overflow-y: auto;
}

.modal_title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
}

.modal_actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.modal_actions .btn { flex: 1; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: #1c1917;
  color: #fff;
  padding: 10px 18px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 300;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}

.toast.is-visible { opacity: 1; }

/* ── Login Page ────────────────────────────────────────────────────────────── */
.login_page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login_card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
}

.login_title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
  margin-bottom: 6px;
}

.login_subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* ── Graph ─────────────────────────────────────────────────────────────────── */
.graph_section {
  padding: 0 16px 16px;
  max-width: 640px;
  margin: 0 auto;
}

.graph_card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.graph_toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.graph_toggle_btn {
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
  transition: all .15s;
}

.graph_toggle_btn.is-active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.graph_canvas_wrap {
  position: relative;
  height: 220px;
}

.graph_totals {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.graph_total_item {
  text-align: center;
}

.graph_total_label {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: .04em;
  display: block;
  margin-bottom: 2px;
}

.graph_total_value {
  font-size: 13px;
  font-weight: 700;
}

.graph_total_pct {
  font-size: 10px;
  color: var(--text-secondary);
}

/* ── Divider ───────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ── Utilities ─────────────────────────────────────────────────────────────── */
.text-secondary { color: var(--text-secondary); }
.text-muted     { color: var(--text-muted); }
.text-sm        { font-size: 13px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.hidden { display: none !important; }

/* ── Loading ───────────────────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (min-width: 640px) {
  .nutrient_grid { grid-template-columns: repeat(4, 1fr); }
  .food_grid { grid-template-columns: repeat(3, 1fr); }
}
