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

:root {
  --green: #2DB324;
  --green-dark: #1E8A19;
  --green-light: #E6F9E4;
  --red: #E5484D;
  --red-light: #FFF0F0;
  --orange: #F5A623;
  --orange-light: #FFF8ED;
  --blue: #3B82F6;
  --blue-light: #EFF6FF;
  --gray-50: #FAFAFA;
  --gray-100: #F4F4F5;
  --gray-200: #E4E4E7;
  --gray-300: #D4D4D8;
  --gray-500: #71717A;
  --gray-700: #3F3F46;
  --gray-900: #18181B;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

.hidden { display: none !important; }

.screen { display: none; }
.screen.active { display: block; }

/* Auth Screen */
.auth-container {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 24px;
}

.logo-area {
  text-align: center;
}

.logo-icon {
  margin: 0 auto 16px;
  width: 72px;
  height: 72px;
}

.logo-icon svg {
  width: 72px;
  height: 72px;
}

.logo-area h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--gray-500);
  font-size: 15px;
  line-height: 1.5;
  max-width: 280px;
  margin: 0 auto;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 600;
  font-size: 15px;
  padding: 12px 24px;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.btn-primary {
  background: var(--green);
  color: white;
}

.btn-primary:hover {
  background: var(--green-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

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

.btn-lg {
  padding: 16px 32px;
  font-size: 16px;
  border-radius: var(--radius);
}

.btn-icon {
  display: flex;
  align-items: center;
}

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

/* Input */
.input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.2s;
  outline: none;
}

.input:focus {
  border-color: var(--green);
}

.helper-text {
  font-size: 13px;
  color: var(--gray-500);
  text-align: center;
}

#auth-waiting-hint {
  animation: pulse-opacity 2s ease-in-out infinite;
}

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

.error-msg {
  color: var(--red);
  font-size: 14px;
  text-align: center;
  padding: 12px;
  background: var(--red-light);
  border-radius: var(--radius-sm);
  width: 100%;
  max-width: 400px;
}

/* Header */
.app-header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  max-width: 960px;
  margin: 0 auto;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-logo svg {
  width: 28px;
  height: 28px;
  display: block;
}

.header-title {
  font-weight: 700;
  font-size: 17px;
}

.user-badge {
  font-size: 13px;
  color: var(--gray-500);
  background: var(--gray-100);
  padding: 4px 12px;
  border-radius: 20px;
}

/* Main Content */
.main-content {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

/* Hero */
.hero-section {
  text-align: center;
  padding: 32px 8px;
}

.hero-section h2 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.3px;
  margin-bottom: 8px;
  line-height: 1.3;
}

.hero-section p {
  color: var(--gray-500);
  font-size: 14px;
  margin-bottom: 24px;
  line-height: 1.5;
}

.btn-analyze {
  max-width: 360px;
  margin: 0 auto;
}

.last-analysis-date {
  font-size: 13px;
  color: var(--gray-500);
  margin-bottom: 16px;
  background: var(--gray-100);
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
}

/* Loading */
.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 24px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

#loading-status {
  color: var(--gray-500);
  font-size: 14px;
}

/* Cards */
.card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Score Ring */
.score-card {
  text-align: center;
}

.score-ring-container {
  display: flex;
  justify-content: center;
  padding: 8px 0;
}

.score-ring {
  position: relative;
  width: 140px;
  height: 140px;
}

.score-ring svg {
  width: 100%;
  height: 100%;
}

#score-circle {
  transition: stroke-dashoffset 1.5s ease-out, stroke 0.5s;
}

.score-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-number {
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
}

.score-max {
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-500);
  line-height: 1;
  margin-top: 6px;
}

/* Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.metric-item {
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  padding: 14px;
  min-height: 80px;
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-500);
  margin-bottom: 6px;
}

.metric-value {
  font-size: 18px;
  font-weight: 700;
}

.metric-value.good { color: var(--green); }
.metric-value.warning { color: var(--orange); }
.metric-value.bad { color: var(--red); }

.metric-value.metric-text {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
}

.metric-sub {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 2px;
}

/* Macronutrients */
.macros-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.macro-card {
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.macro-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}

.macro-emoji {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

.macro-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-500);
}

.macro-main {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.macro-main.good { color: var(--green); }
.macro-main.warning { color: var(--orange); }
.macro-main.bad { color: var(--red); }

.macro-detail {
  font-size: 12px;
  color: var(--gray-500);
  line-height: 1.4;
}

.macro-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.macro-bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.macro-bar-label {
  font-size: 11px;
  color: var(--gray-500);
  width: 72px;
  flex-shrink: 0;
}

.macro-bar-track {
  flex: 1;
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
}

.macro-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 1s ease-out;
}

.bar-sat { background: var(--orange); }
.bar-unsat { background: var(--green); }
.bar-trans { background: var(--red); }

.macro-bar-val {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-700);
  width: 32px;
  text-align: right;
  flex-shrink: 0;
}

.macro-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.macro-sub-label {
  font-size: 11px;
  color: var(--gray-500);
  margin-bottom: 2px;
}

.macro-sub-value {
  font-size: 15px;
  font-weight: 700;
}

.macro-sub-value.good { color: var(--green); }
.macro-sub-value.warning { color: var(--orange); }
.macro-sub-value.bad { color: var(--red); }

/* Category Chart */
.category-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chart-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chart-label {
  font-size: 12px;
  color: var(--gray-700);
  width: 100px;
  flex-shrink: 0;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-bar-bg {
  flex: 1;
  height: 28px;
  background: var(--gray-100);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.chart-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 1s ease-out;
  min-width: 2px;
}

.chart-bar-value {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-700);
}

/* Strengths & Weaknesses */
.strengths-weaknesses {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.sw-card ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sw-card li {
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--gray-50);
}

.sw-card:first-child li {
  background: var(--green-light);
  color: var(--green-dark);
}

.sw-card:last-child li {
  background: var(--red-light);
  color: #B91C1C;
}

/* Recommendations */
.recommendations-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.rec-item {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  overflow: hidden;
}

.rec-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}

.rec-icon {
  width: 36px;
  height: 36px;
  background: var(--green-light);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}

.rec-name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 2px;
  word-break: break-word;
}

.rec-reason {
  font-size: 13px;
  color: var(--gray-500);
  line-height: 1.4;
  word-break: break-word;
}

.sku-carousel {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0 8px;
  scrollbar-width: none;
}

.sku-carousel::-webkit-scrollbar {
  display: none;
}

.sku-card {
  flex: 0 0 140px;
  scroll-snap-align: start;
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--gray-200);
  transition: box-shadow 0.2s;
}

.sku-card:hover {
  box-shadow: var(--shadow-md);
}

.sku-card-img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: white;
  padding: 8px;
}

.sku-card-img-placeholder {
  width: 100%;
  aspect-ratio: 1;
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: var(--gray-300);
}

.sku-card-body {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.sku-card-name {
  font-size: 12px;
  line-height: 1.3;
  color: var(--gray-700);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sku-card-price {
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-900);
}

.sku-card-cart-btn {
  margin-top: auto;
  padding: 6px 0;
  border: none;
  border-radius: 6px;
  background: var(--green);
  color: white;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.sku-card-cart-btn:hover {
  background: var(--green-dark);
  transform: scale(1.03);
}

.sku-card-cart-btn:active {
  transform: scale(0.97);
}

.sku-card-cart-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.sku-card-cart-btn.added {
  background: var(--gray-200);
  color: var(--gray-700);
}

/* Bar colors */
.bar-color-0 { background: #2DB324; }
.bar-color-1 { background: #3B82F6; }
.bar-color-2 { background: #F5A623; }
.bar-color-3 { background: #8B5CF6; }
.bar-color-4 { background: #EC4899; }
.bar-color-5 { background: #14B8A6; }
.bar-color-6 { background: #EF4444; }
.bar-color-7 { background: #6366F1; }
.bar-color-8 { background: #F97316; }
.bar-color-9 { background: #06B6D4; }

/* ===== DESKTOP (768px+) ===== */
@media (min-width: 768px) {
  .auth-container {
    gap: 32px;
  }

  .logo-icon, .logo-icon svg {
    width: 88px;
    height: 88px;
  }

  .logo-area h1 {
    font-size: 36px;
  }

  .subtitle {
    font-size: 17px;
    max-width: 360px;
  }

  .btn-lg {
    width: auto;
    min-width: 320px;
  }

  .header-content {
    padding: 14px 32px;
  }

  .main-content {
    padding: 24px 32px;
  }

  .hero-section {
    padding: 48px 16px;
  }

  .hero-section h2 {
    font-size: 30px;
  }

  .hero-section p {
    font-size: 16px;
  }

  .card {
    padding: 28px;
    margin-bottom: 20px;
  }

  .card h3 {
    font-size: 18px;
  }

  .score-ring {
    width: 180px;
    height: 180px;
  }

  .score-number {
    font-size: 48px;
  }

  .metrics-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
  }

  .strengths-weaknesses {
    grid-template-columns: 1fr 1fr;
  }

  .chart-label {
    width: 140px;
    font-size: 13px;
  }

  .chart-bar-bg {
    height: 32px;
  }

  .recommendations-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
  }

  .sku-card {
    flex: 0 0 150px;
  }

}

@media (min-width: 1024px) {
  .hero-section h2 {
    font-size: 34px;
  }

  .recommendations-list {
    grid-template-columns: repeat(3, 1fr);
  }
}
