/* 配色与桌面版保持一致 */
:root {
  --page-bg: #f3f4f6;
  --sidebar-bg: #1e2330;
  --sidebar-active: #2a3346;
  --card-bg: #ffffff;
  --border: #e4e7ec;
  --text-primary: #1f2937;
  --text-muted: #6b7280;
  --text-on-dark: #c9cfdb;
  --accent: #3b82f6;
  --accent-soft: #eaf1fe;
  --green: #0f9d58;
  --in-stock: #0f766e;
  --in-use: #b45309;
  --danger: #d64541;
  --danger-soft: #fdecea;
  --row-alt: #fbfcfd;
  --header-bg: #f7f8fa;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--page-bg);
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

/* ---------- 左侧导航 ---------- */
#sidebar {
  width: 212px;
  flex: 0 0 212px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 14px;
}

.brand {
  padding: 8px 4px 0;
  height: 74px;
}

.brand-title {
  font-size: 18px;
  font-weight: bold;
  color: #fff;
}

.brand-sub {
  margin-top: 8px;
  font-size: 11px;
  color: #7a8599;
}

#sidebar .divider {
  height: 1px;
  background: #2e3748;
  margin: 0;
}

#nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 0;
}

.nav-item {
  height: 42px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-on-dark);
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  padding: 0 16px;
  cursor: pointer;
}

.nav-item:hover {
  background: #232b3b;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: bold;
}

#sidebar .spacer {
  flex: 1;
}

.version {
  font-size: 11px;
  color: #6b7688;
}

/* ---------- 顶栏 ---------- */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#header {
  height: 72px;
  flex: 0 0 72px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

#page-title {
  margin: 0;
  font-size: 18px;
  font-weight: bold;
  line-height: 26px;
}

#page-subtitle {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
}

.status {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 24px;
  max-width: 46%;
  text-align: right;
}

.status.saving {
  color: var(--accent);
}

.status.error {
  color: var(--danger);
}

/* ---------- 内容区 ---------- */
#content {
  flex: 1;
  min-height: 0;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.page {
  display: none;
}

.page.active {
  display: flex;
}

/* ---------- 卡片 ---------- */
.card {
  flex: 1;
  min-height: 0;
  background: var(--card-bg);
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 18px 20px 16px;
  flex-direction: column;
  gap: 12px;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 26px;
  flex: 0 0 26px;
}

.card-title-row h2 {
  margin: 0;
  font-size: 16px;
  font-weight: bold;
}

.muted {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- 工具栏与控件 ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  flex: 0 0 36px;
}

input[type="text"],
textarea {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  background: #fff;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}

input[type="text"]::placeholder,
textarea::placeholder {
  color: #a0a6b1;
}

input[type="text"]:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

#search-input {
  width: 240px;
}

.toolbar-spacer {
  flex: 1;
}

textarea {
  height: auto;
  min-height: 76px;
  padding: 8px 12px;
  line-height: 1.5;
  resize: vertical;
}

.btn {
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 7px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  background: #f1f3f5;
  color: var(--text-primary);
  transition: filter 0.12s, background 0.12s;
}

.btn:hover {
  filter: brightness(0.96);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}

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

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

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

.btn-ghost {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 6px;
}

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

/* ---------- 表格 ---------- */
.table-wrap {
  flex: 1;
  min-height: 120px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table.data-table {
  width: 100%;
  min-width: 1000px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

table.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 34px;
  padding: 0 12px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 12px;
  font-weight: normal;
  color: var(--text-muted);
  white-space: nowrap;
}

table.data-table tbody td {
  height: 46px;
  padding: 0 12px;
  border-bottom: 1px solid #f1f2f4;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

table.data-table tbody tr:nth-child(even) td {
  background: var(--row-alt);
}

table.data-table tbody tr:hover td {
  background: #f6f9ff;
}

table.data-table tbody tr.row-flash td {
  background: var(--accent-soft);
  transition: background 0.4s;
}

td.cell-code {
  color: var(--text-muted);
}

td.cell-actions {
  white-space: nowrap;
}

td.cell-actions .btn {
  margin-right: 6px;
}

td.cell-actions .btn:last-child {
  margin-right: 0;
}

.tag-instock {
  color: var(--in-stock);
}

.tag-inuse {
  color: var(--in-use);
}

.tag-out {
  color: var(--in-use);
}

.tag-in {
  color: var(--in-stock);
}

.col-code {
  width: 112px;
}

.col-name {
  width: auto;
}

.col-status {
  width: 80px;
}

.col-holder {
  width: 110px;
}

.col-last {
  width: 170px;
}

.col-action {
  width: 300px;
}

.col-time {
  width: 150px;
}

.col-action-sm {
  width: 70px;
}

.col-note {
  width: 200px;
}

table.data-table tbody td.empty-row {
  height: 96px;
  text-align: center;
  color: var(--text-muted);
  border-bottom: 0;
}

/* ---------- 弹窗 ---------- */
#modal-root:empty {
  display: none;
}

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.24);
  display: flex;
  flex-direction: column;
  max-height: 88vh;
  width: 460px;
  max-width: calc(100vw - 32px);
}

.modal-header {
  padding: 18px 20px 0;
  font-size: 16px;
  font-weight: bold;
}

.modal-body {
  padding: 14px 20px 4px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-footer {
  padding: 14px 20px 18px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.field-caption {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-message {
  min-height: 18px;
  font-size: 12px;
  color: var(--danger);
}

.info-row {
  display: flex;
  gap: 8px;
  font-size: 13px;
  line-height: 22px;
}

.info-row .info-label {
  width: 80px;
  flex: 0 0 80px;
  font-size: 12px;
  color: var(--text-muted);
}

.info-row .info-value {
  flex: 1;
  color: var(--text-primary);
  word-break: break-all;
}

.detail-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0 4px;
}

.detail-subtitle {
  font-size: 14px;
  font-weight: bold;
  margin: 0;
}

.detail-records {
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.detail-records table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.detail-records thead th {
  position: sticky;
  top: 0;
  background: var(--header-bg);
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: normal;
  color: var(--text-muted);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.detail-records tbody td {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-bottom: 1px solid #f3f4f6;
}

.detail-records tbody tr:nth-child(even) td {
  background: #f7f8fa;
}

.device-caption {
  font-size: 14px;
  color: var(--text-primary);
}

/* ---------- 二维码 ---------- */

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 6px 0 2px;
}

.qr-box img {
  width: 220px;
  height: 220px;
  image-rendering: pixelated;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.qr-code-text {
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 2px;
  color: var(--text-primary);
}

.qr-tip {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
}

.scan-area {
  position: relative;
  width: 100%;
  height: 300px;
  background: #10141c;
  border-radius: 8px;
  overflow: hidden;
}

.scan-area video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scan-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 200px;
  height: 200px;
  margin: -100px 0 0 -100px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 10px;
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

.device-caption-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* ---------- 窄屏 ---------- */
@media (max-width: 900px) {
  #sidebar {
    width: 150px;
    flex-basis: 150px;
  }

  #header {
    padding-left: 16px;
    padding-right: 16px;
  }

  #content {
    padding: 12px;
  }

  .status {
    display: none;
  }

  .modal {
    width: calc(100vw - 32px);
  }

  #search-input {
    width: 160px;
  }
}
