:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --ink: #17212f;
  --muted: #637083;
  --line: #d8e0e8;
  --blue: #1d63a7;
  --green: #16845f;
  --amber: #b66b12;
  --red: #bd3333;
  --shadow: 0 12px 34px rgba(32, 44, 61, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #334155;
  background: var(--surface-2);
}

.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(120deg, rgba(29, 99, 167, .14), transparent 38%),
    linear-gradient(300deg, rgba(22, 132, 95, .12), transparent 42%),
    var(--bg);
}

.login-panel {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 28px;
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin: 0;
  font-size: 42px;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  line-height: 1.45;
}

.stack {
  display: grid;
  gap: 14px;
}

.primary {
  background: var(--blue);
  color: #fff;
  padding: 11px 14px;
}

.ghost {
  background: #e8edf3;
  color: #253347;
  padding: 10px 14px;
}

.danger {
  background: var(--red);
  color: #fff;
  padding: 10px 14px;
}

.small {
  background: #e8edf3;
  color: #253347;
  padding: 8px 10px;
  font-size: 12px;
}

.btn-del {
  background: var(--red);
  color: #fff;
  padding: 6px 10px;
  font-size: 12px;
}

.lvl-select {
  padding: 6px 8px;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.icon-danger {
  min-width: 30px;
  min-height: 30px;
  padding: 4px 8px;
  border: 1px solid #f0b6b6;
  background: #ffe2e2;
  color: #8c2323;
  font-size: 13px;
}

.status.error {
  min-height: 20px;
  color: var(--red);
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  background: #121a24;
  color: #fff;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: var(--green);
  font-weight: 900;
}

.brand small {
  display: block;
  color: #9db0c5;
  margin-top: 2px;
}

.nav-tabs {
  display: grid;
  gap: 6px;
}

.nav-tabs button {
  padding: 11px 12px;
  text-align: left;
  background: transparent;
  color: #c8d3df;
}

.nav-tabs button.active,
.nav-tabs button:hover {
  background: #223044;
  color: #fff;
}

.sidebar .ghost {
  margin-top: auto;
  background: #223044;
  color: #fff;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.topbar h2 {
  margin: 0;
  font-size: 26px;
}

.operator-chip {
  min-width: 180px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: right;
}

.operator-chip strong {
  display: block;
  font-size: 15px;
}

.operator-chip #switchUserBtn {
  margin-top: 6px;
}

.operator-chip small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
  gap: 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.metric, .panel, .receipt-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(32, 44, 61, .06);
}

.metric {
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.production-total-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(32, 44, 61, .06);
}

.production-total-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.production-total-card strong {
  font-size: 30px;
}

.panel {
  padding: 16px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.panel-title h3, .backup-panel h3 {
  margin: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.op-sequence-grid {
  display: grid;
  grid-template-columns: 180px 220px auto;
  gap: 12px;
  align-items: end;
}

.scan-setup-grid {
  max-width: 620px;
}

.checkbox-label {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 9px;
}

.checkbox-label input {
  width: 18px;
  height: 18px;
}

.form-grid textarea,
.form-actions {
  grid-column: 1 / -1;
}

.form-actions, .button-row, .search-row {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

.button-row.compact {
  gap: 8px;
}

.search-row label {
  flex: 1 1 360px;
}

.queue-summary {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.op-queue-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  max-height: 150px;
  overflow: auto;
  padding: 2px;
}

.op-chip {
  display: inline-grid;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #253347;
  font-size: 12px;
}

.op-chip-wrap {
  display: inline-flex;
  align-items: stretch;
  gap: 4px;
}

.op-chip-wrap .icon-danger {
  min-width: 28px;
  min-height: 32px;
  align-self: stretch;
  border-radius: 999px;
}

.op-chip small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
}

.op-chip.active {
  border-color: var(--blue);
  background: #eaf3fc;
  color: #154b7e;
}

.op-chip.used {
  background: #e7f5ef;
  color: #0d6647;
  text-decoration: line-through;
}

.op-chip:disabled {
  cursor: default;
  opacity: .72;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.pill.ok { background: #dcf5ea; color: #0d6647; }
.pill.pending { background: #fff1d7; color: #80500b; }
.pill.bad { background: #ffe2e2; color: #8c2323; }
.pill.rma { background: #e7e0fb; color: #553c9a; }

.bars {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #e8edf3;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--green);
}

.bar-fill.warn { background: var(--amber); }
.bar-fill.bad { background: var(--red); }
.bar-fill.rma { background: #7c5cd6; }

.activity-list {
  display: grid;
  gap: 8px;
}

.activity-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.activity-item strong {
  display: block;
}

.trace-result {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.trace-card {
  border-left: 4px solid var(--blue);
  padding: 12px;
  background: var(--surface-2);
  border-radius: 6px;
}

.receipt-preview {
  padding: 22px;
  min-height: 260px;
}

.receipt-preview h3 {
  margin-top: 0;
  text-align: center;
}

.receipt-line {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 9px 0;
  gap: 18px;
}

.file-button {
  display: inline-flex;
  width: auto;
  align-items: center;
  border-radius: 6px;
  background: #e8edf3;
  color: #253347;
  padding: 10px 14px;
  cursor: pointer;
}

.file-button input {
  display: none;
}

.backup-panel {
  display: grid;
  gap: 16px;
}

pre {
  white-space: pre-wrap;
  margin: 0;
  color: var(--muted);
}

/* Popup central: vermelho p/ erro, verde p/ sucesso, escuro neutro p/ info. */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 300px;
  max-width: 460px;
  padding: 26px 34px;
  border-radius: 14px;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
  color: #fff;
  background: #121a24;
  box-shadow: 0 22px 60px rgba(15, 23, 32, .38);
  /* deixa passar o clique: o popup nunca bloqueia a tabela/botoes embaixo */
  pointer-events: none;
  animation: toast-pop .22s ease-out;
}

.toast::before {
  font-size: 44px;
  line-height: 1;
  font-weight: 700;
}

.toast-msg { display: block; }

/* unico elemento clicavel do popup: o "x" para fechar antes do tempo */
.toast-close {
  position: absolute;
  top: 8px;
  right: 12px;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 24px;
  line-height: 1;
  font-weight: 700;
  opacity: .75;
  cursor: pointer;
  pointer-events: auto;
}
.toast-close:hover { opacity: 1; }

.toast.success {
  background: #16915f;
  box-shadow: 0 22px 60px rgba(15, 80, 55, .42);
}
.toast.success::before { content: "\2714"; }

.toast.error {
  background: #cf3030;
  box-shadow: 0 22px 60px rgba(110, 25, 25, .44);
}
.toast.error::before { content: "\26A0"; }

@keyframes toast-pop {
  from { opacity: 0; transform: translate(-50%, -50%) scale(.85); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(18, 26, 36, .58);
}

.modal-panel {
  width: min(720px, 100%);
  max-height: min(780px, 92vh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.modal-panel h3 {
  margin: 0;
}

.scan-status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
}

.scan-status strong {
  color: var(--ink);
}

.draft-status {
  margin: 10px 0 0;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.scan-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
  margin-top: 14px;
}

.scan-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  margin: 12px 0;
}

.scan-row {
  display: grid;
  grid-template-columns: 42px 1fr 160px 34px;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 13px;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-grid, .dashboard-grid, .form-grid, .op-sequence-grid, .scan-form, .scan-row, .login-panel {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .operator-chip {
    text-align: left;
  }
}

@media print {
  body * {
    visibility: hidden;
  }

  #receiptPreview, #receiptPreview * {
    visibility: visible;
  }

  #receiptPreview {
    position: absolute;
    inset: 0;
    box-shadow: none;
    border: 0;
  }
}

/* ===== Bipagem rapida (Aprovados / Reprovados) ===== */
.scan-fast .scan-hint {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  font-size: 13px;
}
.count-badge {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 12px;
  font-weight: 700;
  color: var(--blue);
}
.obs-input {
  padding: 6px 8px;
  font-size: 13px;
  background: var(--surface-2);
}
.obs-input:focus {
  background: #fff;
  border-color: var(--blue);
}

/* ===== Acoes por linha (mover entre depositos + excluir) ===== */
.row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.btn-move {
  min-height: 30px;
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn-move.approve { background: #dcf5ea; color: #0d6647; border-color: #9fdcc2; }
.btn-move.reprove { background: #ffe2e2; color: #8c2323; border-color: #f0b6b6; }
.btn-move.rma     { background: #efe9fc; color: #553c9a; border-color: #cbbef0; }
.btn-move:hover { filter: brightness(.97); }

/* Destaque temporario ao bipar uma OP ja existente */
@keyframes row-flash {
  from { background: #fff3bf; }
  to   { background: transparent; }
}
.row-highlight > td { animation: row-flash 1.9s ease-out; }
