:root {
  --green: #22c55e;
  --green-d: #16a34a;
  --green-l: #dcfce7;
  --green-ll: #f0fdf4;
  --bg: #f0fdf4;
  --card: #ffffff;
  --border: #d1fae5;
  --text: #14532d;
  --text-m: #374151;
  --text-l: #6b7280;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 24px rgba(0,0,0,0.09);
  --r: 16px;
  --r-sm: 10px;
  --r-pill: 100px;
  --transition: all 0.2s ease;
}

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

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-m);
  min-height: 100vh;
  line-height: 1.6;
}

/* ─── App Wrapper ─── */
.app {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

/* ─── Header ─── */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

.logo {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--green-d);
  text-decoration: none;
  letter-spacing: -0.5px;
}

.logo:hover { color: var(--green); }

.ai-badge {
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  color: white;
  padding: 5px 16px;
  border-radius: var(--r-pill);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}

/* ─── Step Bar ─── */
.step-bar {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  margin-bottom: 32px;
}

.step-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.sdot {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid #d1d5db;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-l);
  transition: var(--transition);
}

.step-item.active .sdot {
  background: var(--green);
  border-color: var(--green);
  color: white;
  box-shadow: 0 0 0 4px rgba(34,197,94,0.2);
}

.step-item span {
  font-size: 0.75rem;
  color: var(--text-l);
  font-weight: 500;
}

.step-item.active span {
  color: var(--green-d);
  font-weight: 700;
}

.step-line {
  width: 80px;
  height: 2px;
  background: #e5e7eb;
  margin: 0 10px;
  margin-top: 19px;
  flex-shrink: 0;
}

/* ─── Panel (form steps) ─── */
.panel {
  background: white;
  border-radius: var(--r);
  box-shadow: var(--shadow-md);
  padding: 40px;
  animation: fadeUp 0.35s ease;
}

.panel-header { margin-bottom: 4px; }

.panel-header h2 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.3px;
}

.panel-header p {
  font-size: 0.95rem;
  color: var(--text-l);
  margin-top: 4px;
}

/* ─── Form Grid ─── */
.fgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 28px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field.span2 { grid-column: 1 / -1; }

.field > label:not(.opt):not(.pill) {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-m);
}

input[type="number"],
input[type="password"],
input[type="text"],
select {
  width: 100%;
  padding: 12px 15px;
  border: 1.5px solid #e5e7eb;
  border-radius: var(--r-sm);
  font-size: 1rem;
  color: var(--text-m);
  background: white;
  transition: var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

input[type="number"]:focus,
input[type="password"]:focus,
input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34,197,94,0.18);
}

select {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 42px;
  cursor: pointer;
}

/* ─── Option Cards (radio) ─── */
.opts-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 12px 14px;
  border: 2px solid #e5e7eb;
  border-radius: var(--r-sm);
  cursor: pointer;
  text-align: center;
  background: #fafafa;
  transition: var(--transition);
  user-select: none;
  position: relative;
}

.opt input[type="radio"] { display: none; }

.opt:hover {
  border-color: #86efac;
  background: var(--green-ll);
}

.opt.selected {
  border-color: var(--green);
  background: var(--green-ll);
  box-shadow: 0 0 0 3px rgba(34,197,94,0.18);
}

.opt-e {
  font-size: 2rem;
  line-height: 1;
  display: block;
  margin-bottom: 6px;
}

.opt-t {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-m);
  display: block;
}

.opt-s {
  font-size: 0.72rem;
  color: var(--text-l);
  display: block;
  line-height: 1.3;
  margin-top: 2px;
}

.opt.selected .opt-t { color: var(--green-d); }

/* ─── Pill Checkboxes ─── */
.pills-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: 1.5px solid #e5e7eb;
  border-radius: var(--r-pill);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-m);
  background: #fafafa;
  transition: var(--transition);
  user-select: none;
}

.pill input { display: none; }

.pill:hover {
  border-color: var(--green);
  background: var(--green-ll);
}

.pill.checked {
  border-color: var(--green);
  background: var(--green-l);
  color: var(--green-d);
  font-weight: 700;
}

/* ─── API Key Row ─── */
.key-row {
  display: flex;
  gap: 8px;
}

.key-row input { flex: 1; }

.key-btn {
  padding: 12px 15px;
  border: 1.5px solid #e5e7eb;
  border-radius: var(--r-sm);
  background: white;
  cursor: pointer;
  font-size: 1rem;
  transition: var(--transition);
  flex-shrink: 0;
}

.key-btn:hover {
  border-color: var(--green);
  background: var(--green-ll);
}

.hint {
  font-size: 0.78rem;
  color: var(--text-l);
  margin-top: 6px;
  line-height: 1.5;
}

.muted { color: var(--text-l); font-weight: 400; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 26px;
  border-radius: var(--r-sm);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  white-space: nowrap;
}

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

.btn.primary:hover {
  background: var(--green-d);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(22,163,74,0.35);
}

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

.btn.outline {
  background: transparent;
  color: var(--green-d);
  border: 2px solid var(--green);
}

.btn.outline:hover {
  background: var(--green-ll);
}

/* ─── Panel Footer ─── */
.panel-foot {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 36px;
  padding-top: 24px;
  border-top: 1px solid #f3f4f6;
}

/* ─── Error Box ─── */
.form-error {
  background: #fef2f2;
  border: 1.5px solid #fca5a5;
  color: #b91c1c;
  padding: 12px 16px;
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 16px;
}

/* ─── Loader ─── */
.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  gap: 20px;
  animation: fadeUp 0.3s ease;
}

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

.load-msg {
  font-size: 1rem;
  color: var(--text-l);
  font-weight: 500;
  text-align: center;
}

/* ─── Results ─── */
.results { animation: fadeUp 0.4s ease; }

.results-foot {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 36px;
  flex-wrap: wrap;
}

/* ─── Summary Cards ─── */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.sum-card {
  background: white;
  border-radius: var(--r);
  padding: 24px 18px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: var(--transition);
}

.sum-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.sum-icon { font-size: 2.2rem; margin-bottom: 4px; }
.sum-label { font-size: 0.72rem; font-weight: 700; color: var(--text-l); text-transform: uppercase; letter-spacing: 0.8px; }
.sum-value { font-size: 1.9rem; font-weight: 800; color: var(--text); line-height: 1.1; margin: 2px 0; }
.sum-sub { font-size: 0.82rem; color: var(--text-l); }

.bmi-good { color: #16a34a; font-weight: 700; }
.bmi-low  { color: #2563eb; font-weight: 700; }
.bmi-warn { color: #d97706; font-weight: 700; }
.bmi-high { color: #dc2626; font-weight: 700; }

.bmi-bar {
  width: 100%;
  height: 6px;
  background: #f3f4f6;
  border-radius: 4px;
  margin-top: 10px;
  overflow: hidden;
}

.bmi-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.8s ease;
}

/* ─── Section Cards ─── */
.section-card {
  background: white;
  border-radius: var(--r);
  padding: 30px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  animation: fadeUp 0.4s ease;
}

.section-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-sub {
  font-size: 0.85rem;
  color: var(--text-l);
  margin-top: 4px;
  margin-bottom: 20px;
}

/* ─── Macro Bars ─── */
.macro-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-top: 20px;
}

.macro-block { display: flex; flex-direction: column; gap: 8px; }

.macro-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-m);
}

.macro-pct {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-l);
}

.macro-bar-wrap {
  background: #f3f4f6;
  border-radius: 6px;
  height: 10px;
  overflow: hidden;
}

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

.protein-bar { background: linear-gradient(90deg, #6366f1, #8b5cf6); }
.carbs-bar   { background: linear-gradient(90deg, #f59e0b, #f97316); }
.fat-bar     { background: linear-gradient(90deg, #10b981, #06b6d4); }

.macro-nums {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.macro-target { font-size: 1.25rem; font-weight: 800; color: var(--text); }
.macro-range  { font-size: 0.75rem; color: var(--text-l); }

/* ─── Meal Plan ─── */
.meal-section { margin-top: 28px; }
.meal-section:first-of-type { margin-top: 0; }

.meal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  flex-wrap: wrap;
  gap: 8px;
}

.meal-head h4 {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
}

.meal-target {
  background: var(--green-l);
  color: var(--green-d);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: var(--r-pill);
}

.meal-sub {
  font-size: 0.8rem;
  color: var(--text-l);
  margin-bottom: 14px;
}

.food-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

/* ─── Food Cards ─── */
.food-card {
  border: 1.5px solid #ecfdf5;
  border-radius: var(--r-sm);
  padding: 14px;
  background: #f9fffe;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  transition: var(--transition);
  cursor: default;
}

.food-card:hover {
  border-color: var(--green);
  box-shadow: 0 2px 10px rgba(34,197,94,0.15);
  background: var(--green-ll);
  transform: translateY(-2px);
}

.food-emoji { font-size: 1.9rem; line-height: 1; flex-shrink: 0; margin-top: 2px; }

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

.food-name {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-m);
  margin-bottom: 2px;
  line-height: 1.3;
}

.food-portion {
  font-size: 0.75rem;
  color: var(--text-l);
  margin-bottom: 9px;
}

.macro-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chip {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-weight: 700;
}

.chip-cal  { background: #fef3c7; color: #92400e; }
.chip-pro  { background: #ede9fe; color: #5b21b6; }
.chip-carb { background: #fef9c3; color: #854d0e; }
.chip-fat  { background: #d1fae5; color: #065f46; }

/* ─── No Foods Message ─── */
.no-foods {
  color: var(--text-l);
  font-size: 0.875rem;
  font-style: italic;
  padding: 12px 0;
}

/* ─── Meal Divider ─── */
.meal-divider {
  border: none;
  border-top: 1.5px solid #f0fdf4;
  margin: 24px 0 0;
}

/* ─── AI Section ─── */
.ai-section {
  border: 2px solid #a5b4fc;
  background: linear-gradient(135deg, #f5f3ff 0%, #eff6ff 100%);
}

.ai-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.ai-header h3 {
  font-size: 1.1rem;
  font-weight: 800;
  color: #3730a3;
  flex: 1;
  min-width: 160px;
}

.ai-icon { font-size: 1.5rem; }

.ai-powered-badge {
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  color: white;
  padding: 3px 14px;
  border-radius: var(--r-pill);
  font-size: 0.72rem;
  font-weight: 700;
}

.ai-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-list li {
  background: white;
  border-radius: var(--r-sm);
  padding: 12px 16px;
  font-size: 0.9rem;
  color: var(--text-m);
  line-height: 1.65;
  border-left: 3px solid #818cf8;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* ─── AI Error ─── */
.ai-error {
  background: #fef2f2;
  border: 1.5px solid #fca5a5;
  border-radius: var(--r-sm);
  padding: 14px 16px;
  color: #991b1b;
  font-size: 0.875rem;
}

/* ─── Shopping List ─── */
.shopping-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.shopping-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--green-ll);
  border: 1px solid var(--green-l);
  border-radius: var(--r-sm);
  transition: var(--transition);
}

.shopping-list li:hover {
  background: var(--green-l);
  border-color: var(--green);
}

.s-emoji { font-size: 1.3rem; flex-shrink: 0; }
.s-name  { font-size: 0.875rem; font-weight: 700; color: var(--text-m); }
.s-detail { font-size: 0.75rem; color: var(--text-l); margin-top: 1px; }

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

/* ─── Animations ─── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

/* ─── Print ─── */
@media print {
  body { background: white; }
  .app-header { margin-bottom: 12px; }
  .no-print, .results-foot { display: none !important; }
  .section-card, .sum-card { box-shadow: none; border: 1px solid #e5e7eb; }
  .food-card { break-inside: avoid; }
  .meal-section { break-inside: avoid; }
}

/* ─── Responsive ─── */
@media (max-width: 640px) {
  .app { padding: 16px 14px 60px; }
  .panel { padding: 24px 18px; }
  .fgrid { grid-template-columns: 1fr; }
  .field.span2 { grid-column: 1; }
  .opts-row { grid-template-columns: repeat(2, 1fr); }
  .macro-row { grid-template-columns: 1fr; gap: 16px; }
  .food-cards { grid-template-columns: 1fr; }
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
  .shopping-list { grid-template-columns: 1fr; }
  .panel-foot { justify-content: stretch; }
  .panel-foot .btn { flex: 1; justify-content: center; }
  .step-line { width: 50px; }
}

@media (max-width: 380px) {
  .summary-cards { grid-template-columns: 1fr 1fr; }
  .sum-value { font-size: 1.5rem; }
}

/* Add these styles to your naturicalc.css */

.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 1s ease-in-out infinite;
  margin-right: 8px;
}

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

.macros-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.macro-item {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
  border-left: 4px solid #4caf50;
}

.macro-label {
  font-weight: bold;
  color: #333;
  margin-bottom: 0.5rem;
  text-transform: capitalize;
}

.macro-value {
  font-size: 1.1rem;
  color: #4caf50;
  font-weight: 500;
}

.meal-plan-header {
  text-align: center;
  margin-bottom: 2rem;
}

.plan-summary {
  color: #666;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

.meal-section {
  background: white;
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.meal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #f0f0f0;
}

.meal-summary {
  font-size: 0.9rem;
  color: #4caf50;
  font-weight: 500;
}

.meal-foods {
  margin-bottom: 1rem;
}

.food-item {
  background: #f8f9fa;
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.food-name {
  font-weight: 500;
  color: #333;
}

.food-details {
  display: flex;
  gap: 1rem;
  font-size: 0.9rem;
  color: #666;
}

.food-details span {
  background: white;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  border: 1px solid #e0e0e0;
}

.meal-target {
  text-align: center;
  padding-top: 0.5rem;
  border-top: 1px dashed #e0e0e0;
  color: #888;
  font-size: 0.85rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .macros-grid {
    grid-template-columns: 1fr;
  }

  .meal-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .food-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .food-details {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
}
