:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --ink: #18202f;
  --muted: #667085;
  --line: #dde3ea;
  --line-strong: #b9c2cf;
  --blue: #2563eb;
  --blue-soft: #e8f0ff;
  --green: #059669;
  --green-soft: #e6f7ef;
  --amber: #b7791f;
  --amber-soft: #fff6d8;
  --red: #d92d20;
  --red-soft: #ffe8e5;
  --violet: #6d35b8;
  --violet-soft: #f0e9fb;
  --shadow: 0 8px 24px rgba(20, 29, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  border-color: var(--line-strong);
}

button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

button.success {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

button.warning {
  background: var(--amber-soft);
  border-color: #efc35b;
  color: #7a4b00;
}

button.danger {
  background: var(--red-soft);
  border-color: #ffb5ad;
  color: var(--red);
}

button.icon {
  width: 36px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

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

textarea {
  min-height: 88px;
  resize: vertical;
}

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

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 190px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  background: linear-gradient(135deg, #2563eb, #059669);
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
}

.brand-title {
  font-size: 17px;
  font-weight: 800;
}

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

.role-switch,
.view-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  padding: 4px;
  border-radius: 8px;
  overflow-x: auto;
}

.role-switch button,
.view-tabs button {
  white-space: nowrap;
  border: 0;
  background: transparent;
  min-height: 32px;
}

.role-switch button.active,
.view-tabs button.active {
  background: white;
  box-shadow: 0 1px 4px rgba(20, 29, 43, 0.12);
}

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

.content {
  padding: 18px;
  max-width: 1440px;
  margin: 0 auto;
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 86px;
}

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

.metric-value {
  margin-top: 6px;
  font-weight: 800;
  font-size: clamp(20px, 3vw, 28px);
}

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

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-title {
  font-weight: 800;
}

.panel-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.panel-body {
  padding: 12px;
}

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

.toolbar .search {
  max-width: 280px;
}

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

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

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

th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #f8fafc;
  color: #394255;
  font-size: 12px;
  font-weight: 800;
}

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

tr.warn-row {
  background: var(--amber-soft);
}

tr.danger-row {
  background: var(--red-soft);
}

.cell-strong {
  font-weight: 700;
}

.money {
  font-variant-numeric: tabular-nums;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eef2f7;
  color: #344054;
  font-size: 12px;
  white-space: nowrap;
}

.tag.blue {
  background: var(--blue-soft);
  color: #174ea6;
}

.tag.green {
  background: var(--green-soft);
  color: #027a48;
}

.tag.amber {
  background: var(--amber-soft);
  color: #8a5a00;
}

.tag.red {
  background: var(--red-soft);
  color: var(--red);
}

.tag.violet {
  background: var(--violet-soft);
  color: var(--violet);
}

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

.issue {
  border: 1px solid #efc35b;
  background: var(--amber-soft);
  border-radius: 8px;
  padding: 10px;
}

.issue.high {
  border-color: #ffb5ad;
  background: var(--red-soft);
}

.issue-title {
  font-weight: 800;
}

.issue-detail {
  color: #5f4b18;
  font-size: 12px;
  margin-top: 3px;
}

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

.form-grid.one {
  grid-template-columns: 1fr;
}

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

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

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

.ai-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.scanner-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101828;
  overflow: hidden;
}

.scanner-box video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.qr-reader {
  width: 100%;
  min-height: 280px;
  background: #101828;
}

.qr-reader video {
  width: 100% !important;
  min-height: 260px;
  object-fit: cover;
}

.empty-video {
  aspect-ratio: 4 / 3;
  color: #d0d5dd;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 18px;
}

.scan-actions {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: white;
}

.scan-status {
  padding: 8px 10px;
  background: #fff6d8;
  color: #7a4b00;
  border-top: 1px solid #efc35b;
  font-size: 13px;
}

.history {
  display: grid;
  gap: 8px;
}

.history-item {
  border-left: 3px solid var(--blue);
  padding-left: 9px;
  font-size: 12px;
}

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

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(16, 24, 40, 0.38);
}

.modal {
  width: min(760px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: white;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 72px rgba(16, 24, 40, 0.28);
}

.modal-header {
  position: sticky;
  top: 0;
  background: white;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.modal-body {
  padding: 14px;
}

.mobile-list {
  display: none;
}

.item-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.item-row.warn-row {
  border-color: #efc35b;
  background: var(--amber-soft);
}

.item-row.danger-row {
  border-color: #ffb5ad;
  background: var(--red-soft);
}

.row-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

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

@media (max-width: 1100px) {
  .dashboard {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }

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

  .topbar {
    flex-wrap: wrap;
  }

  .brand {
    min-width: unset;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 10px;
  }

  .content {
    padding: 10px;
  }

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

  .view-tabs {
    width: 100%;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1;
  }

  .form-grid,
  .form-grid.three {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    display: none;
  }

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

  .metric {
    min-height: 78px;
  }
}
