/* ── Variables ───────────────────────────────────────────────────────────────── */
:root {
  --bg:           #0d0d1a;
  --surface:      #1a1a2e;
  --card:         #16213e;
  --border:       #252550;
  --primary:      #7c4dff;
  --primary-dark: #6039ca;
  --primary-glow: rgba(124, 77, 255, 0.3);
  --success:      #00c853;
  --danger:       #ff1744;
  --warning:      #ff9100;
  --text:         #e8e8ff;
  --text-muted:   #6868a0;
  --accent:       #4fc3f7;
  --header-h:     56px;
  --nav-h:        64px;
}

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

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

/* ── Header ──────────────────────────────────────────────────────────────────── */
.app-header {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}

.app-header h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  background: linear-gradient(130deg, #a47dff, #4fc3f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  line-height: 1;
  transition: background 0.15s;
}
.icon-btn:active { background: var(--border); }

/* ── Main & screens ──────────────────────────────────────────────────────────── */
.app-main {
  position: fixed;
  top: var(--header-h);
  bottom: var(--nav-h);
  left: 0; right: 0;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.screen.active { display: flex; }

/* ── Bottom Navigation ───────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  inset: auto 0 0 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px 0;
  transition: color 0.2s;
}
.nav-btn.active { color: var(--primary); }
.nav-btn:active { background: rgba(255,255,255,0.04); }

.nav-icon  { font-size: 1.35rem; line-height: 1; }
.nav-label { font-size: 0.62rem; font-weight: 600; letter-spacing: 0.6px; text-transform: uppercase; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 22px;
  border: none;
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:active  { transform: scale(0.95); }
.btn:disabled { opacity: 0.4; pointer-events: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #a066ff);
  color: #fff;
  box-shadow: 0 4px 18px var(--primary-glow);
}
.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-success {
  background: linear-gradient(135deg, #00c853, #1de9b6);
  color: #fff;
  box-shadow: 0 4px 18px rgba(0,200,83,0.3);
}
.btn-danger {
  background: linear-gradient(135deg, #ff1744, #ff4081);
  color: #fff;
}
.btn-sm {
  padding: 8px 14px;
  font-size: 0.8rem;
  border-radius: 10px;
}

/* ────────────────────────────────────────────────────────────────────────────── */
/*  CAMERA SCREEN                                                                 */
/* ────────────────────────────────────────────────────────────────────────────── */
#screen-camera { overflow: hidden; }

.camera-container {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none; /* shown by JS when stream is ready */
}

/* ── Scan overlay & corners ─────────────────────────────────────────────────── */
#scan-overlay {
  position: absolute;
  inset: 0;
  display: none; /* shown by JS */
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: background 0.15s;
}
#scan-overlay.flash { background: rgba(255,255,255,0.55); }

.scan-frame {
  width: 75%;
  max-width: 300px;
  aspect-ratio: 4/3;
  position: relative;
}

.corner {
  position: absolute;
  width: 26px;
  height: 26px;
  border-color: rgba(255,255,255,0.9);
  border-style: solid;
  animation: corner-pulse 2.2s ease-in-out infinite;
}
.corner.tl { top: 0;    left: 0;   border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.corner.tr { top: 0;    right: 0;  border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.corner.bl { bottom: 0; left: 0;   border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.corner.br { bottom: 0; right: 0;  border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }

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

/* ── Camera unavailable message ─────────────────────────────────────────────── */
.camera-unavailable {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px 24px;
}
.camera-unavailable .unavail-icon { font-size: 3.5rem; }
.camera-unavailable p { font-size: 0.9rem; line-height: 1.5; }

/* ── Preview ─────────────────────────────────────────────────────────────────── */
.preview-container {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: #000;
}
#preview-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-orientation: from-image;
}

/* ── Camera controls bar ─────────────────────────────────────────────────────── */
.camera-controls {
  flex-shrink: 0;
  padding: 16px 20px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#capture-controls,
#analyze-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.capture-btn {
  width: 72px;
  height: 72px;
  border-radius: 50% !important;
  font-size: 1.9rem;
  padding: 0;
  flex-shrink: 0;
  box-shadow: 0 0 0 4px rgba(124,77,255,0.25);
}

.upload-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 14px 22px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s;
}
.upload-label:active { transform: scale(0.95); }

/* ── Loading overlay ─────────────────────────────────────────────────────────── */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(13, 13, 26, 0.9);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 50;
  backdrop-filter: blur(6px);
}
.loading-overlay p {
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 500;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ────────────────────────────────────────────────────────────────────────────── */
/*  REVIEW SCREEN                                                                 */
/* ────────────────────────────────────────────────────────────────────────────── */
.review-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.review-thumb-box {
  width: 100%;
  aspect-ratio: 16/9;
  border-radius: 14px;
  overflow: hidden;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.review-thumb-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-orientation: from-image;
}

.review-form { display: flex; flex-direction: column; gap: 12px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.9px;
}

.form-control {
  width: 100%;
  padding: 13px 15px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.form-control::placeholder { color: var(--text-muted); }

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236868a0' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
}
select.form-control option { background: var(--card); }

textarea.form-control { resize: none; line-height: 1.5; }

.review-actions {
  flex-shrink: 0;
  display: flex;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.review-actions .btn { flex: 1; }

/* ────────────────────────────────────────────────────────────────────────────── */
/*  HISTORY SCREEN                                                                */
/* ────────────────────────────────────────────────────────────────────────────── */
.history-toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.history-count {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.history-card:active { transform: scale(0.98); border-color: var(--primary); }

.history-thumb {
  width: 62px;
  height: 62px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.history-thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-placeholder  { font-size: 1.8rem; }

.history-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-badge {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.history-vendor {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.77rem;
  color: var(--text-muted);
}
.history-amount {
  font-weight: 700;
  color: var(--success);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.drive-btn,
.delete-btn {
  background: none;
  border: none;
  font-size: 1.05rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  opacity: 0.45;
  transition: opacity 0.15s, background 0.15s;
  flex-shrink: 0;
  line-height: 1;
}
.drive-btn:active  { opacity: 1; background: rgba(66,133,244,0.15); }
.delete-btn:active { opacity: 1; background: rgba(255,23,68,0.15); }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 48px 24px;
  text-align: center;
}
.empty-icon { font-size: 4rem; margin-bottom: 8px; }
.empty-state p  { color: var(--text-muted); font-size: 0.95rem; }
.empty-hint     { font-size: 0.82rem !important; opacity: 0.65; }

/* ────────────────────────────────────────────────────────────────────────────── */
/*  SETTINGS SCREEN                                                               */
/* ────────────────────────────────────────────────────────────────────────────── */
.settings-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-card h2 {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.settings-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.key-status {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  display: inline-block;
}
.key-ok      { color: var(--success); background: rgba(0,200,83,0.1); }
.key-missing { color: var(--warning); background: rgba(255,145,0,0.1); }

.settings-row {
  display: flex;
  gap: 10px;
}
.settings-row .btn { flex: 1; }

/* ────────────────────────────────────────────────────────────────────────────── */
/*  MODAL / BOTTOM SHEET                                                          */
/* ────────────────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  backdrop-filter: blur(4px);
  animation: fade-in 0.2s ease;
}

.modal {
  width: 100%;
  max-height: 88vh;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slide-up 0.28s cubic-bezier(0.34, 1.2, 0.64, 1);
}

.modal-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.05rem; font-weight: 700; }

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--card);
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:active { background: var(--border); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 12px;
  background: var(--card);
}

.detail-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 16px;
}
.detail-list dt {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  align-self: start;
  padding-top: 2px;
  white-space: nowrap;
}
.detail-list dd {
  font-size: 0.92rem;
  word-break: break-word;
}

/* ────────────────────────────────────────────────────────────────────────────── */
/*  TOAST                                                                         */
/* ────────────────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 14px);
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 100px;
  font-size: 0.88rem;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 48px);
  text-align: center;
  transition: opacity 0.22s, transform 0.22s;
}
.toast.show      { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success   { border-color: var(--success); color: var(--success); }
.toast-error     { border-color: var(--danger);  color: var(--danger);  }
.toast-warning   { border-color: var(--warning); color: var(--warning); }

/* ────────────────────────────────────────────────────────────────────────────── */
/*  ANIMATIONS                                                                    */
/* ────────────────────────────────────────────────────────────────────────────── */
@keyframes fade-in  { from { opacity: 0; }            to { opacity: 1; }          }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ── Scrollbar styling (where visible) ──────────────────────────────────────── */
::-webkit-scrollbar       { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
