:root {
  color-scheme: dark;
  --bg: #090b0c;
  --surface: #111416;
  --surface-raised: #171b1d;
  --surface-soft: #1d2224;
  --line: #2b3235;
  --line-strong: #3a4346;
  --text: #f4f6f5;
  --muted: #9aa4a5;
  --dim: #697476;
  --green: #43e58d;
  --green-deep: #163d2b;
  --red: #ff5f68;
  --red-deep: #461c22;
  --yellow: #f6c85f;
  --yellow-deep: #443617;
  --cyan: #58c9dc;
  --focus: #a7e7f1;
  --topbar-h: 116px;
  --commandbar-h: 68px;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 760px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) var(--commandbar-h);
  width: 100%;
  height: 100%;
  background: var(--bg);
}

.app-shell.has-network-banner {
  grid-template-rows: var(--topbar-h) 38px minmax(0, 1fr) var(--commandbar-h);
}

.topbar {
  display: grid;
  grid-template-columns: 220px minmax(540px, 1fr) 265px;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
  background: #0d1011;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  border-right: 1px solid var(--line);
}

.brand-block strong,
.brand-block span {
  display: block;
}

.brand-block strong {
  font-size: 20px;
  line-height: 1.1;
}

.brand-block div > span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 9px);
  grid-template-rows: repeat(2, 9px);
  gap: 3px;
  width: 21px;
  height: 21px;
}

.brand-mark i {
  display: block;
  background: var(--green);
}

.brand-mark i:nth-child(2) {
  background: var(--cyan);
}

.brand-mark i:nth-child(3) {
  grid-column: span 2;
  background: var(--yellow);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
}

.metric {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, auto) auto;
  grid-template-rows: auto 1fr;
  align-content: center;
  column-gap: 8px;
  padding: 17px 26px 14px;
  border-right: 1px solid var(--line);
}

.metric-label {
  grid-column: 1 / -1;
  align-self: end;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  align-self: end;
  overflow: hidden;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 48px;
  line-height: 1;
  text-overflow: ellipsis;
}

.metric-primary strong {
  color: var(--green);
}

.metric-unit {
  align-self: end;
  padding-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.top-status {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 9px;
  padding: 0 22px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.status-pill > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot,
.health-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dim);
  box-shadow: 0 0 0 3px rgba(105, 116, 118, 0.12);
}

[data-state="on"] .status-dot,
.health-dot.on {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(67, 229, 141, 0.14);
}

[data-state="warn"] .status-dot,
.health-dot.warn {
  background: var(--yellow);
  box-shadow: 0 0 0 3px rgba(246, 200, 95, 0.14);
}

[data-state="off"] .status-dot,
.health-dot.off {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(255, 95, 104, 0.14);
}

#clock {
  margin-top: 2px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.network-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 24px;
  overflow: hidden;
  border-bottom: 1px solid #775f23;
  background: var(--yellow-deep);
  color: #ffe8a8;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 316px;
  min-height: 0;
}

.viewer {
  display: grid;
  grid-template-rows: 60px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
}

.viewer-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-width: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.viewer-heading > div:first-child {
  min-width: 0;
}

.viewer-heading strong {
  display: inline-block;
  max-width: 460px;
  margin-left: 14px;
  overflow: hidden;
  vertical-align: bottom;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.capture-details {
  display: flex;
  flex: 0 0 auto;
  gap: 20px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.image-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #050606;
  box-shadow: inset 0 0 0 2px transparent;
}

.image-stage[data-level="success"] {
  animation: success-flash 560ms ease-out;
}

.image-stage[data-level="error"] {
  box-shadow: inset 0 0 0 4px var(--red);
}

.image-stage[data-level="warning"] {
  box-shadow: inset 0 0 0 4px var(--yellow);
}

@keyframes success-flash {
  0% { box-shadow: inset 0 0 0 10px var(--green); }
  100% { box-shadow: inset 0 0 0 2px rgba(67, 229, 141, 0.18); }
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: #d9dedd;
  font-size: 20px;
}

.empty-state > span:last-child {
  max-width: 440px;
  color: var(--dim);
  font-size: 13px;
}

.empty-glyph {
  position: relative;
  width: 66px;
  height: 84px;
  margin-bottom: 10px;
  border: 2px solid var(--line-strong);
}

.empty-glyph::before,
.empty-glyph::after {
  position: absolute;
  left: 13px;
  right: 13px;
  height: 2px;
  background: var(--line-strong);
  content: "";
}

.empty-glyph::before { top: 25px; }
.empty-glyph::after { top: 39px; }

.main-image-wrap {
  position: absolute;
  inset: 14px;
}

.main-image-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#detection-overlay {
  position: absolute;
  pointer-events: none;
  overflow: visible;
}

#detection-overlay rect {
  fill: rgba(67, 229, 141, 0.08);
  stroke: var(--green);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

#detection-overlay text {
  fill: #04140c;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
}

#detection-overlay .box-label {
  fill: var(--green);
  stroke: none;
}

.original-peek {
  position: absolute;
  top: 24px;
  right: 24px;
  width: clamp(180px, 22%, 320px);
  aspect-ratio: 4 / 3;
  margin: 0;
  overflow: hidden;
  border: 1px solid #687174;
  border-radius: 4px;
  background: #020303;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.42);
}

.original-peek img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.original-peek figcaption {
  position: absolute;
  z-index: 1;
  top: 7px;
  left: 7px;
  padding: 4px 7px;
  border-radius: 3px;
  background: rgba(3, 5, 5, 0.78);
  color: #d5dbda;
  font-size: 10px;
}

.feedback {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 28px;
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 360px;
  max-width: calc(100% - 80px);
  min-height: 64px;
  padding: 13px 22px;
  transform: translateX(-50%);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: rgba(17, 20, 22, 0.94);
  color: #d9dedd;
  font-size: 24px;
  font-weight: 750;
  line-height: 1.25;
  text-align: left;
}

.feedback[data-level="success"] {
  border-color: var(--green);
  background: rgba(10, 48, 30, 0.95);
  color: #b9ffd7;
}

.feedback[data-level="error"] {
  border-color: var(--red);
  background: rgba(68, 20, 26, 0.96);
  color: #ffd7d9;
  font-size: 30px;
}

.feedback[data-level="warning"] {
  border-color: var(--yellow);
  background: rgba(65, 50, 15, 0.96);
  color: #ffedb9;
}

.feedback-icon {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 2px solid currentColor;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}

.image-meta {
  position: absolute;
  z-index: 2;
  bottom: 8px;
  left: 12px;
  display: flex;
  gap: 14px;
  color: #879194;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.side-rail {
  display: grid;
  grid-template-rows: minmax(292px, 1.45fr) minmax(180px, 1fr) minmax(112px, 0.55fr);
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
}

.side-rail > section {
  min-height: 0;
  padding: 18px 20px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.section-heading > div {
  min-width: 0;
}

.section-heading strong {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-heading.compact {
  align-items: center;
  color: var(--dim);
  font-size: 11px;
}

.live-tag {
  flex: 0 0 auto;
  padding: 3px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  color: var(--muted);
  font-size: 10px;
}

.live-tag.on {
  border-color: #276944;
  color: var(--green);
}

.qr-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(188px, 100%);
  aspect-ratio: 1;
  margin: 14px auto 10px;
  overflow: hidden;
  border-radius: 4px;
  background: #fff;
}

#pairing-qr {
  display: block;
  width: 100%;
  height: 100%;
}

.batch-name,
.pairing-address {
  display: block;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.batch-name {
  font-size: 13px;
}

.pairing-address {
  margin-top: 5px;
  color: var(--dim);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.health-list {
  display: grid;
  gap: 10px;
  margin: 16px 0 0;
}

.health-list > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 24px;
}

.health-list dt,
.health-list dd {
  margin: 0;
  font-size: 12px;
}

.health-list dt {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.health-list dd {
  min-width: 0;
  overflow: hidden;
  color: #d8dddc;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-button {
  padding: 2px 0;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  background: transparent;
  color: var(--yellow);
  cursor: pointer;
  font-size: 12px;
}

.quality-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 14px;
}

.quality-stats > div {
  min-width: 0;
  padding: 0 7px;
  border-right: 1px solid var(--line);
  text-align: center;
}

.quality-stats > div:first-child { padding-left: 0; }
.quality-stats > div:last-child { padding-right: 0; border-right: 0; }

.quality-stats strong,
.quality-stats span {
  display: block;
}

.quality-stats strong {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.quality-stats span {
  margin-top: 5px;
  overflow: hidden;
  color: var(--dim);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.commandbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 16px;
  border-top: 1px solid var(--line);
  background: #0d1011;
}

.command-group {
  display: flex;
  min-width: 0;
  gap: 8px;
}

.command-button,
.secondary-button,
.submit-button,
.icon-button {
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface-raised);
  cursor: pointer;
}

.command-button {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  color: #dce1e0;
  white-space: nowrap;
}

.command-button:hover,
.icon-button:hover,
.secondary-button:hover {
  border-color: #667174;
  background: var(--surface-soft);
}

.command-button.primary { border-color: #2b7850; }
.command-button.primary:hover { background: var(--green-deep); }
.command-button.danger { border-color: #773139; }
.command-button.danger:hover { background: var(--red-deep); }
.command-button.warn { border-color: #735c25; }
.command-button.warn:hover { background: var(--yellow-deep); }

.command-button:disabled,
.submit-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  padding: 0 5px;
  border: 1px solid #596265;
  border-bottom-width: 2px;
  border-radius: 3px;
  background: #0b0d0e;
  color: #cdd3d2;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 10px;
}

.command-state {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--dim);
  font-size: 11px;
}

#command-message {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 21px;
  line-height: 1;
}

.batch-dialog {
  width: min(720px, calc(100% - 48px));
  max-height: calc(100% - 48px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.7);
}

.batch-dialog::backdrop {
  background: rgba(0, 0, 0, 0.76);
}

.batch-dialog form {
  padding: 24px;
}

.batch-dialog header,
.batch-dialog footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.batch-dialog h2 {
  margin: 4px 0 0;
  font-size: 25px;
}

.batch-dialog header .icon-button {
  align-self: flex-start;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field.wide {
  grid-column: 1 / -1;
  margin-top: 22px;
}

.form-grid .field.wide {
  margin-top: 0;
}

.field > span {
  color: var(--muted);
  font-size: 12px;
}

.field input,
.field select {
  width: 100%;
  height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #0c0f10;
  color: var(--text);
}

.field input::placeholder {
  color: #596265;
}

.form-error {
  margin: 15px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--red);
  background: var(--red-deep);
  color: #ffd4d7;
  font-size: 12px;
}

.batch-dialog footer {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.secondary-button,
.submit-button {
  min-width: 96px;
  height: 40px;
  padding: 0 16px;
}

.submit-button {
  border-color: #2b7850;
  background: #1c6d44;
  color: #fff;
  font-weight: 700;
}

.submit-button:hover {
  background: #238455;
}

@media (max-width: 1440px) {
  :root {
    --topbar-h: 100px;
    --commandbar-h: 62px;
  }

  .topbar {
    grid-template-columns: 184px minmax(480px, 1fr) 226px;
  }

  .brand-block { padding: 0 18px; }
  .metric { padding: 13px 18px 11px; }
  .metric strong { font-size: 39px; }
  .workspace { grid-template-columns: minmax(0, 1fr) 278px; }
  .side-rail > section { padding: 14px 16px; }
  .side-rail { grid-template-rows: minmax(250px, 1.35fr) minmax(165px, 0.9fr) minmax(100px, 0.5fr); }
  .qr-wrap { width: min(158px, 100%); margin-top: 10px; }
  .feedback { min-height: 58px; font-size: 20px; }
  .feedback[data-level="error"] { font-size: 25px; }
  .command-button { padding: 0 9px; }
}

@media (max-width: 1120px) {
  .topbar {
    grid-template-columns: 150px minmax(450px, 1fr) 166px;
  }

  .brand-block { gap: 9px; padding: 0 12px; }
  .brand-block strong { font-size: 17px; }
  .metric { padding-right: 12px; padding-left: 12px; }
  .metric strong { font-size: 34px; }
  .top-status { padding: 0 12px; }
  .workspace { grid-template-columns: minmax(0, 1fr) 244px; }
  .side-rail { grid-template-rows: minmax(232px, 1.3fr) minmax(160px, 0.9fr) minmax(96px, 0.5fr); }
  .side-rail > section { padding: 12px; }
  .qr-wrap { width: min(138px, 100%); }
  .health-list { gap: 7px; margin-top: 11px; }
  .quality-stats { margin-top: 9px; }
  .quality-stats strong { font-size: 18px; }
  .command-button span { display: none; }
  .command-button { width: 48px; justify-content: center; }
  .command-button:first-child { width: 68px; }
  .original-peek { width: 190px; }
}

@media (max-height: 800px) {
  :root {
    --topbar-h: 88px;
    --commandbar-h: 58px;
  }

  .metric strong { font-size: 34px; }
  .viewer { grid-template-rows: 50px minmax(0, 1fr); }
  .side-rail { grid-template-rows: minmax(210px, 1.15fr) minmax(146px, 0.8fr) minmax(86px, 0.45fr); }
  .side-rail > section { padding-top: 10px; padding-bottom: 10px; }
  .qr-wrap { width: min(126px, 100%); margin-top: 8px; margin-bottom: 6px; }
  .feedback { bottom: 20px; min-height: 52px; padding: 9px 16px; font-size: 18px; }
  .feedback[data-level="error"] { font-size: 22px; }
  .quality-stats { margin-top: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
