:root {
  --bg: #0e0f12;
  --card: #17191e;
  --card-2: #1e2127;
  --border: #262a32;
  --text: #f2f3f5;
  --muted: #8b909a;
  --accent: #4ade80;
  --p: #60a5fa;
  --c: #fbbf24;
  --f: #f472b6;
  --danger: #f43f5e;
  --radius: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }

/* ---------- Giriş ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-box .logo { font-size: 56px; }
.login-box h1 { margin: 8px 0 4px; font-size: 32px; }
.login-box input {
  width: 100%; margin-top: 20px; padding: 14px 16px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--border); outline: none;
}
.btn-primary {
  width: 100%; margin-top: 12px; padding: 14px; border-radius: 14px;
  background: var(--accent); color: #062b14; font-weight: 700;
}
.btn-primary:disabled { opacity: .5; }
.err { color: var(--danger); min-height: 1.2em; font-size: 14px; }

/* ---------- Üst ---------- */
main { max-width: 520px; margin: 0 auto; padding: calc(var(--safe-t) + 10px) 16px 0; }
.top { display: flex; align-items: center; gap: 4px; padding: 6px 0 10px; }
.top-title { flex: 1; text-align: center; }
.day-label { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.date-label { font-size: 13px; color: var(--muted); margin-top: 1px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; font-size: 26px; line-height: 1;
  display: grid; place-items: center; color: var(--muted);
}
.icon-btn:active { background: var(--card); }
.icon-btn:disabled { opacity: .25; }
.icon-btn.gear { font-size: 20px; }

/* ---------- Hafta şeridi ---------- */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 14px; }
.wday {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 8px 0 10px; border-radius: 14px; color: var(--muted); font-size: 12px; font-weight: 600;
}
.wday.sel { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.wday.future { opacity: .35; }
.wday svg { width: 30px; height: 30px; transform: rotate(-90deg); }
.wday .wbg { fill: none; stroke: #2a2e36; stroke-width: 4; }
.wday .wfg { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; }
.wday .wfg.over { stroke: #fb923c; }
.wday .wnum { font-size: 13px; }

/* ---------- Halka ---------- */
.ring-card { padding: 22px 18px 18px; display: flex; flex-direction: column; align-items: center; }
.ring-wrap { position: relative; width: 210px; height: 210px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: #23262d; stroke-width: 16; }
.ring-fg {
  fill: none; stroke: url(#ringGrad); stroke-width: 16; stroke-linecap: round;
  transition: stroke-dashoffset .8s cubic-bezier(.2,.8,.2,1);
}
.ring-fg.over { stroke: url(#ringOver); }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.remain-num { font-size: 46px; font-weight: 800; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.remain-lbl { color: var(--muted); font-size: 14px; margin-top: 6px; }
.ring-stats { display: flex; align-items: center; gap: 28px; margin-top: 14px; }
.ring-stats > div:not(.divider) { display: flex; flex-direction: column; align-items: center; }
.stat-num { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: 12px; color: var(--muted); }
.divider { width: 1px; height: 28px; background: var(--border); }

/* ---------- Makrolar ---------- */
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.macro { padding: 12px 12px 14px; border-radius: 16px; }
.macro-head { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.p, .bar i.p { background: var(--p); }
.dot.c, .bar i.c { background: var(--c); }
.dot.f, .bar i.f { background: var(--f); }
.macro-val { margin: 6px 0 8px; font-variant-numeric: tabular-nums; }
.macro-val b { font-size: 20px; }
.macro-val span { color: var(--muted); font-size: 13px; }
.bar { height: 6px; border-radius: 6px; background: #262a32; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 6px; transition: width .6s ease; }

/* ---------- Öğün listesi ---------- */
.meals h2 { font-size: 18px; margin: 22px 4px 10px; }
.meal {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--border); border-radius: 16px; width: 100%; text-align: left;
}
.meal:active { background: var(--card-2); }
.meal-thumb {
  width: 52px; height: 52px; border-radius: 12px; flex: none; object-fit: cover;
  background: var(--card-2); display: grid; place-items: center; font-size: 24px;
}
.meal-main { flex: 1; min-width: 0; }
.meal-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.meal-sub .mp { color: var(--p); } .meal-sub .mc { color: var(--c); } .meal-sub .mf { color: var(--f); }
.meal-kcal { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.meal-kcal small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }

.meal.pending { opacity: .8; }
.meal.pending .meal-title, .meal.pending .meal-kcal { color: var(--muted); }
.shimmer {
  background: linear-gradient(90deg, #1e2127 0%, #2a2e36 50%, #1e2127 100%);
  background-size: 200% 100%; animation: sh 1.2s infinite linear;
}
@keyframes sh { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.empty { text-align: center; color: var(--muted); padding: 26px 0 10px; }
.empty-emoji { font-size: 38px; }

.composer-spacer { height: calc(110px + var(--safe-b)); }

/* ---------- Alt çubuk ---------- */
.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 10px 12px calc(10px + var(--safe-b));
  background: rgba(14, 15, 18, .82); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
}
.composer-row { max-width: 520px; margin: 0 auto; display: flex; align-items: center; gap: 8px; }
.cam-btn, .send-btn {
  width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center;
}
.cam-btn { background: var(--card); border: 1px solid var(--border); color: var(--text); cursor: pointer; }
.send-btn { background: var(--accent); color: #062b14; }
.send-btn:disabled { opacity: .45; }
.text-input {
  flex: 1; min-width: 0; height: 46px; padding: 0 16px; border-radius: 23px; outline: none;
  background: var(--card); border: 1px solid var(--border); font-size: 16px;
}
.text-input::placeholder { color: #6b707a; }
.photo-preview { max-width: 520px; margin: 0 auto 8px; position: relative; width: fit-content; }
.photo-preview img { height: 72px; border-radius: 12px; display: block; border: 1px solid var(--border); }
.photo-remove {
  position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 50%;
  background: #33373f; font-size: 12px; display: grid; place-items: center;
}

/* ---------- Alt sayfa ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 30; animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-height: 88dvh; overflow-y: auto;
  background: #15171b; border-top: 1px solid var(--border); border-radius: 24px 24px 0 0;
  padding: 8px 18px calc(22px + var(--safe-b)); animation: up .25s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 560px) { .sheet { max-width: 520px; margin: 0 auto; } }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet-handle { width: 38px; height: 5px; border-radius: 3px; background: #3a3e47; margin: 4px auto 14px; }
.sheet h3 { margin: 0 0 4px; font-size: 20px; }
.sheet .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.sheet-photo { width: 100%; max-height: 200px; object-fit: cover; border-radius: 16px; margin-bottom: 14px; }
.items { border: 1px solid var(--border); border-radius: 16px; overflow: hidden; margin-bottom: 12px; }
.item { display: flex; justify-content: space-between; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
.item-name { font-weight: 600; }
.item-portion { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.item-kcal { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.note { font-size: 13px; color: var(--muted); background: var(--card); border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; }
.section-lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 16px 2px 8px; }
.fix-row { display: flex; gap: 8px; }
.fix-row input, .grid-form input {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px; outline: none;
  background: var(--card); border: 1px solid var(--border); font-size: 16px;
}
.btn {
  padding: 12px 16px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--border); font-weight: 600;
}
.btn.green { background: var(--accent); color: #062b14; border-color: transparent; }
.btn.danger { color: var(--danger); width: 100%; margin-top: 18px; }
.btn:disabled { opacity: .5; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-form input { width: 100%; }
.grid-form label { min-width: 0; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.grid-form .full { grid-column: 1 / -1; }
.sheet-actions { display: flex; gap: 8px; margin-top: 12px; }
.sheet-actions .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(96px + var(--safe-b)); max-width: 90vw;
  background: #2a2e36; color: var(--text); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.4); animation: fade .2s;
}
.toast.error { background: #4c1d24; }
