:root {
  --safe: #4CAF50;
  --safe-bg: #E8F5E9;
  --caution: #F59E0B;
  --caution-bg: #FEF3C7;
  --avoid: #EF4444;
  --avoid-bg: #FEE2E2;
  --irritant: #F97316;
  --irritant-bg: #FFF7ED;
  --accent: #B8829A;
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --text: #1F2937;
  --text-light: #6B7280;
  --border: #E5E7EB;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html {
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 480px;
  margin: 0 auto;
}

.logo h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

main {
  flex: 1;
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}

.tab-panel {
  display: none;
  animation: fadeIn 0.2s ease;
}

.tab-panel.active {
  display: block;
}

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

.tab-content {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px;
}

.section-intro {
  margin-bottom: 20px;
}

.section-intro h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.section-intro p {
  color: var(--text-light);
  font-size: 14px;
  line-height: 1.5;
}

/* Tab Bar */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  gap: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 10;
}

.tab-btn {
  flex: 1;
  max-width: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 11px;
  font-family: var(--font);
  cursor: pointer;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn.active {
  color: var(--safe);
}

.tab-btn svg {
  transition: transform 0.15s;
}

.tab-btn.active svg {
  transform: scale(1.1);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  width: 100%;
  padding: 14px 24px;
  background: var(--safe);
  color: white;
  box-shadow: var(--shadow);
}

.btn-primary:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.btn-small {
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  font-size: 13px;
}

.btn-secondary {
  padding: 10px 20px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

/* Textarea */
textarea {
  width: 100%;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
  margin-bottom: 12px;
  transition: border-color 0.15s;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea::placeholder {
  color: #9CA3AF;
}

/* Scanner */
#scanner-container {
  margin-bottom: 16px;
}

#scanner-reader {
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}

#scanner-reader video {
  border-radius: var(--radius);
}

/* Status Messages */
.status-msg {
  text-align: center;
  padding: 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin: 12px 0;
}

.status-msg.loading {
  background: #EEF2FF;
  color: #4338CA;
}

.status-msg.error {
  background: var(--avoid-bg);
  color: var(--avoid);
}

.status-msg.info {
  background: #F0F9FF;
  color: #0369A1;
}

/* Results */
.results-container {
  margin-top: 16px;
}

.results-summary {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.results-summary h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.summary-stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
}

.stat-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.stat-dot.avoid { background: var(--avoid); }
.stat-dot.caution { background: var(--caution); }
.stat-dot.irritant { background: var(--irritant); }
.stat-dot.safe { background: var(--safe); }

.product-info {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.product-info img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.product-info h3 {
  font-size: 16px;
  font-weight: 600;
}

.product-info p {
  font-size: 13px;
  color: var(--text-light);
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  margin: 16px 0 8px;
}

.ingredient-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 6px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-left: 4px solid transparent;
}

.ingredient-card.avoid {
  border-left-color: var(--avoid);
  background: var(--avoid-bg);
}

.ingredient-card.caution {
  border-left-color: var(--caution);
  background: var(--caution-bg);
}

.ingredient-card.safe-card {
  border-left-color: var(--safe);
}

.ingredient-card.may-contain {
  opacity: 0.75;
}

.ingredient-name {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
}

.ingredient-name small {
  display: block;
  font-size: 12px;
  color: var(--text-light);
  font-weight: 400;
  margin-top: 1px;
}

.badges {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.avoid {
  background: var(--avoid);
  color: white;
}

.badge.caution {
  background: var(--caution);
  color: white;
}

.badge.irritant {
  background: var(--irritant);
  color: white;
}

.safe-toggle {
  width: 100%;
  padding: 10px;
  background: var(--safe-bg);
  border: 1px solid #C8E6C9;
  border-radius: var(--radius-sm);
  color: #2E7D32;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 8px;
  -webkit-tap-highlight-color: transparent;
}

.safe-list {
  margin-top: 6px;
}

.safe-list .ingredient-card {
  border-left-color: var(--safe);
  background: var(--safe-bg);
}

.verdict {
  text-align: center;
  padding: 16px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
}

.verdict.verdict-safe {
  background: var(--safe-bg);
  color: #2E7D32;
}

.verdict.verdict-caution {
  background: var(--caution-bg);
  color: #92400E;
}

.verdict.verdict-avoid {
  background: var(--avoid-bg);
  color: #991B1B;
}

/* Setup Tab */
.setup-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.setup-card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
}

.setup-card p {
  font-size: 14px;
  color: var(--text-light);
  line-height: 1.5;
  margin-bottom: 12px;
}

.setup-steps {
  padding-left: 20px;
  margin-bottom: 16px;
}

.setup-steps li {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text);
}

.bookmarklet-btn {
  display: inline-block;
  padding: 10px 24px;
  background: var(--safe);
  color: white;
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  box-shadow: var(--shadow);
  cursor: grab;
}

.copy-block {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bookmarklet-code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  word-break: break-all;
  color: var(--text-light);
  max-height: 80px;
  overflow-y: auto;
  line-height: 1.5;
}

.site-list {
  list-style: none;
  padding: 0;
}

.site-list li {
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.site-list li:last-child {
  border-bottom: none;
}

.note {
  font-size: 12px !important;
  color: var(--text-light) !important;
  font-style: italic;
  margin-top: 8px;
}

/* Not found state */
.not-found {
  text-align: center;
  padding: 24px 16px;
}

.not-found p {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 12px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  background: #1F2937;
  color: white;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 500;
  z-index: 100;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2s forwards;
  white-space: nowrap;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Responsive */
@media (min-width: 768px) {
  .tab-content {
    padding: 32px 24px;
  }
}
