/* RWS tablet UI — dark industrial theme, landscape-first, glove-sized targets */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-3: #898781;
  --hairline: #2c2c2a;
  --accent: #3987e5;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --radius: 14px;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  user-select: none;
}

/* ---- status bar ---- */
#statusbar {
  height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}
.sb-brand { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.sb-brand span { font-weight: 400; color: var(--ink-2); font-size: 16px; margin-left: 6px; }
.sb-right { display: flex; align-items: center; gap: 10px; }
.sb-chip {
  font-size: 14px; color: var(--ink-2);
  background: var(--surface-2); border: 1px solid var(--hairline);
  padding: 6px 12px; border-radius: 99px;
}
.sb-chip.ok::before { content: "●"; color: var(--good); margin-right: 6px; font-size: 10px; }
.sb-chip.bad::before { content: "●"; color: var(--critical); margin-right: 6px; font-size: 10px; }
.sb-btn {
  font-size: 14px; color: var(--ink-2); background: none;
  border: 1px solid var(--hairline); padding: 8px 14px; border-radius: 99px;
}

#app { height: calc(100% - 56px); overflow-y: auto; padding: 24px; }

/* ---- shared ---- */
button { font-family: inherit; color: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 60px; padding: 0 28px; white-space: nowrap;
  font-size: 19px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--hairline);
  border-radius: var(--radius);
  transition: transform .05s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:disabled { background: var(--surface-2); border-color: var(--hairline); color: var(--ink-3); }
.btn.ghost { background: none; }
.btn.danger { border-color: var(--critical); color: var(--critical); background: none; }
.btn.big { min-height: 76px; font-size: 22px; width: 100%; }

input[type=text], input[type=password], input[type=number], textarea {
  width: 100%; min-height: 60px; padding: 0 18px;
  font-size: 20px; font-family: inherit;
  color: var(--ink); background: var(--page);
  border: 1.5px solid var(--hairline); border-radius: var(--radius);
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
label.fld { display: block; font-size: 15px; color: var(--ink-2); margin: 18px 0 8px; }

.view-head { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.view-head h1 { font-size: 24px; font-weight: 700; }
.view-head .sub { color: var(--ink-2); font-size: 16px; }
.back-btn {
  min-width: 60px; min-height: 60px; font-size: 26px;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius);
}

.card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 20px;
}

/* ---- login ---- */
.login-wrap { max-width: 480px; margin: 6vh auto 0; }
.login-logo { text-align: center; margin-bottom: 30px; }
.login-logo .mark { font-size: 54px; }
.login-logo h1 { font-size: 30px; margin-top: 8px; }
.login-logo p { color: var(--ink-2); margin-top: 6px; font-size: 16px; }
.login-hint { margin-top: 18px; text-align: center; color: var(--ink-3); font-size: 14px; line-height: 1.6; }

/* ---- order queue ---- */
.order-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.order-card { text-align: left; padding: 22px; }
.order-card .ono { font-size: 15px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.order-card h3 { font-size: 22px; margin: 8px 0 4px; }
.order-card .lot { color: var(--ink-2); font-size: 16px; }
.order-card .prog { margin-top: 16px; display: flex; align-items: center; gap: 12px; }
.prog-track { flex: 1; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.prog-fill { height: 100%; border-radius: 4px; background: var(--accent); }
.prog-fill.done { background: var(--good); }
.prog-num { font-size: 15px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.badge { display: inline-block; font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 6px; }
.badge.WAIT { background: var(--surface-2); color: var(--ink-2); }
.badge.RUN { background: rgba(57,135,229,.15); color: var(--accent); }
.badge.DONE { background: rgba(12,163,12,.15); color: var(--good); }
.badge.HANDED { background: var(--surface-2); color: var(--good); border: 1px solid var(--good); }

/* ---- material list ---- */
.mat-list { display: flex; flex-direction: column; gap: 12px; }
.mat-row {
  display: flex; align-items: center; gap: 18px;
  padding: 18px 20px; text-align: left;
}
.mat-row .seq {
  min-width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); font-weight: 700; font-size: 18px;
}
.mat-row .info { flex: 1; }
.mat-row .info h4 { font-size: 20px; }
.mat-row .info .meta { color: var(--ink-2); font-size: 15px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.mat-row .state { text-align: right; }
.mat-state { font-size: 15px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.mat-state.WAIT { color: var(--ink-3); }
.mat-state.VERIFIED { color: var(--accent); }
.mat-state.WEIGHED { color: var(--warning); }
.mat-state.DONE { color: var(--good); }
.mat-row .qty { font-size: 17px; color: var(--ink-2); margin-top: 4px; font-variant-numeric: tabular-nums; }

/* ---- scan panel ---- */
.scan-panel { display: flex; gap: 12px; margin-bottom: 20px; }
.scan-panel input { flex: 1; }
.scan-result { margin-bottom: 20px; padding: 16px 20px; border-radius: var(--radius); font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.scan-result.ok { background: rgba(12,163,12,.12); border: 1px solid var(--good); color: var(--good); }
.scan-result.fail { background: rgba(208,59,59,.12); border: 1px solid var(--critical); color: var(--critical); }

/* ---- scale select ---- */
.scale-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.scale-card { text-align: left; padding: 22px; }
.scale-card h3 { font-size: 21px; margin-bottom: 6px; }
.scale-card .meta { color: var(--ink-2); font-size: 15px; }
.scale-card .chk { margin-top: 14px; font-size: 15px; font-weight: 600; }
.scale-card .chk.ok { color: var(--good); }
.scale-card .chk.warn { color: var(--warning); }
.scale-card .claimed { color: var(--critical); }

/* ---- weighing (S5) ---- */
.weigh-layout {
  display: grid; grid-template-columns: 1fr 380px; gap: 20px;
  /* fit everything (incl. tolerance bar) in one screen: viewport minus statusbar/header/paddings */
  height: calc(100vh - 245px); min-height: 420px;
}
.weigh-main { display: flex; flex-direction: column; gap: 16px; min-height: 0; }
.weight-display {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative; min-height: 0;
}
.weight-value {
  font-size: clamp(72px, 13vw, 148px); font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -2px;
}
.weight-value .unit { font-size: .3em; font-weight: 500; color: var(--ink-2); margin-left: 10px; letter-spacing: 0; }
.stable-ind {
  margin-top: 14px; font-size: 18px; font-weight: 700;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 18px; border-radius: 99px;
}
.stable-ind.stable { background: rgba(12,163,12,.14); color: var(--good); }
.stable-ind.unstable { background: rgba(250,178,25,.14); color: var(--warning); }
.stable-ind.off { background: var(--surface-2); color: var(--ink-3); }
.judge-flag { position: absolute; top: 14px; right: 18px; font-size: 17px; font-weight: 700; }
.judge-flag.OK { color: var(--good); }
.judge-flag.UNDER, .judge-flag.OVER { color: var(--critical); }

/* tolerance bar */
.tol-wrap { padding: 22px 26px 30px; }
.tol-scale-head { display: flex; justify-content: space-between; color: var(--ink-2); font-size: 15px; margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.tol-track { position: relative; height: 26px; border-radius: 13px; background: var(--surface-2); }
.tol-zone { position: absolute; top: 0; height: 100%; }
.tol-zone.permit { background: rgba(250,178,25,.30); }
.tol-zone.manage { background: rgba(12,163,12,.38); }
.tol-zone.left-round { border-radius: 13px 0 0 13px; }
.tol-zone.right-round { border-radius: 0 13px 13px 0; }
.tol-target { position: absolute; top: -7px; width: 3px; height: 40px; background: var(--ink); border-radius: 2px; }
.tol-needle {
  position: absolute; top: -10px; width: 5px; height: 46px;
  background: var(--accent); border-radius: 3px;
  box-shadow: 0 0 10px rgba(57,135,229,.8);
  transition: left .12s linear;
}
.tol-needle.out { background: var(--critical); box-shadow: 0 0 10px rgba(208,59,59,.8); }
.tol-labels { position: relative; height: 20px; margin-top: 12px; color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.tol-labels span { position: absolute; transform: translateX(-50%); }

.tol-acc {
  position: absolute; top: -4px; width: 4px; height: 34px;
  background: var(--good); border-radius: 2px;
  transition: left .2s ease;
}

/* pack list (subdivision) */
.pack-list { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; max-height: 22vh; overflow-y: auto; }
.pack-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 10px; background: var(--surface-2);
  font-size: 16px;
}
.pack-row .pk-no { color: var(--ink-2); min-width: 48px; }
.pack-row .pk-qty { flex: 1; font-weight: 700; font-variant-numeric: tabular-nums; }
.pack-row .pk-manual { font-size: 12px; color: var(--warning); border: 1px solid var(--warning); padding: 2px 8px; border-radius: 6px; }
.pack-row .pk-del {
  min-width: 40px; min-height: 40px; border-radius: 8px;
  background: none; border: 1px solid var(--hairline); color: var(--ink-3); font-size: 16px;
}

/* weigh side panel */
.weigh-side { display: flex; flex-direction: column; gap: 14px; }
.weigh-side .card h4 { font-size: 15px; color: var(--ink-2); font-weight: 600; margin-bottom: 6px; }
.weigh-side .card .v { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.weigh-side .card .v small { color: var(--ink-2); font-weight: 400; font-size: 15px; }
.tare-row { display: flex; gap: 10px; align-items: center; }
.tare-row input { flex: 1; }
.confirm-btn { min-height: 96px !important; font-size: 26px !important; }
.manual-link { text-align: center; color: var(--ink-3); font-size: 15px; background: none; border: none; text-decoration: underline; min-height: 44px; }

/* ---- photos (S6) ---- */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.photo-slot {
  aspect-ratio: 4/3; border-radius: var(--radius); overflow: hidden; position: relative;
  background: var(--surface-2); border: 1.5px dashed var(--hairline);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  font-size: 17px; color: var(--ink-2);
}
.photo-slot.filled { border-style: solid; border-color: var(--good); }
.photo-slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-slot .slot-tag {
  position: absolute; top: 10px; left: 10px; z-index: 1;
  background: rgba(0,0,0,.65); padding: 4px 10px; border-radius: 6px; font-size: 14px; color: #fff;
}
.photo-slot .shot { z-index: 1; }
#cam-video { width: 100%; border-radius: var(--radius); background: #000; }

/* ---- sign (S7) ---- */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal { width: min(560px, 92vw); background: var(--surface); border: 1px solid var(--hairline); border-radius: 18px; padding: 28px; max-height: 90vh; overflow-y: auto; }
.modal h2 { font-size: 23px; margin-bottom: 6px; }
.modal .desc { color: var(--ink-2); font-size: 16px; line-height: 1.5; }
.modal .actions { display: flex; gap: 12px; margin-top: 26px; }
.modal .actions .btn { flex: 1; }

/* ---- label (S8) ---- */
.label-preview {
  background: #fff; color: #111; border-radius: 10px; padding: 24px;
  font-family: system-ui, sans-serif; max-width: 460px;
}
.label-preview h3 { font-size: 20px; border-bottom: 2px solid #111; padding-bottom: 8px; margin-bottom: 12px; }
.label-preview .row { display: flex; justify-content: space-between; font-size: 16px; padding: 4px 0; }
.label-preview .row b { font-variant-numeric: tabular-nums; }
.label-preview .net { font-size: 24px; font-weight: 800; margin: 10px 0; }
.label-preview .bc {
  margin-top: 14px; padding: 12px 6px; text-align: center;
  font-family: "Libre Barcode 128", monospace; overflow: hidden;
}
.label-preview .bc .bars { display: flex; justify-content: center; align-items: stretch; height: 62px; }
.label-preview .bc .bars i { display: block; }
.label-preview .bc .txt { font-size: 12px; margin-top: 6px; font-variant-numeric: tabular-nums; }

/* ---- done (S9) ---- */
.done-wrap { max-width: 560px; margin: 8vh auto 0; text-align: center; }
.done-wrap .mark { font-size: 84px; }
.done-wrap h1 { font-size: 30px; margin: 18px 0 10px; }
.done-wrap p { color: var(--ink-2); font-size: 17px; line-height: 1.6; }

/* ---- audit ---- */
.audit-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.audit-table th, .audit-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--hairline); }
.audit-table th { color: var(--ink-3); font-weight: 600; }
.audit-table td { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.audit-table td.act { color: var(--ink); font-weight: 600; }

/* ---- toast ---- */
#toast-wrap { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 10px; }
.toast {
  padding: 16px 26px; border-radius: 12px; font-size: 17px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--hairline);
  animation: toast-in .18s ease-out;
}
.toast.ok { border-color: var(--good); color: var(--good); }
.toast.err { border-color: var(--critical); color: var(--critical); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

@media (max-width: 900px) {
  .weigh-layout { grid-template-columns: 1fr; }
}
