:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef3f7;
  --ink: #17212b;
  --muted: #637083;
  --line: #d8e0ea;
  --primary: #126d73;
  --primary-dark: #0d5055;
  --accent: #d6932b;
  --danger: #b83338;
  --success: #287d4f;
  --shadow: 0 18px 40px rgba(23, 33, 43, 0.12);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(18, 109, 115, 0.92), rgba(23, 33, 43, 0.75)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1200' height='700' viewBox='0 0 1200 700'%3E%3Crect fill='%23e9eff5' width='1200' height='700'/%3E%3Cpath fill='%23cdd8e2' d='M0 470h1200v230H0z'/%3E%3Crect x='78' y='120' width='250' height='360' rx='8' fill='%23fff'/%3E%3Crect x='367' y='160' width='338' height='255' rx='8' fill='%23fff'/%3E%3Crect x='750' y='98' width='300' height='385' rx='8' fill='%23fff'/%3E%3Crect x='119' y='160' width='170' height='26' fill='%2394a4b4'/%3E%3Crect x='402' y='198' width='260' height='30' fill='%2394a4b4'/%3E%3Crect x='792' y='142' width='215' height='34' fill='%2394a4b4'/%3E%3Ccircle cx='482' cy='508' r='58' fill='%23126d73'/%3E%3Ccircle cx='570' cy='508' r='58' fill='%23d6932b'/%3E%3Crect x='850' y='505' width='170' height='58' rx='6' fill='%2317212b'/%3E%3C/svg%3E") center / cover;
}

.login-panel {
  width: min(460px, 100%);
  padding: 32px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: 32px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 28px;
}

h3 {
  margin-bottom: 18px;
  font-size: 18px;
}

.muted,
small {
  color: var(--muted);
}

.form-grid {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #384455;
  font-size: 13px;
  font-weight: 700;
}

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

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(18, 109, 115, 0.14);
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.icon-button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
}

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

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

.secondary-button {
  background: #dcebee;
  color: var(--primary-dark);
}

.ghost-button {
  background: transparent;
  color: var(--primary-dark);
  border: 1px solid var(--line);
}

.danger-button {
  background: var(--danger);
  color: #fff;
}

.icon-button {
  min-width: 40px;
  padding: 0;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 22px;
}

.error-text {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.demo-box {
  display: grid;
  gap: 5px;
  margin-top: 22px;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
}

.demo-box strong {
  color: var(--ink);
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 24px;
  padding: 20px;
  background: #17212b;
  color: #fff;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #1f2933;
  font-weight: 900;
}

.brand small,
.user-box small {
  display: block;
  color: #b7c4d2;
}

.nav-tabs {
  display: grid;
  align-content: start;
  gap: 8px;
}

.nav-tab {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: transparent;
  color: #dce5ef;
  text-align: left;
  font-weight: 800;
}

.nav-tab:hover,
.nav-tab.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.user-box {
  display: grid;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
}

.user-box .ghost-button {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
}

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

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-box,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stat-box {
  display: grid;
  gap: 6px;
  padding: 16px;
}

.stat-box span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.stat-box strong {
  font-size: 28px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.toolbar input {
  flex: 1 1 280px;
}

.toolbar select {
  flex: 0 1 210px;
}

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

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

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

th {
  background: #eef3f7;
  color: #384455;
  font-size: 12px;
  text-transform: uppercase;
}

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

.item-title {
  display: grid;
  gap: 3px;
}

.item-title small {
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  background: #e5f2eb;
  color: var(--success);
  font-size: 12px;
  font-weight: 900;
}

.status-pill.off {
  background: #f8e7e8;
  color: var(--danger);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.actions button {
  min-height: 32px;
  border-radius: 8px;
  padding: 0 9px;
  border: 1px solid var(--line);
  background: #fff;
  color: #304050;
  font-weight: 800;
}

.actions .danger-action {
  color: var(--danger);
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 16px;
}

.scan-layout,
.detail-grid {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 16px;
}

.scanner-panel {
  position: relative;
  min-height: 420px;
  overflow: hidden;
  border-radius: 8px;
  background: #111820;
}

#scannerVideo {
  width: 100%;
  height: 100%;
  min-height: 420px;
  display: block;
  object-fit: cover;
}

.scan-frame {
  position: absolute;
  inset: 50% auto auto 50%;
  width: min(72%, 300px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 255, 255, 0.88);
  border-radius: 12px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.32);
}

.scan-frame::before,
.scan-frame::after {
  content: "";
  position: absolute;
  inset: -2px;
  border: 4px solid var(--accent);
  border-radius: 12px;
  pointer-events: none;
}

.scan-frame::before {
  clip-path: polygon(
    0 0, 28% 0, 28% 8px, 8px 8px, 8px 28%, 0 28%,
    0 72%, 8px 72%, 8px calc(100% - 8px), 28% calc(100% - 8px), 28% 100%, 0 100%
  );
}

.scan-frame::after {
  clip-path: polygon(
    72% 0, 100% 0, 100% 28%, calc(100% - 8px) 28%, calc(100% - 8px) 8px, 72% 8px,
    72% calc(100% - 8px), calc(100% - 8px) calc(100% - 8px), calc(100% - 8px) 72%, 100% 72%, 100% 100%, 72% 100%
  );
}

.asset-detail {
  display: grid;
  gap: 16px;
}

.detail-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
}

.detail-header h3 {
  margin: 0;
  font-size: 24px;
}

.detail-card dl {
  display: grid;
  grid-template-columns: 135px 1fr;
  gap: 10px 14px;
  margin: 0 0 18px;
}

.detail-card dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.detail-card dd {
  margin: 0;
}

.panel {
  padding: 18px;
}

.stack-list {
  display: grid;
  gap: 10px;
}

.list-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.list-row div:first-child {
  display: grid;
  gap: 3px;
}

.timeline {
  display: grid;
  gap: 10px;
}

.timeline-entry {
  display: grid;
  gap: 5px;
  padding: 14px;
  border-left: 4px solid var(--primary);
  background: var(--surface);
  border-radius: 8px;
}

.change-line {
  color: #384455;
  font-size: 13px;
}

.label-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.label-choice {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.label-choice input {
  width: 18px;
  min-height: 18px;
  margin-top: 3px;
}

dialog {
  width: min(720px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(23, 33, 43, 0.48);
}

.dialog-body {
  padding: 20px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.history-dialog {
  display: grid;
  grid-template-columns: 1fr;
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
}

.dialog-header,
.dialog-actions,
.wide {
  grid-column: 1 / -1;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-header h3 {
  margin: 0;
}

.dialog-actions {
  margin: 6px 0 0;
  padding: 0;
}

#printArea {
  display: none;
}

.print-label {
  width: 70mm;
  height: 38mm;
  box-sizing: border-box;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 1mm;
  padding: 2mm 3mm;
  border: 1px solid #111;
  background: #fff;
  color: #111;
  overflow: hidden;
  break-inside: avoid;
  page-break-inside: avoid;
}

.label-meta {
  min-width: 0;
}

.label-details {
  min-width: 0;
}

.qr-label {
  grid-template-columns: minmax(0, 1fr) 22mm;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "meta qr"
    "details qr";
  column-gap: 3mm;
  row-gap: 1mm;
  align-items: start;
}

.qr-label .label-meta {
  grid-area: meta;
}

.qr-label .label-details {
  grid-area: details;
}

.qr-label .qr-block {
  grid-area: qr;
}

.print-label strong {
  font-size: 11pt;
  line-height: 1.05;
}

.print-label span {
  font-size: 7pt;
  line-height: 1.1;
}

.barcode-block {
  display: grid;
  gap: 0.5mm;
  align-self: end;
  min-width: 0;
}

.qr-block {
  justify-self: center;
  align-self: center;
}

.barcode-svg {
  width: 100%;
  height: 13mm;
  display: block;
  overflow: hidden;
}

.qr-svg {
  width: 21mm;
  height: 21mm;
  display: block;
  shape-rendering: crispEdges;
}

.barcode-caption,
.plain-code {
  display: block;
  text-align: center;
  font-family: Consolas, "Courier New", monospace;
  letter-spacing: 0;
}

.barcode-caption {
  font-size: 6pt;
  line-height: 1;
}

.plain-code {
  align-self: end;
  font-size: 16pt;
  font-weight: 800;
}

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

  .sidebar {
    position: sticky;
    z-index: 20;
    top: 0;
    height: auto;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    grid-template-areas:
      "brand user"
      "nav nav";
    gap: 10px 12px;
    padding: 10px 12px 12px;
    box-shadow: 0 8px 22px rgba(23, 33, 43, 0.18);
  }

  .brand {
    grid-area: brand;
    min-width: 0;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 13px;
  }

  .nav-tabs {
    grid-area: nav;
    display: flex;
    gap: 8px;
    margin: 0 -12px;
    padding: 0 12px 2px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .nav-tabs::-webkit-scrollbar {
    display: none;
  }

  .nav-tab {
    flex: 0 0 auto;
    min-height: 36px;
    border-radius: 999px;
    padding: 0 14px;
    background: rgba(255, 255, 255, 0.08);
    text-align: center;
    white-space: nowrap;
    font-size: 13px;
  }

  .nav-tab.active {
    background: var(--accent);
    color: #17212b;
  }

  .user-box {
    grid-area: user;
    align-self: center;
    gap: 4px;
    padding: 0;
    border-top: 0;
    text-align: right;
  }

  .user-box small {
    display: none;
  }

  .user-box .ghost-button {
    min-height: 34px;
    padding: 0 10px;
  }

  .workspace {
    padding: 16px;
  }

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

  .toolbar select {
    width: 100%;
  }

  .stats-grid,
  .split-layout,
  .scan-layout,
  .detail-grid {
    grid-template-columns: 1fr;
  }

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

  .scanner-panel,
  #scannerVideo {
    min-height: min(460px, 72vh);
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tr {
    padding: 12px;
    border-bottom: 1px solid var(--line);
  }

  td {
    display: grid;
    grid-template-columns: 118px 1fr;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
  }

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

  .actions button {
    min-height: 38px;
  }

  .detail-header {
    grid-template-columns: 1fr;
  }

  .detail-card dl {
    grid-template-columns: 1fr;
  }

  .dialog-body {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .sidebar {
    grid-template-columns: minmax(0, 1fr) auto;
    padding-inline: 10px;
  }

  .brand strong {
    font-size: 14px;
  }

  .brand small,
  #currentUserName {
    display: none;
  }

  .nav-tabs {
    margin-inline: -10px;
    padding-inline: 10px;
  }

  .nav-tab {
    min-height: 34px;
    padding-inline: 12px;
    font-size: 12px;
  }
}

@media print {
  body {
    background: #fff;
  }

  #loginView,
  #appView,
  dialog {
    display: none !important;
  }

  #printArea {
    display: grid !important;
    grid-template-columns: repeat(2, 70mm);
    gap: 6mm;
    padding: 0;
  }
}
