:root {
  color-scheme: light;
  --bg: #f2f5f8;
  --bg-soft: #e8f0f8;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #edf3fa;
  --text: #172333;
  --muted: #637286;
  --muted-2: #8996a6;
  --line: #d7e0ea;
  --line-strong: #adbdcf;
  --primary: #0058a3;
  --primary-dark: #003e73;
  --primary-soft: #e4f0fa;
  --yellow: #ffda1a;
  --yellow-dark: #e2bd00;
  --coral: #d94b3d;
  --coral-soft: #fff0eb;
  --amber: #ffda1a;
  --amber-soft: #fff8cc;
  --sky: #0078c9;
  --sky-soft: #e8f4fc;
  --green: #23845f;
  --green-soft: #e8f5ef;
  --danger: #c93d3d;
  --shadow: 0 16px 40px rgba(0, 62, 115, 0.1);
  --shadow-soft: 0 8px 22px rgba(0, 62, 115, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

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

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

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    background 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

button:active {
  transform: translateY(1px);
}

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

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 16px clamp(16px, 4vw, 44px);
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid rgba(219, 232, 227, 0.8);
  backdrop-filter: blur(18px);
}

.topbar h1,
.section-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(21px, 2.2vw, 28px);
  line-height: 1.1;
}

.section-head h2 {
  font-size: 18px;
  line-height: 1.25;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.top-actions,
.row-actions,
.image-actions,
.summary-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  width: 44px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  color: #fff;
  background: var(--primary);
  box-shadow: var(--shadow-soft);
}

.primary {
  color: var(--primary-dark);
  background: var(--yellow);
  box-shadow: 0 8px 18px rgba(226, 189, 0, 0.22);
  font-weight: 850;
}

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

.secondary {
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
}

.secondary:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-soft);
}

.danger {
  min-height: 36px;
  color: #fff;
  background: var(--danger);
}

.danger-outline {
  color: var(--danger);
  background: #fff;
  border: 1px solid rgba(200, 69, 69, 0.24);
  box-shadow: none;
}

.compact {
  min-height: 38px;
  padding: 0 14px;
}

.wide {
  width: 100%;
}

.auth-layout {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 28px 16px;
}

.auth-panel {
  width: min(470px, 100%);
  padding: 24px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(219, 232, 227, 0.92);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  min-height: 46px;
  padding: 4px;
  margin: 18px 0;
  background: var(--surface-3);
  border-radius: 8px;
}

.segmented button {
  min-height: 38px;
  color: var(--muted);
  background: transparent;
}

.segmented button.active {
  color: var(--primary-dark);
  background: #fff;
  box-shadow: 0 5px 14px rgba(0, 62, 115, 0.1);
}

.workspace {
  width: min(680px, 100%);
  margin: 0 auto;
  padding: 14px 14px calc(104px + env(safe-area-inset-bottom));
}

.app-page {
  display: none;
  gap: 14px;
}

.app-page.active {
  display: grid;
}

.summary-band {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: stretch;
}

.summary-control,
.metric,
.panel {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(219, 232, 227, 0.92);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.summary-control {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  min-height: auto;
  padding: 14px;
  overflow: hidden;
}

.summary-control::before {
  content: none;
}

.summary-control label,
.summary-control button {
  position: relative;
}

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

.summary-control label span {
  white-space: nowrap;
}

.summary-control input[type="date"] {
  max-width: 170px;
  text-align: center;
}

.summary-control button {
  justify-self: end;
}

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

.metric {
  position: relative;
  min-height: 106px;
  padding: 16px;
  overflow: hidden;
}

.metric::before {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  top: 0;
  height: 4px;
  border-radius: 0 0 8px 8px;
  background: var(--primary);
}

.metric:nth-child(2)::before {
  background: var(--yellow);
}

.metric:nth-child(3)::before {
  background: var(--green);
}

.metric:nth-child(1)::before {
  background: var(--primary);
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric span {
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: clamp(28px, 3vw, 36px);
  line-height: 1;
  letter-spacing: 0;
}

.metric small {
  margin-top: 8px;
  font-size: 13px;
}

.metric.accent {
  border-color: rgba(232, 121, 77, 0.35);
  background: var(--coral-soft);
}

.metric.accent::before {
  background: var(--coral);
}

.metric.accent strong {
  color: var(--coral);
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.35fr) minmax(300px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.panel {
  padding: 18px;
}

.profile-overview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.avatar-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  color: var(--yellow);
  background: var(--primary);
  border-radius: 999px;
  font-weight: 900;
}

.profile-overview strong,
.profile-overview span {
  display: block;
}

.profile-overview strong {
  font-size: 20px;
}

.profile-overview span {
  margin-top: 3px;
  color: var(--muted);
}

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

.profile-stats span {
  min-height: 66px;
  padding: 10px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.profile-stats strong {
  display: block;
  margin-top: 5px;
  color: var(--text);
}

.profile-actions {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.capture-panel {
  grid-row: span 2;
  border-color: rgba(0, 88, 163, 0.3);
}

.log-panel {
  grid-row: span 2;
}

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

.status-pill,
#imageQualityBadge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border: 1px solid rgba(0, 88, 163, 0.24);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.share-login-hint {
  margin-bottom: 14px;
  padding: 12px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border: 1px solid rgba(0, 88, 163, 0.28);
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
}

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

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

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  max-width: 100%;
  min-height: 44px;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.field-hint {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

input[type="date"],
input[type="datetime-local"] {
  -webkit-appearance: none;
  appearance: none;
  font-size: 16px;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 88, 163, 0.13);
}

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

.image-actions button {
  width: 100%;
}

#demoImageButton,
.image-actions .primary {
  grid-column: 1 / -1;
}

.image-actions .secondary {
  background: var(--surface-2);
}

.preview-box {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 280px;
  overflow: hidden;
  background: #eef3f8;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
}

.preview-box img {
  width: 100%;
  height: 100%;
  max-height: 430px;
  object-fit: contain;
  background: #fff;
}

.dining-mode-panel {
  margin-top: 14px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.dining-mode-switch {
  margin: 0;
}

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

.group-settings > small {
  grid-column: 1 / -1;
  color: var(--muted);
  line-height: 1.45;
}

.empty-preview,
.empty-row {
  color: var(--muted);
}

.empty-preview {
  display: grid;
  place-items: center;
  width: calc(100% - 32px);
  min-height: 180px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  font-weight: 800;
}

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

.analysis-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.analysis-summary strong {
  color: var(--primary-dark);
  font-size: 22px;
}

.analysis-calorie-block {
  display: grid;
  justify-items: center;
  gap: 2px;
}

.analysis-calorie-block small {
  color: var(--muted);
}

.analysis-calorie-block b {
  color: var(--text);
}

.analysis-summary small {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

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

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

.food-item.group-food {
  border-color: rgba(0, 88, 163, 0.28);
}

.food-main,
.food-nutrients {
  display: grid;
  gap: 10px;
}

.food-main {
  grid-template-columns: minmax(130px, 1.4fr) minmax(94px, 0.8fr) minmax(112px, 0.9fr);
}

.food-nutrients {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 10px;
}

.food-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

.food-footer span {
  color: var(--coral);
  font-size: 18px;
  font-weight: 900;
}

.share-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.share-editor .no-eat-button {
  min-height: 44px;
  white-space: nowrap;
}

.share-editor .no-eat-button.active {
  color: var(--danger);
  background: #fff5f5;
  border-color: rgba(200, 69, 69, 0.3);
}

.row-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 12px;
}

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

.macro-row span {
  min-height: 58px;
  padding: 10px;
  color: var(--muted);
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.macro-row span:nth-child(2) {
  background: var(--amber-soft);
}

.macro-row span:nth-child(3) {
  background: var(--sky-soft);
}

.macro-row strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 18px;
}

.record-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.record-item,
.empty-row {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.meal-record-button {
  display: block;
  width: 100%;
  min-height: 0;
  color: inherit;
  text-align: left;
}

.meal-record-button:active {
  transform: none;
}

.empty-state {
  display: grid;
  gap: 6px;
  min-height: 150px;
  place-items: center;
  padding: 22px;
  color: var(--muted);
  text-align: center;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.empty-state strong {
  color: var(--text);
  font-size: 18px;
}

.empty-state small {
  line-height: 1.5;
}

.record-item div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.record-item strong {
  min-width: 0;
}

.record-item span {
  color: var(--coral);
  font-weight: 900;
  white-space: nowrap;
}

.record-item.meal-record span {
  color: var(--sky);
}

.record-item.exercise-record span {
  color: var(--green);
}

.record-item small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
}

.meal-detail-panel {
  display: grid;
  gap: 14px;
}

.meal-detail-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: var(--sky-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.meal-detail-summary span {
  color: var(--muted);
}

.meal-detail-summary strong {
  color: var(--sky);
  font-size: 22px;
}

.meal-detail-foods {
  display: grid;
  gap: 10px;
}

.meal-detail-food {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 116px auto;
  align-items: end;
  gap: 10px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.meal-detail-food strong,
.meal-detail-food small {
  display: block;
}

.meal-detail-food small {
  margin-top: 4px;
  color: var(--muted);
}

.meal-detail-food label {
  display: grid;
  gap: 5px;
}

.meal-detail-food label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.meal-detail-food > span {
  color: var(--sky);
  font-weight: 900;
  white-space: nowrap;
}

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

.sheet-copy {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.share-panel,
.join-gathering-panel {
  display: grid;
  gap: 14px;
}

.join-gathering-panel {
  max-height: min(88vh, 820px);
}

.join-summary {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 12px;
  background: var(--primary-soft);
  border: 1px solid rgba(0, 88, 163, 0.25);
  border-radius: 8px;
}

.join-summary span {
  color: var(--muted);
}

.join-summary strong {
  color: var(--primary-dark);
  font-size: 22px;
}

.join-summary small {
  grid-column: 2;
  color: var(--muted);
  text-align: right;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 50;
  width: min(420px, calc(100vw - 32px));
  min-height: 46px;
  padding: 12px 16px;
  color: #fff;
  background: var(--primary-dark);
  border-radius: 8px;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  width: min(680px, 100%);
  min-height: calc(76px + env(safe-area-inset-bottom));
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.95);
  border-top: 1px solid var(--line);
  box-shadow: 0 -16px 34px rgba(0, 62, 115, 0.1);
  transform: translateX(-50%);
  backdrop-filter: blur(18px);
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  align-items: end;
  padding: 18px 12px calc(18px + env(safe-area-inset-bottom));
  background: rgba(0, 34, 66, 0.3);
}

.sheet-panel {
  width: min(680px, 100%);
  max-height: min(78vh, 720px);
  margin: 0 auto;
  overflow: auto;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 -18px 44px rgba(0, 62, 115, 0.2);
}

.nav-item {
  display: grid;
  place-items: center;
  gap: 3px;
  min-height: 56px;
  padding: 0 4px;
  color: var(--muted);
  background: transparent;
  box-shadow: none;
  font-size: 11px;
  font-weight: 800;
}

.nav-item span {
  font-size: 18px;
  line-height: 1;
}

.nav-item.active {
  color: var(--primary-dark);
}

.nav-camera {
  min-height: 62px;
  color: var(--primary-dark);
  transform: translateY(-16px);
}

.nav-camera:active {
  transform: translateY(-15px);
}

.nav-camera span {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  color: var(--primary-dark);
  background: var(--yellow);
  border: 5px solid #fff;
  border-radius: 999px;
  box-shadow: 0 12px 24px rgba(226, 189, 0, 0.32);
  font-size: 28px;
}

.nav-camera.active span {
  color: var(--yellow);
  background: var(--primary);
}

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

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

  .capture-panel,
  .log-panel {
    grid-row: auto;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    min-height: 72px;
    padding: 14px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .workspace {
    padding: 12px 12px calc(104px + env(safe-area-inset-bottom));
  }

  .metrics-grid {
    gap: 8px;
  }

  .metric {
    min-height: 104px;
    padding: 15px;
  }

  .metric strong {
    font-size: 28px;
  }

  .form-grid,
  .meal-meta,
  .food-main,
  .food-nutrients,
  .group-settings,
  .share-editor {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 14px;
  }

  .preview-box {
    min-height: 228px;
  }

  .analysis-summary,
  .record-item div,
  .meal-detail-summary {
    align-items: stretch;
    flex-direction: column;
  }

  .meal-detail-food {
    grid-template-columns: 1fr;
  }

  .analysis-summary small {
    white-space: normal;
  }

  .analysis-calorie-block {
    justify-items: start;
  }

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

  .row-actions,
  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

@media (max-width: 420px) {
  .top-actions {
    gap: 8px;
  }

  .top-actions .secondary {
    padding: 0 12px;
  }

  .row-actions button {
    flex: 1 1 140px;
  }

}
