/* ===== Kcal — dark mobile-first PWA ===== */
:root {
  --bg: #0f0f12;
  --card: #1a1a20;
  --card-2: #22222a;
  --text: #f2f2f5;
  --muted: #8b8b96;
  --accent: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --blue: #60a5fa;
  --radius: 18px;
  --nav-h: 64px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); }

#main { max-width: 520px; margin: 0 auto; padding: 0 16px; }

.view { display: none; animation: fadein 0.18s ease; }
.view.active { display: block; }
@keyframes fadein { from { opacity: 0.4; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 18px) 4px 14px;
}
.page-head h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title { font-weight: 700; font-size: 15px; }
.row-between { display: flex; justify-content: space-between; align-items: center; }

/* ===== kcal ring ===== */
.ring-card { display: flex; flex-direction: column; align-items: center; padding: 22px 16px 16px; }
.ring-wrap { position: relative; width: 190px; height: 190px; }
.ring-bg { fill: none; stroke: var(--card-2); stroke-width: 14; }
.ring-fg {
  fill: none; stroke: var(--accent); stroke-width: 14; stroke-linecap: round;
  transform: rotate(-90deg); transform-origin: 100px 100px;
  transition: stroke-dashoffset 0.6s ease, stroke 0.4s ease;
}
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.ring-number { font-size: 44px; font-weight: 800; letter-spacing: -1px; font-variant-numeric: tabular-nums; }
.ring-number.over { color: var(--red); }
.ring-label { color: var(--muted); font-size: 14px; margin-top: -2px; }
.budget-line { margin-top: 10px; font-size: 13px; text-align: center; }

/* ===== protein bar ===== */
.bar { height: 10px; background: var(--card-2); border-radius: 6px; margin-top: 10px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--blue); border-radius: 6px; transition: width 0.5s ease; }
.macro-line { margin-top: 8px; font-size: 12.5px; }

/* ===== sparkline / chart ===== */
.spark { width: 100%; height: 60px; margin-top: 8px; display: block; }
.chart { width: 100%; height: 160px; margin-top: 8px; display: block; }
.spark path, .chart path { fill: none; }
.line-raw { stroke: #3f3f4a; stroke-width: 1.5; }
.line-trend { stroke: var(--blue); stroke-width: 2.5; }
.dot-raw { fill: #55555f; }

.activity-line {
  background: linear-gradient(90deg, #1d2b22, #1a1a20);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px;
  font-size: 14px;
}

/* ===== favorites chips ===== */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; background: var(--card); border: 1px solid #2a2a33;
  color: var(--text); border-radius: 22px; padding: 9px 14px; font-size: 13.5px;
  display: flex; align-items: center; gap: 6px;
}
.chip .chip-kcal { color: var(--muted); font-size: 12px; }
.chip:active { background: var(--card-2); }

.section-title { font-size: 16px; font-weight: 700; margin: 6px 4px 10px; }

/* ===== entries ===== */
.entry-list { display: flex; flex-direction: column; gap: 8px; }
.entry {
  background: var(--card); border-radius: 14px; padding: 12px 14px;
  position: relative; overflow: hidden;
}
.entry-main { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.entry-name { font-size: 14.5px; font-weight: 600; }
.entry-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.entry-kcal { font-weight: 700; font-size: 15px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.entry-actions { display: flex; gap: 14px; margin-top: 8px; }
.entry-action { color: var(--muted); font-size: 12.5px; background: none; border: none; padding: 0; }
.entry-action.danger { color: var(--red); }

.question-chip {
  margin-top: 8px; background: rgba(251, 191, 36, 0.12); border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 10px; padding: 8px 10px; font-size: 13px; color: var(--amber);
}
.question-chip .q-actions { margin-top: 6px; display: flex; gap: 12px; }
.question-chip button { background: none; border: none; color: var(--amber); font-weight: 700; font-size: 13px; padding: 0; }
.question-chip button.q-dismiss { color: var(--muted); font-weight: 400; }
.question-chip input {
  width: 100%; margin-top: 6px; background: var(--card-2); border: none; border-radius: 8px;
  color: var(--text); padding: 8px 10px; font-size: 14px;
}

.empty-hint { text-align: center; color: var(--muted); padding: 34px 20px; line-height: 1.6; font-size: 14.5px; }

/* ===== week bars ===== */
.week-bars { display: flex; align-items: flex-end; gap: 8px; height: 130px; margin: 16px 0 4px; }
.wb { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.wb-bar { width: 100%; max-width: 34px; border-radius: 7px 7px 3px 3px; background: var(--accent); min-height: 3px; transition: height 0.4s ease; }
.wb-bar.over { background: var(--red); }
.wb-bar.empty { background: var(--card-2); }
.wb.selected .wb-bar { outline: 2px solid var(--blue); }
.wb-label { font-size: 11px; color: var(--muted); }
.week-budget-note { font-size: 12px; color: var(--muted); }

/* ===== settings ===== */
.setting-row { display: flex; justify-content: space-between; align-items: center; margin: 14px 0 6px; font-size: 14.5px; }
.setting-val { font-weight: 700; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.num-input {
  width: 76px; background: var(--card-2); border: none; border-radius: 10px;
  color: var(--text); padding: 8px 10px; font-size: 15px; text-align: right;
}
.toggle { width: 22px; height: 22px; accent-color: var(--accent); }
.tdee-explain { font-size: 14px; line-height: 1.65; color: #c9c9d2; margin-top: 6px; }
.tdee-explain b { color: var(--text); }

.btn {
  display: block; width: 100%; border: none; border-radius: 14px;
  padding: 14px; font-size: 16px; font-weight: 700; margin-top: 14px;
}
.btn-primary { background: var(--accent); color: #06220f; }
.btn-primary:disabled { opacity: 0.4; }
.btn:active { transform: scale(0.98); }

.icon-btn {
  background: var(--card-2); border: none; color: var(--text);
  width: 34px; height: 34px; border-radius: 10px; font-size: 18px;
}

/* ===== bottom nav ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(20, 20, 25, 0.92);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid #26262e;
  display: flex; align-items: center; justify-content: space-around;
  z-index: 40;
}
.nav-btn {
  background: none; border: none; color: var(--muted); font-size: 11px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; width: 74px;
}
.nav-btn.active { color: var(--text); }
.nav-ico { font-size: 21px; }
.nav-add {
  width: 54px; height: 54px; border-radius: 50%; border: none;
  background: var(--accent); color: #06220f; font-size: 32px; font-weight: 500;
  line-height: 1; margin-top: -18px;
  box-shadow: 0 6px 20px rgba(74, 222, 128, 0.35);
}
.nav-add:active { transform: scale(0.94); }

/* ===== sheets ===== */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 50;
  animation: fadein 0.15s ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(env(safe-area-inset-bottom) + 22px);
  animation: slideup 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
  max-width: 520px; margin: 0 auto;
}
@keyframes slideup { from { transform: translateY(60%); } to { transform: none; } }
.sheet-handle { width: 38px; height: 4px; background: #3a3a44; border-radius: 3px; margin: 4px auto 14px; }
.sheet-title { font-size: 17px; font-weight: 700; margin-bottom: 12px; }

.add-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.add-big {
  background: var(--card-2); border: none; border-radius: 16px; color: var(--text);
  padding: 20px 0 16px; font-size: 15px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.add-ico { font-size: 30px; }
.add-big:active { background: #2a2a33; }
.add-row { display: flex; gap: 8px; margin-top: 10px; }
.add-small {
  flex: 1; background: var(--card-2); border: none; border-radius: 12px;
  color: var(--text); padding: 12px 0; font-size: 13.5px; font-weight: 600;
}
.fav-sheet-list { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; max-height: 30vh; overflow-y: auto; }
.fav-sheet-item {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card-2); border: none; border-radius: 12px; color: var(--text);
  padding: 11px 14px; font-size: 14px; width: 100%; text-align: left;
}
.fav-sheet-item .chip-kcal { color: var(--muted); font-size: 12.5px; }

textarea, input[type="text"] {
  width: 100%; background: var(--card-2); border: none; border-radius: 12px;
  color: var(--text); padding: 13px 14px; font-size: 16px; font-family: inherit;
  resize: none; margin-bottom: 4px;
}
textarea:focus, input:focus { outline: 2px solid rgba(74, 222, 128, 0.4); }

.type-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.type-btn {
  background: var(--card-2); border: 2px solid transparent; border-radius: 12px;
  color: var(--text); padding: 13px 4px; font-size: 13.5px; font-weight: 600;
}
.type-btn.selected { border-color: var(--accent); }
.dur-row { display: flex; gap: 8px; margin-top: 12px; }
.dur-btn {
  flex: 1; background: var(--card-2); border: 2px solid transparent; border-radius: 10px;
  color: var(--text); padding: 10px 0; font-size: 13.5px;
}
.dur-btn.selected { border-color: var(--accent); }

.big-num-input {
  width: 100%; background: var(--card-2); border: none; border-radius: 14px;
  color: var(--text); padding: 16px; font-size: 32px; font-weight: 700;
  text-align: center; font-variant-numeric: tabular-nums;
}
.manual-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.manual-grid label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.manual-grid input {
  background: var(--card-2); border: none; border-radius: 10px;
  color: var(--text); padding: 11px; font-size: 16px;
}

/* ===== result overlay ===== */
.result-overlay {
  position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fadein 0.15s ease;
}
.result-card {
  background: var(--card); border-radius: 20px; padding: 20px;
  width: 100%; max-width: 400px; animation: popin 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  max-height: 80vh; overflow-y: auto;
}
@keyframes popin { from { transform: scale(0.92); opacity: 0; } to { transform: none; opacity: 1; } }
.result-kcal { font-size: 40px; font-weight: 800; letter-spacing: -1px; }
.result-name { font-size: 16px; font-weight: 700; margin-top: 2px; }
.result-macros { color: var(--muted); font-size: 13.5px; margin: 6px 0 12px; }
.result-items { border-top: 1px solid #2a2a33; padding-top: 10px; margin-bottom: 4px; }
.result-item { display: flex; justify-content: space-between; font-size: 13.5px; padding: 4px 0; color: #c9c9d2; }
.result-item span:last-child { color: var(--muted); white-space: nowrap; margin-left: 10px; }
.result-question {
  background: rgba(251, 191, 36, 0.12); border-radius: 10px; padding: 10px;
  font-size: 13.5px; color: var(--amber); margin-top: 10px;
}
.result-actions { display: flex; gap: 10px; margin-top: 14px; }
.result-actions .btn { margin-top: 0; }
.btn-ghost { background: var(--card-2); color: var(--text); }

.loading-spinner {
  width: 42px; height: 42px; border-radius: 50%; margin: 10px auto;
  border: 4px solid var(--card-2); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { text-align: center; color: var(--muted); padding-bottom: 8px; }

/* ===== toast ===== */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px);
  left: 50%; transform: translateX(-50%); z-index: 70;
  background: #2c2c36; color: var(--text); border-radius: 14px;
  padding: 12px 18px; font-size: 14px; display: flex; gap: 14px; align-items: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); white-space: nowrap;
  animation: slideup 0.2s ease;
}
.toast button { background: none; border: none; color: var(--accent); font-weight: 700; font-size: 14px; }
