:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --panel: #ffffff;
  --text: #1d241f;
  --muted: #687268;
  --border: #dce4dc;
  --accent: #2e6f57;
  --accent-strong: #194c3c;
  --accent-soft: #e5f1eb;
  --warn: #a15f18;
  --shadow: 0 18px 42px rgba(31, 49, 39, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(229, 241, 235, 0.9), rgba(245, 247, 244, 0) 320px),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 760;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1;
}

h2 {
  font-size: 22px;
}

.actions {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.date-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(46, 111, 87, 0.15);
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  padding: 0 16px;
  font-weight: 760;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

button.secondary:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary article {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.summary span,
.summary small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

.summary strong {
  display: block;
  margin-top: 8px;
  font-size: 34px;
  line-height: 1;
}

.summary small {
  margin-top: 4px;
}

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

.meal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.meal-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.meal-card h3 {
  margin: 0;
  font-size: 20px;
}

.meal-card .count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 10px;
  align-items: end;
}

.portion-field {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.meal-detail {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.meal-title {
  margin: 0 0 10px;
  font-weight: 780;
}

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

.macros.compact {
  margin-top: 12px;
}

.macros div {
  min-height: 64px;
  border-radius: 8px;
  background: var(--accent-soft);
  padding: 10px;
}

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

.macros strong {
  display: block;
  margin-top: 5px;
  font-size: 18px;
}

.ingredients {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ingredients li {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--muted);
  font-size: 12px;
}

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

.manual-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.manual-grid label:first-child {
  grid-column: 1 / -1;
}

.empty {
  margin: 14px 0 0;
  color: var(--muted);
}

.catalog {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-top: 20px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.catalog p:last-child {
  margin: 0;
  color: var(--muted);
  text-align: right;
}

.catalog-manager {
  margin-top: 14px;
}

.catalog-manager-head,
.meal-editor,
.catalog-period {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.catalog-manager-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px;
}

.meal-editor {
  margin-top: 12px;
  padding: 18px;
}

.meal-editor header,
.catalog-period header,
.catalog-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.meal-editor h3,
.catalog-period h3 {
  margin: 0;
}

.meal-editor-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.meal-editor-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.meal-editor-grid label:nth-child(2) {
  grid-column: span 2;
}

.editor-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

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

.catalog-period {
  padding: 16px;
}

.catalog-period header span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.catalog-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.catalog-row {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.catalog-row div {
  min-width: 0;
}

.catalog-row strong,
.catalog-row span {
  display: block;
}

.catalog-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.catalog-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(16px);
  max-width: min(520px, calc(100% - 32px));
  border-radius: 8px;
  background: #1d241f;
  color: white;
  padding: 12px 14px;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 840px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    justify-content: stretch;
  }

  .date-field,
  .actions button {
    flex: 1;
  }

  .summary,
  .planner,
  .catalog-periods {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 560px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

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

  .summary article,
  .meal-card,
  .catalog {
    padding: 14px;
  }

  .controls {
    grid-template-columns: 1fr;
  }

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

  .manual-grid {
    grid-template-columns: 1fr;
  }

  .catalog {
    align-items: flex-start;
    flex-direction: column;
  }

  .catalog-manager-head,
  .meal-editor header,
  .catalog-row {
    align-items: stretch;
    flex-direction: column;
  }

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

  .meal-editor-grid label:nth-child(2) {
    grid-column: auto;
  }

  .editor-actions {
    flex-direction: column;
  }

  .catalog p:last-child {
    text-align: left;
  }
}
