:root {
  /* тёмная палитра FatSecret — используется по умолчанию, независимо от системной темы */
  color-scheme: dark;
  --page: #0b0e1a;
  --surface: #171b28;
  --ink: #ffffff;
  --ink-2: #b8bfcf;
  --muted: #7d8393;
  --border: rgba(255, 255, 255, 0.08);
  --good: #22c55e;
  --critical: #f0605a;
  --carbs: #63b3ed;
  --fat: #f5a742;
  --protein: #f0776e;
  --radius: 18px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --good: #0ca30c;
  --critical: #d03b3b;
  --carbs: #1baf7a;
  --fat: #eb6834;
  --protein: #2a78d6;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body { padding-bottom: env(safe-area-inset-bottom); }

.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 16px;
}
.login-card {
  width: 100%; max-width: 320px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 24px; text-align: center;
}
.login-card h1 { font-size: 20px; margin: 0 0 24px; }
.pin-label {
  display: block; font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 14px;
}
.pin-dots { display: flex; justify-content: center; gap: 12px; margin-bottom: 8px; }
.pin-dot {
  width: 44px; height: 52px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--page); display: flex; align-items: center; justify-content: center;
  transition: border-color .15s, background .15s;
}
.pin-dot.filled { border-color: var(--good); background: color-mix(in srgb, var(--good) 15%, var(--page)); }
.pin-dot.filled::after { content: "•"; font-size: 28px; color: var(--good); line-height: 0; }
.pin-hidden-input {
  position: absolute; opacity: 0; height: 1px; width: 1px; pointer-events: none;
}
.login-error { color: var(--critical); font-size: 13px; min-height: 18px; margin: 8px 0 0; }

.app { max-width: 480px; margin: 0 auto; padding: 16px 16px 32px; }

.header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.header h1 { font-size: 20px; margin: 0; text-transform: capitalize; }
.header button.icon-btn {
  background: none; border: none; color: var(--ink-2); font-size: 20px; padding: 6px;
}
.header select#profileSelect {
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 8px; font-size: 13px; margin-right: 4px;
}

.weekdays { display: flex; justify-content: space-between; margin-bottom: 18px; }
.weekday {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: none; border: none; color: var(--muted); font-size: 12px; padding: 0;
}
.weekday .dot {
  width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; border: 1px solid var(--border); color: var(--ink-2); font-size: 13px;
}
.weekday.selected .dot { border-color: var(--good); color: var(--good); font-weight: 700; }
.weekday.has-entries .dot { background: var(--good); color: #fff; border-color: var(--good); }
.weekday.selected.has-entries .dot { background: var(--good); box-shadow: 0 0 0 2px var(--page), 0 0 0 3px var(--good); }

.diary-summary {
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 14px 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px;
}
.diary-summary .label { font-size: 11px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.diary-summary .macros { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.diary-summary .kcal { text-align: right; }
.diary-summary .kcal .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.diary-summary .kcal .unit { font-size: 12px; color: var(--muted); }

.meal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 10px; overflow: hidden;
}
.meal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; cursor: pointer;
}
.meal-head .name { font-weight: 600; display: flex; align-items: center; gap: 10px; }
.meal-head .kcal { text-align: right; font-variant-numeric: tabular-nums; }
.meal-head .kcal .n { font-size: 17px; font-weight: 700; }
.meal-head .kcal .u { font-size: 11px; color: var(--muted); display: block; }
.meal-items { border-top: 1px solid var(--border); }
.meal-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; font-size: 14px; color: var(--ink-2); gap: 8px;
}
.meal-item .del { background: none; border: none; color: var(--critical); font-size: 12px; }
.meal-empty { padding: 10px 16px; font-size: 13px; color: var(--muted); }

.summary-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 16px; margin-top: 18px;
}
.summary-box h2 { font-size: 15px; margin: 0 0 12px; }
.summary-row { display: flex; align-items: center; gap: 16px; }
.summary-text { flex: 1; }
.summary-text .line { display: flex; justify-content: space-between; font-size: 14px; padding: 4px 0; }
.summary-text .line .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.grid-squares { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; width: 100px; }
.grid-squares div { aspect-ratio: 1; border-radius: 2px; background: var(--border); }
.grid-squares div.filled { background: var(--good); }
.grid-squares div.over { background: var(--critical); }

.donut-wrap { display: flex; align-items: center; gap: 16px; margin-top: 16px; }
.donut { width: 96px; height: 96px; border-radius: 50%; flex-shrink: 0; }
.donut-legend { font-size: 13px; }
.donut-legend .row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.donut-legend .sw { width: 10px; height: 10px; border-radius: 3px; }

.water-row { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; font-size: 14px; }
.water-value { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.water-bar { height: 8px; border-radius: 4px; background: var(--border); margin-top: 6px; overflow: hidden; }
.water-bar-fill { height: 100%; background: var(--carbs); border-radius: 4px; transition: width .2s; }

.checkin-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 5px 0; font-size: 13px; }
.checkin-date { color: var(--muted); min-width: 44px; }
.checkin-chip { padding: 3px 8px; border-radius: 10px; background: var(--border); }
.checkin-chip.ok { color: var(--good); }
.checkin-chip.bad { color: var(--critical); cursor: help; }

.mode-switch { display: flex; gap: 8px; margin-bottom: 16px; }
.mode-switch button {
  flex: 1; padding: 8px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2); font-size: 13px;
}
.mode-switch button.active { color: var(--ink); border-color: var(--good); font-weight: 600; }

.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 160px; margin-top: 8px; }
.bar-chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-chart .bar { width: 100%; border-radius: 4px 4px 0 0; }
.bar-chart .day-label { font-size: 10px; color: var(--muted); margin-top: 4px; }

.goal-form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.goal-form label { font-size: 13px; color: var(--ink-2); display: flex; justify-content: space-between; align-items: center; }
.goal-form input {
  width: 100px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--page); color: var(--ink); text-align: right; font-variant-numeric: tabular-nums;
}
.goal-form button {
  margin-top: 6px; padding: 10px; border-radius: 10px; border: none;
  background: var(--good); color: #fff; font-weight: 600;
}
