:root {
  color-scheme: dark;
  font: 16px/1.4 Inter, "Segoe UI", Arial, sans-serif;
  color: #f3f6f8;
  background: #0b0e11;
  --panel: #12171c;
  --panel-2: #171d23;
  --line: #2b343d;
  --muted: #8f9aa7;
  --accent: #d7ff3f;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #0b0e11; }
html, body { height: 100dvh; overflow: hidden; overscroll-behavior: none; touch-action: pan-y; }
button, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
html.camera-scanning, html.camera-scanning body { background: transparent !important; }
html.camera-scanning body > *:not(#camera-overlay) { visibility: hidden !important; }
#camera-overlay { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; color: #fff; }
.camera-window { position: relative; width: min(82vw, 680px); height: min(30vh, 280px); border: 4px solid #fff; border-radius: 14px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.55); overflow: hidden; }
.camera-window video { width: 100%; height: 100%; object-fit: cover; }
.camera-window i { position: absolute; z-index: 1; left: 4%; right: 4%; top: 20%; height: 3px; background: #ff3b30; box-shadow: 0 0 12px #ff3b30; animation: scan-line 1.5s ease-in-out infinite alternate; }
#camera-hint { position: relative; margin: 0; font-size: 1.25rem; text-shadow: 0 1px 4px #000; }
#camera-cancel { position: relative; min-width: 180px; background: rgba(0,0,0,.55); }
@keyframes scan-line { to { top: 80%; } }

header {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: #101419;
}
.brand-stack { min-width: 0; display: grid; gap: 1px; margin-right: auto; }
.brand { font-size: 1.08rem; font-weight: 900; letter-spacing: -.03em; }
.brand strong { color: #7b2033; transition: color .15s ease; }
.brand strong.connected { color: var(--accent); }
.brand span { color: var(--muted); font-weight: 650; }
.app-version { margin-left: 3px; color: #71808e; font-size: .58rem; font-weight: 650; letter-spacing: 0; vertical-align: baseline; }
.bridge-state { color: var(--muted); font-size: .72rem; line-height: 1.1; white-space: nowrap; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 9px; color: #e5eaf0; background: var(--panel-2); font-size: 1.25rem; }
.icon-button svg { display: block; width: 100%; height: 100%; }
#refresh-label-data svg { width: 22px; height: 22px; margin: auto; fill: none; }
#refresh-label-data.refreshing svg { animation: refresh-spin .8s linear infinite; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }

main { height: calc(100dvh - 64px); min-height: 0; display: flex; flex-direction: column; padding: 16px; overflow: hidden; }
.scanner { margin-bottom: 16px; }
main > .scanner { flex: 0 0 auto; }
.mobile-only-workspace-search { display: none; }
.search-field { position: relative; }
input { border: 1px solid #38434d; border-radius: 8px; color: #fff; background: #080b0e; padding: 12px 14px; outline: none; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(215,255,63,.08); }
.scanner input { width: 100%; min-height: 58px; padding-right: 68px; font-size: 1.05rem; }
.scan-icon-button { position: absolute; inset: 7px 7px 7px auto; width: 44px; border: 1px solid var(--line); border-radius: 7px; color: var(--accent); background: #171e24; padding: 10px; }
.scan-icon-button svg { display: block; width: 100%; height: 100%; fill: currentColor; }
.scan-icon-button:hover { border-color: var(--accent); background: #202930; }
.primary, .secondary { min-height: 46px; border-radius: 8px; padding: 10px 16px; font-weight: 800; }
.primary { border: 0; color: #182007; background: var(--accent); }
.primary:hover { background: #e4ff79; }
.secondary { border: 1px solid var(--line); color: #e4e9ee; background: #181f25; }
.secondary:hover { border-color: #596571; }
button:disabled { opacity: .45; cursor: default; }

.workspace { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, .75fr); align-items: stretch; gap: 16px; min-height: 0; flex: 1 1 auto; overflow: hidden; }
.panel { border: 1px solid var(--line); border-radius: 11px; background: var(--panel); overflow: hidden; }
.panel h2 { margin: 0; font-size: 1rem; }
.inventory { min-height: 0; height: 100%; display: flex; flex-direction: column; }
#result-count { color: var(--muted); font-size: .75rem; text-align: center !important; text-transform: none; letter-spacing: 0; }
.table-wrap { position: relative; min-height: 0; flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid #232b33; text-align: left; }
th { color: #7e8b98; font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; }
td { color: #c4ccd4; font-size: .86rem; }
td:first-child { min-width: 180px; }
.item-cell { display: grid; gap: 1px; }
.item-name { color: #f2f5f7; font-weight: 650; }
.item-barcode { color: #7f8b97; font-size: .72rem; }
td:last-child { color: #f3f6f8; font-weight: 700; white-space: nowrap; text-align: right; }
th:last-child { text-align: right; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #182027; }
tbody tr.selected { background: #202819; box-shadow: inset 3px 0 var(--accent); }
tbody tr::selection { background: transparent; }
.empty { position: absolute; inset: 60px 0 0; display: grid; place-content: center; justify-items: center; color: var(--muted); text-align: center; }
.empty strong { color: #b8c1ca; }
.empty p { margin: 6px 0; font-size: .82rem; }

.label-setup { min-height: 0; height: 100px; align-self: end; padding: 5px 14px 0; overflow: hidden; overscroll-behavior: contain; position: relative; transition: height .2s ease, min-height .2s ease; }
.label-setup:not(.has-preview) { height: 100px; }
#print-button.print-working { background: #8fa800; }
#print-button.print-success { background: #75d66b; }
#print-button.print-error { color: #fff; background: var(--accent); }
.copies { display: grid; gap: 5px; align-items: end; justify-items: center; margin-left: auto; color: #b3bdc6; font-size: .75rem; font-weight: 700; text-align: center; }
.copies input { width: 78px; min-height: 36px; height: 36px; padding: 6px 10px; text-align: center; }
.toggle { display: flex; gap: 12px; align-items: center; min-width: 0; padding: 13px; border: 1px solid var(--line); border-radius: 9px; background: #0e1317; }
.toggle-copy { display: grid; min-width: 0; gap: 2px; }
.toggle small { color: var(--muted); font-size: .7rem; }
input[type="checkbox"] { accent-color: var(--accent); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 10px; }
.print-actions { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: end; gap: 10px; }
.print-actions .copies { margin: 0; }
.print-actions #print-button { min-height: 58px; }
.preview-resize-handle { width: 100%; height: 28px; min-height: 28px; margin: -5px 0 2px; padding: 0; border: 0; background: transparent; cursor: ns-resize; touch-action: manipulation; }
.preview-resize-handle span { position: relative; display: block; width: 54px; height: 12px; margin: auto; }
.preview-resize-handle span::before,
.preview-resize-handle span::after { content: ""; position: absolute; left: 0; width: 100%; height: 3px; border-radius: 4px; background: #5e6974; }
.preview-resize-handle span::before { top: 1px; }
.preview-resize-handle span::after { bottom: 1px; }
.preview-resize-handle.expanded span::before,
.preview-resize-handle.expanded span::after { background: var(--accent); }
.label-setup.preview-expanded { position: fixed; z-index: 100; left: 16px; right: 16px; bottom: 16px; width: auto; height: min(72dvh, 660px); min-height: 0; overflow-y: auto; box-shadow: 0 -12px 40px rgba(0,0,0,.6); will-change: transform, opacity; }
.label-setup.preview-expanded .label-render-preview { display: block !important; }
.label-setup.preview-expanded:not(.has-preview) { height: min(72dvh, 660px); }
.label-setup.preview-expanded .label-render-preview { max-height: none; overflow: visible; }
.preview-resize-handle span { transition: background .18s ease, width .18s ease; }
.preview-resize-handle.expanded span { width: 68px; }
@media (prefers-reduced-motion: reduce) {
  .preview-resize-handle span { transition: none; }
}
.pending-edits-button { margin-top: 6px; }
.pending-edit-list { display: grid; gap: 9px; max-height: min(46vh, 420px); overflow-y: auto; }
.pending-edit { display: grid; gap: 5px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: #0b1014; }
.pending-edit-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.pending-edit-name { min-width: 0; font-weight: 800; overflow-wrap: anywhere; }
.pending-edit-change { color: var(--muted); font-size: .78rem; }
.pending-edit-change strong { color: #fff; }
.remove-pending-edit { flex: 0 0 auto; width: 30px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 6px; color: #ff9d9d; background: transparent; }
.confirm-edit { display: flex; align-items: flex-start; gap: 10px; }
.label-render-preview { min-height: 0; margin-top: 8px; max-height: calc(100% - 118px); overflow-y: auto; overscroll-behavior: contain; }
.label-setup:not(.preview-expanded) .label-render-preview { display: none !important; }
.label-preview-caption { display: block; margin-bottom: 8px; color: #788491; font-size: .65rem; font-weight: 850; letter-spacing: .12em; }
.rendered-labels { display: grid; gap: 10px; }
.rendered-label { display: grid; align-content: center; border-radius: 5px; color: #111; background: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.rendered-label-name { max-width: 100%; overflow: hidden; font-size: 1rem; font-weight: 800; overflow-wrap: anywhere; white-space: normal; line-height: 1.05; }
.rendered-label-barcode { height: 66px; display: flex; align-items: stretch; justify-content: center; gap: 2px; overflow: hidden; background: repeating-linear-gradient(90deg,#000 0 2px,transparent 2px 4px,#000 4px 5px,transparent 5px 8px); }
.rendered-label-barcode i { flex: 0 0 auto; background: transparent; }
.rendered-label-code { color: #111; font-family: monospace; font-size: .78rem; letter-spacing: .1em; text-align: center; }
.rendered-label-price { font-size: 1.35rem; font-weight: 900; }
.rendered-label sup { position: relative; margin-left: 1px; font-size: .5em; line-height: 0; vertical-align: baseline; top: -.45em; }
.preview-field { transform-origin: top left; }

dialog { width: min(480px, calc(100% - 24px)); border: 1px solid #37424c; border-radius: 13px; color: #f4f6f8; background: #12171c; box-shadow: 0 30px 100px #000; }
dialog::backdrop { background: rgba(0,0,0,.75); backdrop-filter: blur(4px); }
dialog form { display: grid; gap: 13px; padding: 18px; }
dialog textarea { width: 100%; resize: vertical; border: 1px solid #38434d; border-radius: 8px; color: #e5f3df; background: #080b0e; padding: 12px; font: 13px/1.4 Consolas, monospace; outline: none; }
dialog small { color: var(--muted); }
dialog label { display: grid; gap: 6px; color: #bac3cc; font-size: .82rem; }
dialog select { width: 100%; min-height: 44px; border: 1px solid #38434d; border-radius: 8px; color: #fff; background: #080b0e; padding: 10px 12px; font: inherit; outline: none; }
dialog select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(215,255,63,.08); }
dialog p { margin: 0; color: var(--muted); font-size: .82rem; }
.dialog-head, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.output-actions > * { flex: 1; min-height: 72px; }
.esl-mobile-preview { display: grid; place-items: center; margin: 18px 0; padding: 12px; border-radius: 10px; background: #0b0f12; }
.esl-mobile-preview img { width: 100%; max-width: 500px; height: auto; image-rendering: pixelated; background: white; }
.dialog-head h2 { margin: 0; }
.dialog-actions > * { flex: 1; }
.full-width { width: 100%; }
.dialog-status.error { color: #ff8d8d; }
.settings-divider { height: 1px; margin: 4px 0; background: var(--line); }
#pin-dialog { width: min(380px, calc(100% - 24px)); }
#pin-dialog input { letter-spacing: .35em; }
@media (max-width: 760px) {
  header { padding: 0 14px; }
  .bridge-state { font-size: .7rem; }
  main { padding: 12px; }
  .workspace { display: flex; flex-direction: column; grid-template-columns: 1fr; }
  .inventory { min-height: 0; height: auto; flex: 1 1 auto; }
  .label-setup { flex: 0 0 110px; height: 110px; width: 100%; align-self: stretch; margin-top: auto; }
  .label-setup:not(.has-preview) { height: 110px; flex-basis: 110px; }
  .table-wrap { min-height: 280px; }
  .actions { grid-template-columns: 1fr 1fr; }
  .primary[type="button"] { min-height: 52px; }
}

@media (orientation: landscape) and (max-height: 600px) {
  html, body { height: 100dvh; min-height: 0; overflow: hidden; }
  header { min-height: 52px; height: 52px; padding: 0 12px; }
  header .icon-button { width: 36px; height: 36px; }
  main {
    height: calc(100dvh - 52px);
    min-height: 0;
    display: block;
    padding: 10px;
    overflow: hidden;
  }
  main > .scanner { display: none; }
  .mobile-only-workspace-search { display: block; }
  .scanner { min-width: 0; margin: 0 0 10px; }
  .scanner input { min-height: 46px; height: 46px; padding-top: 8px; padding-bottom: 8px; }
  .scan-icon-button { inset: 5px 5px 5px auto; width: 38px; padding: 8px; }
  .workspace {
    min-width: 0;
    min-height: 0;
    display: grid;
    height: 100%;
    grid-template-columns: minmax(0, 3fr) minmax(250px, 2fr);
    gap: 10px;
    overflow: hidden;
  }
  .inventory, .label-setup { min-width: 0; min-height: 0; }
  .inventory { display: flex; flex-direction: column; height: 100%; }
  .label-setup { height: 100px; align-self: end; max-height: 100%; }
  .label-setup:not(.has-preview) { height: 100px; }
  .panel-head { flex: 0 0 auto; padding: 10px 14px; }
  .table-wrap { flex: 1 1 auto; min-height: 0; height: auto; overflow-y: auto; overscroll-behavior: contain; }
  th { position: sticky; z-index: 2; top: 0; background: var(--panel); }
  .empty { inset: 42px 0 0; }
  .label-setup { padding: 8px 12px 12px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .label-setup.preview-expanded,
  .label-setup.preview-expanded:not(.has-preview) { position: relative; z-index: 2; left: auto; right: auto; bottom: auto; width: auto; height: calc(100dvh - 72px); max-height: calc(100dvh - 72px); align-self: end; }
  .toggle { padding: 9px 11px; }
  .actions { margin-top: 10px; }
  .actions > button { min-height: 42px; }
  .label-render-preview { margin-top: 10px; }
  .rendered-label { min-height: 130px; }
}
