:root {
  color-scheme: light dark;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg: #ffffff;
  --surface: #f4f4f5;
  --surface-2: #ececee;
  --text: #111113;
  --text-2: #5c5c63;
  --border: #e2e2e5;
  --border-strong: #c9c9cf;
  --action-bg: #111113;
  --action-text: #ffffff;
  --action-2-bg: #ffffff;
  --action-2-border: #d3d3d8;
  --user-bg: #111113;
  --user-text: #ffffff;
  --danger: #c2231c;
  --danger-bg: #fbeaea;
  --success: #1a7f37;
  --focus: #111113;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --scrim: #000000d9;
  font-family: var(--font-sans);
  font-size: 18px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
}

@supports (font: -apple-system-body) {
  :root { font: -apple-system-body; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #161617;
    --surface-2: #222225;
    --text: #f4f4f5;
    --text-2: #a6a6ad;
    --border: #2b2b2f;
    --border-strong: #3f3f45;
    --action-bg: #ffffff;
    --action-text: #000000;
    --action-2-bg: #000000;
    --action-2-border: #333338;
    --user-bg: #ffffff;
    --user-text: #000000;
    --danger: #f0665c;
    --danger-bg: #2a1313;
    --success: #4ade80;
    --focus: #ffffff;
    --accent: #2563eb;
    --accent-text: #ffffff;
    --scrim: #000000e6;
  }
}

* { box-sizing: border-box; }

body { margin: 0; }

.icon { width: 18px; height: 18px; flex: 0 0 auto; vertical-align: middle; }

button, textarea, input { font: inherit; }

button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 44px;
  padding: 10px 16px;
  background: var(--action-bg);
  color: var(--action-text);
  font-weight: 500;
  cursor: pointer;
}

button.secondary {
  background: var(--action-2-bg);
  color: var(--text);
  border-color: var(--action-2-border);
}

button.destructive {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

button:disabled { cursor: not-allowed; opacity: .5; }

button:active { transform: scale(.98); }

button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

textarea, input[type="date"], input[type="number"], input[type="text"] {
  width: 100%;
  min-height: 44px;
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
}

#app {
  max-width: 720px;
  min-height: 100dvh;
  margin: auto;
  padding: 20px 16px 36px;
}

#app.chat {
  padding: 0;
  width: 100%;
  max-width: 720px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.loading, .muted { color: var(--text-2); }

.status { min-height: 1.3em; margin: 0; color: var(--text-2); }

.top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

#app.chat .chat-top {
  margin: 0;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  flex: 0 0 auto;
}

#app.chat .chat-top h1 { font-size: 1.1rem; font-weight: 500; }

.brand { min-width: 0; }

.brand h1 { margin: 0; }

.chat-date-nav { min-width: 0; }

.build-metadata {
  margin: 2px 0 0;
  display: grid;
  gap: 2px;
  color: var(--text-2);
  font-size: .65rem;
  line-height: 1.2;
}

.build-metadata > div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#app.chat .status { padding: 0 16px; flex: 0 0 auto; }

#app.chat .status:empty { display: none; }

#app.chat .chat-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 16px 8px;
}

#app.chat .scroll-latest-wrap {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  margin: 0 16px 4px;
}

#app.chat .scroll-latest-wrap button { min-height: 36px; padding: 6px 12px; }

#app.chat .chat-compose {
  flex: 0 0 auto;
  display: grid;
  gap: 10px;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}

#app.chat .chat-compose > * { min-width: 0; }

#app.chat .chat-compose .row { justify-content: flex-end; }

.profile-button {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--action-2-bg);
  color: var(--text);
  border: 1px solid var(--action-2-border);
}

.profile-button .icon { width: 22px; height: 22px; }

.menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 2;
  display: grid;
  gap: 2px;
  min-width: 220px;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px #00000030;
}

.menu button {
  text-align: left;
  white-space: nowrap;
  border: 0;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
}

.menu button:hover { background: var(--surface); }

.menu button[aria-current="page"] { background: var(--surface); }

.menu button.menu-sign-out { color: var(--danger); }

.question-inline {
  display: grid;
  gap: 8px;
  width: min(100%, 520px);
  padding: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface);
}

.question-active { box-shadow: 0 6px 18px #00000018; }

.question-answered { border-style: dashed; }

.question-text, .question-state { margin: 0; }

.question-text { font-weight: 500; }

.question-state { color: var(--text-2); font-size: .85rem; }

.question-options { display: flex; flex-wrap: wrap; gap: 8px; }

.question-pill { min-height: 40px; }

.consent-scrim {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--scrim);
}

.photo-consent-dialog {
  width: min(100%, 460px);
  padding: 20px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--bg);
  box-shadow: 0 16px 40px #00000050;
}

.photo-consent-dialog h2 { margin: 0 0 10px; font-size: 1.15rem; }

.photo-consent-dialog p { margin: 0 0 18px; color: var(--text-2); line-height: 1.5; }

.photo-consent-dialog .row { justify-content: flex-end; }

.composer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: var(--bg);
}

.composer-paused { border-style: dashed; opacity: .72; }

.composer-row :disabled { cursor: not-allowed; }

.composer-row textarea {
  flex: 1 1 auto;
  min-width: 0;
  height: 36px;
  min-height: 36px;
  max-height: 56px;
  padding: 6px 4px;
  line-height: 20px;
  border: 0;
  border-radius: 0;
  resize: none;
  overflow-y: hidden;
  background: transparent;
}

.composer-row textarea:focus-visible { outline: 0; }

.composer-action {
  flex: 0 0 36px;
  width: 36px;
  min-height: 36px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--text-2);
  line-height: 1;
}

.composer-action .icon { width: 20px; height: 20px; }

.composer-action:hover { background: var(--surface); }

.composer-send {
  display: none;
  background: var(--action-bg);
  color: var(--action-text);
}

.composer-send .icon { color: var(--action-text); }

.composer-row:has(#chat-text:not(:placeholder-shown)) .composer-send,
.chat-compose:has(.attachment-preview) .composer-send { display: grid; }

.voice-status { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--text-2); }

.attachment-menu { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0; }

.attachment-menu button { min-height: 44px; }

.attachment-preview {
  display: flex;
  gap: 8px;
  padding: 8px;
}

.attachment-thumbnail { position: relative; width: 64px; height: 64px; flex: 0 0 64px; }

.attachment-thumbnail img { width: 64px; height: 64px; display: block; object-fit: cover; border-radius: 8px; }

.attachment-remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
}

.attachment-remove:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.upload-status { margin: 0; color: var(--text-2); font-size: .9rem; }

.upload-status button { margin-left: 8px; min-height: 34px; padding: 6px 10px; }

h1 { margin: 0; font-size: 1.25rem; font-weight: 500; }

h2, h3, h4 { margin: 0 0 10px; font-weight: 500; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin: 12px 0;
}

.chat-surface {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  margin: 0;
}

.daily-status {
  flex: 0 0 auto;
  padding: 0 0 12px;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 0;
}

.day-nav {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
}

.date-label {
  min-width: 0;
  padding: 0;
  background: transparent;
  border-color: transparent;
  color: var(--text);
  text-align: left;
  white-space: nowrap;
}

.date-primary { font-size: 1rem; font-weight: 500; }

.date-secondary { color: var(--text-2); font-size: .85rem; }

.daily-status > #back-to-today { margin: 8px 0 0; }

.calorie-progress {
  width: 100%;
  height: 8px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.calorie-progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 999px; }
.calorie-progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
.calorie-progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

.coaching-empty { padding: 24px 0 8px; text-align: center; }

.coaching-empty h2 { font-size: 1.05rem; font-weight: 500; margin: 0 0 8px; }

.coaching-empty p { margin: 0 0 16px; }

.coaching-empty .row { justify-content: center; }

.confirmation { color: var(--success); }

.error {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

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

.messages { display: grid; gap: 16px; margin: 16px 0; }

.message { padding: 0; white-space: pre-wrap; }

.markdown-table-wrap {
  max-width: 100%;
  margin: 12px 0;
  overflow-x: auto;
}

.markdown-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  white-space: normal;
}

.markdown-table-wrap th,
.markdown-table-wrap td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.markdown-table-wrap th { color: var(--text-2); font-weight: 500; }

.message.user {
  background: var(--user-bg);
  color: var(--user-text);
  padding: 10px 14px;
  border-radius: 14px;
  margin-left: 12%;
}

.tool-activity {
  margin: 8px 0 0;
  padding-left: 12px;
  border-left: 2px solid var(--border-strong);
  color: var(--text-2);
  font-size: .85rem;
}

.tool-activity-live { border-left-color: var(--accent); }

.tool-activity-outcome {
  margin: 8px 0 0;
  color: var(--text-2);
  font-size: .85rem;
}

.tool-activity ol {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 20px;
}

.tool-activity-item.failed { color: var(--danger); }

.tool-activity-status { font-weight: 600; }

.meal-list { display: grid; gap: 10px; margin: 16px 0; }

.meal-empty { margin: 16px 0; }

.meal-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}

.meal-card h4 { font-size: 1.05rem; }

.historical-meal-card { margin: 0; }

.historical-meal-card h3 { margin: 0; font-size: 1.05rem; }

.meal-category { margin: 0 0 4px; color: var(--text-2); font-size: .82rem; font-weight: 600; }

.meal-macros { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; margin: 12px 0; }

.meal-macros div, .profile-details div, .telemetry-details div {
  padding: 8px;
  border-radius: 8px;
  background: var(--surface-2);
}

dt { color: var(--text-2); font-size: .8rem; }

dd { margin: 3px 0 0; font-weight: 500; word-break: break-word; }

.profile-panel { margin: 16px 0; }

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

.entry { border-top: 1px solid var(--border); padding: 10px 0; display: flex; justify-content: space-between; gap: 12px; }

.badge { padding: 3px 8px; border-radius: 999px; background: var(--danger-bg); color: var(--danger); font-size: .82rem; font-weight: 500; }

pre {
  overflow: auto;
  white-space: pre-wrap;
  font-size: .82rem;
  background: var(--surface);
  padding: 10px;
  border-radius: 10px;
}

.transcript { margin: 14px 0 2px; }

.transcript summary { cursor: pointer; font-weight: 500; color: var(--text-2); }

.transcript-body { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 10px; }

.transcript-line { margin: 0 0 12px; white-space: pre-wrap; }

.transcript-steps { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 10px; }

.transcript-step { background: var(--surface); border-radius: 10px; padding: 10px; }

.transcript-step .row { justify-content: space-between; margin-bottom: 8px; }

.transcript-json { margin: 6px 0 0; background: var(--surface); }

.saved-meal-editor { background: var(--surface); }

.saved-meal-editor form { display: grid; gap: 12px; }

.saved-meal-editor label { display: grid; gap: 6px; font-weight: 500; }

.saved-meal-components { margin: 8px 0 14px; padding-left: 20px; color: var(--text); }

.saved-meal-card h3 { margin: 0; }

.saved-meal-card .row:first-child { justify-content: space-between; }

.spacer { flex: 1 1 auto; }

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

.pending-status { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: .82rem; white-space: nowrap; }

.failed-message { border: 1px solid var(--danger); }

.failed-message .secondary { min-height: 32px; padding: 4px 8px; }

.pending-spinner { width: 14px; height: 14px; border: 2px solid var(--text-2); border-top-color: transparent; border-radius: 50%; animation: pending-spin .8s linear infinite; }

@keyframes pending-spin { to { transform: rotate(360deg); } }

.history-image {
  display: block;
  width: min(100%, 280px);
  min-height: 0;
  margin: 0 0 8px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  background: transparent;
}

.history-image img { display: block; width: 100%; max-height: 280px; object-fit: cover; }

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  gap: 12px;
  padding: 24px;
  background: var(--scrim);
}

.image-viewer img { max-width: min(100%, 900px); max-height: calc(100dvh - 100px); object-fit: contain; border-radius: 12px; }

.image-viewer button { justify-self: end; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 480px) {
  .meal-macros, .profile-details, .telemetry-details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #app.chat .chat-top { padding: calc(10px + env(safe-area-inset-top)) 12px 8px; gap: 8px; }
  #app.chat .chat-top h1 { font-size: 1.05rem; }
  #app.chat .chat-scroll { padding: 0 12px 6px; }
  #app.chat .chat-compose { gap: 8px; padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
  #app.chat .composer-row textarea { min-height: 36px; }
  .chat-surface { padding: 0; margin: 0; }
  .messages { margin: 12px 0; }
}

@media (max-width: 330px) {
  .meal-macros, .profile-details, .telemetry-details { grid-template-columns: 1fr; }
}
