:root {
  --bg: #f4f7f4;
  --panel: #ffffff;
  --ink: #17331c;
  --muted: #5b7260;
  --line: #d3e0d5;
  --accent: #196625;
  --gold: #196625;
  --ok: #196625;
  --input-bg: #ffffff;
  --surface: #eef5ef;
  --stock-bg: #e8f4ea;
  --print-bg: #f3f8f4;
  --ok-text: #14521e;
  --warn-bg: #fff6e5;
  --warn-text: #8a5a10;
  --err-bg: #fdeeee;
  --err-text: #b42318;
  --scale: 5.2;
  --theme: #196625;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: "IBM Plex Sans", system-ui, sans-serif; }
html { -webkit-text-size-adjust: 100%; }
a { color: var(--gold); }
.app { max-width: 1240px; margin: 0 auto; padding: 22px 18px max(56px, env(safe-area-inset-bottom)); }
.top { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 20px; }
.eyebrow { margin: 0; letter-spacing: .14em; text-transform: uppercase; font-size: 11px; color: var(--gold); }
h1 { margin: 4px 0 8px; font-size: 30px; }
.sub { margin: 0; color: var(--muted); max-width: 540px; }
.printer-bar, .sizes { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
label { display: grid; gap: 5px; font-size: 12px; color: var(--muted); }
input, button { font: inherit; font-size: 16px; border-radius: 10px; border: 1px solid var(--line); min-height: 44px; }
input { background: var(--input-bg); color: var(--ink); padding: 9px 11px; width: 100%; }
#printerIp, #tillIp { width: 148px; }
#printerPort, #tillPort, #widthMm, #heightMm { width: 78px; }
.search { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.search input { flex: 1 1 160px; width: auto; min-width: 0; }
.search-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.search-actions button[type="submit"] { flex: 1 1 auto; }
.scan-btn {
  min-width: 88px; padding: 0 12px;
  background: var(--input-bg); color: var(--gold); border: 1px solid var(--gold);
}
.scanner-modal {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.82);
  display: grid; place-items: center; padding: 16px;
}
.scanner-modal[hidden] { display: none !important; }
.scanner-box {
  width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 16px; display: grid; gap: 12px;
}
.scanner-box p { margin: 0; text-align: center; }
#qrReader { width: 100%; min-height: 240px; overflow: hidden; border-radius: 12px; background: #000; }
.scanner-box button { width: 100%; }
.perm-box { gap: 10px; }
.perm-box h2 { margin: 0; text-align: center; font-size: 20px; }
.perm-box p { text-align: left; color: var(--ink); }
.perm-chip { min-height: 44px; padding: 8px 12px; }
.perm-chip.need { border-color: var(--gold); color: var(--gold); }
.flush-btn {
  min-height: 44px; padding: 8px 14px; border-radius: 10px;
  font-weight: 700; white-space: nowrap;
}
.till-open-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 52px; min-width: 140px; padding: 10px 22px;
  font-size: 18px; font-weight: 800; letter-spacing: .04em;
  text-transform: uppercase; background: var(--accent); color: #fff !important;
  text-decoration: none; border-radius: 10px; border: 0;
}
.till-screen {
  position: fixed; inset: 0; z-index: 35;
  background: var(--bg); overflow: auto;
  padding: 16px 16px max(24px, env(safe-area-inset-bottom));
}
.till-screen[hidden] { display: none !important; }
.till-page {
  position: relative; inset: auto; min-height: 100vh; z-index: 1;
  background: var(--bg);
}
.till-head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.till-head-actions .logout {
  min-height: 44px; display: inline-flex; align-items: center;
  padding: 8px 14px; border-radius: 10px; text-decoration: none;
}
.till-inner { max-width: 560px; margin: 0 auto; display: grid; gap: 12px; }
.till-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.till-head h2 { margin: 4px 0 0; font-size: 28px; }
.till-lines { display: grid; gap: 8px; }
.till-cols {
  display: grid; grid-template-columns: 1fr 4.2rem 4.4rem 4.4rem 44px;
  gap: 8px; padding: 0 12px; font-size: 11px; color: var(--muted); font-weight: 700;
}
.till-cols span:nth-child(n+2) { text-align: right; }
.till-line {
  display: grid; grid-template-columns: 1fr 4.2rem 4.4rem 4.4rem 44px; gap: 8px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
}
.till-unit, .till-amt { text-align: right; font-size: 13px; font-weight: 700; }
.till-line strong { display: block; font-size: 14px; }
.till-line span { display: block; color: var(--muted); font-size: 12px; }
.till-line-qty {
  width: 4.2rem; min-height: 40px; text-align: center; font-weight: 700;
}
.till-search { display: flex; gap: 8px; align-items: stretch; }
.till-search #tillQ { flex: 1 1 auto; }
.till-wait {
  caret-color: var(--accent);
  border-color: var(--gold) !important;
  animation: till-wait-pulse 1.1s ease-in-out infinite;
}
@keyframes till-wait-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(25, 102, 37, .18); }
  50% { box-shadow: 0 0 0 6px rgba(25, 102, 37, .38); }
}
.till-line-del {
  min-width: 44px; min-height: 44px; padding: 8px;
  color: var(--err-text); border-color: #f0c9c6;
  display: grid; place-items: center;
}
.till-line-del svg { width: 22px; height: 22px; display: block; }
.till-grand {
  margin: 0; text-align: center; font-size: 22px; font-weight: 800;
  padding: 12px; border-top: 2px dashed var(--ink);
}
.till-actions { display: grid; gap: 8px; }
.till-actions button { width: 100%; }
button { background: var(--accent); color: #fff; padding: 10px 16px; cursor: pointer; font-weight: 600; border: 0; }
button:disabled { opacity: .4; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.is-office .admin-only { display: none !important; }
.is-office .field { cursor: default; pointer-events: none; }
.is-office .field.active { outline: none; }
@media (max-width: 980px) { .grid { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.status { color: var(--muted); font-size: 13px; }
.auto { display: flex; flex-direction: row; align-items: center; gap: 8px; margin: 8px 0 12px; color: var(--ink); }
.auto input { width: auto; }
.results { display: grid; gap: 8px; max-height: min(40vh, 360px); overflow: auto; }
.results[hidden] { display: none !important; }
.found-bar {
  display: none; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 14px; line-height: 1.3;
  overflow-wrap: anywhere;
}
.found-bar.is-on { display: block; }
.found-bar strong { display: block; }
.found-bar span { display: block; color: var(--muted); font-size: 13px; }
.result-block { display: grid; gap: 10px; }
.action-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-items: stretch; margin-top: 14px; }
.action-panel[hidden] { display: none !important; }
.job-card {
  padding: 10px; border-radius: 12px; display: grid; gap: 8px; min-width: 0;
}
.job-card h3 {
  margin: 0; font-size: 14px; display: flex; justify-content: space-between;
  align-items: baseline; gap: 8px;
}
.stock-inline { font-weight: 700; color: var(--ok-text); }
.stock-inline.low { color: var(--warn-text); }
.stock-inline.out { color: var(--err-text); }
.job-help { margin: 0; font-size: 12px; color: var(--muted); }
.stock-card { border: 1px solid var(--ok); background: var(--stock-bg); }
.print-card { border: 1px solid var(--gold); background: var(--print-bg); }
.till-card { grid-column: 1 / -1; border: 1px solid var(--gold); background: var(--print-bg); }
.stock-edit, .print-edit { display: grid; gap: 8px; align-items: stretch; min-width: 0; }
.stock-edit { grid-template-columns: minmax(0, 1fr) auto; }
.print-edit { grid-template-columns: 4.5rem minmax(0, 1fr); }
.print-edit-stack { grid-template-columns: 4.5rem 1fr; }
.print-edit-stack #copies { grid-column: 1; }
.print-edit-stack #printBtn32 { grid-column: 2; }
.print-edit-stack #printBtn { grid-column: 1 / -1; }
.print-edit-till { grid-template-columns: 4.5rem minmax(0, 1fr); }
.print-edit-till #tillQty { grid-column: 1; }
.print-edit-till #tillBtn { grid-column: 2; }
.print-edit-till #tillOsBtn { grid-column: 1 / -1; }
.stock-edit button, .print-edit button { min-width: 0; padding: 10px 10px; white-space: nowrap; font-size: 15px; }
.lan-print-btn { width: 100%; }
.lan-trust { display: inline-block; margin-top: 6px; }
.stock-box {
  font-weight: 700; font-size: 16px; padding: 8px 12px; border-radius: 10px;
  background: var(--stock-bg); color: var(--ok-text); min-width: 140px;
}
.stock-box.low { background: var(--warn-bg); color: var(--warn-text); }
.stock-box.out { background: var(--err-bg); color: var(--err-text); }
.item .stock {
  font-size: 12px; font-weight: 700; margin-top: 4px;
}
.item .stock.ok { color: var(--ok-text); }
.item .stock.low { color: var(--warn-text); }
.item .stock.out { color: var(--err-text); }
.item { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--surface); }
.item:hover, .item.active { border-color: var(--gold); }
.item img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; background: #111; }
.item h3 { margin: 0; font-size: 14px; font-weight: 600; }
.item p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.item .p { font-weight: 700; color: var(--gold); white-space: nowrap; }
.preview-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.preview-wrap { display: flex; flex-direction: column; gap: 10px; }
.preview-wrap h2 { margin: 0; font-size: 16px; }
.label-stack { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.stage {
  margin: 0; padding: 0; width: 100%; background: #fff; border-radius: 10px;
  overflow: hidden; line-height: 0; border: 1px solid var(--line);
}
.product-photo { margin: 0; padding: 0; width: 100%; display: none; }
.product-photo.is-on { display: block; }
.product-photo img {
  width: 100%; aspect-ratio: 1; object-fit: contain;
  background: #fff; border-radius: 10px; border: 1px solid var(--line);
  display: block;
}
.label {
  position: relative; width: 100%; background: #fff; color: #111; overflow: hidden; user-select: none;
  font-family: Verdana, Geneva, sans-serif;
}
.field {
  position: absolute; cursor: grab; white-space: nowrap; line-height: 1.1;
  padding: 0; margin: 0;
}
.field.dragging { cursor: grabbing; }
.field.active { outline: 1px dashed #c43c2c; outline-offset: 1px; }
#f-shop { letter-spacing: .12em; font-weight: 700; }
#f-price { font-weight: 400; }
#f-code, #f-name, #f-shop, #f-price { font-family: Verdana, Geneva, sans-serif; }
#f-name { white-space: normal; overflow: hidden; }
.barcode-wrap { display: flex; align-items: stretch; touch-action: none; }
.barcode-wrap svg { width: 100%; height: 100%; display: block; pointer-events: none; }
.field-editor { display: grid; gap: 8px; margin-top: 12px; }
.row { display: grid; grid-template-columns: 92px 1fr 1fr 1fr 1fr auto; gap: 8px; align-items: center; font-size: 12px; }
.row input[type="number"] { width: 100%; padding: 6px 8px; }
.row .on { width: auto; }
.agent { font-size: 12px; padding: 8px 10px; border-radius: 999px; border: 1px solid var(--line); }
.agent.on { color: var(--ok-text); border-color: var(--ok); }
.agent.off { color: var(--err-text); }
.actions { display: flex; gap: 8px; margin: 16px 0 8px; flex-wrap: wrap; }
.hint { font-size: 12px; color: var(--muted); }
.hint:empty { display: none; }
.meta { display: grid; grid-template-columns: 90px 1fr; gap: 4px 10px; font-size: 13px; color: var(--muted); margin: 0; }
.meta:empty { display: none; }
.ok { color: var(--ok-text); }
.err { color: var(--err-text); }
.logout { color: var(--muted); font-size: 13px; align-self: end; padding: 10px 4px; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px; display: grid; gap: 12px;
}
.login-logo {
  display: block; width: min(220px, 80%); height: auto; margin: 0 auto 4px;
}
.login-card h1 { margin: 0; text-align: center; }
.login-card input { width: 100%; }
.login-card button { margin-top: 8px; }
.remember {
  display: flex; flex-direction: row; align-items: center; gap: 10px;
  font-size: 15px; color: var(--ink); cursor: pointer;
}
.remember input { width: auto; min-height: 22px; accent-color: var(--accent); }
.powered-by {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: .35rem .45rem;
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--muted);
}
.powered-by-label { opacity: .85; }
.powered-by-link {
  color: inherit;
  font-weight: 800;
  letter-spacing: .08em;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  border-bottom-color: rgba(25, 102, 37, .35);
  padding-bottom: 1px;
}
.powered-by-link:hover,
.powered-by-link:focus-visible {
  color: var(--accent);
  border-bottom-color: var(--accent);
  outline: none;
}
.powered-by--login {
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.login-till {
  margin: 12px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.download-card { width: min(480px, 100%); }
.download-steps { margin: 0; padding-left: 22px; color: var(--ink); line-height: 1.55; }
.download-steps li { margin: 6px 0; }
.download-btn {
  display: block; text-align: center; background: var(--accent); color: #fff !important;
  text-decoration: none; font-weight: 600; padding: 12px 16px; border-radius: 10px;
  min-height: 44px; line-height: 20px;
}

@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr; }
  .app { padding: 14px 12px max(24px, env(safe-area-inset-bottom)); }
  h1 { font-size: 24px; }
  .sub { font-size: 14px; }
  .panel { min-height: 0; padding: 14px; }
  .search { flex-direction: column; }
  .search-actions { width: 100%; }
  .search-actions button[type="submit"] { flex: 1; }
  .scan-btn { min-width: 96px; }
  .action-panel { grid-template-columns: 1fr; }
  .item { grid-template-columns: 64px 1fr; }
  .item .p { grid-column: 2; }
  .row { grid-template-columns: 1fr 1fr; }
  .printer-bar { width: 100%; }
  .logout { min-height: 44px; display: inline-flex; align-items: center; }
}

.print-root { display: none; }
@media print {
  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  body > *:not(.print-root) { display: none !important; }
  .print-root { display: block !important; }
  .print-root img {
    width: var(--label-w, 75mm); height: var(--label-h, 25mm);
    display: block; page-break-after: always;
  }
  @page { size: var(--label-w, 75mm) var(--label-h, 25mm); margin: 0; }
}
