/* ---------- Kolory ---------- */

/* Akcenty: -l dla jasnego trybu, -d dla ciemnego. --ai-l to ciemniejszy odcień do tekstu na jasnym tle akcentu.
   Tekst na przycisku i na tle akcentu ma kontrast ≥ 4.5:1. */
:root,
:root[data-accent="green"] {
  --a-l: #24804e; --as-l: #e2f1e8; --ai-l: #1d6b41;
  --a-d: #4cbb7f; --as-d: #1f3529; --at-d: #0e1a13;
}
:root[data-accent="blue"] {
  --a-l: #2563c9; --as-l: #e3ecfb; --ai-l: #1f55ad;
  --a-d: #6ea8ff; --as-d: #1c2a42; --at-d: #0b1526;
}
:root[data-accent="violet"] {
  --a-l: #7046c9; --as-l: #ece6fa; --ai-l: #5f3bb0;
  --a-d: #b39dff; --as-d: #2a2342; --at-d: #1a1230;
}
:root[data-accent="orange"] {
  --a-l: #b84e08; --as-l: #fbe9dc; --ai-l: #9a4106;
  --a-d: #ff9f5a; --as-d: #3a2717; --at-d: #2a1405;
}
:root[data-accent="pink"] {
  --a-l: #c2307a; --as-l: #fae3ee; --ai-l: #a5276a;
  --a-d: #ff8cc6; --as-d: #3a1f2d; --at-d: #2d0b1c;
}

:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --text: #1d1f23;
  --muted: #6b6f78;
  --border: #e4e2dc;
  --danger: #c2413b;
  --done: #a3a6ad;
  --shadow: 0 1px 2px rgba(20, 20, 20, .05), 0 2px 8px rgba(20, 20, 20, .04);
  --backdrop: rgba(20, 20, 24, .35);
  --accent: var(--a-l);
  --accent-soft: var(--as-l);
  --accent-ink: var(--ai-l);
  --accent-text: #ffffff;
  --radius: 14px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #16181d;
  --surface: #1f2228;
  --surface-2: #272a31;
  --text: #eceef1;
  --muted: #9aa0aa;
  --border: #2e323a;
  --danger: #ef6b64;
  --done: #6a6f79;
  --shadow: none;
  --backdrop: rgba(0, 0, 0, .55);
  --accent: var(--a-d);
  --accent-soft: var(--as-d);
  --accent-ink: var(--a-d);
  --accent-text: var(--at-d);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181d;
    --surface: #1f2228;
    --surface-2: #272a31;
    --text: #eceef1;
    --muted: #9aa0aa;
    --border: #2e323a;
    --danger: #ef6b64;
    --done: #6a6f79;
    --shadow: none;
    --backdrop: rgba(0, 0, 0, .55);
    --accent: var(--a-d);
    --accent-soft: var(--as-d);
    --accent-ink: var(--a-d);
    --accent-text: var(--at-d);
    color-scheme: dark;
  }
}

/* ---------- Podstawy ---------- */

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(96px, env(safe-area-inset-bottom));
}

.muted { color: var(--muted); margin: 0; }
.center { text-align: center; }

/* ---------- Nagłówek ---------- */

.bar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  margin-bottom: 16px;
}

.bar h1 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-edit { cursor: text; }

/* ---------- Przyciski ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: transform .08s ease, opacity .15s ease;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 18px; height: 18px; }

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--accent-soft); color: var(--accent-ink); }
.btn-small { min-height: 40px; padding: 0 14px; font-size: 15px; flex-shrink: 0; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-danger, .btn-danger:hover { color: var(--danger); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}
.bar > .icon-btn:first-child { margin-left: -10px; }
.icon-btn-end { margin-right: -10px; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; }
#arrange svg { width: 22px; height: 22px; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Pola ---------- */

.add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.input-wrap { position: relative; flex: 1; min-width: 0; display: flex; }

.add-row input,
.rename-input,
.field input {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  outline: none;
}
.add-row input:focus,
.rename-input:focus,
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.add-row input::placeholder,
.field input::placeholder { color: var(--muted); }

.input-wrap input { padding-right: 52px; }
.input-wrap:has(#mic:not([hidden])) input { padding-right: 92px; }

.input-tools {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
}

.tool {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tool svg { width: 22px; height: 22px; }
.tool:hover { color: var(--accent); }
.tool.listening { background: var(--accent); color: var(--accent-text); animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-soft); }
  50% { box-shadow: 0 0 0 8px var(--accent-soft); }
}

.rename-input { font-size: 22px; font-weight: 700; min-height: 44px; }

/* ---------- Podpowiedzi ---------- */

.suggest { margin: -2px 0 14px; }
.suggest-label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -16px;
  padding: 0 16px 2px;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
}
.chip:active { transform: scale(.96); }
.chip-plus { color: var(--accent); font-weight: 700; }
.chip-qty { color: var(--muted); font-size: 13px; }

/* ---------- Karty list ---------- */

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.card:active { transform: scale(.99); }

.card-main { flex: 1; min-width: 0; }
.card-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.card-chev { width: 20px; height: 20px; color: var(--muted); flex-shrink: 0; }

.bar-track { height: 4px; border-radius: 2px; background: var(--border); margin-top: 8px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 2px; }

/* ---------- Działy i produkty ---------- */

.progress { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.progress:empty { display: none; }
.hint { margin: 0 0 12px; padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); color: var(--text); font-size: 14px; }

.groups { display: grid; gap: 14px; }

.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 32px;
  margin: 0 0 6px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
}
.group-head .emoji { font-size: 16px; }
.group-head .label { flex: 1; }
.group-head .count { font-weight: 500; }
button.group-head { cursor: pointer; }
.group-head .chev { width: 18px; height: 18px; transition: transform .15s ease; }
.group.collapsed .chev { transform: rotate(-90deg); }
.group.collapsed .items { display: none; }

.items {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.item {
  display: flex;
  align-items: center;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.item:first-child { border-top: 0; border-radius: var(--radius) var(--radius) 0 0; }
.item:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.item:only-child { border-radius: var(--radius); }

.item-toggle {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  min-height: 56px;
  padding: 8px 4px 8px 16px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.item-toggle:disabled { cursor: default; }

.check {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 2px solid var(--border);
  border-radius: 50%;
  transition: background .15s ease, border-color .15s ease;
}
.check svg { width: 16px; height: 16px; stroke: var(--accent-text); stroke-width: 3; opacity: 0; }

.item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.item-name { overflow-wrap: anywhere; }
.item-promo { color: var(--muted); font-size: 13px; line-height: 1.3; }
.item-promo.soon { color: var(--danger); font-weight: 600; }
.item-promo.expired { color: var(--done); }
.item.done .item-promo { color: var(--done); font-weight: 400; }
.item-qty {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 600;
}

.item.done .check { background: var(--accent); border-color: var(--accent); }
.item.done .check svg { opacity: 1; }
.item.done .item-name { color: var(--done); text-decoration: line-through; }
.item.done .item-qty { background: transparent; color: var(--done); }

.item-more,
.drag-handle {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 56px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.item-more svg { width: 20px; height: 20px; }
.item-more:hover { color: var(--text); }

.drag-handle {
  font-size: 22px;
  line-height: 1;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.group-head .drag-handle { width: 40px; height: 32px; margin-right: -4px; font-size: 18px; }

.dragging {
  position: relative;
  z-index: 5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  cursor: grabbing;
}
.item.dragging { border-radius: 12px; }
.sorting { user-select: none; -webkit-user-select: none; }

.list-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
}
.list-actions #delete-list { margin-left: auto; }

.empty {
  margin: 40px 0;
  color: var(--muted);
  text-align: center;
}

/* ---------- Panele (import, ustawienia) ---------- */

.panel {
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 4px; font-size: 22px; overflow-wrap: anywhere; }
.panel .panel-title { font-size: 15px; font-weight: 600; color: var(--muted); margin: 0 0 10px; }
.panel .panel-title:not(:first-child) { margin-top: 18px; }
.panel .muted + .stack { margin-top: 14px; }

.stack { display: flex; flex-direction: column; gap: 8px; }

.import-items {
  margin: 16px 0;
  padding-left: 20px;
  max-height: 45vh;
  overflow: auto;
}
.import-items li { padding: 3px 0; }
.import-items li.done { color: var(--done); text-decoration: line-through; }

.segmented {
  display: flex;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
}
.segmented button {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

.swatches { display: flex; gap: 14px; flex-wrap: wrap; }
.swatch {
  width: 44px;
  height: 44px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}
.swatch[aria-checked="true"] { box-shadow: 0 0 0 3px var(--text); }
.swatch[data-accent-value="green"] { background: #24804e; }
.swatch[data-accent-value="blue"] { background: #2563c9; }
.swatch[data-accent-value="violet"] { background: #7046c9; }
.swatch[data-accent-value="orange"] { background: #b84e08; }
.swatch[data-accent-value="pink"] { background: #c2307a; }

.footer-note { color: var(--muted); font-size: 13px; text-align: center; margin: 24px 0 0; }

/* ---------- Dolne panele (dialog) ---------- */

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  margin: auto auto 0;
  padding: 20px 16px max(20px, env(safe-area-inset-bottom));
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
  overflow: auto;
}
.sheet::backdrop { background: var(--backdrop); }
.sheet[open] { animation: sheet-in .2s ease-out; }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { margin: 0 0 16px; font-size: 20px; }

@media (min-width: 600px) {
  .sheet { margin: auto; border-radius: 20px; max-width: 480px; }
}

.field { display: block; margin: 0 0 14px; padding: 0; border: 0; }
.field > span,
.field > legend { display: block; margin-bottom: 6px; padding: 0; color: var(--muted); font-size: 14px; font-weight: 600; }

.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.cat-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.cat-option .emoji { font-size: 18px; }
.cat-option[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.sheet-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; }
.sheet-actions .btn-primary { flex: 1; max-width: 220px; margin-left: auto; }

.choices { display: grid; gap: 8px; margin-bottom: 16px; }
.choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.choice small { color: var(--muted); font-size: 14px; }
.choice[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.choice[aria-checked="true"] strong { color: var(--accent-ink); }
.choice:disabled { opacity: .45; cursor: default; }

.qr-box {
  width: min(100%, 320px);
  margin: 0 auto 12px;
  padding: 0;
  border-radius: 16px;
  overflow: hidden;
  background: #ffffff;
}
.qr-box svg { display: block; width: 100%; height: auto; stroke: none; }

/* ---------- Komunikat ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 10px 10px 18px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
  z-index: 20;
}
.toast:not(:has(.toast-undo:not([hidden]))) { padding-right: 18px; }
#toast-text { min-width: 0; overflow-wrap: anywhere; }
.toast-undo {
  flex-shrink: 0;
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--bg);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- Promocja w edycji produktu ---------- */

.promo-fields { margin-top: 4px; }
.promo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.promo-grid .field { margin-bottom: 10px; }
.field input[type="date"] { min-height: 48px; padding: 0 10px; }

/* ---------- Panel: z gazetki ---------- */

.scan-loading { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.scan-loading p { margin: 0; }
.scan-thumb {
  width: 72px;
  height: 120px;
  object-fit: cover;
  object-position: top;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}
.spinner {
  width: 26px;
  height: 26px;
  margin-bottom: 8px;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.scan-error {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
}
#scan-hint { margin-bottom: 8px; }

.scan-results {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  max-height: 50vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.scan-results:empty { display: none; }
.scan-results li + li { border-top: 1px solid var(--border); }
.scan-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 8px 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.scan-row[aria-checked="true"] { background: var(--accent-soft); }
.scan-row[aria-checked="true"] .check { background: var(--accent); border-color: var(--accent); }
.scan-row[aria-checked="true"] .check svg { opacity: 1; }

.footnote { margin: 14px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

/* ---------- Kod rodzinny ---------- */

.code-row { margin: 14px 0 0; }
.code-status { margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.code-status:empty { display: none; }
.code-status.ok { color: var(--accent-ink); font-weight: 600; }
.code-status.bad { color: var(--danger); font-weight: 600; }
