:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #1b2d26;
  --ink-2: #36463f;
  --muted: #6f7a82;
  --line: #d8dee8;
  --line-soft: #e8edf4;
  --accent: #1e7b5c;
  --accent-dark: #0f4b3a;
  --accent-soft: #ddeee6;
  --warn: #b85c2a;
  --warn-soft: #f6e2d3;
  --elani: #b85076;
  --elani-soft: #f6e0ea;
  --dean: #2c7ca6;
  --dean-soft: #dcedf6;
  --breakfast-bg: #ffefcc;
  --breakfast-fg: #7b5a0f;
  --lunch-bg: #ffdfc9;
  --lunch-fg: #8b3e17;
  --dinner-bg: #dbe5f2;
  --dinner-fg: #1f3f66;
  --snack-bg: #eadcf1;
  --snack-fg: #5a2a7a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 0.9), rgb(255 255 255 / 0) 260px),
    var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button, input, select {
  font: inherit;
  min-width: 0;
}

button {
  min-height: 44px;
  border: 0;
  cursor: pointer;
}

.app {
  min-height: 100vh;
  width: min(100%, 780px);
  padding: 16px max(14px, env(safe-area-inset-left)) 104px max(14px, env(safe-area-inset-right));
  max-width: 780px;
  margin: 0 auto;
}

.login {
  min-height: 100vh;
  display: grid;
  align-content: center;
  gap: 16px;
  max-width: 460px;
  margin: 0 auto;
  padding: 24px 16px;
}

.hero {
  padding: 18px 4px 16px;
}

.progress-hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.hero h1 {
  margin: 0 0 4px;
  font-size: 28px;
  line-height: 1.1;
}

.hero p, .muted {
  margin: 0;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin: 10px 0;
  box-shadow: 0 8px 22px rgb(27 45 38 / 0.045);
}

.section-title {
  font-size: 18px;
  margin: 20px 2px 8px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 10px; }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

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

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-width: 0;
  box-shadow: 0 8px 22px rgb(27 45 38 / 0.035);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 4px;
}

.stat strong {
  display: block;
  font-size: clamp(18px, 5vw, 24px);
  line-height: 1.05;
}

.today-dashboard {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 14px;
}

.calorie-card,
.weight-card,
.macro-card,
.quick-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgb(27 45 38 / 0.045);
  min-width: 0;
}

.calorie-card {
  grid-column: span 2;
  display: grid;
  gap: 10px;
  padding: 16px;
}

.calorie-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.calorie-main strong {
  color: var(--accent-dark);
  font-size: clamp(44px, 8vw, 64px);
  line-height: 0.95;
}

.calorie-main span {
  color: var(--ink-2);
  font-size: 18px;
  font-weight: 900;
}

.calorie-progress {
  height: 13px;
}

.weight-card {
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 16px;
}

.weight-card strong {
  font-size: clamp(26px, 5vw, 36px);
  line-height: 1;
}

.weight-card p {
  margin: 0;
  font-weight: 900;
}

.macro-card {
  padding: 14px;
}

.quick-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.quick-card {
  display: grid;
  gap: 10px;
  min-height: 138px;
  padding: 14px;
  text-align: left;
  color: var(--ink);
  width: 100%;
}

.quick-card:hover {
  border-color: #bdd3cc;
  box-shadow: 0 10px 26px rgb(27 45 38 / 0.075);
}

.quick-card strong {
  font-size: 16px;
}

.progress-layout {
  display: grid;
  gap: 12px;
}

.progress-form {
  align-self: start;
  display: grid;
  gap: 12px;
}

.progress-form p {
  margin-top: 3px;
}

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

.target-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, 1fr);
  margin: 4px 0 12px;
}

.target-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgb(27 45 38 / 0.035);
}

.target-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.target-card strong {
  display: block;
  margin: 5px 0;
  font-size: clamp(20px, 4vw, 28px);
  line-height: 1;
}

.target-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.target-card.you {
  border-color: #b8d9ab;
  background: linear-gradient(180deg, #f7fff4, #fff);
}

.target-card.him {
  border-color: #b8cce8;
  background: linear-gradient(180deg, #f4f8ff, #fff);
}

.target-card.rule {
  border-color: #e6d4ae;
  background: linear-gradient(180deg, #fffaf0, #fff);
}

.guide-grid {
  display: grid;
  gap: 10px;
}

.account-card {
  display: grid;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 8px 22px rgb(27 45 38 / 0.045);
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.account-row > div {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
}

.account-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.phase-recommendation {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 12px;
}

.phase-recommendation.ready {
  border-color: #bdd9cb;
  background: var(--accent-soft);
}

.phase-recommendation p {
  margin: 4px 0 0;
  color: var(--muted);
}

.shop-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.shop-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 120px auto;
  gap: 10px;
  align-items: end;
}

.shop-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.shop-actions .inline {
  white-space: nowrap;
}

.shop-columns {
  display: grid;
  gap: 14px;
  align-items: start;
}

.inventory-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: 0 6px 16px rgb(27 45 38 / 0.035);
}

.inventory-line strong {
  display: block;
  margin-bottom: 2px;
}

.portion-guide {
  display: grid;
  gap: 8px;
  margin: 10px 0;
}

.portion-section {
  display: grid;
}

.portion-head {
  border-radius: 8px 8px 0 0;
  padding: 12px 14px;
  color: #fff;
  background: linear-gradient(90deg, #10233e, #1e7b5c);
  cursor: pointer;
  list-style: none;
}

.portion-head::-webkit-details-marker { display: none; }

.portion-head p {
  margin-top: 2px;
  color: rgb(255 255 255 / 0.78);
}

.portion-head::after {
  content: "Hide";
  float: right;
  margin-top: -26px;
  border-radius: 999px;
  padding: 4px 9px;
  background: rgb(255 255 255 / 0.18);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.portion-section:not([open]) .portion-head {
  border-radius: 8px;
}

.portion-section:not([open]) .portion-head::after {
  content: "Open";
}

.portion-head.veg {
  background: linear-gradient(90deg, #1b5e20, #5a8f16);
}

.portion-head.extras {
  background: linear-gradient(90deg, #8b3e17, #6d4b8d);
}

.guide-table {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgb(27 45 38 / 0.035);
}

.guide-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.1fr) minmax(120px, 0.75fr) minmax(120px, 0.75fr) minmax(180px, 1.2fr);
  min-height: 50px;
  border-top: 1px solid var(--line-soft);
  min-width: 620px;
}

.guide-row > * {
  padding: 11px 12px;
  display: grid;
  align-content: center;
  border-left: 1px solid var(--line-soft);
}

.guide-row > *:first-child {
  border-left: 0;
}

.guide-row-head {
  min-height: 40px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.you-col {
  color: #1b5e20;
  background: #f4fbf0;
  font-weight: 900;
}

.him-col {
  color: #163b78;
  background: #f3f7ff;
  font-weight: 900;
}

.tip-col {
  color: var(--ink-2);
  font-size: 13px;
}

.positive { color: var(--accent-dark); }
.negative { color: var(--warn); }

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 13px;
  font-weight: 700;
}

.elani { color: var(--elani); background: var(--elani-soft); }
.dean { color: var(--dean); background: var(--dean-soft); }
.ok { color: var(--accent-dark); background: var(--accent-soft); }
.warn { color: var(--warn); background: var(--warn-soft); }

.metric-big {
  font-size: 46px;
  line-height: 1;
  color: var(--accent-dark);
  font-weight: 800;
}

.bar {
  height: 10px;
  background: var(--line-soft);
  border-radius: 999px;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  width: min(var(--pct), 100%);
  background: var(--accent);
  border-radius: inherit;
}

.meal-tag {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
}

.Breakfast { color: var(--breakfast-fg); background: var(--breakfast-bg); }
.Lunch { color: var(--lunch-fg); background: var(--lunch-bg); }
.Dinner { color: var(--dinner-fg); background: var(--dinner-bg); }
.Snack { color: var(--snack-fg); background: var(--snack-bg); }

.meal-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 6px;
  min-width: 0;
}

.create-meal-btn {
  margin-bottom: 12px;
}

.meal-library {
  display: grid;
  gap: 12px;
}

.recipe-card {
  display: grid;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 8px 22px rgb(27 45 38 / 0.045);
  min-width: 0;
}

.recipe-top,
.recipe-title-row,
.recipe-actions,
.macro-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.recipe-top,
.recipe-title-row {
  justify-content: space-between;
}

.recipe-title-row strong {
  font-size: 18px;
}

.recipe-title-row span {
  color: var(--ink-2);
  font-weight: 900;
}

.macro-row {
  flex-wrap: wrap;
}

.macro-row span {
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  color: var(--ink-2);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 900;
}

.recipe-actions {
  flex-wrap: wrap;
}

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 8px max(8px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
  z-index: 10;
  box-shadow: 0 -10px 28px rgb(15 23 42 / 0.08);
  gap: 4px;
}

.nav button {
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
  min-height: 48px;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
  padding: 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav button.active {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.primary, .secondary, .danger {
  width: 100%;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
}

.primary { background: var(--accent); color: #fff; }
.secondary { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.danger { background: var(--warn-soft); color: var(--warn); }
.inline { width: auto; min-height: 38px; }

label {
  display: grid;
  gap: 5px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}

input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 9px 11px;
}

input:focus, select:focus {
  outline: 3px solid var(--accent-soft);
  border-color: var(--accent);
}

.food-row {
  display: grid;
  grid-template-columns: auto 1fr 88px;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
}

.food-row input[type="checkbox"] {
  width: 22px;
  min-height: 22px;
}

.food-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.food-group + .food-group {
  margin-top: 10px;
}

.food-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
}

.food-group-head span {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  min-height: 24px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
}

.food-group .food-row {
  padding: 10px 12px;
}

.food-group .food-row:last-child {
  border-bottom: 0;
}

.dialog {
  position: fixed;
  inset: 0;
  background: rgb(27 45 38 / 0.36);
  display: grid;
  align-items: end;
  z-index: 20;
}

.sheet {
  background: var(--bg);
  max-height: 88vh;
  overflow: auto;
  border-radius: 12px 12px 0 0;
  padding: 16px;
  width: 100%;
}

.empty {
  color: var(--muted);
  padding: 12px;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.empty-state p {
  margin-top: 4px;
}

.chart-card {
  overflow: hidden;
  padding: 16px;
}

.chart {
  display: block;
  width: 100%;
  height: 260px;
  margin-top: 6px;
}

.chart-axis {
  stroke: var(--line);
  stroke-width: 2;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 6px 7px rgb(30 123 92 / 0.14));
}

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

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

.chart-empty {
  min-height: 140px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 8px;
  margin-top: 10px;
  padding: 16px;
  text-align: center;
}

.history-head .section-title {
  margin-top: 12px;
}

.progress-entry {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 12px;
  align-items: stretch;
}

.entry-date {
  display: grid;
  place-items: center;
  min-height: 64px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border: 1px solid #c9e3d7;
  border-radius: 8px;
  font-weight: 900;
  text-align: center;
}

.entry-body {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  display: grid;
  align-content: center;
  gap: 3px;
  box-shadow: 0 6px 16px rgb(27 45 38 / 0.035);
}

.entry-body strong {
  font-size: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translate(-50%, 12px);
  max-width: min(420px, calc(100vw - 32px));
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  font-weight: 800;
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 40;
  box-shadow: 0 10px 26px rgb(27 45 38 / 0.22);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hidden { display: none; }

@media (min-width: 780px) {
  .app {
    width: min(100%, 860px);
    max-width: 860px;
    padding: 18px 22px 56px;
  }
  .nav {
    position: sticky;
    top: 14px;
    bottom: auto;
    max-width: 860px;
    margin: 0 auto 22px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 6px;
    background: rgb(255 255 255 / 0.86);
    backdrop-filter: blur(14px);
    box-shadow: 0 12px 30px rgb(15 23 42 / 0.07);
  }

  .nav button {
    min-height: 46px;
    border-radius: 8px;
  }

  .nav button:hover {
    color: var(--ink-2);
    background: var(--surface-2);
  }

  .nav button.active {
    color: var(--accent-dark);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px rgb(15 75 58 / 0.06);
  }

  .hero {
    padding-top: 0;
  }

  .dialog { align-items: center; }
  .sheet {
    width: min(680px, calc(100vw - 32px));
    margin: 0 auto;
    border-radius: 8px;
  }
  .sheet-wide {
    width: min(1120px, calc(100vw - 32px));
  }
  .toast { bottom: 24px; }
}

@media (min-width: 640px) and (max-width: 1039px) {
  .today-dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .calorie-card {
    grid-column: span 2;
  }

  .shop-form {
    grid-template-columns: minmax(220px, 1fr) 120px;
  }

  .shop-actions {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1040px) {
  .app,
  .nav {
    width: min(100%, 980px);
    max-width: 980px;
  }

  .progress-layout {
    grid-template-columns: minmax(0, 1.6fr) minmax(310px, 0.8fr);
    align-items: start;
  }

  .progress-form {
    margin-top: 10px;
  }

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

  .account-card {
    grid-column: 1 / -1;
  }

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

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

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

  .chart {
    height: 300px;
  }
}

@media (max-width: 639px) {
  .insights,
  .target-grid,
  .shop-stats {
    grid-template-columns: 1fr;
  }

  .progress-hero {
    display: grid;
    align-items: start;
  }

  .progress-hero > .chip {
    width: 100%;
  }

  .today-dashboard {
    grid-template-columns: 1fr;
  }

  .calorie-card {
    grid-column: auto;
  }

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

  .chart {
    height: 220px;
  }

  .progress-entry {
    grid-template-columns: 64px 1fr;
  }

  .guide-row {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .portion-section:not(:first-child) {
    margin-top: 6px;
  }

  .portion-section:not([open]) .guide-table {
    display: none;
  }

  .portion-head {
    border-radius: 8px;
  }

  .shop-form,
  .shop-columns {
    grid-template-columns: 1fr;
  }

  .shop-actions {
    display: grid;
  }

  .inventory-line {
    grid-template-columns: 1fr;
  }

  .account-row {
    display: flex;
    align-items: center;
  }

  .account-row > div {
    flex: 1 1 0;
  }

  .account-actions {
    justify-content: flex-end;
  }

  .account-actions .inline {
    width: auto;
    min-width: 96px;
  }

  .recipe-top,
  .recipe-title-row,
  .recipe-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .recipe-actions .inline {
    width: 100%;
  }

  .guide-row-head {
    display: none;
  }

  .guide-row > * {
    border-left: 0;
  }

  .guide-row strong {
    background: #f8fafc;
  }
}

@media (max-width: 380px) {
  .app {
    padding-left: 10px;
    padding-right: 10px;
  }

  .hero h1 {
    font-size: 24px;
  }

  .nav {
    padding-left: 4px;
    padding-right: 4px;
  }

  .nav button {
    font-size: 11px;
    min-height: 44px;
  }

  .calorie-main strong {
    font-size: 40px;
  }

  .meal-line,
  .inventory-line {
    grid-template-columns: 1fr;
  }
}
