/* Licznik Kalorii – style (mobile-first) */
:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1d2422;
  --muted: #6b7672;
  --line: #e2e7e5;
  --primary: #2e7d5b;
  --primary-soft: #e3f1ea;
  --danger: #c0392b;
  --warn-bg: #fff4e0;
  --warn-text: #8a5a00;
  --radius: 14px;
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --card: #1c2220;
    --text: #e8eeec;
    --muted: #94a19c;
    --line: #2c3431;
    --primary: #4cb386;
    --primary-soft: #1f3a2e;
    --danger: #e5675a;
    --warn-bg: #3a2e14;
    --warn-text: #f0c46b;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
body.noscroll { overflow: hidden; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 .5rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

main, .auth { max-width: 560px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.notice { background: var(--primary-soft); padding: 10px 12px; border-radius: 10px; margin: 8px 0; }
.warning { background: var(--warn-bg); color: var(--warn-text); padding: 10px 12px; border-radius: 10px; margin: 8px 0; }

/* Formularze */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
.form label.check { flex-direction: row; align-items: flex-start; gap: 10px; color: var(--text); }
.form label.check input { margin-top: 3px; width: 18px; height: 18px; flex: none; }
input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Przyciski */
.btn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; border-style: dashed; color: var(--primary); width: 100%; }
.btn:disabled, .btn.busy { opacity: .6; pointer-events: none; }
.icon-btn {
  font-size: 1.5rem; line-height: 1;
  background: none; border: none; color: var(--text);
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
}
.icon-btn:hover { background: var(--line); }

/* Logowanie */
.auth { padding-top: 40px; }
.auth-logo { text-align: center; font-size: 1.6rem; margin-bottom: 20px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.tab { font: inherit; padding: 10px; border: none; border-radius: 10px; background: var(--card); color: var(--muted); cursor: pointer; }
.tab.active { background: var(--primary); color: #fff; font-weight: 600; }

/* Pasek daty */
.datebar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.datebar-label { font: inherit; font-weight: 600; font-size: 1.1rem; background: none; border: none; color: var(--text); cursor: pointer; padding: 8px 16px; }

/* Podsumowanie */
.summary-top { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 10px; }
.summary-top .center { text-align: center; }
.summary-top .right { text-align: right; }
.big { font-size: 1.4rem; font-weight: 700; }
.big.over { color: var(--danger); }
.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--primary); border-radius: 99px; transition: width .3s; }
.bar.over > div { background: var(--danger); }
.bar.small { height: 6px; }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.macro-head { display: flex; flex-direction: column; font-size: .8rem; margin-bottom: 4px; }
.macro-head span:first-child { color: var(--muted); }

/* Posiłki */
.meal-head { display: flex; justify-content: space-between; align-items: baseline; }
.entries, .results { list-style: none; margin: 0 0 10px; padding: 0; }
.entries li, .results li {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.entries li:last-child, .results li:last-child { border-bottom: none; }
.entry-name { overflow-wrap: anywhere; }
.entry-meta { display: flex; justify-content: space-between; font-size: .9rem; color: var(--muted); }
.entry-meta strong { color: var(--text); }
.badge { font-size: .7rem; background: var(--primary-soft); color: var(--primary); padding: 2px 6px; border-radius: 6px; margin-left: 4px; }

/* Profil */
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.result-grid > div { display: flex; flex-direction: column; background: var(--bg); padding: 10px; border-radius: 10px; }
.result-grid .hl { background: var(--primary-soft); }
.account { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Nawigacja dolna */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.bottomnav button {
  flex: 1; font: inherit; font-size: 1.3rem;
  background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  cursor: pointer;
}
.bottomnav button span { font-size: .75rem; }
.bottomnav button.active { color: var(--primary); font-weight: 600; }

/* Bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-width: 560px; margin: 0 auto;
  max-height: 90vh;
  display: flex; flex-direction: column;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  z-index: 21;
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px 0 16px; }
.sheet-head h3 { flex: 1; margin: 0; }
.sheet-body { overflow-y: auto; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); }
.search { margin-bottom: 10px; }
.add-actions { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.add-actions .btn { flex: 1; }
.product-head { margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font: inherit; font-size: .9rem; padding: 8px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--bg); color: var(--text); cursor: pointer; }
.chip:hover { border-color: var(--primary); }
.preview { background: var(--bg); padding: 12px; border-radius: 10px; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  background: #222; color: #fff;
  padding: 10px 16px; border-radius: 10px;
  max-width: calc(100% - 32px);
  z-index: 30;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.toast.error { background: var(--danger); }

.footer { text-align: center; font-size: .8rem; color: var(--muted); padding: 8px 16px 16px; }
