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

:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --green: #16a34a;
  --green-dark: #15803d;
  --green-bg: #dcfce7;
  --green-border: #86efac;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --red-border: #fca5a5;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --amber-border: #fcd34d;
  --blue: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.05);
}

html, body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: #0f172a;
  color: #fff;
  padding: 14px 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
}

.brand-icon {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  background: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand h1 {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.brand p {
  font-size: 13px;
  color: #94a3b8;
}

.version {
  display: inline-block;
  background: var(--green);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 6px;
  vertical-align: middle;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.tab {
  border: none;
  background: transparent;
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--ink);
}

.tab.active {
  color: var(--green-dark);
  border-bottom-color: var(--green);
}

main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 24px 48px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.scan-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 20px;
  align-items: start;
}

.scan-box {
  padding: 20px;
}

.scan-box h2 {
  font-size: 17px;
  margin-bottom: 14px;
}

#scanner {
  width: 100%;
  height: 320px;
  border-radius: 10px;
  overflow: hidden;
  background: #0f172a;
  border: 1px solid var(--border);
}

#scanner video {
  object-fit: cover;
}

.scan-controls {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.manual-entry {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
}

.manual-entry label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.manual-row {
  display: flex;
  gap: 8px;
}

.manual-row input,
.panel-head input.search,
.panel-head select.search {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  background: #fff;
}

.manual-row input:focus,
.panel-head input.search:focus,
.panel-head select.search:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}

.scan-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  text-align: center;
}

.stat-num {
  display: block;
  font-size: 28px;
  font-weight: 800;
  color: var(--green-dark);
}

.stat-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.result {
  border-radius: var(--radius);
  padding: 26px 20px;
  text-align: center;
}

.result.hidden {
  display: none;
}

.result.ok {
  background: var(--green-bg);
  border: 2px solid var(--green);
}

.result.bad {
  background: var(--red-bg);
  border: 2px solid var(--red);
}

.result.warn {
  background: var(--amber-bg);
  border: 2px solid var(--amber);
}

.result .result-title {
  display: block;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.result .result-code {
  display: block;
  font-size: 18px;
  font-weight: 600;
  margin-top: 6px;
  word-break: break-all;
}

.result .result-desc {
  display: block;
  font-size: 14px;
  margin-top: 8px;
  opacity: 0.85;
}

.result .result-time {
  display: block;
  font-size: 12px;
  margin-top: 10px;
  opacity: 0.6;
}

.result.ok .result-title { color: var(--green-dark); }
.result.bad .result-title { color: var(--red); }
.result.warn .result-title { color: var(--amber); }

.panel-head {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  background: var(--green);
  color: #fff;
}

.btn.primary:hover {
  background: var(--green-dark);
}

.btn.secondary {
  background: #e2e8f0;
  color: var(--ink);
}

.btn.secondary:hover {
  background: #cbd5e1;
}

.btn.danger {
  background: var(--red-bg);
  color: var(--red);
}

.btn.danger:hover {
  background: var(--red-border);
}

.table-wrap {
  overflow-x: auto;
  padding: 0;
}

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

th {
  text-align: left;
  padding: 12px 14px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #f8fafc;
}

td .code {
  font-weight: 700;
  word-break: break-all;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.ok {
  background: var(--green-bg);
  color: var(--green-dark);
}

.badge.bad {
  background: var(--red-bg);
  color: var(--red);
}

.badge.warn {
  background: var(--amber-bg);
  color: var(--amber);
}

.badge.muted {
  background: #f1f5f9;
  color: var(--muted);
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-actions button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.row-actions button:hover {
  background: #f1f5f9;
}

.row-actions button.danger-row {
  color: var(--red);
  border-color: var(--red-border);
}

.row-actions button.danger-row:hover {
  background: var(--red-bg);
}

.empty-msg {
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
  font-size: 14px;
}

.hint-csv {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-box {
  width: 100%;
  max-width: 420px;
  padding: 24px;
}

.modal-box h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

.modal-box label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0 6px;
}

.modal-box label b {
  color: var(--red);
}

.modal-box input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
}

.modal-box input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.modal-result-box {
  width: 100%;
  max-width: 480px;
  padding: 34px 28px 26px;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: result-pop 0.25s ease-out;
}

@keyframes result-pop {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.modal-result-box .result-title {
  font-size: 34px;
}

.modal-result-box .result-code {
  font-size: 20px;
}

.modal-result-box .btn {
  margin-top: 18px;
  min-width: 140px;
  font-size: 15px;
  padding: 12px 20px;
}

.modal-result-box.ok .btn {
  background: var(--green-dark);
}

.modal-result-box.warn .btn {
  background: var(--amber);
}

.modal-result-box.bad .btn {
  background: var(--red);
}

.barcode-box {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 16px;
  text-align: center;
}

.barcode-box svg {
  max-width: 100%;
  height: auto;
}

.barcode-code {
  font-size: 16px;
  font-weight: 800;
  margin-top: 10px;
  letter-spacing: 2px;
  word-break: break-all;
}

.barcode-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

#print-area {
  position: fixed;
  top: 0;
  left: -10000px;
  width: 100%;
}

.print-label {
  display: inline-block;
  width: 3.7in;
  padding: 10px;
  margin: 5px;
  border: 1px dashed #999;
  text-align: center;
  page-break-inside: avoid;
}

.print-label svg {
  max-width: 100%;
  height: auto;
}

.print-code {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  margin-top: 4px;
  word-break: break-all;
}

.print-meta {
  font-size: 11px;
  color: #555;
}

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

  #print-area,
  #print-area * {
    visibility: visible;
  }

  #print-area {
    position: static;
    left: 0;
  }

  @page {
    margin: 8mm;
  }
}

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

#toast.error {
  background: var(--red);
}

#toast.ok {
  background: var(--green);
}

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

  .tabs {
    padding: 0 10px;
  }

  main {
    padding: 16px 12px 40px;
  }

  #scanner {
    height: 260px;
  }
}
