:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --ink: #18302d;
  --muted: #657673;
  --line: #dfe8e4;
  --brand: #0f766e;
  --brand-dark: #0a5b55;
  --accent: #d97706;
  --soft: #e3f4ef;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  min-height: 110px; padding: 24px clamp(20px, 5vw, 72px); color: white;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(120deg, #0b514c, #0f766e 60%, #199187);
}
.topbar h1 { margin: 3px 0 0; font-size: clamp(1.7rem, 3vw, 2.4rem); }
.eyebrow { margin: 0; font-size: .72rem; font-weight: 800; letter-spacing: .14em; opacity: .75; }
.status { font-size: .82rem; background: rgba(255,255,255,.14); padding: 9px 12px; border-radius: 999px; }
.status span { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: #a7f3d0; }

.tabs { display: flex; gap: 4px; padding: 0 clamp(16px, 5vw, 72px); background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { border: 0; background: transparent; padding: 16px 18px; color: var(--muted); font-weight: 700; white-space: nowrap; border-bottom: 3px solid transparent; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

main { width: min(1180px, calc(100% - 32px)); margin: 30px auto 72px; }
.view { display: none; }
.view.active { display: block; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
h2 { margin: 5px 0 0; font-size: clamp(1.5rem, 3vw, 2.25rem); }
h3 { margin: 0; }
.muted { color: var(--muted); }

.calorie-card, .panel, .metric, .day-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 8px 24px rgba(24,48,45,.04); }
.calorie-card { padding: 24px; }
.calorie-card p { margin-top: 0; }
.calorie-number { margin-bottom: 20px; }
.calorie-number strong { font-size: clamp(2rem, 5vw, 3.4rem); }
.calorie-number span { color: var(--muted); }
.progress-track { height: 12px; border-radius: 999px; background: #e5ece9; overflow: hidden; }
.progress-fill { width: 0; height: 100%; background: linear-gradient(90deg, var(--brand), #2bb7a7); transition: width .35s ease; }
.remaining { margin: 10px 0 0 !important; color: var(--brand-dark); font-weight: 700; }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 14px 0; }
.metric { padding: 18px; }
.metric span, .metric small { display: block; color: var(--muted); }
.metric strong { display: block; margin: 8px 0 4px; font-size: 1.45rem; }

.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.panel { padding: 22px; }
.panel-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.text-button { padding: 0; border: 0; background: none; color: var(--brand); font-weight: 800; }
.stack { display: grid; gap: 10px; }
.entry { display: flex; justify-content: space-between; gap: 18px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.entry p { margin: 2px 0; }
.entry strong { white-space: nowrap; }
.pill { display: inline-block; border-radius: 999px; padding: 3px 8px; background: var(--soft); color: var(--brand-dark); font-size: .72rem; font-weight: 800; text-transform: uppercase; }
.empty-state:empty::after { content: "Nothing here yet."; color: var(--muted); }

.week-grid { display: grid; grid-template-columns: repeat(7, minmax(150px, 1fr)); gap: 10px; overflow-x: auto; padding-bottom: 12px; }
.day-card { padding: 15px; min-height: 250px; }
.day-card h3 { font-size: .95rem; }
.day-card > p { margin: 3px 0 14px; color: var(--muted); font-size: .8rem; }
.meal-slot { padding: 10px; margin-top: 8px; border-radius: 12px; background: var(--bg); }
.meal-slot small { display: block; color: var(--muted); text-transform: capitalize; }
.meal-slot strong { display: block; margin: 3px 0; font-size: .84rem; }

.form-panel { margin-top: 18px; }
.form-panel summary { font-size: 1.1rem; font-weight: 800; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
.spaced { margin-top: 24px; }
label { display: grid; gap: 6px; color: #38514d; font-size: .82rem; font-weight: 750; }
input, select, textarea { width: 100%; border: 1px solid #cddbd6; border-radius: 10px; padding: 11px 12px; color: var(--ink); background: white; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(15,118,110,.14); border-color: var(--brand); }
.span-2 { grid-column: span 2; }
.primary, .secondary { border: 0; border-radius: 11px; padding: 12px 16px; font-weight: 800; }
.primary { background: var(--brand); color: white; }
.primary:hover { background: var(--brand-dark); }
.secondary { width: 100%; margin-top: 12px; background: var(--soft); color: var(--brand-dark); }

.recipe-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.recipe-card { background: white; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.recipe-color { height: 8px; background: linear-gradient(90deg, var(--brand), #65a30d); }
.recipe-content { padding: 18px; }
.recipe-content p { color: var(--muted); min-height: 42px; }
.recipe-macros { display: flex; gap: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.recipe-macros span { font-size: .8rem; color: var(--muted); }
.recipe-macros strong { display: block; color: var(--ink); font-size: 1rem; }

.log-layout { align-items: start; }
.upload-box { margin: 18px 0 12px; padding: 28px 16px; text-align: center; border: 2px dashed #b9d2ca; border-radius: 14px; background: #f7fbfa; }
.upload-box input { margin-bottom: 12px; }
.upload-box span { display: block; margin-top: 4px; color: var(--muted); font-weight: 500; }
.analysis-result { margin-top: 14px; padding: 14px; border-radius: 12px; background: var(--bg); white-space: pre-wrap; }

#toast { position: fixed; right: 22px; bottom: 22px; max-width: 360px; padding: 13px 16px; border-radius: 12px; background: #18302d; color: white; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s; }
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { background: #991b1b; }

@media (max-width: 840px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .two-column, .recipe-grid { grid-template-columns: 1fr; }
  .week-grid { grid-template-columns: repeat(7, 170px); }
}

@media (max-width: 560px) {
  .topbar { min-height: 90px; padding: 18px; }
  .status { display: none; }
  main { width: min(100% - 22px, 1180px); margin-top: 20px; }
  .section-heading { align-items: start; flex-direction: column; }
  .section-heading input { width: 100%; }
  .metric-grid { gap: 8px; }
  .metric, .panel, .calorie-card { padding: 16px; border-radius: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
}
