:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #16a34a;
  --primary-dark: #15803d;
  --danger: #dc2626;
  --warn-bg: #fef2f2;
  --warn-border: #fca5a5;
  --border: #e2e8f0;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --mode-add: #16a34a;
  --mode-add-dark: #15803d;
  --mode-remove: #ea580c;
  --mode-remove-dark: #c2410c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  overscroll-behavior-y: none;
}

#app, .app { min-height: 100vh; }

.screen {
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: calc(96px + var(--safe-bottom));
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 19px; margin: 0; flex: 1; text-align: center; }
.topbar-dark { background: #111827; color: #fff; border-bottom: none; }
.topbar-dark .icon-btn { color: #fff; }

.icon-btn {
  background: none;
  border: none;
  font-size: 22px;
  padding: 8px;
  cursor: pointer;
  line-height: 1;
  min-width: 40px;
}

.banner {
  margin: 12px 16px 0;
  padding: 14px 16px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: #991b1b;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.hidden { display: none !important; }

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px;
}
@media (min-width: 600px) {
  .tiles { grid-template-columns: 1fr 1fr 1fr; }
}

.tile {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 14px;
  text-align: left;
  border: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 108px;
}
.tile-icon { font-size: 30px; }
.tile-name { font-weight: 700; font-size: 15px; }
.tile-count { font-size: 13px; color: var(--muted); }

.tile-low { color: #fff; }
.tile-low .tile-count { color: rgba(255,255,255,0.85); }
.tile-low.low-bad { background: linear-gradient(135deg, #ef4444, #dc2626); }
.tile-low.low-ok { background: linear-gradient(135deg, #22c55e, #16a34a); }

.fab-row {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 16px;
  z-index: 20;
}
.fab {
  border: none;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  font-size: 26px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab-primary { background: var(--primary); color: #fff; }
.fab-secondary { background: var(--card); color: var(--text); border: 1px solid var(--border); }

.search-bar { padding: 12px 16px 0; }
.search-bar input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 16px;
  background: var(--card);
}

.product-list { padding: 12px 16px 0; display: flex; flex-direction: column; gap: 10px; }

.product-row {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  gap: 10px;
}
.product-row.low { border: 1.5px solid var(--warn-border); background: var(--warn-bg); }
.product-info { flex: 1; min-width: 0; cursor: pointer; }
.product-name { font-weight: 600; font-size: 15px; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.qty { color: var(--muted); font-size: 14px; }
.warn-badge { color: #991b1b; font-size: 12px; font-weight: 700; }

.stepper { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.step-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.step-minus { background: #fee2e2; color: #b91c1c; }
.step-plus { background: #dcfce7; color: #15803d; }
.stepper-lg .step-btn { width: 56px; height: 56px; font-size: 30px; }

.empty-state { text-align: center; color: var(--muted); padding: 40px 20px; }

/* Login */
.screen-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}
.login-logo { font-size: 48px; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.muted { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.pin-input {
  width: 100%;
  font-size: 28px;
  letter-spacing: 8px;
  text-align: center;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-block { width: 100%; }
.btn-lg { padding: 16px; font-size: 17px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: #fee2e2; color: var(--danger); }

.error { color: var(--danger); font-size: 14px; min-height: 18px; margin: 4px 0; }

/* Forms */
.form { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.form input, .form select, .form textarea {
  font-size: 16px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-family: inherit;
  color: var(--text);
  background: var(--card);
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-inline { display: flex; gap: 8px; }
.row-inline input { flex: 1; }
.row-inline .btn { flex-shrink: 0; padding: 12px 16px; }
.form-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.notice { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.notice-error { background: var(--warn-bg); border-color: var(--warn-border); color: #991b1b; }

/* Scanner */
.screen-scanner { background: #111827; min-height: 100vh; padding-bottom: 20px; }
#reader { width: 100%; max-width: 480px; margin: 20px auto 0; }
#reader video { border-radius: 12px; }
.scanner-hint { text-align: center; color: #d1d5db; font-size: 14px; margin-top: 16px; }
.scanner-debug { text-align: center; color: #6b7280; font-size: 12px; margin-top: 6px; min-height: 16px; }

/* Scan result */
.scan-result-card { padding: 24px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.scan-result-icon { font-size: 48px; }
.scan-result-name { font-size: 20px; font-weight: 700; }
.scan-result-qty { color: var(--muted); font-size: 15px; margin-bottom: 8px; }
.scan-result-card .stepper { margin: 16px 0 24px; gap: 24px; }

/* Settings */
.settings-section { padding: 16px; }
.settings-section h2 { font-size: 16px; margin: 0 0 12px; }
.category-manage-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.category-manage-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.category-manage-row .cat-icon { font-size: 22px; }
.category-manage-row .cat-name { flex: 1; font-weight: 600; }
.category-manage-row .cat-swatch { width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
}
.modal {
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
@media (min-width: 600px) {
  .modal { border-radius: 16px; }
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.modal input { font-size: 16px; padding: 12px; border-radius: 10px; border: 1px solid var(--border); }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn { flex: 1; }

/* Mode action buttons (dashboard: Dodaj / Zdejmij) */
.mode-action-row {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 20;
}
.mode-action {
  flex: 1;
  max-width: 260px;
  border: none;
  border-radius: 16px;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
}
.mode-action-icon { font-size: 26px; }
.mode-action-label { font-size: 16px; font-weight: 700; }
.mode-action-add { background: linear-gradient(135deg, var(--mode-add), var(--mode-add-dark)); }
.mode-action-remove { background: linear-gradient(135deg, var(--mode-remove), var(--mode-remove-dark)); }

/* Colored mode headers */
.topbar-add { background: var(--mode-add); color: #fff; border-bottom: none; }
.topbar-remove { background: var(--mode-remove); color: #fff; border-bottom: none; }
.topbar-add .icon-btn, .topbar-remove .icon-btn { color: #fff; }

/* Mode chooser screen */
.mode-choice {
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 420px;
  margin: 0 auto;
}
.mode-choice-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.mode-choice-icon { font-size: 36px; }

/* Manual pick list */
.mode-pick-row {
  width: 100%;
  text-align: left;
  border: none;
  font-family: inherit;
  cursor: pointer;
}
.mode-pick-arrow { font-size: 22px; color: var(--muted); flex-shrink: 0; }
.mode-pick-new { padding: 12px 16px calc(16px + var(--safe-bottom)); }

/* Quantity operation card */
.qty-card {
  padding: 28px 20px;
  max-width: 420px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}
.qty-icon { font-size: 46px; }
.qty-name { font-size: 20px; font-weight: 700; }
.qty-current { color: var(--muted); font-size: 15px; margin-bottom: 12px; }
#qty-op-section, #qty-result-section { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.qty-chips { display: flex; gap: 10px; justify-content: center; }
.qty-chip {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
}
.qty-chip.active { color: #fff; border-color: transparent; }
.qty-amount-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-align: left;
}
.qty-amount-label input {
  font-size: 22px;
  text-align: center;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.qty-result-message { font-size: 18px; font-weight: 700; }
.qty-result-warning { color: #991b1b; background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 10px; padding: 10px; font-weight: 600; }
.qty-result-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.btn-mode-add { background: var(--mode-add); color: #fff; }
.btn-mode-add:active { background: var(--mode-add-dark); }
.btn-mode-remove { background: var(--mode-remove); color: #fff; }
.btn-mode-remove:active { background: var(--mode-remove-dark); }
.qty-chip.chip-add { background: var(--mode-add); }
.qty-chip.chip-remove { background: var(--mode-remove); }
