:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #111827;
  --line: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, #1d4ed840, transparent 40%),
    radial-gradient(circle at 80% 10%, #10b9812e, transparent 35%),
    var(--bg);
  font-family: "Segoe UI", "Noto Sans TC", sans-serif;
}

.app-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 12px calc(env(safe-area-inset-bottom, 0px) + 18px);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.05rem, 4vw, 1.45rem);
  font-weight: 700;
}

.api-status-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  font-size: 0.8rem;
  color: var(--muted);
}

.api-status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.3s;
}
.api-status-dot.ok          { background: var(--ok); }
.api-status-dot.auth_error  { background: var(--warn); }
.api-status-dot.error       { background: var(--err); }
.api-status-dot.disabled    { background: var(--muted); }

.api-status-label.ok         { color: #4ade80; }
.api-status-label.auth_error { color: #fbbf24; }
.api-status-label.error      { color: #f87171; }

.panel {
  background: linear-gradient(180deg, #1f2937, #111827);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
}

.scanner-box {
  width: 100%;
  min-height: 300px;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

#scanner video {
  width: 100% !important;
  height: auto !important;
  object-fit: cover;
}

.scanner-actions {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.scanner-actions .btn {
  min-height: 44px;
}

.status {
  margin-top: 10px;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.93rem;
  background: #1f2937;
  border: 1px solid var(--line);
}

.status.ok { border-color: #166534; color: #bbf7d0; }
.status.warn { border-color: #78350f; color: #fde68a; }
.status.err { border-color: #7f1d1d; color: #fecaca; }
.status.idle { color: var(--muted); }

.result-head,
.records-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.result-head h2,
.records-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.result-code {
  margin: 10px 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-family: "Cascadia Mono", Consolas, monospace;
  word-break: break-all;
}

.scan-success {
  animation: scanPulse 420ms ease-out;
}

@keyframes scanPulse {
  0% {
    box-shadow: 0 0 0 0 #22c55e00;
    border-color: var(--line);
  }
  40% {
    box-shadow: 0 0 0 4px #22c55e40;
    border-color: #22c55e;
  }
  100% {
    box-shadow: 0 0 0 0 #22c55e00;
    border-color: var(--line);
  }
}

.match-panel {
  border: 1px solid #365314;
  background: linear-gradient(180deg, #17230f, #0f1a0a);
  border-radius: 10px;
  padding: 10px;
}

.match-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.match-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.match-hint {
  margin: 8px 0;
  color: #d1d5db;
  font-size: 0.88rem;
}

.match-success {
  animation: matchPulse 520ms ease-out;
}

@keyframes matchPulse {
  0% {
    transform: scale(1);
    border-color: #365314;
  }
  45% {
    transform: scale(1.01);
    border-color: #22c55e;
  }
  100% {
    transform: scale(1);
    border-color: #365314;
  }
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.records-list .empty {
  margin: 0;
  text-align: center;
  color: var(--muted);
}

.record-item {
  border: 1px solid var(--line);
  background: #0b1220;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
}

.record-item:last-child {
  margin-bottom: 0;
}

.record-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.record-actions {
  display: flex;
  gap: 6px;
}

.record-code {
  margin: 0;
  word-break: break-all;
  font-family: "Cascadia Mono", Consolas, monospace;
  color: #cbd5e1;
  font-size: 0.9rem;
}

.match-line {
  margin-top: 6px;
  font-size: 0.88rem;
  border-radius: 8px;
  padding: 5px 8px;
}

.match-line.pending {
  color: #fcd34d;
  background: #422006;
  border: 1px solid #78350f;
}

.match-line.confirmed {
  color: #86efac;
  background: #052e16;
  border: 1px solid #166534;
}

.modal-dark {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
}

.modal-dark .form-control {
  background: #0f172a;
  color: var(--text);
  border-color: var(--line);
}

@media (max-width: 460px) {
  .scanner-box {
    min-height: 250px;
  }

  .record-meta {
    flex-direction: column;
    align-items: flex-start;
  }
}
