/* ── RESET & BASE ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0f1e;
  --bg2:       #111827;
  --bg3:       #1a2235;
  --teal:      #00d4aa;
  --teal-dim:  #00a880;
  --amber:     #f59e0b;
  --red:       #ef4444;
  --text:      #f0f4f8;
  --text-muted:#8899aa;
  --border:    #1e2d3d;
  --radius:    14px;
  --scan-h:    56vw;   /* viewfinder height = 56% of viewport width */
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
}

/* ── HEADER ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 8px var(--teal);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text);
}

.status-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--teal);
  background: rgba(0,212,170,0.1);
  border: 1px solid rgba(0,212,170,0.3);
  padding: 3px 8px;
  border-radius: 20px;
  transition: all 0.3s;
}

.status-badge.scanning { color: var(--teal); border-color: rgba(0,212,170,0.5); background: rgba(0,212,170,0.15); }
.status-badge.found    { color: #22c55e; border-color: rgba(34,197,94,0.5); background: rgba(34,197,94,0.15); }
.status-badge.error    { color: var(--red); border-color: rgba(239,68,68,0.4); background: rgba(239,68,68,0.1); }

/* ── VIEWFINDER ── */
.viewfinder-section {
  padding: 16px;
  background: var(--bg);
}

.viewfinder-wrap {
  position: relative;
  width: 100%;
  height: var(--scan-h);
  min-height: 200px;
  max-height: 300px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Scanner corners overlay */
.scan-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scan-corner {
  position: absolute;
  width: 24px; height: 24px;
  border-color: var(--teal);
  border-style: solid;
}
.scan-corner.tl { top: 16px; left: 16px; border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.scan-corner.tr { top: 16px; right: 16px; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.scan-corner.bl { bottom: 16px; left: 16px; border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.scan-corner.br { bottom: 16px; right: 16px; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }

/* Scan line animation */
.scan-line {
  position: absolute;
  left: 16px; right: 16px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--teal), transparent);
  top: 16px;
  animation: scanMove 2s ease-in-out infinite;
  box-shadow: 0 0 8px var(--teal);
  opacity: 0;
  transition: opacity 0.3s;
}

.scanning-active .scan-line { opacity: 1; }

@keyframes scanMove {
  0%   { top: 16px; }
  50%  { top: calc(100% - 18px); }
  100% { top: 16px; }
}

/* Tap hint */
.tap-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  background: rgba(0,0,0,0.4);
  padding: 3px 10px;
  border-radius: 20px;
  pointer-events: none;
  transition: opacity 0.5s;
}

/* Focus ripple */
.focus-ripple {
  position: absolute;
  width: 60px; height: 60px;
  border: 2px solid var(--teal);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.5);
  transition: opacity 0.3s, transform 0.3s;
}

.focus-ripple.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  animation: rippleFade 0.6s forwards;
}

@keyframes rippleFade {
  0%   { opacity:1; transform: translate(-50%, -50%) scale(0.6); }
  100% { opacity:0; transform: translate(-50%, -50%) scale(1.3); }
}

/* ── CAM CONTROLS ── */
.cam-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-top: 14px;
}

.ctrl-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.ctrl-btn svg { width: 18px; height: 18px; }

.ctrl-btn:active { transform: scale(0.92); }

.ctrl-btn:hover, .ctrl-btn.active {
  border-color: var(--teal);
  color: var(--teal);
  background: rgba(0,212,170,0.08);
}

.ctrl-main {
  width: 56px; height: 56px;
  background: var(--teal);
  border-color: var(--teal);
  color: #000;
}

.ctrl-main:hover { background: var(--teal-dim); }

.ctrl-main.running {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

/* ── RESULT CARD ── */
.result-section {
  padding: 0 16px 16px;
}

.result-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 0.3s;
}

.result-card.flash-found {
  animation: flashFound 0.5s ease-out;
}

@keyframes flashFound {
  0%   { border-color: var(--teal); box-shadow: 0 0 20px rgba(0,212,170,0.4); }
  100% { border-color: var(--border); box-shadow: none; }
}

.result-card.flash-notfound {
  animation: flashNotFound 0.5s ease-out;
}

@keyframes flashNotFound {
  0%   { border-color: var(--red); box-shadow: 0 0 20px rgba(239,68,68,0.3); }
  100% { border-color: var(--border); box-shadow: none; }
}

/* Idle state */
.result-idle {
  text-align: center;
  color: var(--text-muted);
  padding: 24px;
}

.idle-icon svg {
  width: 40px; height: 40px;
  margin-bottom: 10px;
  opacity: 0.3;
}

.result-idle p { font-size: 13px; line-height: 1.5; }

/* Found state */
.result-found {
  width: 100%;
  padding: 20px;
}

.found-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--teal);
  margin-bottom: 8px;
}

.found-name {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
  margin-bottom: 12px;
}

.found-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.meta-chip {
  font-size: 11px;
  font-family: 'Courier New', monospace;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 6px;
}

.meta-tipe {
  color: var(--amber);
  border-color: rgba(245,158,11,0.3);
  background: rgba(245,158,11,0.08);
}

.found-principal {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Not found state */
.result-notfound {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
}

.nf-icon {
  font-size: 36px;
  font-weight: 900;
  color: var(--red);
  opacity: 0.7;
  margin-bottom: 8px;
}

.nf-code {
  font-family: monospace;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.result-notfound p { font-size: 12px; }

/* ── HISTORY ── */
.history-section {
  flex: 1;
  padding: 0 16px 24px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.clear-btn {
  background: none;
  border: none;
  color: var(--red);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.clear-btn:hover { opacity: 1; }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 20px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.history-item:hover { border-color: var(--teal); }

.history-item.not-found { opacity: 0.5; }

.hi-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--teal);
  flex-shrink: 0;
}
.history-item.not-found .hi-dot { background: var(--red); }

.hi-name {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hi-time {
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 24px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  transition: transform 0.3s ease, opacity 0.3s;
  opacity: 0;
  z-index: 999;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── LOADING OVERLAY ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 999;
  transition: opacity 0.4s;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

/* ── SAFE AREA ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .history-section { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}
/* ── SEARCH ── */
.search-section {
  padding: 0 16px 12px;
  background: var(--bg);
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

#searchInput {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 36px 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

#searchInput:focus {
  border-color: var(--teal);
}

#searchInput::placeholder {
  color: var(--text-muted);
}

.search-clear {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  display: none;
}

.search-results {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.search-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.search-item:hover {
  border-color: var(--teal);
}

.search-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.search-item-barcode {
  font-size: 11px;
  font-family: monospace;
  color: var(--text-muted);
  margin-top: 2px;
}