/* ===== Reset & Variables ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #ff6b35;
  --primary-light: #fff3ee;
  --secondary:     #4caf76;
  --danger:        #e74c3c;
  --blue:          #3b82f6;
  --bg:            #f7f8fc;
  --card:          #ffffff;
  --text:          #2d2d2d;
  --muted:         #888;
  --border:        #e8e8e8;
  --radius:        14px;
  --shadow:        0 4px 20px rgba(0,0,0,0.07);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 14px 80px;
}

/* ===== Header ===== */
.header { text-align: center; padding: 28px 0 16px; }
.header h1 { font-size: 1.9rem; font-weight: 700; color: var(--primary); }
.subtitle { color: var(--muted); margin-top: 5px; font-size: 0.88rem; }

/* ===== Date Nav ===== */
.date-nav {
  display: flex; align-items: center; justify-content: center;
  gap: 16px; margin-bottom: 16px;
}
.nav-btn {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 50%; width: 38px; height: 38px;
  font-size: 1rem; cursor: pointer; transition: background .15s;
  display: flex; align-items: center; justify-content: center;
}
.nav-btn:hover { background: var(--primary-light); }
.date-display { display: flex; flex-direction: column; align-items: center; gap: 3px; }
#datePicker {
  border: none; background: transparent; font-size: 1rem;
  color: var(--text); cursor: pointer; text-align: center; outline: none;
}
#dateLabel { font-size: 0.8rem; color: var(--muted); }

/* ===== Tabs ===== */
.tab-bar {
  display: flex; gap: 6px; margin-bottom: 18px;
  background: var(--card); border-radius: var(--radius);
  padding: 6px; box-shadow: var(--shadow);
}
.tab {
  flex: 1; padding: 10px 4px; border: none; border-radius: 10px;
  font-size: 0.85rem; font-weight: 500; cursor: pointer;
  background: transparent; color: var(--muted); transition: all .2s;
}
.tab.active { background: var(--primary); color: #fff; }
.tab:not(.active):hover { background: var(--primary-light); color: var(--primary); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== Card ===== */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
}
.card h2 { font-size: 0.98rem; font-weight: 600; margin-bottom: 16px; }

/* ===== Summary Card ===== */
.summary-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; justify-content: space-around;
  padding: 22px 14px; margin-bottom: 14px;
}
.summary-item { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.summary-value { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.summary-label { font-size: 0.74rem; color: var(--muted); text-align: center; }
.summary-divider { width: 1px; background: var(--border); align-self: stretch; }

/* ===== Progress ===== */
.progress-section {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 14px;
}
.progress-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.86rem; color: var(--muted); margin-bottom: 10px;
}
.goal-btn {
  background: none; border: 1px solid var(--primary);
  color: var(--primary); border-radius: 20px;
  padding: 3px 12px; font-size: 0.76rem; cursor: pointer;
  transition: background .15s;
}
.goal-btn:hover { background: var(--primary-light); }
.progress-bar-wrap {
  background: #f0f0f0; border-radius: 99px; height: 11px; overflow: hidden;
}
.progress-bar {
  height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--secondary), var(--primary));
  width: 0%; transition: width .5s ease;
}
.progress-bar.over { background: linear-gradient(90deg, var(--primary), var(--danger)); }
.progress-percent { text-align: right; font-size: 0.76rem; color: var(--muted); margin-top: 4px; }

/* ===== Form ===== */
.add-form, .weight-form { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-group { flex: 1; min-width: 120px; display: flex; flex-direction: column; gap: 5px; }
.form-group--s { flex: 0 0 118px; min-width: 100px; }
label { font-size: 0.78rem; color: var(--muted); font-weight: 500; }

input[type="text"],
input[type="number"],
select {
  padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: 10px; font-size: 0.9rem; color: var(--text);
  background: #fafafa; outline: none; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255,107,53,.1);
  background: #fff;
}

/* ===== Suggestions ===== */
.suggestions {
  position: absolute; top: calc(100% + 2px); left: 0; right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.10); z-index: 200;
  max-height: 200px; overflow-y: auto; display: none;
}
.suggestions.open { display: block; }
.suggestion-item {
  padding: 10px 14px; cursor: pointer; font-size: 0.86rem;
  display: flex; justify-content: space-between; align-items: center;
  transition: background .1s;
}
.suggestion-item:hover { background: var(--primary-light); }
.sug-kcal { font-size: 0.76rem; color: var(--primary); font-weight: 600; }

/* ===== Image Upload ===== */
.upload-area {
  border: 2px dashed var(--border); border-radius: 12px;
  padding: 20px; text-align: center; cursor: pointer;
  transition: border-color .2s, background .2s; position: relative;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--primary); background: var(--primary-light);
}
.upload-placeholder { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.upload-icon { font-size: 2rem; }
.upload-placeholder span:last-child { font-size: 0.84rem; color: var(--muted); }
.preview-img {
  max-width: 100%; max-height: 200px; border-radius: 10px;
  object-fit: cover; display: block; margin: 0 auto;
}
.remove-img-btn {
  margin-top: 8px; background: none; border: 1px solid var(--danger);
  color: var(--danger); border-radius: 8px; padding: 4px 14px;
  font-size: 0.8rem; cursor: pointer; transition: background .15s;
}
.remove-img-btn:hover { background: #fdf0f0; }

/* ===== Buttons ===== */
.add-btn {
  background: var(--primary); color: #fff; border: none;
  border-radius: 12px; padding: 13px; font-size: 0.95rem;
  font-weight: 600; cursor: pointer; transition: opacity .15s, transform .1s;
}
.add-btn:hover { opacity: .9; transform: translateY(-1px); }
.add-btn:active { transform: translateY(0); }

/* ===== Food List ===== */
.meal-group { margin-bottom: 14px; }
.meal-group-title {
  font-size: 0.8rem; font-weight: 600; color: var(--muted);
  padding: 4px 0 7px; border-bottom: 1px solid var(--border); margin-bottom: 6px;
}
.food-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 4px; border-radius: 8px; transition: background .1s;
}
.food-item:hover { background: var(--bg); }
.food-thumb {
  width: 46px; height: 46px; border-radius: 8px; object-fit: cover;
  cursor: pointer; flex-shrink: 0; border: 1px solid var(--border);
}
.food-thumb-placeholder {
  width: 46px; height: 46px; border-radius: 8px; background: #f0f0f0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
}
.food-info { flex: 1; min-width: 0; }
.food-name { font-size: 0.9rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.food-meta { font-size: 0.74rem; color: var(--muted); margin-top: 2px; }
.food-cal { font-size: 0.93rem; font-weight: 700; color: var(--primary); flex-shrink: 0; }
.food-del {
  background: none; border: none; color: #ccc; cursor: pointer;
  font-size: 1rem; padding: 4px; border-radius: 6px; transition: color .15s;
}
.food-del:hover { color: var(--danger); }

/* ===== Weight ===== */
.weight-period-btns { display: flex; gap: 10px; }
.period-btn {
  flex: 1; padding: 10px; border: 1.5px solid var(--border);
  border-radius: 10px; font-size: 0.88rem; cursor: pointer;
  background: #fafafa; color: var(--muted); font-weight: 500;
  transition: all .15s;
}
.period-btn.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}

.weight-record {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.weight-record:last-child { border-bottom: none; }
.weight-period-tag {
  font-size: 0.8rem; padding: 3px 10px; border-radius: 20px;
  background: var(--primary-light); color: var(--primary); font-weight: 600;
}
.weight-val { font-size: 1.4rem; font-weight: 700; color: var(--text); }
.weight-note { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }
.weight-del {
  background: none; border: none; color: #ccc; cursor: pointer;
  font-size: 1rem; padding: 4px;
}
.weight-del:hover { color: var(--danger); }

/* ===== History ===== */
.history-day {
  border: 1px solid var(--border); border-radius: 12px;
  margin-bottom: 10px; overflow: hidden;
}
.history-day-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--bg); cursor: pointer;
  user-select: none; font-size: 0.88rem; gap: 10px;
}
.history-day-header:hover { background: var(--primary-light); }
.history-day-info { flex: 1; }
.history-day-date { font-weight: 600; }
.history-day-meta { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }
.history-day-cal { font-weight: 700; color: var(--primary); white-space: nowrap; }
.history-chevron { color: var(--muted); font-size: 0.8rem; transition: transform .2s; }
.history-day-header.open .history-chevron { transform: rotate(180deg); }
.history-day-body { display: none; padding: 8px 14px 12px; }
.history-day-body.open { display: block; }
.history-food-row {
  display: flex; justify-content: space-between;
  font-size: 0.82rem; padding: 5px 0; color: var(--muted);
  border-bottom: 1px dashed var(--border);
}
.history-food-row:last-child { border-bottom: none; }
.history-food-cal { color: var(--primary); font-weight: 600; }
.history-weight-row {
  display: flex; gap: 14px; padding: 6px 0;
  font-size: 0.82rem; color: var(--muted);
}
.history-weight-tag {
  background: var(--primary-light); color: var(--primary);
  border-radius: 10px; padding: 1px 8px; font-size: 0.76rem;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center; padding: 36px 0; color: var(--muted); display: none;
}
.empty-state span { font-size: 2.6rem; display: block; margin-bottom: 8px; }
.empty-state p { font-size: 0.86rem; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: #fff; border-radius: 18px; padding: 26px 22px;
  width: 90%; max-width: 360px;
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
  transform: translateY(10px); transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal--img { max-width: 90vw; max-height: 90vh; padding: 14px; text-align: center; }
.modal--img img { max-width: 100%; max-height: 75vh; border-radius: 12px; object-fit: contain; }
.modal h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 16px; }
.modal input { width: 100%; margin-bottom: 18px; }
.modal-btns { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }
.modal-cancel {
  background: #f0f0f0; border: none; border-radius: 10px;
  padding: 10px 20px; font-size: 0.88rem; cursor: pointer;
}
.modal-cancel:hover { background: #e4e4e4; }
.modal-confirm {
  background: var(--primary); border: none; border-radius: 10px;
  padding: 10px 20px; font-size: 0.88rem; cursor: pointer;
  color: #fff; font-weight: 600;
}
.modal-confirm:hover { opacity: .88; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: #2d2d2d; color: #fff;
  padding: 11px 22px; border-radius: 99px;
  font-size: 0.86rem; z-index: 2000;
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .form-group--s { flex: 1 1 100px; }
  .summary-value { font-size: 1.4rem; }
  .tab { font-size: 0.78rem; padding: 9px 2px; }
}
