:root {
  color-scheme: light;
  --bg: #f6f8f5;
  --surface: #ffffff;
  --surface-strong: #eef6f1;
  --ink: #1c2521;
  --muted: #69776f;
  --line: #dce6df;
  --green: #2f8f68;
  --green-dark: #1f6f51;
  --blue: #3b82a6;
  --amber: #c48a2c;
  --rose: #c86666;
  --shadow: 0 18px 48px rgba(36, 56, 45, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(246, 248, 245, 0.92)),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 24px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--rose);
  font-size: 13px;
  font-weight: 700;
}

.login-required .app-shell {
  display: none;
}

body:not(.login-required) .login-screen {
  display: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 20px;
  background: rgba(255, 255, 255, 0.86);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 34px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  overflow: hidden;
  border-radius: 8px;
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 21px;
  line-height: 1.25;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(24px, 4vw, 36px);
  line-height: 1.15;
}

h3 {
  margin-bottom: 0;
  font-size: 20px;
}

h4 {
  margin-bottom: 0;
  font-size: 16px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab,
.person-button,
.range-button,
.ghost-button,
.primary-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition: 150ms ease;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-tab:hover,
.nav-tab.active {
  background: var(--surface-strong);
  color: var(--green-dark);
}

.nav-tab span,
.nav-tab svg {
  width: 24px;
  height: 24px;
  color: var(--green);
  text-align: center;
}

.ui-icon,
.module-icon {
  display: inline-block;
  color: var(--green);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.ui-icon use,
.module-icon use {
  fill: none;
  stroke: currentColor;
}

.ui-icon {
  width: 20px !important;
  height: 20px !important;
}

.module-icon {
  width: 20px !important;
  height: 20px !important;
  margin-right: 8px;
  vertical-align: -3px;
}

.module-icon.small {
  width: 17px !important;
  height: 17px !important;
  margin-right: 7px;
  vertical-align: -3px;
}

.side-panel {
  margin-top: 32px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfb;
}

.panel-label {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.person-switch,
.range-tabs {
  display: flex;
  gap: 8px;
}

.person-button,
.range-button {
  background: #fff;
  border-color: var(--line);
  color: var(--muted);
  font-weight: 700;
}

.person-button {
  flex: 1;
}

.person-button.active,
.range-button.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.logout-button {
  width: 100%;
  margin-top: 14px;
}

.muted {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.main-content {
  min-width: 0;
  padding: 30px;
  overflow-x: hidden;
}

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

.date-control {
  display: grid;
  gap: 8px;
  min-width: 180px;
}

label span,
.date-control label,
.upload-box > label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

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

textarea {
  padding: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(47, 143, 104, 0.72);
  box-shadow: 0 0 0 4px rgba(47, 143, 104, 0.12);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.record-grid,
.history-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 18px;
  min-width: 0;
}

.wide {
  grid-column: 1 / -1;
}

.section-block {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

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

.history-layout .section-heading {
  align-items: center;
}

.save-state {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: #f2f5f2;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.save-state.saved {
  background: #e1f3eb;
  color: var(--green-dark);
}

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

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

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

.body-main-grid {
  grid-template-columns: minmax(180px, 0.6fr) minmax(180px, 0.6fr);
}

.body-details {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfb;
}

.body-details summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: var(--green-dark);
  font-weight: 800;
  cursor: pointer;
}

.body-details .metrics-grid {
  padding: 0 12px 12px;
}

label,
.textarea-label,
.upload-box {
  display: grid;
  gap: 8px;
}

.textarea-label {
  margin-top: 14px;
}

.meal-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.meal-card {
  display: none;
  min-width: 0;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfb;
}

.meal-card.active {
  display: grid;
}

.meal-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--green-dark);
}

.meal-card-head span {
  color: var(--muted);
  font-size: 12px;
}

.meal-standard-selector {
  margin-bottom: 18px;
}

.sub-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.sub-tab {
  flex: 0 0 auto;
  min-width: 78px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.sub-tab.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.standard-hint {
  min-height: 42px;
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfb;
}

.standard-hint strong,
.standard-meal strong,
.compare-grid strong {
  color: var(--green-dark);
  font-size: 13px;
}

.standard-hint span {
  color: var(--muted);
  font-size: 13px;
}

.standard-meal {
  padding: 12px;
  border: 1px dashed #cfe0d6;
  border-radius: var(--radius);
  background: #f5faf7;
}

.standard-meal ul,
.compare-grid ul {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.7;
}

.standard-meal p,
.compare-grid p {
  margin: 6px 0 0;
  color: var(--muted);
}

.ingredient-list,
.recipe-editor {
  display: grid;
  gap: 10px;
}

.ingredient-row {
  display: grid;
  grid-template-columns: minmax(120px, 1.2fr) 76px 72px minmax(96px, 1fr) 34px;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.ingredient-row input,
.ingredient-row select {
  min-width: 0;
  min-height: 36px;
  padding: 0 8px;
  font-size: 14px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.add-ingredient,
.add-recipe-ingredient,
#addWorkout {
  min-height: 36px;
}

.upload-box {
  margin-top: 14px;
}

.upload-box.compact {
  margin-top: 0;
}

input[type="file"] {
  padding: 9px;
  font-size: 13px;
}

.photo-preview,
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  gap: 8px;
}

.photo-preview img,
.gallery img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #edf2ee;
}

.big-note {
  min-height: 260px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding-bottom: 24px;
}

.ghost-button,
.primary-button {
  padding: 0 18px;
  font-weight: 800;
}

.ghost-button {
  background: #fff;
  border-color: var(--line);
  color: var(--muted);
}

.primary-button {
  background: var(--green);
  color: #fff;
}

.primary-button:hover,
.person-button.active:hover,
.range-button.active:hover {
  background: var(--green-dark);
}

.person-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #ffffff, #f7fbf8);
}

.person-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.status-pill {
  padding: 5px 9px;
  border-radius: 999px;
  background: #eaf4ef;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.body-stat-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.checkin-main-stats {
  grid-template-columns: minmax(140px, 0.35fr) minmax(140px, 0.35fr);
}

.stat {
  padding: 12px;
  border-radius: var(--radius);
  background: #f4f8f5;
}

.stat strong {
  display: block;
  margin-bottom: 4px;
  font-size: 22px;
  line-height: 1;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.timeline-list,
.history-list {
  display: grid;
  gap: 12px;
}

.timeline-item,
.history-item {
  padding: 12px 0 12px 14px;
  border-left: 3px solid var(--green);
}

.timeline-item h4,
.history-item h4 {
  margin-bottom: 5px;
}

.timeline-item p,
.history-item p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.board-note {
  margin: 0 0 18px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: #f5faf7;
  color: var(--muted);
  line-height: 1.7;
}

.checkin-board {
  display: grid;
  gap: 18px;
}

.checkin-person,
.recipe-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfb;
}

.recipe-card {
  display: none;
}

.recipe-card.active {
  display: block;
}

.checkin-section {
  margin-top: 18px;
}

.checkin-section h4 {
  margin-bottom: 10px;
}

.checkin-body-details {
  margin-top: 10px;
}

.checkin-body-details .body-stat-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.checkin-meal {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.checkin-meal h5 {
  margin: 0 0 10px;
  color: var(--green-dark);
  font-size: 15px;
}

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

.compare-grid > div {
  padding: 12px;
  border-radius: var(--radius);
  background: #fff;
}

.workout-line {
  margin-bottom: 0;
  color: var(--ink);
  font-weight: 700;
}

.workout-list {
  display: grid;
  gap: 12px;
}

.workout-card,
.workout-summary {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfb;
}

.workout-row {
  display: grid;
  grid-template-columns: minmax(116px, 0.9fr) 76px 92px minmax(180px, 1.4fr) 34px;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.workout-row input,
.workout-row select {
  min-width: 0;
  min-height: 36px;
  padding: 0 8px;
  font-size: 14px;
}

.workout-summary + .workout-summary {
  margin-top: 8px;
}

.workout-summary strong {
  color: var(--ink);
}

.chart-frame {
  width: 100%;
  aspect-ratio: 16 / 5;
  min-height: 150px;
  overflow: hidden;
  background: #fbfdfb;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.chart-frame-wide {
  aspect-ratio: 16 / 5;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

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

  .sidebar {
    position: static;
    height: auto;
    padding: 18px;
  }

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

  .side-panel {
    margin-top: 16px;
  }

  .record-grid,
  .history-layout {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 720px) {
  .main-content {
    padding: 12px;
  }

  .topbar {
    display: grid;
  }

  .nav-tabs,
  .metrics-grid,
  .body-main-grid,
  .input-grid,
  .meal-list,
  .stat-grid,
  .body-stat-grid,
  .checkin-main-stats,
  .compare-grid {
    grid-template-columns: 1fr;
  }

  .ingredient-row {
    grid-template-columns: minmax(64px, 1.1fr) 50px 48px minmax(44px, 0.8fr) 28px;
    gap: 4px;
    align-items: center;
  }

  .ingredient-row input,
  .ingredient-row select {
    min-height: 32px;
    padding: 0 5px;
    font-size: 12px;
  }

  .ingredient-row .icon-button {
    width: 28px;
    height: 28px;
  }

  .workout-row {
    grid-template-columns: minmax(62px, 1fr) 48px 58px minmax(58px, 0.9fr) 28px;
    gap: 4px;
  }

  .workout-row input,
  .workout-row select {
    min-height: 32px;
    padding: 0 5px;
    font-size: 12px;
  }

  .workout-row .icon-button {
    width: 28px;
    height: 28px;
  }

  .form-actions {
    display: grid;
  }

  .history-layout .section-heading {
    display: grid;
    gap: 12px;
  }

  .history-layout .section-heading h3 {
    display: flex;
    align-items: center;
    font-size: 22px;
    line-height: 1.25;
  }

  .history-layout .range-tabs {
    width: 100%;
  }

  .history-layout .range-button {
    flex: 1;
    min-width: 0;
  }

  .chart-frame {
    aspect-ratio: auto;
    height: 180px;
    min-height: 180px;
  }

  .chart-frame-wide {
    aspect-ratio: auto;
  }

  .section-block {
    padding: 14px;
  }

  .meal-card,
  .workout-card,
  .recipe-card {
    padding: 10px;
  }

  input[type="file"] {
    font-size: 12px;
  }
}
.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}
