/* Any element with the native `hidden` attribute must actually disappear —
   without this, elements that also set their own `display` (flex/grid/etc.)
   for layout purposes silently defeat the browser's default [hidden] rule
   and stay visible/clickable even while "hidden". This bit us on the print
   job overlay and its Open/Print PDF button. */
[hidden] { display: none !important; }

:root {
  --bg: #10141a;
  --panel: #161c23;
  --panel-alt: #1b2229;
  --header-navy: #1c2a3d;
  --header-navy-2: #24374d;
  --border: #34414e;
  --border-strong: #435161;
  --text: #dfe4e8;
  --text-dim: #93a3b0;
  --text-faint: #5c6874;
  --accent-green: #2fa14a;
  --accent-green-dark: #1f8138;
  --accent-red: #cf4a3a;
  --highlight-row: #cdb972;
  --highlight-row-text: #2a2308;
  --input-bg: #cdb972;
  --input-text: #2a2308;
  --status-available: #e2705c;
  --status-printed: #e9e3cd;
  --mono: 'Consolas', 'Courier New', monospace;
  --sans: 'Segoe UI', Tahoma, Arial, sans-serif;
  --shadow: 0 2px 6px rgba(0,0,0,0.45);
}

[data-theme="light"] {
  --bg: #e9edf0;
  --panel: #ffffff;
  --panel-alt: #f3f5f7;
  --header-navy: #2b4258;
  --header-navy-2: #35526c;
  --border: #c6ced5;
  --border-strong: #aeb9c2;
  --text: #1c2731;
  --text-dim: #5a6b78;
  --text-faint: #96a5b0;
  --highlight-row: #f1de9c;
  --highlight-row-text: #4a3d0a;
  --input-bg: #f1de9c;
  --input-text: #4a3d0a;
  --shadow: 0 2px 8px rgba(30,50,70,0.10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 12.5px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 4px;
  background: linear-gradient(135deg, var(--header-navy-2), var(--accent-green));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; color: #fff;
}
.brand-logo { height: 48px; width: auto; display: block; border-radius: 3px; }
.login-box .brand-logo { height: 66px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text .b1 { font-weight: 700; font-size: 14px; }
.brand-text .b2 { font-size: 9.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }

/* Login page */
.login-page { display: flex; align-items: center; justify-content: center; }
.login-box {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 32px; width: 320px; box-shadow: var(--shadow);
}
.login-box .brand { justify-content: center; margin-bottom: 24px; }
.login-error {
  background: rgba(207,74,58,0.15); color: var(--status-available);
  padding: 8px 12px; border-radius: 4px; font-size: 12px; margin-bottom: 14px;
}

.field-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field-label { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-faint); font-weight: 700; }
input[type="text"], input[type="password"], select {
  background: var(--input-bg); border: 1px solid var(--border-strong); color: var(--input-text);
  padding: 6px 9px; border-radius: 3px; font-family: var(--mono); font-size: 12px; font-weight: 600;
}
input[disabled] { opacity: 0.75; }
input:focus, select:focus { outline: 2px solid var(--header-navy-2); outline-offset: 1px; }

.btn {
  border: 1px solid rgba(0,0,0,0.25); border-radius: 3px; padding: 7px 16px; font-weight: 700; font-size: 11px;
  letter-spacing: 0.4px; cursor: pointer; text-transform: uppercase;
  display: inline-flex; align-items: center; gap: 6px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.15);
}
.btn-pull { background: linear-gradient(180deg, #39b358, var(--accent-green-dark)); color: #fff; }
.btn-print { background: linear-gradient(180deg, #39b358, var(--accent-green-dark)); color: #fff; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; filter: none; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border-bottom: 1px solid var(--border); padding: 9px 18px; box-shadow: var(--shadow);
}
.topbar-right { display: flex; align-items: center; gap: 18px; }
.theme-toggle { display: flex; align-items: center; gap: 8px; font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; }
.switch { position: relative; width: 38px; height: 19px; background: var(--border); border-radius: 20px; cursor: pointer; }
.switch.on { background: var(--accent-green); }
.switch::after { content:''; position:absolute; top:2px; left:2px; width:15px; height:15px; border-radius:50%; background:#fff; transition:left .2s; }
.switch.on::after { left: 21px; }
.user-chip { font-size: 10.5px; color: var(--text-dim); padding: 5px 10px; border: 1px solid var(--border); border-radius: 3px; }
.logout-link { color: var(--text-dim); font-size: 10.5px; text-decoration: none; }
.logout-link:hover { color: var(--text); }

/* Panel title bar (e.g. "Incoming Batches") */
.panel-title {
  background: linear-gradient(180deg, var(--header-navy-2), var(--header-navy)); color: #eef2f5;
  padding: 7px 16px; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px;
  border-bottom: 1px solid var(--border-strong);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
}

/* Toolbar */
.toolbar { display: flex; align-items: center; gap: 14px; background: var(--panel-alt); border-bottom: 1px solid var(--border); padding: 9px 18px; flex-wrap: wrap; }
.spacer { flex: 1; }
.remaining-badge { background: linear-gradient(180deg, #dd5b41, var(--accent-red)); color: #fff; padding: 7px 16px; border-radius: 3px; font-weight: 700; font-size: 11.5px; letter-spacing: 0.3px; }
.qr-counter-badge { display: inline-flex; align-items: center; gap: 7px; background: linear-gradient(180deg, #39b358, var(--accent-green-dark)); color: #fff; padding: 7px 14px; border-radius: 3px; font-weight: 700; font-size: 11.5px; letter-spacing: 0.3px; white-space: nowrap; }
.qr-counter-badge .qr-counter-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.85; font-weight: 700; }
.qr-counter-badge .qr-counter-num { font-size: 14px; font-weight: 800; }
.chk-label { display: inline-flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.4px; cursor: pointer; white-space: nowrap; font-weight: 600; }
.chk-label input[type="checkbox"] { accent-color: var(--accent-green); width: 13px; height: 13px; cursor: pointer; }

/* Main grid — align-items:stretch (the default) makes all three columns
   exactly as tall as the tallest one, whatever their own content adds up to.
   Combined with the margin-top:auto trick below, each column's footer then
   pins itself to that shared bottom edge automatically — so the three
   footers always end on the same line, even if a header/banner/table
   render a few pixels taller in one column than another. */
.main { display: grid; grid-template-columns: 1.1fr 1fr 1fr; grid-template-rows: minmax(0, 1fr); align-items: stretch; gap: 1px; background: var(--border); height: calc(100vh - 150px); border-top: 1px solid var(--border); overflow: hidden; }
.col { background: var(--bg); display: flex; flex-direction: column; overflow: hidden; height: 100%; min-height: 0; }
.col-header {
  background: linear-gradient(180deg, var(--header-navy-2), var(--header-navy)); color: #eef2f5;
  padding: 8px 14px; font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.5px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border-strong);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
  flex: 0 0 auto;
}
.col-header .count { background: rgba(255,255,255,0.16); padding: 2px 8px; border-radius: 9px; font-size: 9.5px; }
.sub-banner { font-size: 10.5px; padding: 6px 14px; background: var(--panel-alt); border-bottom: 1px solid var(--border); color: var(--text-dim); box-sizing: border-box; flex: 0 0 auto; }
.table-wrap { overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.sub-banner + .table-wrap { flex: 1 1 auto; min-height: 0; }
.search-row + .table-wrap { flex: 1 1 auto; min-height: 0; }
table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 11px; }
thead th {
  position: sticky; top: 0; background: var(--panel); color: var(--text-dim); text-align: left; padding: 7px 9px;
  font-size: 9.5px; text-transform: uppercase; border: 1px solid var(--border); line-height: 1.3; font-weight: 700;
  white-space: nowrap;
}
thead th::after { content: '\21C5'; font-size: 8px; color: var(--text-faint); margin-left: 5px; }
thead th { cursor: pointer; user-select: none; }
thead th.sort-asc::after { content: '\2191'; color: var(--accent-green); }
thead th.sort-desc::after { content: '\2193'; color: var(--accent-green); }
.search-row { display: flex; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--border); box-sizing: border-box; }
.search-row select { width: 88px; flex: 0 0 88px; padding: 5px 6px; font-size: 10.5px; }
.search-row input[type="text"] { flex: 1; min-width: 0; padding: 5px 7px; font-size: 10.5px; }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:nth-child(even) { background: rgba(255,255,255,0.015); }
tbody tr:hover { background: var(--panel-alt); }
tbody tr.selected { background: var(--highlight-row); }
tbody tr.selected td { color: var(--highlight-row-text); font-weight: 700; }
td { padding: 6px 9px; color: var(--text); white-space: nowrap; border: 1px solid var(--border); }
td.dim { color: var(--text-dim); }
tr.selected td.dim { color: var(--highlight-row-text); opacity: 0.75; }
.status-badge { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }
.status-badge .ddw { font-style: normal; font-size: 9px; opacity: 0.75; }
.status-badge.available { color: var(--status-available); }
.status-badge.printed { color: var(--status-printed); }
tr.selected .status-badge.printed,
tr.selected .status-badge.available { color: var(--highlight-row-text); }
.col-footer {
  border-top: 1px solid var(--border-strong); padding: 10px 14px; background: var(--panel-alt);
  font-family: var(--mono); font-size: 10.5px; color: var(--text-dim);
  box-sizing: border-box; height: 190px; flex: 0 0 190px; overflow: hidden; display: flex; flex-direction: column; justify-content: center;
  margin-top: auto; /* pins this footer to the bottom of the (stretched) column */
}
.sgtin-bar + .col-footer { height: 164px; flex-basis: 164px; margin-top: 0; }
.footer-row { display: flex; justify-content: space-between; margin-bottom: 4px; }
.footer-row .val { color: var(--text); }
.sgtin-bar {
  background: linear-gradient(180deg, var(--header-navy-2), var(--header-navy)); color: #eef2f5;
  padding: 6px 14px; font-weight: 700; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px;
  border-top: 1px solid var(--border-strong); box-sizing: border-box;
  flex: 0 0 auto; margin-top: auto; /* pushes the sgtin-bar + its footer down together */
}
.sgtin-row, .tri-row { display: flex; gap: 18px; font-family: var(--mono); font-size: 10.5px; }
.sgtin-row { justify-content: center; align-items: center; gap: 36px; width: 100%; }
.tri-row { justify-content: space-between; margin-bottom: 6px; flex-wrap: wrap; }
.tri-row.two-col > div { flex: 1; }
.tri-row.two-col .remaining-badge { flex: 0 0 auto; align-self: center; }
.sgtin-row .lbl, .tri-row .lbl { display: block; color: var(--text-faint); text-transform: uppercase; font-size: 9px; letter-spacing: 0.4px; margin-bottom: 1px; }
.sgtin-row .lbl { font-size: 12px; text-align: center; margin-bottom: 6px; }
.sgtin-row .val, .tri-row .val {
  color: var(--input-text); font-weight: 700; background: var(--input-bg);
  display: inline-block; padding: 3px 8px; border-radius: 2px; margin-top: 1px;
}
.sgtin-row .val { font-size: 17px; padding: 10px 20px; border-radius: 4px; }
.url-line { font-size: 10px; color: #6fb8d9; word-break: break-all; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px dashed var(--border); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.url-print-icon { flex-shrink: 0; opacity: 0.75; color: var(--accent-green); }
.range-controls { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; flex-wrap: wrap; }
.range-controls input[type="text"] { width: 52px; min-width: unset; padding: 5px 7px; text-align: center; }
.empty-state { padding: 30px 14px; color: var(--text-faint); text-align: center; font-size: 12px; }

/* Bottom status bar */
.statusbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border-top: 1px solid var(--border);
  padding: 6px 18px; font-size: 10.5px; color: var(--text-dim); font-family: var(--mono);
}
.statusbar-center { flex: 1; text-align: center; }
.statusbar-right { display: flex; align-items: center; gap: 14px; }
/* Print-label background job modal */
.btn-secondary {
  background: var(--panel-alt); color: var(--text); border: 1px solid var(--border-strong);
}
.print-job-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.18s ease;
}
.print-job-overlay.open { opacity: 1; }
.print-job-modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 24px 28px; width: 380px; max-width: 90vw; box-shadow: 0 12px 40px rgba(0,0,0,0.4);
  transform: scale(0.96) translateY(6px); transition: transform 0.18s ease;
}
.print-job-modal-wide { width: 460px; }
.print-job-overlay.open .print-job-modal { transform: scale(1) translateY(0); }
.print-job-header { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 4px; }
.print-job-header .print-job-spinner { margin-bottom: 0; margin-top: 2px; flex: 0 0 auto; }
.print-job-header h3 { margin: 0 0 4px; }
.print-job-modal h3 { margin: 0 0 16px; font-size: 15px; color: var(--text); }

.print-job-spinner {
  width: 22px; height: 22px; margin-bottom: 14px; border-radius: 50%;
  border: 2.5px solid var(--border-strong); border-top-color: var(--accent-green);
  animation: printJobSpin 0.8s linear infinite;
}
.print-job-spinner.done { border: none; animation: none; width: auto; height: auto; margin-bottom: 10px; }
.print-job-spinner.done::before { content: '✓'; display: inline-block; color: var(--accent-green); font-size: 20px; font-weight: 700; }
.print-job-spinner.error { border-color: var(--accent-red); border-top-color: var(--accent-red); animation: none; }
@keyframes printJobSpin { to { transform: rotate(360deg); } }

.print-job-bar-track {
  width: 100%; height: 10px; border-radius: 5px; background: var(--panel-alt);
  border: 1px solid var(--border); overflow: hidden; position: relative;
}
.print-job-bar-fill {
  height: 100%; background: linear-gradient(90deg, #39b358, var(--accent-green-dark));
  transition: width 0.4s ease;
}
/* While waiting on the very first server response (before we know a total),
   show a moving shimmer instead of a static sliver so the modal never looks
   frozen. Swaps out for real, steadily-incrementing progress once chunks
   start reporting back. */
.print-job-bar-fill.indeterminate {
  width: 40% !important; background: linear-gradient(90deg, transparent, #39b358, transparent);
  animation: printJobShimmer 1.1s ease-in-out infinite;
}
@keyframes printJobShimmer {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}
.print-job-status-text { margin-top: 10px; font-size: 12px; color: var(--text-dim); font-family: var(--mono); }
.print-job-batch-note { margin-top: 4px; color: var(--accent-green); min-height: 14px; }
.print-job-error { margin-top: 10px; font-size: 12px; color: var(--accent-red); }
.print-job-chunk-hint { margin-top: 14px; font-size: 11px; color: var(--text-dim); line-height: 1.4; }
.print-job-chunk-list {
  list-style: none; margin: 10px 0 0; padding: 0;
  max-height: 190px; overflow-y: auto; border: 1px solid var(--border); border-radius: 4px;
  background: var(--panel-alt);
}
.print-job-chunk-list:empty { display: none; }
.print-job-chunk-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 7px 10px; border-bottom: 1px solid var(--border); font-size: 12px; font-family: var(--mono);
  animation: printJobChunkIn 0.25s ease;
}
.print-job-chunk-item:last-child { border-bottom: none; }
@keyframes printJobChunkIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.print-job-chunk-label { color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 10px; }
.print-job-actions { margin-top: 20px; display: flex; gap: 10px; justify-content: flex-end; }
.print-job-open-btn {
  opacity: 0; transform: translateY(4px); animation: printJobBtnIn 0.3s ease forwards;
}
@keyframes printJobBtnIn { to { opacity: 1; transform: translateY(0); } }
.print-job-frame {
  position: fixed; left: -9999px; top: -9999px; width: 1px; height: 1px;
  border: 0; opacity: 0.01; pointer-events: none;
}