:root {
  --cream: #fff7ed;
  --sand: #fef0e2;
  --card: #ffffff;
  --ink: #1a0f08;
  --ink-soft: #3a261a;
  --muted: rgba(26, 15, 8, 0.55);
  --border: rgba(26, 15, 8, 0.12);
  --mango: #ff6b1a;
  --mango-700: #ea580c;
  --mango-50: #ffedd5;
  --leaf: #1d8a52;
  --danger: #dc2626;

  --radius-card: 24px;
  --radius-chip: 12px;
  --shadow-card: 0 18px 40px -20px rgba(26, 15, 8, 0.22);
  --shadow-hard: 4px 4px 0 var(--ink);

  --font-display: "Unbounded", ui-sans-serif, system-ui, sans-serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-hand: "Caveat", cursive;

  --header-h: 64px;
  --tabbar-h: 62px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior-y: none;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--cream);
  position: relative;
}

.header {
  flex: 0 0 auto;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 3px;
  background: var(--ink);
  color: var(--cream);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.04em;
}

.header-target {
  font-family: var(--font-hand);
  font-size: 17px;
  font-weight: 700;
  color: var(--mango);
}

.content {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fade 0.18s ease;
}

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.view-title {
  margin: 2px 0 16px;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: -0.01em;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
}

.card-head {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink);
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.field > span {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.field-row {
  display: flex;
  gap: 12px;
}

input, select, textarea {
  width: 100%;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  padding: 13px 14px;
  outline: none;
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--mango);
  background: #fff;
  box-shadow: 0 0 0 3px var(--mango-50);
}

.btn {
  width: 100%;
  min-height: 50px;
  border: none;
  border-radius: 9999px;
  background: var(--mango);
  color: var(--cream);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.btn:active {
  background: var(--mango-700);
  transform: translateY(1px);
}

.hint {
  color: var(--muted);
  font-size: 14px;
}

.hidden {
  display: none !important;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  font-size: 14px;
}

.list-item .meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.list-item .del {
  border: none;
  background: transparent;
  color: var(--danger);
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
}

.totals {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: var(--mango-700);
}

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

.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px;
  box-shadow: var(--shadow-card);
}

.stat .label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.stat .value {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: -0.02em;
}

.stat .unit {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 3px;
}

.stat.accent {
  background: var(--mango);
  border-color: var(--mango);
  color: var(--cream);
  box-shadow: var(--shadow-hard);
}

.stat.accent .label,
.stat.accent .unit {
  color: rgba(255, 247, 237, 0.9);
}

.macros {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  text-align: center;
}

.macros .m-cell {
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  padding: 14px 6px;
}

.macros .m-cell .v {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
}

.macros .m-cell .l {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-top: 2px;
}

.chart {
  width: 100%;
  height: 160px;
}

.chart svg {
  width: 100%;
  height: 100%;
}

.chart-legend {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.legend-item::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.legend-weight::before { background: var(--mango); }
.legend-waist::before { background: var(--leaf); }

.cal {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cal-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  text-transform: capitalize;
}

.cal-nav {
  display: flex;
  gap: 8px;
}

.cal-nav button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--cream);
  border-radius: 9999px;
  font-size: 18px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
}

.cal-nav button:active {
  background: var(--mango-50);
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-weekday {
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding-bottom: 2px;
}

.cal-day {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 12px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.cal-day.other-month {
  color: rgba(26, 15, 8, 0.25);
}

.cal-day.today {
  border: 1.5px solid var(--mango);
}

.cal-day.selected {
  background: var(--ink);
  color: var(--cream);
}

.cal-day.has-entry::after {
  content: "";
  position: absolute;
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--mango);
}

.cal-day.selected.has-entry::after {
  background: var(--cream);
}

.journal-entry {
  flex-direction: column;
  align-items: stretch;
}

.journal-entry .row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.journal-entry .text {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 12px;
}

.bubble {
  max-width: 85%;
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: var(--mango);
  color: var(--cream);
  border-bottom-right-radius: 5px;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-card);
}

.bubble.typing {
  color: var(--muted);
  font-style: italic;
}

.chat-input {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding-top: 8px;
  background: var(--cream);
}

.chat-input textarea {
  resize: none;
  max-height: 120px;
  border-radius: 22px;
}

.btn-send {
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 50%;
  background: var(--mango);
  color: var(--cream);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-send svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--cream);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tabbar {
  flex: 0 0 auto;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  z-index: 10;
}

.tab {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0;
}

.tab span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab.active {
  color: var(--mango);
}

.food-ai {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  border: 1.5px solid var(--ink);
  border-radius: 9999px;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
}

.btn-secondary:active {
  background: var(--mango-50);
}

.btn-secondary:disabled {
  opacity: 0.6;
}

.btn-secondary svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ai-note {
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 4px;
}

.ai-head {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 4px;
}

.suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.suggestion {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  background: var(--mango-50);
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
}

.suggestion .meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.suggestion .kcal {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--mango-700);
  white-space: nowrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--cream);
  padding: 11px 20px;
  border-radius: 9999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  box-shadow: var(--shadow-hard);
}

.toast.show {
  opacity: 1;
}
