/* SilFit – prosty, mobilny styl (mobile-first)
   Rozmiary wg wytycznych: elementy STATYCZNE (bez klikania) 20px,
   elementy KLIKALNE minimum 40×40 px. */
:root {
  --accent: #16a34a;
  --accent-dark: #15803d;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --danger: #dc2626;
  --radius: 12px;
  --size-static: 20px;   /* teksty informacyjne (etykiety, nagłówki, sumy) */
  --tap: 40px;           /* minimum dla elementów z reakcją na klikanie */
}

* { box-sizing: border-box; }

body {
  position: relative;
  z-index: 0;
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Pasek narzędzi (wzór sf2026) — pas górny, zawsze widoczny ---------- */
.toolbar {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 48px;
  padding: 8px 5px;
  background: var(--card);
  border-bottom: 1px solid #e5e7eb;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
/* gdy klawiatura HTML otwarta – toolbar przyklejony do góry (scroll rezerwuje miejsce przez main) */
body.kb-open .toolbar { position: sticky; top: 0; z-index: 20; }

.toolbar-button {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: none;
  border-radius: 6px;
  background: #eef1ef;
  color: var(--text);
  cursor: pointer;
}
.toolbar-button > svg {
  display: block;
  width: 80%;
  height: 80%;
}
/* stan trybu klawiatury (jak w sf2026): zielone tło = „tak” (zawsze) */
.toolbar-button.keyboard-visible { background: var(--accent); color: #fff; }

.toolbar-text {
  flex: none;
  min-width: var(--tap);
  height: var(--tap);
  padding: 0 10px;
  border: none;
  border-radius: 6px;
  background: #eef1ef;
  color: var(--text);
  font-family: inherit;
  font-size: var(--size-static);
  cursor: pointer;
  white-space: nowrap;
}
.toolbar-text.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.toolbar-filter {
  display: flex;
  align-items: center;
  flex: 1 1 100px;
  min-width: 90px;
  height: var(--tap);
  padding: 0 10px;
  font-size: var(--size-static);
  border: 1px solid #d1d5db;
  border-radius: 9px;
  background: var(--card);
  white-space: nowrap;
  overflow: hidden;
  cursor: text;
}
.toolbar-filter:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.toolbar-filter.is-empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  font-size: 16px;
}

.sync {
  flex: none;
  margin-right: 4px;
  font-size: var(--size-static);
  white-space: nowrap;
  color: var(--muted);
}
.sync.ok { color: var(--accent-dark); }
.sync.ok::before { content: "✓ "; }
.sync.pending::before { content: "… "; }
.sync.offline { color: #b45309; }
.sync.offline::before { content: "⚡ "; }
.sync.error { color: var(--danger); }
.sync.error::before { content: "✗ "; }

/* ---------- Panel menu (kafle jak w sf2026) ---------- */
.menu-panel {
  position: fixed;
  inset: 48px 0 0 0;
  z-index: 25;
  overflow-y: auto;
  background: var(--bg);
}
.menu-panel.hidden { display: none; }

.menu-panel-inner {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
}

.menu-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 92px;
  padding: 8px;
  border: none;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: var(--size-static);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  cursor: pointer;
}
.menu-tile:active { background: #ecfdf5; }
.menu-tile-icon { font-size: 28px; line-height: 1; }

/* Panel środkowy – pas środkowy: sam się przewija, kurczy się gdy klawiatura zajmuje dół */
main {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px;
  overflow-y: auto;
}

.hidden { display: none !important; }

/* ---------- Formularz dodawania (kompaktowy, jedna kolumna) ---------- */
.add-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  padding: 10px 12px;
  margin-bottom: 12px;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.field-label {
  flex: none;
  width: 110px;
  font-size: var(--size-static);   /* statyczne = 20px */
  color: var(--muted);
}
.field-row input { flex: 1; min-width: 0; }

input {
  width: 100%;
  min-height: var(--tap);          /* klikalne = min 40px */
  padding: 8px 10px;
  font-size: var(--size-static);
  font-family: inherit;
  border: 1px solid #d1d5db;
  border-radius: 9px;
  background: var(--card);
}
input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

.btn-primary {
  width: 100%;
  min-height: var(--tap);
  padding: 10px;
  font-size: var(--size-static);
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 9px;
  cursor: pointer;
}
.btn-primary:active { background: var(--accent-dark); }

.btn-small, .btn-icon {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 12px;
  font-size: var(--size-static);
  font-family: inherit;
  border: 1px solid #d1d5db;
  border-radius: 9px;
  background: var(--card);
  cursor: pointer;
}
.btn-icon { font-size: 24px; line-height: 1; padding: 0; }

.calc-preview {
  margin: 4px 0 8px;
  padding: 6px;
  text-align: center;
  background: #ecfdf5;
  border: 1px solid #bbf7d0;
  border-radius: 9px;
  font-size: var(--size-static);
}
.calc-preview strong { color: var(--accent-dark); }

/* ---------- Nawigacja dni + suma ---------- */
.day-nav { display: flex; gap: 6px; margin-bottom: 8px; }
.day-nav input { flex: 1; }
.day-nav .btn-small, .day-nav .btn-icon { flex-shrink: 0; }

.day-total {
  text-align: center;
  padding: 6px;
  margin-bottom: 8px;
  background: var(--card);
  border-radius: 9px;
  font-size: var(--size-static);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.day-total strong { color: var(--accent-dark); }

/* ---------- Listy (kompaktowe) ---------- */
.list { list-style: none; margin: 0; padding: 0; }

.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  margin-bottom: 4px;
  min-height: var(--tap);
  background: var(--card);
  border-radius: 9px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.list .item-main { flex: 1; min-width: 0; }
.list .item-title {
  font-size: var(--size-static);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list .item-sub { font-size: var(--size-static); color: var(--muted); }
.list .item-kcal { font-size: var(--size-static); font-weight: 700; white-space: nowrap; }
.list .item-del {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  border: none;
  background: none;
  color: var(--danger);
  font-size: 22px;
  cursor: pointer;
}
.pending-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 6px;
  border-radius: 50%;
  background: #f59e0b;
  vertical-align: middle;
}

.row-form { display: flex; gap: 6px; margin-bottom: 10px; }
.row-form input { flex: 1; min-width: 0; }
.row-form .btn-primary { width: auto; padding: 8px 14px; flex-shrink: 0; }

.empty { text-align: center; color: var(--muted); font-size: var(--size-static); }

.toast {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 10px 18px;
  background: #111827;
  color: #fff;
  border-radius: 999px;
  font-size: var(--size-static);
  z-index: 100;
}

/* ---------- Klawiatura HTML (wzór sf2026) ---------- */
/* Pas dolny – klawiatura HTML w strumieniu layoutu (nie nakłada się; main się kurczy) */
.kb-footer {
  position: relative;
  flex: none;
  z-index: 40;
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 6px 5px calc(6px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  border-top: 2px solid #e5e7eb;
}
.kb-footer.hidden { display: none !important; }

.kb-side { flex: 1 1 0; min-width: 0; }

.kb-center {
  display: flex;
  flex: 0 1 auto;
  flex-direction: column;
  width: min(680px, 100%);
  gap: 4px;
  min-width: 0;
}

.kb-row {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 4px;
}

.kb-key {
  display: flex;
  flex: 1 1 0;
  min-width: 20px;
  height: var(--tap);
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: none;
  border-radius: 4px;
  background: #eef1ef;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  font-weight: bold;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
}
.kb-key.single { font-size: 20px; }

.kb-key:active, .kb-key.pressed { background: #3b82f6 !important; color: #fff; }
.kb-key.action { background: #ef4444; color: #fff; }
.kb-key.func { background: #0284c7; color: #fff; }
.kb-key.shift-active { background: #f59e0b !important; color: #000; }
.kb-key.sign-active { background: #a855f7 !important; color: #fff; }
.kb-key.copied { background: #22c55e !important; color: #000 !important; }
.kb-key.flash { background: #3b82f6 !important; color: #fff; }

/* ---------- Pola edycyjne (div contenteditable) ---------- */
.editable {
  border: 1px solid #d1d5db;
  border-radius: 9px;
  background: var(--card);
  padding: 8px 10px;
  min-height: var(--tap);
  font-size: var(--size-static);
  line-height: 1.35;
  cursor: text;
  word-break: break-word;
}
.editable:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.editable.is-empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  font-size: 16px;
  pointer-events: none;
}
.main-line { display: flex; gap: 8px; align-items: stretch; }
.edit-wide { flex: 1; min-width: 0; }
.edit-num { width: 116px; flex: none; }
.date-btn { cursor: pointer; user-select: none; }

/* ---------- Podgląd produktów (pierwsza linia Dziennika) ---------- */
.sugg-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
}
.sugg-hint { color: var(--muted); font-size: 13px; }
.suggestions {
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 9px;
  background: var(--card);
  margin-bottom: 8px;
}
.sugg {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 0;
  border-bottom: 1px solid #f1f3f5;
  background: transparent;
  font-size: 18px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}
.sugg:last-child { border-bottom: 0; }
.sugg:active, .sugg:hover { background: #f0fdf4; }
.sugg-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sugg-kcal { flex: none; color: var(--muted); font-size: 15px; }

/* ---------- Kalendarz dwumiesięczny ---------- */
.cal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background: rgba(17, 24, 39, 0.5);
}
.cal-box {
  background: var(--card);
  border-radius: 14px;
  padding: 12px;
  width: min(740px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.cal-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
}
.cal-header select {
  min-height: var(--tap);
  font-size: 18px;
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
}
.cal-months {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
}
.cal-month { flex: 1 1 300px; min-width: 280px; max-width: 360px; }
.cal-title {
  text-align: center;
  font-size: var(--size-static);
  font-weight: 700;
  margin: 4px 0 6px;
}
.cal-dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.cal-pad { min-height: 44px; }
.cal-day {
  min-height: 44px;
  min-width: 44px;
  border: 0;
  border-radius: 9px;
  background: #f8fafc;
  font-size: var(--size-static);
  color: var(--text);
  cursor: pointer;
}
.cal-day:active { background: #e5e7eb; }
.cal-today { background: var(--accent); color: #fff; font-weight: 700; }
.cal-selected {
  background: #dcfce7;
  box-shadow: inset 0 0 0 2px var(--accent-dark);
  font-weight: 700;
}

