:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #171717;
  --muted: #667085;
  --line: #d8dee8;
  --accent: #b5122d;
  --accent-dark: #7f1022;
  --black: #111111;
  --warn: #b45309;
  --danger: #b42318;
  --ok: #047857;
  --shadow: 0 16px 40px rgba(17, 17, 17, 0.09);
}

body.dark-mode {
  color-scheme: dark;
  --bg: #101418;
  --panel: #171d23;
  --ink: #edf2f7;
  --muted: #a7b0bd;
  --line: #303946;
  --accent: #ef405f;
  --accent-dark: #b5122d;
  --black: #0b0f14;
  --warn: #f59e0b;
  --danger: #fb7185;
  --ok: #34d399;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body.locked .app-shell {
  display: none;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #111 0%, #2a1116 46%, #b5122d 100%);
}

.login-card {
  width: min(460px, 100%);
  border-radius: 10px;
  padding: 24px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
}

.login-brand {
  margin-bottom: 24px;
}

.login-brand h1 {
  font-size: 28px;
}

.login-modes {
  display: grid;
  gap: 10px;
}

.first-password-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.login-separator {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.login-separator::before,
.login-separator::after {
  content: "";
  height: 1px;
  background: var(--line);
}

.login-submit {
  text-align: center;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button {
  border: 0;
}

.app-shell {
  width: min(1360px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

.topbar,
.brand,
.topbar-actions,
.scanner-panel,
.content-grid,
.panel-heading,
.scan-row,
.scan-actions,
.stats,
.actions,
.filters {
  display: flex;
  gap: 14px;
}

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

.brand {
  align-items: center;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--black), var(--accent));
  color: #fff;
  font-weight: 900;
}

.topbar-actions {
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

.title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.version-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: #fee4e2;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

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

.hint {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.scanner-panel {
  align-items: stretch;
  margin-bottom: 16px;
}

.scan-card,
.panel,
.stats article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.scan-card {
  flex: 1;
  padding: 18px;
}

.panel {
  padding: 18px;
}

.form-panel {
  width: 350px;
}

.inventory-panel {
  flex: 1;
  min-width: 0;
}

.panel-heading {
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

label {
  display: block;
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.user-switch {
  min-width: 250px;
  margin: 0;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  background: var(--panel);
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(181, 18, 45, 0.14);
}

textarea {
  resize: vertical;
}

.compact-select {
  max-width: 230px;
}

.qty-field {
  max-width: 90px;
}

.scan-row {
  align-items: center;
}

.scan-actions {
  flex-wrap: wrap;
  margin-top: 10px;
}

.primary-btn,
.warn-btn,
.ghost-btn,
.icon-btn {
  min-height: 40px;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 800;
}

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

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

.warn-btn {
  background: color-mix(in srgb, var(--warn) 18%, var(--panel) 82%);
  color: var(--warn);
}

.ghost-btn,
.icon-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}

.icon-btn {
  width: 36px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.status {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--muted);
}

.status.success {
  color: var(--ok);
  font-weight: 800;
}

.status.warning {
  color: var(--warn);
  font-weight: 800;
}

.camera-scanner {
  margin-top: 16px;
}

.camera-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101828;
}

.camera-frame > div,
.camera-frame video,
#qrReader video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

#qrReader {
  position: absolute !important;
  inset: 0;
  color: #fff;
  overflow: hidden;
}

#qrReader > div,
#qrReader__scan_region {
  width: 100% !important;
  height: 100% !important;
  border: 0 !important;
  background: transparent !important;
}

#qrReader__scan_region video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}

#qrReader__dashboard,
#qrReader__scan_region img,
#qrReader__header_message {
  display: none !important;
}

.scan-target {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(72%, 320px);
  aspect-ratio: 1.7 / 1;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 10px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.18);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.scan-target::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  top: 50%;
  height: 2px;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.9);
}

.camera-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.stats {
  width: 390px;
}

.stats article {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 18px 12px;
  text-align: center;
}

.stats span {
  font-size: 30px;
  font-weight: 900;
}

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

.workspace-layout {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 16px;
  align-items: flex-start;
}

.workspace-content {
  min-width: 0;
}

.taskbar {
  position: sticky;
  top: 16px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.taskbar-main {
  display: grid;
  gap: 8px;
}

.task {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 13px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
  text-align: left;
  white-space: nowrap;
}

.task.active,
.menu-action.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.app-menu {
  position: relative;
  flex: 0 0 auto;
}

.menu-btn {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  align-content: center;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  padding: 0;
}

.menu-btn span {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 999px;
  background: var(--ink);
}

.app-menu-panel {
  position: absolute;
  z-index: 20;
  right: 0;
  top: calc(100% + 8px);
  display: grid;
  width: 290px;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.app-menu-panel h3 {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  text-transform: uppercase;
}

.menu-action {
  width: 100%;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 11px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
  text-align: left;
}

.menu-action:hover {
  background: color-mix(in srgb, var(--panel) 82%, var(--accent) 18%);
}

.menu-action.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.menu-action.disabled,
.menu-action:disabled {
  cursor: not-allowed;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 88%, var(--line) 12%);
}

.menu-status {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.menu-status.online {
  color: var(--ok);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  margin: 0;
  padding: 2px 0;
  color: var(--ink);
}

.switch-control {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  width: 46px;
  height: 26px;
}

.switch-control input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  min-height: 100%;
  margin: 0;
  opacity: 0;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background 160ms ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 2px 7px rgba(15, 23, 42, 0.28);
  transition: transform 160ms ease;
}

.switch-control input:checked + .switch-track {
  background: var(--accent);
}

.switch-control input:checked + .switch-track::after {
  transform: translateX(20px);
}

.switch-control input:focus-visible + .switch-track {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.full-panel {
  grid-column: 1 / -1;
}

.content-grid {
  align-items: flex-start;
}

.filters {
  align-items: center;
}

.search {
  width: min(320px, 100%);
}

.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

form input,
form select {
  margin-bottom: 13px;
}

form .primary-btn {
  width: 100%;
  margin-top: 4px;
}

.import-box {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.full-btn {
  width: 100%;
  justify-content: center;
  margin-bottom: 10px;
}

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.item-code {
  color: var(--muted);
  font-family: Consolas, monospace;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  background: color-mix(in srgb, var(--panel) 78%, var(--line) 22%);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}

.badge.danger {
  background: color-mix(in srgb, var(--danger) 18%, var(--panel) 82%);
  color: var(--danger);
}

.badge.ok {
  background: color-mix(in srgb, var(--ok) 18%, var(--panel) 82%);
  color: var(--ok);
}

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

.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
}

.list-item span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.location-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.location-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
}

.location-card span,
.location-card small {
  display: block;
  color: var(--muted);
}

.location-card b {
  display: block;
  margin: 10px 0 4px;
  font-size: 28px;
}

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

.draft-list,
.batch-control-list {
  display: grid;
  gap: 10px;
  margin: 10px 0 14px;
}

.draft-heading {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.draft-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: color-mix(in srgb, var(--panel) 88%, var(--line) 12%);
}

.draft-item span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.draft-item button {
  min-height: 32px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--danger) 18%, var(--panel) 82%);
  color: var(--danger);
  font-weight: 800;
}

.small-empty {
  padding: 10px;
  font-size: 13px;
}

.inventory-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px 100px;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
}

.inventory-row span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.inventory-row input {
  margin: 0;
}

.inventory-row button {
  min-height: 38px;
  border-radius: 6px;
  background: var(--black);
  color: #fff;
  font-weight: 800;
}

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

.actions button {
  min-height: 32px;
  border-radius: 6px;
  padding: 0 10px;
  background: color-mix(in srgb, var(--panel) 78%, var(--line) 22%);
  color: var(--ink);
  font-weight: 800;
}

.actions .delete {
  background: color-mix(in srgb, var(--danger) 18%, var(--panel) 82%);
  color: var(--danger);
}

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

.label-card {
  min-height: 130px;
  border: 1px dashed #111;
  border-radius: 6px;
  padding: 12px;
  background: var(--panel);
}

.label-card span,
.label-card code {
  display: block;
  margin-top: 5px;
}

.barcode-bars {
  display: flex;
  align-items: stretch;
  gap: 2px;
  height: 40px;
  margin-top: 10px;
}

.barcode-bars i {
  display: block;
  background: #111;
}

.account-list,
.catalog-list,
.rights-list {
  display: grid;
  gap: 12px;
}

.heading-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.small-primary-btn {
  min-height: 30px;
  border-radius: 6px;
  padding: 0 12px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

#accountTempPassword {
  align-self: start;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 4px;
}

.catalog-card,
.account-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}

.catalog-card div > span,
.account-card div > span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.catalog-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.catalog-actions button {
  min-height: 32px;
  border-radius: 6px;
  padding: 0 10px;
  background: color-mix(in srgb, var(--panel) 78%, var(--line) 22%);
  color: var(--ink);
  font-weight: 800;
}

.catalog-actions .delete {
  background: color-mix(in srgb, var(--danger) 18%, var(--panel) 82%);
  color: var(--danger);
}

.batch-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
}

.batch-card.checked {
  border-color: rgba(4, 120, 87, 0.45);
  background: color-mix(in srgb, var(--ok) 12%, var(--panel) 88%);
}

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

.batch-head span,
.batch-meta span,
.batch-lines span,
.batch-actions small {
  color: var(--muted);
  font-size: 13px;
}

.batch-meta {
  justify-content: flex-start;
  margin-top: 10px;
}

.batch-lines {
  display: grid;
  gap: 5px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.batch-actions {
  justify-content: flex-end;
  margin-top: 12px;
}

.batch-actions .primary-btn {
  width: auto;
}

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

.top-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 70px;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.rank {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 999px;
  background: var(--black);
  color: #fff;
  font-weight: 900;
}

.top-info strong {
  display: block;
  margin-bottom: 8px;
}

.top-bar {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 78%, var(--line) 22%);
}

.top-bar i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

.top-item b {
  text-align: right;
  font-size: 20px;
}

.rights-card {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.rights-card span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.rights-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  font-weight: 700;
}

.check-row input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

.check-row span {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
}

.empty {
  padding: 18px 10px;
  color: var(--muted);
  text-align: center;
}

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

  .topbar,
  .scanner-panel,
  .taskbar,
  .panel-heading button {
    display: none !important;
  }

  .view {
    display: none !important;
  }

  #labelsView {
    display: block !important;
  }

  .panel {
    border: 0;
    box-shadow: none;
  }
}

@media (max-width: 980px) {
  .topbar,
  .scanner-panel,
  .content-grid {
    flex-direction: column;
  }

  .workspace-layout {
    grid-template-columns: 1fr;
  }

  .taskbar {
    position: static;
  }

  .taskbar-main {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .form-panel,
  .stats {
    width: 100%;
  }

  .dashboard-grid,
  .location-grid,
  .label-grid,
  .rights-card,
  .rights-options {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 18px, 1360px);
    padding-top: 14px;
  }

  .topbar-actions,
  .scan-row,
  .filters,
  .panel-heading,
  .taskbar {
    align-items: stretch;
    flex-direction: column;
  }

  .taskbar-main {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .app-menu {
    width: 100%;
  }

  .app-menu-panel {
    position: static;
    width: 100%;
    margin-top: 8px;
  }

  .compact-select,
  .qty-field,
  .search {
    max-width: none;
    width: 100%;
  }

  .stats,
  .dashboard-grid,
  .location-grid,
  .label-grid,
  .rights-card,
  .rights-options,
  .two-cols {
    grid-template-columns: 1fr;
  }

  .inventory-row {
    grid-template-columns: 1fr;
  }

  .draft-item,
  .top-item,
  .catalog-card,
  .catalog-actions,
  .batch-head,
  .batch-meta,
  .batch-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}
