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

:root {
  --primary: #007AFF;
  --primary-light: rgba(0, 122, 255, 0.08);
  --bg: #F2F2F7;
  --surface: #ffffff;
  --text: #1C1C1E;
  --text-secondary: #8E8E93;
  --text-tertiary: #AEAEB2;
  --text-muted: var(--text-secondary);
  --separator: rgba(60, 60, 67, 0.12);
  --border: rgba(60, 60, 67, 0.12);
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 10px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.08);
  --high: #34C759;
  --medium: #FF9500;
  --low: #FF3B30;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Header (inner screens only) ─────────────────────────── */
header {
  background: rgba(242, 242, 247, 0.85);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  color: var(--text);
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 0.5px solid var(--separator);
  display: flex;
  align-items: center;
  gap: 12px;
}

header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 1.4rem;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}

.back-btn:active { opacity: 0.5; }

/* ── Tabs ─────────────────────────────────────────────────── */
.tab { display: none; padding: 20px 16px 100px; min-height: calc(100vh - 80px); }
.tab.active { display: block; }

/* ── Camera Area ──────────────────────────────────────────── */
.camera-area {
  background: var(--text);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: 16px;
}

.camera-placeholder {
  text-align: center;
  color: rgba(255,255,255,0.5);
}

.camera-icon { font-size: 2.5rem; margin-bottom: 8px; }
.camera-placeholder p { font-size: 0.9rem; line-height: 1.5; }

#preview, #video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0; left: 0;
}

/* ── Buttons ──────────────────────────────────────────────── */
.camera-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity 0.18s, transform 0.18s;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  flex: 1;
}
.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
  background: var(--primary-light);
  color: var(--primary);
  border: none;
  flex: 1;
}
.btn-secondary:hover { opacity: 0.75; }

.btn-capture {
  background: var(--primary);
  color: #fff;
  flex: 1 1 100%;
  font-size: 1.1rem;
  padding: 16px;
}

.btn-outline {
  background: var(--primary-light);
  color: var(--primary);
  border: none;
}

.btn-scan {
  background: var(--primary);
  color: #fff;
  width: 100%;
  padding: 16px;
  font-size: 1.1rem;
  border-radius: var(--radius);
}
.btn-scan:hover { opacity: 0.85; }

.btn-save {
  margin-top: 12px;
  width: 100%;
  background: var(--primary);
  color: #fff;
}

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

.scan-action { margin-bottom: 20px; }

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result Card ──────────────────────────────────────────── */
.results { margin-top: 4px; }

.result-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.brand {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.product-name {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.category-pill {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
  text-align: center;
  max-width: 130px;
  line-height: 1.3;
}

.info-rows {
  border-top: 0.5px solid var(--separator);
  margin-top: 12px;
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}

.info-label { color: var(--text-secondary); }
.info-value { font-weight: 600; color: var(--text); text-align: right; }

.color-swatches {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.color-swatch {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.color-swatch-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
  flex-shrink: 0;
}
.info-highlight { color: var(--primary); font-size: 1rem; }
.confidence-high   { color: var(--high); }
.confidence-medium { color: var(--medium); }
.confidence-low    { color: var(--low); }

/* ── Not relevant warning ─────────────────────────────────── */
.not-relevant {
  background: rgba(255, 59, 48, 0.08);
  color: var(--low);
  border: 1px solid rgba(255, 59, 48, 0.2);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  margin-top: 4px;
  animation: slideUp 0.3s ease;
}

.warning-icon {
  font-size: 3.5rem;
  line-height: 1;
  margin-bottom: 10px;
}

.warning-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.warning-body {
  font-size: 0.9rem;
  opacity: 0.8;
  line-height: 1.5;
}

/* ── Error ────────────────────────────────────────────────── */
.error-msg {
  background: rgba(255, 59, 48, 0.08);
  color: var(--low);
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-top: 12px;
  border: 1px solid rgba(255, 59, 48, 0.15);
}

/* ── History ──────────────────────────────────────────────── */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.history-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 48px 20px;
  font-size: 0.95rem;
  line-height: 1.6;
  background: transparent;
  box-shadow: none;
}

.history-item {
  background: var(--surface);
  border-radius: 0;
  padding: 14px;
  display: flex;
  gap: 14px;
  align-items: center;
  box-shadow: none;
  animation: slideUp 0.25s ease;
  border-bottom: 0.5px solid var(--separator);
}

.history-item:last-child {
  border-bottom: none;
}

.history-thumb {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
}

.history-info { flex: 1; min-width: 0; }

.history-brand {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.history-category-pill {
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 10px;
}

.history-nicotine-amount {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.history-time {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.history-delete {
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
.history-delete:hover { color: var(--low); background: rgba(255, 59, 48, 0.08); }

/* Clear All — destructive style */
#btn-clear-history {
  background: rgba(255, 59, 48, 0.08);
  color: var(--low);
  border: none;
}
#btn-clear-history:hover { background: rgba(255, 59, 48, 0.15); }

/* ── Home Screen ─────────────────────────────────────────── */
#tab-home {
  padding: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  flex-direction: column;
}

#tab-home.active { display: flex; }

.home-top {
  padding: 48px 24px 20px;
  color: var(--text);
}

.home-greeting {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.home-date {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

/* ── Big CTA button ──────────────────────────────────────── */
.home-cta {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 24px 24px;
  padding: 20px 24px;
  background: #fff;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s;
  box-shadow: var(--shadow-md);
}

.home-cta:active { transform: scale(0.97); }

.home-cta-icon {
  width: 48px;
  height: 48px;
  background: var(--primary);
  color: #fff;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 300;
  flex-shrink: 0;
}

.home-cta-text {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

/* ── Stats strip ─────────────────────────────────────────── */
.home-stats {
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin: 0 24px 24px;
  padding: 16px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.stat-divider {
  width: 1px;
  height: 32px;
  background: var(--separator);
}

/* ── Recent section ──────────────────────────────────────── */
.home-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  margin-bottom: 12px;
}

.home-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.home-section-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  -webkit-tap-highlight-color: transparent;
}

.home-recent {
  flex: 1;
  background: var(--bg);
  padding: 0 16px 32px;
  min-height: 120px;
}

.home-recent-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: var(--surface);
  margin-bottom: 0;
  border-bottom: 0.5px solid var(--separator);
}

.home-recent-item:first-child {
  border-radius: var(--radius) var(--radius) 0 0;
}

.home-recent-item:last-child {
  border-radius: 0 0 var(--radius) var(--radius);
  border-bottom: none;
}

.home-recent-item:only-child {
  border-radius: var(--radius);
}

.home-recent-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
}

.home-recent-info { flex: 1; min-width: 0; }

.home-recent-brand {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-recent-detail {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.home-recent-time {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.empty-state-mini {
  text-align: center;
  color: var(--text-secondary);
  padding: 32px 16px;
  font-size: 0.9rem;
}

/* ── Utilities ────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Desktop tweaks ───────────────────────────────────────── */
@media (min-width: 480px) {
  main { max-width: 420px; margin: 0 auto; }
  #tab-home { max-width: none; margin: 0; }
  .camera-area { aspect-ratio: 16/9; }
}
