:root {
  --primary: #35b57e;
  --primary-dark: #2a9668;
  --primary-light: #5fd6a0;
  --accent: #ff9466;
  --danger: #f5595e;
  --warning: #f5b24a;
  --bg: #0f1512;
  --card-bg: #182019;
  --surface: #1f2a22;
  --surface-hover: #26332a;
  --input-bg: #141b16;
  --text: #eaf2ec;
  --muted: #8ba39a;
  --border: #2a362d;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  font-family: 'Inter', 'Segoe UI', Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation; /* отключает зум двойным тапом; pinch-zoom блокируется viewport-мета выше */
  color-scheme: dark;
}

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(53, 181, 126, 0.14), transparent),
    radial-gradient(900px 500px at -10% 10%, rgba(255, 148, 102, 0.09), transparent),
    var(--bg);
  color: var(--text);
  padding-bottom: 48px;
  min-height: 100vh;
}

/* ---------- Header ---------- */

.app-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white;
  padding: 18px 24px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-md);
}

.app-header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
  padding-right: 40px; /* место под кнопку выхода в правом верхнем углу */
}

.app-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-icon { font-size: 1.4rem; }

.date-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.16);
  padding: 6px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}

.date-picker input[type="date"] {
  padding: 6px 8px;
  border-radius: 999px;
  border: none;
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--input-bg);
  color-scheme: dark;
}

.date-nav-btn {
  background: rgba(255, 255, 255, 0.25);
  border: none;
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.date-nav-btn:hover { background: rgba(255, 255, 255, 0.4); }

.logout-btn {
  position: absolute;
  top: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  flex-shrink: 0;
}
.logout-btn:hover { background: rgba(229, 72, 77, 0.55); }

.btn.ghost {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}
.btn.ghost:hover { background: rgba(255, 255, 255, 0.32); }
.btn.small { padding: 6px 12px; font-size: 0.8rem; border-radius: 999px; }

/* ---------- Layout ---------- */

.people-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 20px;
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  margin: 0 auto 24px;
  max-width: 1156px;
}

/* ---------- Person card ---------- */

.person-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.person-card:hover { box-shadow: var(--shadow-lg); }

.person-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.person-card-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.person-actions { display: flex; gap: 2px; }
.person-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 6px;
  border-radius: 8px;
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease;
}
.person-actions button[data-action="edit-macro-goals"] {
  font-size: 0.64rem;
  font-weight: 700;
}
.person-actions button:hover { color: var(--primary-dark); background: var(--surface-hover); }

.calorie-summary {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 14px 0;
}

.calorie-ring {
  width: 92px;
  height: 92px;
  min-width: 92px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  text-align: center;
  background: conic-gradient(var(--ring-color, var(--primary)) var(--pct, 0%), var(--surface) 0);
  position: relative;
  transition: background 0.3s ease;
}
.calorie-ring::before {
  content: "";
  position: absolute;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: var(--card-bg);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}
.calorie-ring span { position: relative; z-index: 1; }

.calorie-details { flex: 1; min-width: 0; }
.calorie-details p { margin: 3px 0; font-size: 0.88rem; }
.calorie-details .remaining { font-size: 1.15rem; font-weight: 800; color: var(--primary-dark); }
.calorie-details .over { font-size: 1.15rem; font-weight: 800; color: var(--danger); }
.calorie-details .goal-source { color: var(--muted); font-size: 0.76rem; }
.calorie-details .goal-deficit {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 2px;
}

.macro-bar {
  display: flex;
  gap: 10px;
  margin: 12px 0;
  flex-wrap: wrap;
}
.macro-chip {
  flex: 1;
  min-width: 70px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  text-align: center;
}
.macro-chip .macro-label { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.macro-chip .macro-value { font-size: 1rem; font-weight: 700; display: block; margin-top: 2px; }
.macro-progress {
  display: block;
  height: 4px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--input-bg);
}
.macro-progress span {
  display: block;
  width: var(--macro-progress);
  height: 100%;
  border-radius: inherit;
  background: currentColor;
}
.macro-chip.protein .macro-value { color: #2f6fed; }
.macro-chip.fat .macro-value { color: #f5a524; }
.macro-chip.carbs .macro-value { color: #ff6b6b; }
.macro-chip.protein .macro-progress { color: #2f6fed; }
.macro-chip.fat .macro-progress { color: #f5a524; }
.macro-chip.carbs .macro-progress { color: #ff6b6b; }

.weight-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px 8px;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 2px 0 4px;
  cursor: pointer;
  transition: color 0.15s ease;
}
.weight-info:hover { color: var(--primary-dark); }

.meals-section { margin-top: 14px; }

.meal-type-block {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 10px;
}

.meal-type-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.meal-type-header h4 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
}

.meal-type-header .add-meal-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(47, 158, 110, 0.35);
  transition: transform 0.12s ease, background 0.15s ease;
}
.meal-type-header .add-meal-btn:hover { background: var(--primary-dark); transform: scale(1.08); }

.meal-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}

.meal-item .meal-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.meal-item .meal-macros {
  font-size: 0.72rem;
  color: var(--muted);
  display: block;
  margin-top: 1px;
}
.meal-item .meal-kcal { color: var(--muted); white-space: nowrap; font-weight: 600; }
.meal-item .remove-meal {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 4px;
  border-radius: 6px;
}
.meal-item .remove-meal:hover { background: rgba(245, 89, 94, 0.15); }

.meal-type-total { font-size: 0.78rem; color: var(--muted); text-align: right; margin-top: 4px; }

/* ---------- Buttons ---------- */

.btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: scale(0.97); }
.btn.secondary { background: var(--surface); color: var(--text); }
.btn.secondary:hover { background: var(--surface-hover); }

.add-person-section { text-align: center; margin: 4px 0 24px; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.inline-form input {
  flex: 1;
  min-width: 110px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 16px;
  background: var(--input-bg);
}
.inline-form input:focus { outline: none; border-color: var(--primary-light); background: var(--input-bg); }

/* ---------- Products ---------- */

.products-section h2 { margin-top: 0; }

#product-search {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-family: inherit;
  font-size: 16px;
  background: var(--input-bg);
}
#product-search:focus { outline: none; border-color: var(--primary-light); background: var(--input-bg); }

.hint-text { color: var(--muted); font-size: 0.82rem; margin: -4px 0 12px; }

.products-list {
  max-height: 280px;
  overflow-y: auto;
}

.product-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.product-row .product-macros { color: var(--muted); font-size: 0.76rem; }
.product-row .bju-missing { color: var(--warning); font-style: italic; }
.product-row-actions { display: flex; gap: 2px; flex-shrink: 0; }
.product-row-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 6px;
  border-radius: 8px;
}
.product-row-actions button:hover { background: var(--surface-hover); }
.product-row-actions button[data-del-product] { color: var(--danger); }

/* ---------- Dialogs ---------- */

dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 460px;
  width: 90%;
  max-height: 86vh;
  box-shadow: var(--shadow-lg);
  font-family: inherit;
  color: var(--text);
  overflow: hidden;
}
dialog[open] {
  display: flex;
  flex-direction: column;
}
dialog::backdrop { background: rgba(15, 30, 25, 0.45); backdrop-filter: blur(2px); }

dialog form, .weight-modal-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 20px 24px 12px;
  flex-shrink: 0;
}
.dialog-header h3 { margin: 0; color: var(--text); font-weight: 800; font-size: 1.15rem; }
.dialog-close-btn {
  background: var(--surface);
  border: none;
  color: var(--muted);
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.dialog-close-btn:hover { background: var(--surface-hover); color: var(--text); }

.dialog-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

dialog h4 { margin: 10px 0 2px; font-size: 0.95rem; color: var(--text); }
dialog label { font-size: 0.82rem; color: var(--muted); display: flex; flex-direction: column; gap: 5px; font-weight: 500; }
dialog input, dialog select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px; /* >=16px не даёт iOS Safari автоматически зумить при фокусе на поле */
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
}
dialog input:focus, dialog select:focus { outline: none; border-color: var(--primary-light); background: var(--input-bg); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--card-bg);
}
.meal-total-preview { margin: 0; font-size: 0.98rem; color: var(--primary-dark); font-weight: 600; }

.danger-zone {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  text-align: center;
}
.danger-link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 8px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.danger-link-btn:hover { color: var(--danger); }

.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 4px;
  max-height: 180px;
  overflow-y: auto;
  z-index: 10;
  display: none;
  box-shadow: var(--shadow-md);
}
.autocomplete-list.show { display: block; }
.autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
}
.autocomplete-item:hover { background: var(--surface-hover); }

.weight-chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
}

#weight-form {
  display: flex;
  flex: 0 0 auto;
  flex-direction: row;
  min-height: auto;
  margin-bottom: 2px;
}
#weight-goal-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(100px, 0.75fr) auto;
  align-items: end;
  gap: 10px;
  flex: 0 0 auto;
  min-height: auto;
}
#weight-goal-form label {
  white-space: nowrap;
}
#weight-goal-form input {
  min-width: 0;
}
.weight-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.weight-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  min-width: 0;
}
.weight-stat span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  margin-bottom: 3px;
}
.weight-stat strong {
  display: block;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}
.weight-stat.forecast { grid-column: 1 / -1; }
.weight-up { color: var(--accent); }
.weight-down { color: var(--primary-light); }

.nutrition-analytics {
  border-top: 1px solid var(--border);
  padding-top: 6px;
}
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.section-title-row h4 { margin: 8px 0; }
.analytics-period {
  display: inline-flex;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.analytics-period-btn {
  padding: 4px 8px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 600 0.7rem inherit;
  cursor: pointer;
}
.analytics-period-btn.active { background: var(--primary); color: white; }
.analytics-caption {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.72rem;
}
.analytics-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.analytics-stats > div {
  min-width: 0;
  padding: 7px 8px;
  background: var(--surface);
  border-radius: var(--radius-sm);
}
.analytics-stats span {
  display: block;
  color: var(--muted);
  font-size: 0.67rem;
}
.analytics-stats strong {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}
.analytics-stats .analytics-goal { grid-column: 1 / -1; }
.analytics-products {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.analytics-products > div {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.analytics-products h5 {
  margin: 0 0 5px;
  font-size: 0.72rem;
  color: var(--muted);
}
.analytics-products ol {
  margin: 0;
  padding-left: 18px;
  font-size: 0.72rem;
}
.analytics-products li {
  display: flex;
  gap: 4px;
  justify-content: space-between;
  padding: 2px 0;
}
.analytics-products li span {
  min-width: 0;
  overflow-wrap: anywhere;
}
.analytics-products li strong {
  white-space: nowrap;
  color: var(--muted);
}
.analytics-products .empty-hint { margin: 0; padding: 4px 0; font-size: 0.72rem; }

.history-list {
  flex: 0 0 220px;
  min-height: 220px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  background: var(--surface);
}
.history-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}
.history-row:last-child { border-bottom: none; }
.history-row button { background: none; border: none; color: var(--danger); cursor: pointer; }

.empty-hint { color: var(--muted); font-size: 0.85rem; text-align: center; padding: 12px; }

/* ---------- Meal history (expandable days) ---------- */

#meal-history {
  flex-basis: 320px;
  min-height: 320px;
  max-height: 360px;
}

.history-day {
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
}
.history-day:last-child { border-bottom: none; }
.history-day.expanded { background: var(--surface); border-radius: var(--radius-sm); padding: 8px 8px; margin: 2px 0; }

.history-day-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 4px 2px;
  text-align: left;
}
.history-day-date { font-size: 0.86rem; font-weight: 600; color: var(--text); }
.history-day-kcal { font-size: 0.85rem; font-weight: 700; color: var(--primary-dark); white-space: nowrap; }
.history-day-kcal.over { color: var(--danger); }
.history-day-caret { font-size: 0.7rem; color: var(--muted); }

.history-day-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 2px 0;
}
.history-type-chip {
  font-size: 0.72rem;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
  color: var(--muted);
}

.history-day-details {
  margin-top: 10px;
  padding: 10px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.macro-bar.compact { margin: 0 0 10px; gap: 6px; }
.macro-bar.compact .macro-chip { padding: 5px 6px; }
.macro-bar.compact .macro-value { font-size: 0.85rem; }

.history-meals-list { display: flex; flex-direction: column; gap: 6px; }
.history-meal-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
}
.history-meal-item:last-child { border-bottom: none; }
.history-meal-type { flex-shrink: 0; font-size: 0.78rem; }
.history-meal-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.history-meal-kcal { color: var(--muted); font-weight: 600; white-space: nowrap; }

.history-day-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--muted);
  flex-wrap: wrap;
}

/* ---------- Scrollbars (nice touch) ---------- */
.history-list::-webkit-scrollbar, .products-list::-webkit-scrollbar, .autocomplete-list::-webkit-scrollbar {
  width: 6px;
}
.history-list::-webkit-scrollbar-thumb, .products-list::-webkit-scrollbar-thumb, .autocomplete-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

/* ---------- Mobile responsive ---------- */

@media (max-width: 640px) {
  .app-header { padding: 14px 14px; }
  .app-header-inner { flex-direction: column; align-items: stretch; padding-right: 0; }
  .app-header h1 { font-size: 1.1rem; justify-content: center; padding-right: 40px; }
  .date-picker { justify-content: center; }
  .logout-btn { top: 0; right: env(safe-area-inset-right, 0px); }

  .people-container { padding: 14px; gap: 14px; grid-template-columns: 1fr; }
  .card { margin: 0 14px 18px; padding: 16px; }
  .person-card { padding: 16px; }

  .calorie-summary { gap: 14px; }
  .calorie-ring { width: 76px; height: 76px; min-width: 76px; font-size: 0.85rem; }
  .calorie-ring::before { width: 58px; height: 58px; }
  .calorie-details .remaining, .calorie-details .over { font-size: 1rem; }
  .weight-progress { gap: 3px 8px; }

  .macro-bar { gap: 6px; }
  .macro-chip { min-width: 0; padding: 6px 4px; }
  .macro-chip .macro-value { font-size: 0.88rem; }

  .inline-form { flex-direction: column; }
  .inline-form input { width: 100%; }
  #weight-form {
    flex-direction: column;
  }
  #weight-goal-form {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  #weight-goal-form .btn { width: 100%; }
  .section-title-row { align-items: flex-start; }
  .analytics-products { grid-template-columns: 1fr; }
  #weight-history {
    flex-basis: 180px;
    min-height: 180px;
    max-height: 180px;
  }
  #meal-history {
    flex-basis: 240px;
    min-height: 240px;
    max-height: 240px;
  }

  dialog {
    max-width: 100%;
    width: 100%;
    max-height: 100dvh;
    height: 100dvh;
    margin: 0;
    border-radius: 0;
    position: fixed;
    inset: 0;
    top: 0;
    overflow-x: hidden;
  }
  #weight-modal,
  .weight-modal-content,
  .weight-modal-content .dialog-body,
  .weight-chart-wrap {
    max-width: 100%;
    min-width: 0;
  }
  #weight-chart { max-width: 100%; }
  .dialog-header { padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 10px; flex-shrink: 0; }
  .dialog-body { padding: 6px 16px 16px; gap: 14px; }
  .modal-actions {
    flex-direction: column-reverse;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
  }
  .modal-actions .btn { width: 100%; }

  .product-row { flex-wrap: wrap; }
}

@media (max-width: 400px) {
  .person-card-header h2 { font-size: 1.1rem; }
  .calorie-ring { width: 66px; height: 66px; min-width: 66px; font-size: 0.75rem; }
  .calorie-ring::before { width: 50px; height: 50px; }
}

/* ---------- Login page ---------- */

.login-page-body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(53, 181, 126, 0.16), transparent),
    radial-gradient(900px 500px at -10% 10%, rgba(255, 148, 102, 0.1), transparent),
    var(--bg);
}

.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.login-logo { font-size: 2.4rem; }
.login-card h1 { margin: 0; font-size: 1.3rem; color: var(--text); }
.login-subtitle { margin: 0 0 6px; color: var(--muted); font-size: 0.9rem; }

.login-card label {
  text-align: left;
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-weight: 500;
}
.login-card input {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
}
.login-card input:focus { outline: none; border-color: var(--primary-light); background: var(--input-bg); }

.login-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.84rem;
  background: rgba(245, 89, 94, 0.14);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.login-card .btn { width: 100%; margin-top: 4px; }
