:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-muted: #eef2ec;
  --surface-raised: #fbfcfa;
  --text: #202522;
  --muted: #69726e;
  --line: #dfe4dc;
  --accent: #2f7d5b;
  --accent-strong: #1f6144;
  --accent-soft: #dceee4;
  --ink: #173c31;
  --warning: #b85c38;
  --warning-soft: #fff5f0;
  --shadow: 0 20px 50px rgba(45, 51, 46, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111816;
  --surface: #19211e;
  --surface-muted: #24302b;
  --surface-raised: #1f2925;
  --text: #f0f4ee;
  --muted: #a6b4ae;
  --line: #334039;
  --accent: #5bb98c;
  --accent-strong: #7ad3a5;
  --accent-soft: rgba(91, 185, 140, 0.18);
  --ink: #234f3e;
  --warning: #e58a62;
  --warning-soft: rgba(229, 138, 98, 0.13);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.4rem, 8vw, 5.6rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.2rem;
}

h3 {
  margin-bottom: 0;
  font-size: 0.96rem;
}

.date-switcher {
  display: grid;
  grid-template-columns: 44px minmax(150px, 1fr) 44px;
  align-items: center;
  gap: 8px;
}

.top-actions {
  display: grid;
  grid-template-columns: minmax(250px, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
}

.icon-button,
.ghost-button,
.primary-button,
.theme-toggle,
.account-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-button {
  width: 44px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
}

.icon-button:hover,
.ghost-button:hover,
.theme-toggle:hover,
.account-button:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.theme-toggle,
.account-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
  font-weight: 800;
  padding: 0 12px;
}

.theme-toggle {
  min-width: 112px;
}

.account-button {
  min-width: 132px;
  white-space: nowrap;
}

.account-button[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.account-sign-out {
  min-width: 104px;
  white-space: nowrap;
}

.theme-toggle-icon {
  font-size: 1.05rem;
  line-height: 1;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.metric,
.goal-control,
.progress-panel,
.nutrient-card,
.panel,
.preview-panel,
.entries-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric,
.goal-control {
  min-height: 140px;
  padding: 18px;
}

.metric-primary {
  background: var(--ink);
  color: #f8fbf8;
}

.metric span,
.goal-control span,
label span,
.nutrient-card span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.metric-primary span,
.metric-primary small {
  color: #cddbd4;
}

.metric strong {
  display: block;
  font-size: clamp(2.2rem, 6vw, 4rem);
  line-height: 1;
  letter-spacing: 0;
}

.metric small,
.goal-control small,
.nutrient-card small {
  color: var(--muted);
}

.goal-control {
  display: grid;
  align-content: start;
}

.goal-control input {
  margin-bottom: 8px;
  font-weight: 800;
}

.progress-panel {
  padding: 16px 18px;
  margin-bottom: 12px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 200ms ease, background 200ms ease;
}

.progress-fill.over {
  background: var(--warning);
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.auth-status {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 24, 22, 0.48);
}

.login-dialog {
  width: min(440px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.26);
}

.dialog-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.dialog-heading h2 {
  margin-bottom: 4px;
}

.dialog-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

.dialog-close {
  width: 40px;
  min-height: 40px;
  font-size: 1.3rem;
}

.profile-panel {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.profile-goal-panel .panel-heading p {
  margin: 4px 0 0;
  color: var(--muted);
}

.profile-goal-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.goal-progress {
  display: grid;
  gap: 10px;
}

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

.profile-card {
  min-height: 128px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.profile-card span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.profile-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  line-height: 1;
  letter-spacing: 0;
}

.profile-card small {
  color: var(--muted);
  line-height: 1.35;
}

.streak-card {
  min-height: 112px;
}

.hidden {
  display: none;
}

[data-view="profile"] #tracker-view,
[data-view="profile"] #date-switcher,
[data-view="tracker"] #profile-panel {
  display: none;
}

.nutrient-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.nutrient-card {
  min-height: 94px;
  padding: 14px;
}

.nutrient-card strong {
  display: inline-block;
  margin-right: 4px;
  font-size: 1.55rem;
  letter-spacing: 0;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(420px, 1.25fr);
  gap: 12px;
  align-items: start;
}

.panel,
.entries-panel {
  padding: 18px;
}

.panel-heading,
.entries-heading,
.food-list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.food-list-heading {
  margin-top: 18px;
  margin-bottom: 10px;
}

.food-form,
.entry-form {
  display: grid;
  gap: 12px;
}

.full-field {
  display: block;
}

.nutrient-input-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(130px, 0.8fr);
  gap: 12px;
}

.form-row-compact {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.primary-button {
  min-width: 132px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  padding: 0 18px;
}

.primary-button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.full-width {
  width: 100%;
}

.ghost-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 800;
  padding: 0 12px;
}

.preview-panel {
  margin: 12px 0;
  padding: 14px;
  color: var(--muted);
}

.preview-panel strong {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
}

.preview-values {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preview-values span {
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 6px 8px;
}

.entry-list,
.food-list,
.weight-list {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.entry-item,
.food-item,
.weight-item {
  display: grid;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface-raised);
}

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

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

.weight-panel {
  margin-bottom: 12px;
}

.weight-panel .panel-heading p {
  margin: 4px 0 0;
  color: var(--muted);
}

.weight-form {
  display: grid;
  grid-template-columns: minmax(150px, 0.8fr) minmax(150px, 0.8fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.weight-chart {
  min-height: 240px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-raised);
  margin-bottom: 12px;
  overflow: hidden;
}

.weight-chart svg {
  display: block;
  width: 100%;
  height: 240px;
}

.chart-grid {
  stroke: var(--line);
  stroke-width: 1;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.chart-area {
  fill: var(--accent-soft);
}

.chart-dot {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 3;
}

.chart-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.weight-date {
  color: var(--muted);
  font-weight: 700;
}

.weight-value {
  font-weight: 900;
  white-space: nowrap;
}

.entry-main,
.food-main {
  min-width: 0;
}

.entry-name,
.food-name {
  display: block;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.entry-type,
.entry-macros,
.food-values {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
}

.entry-macros,
.food-values {
  margin-top: 2px;
}

.entry-calories {
  font-weight: 900;
  white-space: nowrap;
}

.delete-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--warning);
  font-size: 1.1rem;
  line-height: 1;
}

.delete-button:hover {
  border-color: var(--warning);
  background: var(--warning-soft);
}

.empty-state {
  display: none;
  margin-bottom: 0;
  color: var(--muted);
}

.empty-state.visible {
  display: block;
}

@media (max-width: 1020px) {
  .auth-form {
    grid-template-columns: 1fr;
  }

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

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

  .profile-goal-form,
  .profile-insights-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 20px, 560px);
    padding: 20px 0;
  }

  .topbar,
  .progress-label,
  .entries-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    grid-template-columns: 1fr;
  }

  .summary-grid,
  .nutrient-grid,
  .auth-actions,
  .profile-goal-form,
  .profile-insights-grid,
  .weight-form,
  .form-row,
  .form-row-compact {
    grid-template-columns: 1fr;
  }

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

  .metric,
  .goal-control {
    min-height: 112px;
  }

  .primary-button {
    width: 100%;
  }

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

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

  .entry-calories {
    grid-column: 1 / 2;
  }

  .delete-button {
    grid-column: 2 / 3;
    grid-row: 1 / 3;
  }
}
