/* Дизайн-система Diet Tracker: тёмная тема, mobile-first. */
:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --card: #1a2332;
  --surface-secondary: #222d3d;
  --surface-input: #0f1419;
  --text: #e8eef5;
  --text-secondary: #8b9bb4;
  --muted: #8b9bb4;
  --accent: #22c55e;
  --accent-hover: #1eaf55;
  --on-accent: #052e16;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #22c55e;
  --focus: #22c55e;
  --border: #2d3a4f;
  --chart-grid: #2d3a4f;
  --shadow: rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-card: 16px;
  --gap: 16px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --card: #ffffff;
  --surface-secondary: #eef2f6;
  --surface-input: #ffffff;
  --text: #172033;
  --text-secondary: #56657a;
  --muted: #56657a;
  --accent: #15803d;
  --accent-hover: #166534;
  --on-accent: #ffffff;
  --danger: #b91c1c;
  --warning: #b45309;
  --success: #15803d;
  --focus: #15803d;
  --border: #d5dce5;
  --chart-grid: #d5dce5;
  --shadow: rgba(23, 32, 51, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.topbar {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}
.brand { text-decoration: none; font-size: 18px; font-weight: 600; }
.theme-toggle {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 18px;
  line-height: 1;
  padding: 0 10px;
}
.theme-toggle:hover { border-color: var(--muted); }
@media (max-width: 480px) {
  .topbar { flex-wrap: wrap; }
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px calc(96px + env(safe-area-inset-bottom, 0px));
  width: 100%;
}
@media (min-width: 768px) {
  #app { padding: 24px 24px 32px; }
}
@media (min-width: 1024px) {
  #app { padding: 32px 32px 40px; }
}

/* ---------- Auth ---------- */
.auth-layout { padding: 12px 0 40px; }
.auth-shell {
  max-width: 1040px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 440px;
  gap: 32px;
  align-items: center;
  padding: 24px 16px;
}
.brand-panel h1 { font-size: 28px; font-weight: 700; margin: 0 0 8px; }
.brand-panel .tagline { color: var(--muted); font-size: 15px; margin: 0 0 20px; }
.brand-panel ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.brand-panel li { padding-left: 20px; position: relative; font-size: 14px; }
.brand-panel li::before {
  content: "";
  position: absolute;
  left: 0; top: 7px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--card);
}
.auth-card[data-mode="register"] { max-width: 680px; }
.auth-card-heading h1 { margin: 0; font-size: 24px; font-weight: 600; line-height: 1.3; }
.muted { color: var(--muted); }

.auth-tabs { display: flex; gap: 24px; margin: 20px 0; border-bottom: 1px solid var(--border); }
.auth-tabs button {
  position: relative;
  padding: 0 0 10px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
}
.auth-tabs button[aria-selected="true"] { color: var(--accent); font-weight: 600; }
.auth-tabs button[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--accent);
}

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.login-fields { grid-template-columns: 1fr; }
.field { min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; }
.field input, .field select {
  width: 100%;
  height: 46px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-input);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
}
.field input::placeholder { color: var(--muted); }
.field input:hover, .field select:hover { border-color: var(--muted); }
.field input:focus, .field select:focus {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: 0;
}
.field input[aria-invalid="true"], .field select[aria-invalid="true"] {
  border-color: var(--danger);
}
.input-wrap { position: relative; }
.input-wrap input[autocomplete$="password"] { padding-right: 83px; }
.password-toggle {
  position: absolute;
  right: 8px; top: 0;
  height: 46px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 0 3px;
}
.password-toggle:hover { color: var(--accent); }
.field-error { display: block; color: var(--danger); font-size: 12px; line-height: 1.4; margin-top: 4px; }
.field-error:empty { display: none; }

.alert { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-size: 13px; margin: 16px 0 0; }
.alert-error { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--text); }
.alert-warning { border-color: var(--warning); background: color-mix(in srgb, var(--warning) 12%, transparent); color: var(--text); }
.alert-success { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--text); }
.form-error { border: 1px solid var(--danger); border-radius: var(--radius); background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--text); padding: 10px 12px; font-size: 13px; margin: 16px 0 0; }

.button-primary {
  width: 100%;
  min-height: 46px;
  padding: 11px 18px;
  margin-top: 24px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 14px;
  font-weight: 600;
}
.button-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.button-secondary {
  border: 1px solid var(--border);
  padding: 10px 20px;
  min-height: 44px;
  border-radius: var(--radius);
  color: var(--text);
  background: transparent;
  font-size: 14px;
}
.button-secondary:hover { border-color: var(--muted); }
.button-danger { border-color: var(--danger); color: var(--danger); }
.request-status { margin: 10px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.request-status:empty { display: none; }
.auth-footnote { margin: 22px 0 0; padding-top: 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; line-height: 1.6; }

.site-disclaimer {
  max-width: 1040px;
  margin: 28px auto 0;
  padding: 18px 24px;
  border: 1px solid var(--warning);
  border-radius: var(--radius-card);
  background: var(--card);
}
.site-disclaimer-title {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--warning);
}
.site-disclaimer ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.site-disclaimer li { font-size: 13px; line-height: 1.5; color: var(--muted); }

/* ---------- Общие состояния ---------- */
.loading-message { text-align: center; margin: 90px 0; color: var(--muted); }
.empty-state { text-align: center; padding: 32px 16px; border: 1px dashed var(--border); border-radius: var(--radius-card); color: var(--muted); }
.error-state { text-align: center; padding: 24px 16px; }
.skeleton { border-radius: var(--radius); background: linear-gradient(90deg, var(--card) 25%, var(--border) 50%, var(--card) 75%); background-size: 200% 100%; animation: skeleton 1.4s infinite; min-height: 16px; }
@keyframes skeleton { to { background-position: -200% 0; } }

/* ---------- Dashboard ---------- */
.dashboard-container { text-align: left; }
.dashboard-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 12px; }
.dashboard-title { margin: 0; font-size: 22px; font-weight: 600; outline: none; }
.dashboard-card { max-width: 100%; margin: 0 0 16px 0; padding: 20px; }
.calories-big { font-size: 44px; font-weight: 700; line-height: 1.1; margin: 0; }
.calories-caption { color: var(--muted); font-size: 13px; margin: 4px 0 16px; }
.dashboard-progress-bg { width: 100%; height: 10px; background: var(--surface-input); border-radius: 6px; margin-bottom: 20px; overflow: hidden; border: 1px solid var(--border); }
.dashboard-progress-fill { height: 100%; transition: width .3s ease; }
.bg-error { background: var(--danger); }
.bg-primary { background: var(--accent); }
.dashboard-macros { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.macro-label { font-size: 12px; }
.macro-value { font-weight: 600; }
.macro-norm { font-weight: normal; font-size: 12px; }
.text-error { color: var(--danger); }
.text-ok { color: var(--accent); }

.streak-card { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.streak-value { font-size: 28px; font-weight: 700; margin: 0; }
.streak-label { color: var(--muted); font-size: 12px; margin: 0; }
.streak-flame { font-size: 26px; }
.streak-success { color: var(--accent); }
.streak-fail { color: var(--muted); }

.dashboard-meals-title { font-size: 15px; border-top: 1px solid var(--border); padding-top: 16px; margin-bottom: 12px; }
.dashboard-meals-list { display: flex; flex-direction: column; gap: 16px; }
.meal-type-title { margin: 0 0 6px 0; font-size: 13px; color: var(--accent); }
.meal-items-list { list-style: none; padding: 0; margin: 0; }
.meal-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.meal-item-actions { display: flex; gap: 4px; }
.meal-item-actions button { min-height: 32px; min-width: 32px; border: 1px solid var(--border); border-radius: 8px; background: transparent; color: var(--muted); font-size: 12px; padding: 2px 8px; }
.meal-item-actions button:hover { color: var(--text); border-color: var(--muted); }
.dashboard-add-btn { width: 100%; }

/* ---------- Нижняя навигация ---------- */
.app-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  z-index: 10;
}
.app-nav ul { display: flex; gap: 4px; list-style: none; margin: 0; padding: 6px 12px; max-width: 1200px; width: 100%; }
.app-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 64px;
  min-height: 48px;
  padding: 4px 8px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--muted);
  font-size: 11px;
}
.app-nav a.active { color: var(--accent); font-weight: 600; }
.app-nav a:hover { color: var(--text); }
.app-nav .nav-icon { font-size: 18px; line-height: 1; }

/* ---------- Экраны добавления еды, профиля, веса, статистики ---------- */
.screen-title { font-size: 22px; font-weight: 600; margin: 0 0 16px; }
.product-results { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.product-results li button {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 10px 12px;
  min-height: 44px;
}
.product-results li button.selected { border-color: var(--accent); }
.product-results .product-kcal { color: var(--muted); font-size: 12px; }
.preview-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-top: 16px; font-size: 13px; }
.preview-box dl { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 12px; margin: 0; }
.preview-box dt { color: var(--muted); font-size: 12px; }
.preview-box dd { margin: 0; font-weight: 600; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { border-bottom: 1px solid var(--border); padding: 8px 6px; text-align: left; }
.data-table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.chart-box { border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--card); padding: 12px; margin-bottom: 16px; }
.chart-box canvas { width: 100%; height: 200px; display: block; }
.profile-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.profile-row .muted { font-size: 12px; }
.weight-log-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }

@media (min-width: 900px) {
  .auth-shell {
    grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
    gap: 32px;
  }
  .auth-shell[data-mode="register"] {
    grid-template-columns: minmax(0, 1fr) minmax(360px, 680px);
  }
  .brand-panel { text-align: left; }
  .brand-panel ul { display: grid; }
}
@media (max-width: 899px) {
  .auth-shell { grid-template-columns: 1fr; gap: 8px; }
  .brand-panel { text-align: center; }
  .brand-panel ul { display: none; }
}
@media (min-width: 768px) {
  .app-nav {
    position: static;
    border-top: 0;
    border-bottom: 1px solid var(--border);
  }
  .app-nav ul { padding: 8px 0; }
}
@media (max-width: 560px) {
  .topbar { padding: 14px 16px; }
  #app { padding: 16px 12px 96px; }
  .auth-card { padding: 20px 16px; }
  .auth-card-heading h1 { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; }
  .field input, .field select { font-size: 16px; }
  .calories-big { font-size: 36px; }
}

/* ---------- Навигация: четыре кнопки-карточки ---------- */
.app-nav { background: transparent; border-top: 0; padding: 0 2px; }
.app-nav ul { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 0; }
.app-nav a {
  flex-direction: column;
  min-width: 0;
  min-height: 52px;
  padding: 6px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 11px;
  gap: 4px;
}
.app-nav a:hover { border-color: var(--muted); color: var(--text); }
.app-nav a.active {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}
@media (min-width: 768px) {
  .app-nav a { flex-direction: row; min-height: 48px; font-size: 13px; gap: 8px; }
}
@media (max-width: 767px) {
  .app-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    z-index: 10;
  }
}

/* ---------- Форма добавления еды: вертикальные блоки ---------- */
.stacked-form > label { display: block; margin: 12px 0 6px; font-size: 13px; font-weight: 500; }
.stacked-form input, .stacked-form select {
  width: 100%; min-width: 0; height: 48px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-input); color: var(--text);
  padding: 10px 12px; font-size: 16px;
}
.stacked-form input[type="search"] { margin-top: 6px; }
.product-results {
  max-height: 340px; overflow-y: auto; margin-top: 8px;
  display: grid; gap: 8px;
}
.selected-product {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-top: 8px; padding: 12px;
  border: 1px solid var(--accent); border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  font-size: 14px;
}
.selected-badge {
  padding: 2px 8px; border-radius: 999px;
  background: var(--accent); color: var(--on-accent);
  font-size: 11px; font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- Плотность и сетки (п.17-23 ТЗ) ---------- */
.profile-grid, .stats-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.dash-top { display: grid; grid-template-columns: 1fr; gap: 16px; }
.profile-form-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.norm-values { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 480px) {
  .dashboard-macros { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 768px) {
  .dash-top { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
  .dash-top .dashboard-card { margin-bottom: 0; }
}
@media (min-width: 1024px) {
  .profile-grid { grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); align-items: start; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profile-form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .norm-values { grid-template-columns: repeat(4, 1fr); }
  .auth-card { padding: 20px; }
  #app { padding-top: 16px; }
  .dashboard-card, .chart-box, .auth-card { margin-bottom: 12px; }
}
.form-block label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; }
.form-block input, .form-block select {
  width: 100%; min-width: 0; height: 48px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-input); color: var(--text);
  padding: 10px 12px; font-size: 14px;
}
.weight-inline { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 1024px) {
  .weight-inline { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
}
.table-toggle { margin-top: 8px; }

.profile-form-grid > .alert { grid-column: 1 / -1; }

/* ---------- Правки по ревью ---------- */
/* Заголовок приёма пищи над своей линией, а не под чужой */
.meal-type-title {
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
/* Нет лишней верхней полосы у первого заголовка в карточке */
.auth-card > .dashboard-meals-title:first-child {
  border-top: 0;
  padding-top: 0;
}
/* Воздух между контентом и нижней навигацией */
@media (max-width: 767px) {
  #app { padding-bottom: calc(140px + env(safe-area-inset-bottom, 0px)); }
}
