:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #252836;
  --border: #2e3347;
  --text: #e8eaf0;
  --text2: #8b90a7;
  --accent: #4f9cf9;
  --green: #22c55e;
  --orange: #f97316;
  --red: #ef4444;
  --protein: #a78bfa;
  --carbs: #facc15;
  --fat: #fb923c;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: 100px;
}

/* Header */
.header {
  background: var(--bg2);
  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 h1 { font-size: 18px; font-weight: 700; }
.header-nav { display: flex; gap: 8px; align-items: center; }
.nav-btn {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  text-decoration: none;
  display: flex;
  align-items: center;
}
.nav-btn:hover { background: var(--bg3); color: var(--text); }
.nav-btn.active { color: var(--accent); }

/* Cards */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 12px 16px;
}

/* Calorie ring */
.ring-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}
.ring-wrap { position: relative; width: 160px; height: 160px; }
.progress-ring { transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--bg3); stroke-width: 12; }
.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 12;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s ease;
}
.ring-progress.over { stroke: var(--red); }
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-kcal { font-size: 28px; font-weight: 800; }
.ring-label { font-size: 12px; color: var(--text2); }

/* Macro bars */
.macros { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.macro-row { display: flex; align-items: center; gap: 10px; }
.macro-label { font-size: 13px; color: var(--text2); width: 90px; }
.macro-bar-wrap { flex: 1; background: var(--bg3); border-radius: 99px; height: 8px; }
.macro-bar {
  height: 8px;
  border-radius: 99px;
  transition: width 0.6s ease;
  max-width: 100%;
}
.macro-bar.protein { background: var(--protein); }
.macro-bar.carbs { background: var(--carbs); }
.macro-bar.fat { background: var(--fat); }
.macro-val { font-size: 12px; color: var(--text2); width: 70px; text-align: right; }

/* Entries */
.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 16px 20px 4px;
}
.entry-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.entry-card:hover { background: var(--bg3); }
.entry-thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg3);
}
.entry-thumb-placeholder {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.entry-info { flex: 1; min-width: 0; }
.entry-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entry-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }
.entry-kcal { font-size: 18px; font-weight: 700; color: var(--accent); flex-shrink: 0; }

/* Empty state */
.empty {
  text-align: center;
  color: var(--text2);
  padding: 48px 20px;
  font-size: 15px;
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* FAB */
.fab {
  position: fixed;
  bottom: 24px;
  right: 50%;
  transform: translateX(50%);
  max-width: calc(480px - 48px);
  width: calc(100% - 48px);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 16px;
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(79,156,249,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.1s, box-shadow 0.1s;
  z-index: 99;
}
.fab:active { transform: translateX(50%) scale(0.97); }

/* Modal overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  padding: 20px 20px 40px;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  max-height: 90vh;
  overflow-y: auto;
}
.overlay.open .modal { transform: translateY(0); }

.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  margin: 0 auto 20px;
}
.modal-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
}
.modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: var(--bg3);
  border: none;
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Buttons */
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--red); color: #fff; }
.btn-outline {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s;
}
.btn-outline:hover { background: var(--bg3); }

/* Form elements */
.form-group { margin-bottom: 16px; }
.form-label { font-size: 13px; color: var(--text2); margin-bottom: 6px; display: block; }
.form-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--accent); }
textarea.form-input { resize: vertical; min-height: 80px; }

/* Chip buttons (meal type) */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.chip {
  padding: 8px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.chip.active { border-color: var(--accent); background: rgba(79,156,249,0.15); color: var(--accent); }

/* Analysis result */
.analysis-photo {
  width: 100%;
  border-radius: 10px;
  max-height: 240px;
  object-fit: cover;
  margin-bottom: 16px;
}
.analysis-desc {
  font-size: 14px;
  color: var(--text2);
  margin-bottom: 16px;
  line-height: 1.5;
}
.macro-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.macro-input-group label { font-size: 12px; color: var(--text2); display: block; margin-bottom: 4px; }
.macro-input-group input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 16px;
  font-weight: 600;
  outline: none;
}
.macro-input-group input:focus { border-color: var(--accent); }

.confidence-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
}
.confidence-hoch { background: rgba(34,197,94,0.15); color: var(--green); }
.confidence-mittel { background: rgba(249,115,22,0.15); color: var(--orange); }
.confidence-niedrig { background: rgba(239,68,68,0.15); color: var(--red); }

.questions-box {
  background: rgba(249,115,22,0.08);
  border: 1px solid rgba(249,115,22,0.3);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
}
.questions-title { font-size: 13px; font-weight: 700; color: var(--orange); margin-bottom: 8px; }
.questions-list { list-style: disc; padding-left: 16px; font-size: 13px; color: var(--text2); line-height: 1.8; }

/* Spinner */
.spinner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 15px;
  color: var(--text);
  display: none;
}
.spinner-overlay.show { display: flex; }
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--bg3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Buttons row */
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row .btn { flex: 1; }

/* History */
.history-day {
  margin: 8px 16px;
}
.history-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0 6px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.history-day-date { font-size: 14px; font-weight: 600; }
.history-day-kcal { font-size: 14px; color: var(--accent); font-weight: 700; }
.history-entries { display: none; }
.history-entries.open { display: block; }

/* Settings */
.settings-section { margin: 16px 16px 0; }
.settings-section h2 { font-size: 16px; font-weight: 700; margin-bottom: 12px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 400;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; }
