/* RAVE Build Tracker — shop-floor UI
   Design: industrial graphite + safety orange. Serial numbers are the hero,
   always set large in mono. Touch targets >=48px for gloved/tablet use. */

:root {
  --bg: #eef0f2;
  --surface: #ffffff;
  --ink: #16191d;
  --muted: #5c6670;
  --line: #d4dade;
  --accent: #d9480f;
  --accent-ink: #fff3ec;
  --pass: #2f9e44;
  --pass-bg: #e8f6ec;
  --fail: #e03131;
  --fail-bg: #fdecec;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; max-width: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: 84px;
}

.topbar {
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand-mark {
  font-weight: 800;
  letter-spacing: 3px;
  font-size: 18px;
  color: var(--accent);
}
.brand-sub { margin-left: 10px; font-size: 14px; color: #aab3bb; letter-spacing: 0.5px; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #cfd6dc; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.online { background: var(--pass); }
.dot.offline { background: var(--fail); }
.queue-pill {
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 600;
}

main { max-width: 860px; margin: 0 auto; padding: 18px 16px; }
.screen[hidden] { display: none; }

h2 { font-size: 17px; font-weight: 700; margin: 22px 0 10px; letter-spacing: 0.2px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.err { color: var(--fail); font-size: 14px; margin-top: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.center-card { max-width: 380px; margin: 60px auto; text-align: center; }
.center-card input { text-align: center; font-size: 22px; letter-spacing: 6px; }

label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 5px; text-transform: uppercase; letter-spacing: 0.6px; }
input, select, textarea {
  width: 100%;
  font-size: 17px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  min-height: 48px;
}
textarea { min-height: 0; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.mono { font-family: var(--mono); letter-spacing: 1px; }

.btn {
  min-height: 48px;
  padding: 10px 20px;
  font-size: 16px;
  font-weight: 600;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  margin-top: 12px;
}
.btn:active { transform: scale(0.985); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-style: dashed; color: var(--muted); }
.btn.big { min-height: 60px; font-size: 18px; }
.btn.block { width: 100%; display: block; }
.btn.tiny { min-height: 36px; padding: 4px 12px; font-size: 13px; margin-top: 0; }
.btn.danger { color: var(--fail); border-color: var(--fail); background: #fff; }

.row { display: flex; gap: 10px; align-items: center; }
.row.spread { justify-content: space-between; }
.row input { flex: 1; }
.row .btn { margin-top: 0; flex-shrink: 0; }
.item .row.spread { align-items: flex-start; }
.item .row.spread > span { min-width: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.grid2.tight { gap: 8px; }
@media (max-width: 560px) { .grid3 { grid-template-columns: 1fr; } .grid2 { grid-template-columns: 1fr; } }

.stat-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-num { display: block; font-size: 34px; font-weight: 800; font-family: var(--mono); }
.stat-num.pass { color: var(--pass); }
.stat-num.fail { color: var(--fail); }
.stat-lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.quick-actions .btn { margin-top: 0; }

.list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.list[hidden] { display: none !important; }
.list.compact { gap: 4px; margin-top: 14px; }
.item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.item.tappable { cursor: pointer; }
.item.tappable:active { background: #f6f7f8; }
.item .serial-big { font-family: var(--mono); font-size: 20px; font-weight: 700; letter-spacing: 1.5px; }
.item .meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.item .item-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.badge.pass { background: var(--pass-bg); color: var(--pass); }
.badge.fail { background: var(--fail-bg); color: var(--fail); }
.badge.amend { background: #fff3ec; color: var(--accent); }

.serial-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-family: var(--mono); font-size: 13px; background: #f1f3f4; border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1.5px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-btn { min-height: 56px; font-size: 18px; font-weight: 700; border: none; background: #fff; cursor: pointer; font-family: inherit; color: var(--muted); }
.seg-btn.sel-pass { background: var(--pass); color: #fff; }
.seg-btn.sel-fail { background: var(--fail); color: #fff; }

.check-row { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 4px; }
.check-row label { display: flex; align-items: center; gap: 8px; text-transform: none; font-size: 15px; font-weight: 500; color: var(--ink); letter-spacing: 0; margin: 4px 0; }
.check-row input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; }

.recipe { margin: 10px 0 4px; padding: 10px 12px; background: #f6f7f8; border-radius: 8px; font-size: 14px; }

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--ink);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  min-height: 64px;
  border: none;
  background: none;
  color: #8a939c;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  letter-spacing: 0.4px;
}
.tab .tab-ico { font-size: 20px; line-height: 1; }
.tab.active { color: var(--accent); }

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  max-width: 90vw;
  text-align: center;
}
.toast.bad { background: var(--fail); }

/* ── v2 additions: Work Orders, Serials table, Modal ── */

/* Tab bar extended to 7 tabs */
.tabbar { grid-template-columns: repeat(7, 1fr); }
@media (max-width: 480px) { .tab { font-size: 10px; } .tab .tab-ico { font-size: 17px; } }

/* WO result card */
.result-card { border-radius: var(--radius); padding: 16px 18px; margin: 14px 0; }
.result-card.success { background: var(--pass-bg); border: 1px solid #b2dfbb; }
.result-card.error   { background: var(--fail-bg); border: 1px solid #f5c2c2; }
.result-card h3 { font-size: 15px; margin-bottom: 8px; }
.result-card ul { margin: 6px 0 0 16px; }
.result-card li { font-size: 13px; margin-bottom: 3px; }
.result-card p  { font-size: 14px; margin-bottom: 4px; }

/* Item lookup preview */
.item-preview { font-size: 14px; color: var(--muted); margin-top: 6px; padding: 10px 12px; background: #f6f7f8; border-radius: 8px; }

/* WO group header */
.wo-group { margin-bottom: 20px; }
.wo-group-hdr { font-size: 13px; font-weight: 700; color: var(--muted); padding: 8px 12px; background: #f6f7f8; border-radius: var(--radius) var(--radius) 0 0; border: 1px solid var(--line); border-bottom: none; text-transform: uppercase; letter-spacing: 0.5px; }

/* Serials filter bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.filter-bar input, .filter-bar select { width: auto; font-size: 14px; padding: 9px 12px; min-height: 44px; flex: 1; min-width: 130px; }
.filter-bar .btn { margin-top: 0; min-height: 44px; }

/* Serials data table */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); border: 1px solid var(--line); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); }
.tbl th { background: #f6f7f8; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 11px 12px; border-bottom: 1px solid #edf0f2; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.tappable:hover td { background: #fafbfc; cursor: pointer; }
.tbl .sn-cell { font-family: var(--mono); font-size: 14px; font-weight: 700; letter-spacing: 1px; color: var(--ink); }
.tbl .pn-cell { font-weight: 600; }
.tbl .meta-cell { color: var(--muted); font-size: 12px; }

/* Badge variants for table */
.badge.pending { background: #f1f3f4; color: var(--muted); }
.badge.sub     { background: #fff3ec; color: var(--accent); }
.badge.top     { background: #e8eaf6; color: #3949ab; }
.badge.complete { background: var(--pass-bg); color: var(--pass); }
.badge.in-progress { background: #e3f2fd; color: #1565c0; }

/* Modal */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(22,25,29,0.55); z-index: 40; align-items: flex-end; justify-content: center; }
.modal-backdrop.open { display: flex; }
.modal-sheet { background: var(--surface); border-radius: 18px 18px 0 0; width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto; padding: 20px 20px 40px; position: relative; }
@media (min-width: 600px) { .modal-backdrop { align-items: center; } .modal-sheet { border-radius: 14px; margin: 20px; max-height: 80vh; } }
.modal-handle { width: 40px; height: 4px; background: var(--line); border-radius: 2px; margin: 0 auto 16px; }
.modal-close { position: absolute; top: 16px; right: 16px; background: #f1f3f4; border: none; border-radius: 50%; width: 32px; height: 32px; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 14px; }

/* Detail rows in modal */
.detail-row { display: flex; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; gap: 12px; }
.detail-row:last-child { border-bottom: none; }
.detail-key { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; min-width: 110px; padding-top: 2px; }
.detail-val { flex: 1; font-family: var(--mono); }

/* Cache table in setup */
.cache-tbl { width: 100%; font-size: 13px; border-collapse: collapse; }
.cache-tbl td, .cache-tbl th { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.cache-tbl th { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: 0.4px; }
.cache-tbl tr:last-child td { border-bottom: none; }

/* ---- Mobile setup polish (<=560px) ---- */
@media (max-width: 560px) {
  .card { padding: 16px 14px; }

  /* Product Cache: collapse table into a stacked card per row so the
     Refresh button is no longer pushed off the right edge. */
  .cache-tbl thead { display: none; }
  .cache-tbl, .cache-tbl tbody, .cache-tbl tr, .cache-tbl td { display: block; width: 100%; }
  .cache-tbl tr { border: 1px solid var(--line); border-radius: 8px; padding: 4px 12px; margin-bottom: 8px; }
  .cache-tbl tr:last-child { margin-bottom: 0; }
  .cache-tbl td { border: none; padding: 6px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: right; }
  .cache-tbl td::before { content: attr(data-label); font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: 0.4px; text-align: left; }
  .cache-tbl td:last-child { padding: 8px 0 4px; }
  .cache-tbl td:last-child::before { display: none; }
  .cache-tbl td:last-child .btn.tiny { width: 100%; }
}
