/* ============================================================
   Spiżarnia v2 - design system
   ============================================================ */
:root {
  --green: #2f7d5b;
  --green-dark: #246348;
  --green-soft: #e7f2ec;
  --bg: #f4f6f4;
  --card: #ffffff;
  --text: #22302a;
  --muted: #75837b;
  --line: #e6eae7;
  --red: #c2452e;
  --red-soft: #fbeae6;
  --amber: #b7791f;
  --amber-soft: #fdf3e3;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 4px 16px rgba(20, 40, 30, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
}
.hidden { display: none !important; }
b, strong { font-weight: 650; }

/* ---------- Logowanie ---------- */
.login-screen {
  min-height: 100svh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #2f7d5b 0%, #1d5540 60%, #17402f 100%);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--card);
  border-radius: 24px;
  padding: 32px 26px 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  text-align: center;
}
.login-logo { font-size: 44px; }
.login-card h1 { margin: 6px 0 2px; font-size: 28px; letter-spacing: -0.5px; }
.login-sub { margin: 0 0 22px; color: var(--muted); font-size: 14.5px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; text-align: left; }

/* ---------- Pola formularzy ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  font: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green);
}
textarea { resize: vertical; min-height: 90px; }
.form-error { color: var(--red); font-size: 14px; margin: 4px 0 0; text-align: center; }

/* ---------- Przyciski ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px;
  padding: 11px 18px;
  font: inherit; font-weight: 650; font-size: 15px;
  cursor: pointer;
  transition: transform .05s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:active { background: var(--green-dark); }
.btn-ghost { background: transparent; color: var(--green); border: 1.5px dashed #b9cfc4; }
.btn-danger-soft { background: var(--red-soft); color: var(--red); }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 18px; font-size: 16px; }
.btn-sm { padding: 7px 12px; font-size: 13.5px; border-radius: 10px; }

.icon-chip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .18);
  color: #fff; cursor: pointer;
}

/* ---------- Layout ---------- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  background: var(--green);
  color: #fff;
  padding-top: env(safe-area-inset-top);
}
.app-header-inner {
  max-width: 680px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
}
.app-header h1 { margin: 0; font-size: 21px; letter-spacing: -0.3px; }

#main {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 14px calc(86px + env(safe-area-inset-bottom));
}

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0 8px;
  border: 0; background: none; cursor: pointer;
  color: #9aa8a0;
  font: inherit; font-size: 11.5px; font-weight: 600;
}
.tab.active { color: var(--green); }
.tab.active svg { transform: translateY(-1px); }

/* ---------- Karty / sekcje ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card h3 { margin: 0 0 4px; font-size: 17px; }
.card-sub { color: var(--muted); font-size: 13px; margin: 0 0 10px; }

.banner {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--green-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 14px;
}
.banner p { margin: 2px 0 0; color: #4a5d53; }
.banner-emoji { font-size: 26px; line-height: 1; }
.banner-soft { background: #eef1ee; }
.banner-soft p { color: var(--muted); }

.empty {
  text-align: center; color: var(--muted);
  padding: 26px 12px; font-size: 14.5px;
}
.empty .empty-emoji { font-size: 34px; display: block; margin-bottom: 6px; }

/* ---------- Wiersze list ---------- */
.row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
  min-height: 46px;
}
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .name { display: block; overflow-wrap: break-word; }
.row .sub { display: block; font-size: 12.5px; color: var(--muted); }

.chip {
  display: inline-block;
  font-size: 12px; font-weight: 650;
  padding: 3px 9px;
  border-radius: 99px;
  background: #eef1ee; color: var(--muted);
  white-space: nowrap;
}
.chip-home { background: var(--green-soft); color: var(--green-dark); }
.chip-low { background: var(--red-soft); color: var(--red); }
.chip-qty { background: #eef1ee; color: var(--text); }

/* checkbox zakupowy */
.checkline { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; cursor: pointer; }
.checkline input { display: none; }
.checkmark {
  flex: 0 0 26px; width: 26px; height: 26px;
  border: 2px solid #c3cfc8; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .12s;
}
.checkline input:checked + .checkmark {
  background: var(--green); border-color: var(--green);
}
.checkline input:checked + .checkmark::after {
  content: ""; width: 7px; height: 12px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}
.checkline input:checked ~ .grow .name { text-decoration: line-through; color: var(--muted); }

.iconbtn {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border: 0; border-radius: 10px;
  background: #f0f3f0; color: var(--muted);
  font-size: 17px; cursor: pointer;
}
.iconbtn:active { background: #e4e9e5; }
.iconbtn.bell.on { background: var(--red-soft); color: var(--red); }
.iconbtn.plus { background: var(--green-soft); color: var(--green-dark); font-weight: 700; }

/* pasek postepu listy */
.progress { height: 6px; background: #edf0ed; border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; background: var(--green); border-radius: 99px; transition: width .25s; }

.list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.list-head .muted-sm { color: var(--muted); font-size: 13px; white-space: nowrap; }

.addline { display: flex; gap: 8px; margin-top: 10px; }
.addline input[type="text"] { flex: 1; }
.addline input.qty-in { flex: 0 0 74px; text-align: center; }

.card-actions { display: flex; gap: 8px; margin-top: 12px; }
.card-actions .btn { flex: 1; }

/* kategoria w magazynie */
.cat-title {
  margin: 18px 4px 8px;
  font-size: 12.5px; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
}
.cat-title:first-child { margin-top: 2px; }

/* sekcja "konczy sie" */
.low-card { border-left: 5px solid var(--red); }

/* przepisy */
.recipe-desc { white-space: pre-wrap; color: #40514a; font-size: 14.5px; margin: 6px 0 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ---------- Bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 25, 20, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .15s;
}
.sheet {
  width: 100%; max-width: 680px;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(22px + env(safe-area-inset-bottom));
  max-height: 88svh; overflow-y: auto;
  animation: slideUp .2s ease-out;
}
.sheet-handle { width: 42px; height: 5px; border-radius: 99px; background: #d8deda; margin: 4px auto 14px; }
.sheet h3 { margin: 0 0 14px; font-size: 19px; }
.sheet form { display: flex; flex-direction: column; gap: 13px; }
.sheet .row2 { display: flex; gap: 10px; }
.sheet .row2 > * { flex: 1; }
.check-inline { display: flex; align-items: center; gap: 9px; font-size: 15px; }
.check-inline input { width: 20px; height: 20px; accent-color: var(--green); }

/* ustawienia produktu */
.field-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.opt {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 12px 14px;
  border: 1.5px solid var(--line); border-radius: 12px;
  cursor: pointer;
}
.opt:has(input:checked) { border-color: var(--green); background: var(--green-soft); }
.opt input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--green); flex: 0 0 auto; }
.opt div { display: flex; flex-direction: column; }
.opt span { font-size: 13px; color: var(--muted); }
.tappable { cursor: pointer; }
.dot { font-size: 11px; opacity: .55; }

@keyframes slideUp { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Wydatki ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.tile {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px;
}
.tile-big { grid-column: 1 / -1; background: var(--green); color: #fff; }
.tile-label { font-size: 12.5px; opacity: .75; font-weight: 600; }
.tile-value { font-size: 27px; font-weight: 700; letter-spacing: -0.5px; }
.tile-value.sm { font-size: 19px; }
.tile-sub { font-size: 12.5px; opacity: .9; }
.tile-sub.up::before { content: ""; }
.tile-sub.down { opacity: 1; }

.chart { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.bar-val { font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
.bar-stack { width: 100%; max-width: 46px; display: flex; flex-direction: column; border-radius: 6px; overflow: hidden; min-height: 4px; }
.bar { width: 100%; min-height: 2px; }
.bar.biedra { background: var(--green); }
.bar.allegro { background: #e0a33e; }
.bar-label { font-size: 11px; color: var(--muted); margin-top: 5px; }
.dot-legend { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin: 0 3px 0 8px; }
.dot-legend.biedra { background: var(--green); }
.dot-legend.allegro { background: #e0a33e; }
.dot-legend:first-child { margin-left: 0; }

.catrow { margin-bottom: 11px; }
.catrow-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 3px; }
.rank {
  flex: 0 0 22px; width: 22px; height: 22px; border-radius: 50%;
  background: #eef1ee; color: var(--muted);
  font-size: 11.5px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- Daty ważności ---------- */
.expire-card { border-left: 5px solid var(--amber); }
.chip-warn { background: var(--amber-soft); color: var(--amber); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: calc(64px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 90;
  background: #263831; color: #fff;
  padding: 11px 20px; border-radius: 12px;
  font-size: 14.5px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  max-width: 92%;
  animation: fadeIn .15s;
}
.toast.err { background: var(--red); }
