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

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --primary: #e94560;
  --primary-hover: #c81e45;
  --primary-light: rgba(233, 69, 96, 0.1);
  --border: #e5e7eb;
  --success: #10b981;
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.08);
  --radius: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f1a;
    --surface: #1a1a2e;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --primary: #e94560;
    --primary-hover: #ff6b81;
    --primary-light: rgba(233, 69, 96, 0.15);
    --border: #2d2d44;
    --success: #34d399;
    --error: #f87171;
    --error-bg: rgba(248, 113, 113, 0.1);
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
  }
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

/* ── Screens ─────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100dvh; }
.hidden { display: none !important; }

/* ── Unlock Screen ───────────────────────────────── */
#unlock-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.unlock-card {
  text-align: center;
  max-width: 360px;
  width: 100%;
}

.app-logo {
  margin-bottom: 16px;
}

.app-logo svg {
  border-radius: 16px;
  box-shadow: var(--shadow);
}

#unlock-screen h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

/* ── Header ───────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: var(--primary-light);
  color: var(--primary);
}

/* ── Main Content ────────────────────────────────── */
#scanner-screen .card,
#scanner-screen .btn.full-width {
  max-width: 480px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

/* ── Card ─────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin: 8px 16px;
}

/* ── Capture Area ────────────────────────────────── */
.capture-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  padding: 24px;
  text-align: center;
}

.capture-area:hover,
.capture-area:focus-within {
  border-color: var(--primary);
  background: var(--primary-light);
}

#capture-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
}

#capture-placeholder svg {
  opacity: 0.6;
}

#capture-placeholder span {
  font-size: 0.95rem;
}

#preview-image {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: 8px;
}

.hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* ── Buttons ─────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s, transform 0.1s;
}

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

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn.secondary {
  background: var(--primary-light);
  color: var(--primary);
}

.btn.full-width {
  width: calc(100% - 32px);
  margin: 4px 16px;
}

/* ── Form ─────────────────────────────────────────── */
.input-group {
  margin-bottom: 16px;
  text-align: left;
}

.input-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.2s;
}

.input-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ── Loading ──────────────────────────────────────── */
.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
}

.loading-content p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

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

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

/* ── Results ──────────────────────────────────────── */
#results h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.product-name {
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 4px;
}

.serving-info {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.table-wrap {
  overflow-x: auto;
}

#nutrition-table {
  width: 100%;
  border-collapse: collapse;
}

#nutrition-table th,
#nutrition-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

#nutrition-table th {
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#nutrition-table td:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

#nutrition-table tr:last-child td {
  border-bottom: none;
}

#nutrition-table .nutrient-sub {
  padding-left: 20px;
  color: var(--text-secondary);
}

/* ── Error ────────────────────────────────────────── */
.error {
  color: var(--error);
  font-size: 0.85rem;
  margin-top: 12px;
}

.error-card {
  background: var(--error-bg);
  border-color: var(--error);
  text-align: center;
}

.error-card p {
  color: var(--error);
  margin-bottom: 12px;
  font-size: 0.9rem;
}
