:root {
  --mint-canvas: #edf4ef;
  --mint-cloud: #d9ebe2;
  --reef-50: #f2faf7;
  --reef-100: #e4f4ee;
  --reef-200: #cde8de;
  --reef-600: #1f7a64;
  --reef-700: #185f4e;
  --coral-500: #ef8b5f;
  --ink-900: #182826;
  --ink-700: #3d5450;
  --ink-500: #6a817c;
  --border-soft: rgba(32, 88, 74, 0.16);
  --border-strong: rgba(23, 77, 64, 0.28);
  --surface-0: #f7fbf9;
  --surface-1: #ffffff;
  --surface-2: #f4faf7;
  --surface-3: #eef7f3;
  --shadow-soft: 0 18px 44px rgba(24, 76, 63, 0.1);
  --shadow-card: 0 8px 20px rgba(20, 58, 49, 0.08);
  --success: #19714a;
  --warning: #9b620e;
  --danger: #9d2635;
  --info: #2d5a5e;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", "Segoe UI", sans-serif;
  color: var(--ink-900);
  background:
    radial-gradient(circle at 12% 5%, var(--mint-cloud) 0%, transparent 28%),
    radial-gradient(circle at 86% 8%, #dbe8f5 0%, transparent 22%),
    linear-gradient(140deg, var(--mint-canvas) 0%, #f6faf8 65%);
  min-height: 100vh;
}

.app-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 16px 36px;
}

.topbar {
  border: 1px solid rgba(255, 255, 255, 0.55);
  background:
    linear-gradient(160deg, rgba(23, 110, 90, 0.95), rgba(22, 80, 105, 0.92)),
    radial-gradient(circle at 10% 0%, rgba(255, 255, 255, 0.18), transparent 38%);
  color: #f9fffc;
  border-radius: 28px;
  padding: 20px;
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: visible;
  isolation: isolate;
}

.topbar::after {
  content: "";
  position: absolute;
  inset: -20% auto auto 65%;
  width: 260px;
  height: 260px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.2), transparent 62%);
  pointer-events: none;
  z-index: 0;
}

.topbar > * {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.78;
}

.topbar-title h1 {
  margin: 0;
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: clamp(30px, 4vw, 42px);
  line-height: 1.05;
  letter-spacing: 0.01em;
}

.topbar-title p {
  margin: 8px 0 14px;
  font-size: 14px;
  opacity: 0.92;
}

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

.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: end;
}

.controls-surface {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: var(--radius-md);
  padding: 10px;
}

.controls label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: rgba(247, 255, 252, 0.92);
}

.field-with-help {
  position: relative;
  min-width: 220px;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.help-trigger,
.help-close {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  box-shadow: none;
}

.help-trigger {
  color: #f7fffc;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.36);
}

.help-trigger:hover,
.help-trigger:focus-visible {
  transform: none;
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.56);
}

.field-help-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(360px, calc(100vw - 48px));
  padding: 14px 14px 12px;
  border-radius: 16px;
  border: 1px solid rgba(24, 71, 60, 0.16);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(243, 249, 246, 0.98)),
    radial-gradient(circle at 100% 0%, rgba(31, 122, 100, 0.08), transparent 36%);
  color: var(--ink-900);
  box-shadow: 0 18px 40px rgba(17, 56, 47, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 150ms ease, transform 150ms ease;
  z-index: 30;
}

.field-with-help:focus-within .field-help-popover,
.field-with-help.is-hovered .field-help-popover,
.field-with-help.is-open .field-help-popover {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.field-with-help.is-hovered.is-suppressed .field-help-popover {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
}

.field-help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.field-help-header strong {
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.15;
  color: #1e4f45;
}

.help-close {
  color: var(--reef-700);
  background: rgba(31, 122, 100, 0.08);
  border: 1px solid rgba(31, 122, 100, 0.14);
}

.help-close:hover,
.help-close:focus-visible {
  transform: none;
  filter: none;
  background: rgba(31, 122, 100, 0.16);
}

.field-help-popover p {
  margin: 0 0 10px;
  color: var(--ink-700);
  font-size: 13px;
  line-height: 1.55;
}

.field-help-popover ol {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink-700);
}

.field-help-popover code {
  padding: 1px 5px;
  border-radius: 999px;
  border: 1px solid rgba(31, 122, 100, 0.14);
  background: rgba(31, 122, 100, 0.08);
  color: #205346;
  font-size: 11px;
  font-weight: 700;
}

input,
select,
button {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  font-size: 13px;
  font-family: inherit;
  padding: 9px 12px;
}

input,
select {
  min-width: 180px;
  color: var(--ink-900);
  background: #fff;
}

button {
  cursor: pointer;
  color: #fff;
  border-color: transparent;
  font-weight: 600;
  background: linear-gradient(130deg, var(--reef-600), #1f6e8f);
  transition: transform 120ms ease, filter 140ms ease, box-shadow 140ms ease;
  box-shadow: 0 8px 18px rgba(16, 72, 60, 0.22);
}

button:hover {
  transform: translateY(-1px);
  filter: saturate(1.06);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button.ghost {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.38);
  box-shadow: none;
}

.presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

main {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.panel {
  border: 1px solid var(--border-soft);
  background: linear-gradient(180deg, var(--surface-1), var(--surface-0));
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-card);
}

.panel h2 {
  margin: 0 0 12px;
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: 24px;
  font-weight: 600;
  color: #204e45;
}

.panel-summary {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 253, 250, 0.98)),
    radial-gradient(circle at 92% 8%, rgba(239, 139, 95, 0.1), transparent 24%);
}

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

.card {
  border: 1px solid var(--border-soft);
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 12px;
  line-height: 1.45;
}

.stat-card {
  min-height: 98px;
  display: block;
  color: #244c44;
  background:
    linear-gradient(180deg, #f8fcfa, var(--surface-2)),
    radial-gradient(circle at 100% 0%, rgba(31, 122, 100, 0.08), transparent 35%);
}

.stat-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #2d5b52;
}

.stat-label {
  margin-top: 6px;
  font-size: 12px;
  color: #5d7872;
}

.stat-value {
  margin-top: 3px;
  font-size: 30px;
  line-height: 1.05;
  font-weight: 800;
  color: #183f38;
}

.stat-value span {
  font-size: 14px;
  font-weight: 700;
  color: #456761;
  margin-left: 4px;
}

.stat-subline {
  margin-top: 8px;
  color: #5a756f;
  font-size: 12px;
}

.recommendations {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 14px;
  background: linear-gradient(180deg, #f9fdfb, #f2f8f5);
  color: var(--ink-700);
  line-height: 1.6;
}

.macro-line {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.macro-pill {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  border-radius: 999px;
  padding: 3px 8px;
  border: 1px solid var(--border-soft);
  background: #fff;
}

.macro-pill.protein {
  background: #e6f3ed;
}

.macro-pill.carbs {
  background: #e8f0fb;
}

.macro-pill.fat {
  background: #f9ecd9;
}

.chat-panel {
  background:
    linear-gradient(180deg, #ffffff, #f7fcfa),
    radial-gradient(circle at 90% 0%, rgba(49, 140, 168, 0.08), transparent 30%);
}

.chat-messages {
  border: 1px solid var(--border-soft);
  background: #f9fcfb;
  border-radius: var(--radius-md);
  min-height: 220px;
  max-height: 360px;
  overflow: auto;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.chat-empty {
  color: var(--ink-500);
  font-size: 13px;
}

.chat-msg {
  max-width: 82%;
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid var(--border-soft);
  white-space: pre-wrap;
}

.chat-msg.user {
  justify-self: end;
  background: linear-gradient(180deg, #dff2ea, #d6ede4);
}

.chat-msg.assistant {
  justify-self: start;
  background: #ffffff;
}

.chat-msg.typing {
  color: var(--ink-500);
  font-style: italic;
}

.chat-input-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  margin-top: 10px;
}

.chat-compose-label {
  margin-top: 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #2f5b53;
}

.chat-input-row input {
  min-width: 0;
  min-height: 44px;
  border: 2px solid rgba(31, 122, 100, 0.45);
  background: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 0 0 3px rgba(31, 122, 100, 0.08);
}

.chat-input-row input:focus {
  outline: none;
  border-color: rgba(31, 122, 100, 0.8);
  box-shadow: 0 0 0 4px rgba(31, 122, 100, 0.18);
}

#chatSendBtn {
  min-height: 44px;
  font-weight: 700;
}

#chatClearBtn {
  min-height: 44px;
}

.two-col {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(270px, 0.92fr) minmax(420px, 1.08fr);
}

.skeleton {
  position: relative;
  overflow: hidden;
  color: transparent !important;
  user-select: none;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    rgba(220, 233, 228, 0.5) 20%,
    rgba(244, 251, 248, 0.9) 45%,
    rgba(220, 233, 228, 0.5) 70%
  );
  transform: translateX(-100%);
  animation: shimmer 1.3s infinite;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
  max-height: 560px;
  overflow: auto;
}

.list li {
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 11px;
  background: linear-gradient(180deg, #fafdfe, #f2f8f5);
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.list li:hover {
  border-color: rgba(31, 122, 100, 0.45);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(20, 58, 49, 0.1);
}

.list li.active {
  border-color: rgba(31, 122, 100, 0.66);
  box-shadow: 0 10px 24px rgba(20, 58, 49, 0.14);
  background: linear-gradient(180deg, var(--reef-50), var(--reef-100));
}

#mealDetail {
  color: var(--ink-700);
}

.item-row {
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 11px;
  margin-bottom: 9px;
  background: #fff;
}

.item-row-edit {
  background: var(--surface-3);
}

.item-meta {
  color: var(--ink-500);
  font-size: 12px;
  margin-top: 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  margin-left: 6px;
  border: 1px solid var(--border-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.chip-main {
  background: #dff2ea;
}

.chip-beverage {
  background: #deebf8;
}

.chip-snack {
  background: #f9e8d6;
}

.item-actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 9px;
}

.item-actions button {
  padding: 7px 10px;
  font-size: 12px;
}

.item-edit-grid {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.item-edit-grid label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--ink-700);
  font-weight: 600;
}

.item-edit-grid input,
.item-edit-grid select {
  min-width: 0;
  width: 100%;
}

pre {
  white-space: pre-wrap;
  margin: 0;
  color: var(--ink-700);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 12px;
}

#toastHost {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  z-index: 2000;
}

.toast {
  color: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}

.toast-info {
  background: var(--info);
}

.toast-success {
  background: var(--success);
}

.toast-warn {
  background: var(--warning);
}

.toast-error {
  background: var(--danger);
}

.toast.fade-out {
  opacity: 0;
  transition: opacity 0.2s ease;
}

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

@media (max-width: 760px) {
  .app-shell {
    padding: 12px 10px 24px;
  }
  .topbar {
    border-radius: 20px;
    padding: 14px;
  }
  .grid {
    grid-template-columns: 1fr;
  }
  .item-edit-grid {
    grid-template-columns: 1fr;
  }
  .chat-input-row {
    grid-template-columns: 1fr;
  }
  input,
  select {
    min-width: 145px;
  }
  .field-help-popover {
    left: 0;
    right: auto;
    width: min(100%, calc(100vw - 36px));
  }
}
