:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1a1d29;
  --muted: #6b7280;
  --accent: #0b6cf2;
  --accent-dark: #084fb5;
  --line: #e5e7eb;
  --danger: #dc2626;
  --ok: #16a34a;
  --footer-h: 84px;
}

* { 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 Neue", Arial, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  padding-bottom: calc(var(--footer-h) + env(safe-area-inset-bottom));
}

.topbar {
  background: var(--accent);
  color: #fff;
  padding: 14px 18px calc(14px + env(safe-area-inset-top));
  padding-top: calc(14px + env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: 0.2px; }
.subtitle { font-size: 13px; opacity: 0.88; }

main { padding: 14px; max-width: 720px; margin: 0 auto; }

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.card h2 {
  font-size: 16px;
  margin: 0 0 12px;
  color: var(--text);
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.field { display: block; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
input[type="text"], input[type="date"], input[type="number"], textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11,108,242,0.15);
}
textarea { resize: vertical; min-height: 70px; }

/* Anyag tétel sor */
.item-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.item-row:last-child { border-bottom: none; }
.item-info { min-width: 0; }
.item-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.item-meta {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
}

.qty-control {
  display: flex;
  align-items: center;
  gap: 4px;
}
.qty-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  flex-shrink: 0;
}
.qty-btn:active { background: #eef4ff; transform: scale(0.95); }
.qty-btn[disabled] {
  color: #c5c8d0;
  background: #f5f6fa;
  cursor: not-allowed;
}
.qty-control .qty-input {
  flex: 0 0 44px;
  width: 44px;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  padding: 6px 2px;
}
.qty-input.has-value {
  background: #eef4ff;
  border-color: var(--accent);
  color: var(--accent);
}

/* Scan row (klíma gyári szám + kamera gomb) */
.scan-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: stretch;
}
.scan-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 0 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.scan-btn:active { background: #eef4ff; }
.scan-btn svg { flex-shrink: 0; }
@media (max-width: 380px) {
  .scan-btn span { display: none; }
  .scan-btn { padding: 0 12px; }
}

/* Scanner overlay */
.scanner-overlay { padding: 0; }
.scanner-card {
  background: #000;
  width: 100%;
  height: 100%;
  max-width: none;
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.scanner-header {
  background: #111;
  color: #fff;
  padding: 14px 18px calc(14px + env(safe-area-inset-top));
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 600;
}
.scanner-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  padding: 0 8px;
}
#scanner-reader {
  flex: 1;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#scanner-reader video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}
.scanner-hint {
  background: #111;
  color: #fff;
  text-align: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  font-size: 14px;
  opacity: 0.9;
}

/* Klíma row */
.klima-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 8px;
  align-items: stretch;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.klima-row:last-of-type { border-bottom: none; }
.klima-sn {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  margin-top: 6px;
}
.klima-sn .sn-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.klima-sn .sn-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11,108,242,0.15);
}
.klima-sn .scan-btn {
  padding: 0 10px;
  font-size: 13px;
}
.klima-sn .scan-btn span { display: none; }
.klima-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 32px 12px 12px;
  font-size: 15px;
  font-family: inherit;
  background: #fff
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%236b7280' d='M0 0l5 6 5-6z'/></svg>")
    no-repeat right 12px center;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
}
.klima-row select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11,108,242,0.15);
}
.klima-row .klima-qty {
  grid-column: 1 / -1;
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
.klima-row .qty-input {
  flex: 0 0 60px;
  width: 60px;
  padding: 10px 4px;
  text-align: center;
}
.klima-line {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  padding-top: 4px;
}
.klima-line .line-total {
  font-weight: 600;
  color: var(--accent);
}
.remove-klima {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
}

.ghost-btn {
  width: 100%;
  background: none;
  border: 1px dashed var(--accent);
  color: var(--accent);
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  font-weight: 500;
  margin-top: 10px;
  cursor: pointer;
}
.ghost-btn:active { background: #eef4ff; }

/* Footer bar */
.footer-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
  z-index: 10;
}
.total { display: flex; flex-direction: column; }
.total-label { font-size: 12px; color: var(--muted); }
.total-amount { font-size: 22px; font-weight: 700; color: var(--text); }

.submit-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px 22px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.submit-btn:active { background: var(--accent-dark); }
.submit-btn[disabled] { background: #9aa3b2; cursor: wait; }

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 24px;
}
.overlay[hidden] { display: none; }
.overlay-card {
  background: #fff;
  border-radius: 16px;
  padding: 28px 22px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.overlay-card h2 { margin: 12px 0 6px; font-size: 20px; }
.overlay-card p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.check {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--ok);
  color: #fff;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 700;
}
.check.err { background: var(--danger); }

@media (min-width: 600px) {
  .item-row { grid-template-columns: 1fr auto; }
  .qty-control .qty-input { flex-basis: 64px; width: 64px; }
}
