/* Photo Protein - Main Styles */

:root {
  --protein: #2BD3C4;
  --fat: #f87171;
  --carbs: #818CF8;
  --bg-dark: #0c1117;
  --bg-card: #141b24;
  --bg-elevated: #1c2631;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: rgba(255,255,255,0.08);
  --glow: rgba(43, 211, 196, 0.15);
}

* { box-sizing: border-box; }

html {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
  background: 
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(43, 211, 196, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(59, 130, 246, 0.05), transparent),
    var(--bg-dark);
}

.font-display { font-family: 'Fraunces', Georgia, serif; }

/* ═══════════════════════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════════════════════ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 20px var(--glow), 0 0 60px rgba(43, 211, 196, 0.1); }
  50% { box-shadow: 0 0 30px var(--glow), 0 0 80px rgba(43, 211, 196, 0.15); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

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

@keyframes bounce-gentle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.animate-fade-up { animation: fadeUp 0.6s ease-out forwards; }
.animate-delay-1 { animation-delay: 0.1s; opacity: 0; }
.animate-delay-2 { animation-delay: 0.2s; opacity: 0; }
.animate-delay-3 { animation-delay: 0.3s; opacity: 0; }
.animate-delay-4 { animation-delay: 0.4s; opacity: 0; }
.animate-slide-up { animation: slideUp 0.4s ease-out forwards; }

/* ═══════════════════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════════════════ */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: linear-gradient(135deg, #2BD3C4 0%, #20B5A8 100%);
  color: #022c22;
  font-weight: 600;
  border-radius: 16px;
  padding: 18px 32px;
  font-size: 18px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 20px rgba(43, 211, 196, 0.3), inset 0 1px 0 rgba(255,255,255,0.2);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(43, 211, 196, 0.4), inset 0 1px 0 rgba(255,255,255,0.2);
}

.btn-primary:active { transform: translateY(0); }

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

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-weight: 500;
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 15px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: #243040;
  border-color: rgba(255,255,255,0.15);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  font-weight: 500;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.12);
}

/* ═══════════════════════════════════════════════════════════════════════
   CARDS & CONTAINERS
   ═══════════════════════════════════════════════════════════════════════ */
.glass-card {
  background: rgba(20, 27, 36, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 24px;
}

.demo-phone {
  background: linear-gradient(180deg, #1a2332 0%, #0f151c 100%);
  border-radius: 32px;
  padding: 8px;
  box-shadow: 
    0 25px 50px -12px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255,255,255,0.05),
    inset 0 1px 0 rgba(255,255,255,0.1);
}

.demo-screen {
  background: var(--bg-dark);
  border-radius: 24px;
  overflow: hidden;
}

.meal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
}

.meal-card:hover {
  transform: translateY(-4px);
  border-color: rgba(43, 211, 196, 0.3);
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}

.meal-card:active { transform: translateY(-2px); }

.focus-ring:focus-visible {
  outline: 2px solid var(--protein);
  outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════════════════
   PROGRESS RING
   ═══════════════════════════════════════════════════════════════════════ */
.progress-ring { transform: rotate(-90deg); }
.progress-ring-bg { stroke: var(--bg-elevated); }
.progress-ring-fill {
  stroke: var(--protein);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s ease-out;
}

/* ═══════════════════════════════════════════════════════════════════════
   SCROLL LOCK
   ═══════════════════════════════════════════════════════════════════════ */
html.scroll-locked, body.scroll-locked {
  overflow: hidden;
  overscroll-behavior: none;
}

/* ═══════════════════════════════════════════════════════════════════════
   DRAWER (Bottom Sheet)
   ═══════════════════════════════════════════════════════════════════════ */
#mealDrawer {
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#mealDrawer.open { transform: translateY(0); }

/* ═══════════════════════════════════════════════════════════════════════
   CAMERA OVERLAY
   ═══════════════════════════════════════════════════════════════════════ */
.camera-overlay { background: rgba(12, 17, 23, 0.98); }

/* ═══════════════════════════════════════════════════════════════════════
   ASPECT RATIO HELPERS
   ═══════════════════════════════════════════════════════════════════════ */
.ratio-3-4 { position: relative; width: 100%; }
.ratio-3-4::before { content: ""; display: block; padding-top: 133.333%; }

.ratio-4-3 { position: relative; width: 100%; }
.ratio-4-3::before { content: ""; display: block; padding-top: 75%; }

.ratio-inner { position: absolute; inset: 0; }

#previewBox { width: min(100%, calc(78svh * 0.75)); }

@media (orientation: landscape) {
  #previewBox { width: min(100%, calc(78svh * 1.333)); }
}

.offscreen-video {
  position: fixed !important;
  width: 1px !important;
  height: 1px !important;
  top: -10000px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ═══════════════════════════════════════════════════════════════════════
   TABS
   ═══════════════════════════════════════════════════════════════════════ */
.tab-active {
  background: var(--protein);
  color: #022c22;
}

.tab-inactive {
  background: transparent;
  color: var(--text-secondary);
}

.tab-inactive:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* ═══════════════════════════════════════════════════════════════════════
   TABLE STYLES
   ═══════════════════════════════════════════════════════════════════════ */
#drawerTableWrap thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-elevated);
}

#drawerTableWrap td:first-child,
#drawerTableWrap th:first-child {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ═══════════════════════════════════════════════════════════════════════
   MACRO COLORS
   ═══════════════════════════════════════════════════════════════════════ */
.text-protein { color: var(--protein); }
.text-fat { color: var(--fat); }
.text-carbs { color: var(--carbs); }
.bg-protein { background: var(--protein); }
.bg-fat { background: var(--fat); }
.bg-carbs { background: var(--carbs); }

/* ═══════════════════════════════════════════════════════════════════════
   iOS SAFE AREAS
   ═══════════════════════════════════════════════════════════════════════ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
}

/* ═══════════════════════════════════════════════════════════════════════
   PWA INSTALL BANNER
   ═══════════════════════════════════════════════════════════════════════ */
#pwaInstallBanner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 45;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(12, 17, 23, 0.98), rgba(12, 17, 23, 0.95));
  border-top: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transform: translateY(100%);
  transition: transform 0.3s ease-out;
}

#pwaInstallBanner.show {
  transform: translateY(0);
  animation: bounce-gentle 2s ease-in-out 1s 2;
}

/* ═══════════════════════════════════════════════════════════════════════
   TOAST NOTIFICATION
   ═══════════════════════════════════════════════════════════════════════ */
#toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 100;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ═══════════════════════════════════════════════════════════════════════
   iOS INSTALL INSTRUCTIONS
   ═══════════════════════════════════════════════════════════════════════ */
.ios-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
}

.ios-step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--protein);
  color: #022c22;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════════════
   MACRO CARDS (Drawer Redesign)
   ═══════════════════════════════════════════════════════════════════════ */
.macro-card {
  background: var(--bg-elevated);
  border-radius: 16px;
  padding: 16px 12px;
  text-align: center;
  border: 1px solid var(--border);
  transition: all 0.2s ease;
}

.macro-card--protein {
  background: linear-gradient(135deg, rgba(43, 211, 196, 0.15) 0%, rgba(43, 211, 196, 0.05) 100%);
  border-color: rgba(43, 211, 196, 0.3);
  position: relative;
}

.macro-card--protein::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 17px;
  padding: 1px;
  background: linear-gradient(135deg, rgba(43, 211, 196, 0.5), rgba(43, 211, 196, 0.1));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.macro-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.macro-value--lg {
  font-size: 36px;
}

.macro-label {
  font-size: 12px;
  font-weight: 500;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Protein Score Badge */
.protein-score {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 600;
}

.protein-score--excellent {
  background: rgba(43, 211, 196, 0.15);
  color: #2BD3C4;
  border: 1px solid rgba(43, 211, 196, 0.3);
}

.protein-score--good {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.protein-score--low {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Drawer Image */
.drawer-image {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 16px;
  background: var(--bg-elevated);
}

@media (min-width: 1024px) {
  .drawer-image {
    aspect-ratio: 4 / 3;
  }
}

/* Breakdown Section */
.breakdown-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.breakdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.breakdown-header:hover {
  background: var(--bg-elevated);
}

.breakdown-header h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.breakdown-chevron {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.breakdown-section.open .breakdown-chevron {
  transform: rotate(180deg);
}

.breakdown-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.breakdown-section.open .breakdown-content {
  max-height: 400px;
}

.breakdown-table {
  width: 100%;
  font-size: 13px;
}

.breakdown-table th,
.breakdown-table td {
  padding: 10px 12px;
  text-align: left;
}

.breakdown-table th {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.breakdown-table td {
  border-top: 1px solid var(--border);
  color: var(--text-primary);
}

.breakdown-table td:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.breakdown-table tr:last-child td {
  font-weight: 600;
  background: var(--bg-elevated);
}

/* Calorie Summary */
.calorie-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
  color: var(--text-secondary);
  font-size: 14px;
}

.calorie-summary .divider {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════════════
   AUTH STATE UI (prevent flash)
   ═══════════════════════════════════════════════════════════════════════ */
.presume-signed-in .show-signed-out { display: none !important; }
.presume-signed-out .show-signed-in { display: none !important; }