:root {
  --bg: #f9fafb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #10b981;
  --primary-dark: #059669;
  --danger: #ef4444;
  --warn: #f59e0b;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
}

button.primary {
  background: var(--primary);
  color: white;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  width: 100%;
  margin-top: 8px;
}

button.primary:active { background: var(--primary-dark); }

button.danger {
  background: var(--danger);
  color: white;
  padding: 10px 16px;
  border-radius: 8px;
  width: 100%;
  margin-top: 16px;
}

.muted { color: var(--muted); font-size: 0.875rem; }
.hidden { display: none !important; }
.msg { color: var(--danger); min-height: 1.4em; margin-top: 8px; text-align: center; }

/* ============= AUTH ============= */
#screen-auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
}
.auth-card h1 { margin: 0 0 4px; text-align: center; }
.auth-card p.muted { text-align: center; margin: 0 0 20px; }

.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; margin-bottom: 16px; }
.tab { flex: 1; padding: 8px; border-radius: 6px; font-weight: 500; color: var(--muted); }
.tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.auth-form label { display: block; margin: 10px 0 4px; font-size: 0.875rem; color: var(--muted); }
.auth-form fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 12px 0; }
.auth-form legend { padding: 0 6px; color: var(--muted); font-size: 0.875rem; }

/* ============= MAIN LAYOUT ============= */
#screen-main {
  max-width: 600px;
  margin: 0 auto;
  padding-bottom: 80px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.date-nav { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.iconbtn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.topbar-actions { display: flex; gap: 6px; }

/* ============= SUMMARY ============= */
.summary-card {
  background: var(--card);
  margin: 12px 16px;
  padding: 16px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.summary-ring {
  position: relative;
  width: 140px; height: 140px;
  margin: 0 auto 12px;
}
.summary-ring svg { width: 100%; height: 100%; }
.summary-text {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.kcal-big { font-size: 1.8rem; font-weight: 700; }
.macros { display: flex; justify-content: space-around; font-size: 0.875rem; }
.macro-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.upload-status { margin-top: 8px; font-size: 0.8rem; color: var(--muted); }

/* ============= MEALS ============= */
.meal-list { padding: 0 16px; }
.meal {
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.meal header {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; margin-bottom: 8px;
}
.meal-icon { font-size: 1.2rem; }
.meal-kcal { margin-left: auto; font-weight: 400; }
.items { list-style: none; padding: 0; margin: 0 0 6px; }
.items li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}
.items li:last-child { border-bottom: none; }
.item-name { flex: 1; }
.item-meta { color: var(--muted); font-size: 0.8rem; }
.item-del { color: var(--danger); padding: 4px 8px; font-size: 1.2rem; }
.add-item {
  width: 100%; padding: 8px;
  color: var(--primary); font-weight: 600;
  border-top: 1px dashed var(--border);
  margin-top: 4px;
}

/* ============= VIEWS ============= */
.view { padding: 16px; max-width: 600px; margin: 0 auto; }
.view h2 { margin-top: 0; }

/* ============= BOTTOM NAV ============= */
.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.navbtn {
  flex: 1;
  padding: 10px 4px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}
.navbtn.active { color: var(--primary); font-weight: 600; }

/* ============= MODAL ============= */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end;
  z-index: 100;
}
.modal-content {
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 20px;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-content h3 { margin-top: 0; }
.modal-content label { display: block; margin: 10px 0 4px; font-size: 0.875rem; color: var(--muted); }
.modal-content .row { display: flex; gap: 8px; }
.modal-content .row label { flex: 1; }
.actions { display: flex; gap: 8px; margin-top: 16px; }
.actions button { flex: 1; padding: 12px; border-radius: 8px; }
.actions .primary { margin-top: 0; }

/* ============= TOAST ============= */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.9rem;
  z-index: 200;
  animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ============= MOBILE ============= */
@media (max-width: 480px) {
  .macros { font-size: 0.8rem; }
  .meal { padding: 10px 12px; }
}