:root {
  color-scheme: dark;
  --bg: #0a0d12;
  --panel: #121821;
  --panel-strong: #171f2b;
  --line: #293445;
  --text: #f3f6fa;
  --muted: #8d9aae;
  --blue: #62a8ff;
  --cyan: #58d6c7;
  --red: #ff5c66;
  --green: #55d187;
  --amber: #f2bd59;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 85% 0%, rgba(49, 102, 173, 0.2), transparent 32rem),
    linear-gradient(145deg, #080b10, var(--bg));
  font-family: Inter, "Noto Sans TC", "Segoe UI", sans-serif;
}

.login-view {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
}

.login-card {
  width: min(430px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(155deg, rgba(23, 31, 43, 0.98), rgba(12, 17, 24, 0.98));
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 2rem;
}

.login-description,
.security-note {
  color: var(--muted);
}

.login-description {
  margin: 8px 0 24px;
  line-height: 1.6;
}

.field-label {
  display: block;
  margin: 14px 0 7px;
  color: #c8d1dd;
  font-size: 0.85rem;
}

.login-card input {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  background: #0b1017;
}

.login-card input:focus {
  border-color: var(--blue);
  outline: 2px solid rgba(98, 168, 255, 0.18);
}

.login-error {
  min-height: 1.25rem;
  margin: 12px 0 0;
  color: var(--red);
  font-size: 0.82rem;
}

.security-note {
  margin: 18px 0 0;
  font-size: 0.73rem;
  line-height: 1.55;
  text-align: center;
}

button,
select {
  font: inherit;
}

.app-shell {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 70px 0 48px;
}

.language-switcher {
  position: fixed;
  z-index: 20;
  top: 14px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: rgba(8, 12, 18, 0.94);
  box-shadow: var(--shadow);
  font-size: 0.78rem;
}

.language-switcher select {
  width: auto;
  min-width: 120px;
  padding: 7px 28px 7px 9px;
}

.topbar,
.panel-heading,
.camera-controls,
.action-row,
.roi-readout,
.workflow {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.eyebrow,
.section-number {
  margin: 0 0 5px;
  color: var(--blue);
  font: 700 0.72rem/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.16em;
}

h1,
h2,
.subtitle {
  margin: 0;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  letter-spacing: -0.04em;
}

h2 {
  font-size: 1.15rem;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
}

.status-pill,
.small-state {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.025);
  white-space: nowrap;
}

.status-pill {
  padding: 9px 14px;
  font-size: 0.82rem;
}

.status-ready {
  color: var(--green);
  border-color: rgba(85, 209, 135, 0.4);
}

.status-error {
  color: var(--red);
  border-color: rgba(255, 92, 102, 0.4);
}

.workflow {
  gap: 12px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.82rem;
}

.workflow span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.workflow span:not(:last-child)::after {
  content: "→";
  margin-left: 5px;
  color: #465369;
}

.workflow b {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  color: var(--blue);
  background: rgba(98, 168, 255, 0.12);
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0 0 16px;
  padding: 0;
  border: 0;
}

.mode-switch[hidden],
.mode-switch label[hidden] {
  display: none !important;
}

.mode-switch legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.mode-switch label {
  position: relative;
  display: block;
  cursor: pointer;
}

.mode-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-switch span {
  display: flex;
  min-height: 62px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  flex-direction: column;
  justify-content: center;
  background: rgba(18, 24, 33, 0.85);
  transition: border-color 120ms ease, background 120ms ease;
}

.mode-switch small {
  margin-top: 3px;
  color: var(--muted);
}

.mode-switch input:checked + span {
  border-color: var(--blue);
  background: rgba(98, 168, 255, 0.12);
}

.mode-switch input:focus-visible + span {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

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

.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(155deg, rgba(23, 31, 43, 0.96), rgba(15, 20, 28, 0.96));
  box-shadow: var(--shadow);
}

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

.small-state {
  max-width: 55%;
  overflow: hidden;
  padding: 6px 10px;
  font-size: 0.75rem;
  text-overflow: ellipsis;
}

.camera-controls {
  display: grid;
  grid-template-columns: auto minmax(150px, 1fr) auto;
  gap: 10px;
  margin-bottom: 12px;
}

.camera-controls label {
  align-self: center;
  color: var(--muted);
  font-size: 0.82rem;
}

select {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  background: #0d131b;
}

.media-frame {
  position: relative;
  display: grid;
  min-height: 320px;
  overflow: hidden;
  place-items: center;
  border: 1px solid #303d50;
  border-radius: 12px;
  background-color: #05070a;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 24px 24px;
}

video,
#captureCanvas,
.live-overlay {
  display: block;
  max-width: 100%;
  max-height: 62vh;
}

video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.live-frame video {
  position: relative;
  z-index: 1;
}

.live-overlay {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.live-overlay.roi-enabled {
  cursor: crosshair;
  touch-action: none;
  pointer-events: auto;
}

#captureCanvas {
  cursor: default;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.placeholder-icon {
  color: #4e6078;
  font-size: 2.4rem;
}

.button {
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--text);
  background: var(--panel-strong);
  cursor: pointer;
  transition: border-color 120ms ease, filter 120ms ease, transform 120ms ease;
}

.button:hover:not(:disabled) {
  filter: brightness(1.12);
  transform: translateY(-1px);
}

.button:focus-visible,
select:focus-visible,
#captureCanvas:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.button-primary {
  color: #07111d;
  background: var(--blue);
}

.button-secondary,
.button-ghost {
  border-color: var(--line);
}

.button-accent {
  color: #061412;
  background: var(--cyan);
}

.button-wide {
  width: 100%;
  margin-top: 12px;
}

.auto-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.auto-actions.single-action {
  grid-template-columns: 1fr;
}

.auto-readout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  margin-top: 9px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.18);
  font-size: 0.72rem;
}

.auto-readout code {
  color: var(--cyan);
  text-align: right;
}

.button-small {
  min-height: 36px;
  padding: 7px 11px;
  font-size: 0.78rem;
}

.roi-readout {
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  margin-top: 12px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.78rem;
  background: rgba(0, 0, 0, 0.18);
}

.roi-readout code {
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-row {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.preview-action-row {
  margin-top: 10px;
}

.internal-capture-panel {
  display: none !important;
}

.result-panel {
  margin-top: 16px;
}

.workspace > .result-panel {
  min-width: 0;
  margin-top: 0;
}

.result-heading {
  margin-bottom: 10px;
}

.result-heading-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

#requestState {
  max-width: 100%;
  overflow: visible;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: right;
  text-overflow: clip;
}

.result-visual {
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #05070a;
}

.result-visual-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
}

.result-visual-heading code {
  color: #ff8b92;
  font-family: "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0;
}

.result-status-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0 12px;
}

.result-timing-row {
  flex: 1;
  margin: 0;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 94px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 12px 20px rgba(0, 0, 0, 0.15);
}

.status-pass {
  color: #dfffe8;
  background: linear-gradient(135deg, rgba(31, 178, 90, 0.9), rgba(15, 126, 65, 0.95));
  border-color: rgba(145, 255, 185, 0.6);
}

.status-fail {
  color: #ffe4e6;
  background: linear-gradient(135deg, rgba(248, 81, 73, 0.92), rgba(160, 24, 27, 0.96));
  border-color: rgba(255, 170, 176, 0.75);
}

#resultCanvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: 70vh;
  object-fit: contain;
}

.ocr-results {
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #080c12;
}

.ocr-results-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
}

.ocr-results-heading code {
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0;
}

.ocr-result-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  max-height: 190px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px;
  scrollbar-color: var(--accent) #111823;
  scrollbar-width: auto;
}

.ocr-result-grid::-webkit-scrollbar {
  width: 10px;
}

.ocr-result-grid::-webkit-scrollbar-track {
  border-radius: 999px;
  background: #111823;
}

.ocr-result-grid::-webkit-scrollbar-thumb {
  border: 2px solid #111823;
  border-radius: 999px;
  background: var(--accent);
}

.ocr-result-item {
  min-width: 0;
  padding: 10px 8px;
  overflow-wrap: anywhere;
  border: 1px solid rgba(88, 214, 199, 0.24);
  border-radius: 8px;
  color: var(--text);
  background: rgba(88, 214, 199, 0.07);
  text-align: center;
  font: 0.88rem/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.ocr-result-empty {
  grid-column: 1 / -1;
  padding: 14px;
  overflow-wrap: anywhere;
  color: var(--muted);
  text-align: center;
}

.response-panel {
  margin-top: 16px;
}

.response-heading {
  margin-bottom: 10px;
}

.result-details {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #080c12;
}

.result-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  color: #bcd3ec;
  cursor: pointer;
  user-select: none;
}

.result-details summary:hover {
  background: rgba(255, 255, 255, 0.035);
}

.result-details summary small {
  color: var(--muted);
}

.result-details[open] summary {
  border-bottom: 1px solid var(--line);
}

#resultText {
  min-height: 190px;
  max-height: 440px;
  margin: 0;
  overflow: auto;
  padding: 16px;
  color: #bcd3ec;
  background: transparent;
  font: 0.82rem/1.65 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

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

  .workflow {
    overflow-x: auto;
    padding-bottom: 4px;
  }
}

@media (max-width: 600px) {
  .app-shell {
    width: min(100% - 20px, 1500px);
    padding-top: 70px;
  }

  .language-switcher {
    right: 10px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .camera-controls {
    grid-template-columns: 1fr;
  }

  .camera-controls label {
    display: none;
  }

  .media-frame {
    min-height: 230px;
  }

  .action-row .button {
    flex: 1;
  }

  .auto-actions {
    grid-template-columns: 1fr;
  }

  .mode-switch {
    grid-template-columns: 1fr;
  }
}
