/* =====================================================================
   Popular Systems - Packing & Inspection
   ===================================================================== */

:root {
  --blue:        #1b9cd8;
  --blue-dark:   #1580b4;
  --navy:        #16283c;
  --navy-light:  #1f3a52;
  --navy-2:      #24425c;
  --ink:         #16222e;
  --muted:       #6b7c8c;
  --line:        #dde5ec;
  --bg:          #f2f5f8;
  --panel:       #ffffff;
  --ok:          #148f4b;
  --ok-bg:       #e6f6ec;
  --err:         #c62828;
  --err-bg:      #fdeaea;
  --warn:        #b26a00;
  --warn-bg:     #fff5e2;
  --radius:      8px;
  --shadow:      0 1px 3px rgba(20,40,60,.10), 0 1px 2px rgba(20,40,60,.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.skip {
  position: absolute; left: -9999px;
}
.skip:focus {
  left: 8px; top: 8px; z-index: 999; background: #fff; padding: 8px 12px;
  border-radius: 6px; box-shadow: var(--shadow);
}

/* ------------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 14px;
  background: #fff; border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(20,40,60,.06);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand img { height: 30px; width: auto; display: block; border-radius: 2px; }
.brand-text {
  font-weight: 700; letter-spacing: .04em; color: var(--blue-dark);
  font-size: 17px; white-space: nowrap;
}
.topbar-right {
  margin-left: auto; display: flex; align-items: center; gap: 14px;
  font-size: 13px;
}
.who { display: flex; flex-direction: column; line-height: 1.25; text-align: right; }
.who em { font-style: normal; color: var(--muted); font-size: 11px; text-transform: capitalize; }
.link {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--blue-dark); font-size: 13px; font-family: inherit;
}
.link:hover { text-decoration: underline; }
.inline { display: inline; }

.nav-toggle {
  display: none; flex-direction: column; justify-content: center; gap: 4px;
  width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; cursor: pointer; padding: 0 9px;
}
.nav-toggle span { display: block; height: 2px; background: var(--navy); border-radius: 2px; }

/* -------------------------------------------------------------- shell */
.shell { display: flex; min-height: calc(100vh - 56px); align-items: stretch; }

.sidebar {
  width: 220px; flex: 0 0 220px;
  background: var(--navy); color: #cfdae6;
  padding: 10px 0 30px;
  overflow-y: auto;
}
.nav-group {
  padding: 16px 16px 6px; font-size: 10.5px; letter-spacing: .13em;
  text-transform: uppercase; color: #7b90a6; font-weight: 600;
}
.nav-item {
  display: block; padding: 9px 16px; color: #dbe5ee; font-size: 14px;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.nav-item.active {
  background: rgba(27,156,216,.20); border-left-color: var(--blue); color: #fff; font-weight: 600;
}
.scrim { display: none; }

.content {
  flex: 1 1 auto; min-width: 0; padding: 20px 24px 40px;
  display: flex; flex-direction: column;
}

/* ------------------------------------------------------------ headings */
.page-head {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px;
}
h1 { font-size: 23px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 26px 0 10px; font-weight: 600; }
h3 { font-size: 14px; margin: 18px 0 8px; font-weight: 600; color: var(--muted);
     text-transform: uppercase; letter-spacing: .06em; }
.page-head .spacer { margin-left: auto; }
.subtle { color: var(--muted); font-size: 13px; }

/* -------------------------------------------------------------- panel */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 18px;
}
.panel.tight { padding: 0; overflow: hidden; }

/* -------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  background: var(--blue); color: #fff; text-align: left; font-weight: 600;
  padding: 11px 12px; white-space: nowrap; font-size: 13px;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f7fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap { white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ------------------------------------------------------------- forms */
.field { margin-bottom: 16px; max-width: 640px; }
.field label { display: block; font-size: 13px; margin-bottom: 5px; font-weight: 600; }
.field .req { color: var(--err); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #c6d2dd; border-radius: 6px;
  font: inherit; font-size: 14px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(27,156,216,.16);
}
textarea { min-height: 110px; resize: vertical; }
input[readonly] { background: #f4f7fa; color: var(--muted); }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > .field { flex: 1 1 240px; }
.check { display: flex; align-items: center; gap: 9px; font-size: 14px; margin-bottom: 12px; }
.check input { width: 17px; height: 17px; }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: 6px; border: 1px solid transparent;
  background: var(--blue); color: #fff; font: inherit; font-size: 14px;
  font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--blue-dark); text-decoration: none; color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: #fff; color: var(--ink); border-color: #c6d2dd; }
.btn-ghost:hover { background: #f2f6fa; color: var(--ink); }
.btn-danger { background: var(--err); }
.btn-danger:hover { background: #a91d1d; }
.btn-ok { background: var(--ok); }
.btn-ok:hover { background: #0f7a3e; }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-lg { padding: 13px 24px; font-size: 16px; }
.btn-block { width: 100%; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }

/* -------------------------------------------------------------- flash */
.flash {
  position: relative; padding: 11px 40px 11px 14px; border-radius: 6px;
  margin-bottom: 16px; font-size: 14px; border: 1px solid;
}
.flash-ok  { background: var(--ok-bg);  border-color: #b6e2c6; color: #12633a; }
.flash-err { background: var(--err-bg); border-color: #f2c2c2; color: #96201f; }
.flash-x {
  position: absolute; right: 8px; top: 6px; background: none; border: 0;
  font-size: 20px; line-height: 1; cursor: pointer; color: inherit; opacity: .6;
}
.alert { padding: 11px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; border: 1px solid; }
.alert-err  { background: var(--err-bg);  border-color: #f2c2c2; color: #96201f; }
.alert-warn { background: var(--warn-bg); border-color: #f0d9a8; color: #8a5300; }
.alert-info { background: #e8f4fb; border-color: #bcdff2; color: #14618c; }

/* --------------------------------------------------------------- tags */
.tag {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px;
  font-weight: 600; letter-spacing: .02em;
}
.tag-ok   { background: var(--ok-bg);   color: #12633a; }
.tag-open { background: var(--warn-bg); color: #8a5300; }
.tag-off  { background: #eceff2;        color: #67788a; }

/* ---------------------------------------------------------- dashboard */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card .k { font-size: 12px; color: var(--muted); text-transform: uppercase;
           letter-spacing: .07em; font-weight: 600; }
.card .v { font-size: 30px; font-weight: 700; margin-top: 6px; line-height: 1;
           font-variant-numeric: tabular-nums; }
.card .s { font-size: 12px; color: var(--muted); margin-top: 5px; }
.card.accent { background: linear-gradient(135deg, #1b9cd8, #1470a0); border: 0; color: #fff; }
.card.accent .k, .card.accent .s { color: rgba(255,255,255,.85); }

/* ------------------------------------------------------------- pager */
.pager { display: flex; align-items: center; gap: 10px; justify-content: center;
         margin-top: 16px; font-size: 13px; color: var(--muted); }

/* ------------------------------------------------------- label preview */
.label-cell { display: flex; align-items: center; gap: 10px; min-width: 210px; }
.label-cell .lines {
  font-size: 9.5px; line-height: 1.35; color: #333;
  /* max-width is what makes the ellipsis engage: without a cap the cell
     grows to fit the longest line and pushes the QR out of the table. */
  flex: 1 1 auto; min-width: 0; max-width: 175px;
}
.label-cell .lines > div {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.label-cell img {
  width: 58px; height: 58px; flex: 0 0 58px;
  image-rendering: pixelated;
}
/* Reports carrying a label-preview column need a little more room than a
   plain table; below this width the wrapper scrolls horizontally. */
.table-wrap table.wide { min-width: 860px; }

/* Reserve the column explicitly, otherwise the table layout algorithm
   squeezes the QR preview down to a sliver on a crowded report. The
   remaining columns wrap instead. */
th.label-col { width: 250px; }
td.label-col { min-width: 250px; }
/* Compact variant: just the QR and a print link, for reports whose other
   columns already carry the part details. */
th.label-col.compact-col, td.label-col.compact-col { width: 130px; min-width: 130px; }
.label-cell.compact { min-width: 0; gap: 12px; }
.table-wrap table.wide td:not(.nowrap):not(.label-col) { white-space: normal; }
.print-link { display: inline-block; margin-top: 4px; font-size: 12px; }

/* ==================================================================
   SCAN SCREEN
   ================================================================== */
.scan-layout { display: grid; grid-template-columns: 1fr 340px; gap: 18px; align-items: start; }

.scan-box {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.scan-input-row { display: flex; gap: 10px; }
#scanInput, .scan-input {
  flex: 1 1 auto; font-size: 20px; padding: 14px 16px; letter-spacing: .04em;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  border: 2px solid var(--blue); border-radius: 8px;
}
#scanInput:focus { box-shadow: 0 0 0 4px rgba(27,156,216,.2); }

.progress-wrap { margin: 16px 0 6px; }
.progress-num { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.progress-num small { font-size: 15px; color: var(--muted); font-weight: 500; }
.bar { height: 12px; background: #e4ebf1; border-radius: 20px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--blue);
           border-radius: 20px; transition: width .25s ease; }
.bar.done > i { background: var(--ok); }

.feedback {
  margin-top: 14px; padding: 14px 16px; border-radius: 8px; font-size: 16px;
  font-weight: 600; display: none; border: 1px solid;
}
.feedback.show { display: block; animation: pop .18s ease; }
.feedback.ok   { background: var(--ok-bg);  border-color: #a8dcbd; color: #0f6b38; }
.feedback.err  { background: var(--err-bg); border-color: #f0b6b6; color: #a01c1c; }
.feedback.warn { background: var(--warn-bg);border-color: #eccf96; color: #8a5300; }
@keyframes pop { from { transform: scale(.97); opacity: .4; } to { transform: scale(1); opacity: 1; } }

body.flash-ok-screen  { animation: flashok .4s; }
body.flash-err-screen { animation: flasherr .4s; }
@keyframes flashok  { 0%,100% { background: var(--bg); } 30% { background: #cdf0dc; } }
@keyframes flasherr { 0%,100% { background: var(--bg); } 30% { background: #fbd3d3; } }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px;
  border-bottom: 1px solid var(--line); font-size: 14px;
}
.checklist li:last-child { border-bottom: 0; }
.checklist li.done { background: #f2fbf5; }
.checklist .mark {
  width: 26px; height: 26px; flex: 0 0 26px; border-radius: 50%;
  border: 2px solid #c8d4de; display: flex; align-items: center;
  justify-content: center; font-size: 15px; color: #fff; font-weight: 700;
}
.checklist li.done .mark { background: var(--ok); border-color: var(--ok); }
.checklist .code { font-weight: 700; font-family: ui-monospace, Menlo, monospace; }
.checklist .desc { color: var(--muted); font-size: 12.5px; }
.checklist .when { margin-left: auto; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.checklist .undo { margin-left: 8px; }

/* ------------------------------------------------------- camera panel */
.camera-wrap { display: none; margin-top: 14px; }
.camera-wrap.on { display: block; }
#camView {
  width: 100%; max-width: 460px; border-radius: 10px; background: #000;
  aspect-ratio: 4/3; object-fit: cover; display: block;
}
.cam-hint { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.cam-bar { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }

/* --------------------------------------------------------- final QR */
.final-qr { text-align: center; padding: 20px; }
.final-qr img { width: 230px; height: 230px; image-rendering: pixelated; }
.final-qr .payload {
  font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--muted);
  margin-top: 10px; word-break: break-all;
}

/* ================================================================ mobile */
@media (max-width: 900px) {
  .scan-layout { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
  .nav-toggle { display: flex; }
  .content { padding: 16px 14px 34px; }
  .sidebar {
    position: fixed; top: 56px; bottom: 0; left: 0; z-index: 45;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 4px 0 18px rgba(0,0,0,.25);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim {
    display: block; position: fixed; inset: 56px 0 0 0; z-index: 44;
    background: rgba(10,20,30,.45);
  }
  .brand-text { display: none; }
  .who { display: none; }
  h1 { font-size: 20px; }
  thead th, tbody td { padding: 9px 10px; font-size: 12.5px; }
  .btn { padding: 10px 15px; }
  #scanInput, .scan-input { font-size: 17px; }
}

/* ---------------------------------------------------------------- foot */
.foot {
  margin-top: auto; padding-top: 24px; display: flex; gap: 16px; flex-wrap: wrap;
  color: var(--muted); font-size: 11.5px; border-top: 1px solid var(--line);
  margin-top: 30px; padding-top: 14px;
}

/* --------------------------------------------------------------- login */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: linear-gradient(150deg, #16283c 0%, #22506f 100%);
}
.login-card {
  width: 100%; max-width: 390px; background: #fff; border-radius: 12px;
  padding: 32px 30px; box-shadow: 0 12px 40px rgba(0,0,0,.28);
}
.login-card .logo { text-align: center; margin-bottom: 6px; }
.login-card .logo img { height: 52px; }
.login-card h1 { text-align: center; font-size: 19px; margin: 10px 0 4px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 22px; }

/* ---------------------------------------------------------- utilities */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.hide { display: none !important; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.small { font-size: 12.5px; }
.strike { text-decoration: line-through; opacity: .55; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { margin-bottom: 0; max-width: 260px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 700px) { .split { grid-template-columns: 1fr; } }
