/* Stage 2 panel front end (docs/PANEL_API.md "Front end" section).

   Reads as a calm, native Telegram screen: Telegram's own theme variables
   drive every colour (with light/dark fallbacks for a plain browser),
   generous spacing, one big number per screen, a system font stack, no
   red/green meaning anywhere, and everything responds to
   prefers-reduced-motion. No external stylesheet, no build step. */

/* -------------------------------------------------------------------- */
/* Tokens                                                                */
/* -------------------------------------------------------------------- */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #f0f0f3);
  --text: var(--tg-theme-text-color, #0f1114);
  --hint: var(--tg-theme-hint-color, #757a80);
  --link: var(--tg-theme-link-color, #3390ec);
  --accent: var(--tg-theme-button-color, #3390ec);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --destructive: var(--tg-theme-destructive-text-color, #d64c4c);
  --separator: rgba(15, 17, 20, 0.09);
  --track: rgba(15, 17, 20, 0.08);
  --overlay-bg: rgba(255, 255, 255, 0.85);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --radius: 12px;
  --radius-sm: 8px;
  --font-system: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --bg-secondary: var(--tg-theme-secondary-bg-color, #232e3c);
    --text: var(--tg-theme-text-color, #f0f2f5);
    --hint: var(--tg-theme-hint-color, #8b98a5);
    --link: var(--tg-theme-link-color, #6ab3f3);
    --accent: var(--tg-theme-button-color, #5288c1);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
    --destructive: var(--tg-theme-destructive-text-color, #ec6a6a);
    --separator: rgba(255, 255, 255, 0.10);
    --track: rgba(255, 255, 255, 0.10);
    --overlay-bg: rgba(23, 33, 43, 0.85);
  }
}

/* Telegram's own script sets colorScheme; app.js mirrors it onto this
   attribute so a plain browser opened in dark mode (no Telegram object at
   all) still gets the right palette via the media query above, and inside
   Telegram it tracks Telegram's own theme changes live. */
html[data-tg-scheme="dark"] {
  color-scheme: dark;
}
html[data-tg-scheme="light"] {
  color-scheme: light;
}

/* -------------------------------------------------------------------- */
/* Base                                                                  */
/* -------------------------------------------------------------------- */

* {
  box-sizing: border-box;
}

/* Several classes below set their own `display` (flex/block) so they can
   lay out their children - .state-screen, .state-overlay, .weight-summary,
   .chart-image. Without this rule, that author `display` would silently
   win over the browser's own `[hidden] { display: none }` default (author
   CSS always beats the user-agent stylesheet, whatever the selector
   specificity), so `el.hidden = true` would stop being visually effective
   on exactly the elements app.js toggles most. This restores it,
   unconditionally, for every element carrying the attribute. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-system);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

/* Round-3 visual-QA defect 10: form controls do NOT inherit font-family,
   size or line-height from the page - a browser styles them from its own
   defaults, which is why the "Исправить текстом" textarea rendered its
   placeholder and text in monospace while everything around it was the
   system UI font. `font: inherit` takes all three at once (the shorthand
   also resets font-weight/style to the inherited values, which is what is
   wanted here); `color: inherit` keeps them on the theme's own text
   colour in light AND dark. */
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: none;
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.5;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* -------------------------------------------------------------------- */
/* App shell                                                             */
/* -------------------------------------------------------------------- */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
}

.screens {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5) var(--space-4) var(--space-6);
  padding-bottom: calc(var(--space-6) + 64px);
}

.screen {
  position: relative;
}

.tabbar {
  position: sticky;
  bottom: 0;
  display: flex;
  border-top: 1px solid var(--separator);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-1) var(--space-3);
  min-height: 56px;
  color: var(--hint);
}

.tab[aria-pressed="true"] {
  color: var(--accent);
}

.tab svg {
  width: 22px;
  height: 22px;
}

.tab-label {
  font-size: 11px;
  font-weight: 500;
}

/* -------------------------------------------------------------------- */
/* State screens (boot loading / outside Telegram / boot error)         */
/* -------------------------------------------------------------------- */

.state-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-4);
  padding: var(--space-5);
}

.state-screen p {
  color: var(--hint);
  max-width: 40ch;
  margin: 0;
}

/* Loading/error overlay covering one screen's content while it (re)loads. */
.state-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  text-align: center;
  background: var(--overlay-bg);
  padding: var(--space-5);
  min-height: 220px;
}

.state-overlay p {
  color: var(--hint);
  margin: 0;
  max-width: 32ch;
}

/* -------------------------------------------------------------------- */
/* Buttons                                                               */
/* -------------------------------------------------------------------- */

.button {
  min-height: 44px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  background: var(--bg-secondary);
}

.button-primary {
  background: var(--accent);
  color: var(--accent-text);
  width: 100%;
}

.icon-button {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text);
}

.chip-button {
  min-height: 44px;
  padding: 0 var(--space-3);
  border-radius: 999px;
  background: var(--bg-secondary);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.chip-button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

.status-buttons {
  display: flex;
  gap: var(--space-2);
  margin: var(--space-4) 0;
}

.status-buttons .chip-button {
  flex: 1;
  min-height: 44px;
}

/* -------------------------------------------------------------------- */
/* Day nav (Сегодня / Неделя headers)                                    */
/* -------------------------------------------------------------------- */

.day-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.day-date {
  /* No text-transform: capitalize here on purpose - Russian mid-string
     words (the month, the weekday abbreviation) must stay lowercase;
     capitalize would title-case every word, which reads as wrong in
     Russian ("20 Сентября, Вс" instead of "20 сентября, вс"). */
  font-size: 15px;
  font-weight: 600;
}

/* -------------------------------------------------------------------- */
/* Hero (one big number per screen)                                     */
/* -------------------------------------------------------------------- */

.nutrition-dashboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: var(--space-2) 0 var(--space-4);
}

.loading-quote {
  max-width: 32rem;
  margin: 24px auto;
  padding: 0 24px;
}
.loading-quote blockquote {
  margin: 0 0 18px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(20px, 5vw, 27px);
  line-height: 1.55;
  white-space: pre-line;
  color: var(--text);
}
.loading-quote figcaption { font-size: 13px; line-height: 1.6; }
.loading-quote a { color: var(--hint); text-decoration: none; }
.loading-quote a:hover { text-decoration: underline; }

.calorie-ring {
  --calorie-fill: #4d9b70;
  --calorie-excess: #d45a5a;
  position: relative;
  width: min(54vw, 212px);
  height: min(54vw, 212px);
  display: grid;
  place-items: center;
}

.calorie-ring-no-target {
  --calorie-fill: var(--hint);
}

.calorie-ring-content {
  position: relative;
  z-index: 1;
  width: calc(100% - 24px);
  height: calc(100% - 24px);
  border-radius: 50%;
  /* SVG strokes already form the ring. An opaque inner disc would cover
     the green goal arc and the inner red excess arc in WebKit. */
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-3);
}

.calorie-ring-svg,
.macro-ring-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.ring-track,
.ring-fill,
.ring-excess {
  fill: none;
  stroke-linecap: round;
}

.calorie-ring-svg .ring-track,
.calorie-ring-svg .ring-fill {
  stroke-width: 10;
}

.calorie-ring-svg .ring-track,
.macro-ring-svg .ring-track {
  stroke: var(--track);
}

.calorie-ring-fill {
  stroke: var(--calorie-fill);
}

.ring-excess {
  stroke: var(--calorie-excess);
  stroke-width: 7;
}

.hero {
  text-align: left;
  margin-bottom: var(--space-3);
}

.hero-value {
  font-size: 44px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.hero-sub {
  color: var(--hint);
  font-size: 15px;
  margin-top: var(--space-1);
}

.hero-left {
  color: var(--hint);
  font-size: 15px;
  margin-top: var(--space-1);
}

.hero-note {
  color: var(--hint);
  font-size: 14px;
  margin: var(--space-3) 0 0;
  text-align: center;
}

/* -------------------------------------------------------------------- */
/* Progress bar with a thin target marker                               */
/* -------------------------------------------------------------------- */

.progress-wrap {
  margin: var(--space-3) 0 var(--space-4);
}

.progress-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: var(--track);
  overflow: visible;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  width: 0;
}

.progress-target {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 14px;
  background: var(--text);
  opacity: 0.55;
  left: 0;
}

/* -------------------------------------------------------------------- */
/* Macro row                                                            */
/* -------------------------------------------------------------------- */

.macro-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-2);
  margin: var(--space-2) 0 var(--space-4);
}

.text-action {
  min-height: 44px;
  margin-top: var(--space-1);
  color: var(--link);
  font-size: 15px;
  font-weight: 600;
}

.macro-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
  text-align: center;
}

.macro-ring {
  --macro-accent: var(--accent);
  position: relative;
  width: clamp(62px, 18vw, 74px);
  height: clamp(62px, 18vw, 74px);
  padding: 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.macro-item-no-target .macro-ring {
  --macro-accent: var(--hint);
}

.macro-ring > .macro-label,
.macro-ring > .macro-value {
  position: relative;
  z-index: 1;
}

.macro-ring-svg .ring-track,
.macro-ring-svg .ring-fill {
  stroke-width: 8;
}

.macro-ring-svg .ring-fill {
  stroke: var(--macro-accent);
}

.macro-item:nth-child(1) .macro-ring {
  --macro-accent: #4d8fd1;
}

.macro-item:nth-child(2) .macro-ring {
  --macro-accent: #8a75c9;
}

.macro-item:nth-child(3) .macro-ring {
  --macro-accent: #bb8a3e;
}

.macro-item:nth-child(4) .macro-ring {
  --macro-accent: #4e9a9a;
}

.macro-label {
  font-size: 12px;
  color: var(--hint);
  font-weight: 600;
  line-height: 1;
}

.macro-value {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.1;
}

.macro-caption {
  font-size: 12px;
  font-weight: 600;
}

.macro-detail {
  color: var(--hint);
  font-size: 11px;
  white-space: nowrap;
}

#nutrition-lookback {
  display: block;
  margin-top: 12px;
  padding: 16px;
}
#nutrition-lookback[hidden] { display: none; }
#nutrition-lookback strong { color: var(--text); }
#nutrition-lookback p { margin: 8px 0; }
#nutrition-lookback .macro-row { width: 100%; }
.lookback-calorie { display: grid; justify-items: center; margin: 16px 0; }
.lookback-calorie .macro-ring { width: 120px; height: 120px; }
.lookback-calorie .ring-fill { stroke: #32a66a; }
.lookback-calorie .macro-value { font-size: 25px; color: var(--text); }

.fiber-card {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  color: var(--hint);
  font-size: 13px;
  text-align: center;
}

/* -------------------------------------------------------------------- */
/* Meal list                                                            */
/* -------------------------------------------------------------------- */

.meal-list {
  list-style: none;
  margin: var(--space-3) 0 0;
  padding: 0;
}

.meal {
  padding: var(--space-3) 0;
  border-top: 1px solid var(--separator);
}

.meal:first-child {
  border-top: none;
}

.meal-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  font-weight: 600;
  font-size: 14px;
  margin-bottom: var(--space-1);
}

.meal-time {
  color: var(--text);
}

.meal-photo-tag {
  color: var(--hint);
  font-weight: 500;
  font-size: 12px;
}

.meal-kcal {
  margin-left: auto;
  color: var(--hint);
  font-weight: 500;
}

.meal-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meal-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2);
  font-size: 14px;
  color: var(--hint);
}

.meal-item-name {
  flex: 1;
  color: var(--text);
}

.meal-item-amount {
  text-align: right;
}

.meal-item-nutrients,
.meal-nutrients {
  grid-column: 1 / -1;
  color: var(--hint);
  font-size: 13px;
  line-height: 1.35;
}

.meal-nutrients {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--separator);
  font-weight: 600;
}

.empty-state {
  color: var(--hint);
  font-size: 14px;
  padding: var(--space-3) 0;
  margin: 0;
}

.hint {
  color: var(--hint);
  font-size: 13px;
  margin-top: var(--space-4);
}

/* -------------------------------------------------------------------- */
/* Week bars                                                            */
/* -------------------------------------------------------------------- */

.week-bars {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--space-2);
  align-items: end;
  height: 140px;
  margin-bottom: var(--space-4);
}

.week-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  height: 100%;
}

.week-bar-value {
  color: var(--hint);
  font-size: 10px;
  line-height: 1;
  white-space: nowrap;
}

.week-bar-button {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  border-radius: var(--radius-sm);
}

.week-bar-track {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  overflow: hidden;
}

.week-bar-fill {
  width: 100%;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.week-bar--confirmed {
  background: var(--accent);
  opacity: 1;
}

.week-bar--logged {
  background: var(--accent);
  opacity: 0.45;
}

.week-bar--gap {
  background: transparent;
  height: 2px !important;
}

.week-col-label {
  font-size: 11px;
  color: var(--hint);
}

.week-average-line {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
  color: var(--hint);
  margin: var(--space-3) 0;
}

.week-total-line {
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text);
}

.week-summary-label {
  font-weight: 600;
}

.week-summary-kcal {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.week-summary-nutrients {
  font-size: 12px;
  line-height: 1.35;
}

/* -------------------------------------------------------------------- */
/* History                                                              */
/* -------------------------------------------------------------------- */

.range-switch {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.chart-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin-bottom: var(--space-4);
  background: var(--bg-secondary);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history-row-button {
  width: 100%;
  min-height: 44px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
  border-top: 1px solid var(--separator);
  text-align: left;
}

.history-row:first-child .history-row-button {
  border-top: none;
}

.history-date {
  display: block;
  font-weight: 500;
}

.history-copy {
  min-width: 0;
}

.history-nutrients {
  display: block;
  color: var(--hint);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 2px;
}

.history-kcal {
  color: var(--hint);
}

/* -------------------------------------------------------------------- */
/* Weight                                                               */
/* -------------------------------------------------------------------- */

.field-label {
  display: block;
  font-size: 13px;
  color: var(--hint);
  margin-bottom: var(--space-2);
}

/* The "characters left" line under a capped textarea - shown only near
   the limit (app.js's TEXT_COUNTER_FROM), so it is a quiet note, not a
   permanent counter watching her type. */
.field-counter {
  margin: calc(var(--space-1) * -1) 0 var(--space-2);
  font-size: 12px;
  color: var(--hint);
  text-align: right;
}

.weight-input-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-4);
  margin-bottom: var(--space-3);
}

.weight-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-size: 32px;
  font-weight: 650;
  padding: var(--space-2) 0;
}

.weight-input:focus {
  outline: none;
}

.weight-unit-suffix {
  color: var(--hint);
  font-size: 16px;
  font-weight: 500;
}

.weight-form .button-primary {
  margin-bottom: var(--space-4);
}

.unit-switch {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.confirm-banner {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.confirm-banner p {
  margin: 0 0 var(--space-3);
}

.confirm-actions {
  display: flex;
  gap: var(--space-2);
}

.confirm-actions .button {
  flex: 1;
}

.weight-summary {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 15px;
}

.summary-row span:first-child {
  color: var(--hint);
}

.summary-row span:last-child {
  font-weight: 600;
}

.weight-entries {
  list-style: none;
  margin: 0;
  padding: 0;
}

.weight-entry {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--separator);
  font-size: 15px;
}

.weight-entry:first-child {
  border-top: none;
}

.weight-entry-date {
  color: var(--hint);
  width: 6ch;
}

.weight-entry-value {
  flex: 1;
  font-weight: 500;
}

.weight-entry-undo {
  min-width: 44px;
  min-height: 44px;
  border-radius: 999px;
  color: var(--hint);
  font-size: 14px;
}

.weight-entry-undo:hover,
.weight-entry-undo:focus-visible {
  background: var(--bg-secondary);
  color: var(--destructive);
}

/* -------------------------------------------------------------------- */
/* Motion — only when the viewer hasn't asked for reduced motion         */
/* -------------------------------------------------------------------- */

@media (prefers-reduced-motion: no-preference) {
  .progress-fill,
  .week-bar-fill {
    transition: width 0.25s ease, height 0.25s ease;
  }

  .state-overlay {
    transition: opacity 0.15s ease;
  }
}

/* -------------------------------------------------------------------- */
/* Meal thumbnails + voice marker (v2)                                  */
/* -------------------------------------------------------------------- */

.meal-row-button {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  text-align: left;
  padding: var(--space-1) 0;
}

.meal-thumb {
  flex: none;
  width: 60px;
  height: 60px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  object-fit: cover;
  display: block;
}

.meal-thumb-placeholder {
  flex: none;
  width: 60px;
  height: 60px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hint);
}

.meal-thumb-placeholder svg {
  width: 26px;
  height: 26px;
}

.meal-body {
  flex: 1;
  min-width: 0;
}

.meal-voice-mark {
  color: var(--hint);
  font-size: 13px;
  margin-left: var(--space-1);
}

/* -------------------------------------------------------------------- */
/* Floating add button - fixed above the tab bar, never over content    */
/* since .screens already reserves (space-6 + 64px) of bottom padding   */
/* and the FAB itself sits just above the tab bar's own height.         */
/* -------------------------------------------------------------------- */

.fab {
  position: fixed;
  right: var(--space-4);
  bottom: calc(64px + env(safe-area-inset-bottom, 0) + var(--space-3));
  left: auto;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: 0 var(--space-4) 0 var(--space-3);
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(15, 17, 20, 0.22);
}

.fab svg {
  width: 20px;
  height: 20px;
}

/* Centres the app shell's own max-width so the FAB (fixed to the
   viewport) still lines up with the content column on a wide viewport
   instead of drifting to the physical screen edge. */
@media (min-width: 560px) {
  .fab {
    right: calc(50vw - 280px + var(--space-4));
  }
}

/* -------------------------------------------------------------------- */
/* Bottom sheets - scrim + panel, grab handle, safe-area aware          */
/* -------------------------------------------------------------------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-scrim {
  position: absolute;
  inset: 0;
  background: rgba(15, 17, 20, 0.45);
}

.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: min(88vh, 88dvh);
  overflow-y: auto;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: var(--space-2) var(--space-4) calc(var(--space-5) + env(safe-area-inset-bottom, 0));
  box-shadow: 0 -8px 28px rgba(15, 17, 20, 0.22);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--track);
  margin: var(--space-2) auto var(--space-3);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.sheet-title {
  font-size: 16px;
  font-weight: 650;
}

.sheet-close {
  font-size: 18px;
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sheet-photo {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: var(--space-2);
  background: var(--bg-secondary);
}

.sheet-item-list {
  list-style: none;
  margin: 0 0 var(--space-2);
  padding: 0;
}

.sheet-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--separator);
}

.sheet-item:first-child {
  border-top: none;
}

.sheet-item-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
}

.sheet-item-name-main {
  display: block;
}

.sheet-item-name-meta {
  display: block;
  color: var(--hint);
  font-size: 12px;
  margin-top: 2px;
}

/* -------------------------------------------------------------------- */
/* Steps                                                                */
/* -------------------------------------------------------------------- */

.steps-hero {
  text-align: center;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: var(--space-5) var(--space-4);
  margin-bottom: var(--space-4);
}

.steps-count {
  font-size: 46px;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.steps-unit {
  color: var(--hint);
  font-size: 15px;
  margin-top: var(--space-1);
}

.steps-hero .empty-state {
  padding-bottom: 0;
}

.steps-form {
  margin-bottom: var(--space-4);
}

.steps-goal {
  margin-bottom: var(--space-5);
}

.steps-goal .section-heading {
  margin: 0 0 var(--space-2);
}

.steps-goal-summary {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  font-size: 13px;
  margin-bottom: var(--space-3);
}

.steps-goal-summary p {
  margin: 0;
}

.steps-goal-summary p:first-child {
  color: var(--text);
  font-weight: 650;
}

.steps-goal-summary p:not(:first-child) {
  color: var(--hint);
}

.steps-goal-input {
  width: 100%;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  font-variant-numeric: tabular-nums;
}

.steps-input {
  width: 100%;
  border: 0;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  font-size: 28px;
  font-weight: 650;
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  font-variant-numeric: tabular-nums;
}

.steps-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.steps-form .button-primary {
  width: 100%;
}

.steps-yesterday,
.steps-average {
  color: var(--hint);
  font-size: 13px;
  margin: 0 0 var(--space-4);
}

.steps-week {
  margin-top: var(--space-5);
}

.steps-week .section-heading {
  margin-top: 0;
}

.steps-bars {
  display: grid;
  grid-template-columns: repeat(14, minmax(0, 1fr));
  align-items: end;
  gap: var(--space-2);
  height: 142px;
  margin-bottom: var(--space-2);
}

.steps-bar-entry {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  display: grid;
  grid-template-rows: auto 1fr auto;
  align-items: end;
  gap: var(--space-1);
  height: 100%;
  min-width: 0;
  text-align: center;
}

.steps-bar-value,
.steps-bar-label {
  color: var(--hint);
  font-size: 10px;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.steps-bar-track {
  width: min(12px, 100%);
  justify-self: center;
  height: 100%;
  display: flex;
  align-items: flex-end;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.steps-bar-fill {
  width: 100%;
  background: var(--accent);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.steps-bar-fill--missing {
  height: 2px;
  background: var(--separator);
}
.steps-bar-entry:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.steps-bar-entry .steps-bar-value { font-size: 9px; }
.steps-bars { gap: 4px; }

.steps-chat-hint {
  margin-top: var(--space-2);
}

.steps-burn { color: #d97823; font-size: 18px; font-weight: 650; margin: 12px 0 4px; }
.steps-chart { position: relative; }
.steps-burn-overlay { position: absolute; inset: 18px 0 auto; height: 110px; width: 100%; pointer-events: none; overflow: visible; }
.steps-burn-line { fill: none; stroke: #d97823; stroke-width: 3; vector-effect: non-scaling-stroke; }
.steps-burn-dot { fill: #d97823; }
.oura-card { margin: 20px 0; padding: 16px; background: var(--bg-secondary); border-radius: var(--radius-sm); }
.oura-card .section-heading { margin-top: 0; }
.oura-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.sheet-item-nutrients {
  display: block;
  color: var(--hint);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.sheet-item-amount-field {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: none;
}

/* Round-3 visual-QA defect 8: measured at 36 px and 32 px inside the meal
   sheet, both under the 44 px tap target the contract asks for everywhere
   else in this file. The VISUAL size stays calm - the amount field is
   still a small right-aligned number box and the ✕ is still a quiet grey
   glyph - the hit area grows around them (a taller box, a wider circle),
   which is the part a finger actually has to find. */
.sheet-item-amount-input {
  width: 4.5em;
  min-height: 44px;
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  padding: 0 var(--space-2);
  font-size: 14px;
  text-align: right;
}

.sheet-item-amount-unit {
  color: var(--hint);
  font-size: 13px;
}

.sheet-item-delete {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  border-radius: 999px;
  color: var(--hint);
  font-size: 13px;
}

.sheet-item-delete:hover,
.sheet-item-delete:focus-visible {
  background: var(--bg-secondary);
  color: var(--destructive);
}

.sheet-textarea {
  width: 100%;
  min-height: 64px;
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  padding: var(--space-2) var(--space-3);
  font-size: 14px;
  resize: vertical;
}

.field-help {
  color: var(--hint);
  font-size: 12px;
  line-height: 1.35;
  margin: var(--space-2) 0 0;
}

.sheet-date-input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  padding: 0 var(--space-3);
  font-size: 15px;
}

/* The native file input renders its own "Choose File / No file chosen" in the
   BROWSER's language - English on her phone, in an otherwise Russian screen.
   Keep the real input for the picker and for screen readers, but take it out of
   the layout and let its <label> be the visible, Russian, 48px-tall button
   (clicking a label opens the picker, so no script is involved). */
.sheet-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sheet-file-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  cursor: pointer;
}

.sheet-file-input:focus-visible + .sheet-file-button {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sheet-preview-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sheet-preview {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
}

/* Voice recording in the add sheet (v3). Neutral throughout: no red, no
   green, no "recording!" alarm colouring - the accent the rest of the panel
   already uses, plus motion, is what says "this is listening". */
.sheet-voice {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.voice-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.voice-record {
  flex: 1;
  min-height: 48px;
}

.voice-record[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.voice-timer {
  font-variant-numeric: tabular-nums;
  font-size: 17px;
  color: var(--hint);
  min-width: 48px;
  text-align: right;
}

/* "Near the limit" is emphasis, not an alarm - the same accent the rest of
   the panel uses, never a warning colour (project rule: no red/green
   meaning anywhere she looks). */
.voice-timer-near-limit {
  color: var(--accent);
  font-weight: 600;
}

.voice-level {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  overflow: hidden;
}

.voice-level-bar {
  width: 8px;
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transform: scaleY(0.15);
  transform-origin: center;
  transition: transform 90ms linear;
}

/* The fallback indicator when the browser gives us no analyser: the bar
   still moves, because "is it listening?" must be answerable by looking. */
.voice-level-pulse {
  animation: voice-pulse 1.1s ease-in-out infinite;
}

@keyframes voice-pulse {
  0%,
  100% {
    transform: scaleY(0.2);
  }
  50% {
    transform: scaleY(0.95);
  }
}

@media (prefers-reduced-motion: reduce) {
  .voice-level-bar {
    transition: none;
  }
  .voice-level-pulse {
    animation: none;
    transform: scaleY(0.6);
  }
}

.voice-player-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.voice-player {
  flex: 1;
  min-width: 0;
  height: 44px;
}

.sheet-progress {
  color: var(--hint);
  font-size: 14px;
  margin: 0;
}

.sheet-error {
  color: var(--destructive);
  font-size: 14px;
  margin: 0;
}

.sheet-action-row {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.sheet-action-row .button {
  flex: 1;
}

.button-destructive {
  color: var(--destructive);
}

.button-primary:disabled {
  opacity: 0.6;
}

/* Goal wizard steps (built entirely by app.js into #goal-sheet-body) share
   this vocabulary rather than inventing sheet-local classes. */
.wizard-step {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.wizard-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.wizard-input {
  min-height: 44px;
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  padding: 0 var(--space-3);
  font-size: 15px;
}

.wizard-choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.wizard-note {
  color: var(--hint);
  font-size: 13px;
  margin: 0;
}

.wizard-summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 15px;
  padding: var(--space-1) 0;
}

.wizard-summary-row span:first-child {
  color: var(--hint);
}

/* -------------------------------------------------------------------- */
/* Ещё screen (v2)                                                      */
/* -------------------------------------------------------------------- */

.section-heading {
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  margin: var(--space-5) 0 var(--space-2);
}

.section-heading:first-child {
  margin-top: 0;
}

.more-card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
}

.more-goal-summary {
  margin-bottom: var(--space-3);
  font-size: 14px;
  line-height: 1.6;
}

.more-goal-summary p {
  margin: 0;
}

.cycle-list {
  list-style: none;
  margin: 0 0 var(--space-3);
  padding: 0;
}

.cycle-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
  border-top: 1px solid var(--separator);
  font-size: 14px;
  text-align: left;
}

.cycle-row:first-child {
  border-top: none;
}

.help-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-line;
}

/* -------------------------------------------------------------------- */
/* Toast - one short neutral line (e.g. a 409 stale-reload notice), auto */
/* dismissed; never a colour-coded status, just the same hint tone used  */
/* everywhere else.                                                     */
/* -------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: var(--space-4);
  right: var(--space-4);
  bottom: calc(64px + env(safe-area-inset-bottom, 0) + var(--space-3));
  z-index: 40;
  margin: 0 auto;
  max-width: 480px;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  font-size: 14px;
  text-align: center;
  box-shadow: 0 4px 16px rgba(15, 17, 20, 0.22);
}

/* -------------------------------------------------------------------- */
/* Unknown-result bar - shown when a write's response was lost, so the   */
/* outcome is genuinely unknown. Sits ABOVE the sheets (z-index 50), so  */
/* she sees it while the add sheet is still open, and carries the one    */
/* action that is safe in that state: [Проверить], which re-sends the    */
/* same request_id. Same neutral surface as the toast - never a colour-  */
/* coded error.                                                          */
/* -------------------------------------------------------------------- */

.unknown-result {
  position: fixed;
  left: var(--space-4);
  right: var(--space-4);
  bottom: calc(64px + env(safe-area-inset-bottom, 0) + var(--space-3));
  z-index: 50;
  margin: 0 auto;
  max-width: 480px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  font-size: 15px;
  box-shadow: 0 4px 16px rgba(15, 17, 20, 0.22);
}

.unknown-result button {
  min-height: 44px;
  flex: 0 0 auto;
}

/* The weight-confirm bar (round-2 verifier HIGH defect) has the same shape
   and the same "above the sheets" job, but the two can be on screen at
   once - a weight still waiting for her tap, and then a later write whose
   answer was lost - so it sits one bar higher instead of on top. */
.unknown-result-stacked {
  bottom: calc(64px + env(safe-area-inset-bottom, 0) + var(--space-3) + 76px);
}

/* It also asks a real question rather than offering one action, so the
   question gets its own line and the two answers share the row below it
   evenly - never one wide button and one narrow one. */
.unknown-result-stacked span {
  flex: 1 1 100%;
}

.unknown-result-stacked button {
  flex: 1 1 0;
}

/* -------------------------------------------------------------------- */
/* Lazy-loading thumbnail skeleton (IntersectionObserver hasn't resolved */
/* the blob yet) - a plain pulse, not a spinner, so a slow connection    */
/* doesn't read as broken.                                               */
/* -------------------------------------------------------------------- */

@media (prefers-reduced-motion: no-preference) {
  .meal-thumb-loading {
    animation: thumb-pulse 1.2s ease-in-out infinite;
  }
}

@keyframes thumb-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

/* -------------------------------------------------------------------- */
/* Small phones                                                         */
/* -------------------------------------------------------------------- */

@media (max-width: 360px) {
  .hero-value {
    font-size: 36px;
  }

  .weight-input {
    font-size: 26px;
  }

  .sheet-panel {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }
}
