:root {
  color-scheme: light;
  --bg: #f5f7f2;
  --ink: #1d2520;
  --muted: #647067;
  --line: #dce3db;
  --panel: #ffffff;
  --accent: #167c68;
  --accent-dark: #0f5d4f;
  --warm: #d47a4a;
  --gold: #e4b64b;
  --blue: #5079a6;
  --shadow: 0 18px 45px rgba(29, 37, 32, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #edf4ef 0%, var(--bg) 34%, #fffaf4 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 10px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 6vw, 4.5rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  font-size: 1.35rem;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--accent-dark);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 22px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 20px 40px;
}

.dashboard {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.panel,
.metric {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 20px;
}

.section-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.section-heading.compact {
  align-items: center;
  margin-bottom: 14px;
}

.entry-form,
.food-search,
.goals-form {
  display: grid;
  gap: 18px;
}

.field-grid,
.slider-grid,
.goals-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label,
fieldset {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  padding: 14px;
}

legend {
  padding: 0 8px;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #cfd8d0;
  border-radius: 7px;
  background: #fbfdfb;
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 42px;
  padding: 0 11px;
}

textarea {
  display: block;
  margin-top: 7px;
  padding: 11px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 124, 104, 0.14);
}

input[type="range"] {
  accent-color: var(--accent);
  border: 0;
  padding: 0;
}

output {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 28px;
  margin-top: 2px;
  border-radius: 7px;
  background: #e8f2ef;
  color: var(--accent-dark);
}

.habit-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.habit-list label {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
}

.habit-list input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

button {
  border: 0;
  cursor: pointer;
  font-weight: 800;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

a {
  color: var(--accent-dark);
}

.primary-button,
.secondary-button {
  min-height: 46px;
  border-radius: 7px;
}

.primary-button {
  background: var(--accent);
  color: white;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  background: #23312b;
  color: white;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  background: #1f2a25;
  color: white;
  font-size: 1.35rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  min-height: 116px;
  padding: 16px;
  display: grid;
  align-content: space-between;
}

.metric span,
.metric small {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.metric strong {
  color: var(--accent-dark);
  font-size: clamp(1.45rem, 3vw, 2rem);
  line-height: 1;
}

.dashboard {
  display: grid;
  gap: 18px;
}

.source-link {
  align-self: start;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 11px;
  background: #f7faf7;
  font-size: 0.78rem;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.calorie-summary {
  display: grid;
  gap: 4px;
  margin-bottom: 18px;
  border-left: 5px solid var(--warm);
  border-radius: 8px;
  background: #fff7ef;
  padding: 14px 16px;
}

.calorie-summary strong {
  font-size: 2rem;
  line-height: 1;
}

.calorie-summary span,
.status-text,
.food-meta,
.meal-meta {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.search-row,
.food-action-row,
.sync-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 7px;
}

.sync-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 0;
}

.status-text {
  min-height: 22px;
}

.food-results,
.food-list,
.meal-list {
  display: grid;
  gap: 10px;
}

.food-card,
.meal-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  padding: 12px;
}

.food-card {
  display: grid;
  gap: 10px;
}

.food-card header,
.meal-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.food-card h3,
.meal-item strong {
  margin: 0;
  font-size: 0.98rem;
}

.food-card small {
  color: var(--muted);
  font-weight: 700;
}

.food-action-row {
  grid-template-columns: 88px 1fr auto;
  align-items: end;
}

.food-action-row label {
  min-width: 0;
}

.tiny-button,
.ghost-button {
  min-height: 38px;
  border-radius: 7px;
  padding: 0 11px;
}

.tiny-button {
  background: var(--accent);
  color: white;
}

.ghost-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

.subheading {
  margin-top: 22px;
}

.remove-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: #f7e8e2;
  color: #9c3f28;
}

.empty-state.compact {
  padding: 6px 0;
}

.chart-panel canvas {
  display: block;
  width: 100%;
  height: 320px;
}

.goals-form {
  align-items: end;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 18px;
  align-items: center;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.history-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.history-note {
  color: var(--muted);
  margin-top: 4px;
}

.history-stats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
  margin: 0;
}

.history-stats div {
  min-width: 70px;
  border-radius: 7px;
  background: #f0f4ef;
  padding: 8px;
  text-align: center;
}

.history-stats dt {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.history-stats dd {
  margin: 3px 0 0;
  font-weight: 800;
}

.history-delete {
  flex: 0 0 auto;
}

.empty-state {
  color: var(--muted);
  padding: 16px 0 4px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .dashboard {
    grid-column: auto;
    grid-row: auto;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .app-header {
    padding-top: 22px;
  }

  .field-grid,
  .slider-grid,
  .goals-form,
  .food-action-row,
  .search-row,
  .sync-grid,
  .habit-list {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }

  .panel {
    padding: 16px;
  }

  .history-item {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .history-stats {
    grid-column: 1 / -1;
    justify-content: start;
  }
}
