/* Licznik Kalorii – style (mobile-first), paleta pastelowa: fiolet + błękit */

/* Manrope (zmienna grubość 200–800), hostowana lokalnie – licencja w fonts/OFL.txt */
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url(fonts/manrope-latin-ext.woff2) format('woff2-variations');
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url(fonts/manrope-latin.woff2) format('woff2-variations');
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

:root {
  --bg: #f5f6fb;
  --card: #ffffff;
  --field: #f3f4fa;
  --text: #25263a;
  --muted: #7c7f98;
  --line: #e9eaf3;

  --primary: #7b6cf6;        /* fiolet */
  --primary-2: #5eb0f2;      /* błękit */
  --primary-soft: #efecfe;
  --sky-soft: #e6f3fd;
  --pink: #f08fb0;
  --pink-soft: #fdecf2;

  --grad: linear-gradient(135deg, #8b7cf8 0%, #6fb6f5 100%);
  --grad-soft: linear-gradient(135deg, #f1eeff 0%, #e7f4fe 100%);

  --success: #3fb68b;
  --danger: #e5586b;
  --warn-bg: #fff4e5;
  --warn-text: #9a5b13;

  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 6px 24px rgba(91, 82, 180, .08);
  --nav-h: 68px;
  --on-primary: #ffffff;
  --switch-off: #c9cbe0;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14141f;
    --card: #1e1e2d;
    --field: #262638;
    --text: #ececf5;
    --muted: #9a9bb5;
    --line: #2d2d42;
    --primary: #a497ff;
    --primary-2: #7cc2f7;
    --primary-soft: #2a2747;
    --sky-soft: #1d2f42;
    --pink: #f5a3c0;
    --pink-soft: #3a2433;
    --grad: linear-gradient(135deg, #8b7cf8 0%, #5ea8ea 100%);
    --grad-soft: linear-gradient(135deg, #25223f 0%, #1c2c3e 100%);
    --success: #5fd0a6;
    --danger: #ff7d8e;
    --warn-bg: #3a2e1a;
    --warn-text: #f3c77a;
    --shadow: 0 6px 24px rgba(0, 0, 0, .3);
    --switch-off: #45465f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.45 'Manrope', 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));
  -webkit-font-smoothing: antialiased;
}
body.noscroll { overflow: hidden; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0 0 .5rem; letter-spacing: -.01em; }
h2 { font-size: 1.4rem; font-weight: 800; }
h3 { font-size: 1.02rem; font-weight: 700; }

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

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.notice { background: var(--primary-soft); color: var(--text); padding: 12px 14px; border-radius: var(--radius-sm); margin: 8px 0; }
.warning { background: var(--warn-bg); color: var(--warn-text); padding: 12px 14px; border-radius: var(--radius-sm); margin: 8px 0; }

/* Ikony – rozmiar domyślny także w atrybutach SVG */
.ico { width: 20px; height: 20px; flex: none; vertical-align: -4px; }

/* Formularze */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; font-weight: 600; color: var(--muted); }
.form label.check { flex-direction: row; align-items: flex-start; gap: 10px; color: var(--text); font-weight: 500; font-size: .9rem; }
.form label.check input { margin-top: 2px; width: 18px; height: 18px; flex: none; }
input:not([type=checkbox]), select {
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--field);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  width: 100%;
  min-height: 46px;
  transition: border-color .15s, background .15s;
}
input:not([type=checkbox]):focus, select:focus { outline: none; border-color: var(--primary); background: var(--card); }
input::placeholder { color: var(--muted); opacity: .8; }
input[type=checkbox] { accent-color: var(--primary); cursor: pointer; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Przyciski */
.btn {
  font: inherit;
  font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none;
  background: var(--field);
  color: var(--text);
  border-radius: 14px;
  padding: 11px 16px;
  min-height: 46px;
  cursor: pointer;
  transition: transform .1s, box-shadow .15s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--grad); color: var(--on-primary); box-shadow: 0 6px 16px rgba(123, 108, 246, .28); }
.btn.danger { color: var(--danger); background: transparent; box-shadow: inset 0 0 0 1.5px var(--danger); }
.btn.ghost { background: var(--primary-soft); color: var(--primary); width: 100%; }
.btn:disabled, .btn.busy { opacity: .6; pointer-events: none; }
.icon-btn {
  background: none; border: none; color: var(--text);
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--field); }
.warning .ico { width: 18px; height: 18px; margin-right: 4px; }

/* Logowanie */
.auth { padding-top: 48px; }
.auth-logo { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 1.5rem; font-weight: 800; margin-bottom: 24px; }
.auth-logo .logo { flex: none; border-radius: 12px; box-shadow: 0 6px 16px rgba(123, 108, 246, .3); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 14px; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); }
.tab { font: inherit; font-weight: 600; padding: 10px; border: none; border-radius: 12px; background: transparent; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--grad); color: var(--on-primary); }

/* Pasek daty */
.datebar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.datebar-label { font: inherit; font-weight: 700; font-size: 1.05rem; background: var(--card); border: none; color: var(--text); cursor: pointer; padding: 8px 20px; border-radius: 99px; box-shadow: var(--shadow); }

/* Podsumowanie dnia */
.summary { background: var(--grad-soft); }
.summary-top { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 14px; }
.summary-top .center { text-align: center; }
.summary-top .right { text-align: right; }
.summary-top .muted { font-size: .8rem; font-weight: 600; }
.big { font-size: 1.55rem; font-weight: 800; letter-spacing: -.02em; }
.big.over { color: var(--danger); }
.bar { height: 10px; background: rgba(123, 108, 246, .12); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--grad); border-radius: 99px; transition: width .4s ease; }
.bar.over > div { background: var(--danger); }
.bar.small { height: 6px; }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; }
.macro-head { display: flex; flex-direction: column; font-size: .78rem; font-weight: 600; margin-bottom: 6px; }
.macro-head span:first-child { color: var(--muted); }
.macro:nth-child(1) .bar > div { background: var(--primary); }
.macro:nth-child(2) .bar > div { background: var(--pink); }
.macro:nth-child(3) .bar > div { background: var(--primary-2); }

/* Kontrola cukru */
.sugar-sum { display: flex; align-items: center; gap: 14px; margin-top: 16px; padding-top: 14px; border-top: 1px solid rgba(123, 108, 246, .12); }
.sugar-main { flex: 1; min-width: 0; }
.bar.sugar > div { background: var(--pink); }
.bar.sugar.over > div { background: var(--danger); }
.over-text { color: var(--danger); }
.ww-stat { flex: none; text-align: center; background: var(--card); border-radius: var(--radius-sm); padding: 6px 14px; }
.ww-num { font-size: 1.2rem; font-weight: 800; color: var(--primary); line-height: 1.2; }
.ww-stat .muted { font-size: .7rem; font-weight: 600; }
.sugar-note { margin: 8px 0 0; }
.meal-sugar { font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.limit-warn { display: flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; color: var(--warn-text); background: var(--warn-bg); padding: 6px 10px; border-radius: 10px; margin: 6px 0; }
.limit-warn .ico { width: 16px; height: 16px; }
.preview-sugar { margin-top: 6px; font-size: .9rem; }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }

/* Profil: przełącznik trybu cukru */
.sugar-box { background: var(--field); border-radius: var(--radius-sm); padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.form label.switch-row { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; color: var(--text); font-weight: 500; cursor: pointer; }
.switch-text { display: flex; flex-direction: column; gap: 2px; font-size: .95rem; }
.switch-text .small { font-weight: 500; }
.sugar-fields { display: flex; flex-direction: column; gap: 14px; }
.sugar-fields input:not([type=checkbox]), .sugar-fields select { background: var(--card); }
input.switch {
  appearance: none; -webkit-appearance: none;
  flex: none; width: 48px; height: 28px; margin: 0;
  border-radius: 99px; background: var(--switch-off);
  position: relative; cursor: pointer; transition: background .2s;
}
input.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .2s;
}
input.switch:checked { background: var(--primary); }
input.switch:checked::after { transform: translateX(20px); }
input.switch:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Posiłki */
.meal-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.meal-head h3 { margin: 0; }
.meal-head .muted { font-weight: 600; font-size: .85rem; }
.entries, .results { list-style: none; margin: 0 0 10px; padding: 0; }
.entries li, .results li {
  padding: 11px 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; font-weight: 600; }
.entry-name .muted { font-weight: 500; }
.entry-meta { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); }
.entry-meta strong { color: var(--text); }
.meal .btn.ghost { margin-top: 6px; min-height: 42px; }
.badge { font-size: .68rem; font-weight: 700; background: var(--pink-soft); color: var(--pink); padding: 2px 8px; border-radius: 99px; margin-left: 4px; }

/* Profil */
.result { display: flex; flex-direction: column; gap: 6px; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.result-grid > div { display: flex; flex-direction: column; background: var(--field); padding: 12px; border-radius: var(--radius-sm); }
.result-grid > div .muted { font-size: .78rem; font-weight: 600; }
.result-grid .hl { background: var(--grad-soft); }
.account { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Abonament */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--warn-bg); color: var(--warn-text); font-weight: 600; font-size: .9rem;
  padding: 12px 14px; border-radius: var(--radius); margin-bottom: 14px;
}
.banner .btn { flex: none; }
.sub p { margin: 6px 0; }
.sub h4 { margin: 18px 0 6px; font-size: .92rem; }
#sub-pay { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
#sub-pay[hidden] { display: none; }
.pay-option { display: flex; flex-direction: column; gap: 2px; }
.payu-card {
  min-height: 52px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--field);
}
#btn-sub-cancel { margin-top: 12px; width: 100%; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.history li:last-child { border-bottom: none; }
.history .right { text-align: right; }
.status-completed { color: var(--success); font-weight: 600; }
.status-failed, .status-canceled { color: var(--danger); font-weight: 600; }

/* Nawigacja dolna */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding: 8px 24px env(safe-area-inset-bottom);
  display: flex; gap: 12px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 -4px 20px rgba(91, 82, 180, .06);
  z-index: 10;
}
.bottomnav button {
  flex: 1; font: inherit;
  background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: 16px;
  cursor: pointer;
}
.bottomnav button .ico { width: 22px; height: 22px; }
.bottomnav button span { font-size: .72rem; font-weight: 600; }
.bottomnav button.active { color: var(--primary); background: var(--primary-soft); }

/* Bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(30, 28, 60, .35); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); 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: 26px 26px 0 0;
  box-shadow: 0 -10px 40px rgba(30, 28, 60, .15);
  z-index: 21;
  animation: up .22s ease-out;
}
.sheet::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 8px auto 0; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; gap: 4px; padding: 6px 10px 0 18px; }
.sheet-head h3 { flex: 1; margin: 0; font-size: 1.05rem; }
.sheet-body { overflow-y: auto; padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); }
.search { margin-bottom: 12px; }

/* Kafelki: skanuj / etykieta / ręcznie */
.add-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.add-actions .btn {
  flex-direction: column; gap: 6px;
  font-size: .8rem; font-weight: 600;
  padding: 12px 6px; min-height: 0;
  background: var(--field);
}
.add-actions .btn .ico {
  width: 36px; height: 36px; padding: 8px;
  border-radius: 12px;
  color: var(--primary); background: var(--primary-soft);
}
#btn-label .ico { color: var(--primary-2); background: var(--sky-soft); }
#btn-manual .ico { color: var(--pink); background: var(--pink-soft); }

/* Skaner */
.reader { width: 100%; min-height: 200px; background: #000; border-radius: 16px; overflow: hidden; margin-bottom: 8px; }
.reader video { width: 100% !important; display: block; }
.form.inline { flex-direction: row; gap: 8px; margin-top: 8px; }
.form.inline input { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px 0; color: var(--muted); font-weight: 600; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.product-head { margin-bottom: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font: inherit; font-size: .85rem; font-weight: 600; padding: 8px 14px; border-radius: 99px; border: none; background: var(--primary-soft); color: var(--primary); cursor: pointer; }
.chip:active { transform: scale(.97); }
.preview { background: var(--grad-soft); padding: 14px; border-radius: var(--radius-sm); }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  background: #2b2a45; color: #fff; font-weight: 600; font-size: .9rem;
  padding: 11px 18px; border-radius: 14px;
  max-width: calc(100% - 32px);
  z-index: 30;
  box-shadow: 0 8px 24px rgba(30, 28, 60, .25);
}
.toast.error { background: var(--danger); }

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