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

:root {
  --bg: #f5f5f5;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #666666;
  --border: #e0e0e0;
  --green: #34a853;
  --yellow: #fbbc04;
  --red: #ea4335;
  --blue: #4285f4;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 32px;
}

/* ── Header ── */
header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-date {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-date h1 { font-size: 18px; font-weight: 700; }
.header-date span { color: var(--muted); font-size: 14px; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  padding: 6px;
  border-radius: 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:active { background: var(--bg); }

/* ── Cards ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 12px 16px 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* ── Progress ── */
.calories-main {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 12px;
}

.calories-now { font-size: 32px; font-weight: 800; }
.calories-goal { color: var(--muted); font-size: 16px; }
.calories-unit { color: var(--muted); font-size: 14px; }

.calories-diff {
  font-size: 13px;
  margin-bottom: 14px;
  padding: 4px 10px;
  border-radius: 20px;
  display: inline-block;
}

.calories-diff.under  { background: #fff8e1; color: #f57f17; }
.calories-diff.ok     { background: #e8f5e9; color: #2e7d32; }
.calories-diff.over   { background: #ffebee; color: #c62828; }

.nutrient-rows { display: flex; flex-direction: column; gap: 8px; }

.nutrient-row {
  display: grid;
  grid-template-columns: 44px 1fr 60px;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.nutrient-label { color: var(--muted); }
.nutrient-val { text-align: right; color: var(--muted); font-size: 12px; }

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.fill-yellow { background: var(--yellow); }
.fill-green  { background: var(--green); }
.fill-red    { background: var(--red); }

/* ── Action buttons ── */
.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  min-height: 76px;
  transition: border-color 0.15s, background 0.15s;
}

.btn-action:active { background: #e8e8e8; }
.btn-action .icon { font-size: 26px; }

/* ── Settings panel ── */
.settings-panel {
  display: none;
  border: 2px solid var(--blue);
}
.settings-panel.active { display: block; }

/* ── Input panel ── */
.input-panel {
  display: none;
}

.input-panel.active {
  display: block;
}

textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  height: 90px;
  outline: none;
}

textarea:focus { border-color: var(--blue); }

.photo-upload-area {
  border: 2px dashed var(--border);
  border-radius: 8px;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  position: relative;
}

.photo-upload-area img {
  max-width: 100%;
  max-height: 260px;
  border-radius: 6px;
  object-fit: contain;
}

.photo-upload-area input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

.panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn-submit {
  flex: 1;
  padding: 14px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
}

.btn-submit:disabled { background: #aaa; cursor: default; }

.btn-cancel {
  padding: 14px 20px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
  min-height: 48px;
}

/* ── Result panel ── */
.result-panel { display: none; }
.result-panel.active { display: block; }

.result-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}

.result-note {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

.nutrient-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.nutrient-input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nutrient-input-group label {
  font-size: 12px;
  color: var(--muted);
}

.nutrient-input-group input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  width: 100%;
}

.nutrient-input-group input:focus { border-color: var(--blue); }

.calories-input-group {
  grid-column: 1 / -1;
}

.calories-input-group input { font-size: 20px; font-weight: 700; }

.btn-add {
  width: 100%;
  padding: 16px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
}

/* ── Meal list ── */
.section-title {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 16px 20px 4px;
}

.meal-list { display: flex; flex-direction: column; gap: 0; }

.meal-item {
  background: var(--card);
  margin: 0 16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.meal-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.meal-item:last-child  { border-radius: 0 0 var(--radius) var(--radius); border-bottom: none; }
.meal-item:only-child  { border-radius: var(--radius); border-bottom: none; }

.meal-time { font-size: 13px; color: var(--muted); min-width: 38px; }

.meal-info { flex: 1; }
.meal-name { font-size: 15px; font-weight: 600; }
.meal-macros { font-size: 12px; color: var(--muted); margin-top: 2px; }

.meal-cal { font-size: 15px; font-weight: 700; color: var(--text); }

.meal-delete {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--muted);
  padding: 4px 8px;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 32px 20px;
  font-size: 14px;
}

/* ── Loading / Toast ── */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: #fff;
  font-size: 15px;
}

.loading-overlay.active { display: flex; }

.spinner {
  width: 40px; height: 40px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #333;
  color: #fff;
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 300;
  white-space: nowrap;
  max-width: 90vw;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error { background: var(--red); }
.toast.success { background: var(--green); }

/* ── Water ── */
.fill-blue { background: #4285f4; }
.btn-water { border-color: #4285f4 !important; color: #4285f4 !important; }
.water-item { background: #f0f4ff; }

/* ── Meal thumbnail ── */
.meal-thumb {
  width: 52px; height: 52px;
  border-radius: 8px;
  object-fit: cover;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.meal-thumb:active { opacity: 0.7; }

/* ── Lightbox ── */
.lightbox {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,0.88);
}
.lightbox-img {
  position: relative; max-width: 95vw; max-height: 90vh;
  border-radius: 10px; object-fit: contain;
}

/* ── Settings modal ── */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,0.5);
  align-items: flex-end; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal-card {
  background: #fff; border-radius: 20px 20px 0 0;
  padding: 24px 20px 36px; width: 100%; max-width: 480px;
}
