:root {
  --bg: #0f1410;
  --surface: #1a221b;
  --surface2: #232d24;
  --text: #eef3ee;
  --muted: #93a595;
  --accent: #8fd460;
  --accent-dark: #5da437;
  --protein: #6ec6ff;
  --carbs: #ffd166;
  --fat: #ff8fa3;
  --danger: #ff6b6b;
  --radius: 18px;
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 84px;
}

h1, h2, h3, .date-label, .ring-value { font-family: 'Sora', sans-serif; }
h3 { margin-bottom: 12px; font-size: 1rem; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .85rem; }
.pad { padding: 12px; }

.view { display: none; }
.view.active { display: block; }

/* ---------- Auth ---------- */
#view-auth.active {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.logo-ring {
  width: 84px; height: 84px; margin: 0 auto 16px;
  border: 4px solid var(--accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Sora', sans-serif; font-weight: 800; font-size: 1.2rem;
  color: var(--accent);
}
.auth-card h1 { margin-bottom: 4px; }
.auth-card form { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- Inputs & Buttons ---------- */
input, select {
  width: 100%; padding: 13px 14px;
  background: var(--surface2); color: var(--text);
  border: 1px solid #33402f; border-radius: 12px;
  font-size: 1rem; font-family: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
label input { margin-top: 4px; }

.btn {
  padding: 13px 18px; border: none; border-radius: 12px;
  font-size: 1rem; font-weight: 600; font-family: inherit;
  cursor: pointer; width: 100%;
}
.btn.primary { background: var(--accent); color: #10240a; }
.btn.primary:active { background: var(--accent-dark); }
.btn.ghost { background: var(--surface2); color: var(--text); }
.btn.link { background: none; color: var(--accent); margin-top: 12px; font-size: .9rem; }
.btn.danger { background: var(--danger); color: #fff; margin-top: 12px; }
.icon-btn {
  background: var(--surface2); border: none; color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; font-size: 1.3rem; cursor: pointer;
}

.alert {
  background: #3a1f22; color: #ffb3b3; border-radius: 10px;
  padding: 10px; font-size: .85rem; margin-bottom: 10px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; position: sticky; top: 0;
  background: rgba(15,20,16,.92); backdrop-filter: blur(8px); z-index: 5;
}
.date-label { font-weight: 600; font-size: 1.05rem; cursor: pointer; }

/* ---------- Kalorien-Ring ---------- */
.ring-section { padding: 8px 16px 16px; }
.cal-ring { position: relative; width: 190px; margin: 0 auto; }
.cal-ring svg { width: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--surface2); stroke-width: 10; }
.ring-fg {
  fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 326.7; stroke-dashoffset: 326.7;
  transition: stroke-dashoffset .6s ease;
}
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.ring-value { font-size: 2rem; font-weight: 800; }
.ring-sub { color: var(--muted); font-size: .8rem; }

.macro-row { display: flex; gap: 10px; margin-top: 14px; }
.macro { flex: 1; text-align: center; }
.m-label { font-size: .72rem; color: var(--muted); }
.m-bar {
  height: 6px; background: var(--surface2); border-radius: 3px;
  margin: 5px 0; overflow: hidden;
}
.m-bar div { height: 100%; width: 0; border-radius: 3px; transition: width .4s; }
#bar-protein { background: var(--protein); }
#bar-carbs { background: var(--carbs); }
#bar-fat { background: var(--fat); }
.m-val { font-size: .72rem; }

/* ---------- Mahlzeiten ---------- */
.meal-block {
  background: var(--surface); border-radius: var(--radius);
  margin: 0 12px 12px; padding: 14px;
}
.meal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.meal-head h3 { margin: 0; font-size: .95rem; }
.meal-kcal { color: var(--accent); font-weight: 600; font-size: .9rem; }
.entry-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-top: 1px solid #2a352b; gap: 8px;
}
.entry-name { flex: 1; font-size: .92rem; }
.entry-detail { color: var(--muted); font-size: .78rem; }
.entry-kcal { font-size: .88rem; white-space: nowrap; }
.entry-del { background: none; border: none; color: var(--muted); font-size: 1rem; cursor: pointer; }

/* ---------- Cards / Stats ---------- */
.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.stats-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.stats-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 4px; }
.stats-table td { padding: 6px 4px; border-top: 1px solid #2a352b; }

.seg-control { display: flex; background: var(--surface2); border-radius: 12px; padding: 3px; margin: 0 auto; }
.seg {
  border: none; background: none; color: var(--muted);
  padding: 8px 18px; border-radius: 10px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.seg.active { background: var(--accent); color: #10240a; }

/* ---------- Sheet ---------- */
.sheet {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20;
  display: flex; align-items: flex-end;
}
.sheet-inner {
  background: var(--surface); width: 100%; max-height: 88vh; overflow-y: auto;
  border-radius: 22px 22px 0 0; padding: 12px 16px 24px;
  display: flex; flex-direction: column; gap: 10px;
}
.sheet-handle { width: 42px; height: 4px; background: #3a473b; border-radius: 2px; margin: 0 auto 4px; }
.add-tabs { display: flex; gap: 6px; }
.add-tab {
  flex: 1; padding: 9px 4px; border: none; border-radius: 10px;
  background: var(--surface2); color: var(--muted); font-weight: 600;
  font-size: .8rem; cursor: pointer; font-family: inherit;
}
.add-tab.active { background: var(--accent); color: #10240a; }
.tab-panel { display: none; flex-direction: column; gap: 10px; }
.tab-panel.active { display: flex; }
.row2 { display: flex; gap: 8px; }
.row2 > * { flex: 1; }
.row3 { display: flex; gap: 8px; }
.row3 > * { flex: 1; }

.photo-drop {
  border: 2px dashed #3a473b; border-radius: 14px; padding: 28px;
  text-align: center; color: var(--muted); cursor: pointer; display: block;
}
#barcode-video { width: 100%; border-radius: 14px; background: #000; min-height: 200px; }

.result-item {
  background: var(--surface2); border-radius: 12px; padding: 10px 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  margin-bottom: 6px; cursor: pointer;
}
.result-item small { color: var(--muted); display: block; }
.result-add { color: var(--accent); font-size: 1.3rem; font-weight: 700; }

/* ---------- Freunde ---------- */
.friend-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-top: 1px solid #2a352b; gap: 8px; flex-wrap: wrap;
}
.share-toggles { display: flex; gap: 4px; flex-wrap: wrap; }
.share-chip {
  border: 1px solid #3a473b; background: none; color: var(--muted);
  border-radius: 999px; padding: 4px 10px; font-size: .72rem; cursor: pointer; font-family: inherit;
}
.share-chip.on { background: var(--accent); color: #10240a; border-color: var(--accent); }
.small-btn {
  border: none; background: var(--surface2); color: var(--text);
  border-radius: 10px; padding: 7px 12px; font-size: .8rem; cursor: pointer; font-family: inherit;
}
.small-btn.acc { background: var(--accent); color: #10240a; }

/* ---------- Bottom Nav ---------- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-around;
  background: rgba(20,27,21,.97); backdrop-filter: blur(10px);
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid #232d24;
}
.nav-item {
  background: none; border: none; color: var(--muted);
  font-size: .68rem; display: flex; flex-direction: column; align-items: center; gap: 2px;
  cursor: pointer; font-family: inherit; min-width: 62px;
}
.nav-item span { font-size: 1.25rem; }
.nav-item.active { color: var(--accent); }
.nav-fab {
  width: 54px; height: 54px; border-radius: 50%; border: none;
  background: var(--accent); color: #10240a; font-size: 1.7rem; font-weight: 700;
  cursor: pointer; margin-top: -22px; box-shadow: 0 4px 14px rgba(143,212,96,.35);
}

@media (min-width: 760px) {
  .view.active:not(#view-auth) { max-width: 640px; margin: 0 auto; }
  .bottomnav { max-width: 640px; margin: 0 auto; border-radius: 18px 18px 0 0; }
}
