:root {
  --brand: #c97b4b;
  --brand-dark: #a35e32;
  --bg: #fff8f0;
  --surface: #ffffff;
  --text: #2d2013;
  --muted: #8a7060;
  --border: #e8d5c0;
  --success: #4caf50;
  --danger: #e53935;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

header {
  background: var(--brand);
  color: white;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.01em; }

.icon-btn {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.2); }
.icon-btn svg { width: 22px; height: 22px; }

main { flex: 1; padding: 1.25rem; display: flex; flex-direction: column; gap: 1.25rem; }

/* Scanner section */
.scan-area {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

#preview-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#video, #preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#preview-img { display: none; }

.scan-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scan-frame {
  width: 80%;
  height: 60%;
  border: 2px solid rgba(255,255,255,0.6);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.35);
}

#preview-container.drag-over {
  outline: 3px dashed var(--brand);
  outline-offset: -3px;
}
#preview-container.drag-over .scan-placeholder {
  color: var(--brand);
}

.scan-placeholder {
  color: rgba(255,255,255,0.7);
  text-align: center;
  font-size: 0.9rem;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.scan-placeholder svg { width: 48px; height: 48px; opacity: 0.6; }

#video.hidden, #preview-img.hidden { display: none; }

.scan-controls {
  padding: 1rem;
  display: flex;
  gap: 0.75rem;
}

/* Buttons */
.btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }

.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #dcc9b0; }

.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline {
  background: transparent;
  border: 2px solid var(--brand);
  color: var(--brand);
}
.btn-outline:hover { background: var(--brand); color: white; }

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

/* Status/progress */
#status-bar {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  box-shadow: var(--shadow);
  display: none;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}
#status-bar.visible { display: flex; }

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Result card */
#result-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  display: none;
}
#result-card.visible { display: block; }
#result-card h2 { font-size: 1rem; margin-bottom: 1rem; color: var(--muted); }

.field-group { display: flex; flex-direction: column; gap: 0.875rem; margin-bottom: 1.25rem; }

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.field input {
  width: 100%;
  padding: 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.15s;
}
.field input:focus {
  outline: none;
  border-color: var(--brand);
}

.result-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.result-actions .btn { flex: 1; min-width: 120px; }

/* Records list */
#records-section {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

#records-section h2 {
  font-size: 0.95rem;
  color: var(--muted);
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#records-section h2 button {
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
  flex: unset;
}

#records-list { padding: 0.5rem 0; max-height: 320px; overflow-y: auto; }

.record-item {
  display: flex;
  align-items: center;
  padding: 0.75rem 1.25rem;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.record-item:last-child { border-bottom: none; }
.record-item:hover { background: var(--bg); }

.record-info { flex: 1; min-width: 0; }
.record-name { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.record-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

.record-price { font-weight: 700; color: var(--brand-dark); font-size: 1rem; white-space: nowrap; }

.record-actions { display: flex; gap: 0.4rem; }
.record-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--muted);
  transition: all 0.15s;
  white-space: nowrap;
}
.record-btn:hover { border-color: var(--brand); color: var(--brand); }
.record-btn.stripe-sent { border-color: var(--success); color: var(--success); }
.record-btn.delete { border-color: transparent; color: var(--danger); }
.record-btn.delete:hover { background: #fdecea; border-color: var(--danger); }

.empty-state {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Settings page */
.settings-body { padding: 1.25rem; display: flex; flex-direction: column; gap: 1.25rem; }

.settings-section {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}
.settings-section h2 { font-size: 0.95rem; font-weight: 700; margin-bottom: 0.25rem; }
.settings-section p { font-size: 0.85rem; color: var(--muted); margin-bottom: 1rem; line-height: 1.5; }

.settings-field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.875rem; }
.settings-field label { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.settings-field input {
  padding: 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: monospace;
  color: var(--text);
  background: var(--bg);
}
.settings-field input:focus { outline: none; border-color: var(--brand); }

.save-notice {
  display: none;
  color: var(--success);
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 0.5rem;
}

/* Toast */
#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  z-index: 100;
  transition: transform 0.3s ease;
  pointer-events: none;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.success { background: var(--success); }
#toast.error { background: var(--danger); }

/* OCR raw text */
.ocr-raw {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-family: monospace;
  margin-bottom: 1rem;
  max-height: 80px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.ocr-raw-label { font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.35rem; }
