* { box-sizing: border-box; }
body {
  margin: 0;
background: #101211;
color: #edf3ef;
  font-family: Arial, sans-serif;
}
.app {
  max-width: 480px;
  min-height: 100vh;
  margin: auto;
  padding: 25px 18px 100px;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.logo { color: #42c991; font-size: 30px; font-weight: bold; }
.subtitle { color: #98aaa0; font-size: 13px; margin-top: 5px; }
.card {
background: #1c2420;
  border-radius: 22px;
  padding: 22px;
  margin-top: 20px;
  box-shadow: 0 5px 20px #183b2510;
}
.card h2 { margin-top: 0; font-size: 19px; }
.muted { color: #75847b; font-size: 14px; }
.calories { font-size: 32px; font-weight: bold; margin: 15px 0; }
.calories span { font-size: 16px; color: #8a9890; }
.bar {
  height: 11px;
  background: #e7eee9;
  border-radius: 20px;
  overflow: hidden;
}
.fill {
  height: 100%;
width: 0%;
  background: #23966b;
  border-radius: 20px;
}
.macros { display: flex; justify-content: space-between; margin-top: 20px; }
.macro { font-size: 13px; }
.macro strong { display: block; margin-top: 7px; font-size: 15px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.action {
  background: white;
  border: none;
  border-radius: 18px;
  padding: 22px 12px;
  text-align: left;
  font-size: 15px;
  cursor: pointer;
}
.action .emoji { font-size: 27px; display: block; margin-bottom: 12px; }
.action small { color: #8a9890; display: block; margin-top: 7px; }
nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  justify-content: space-around;
  background: white;
  padding: 15px 4px 22px;
  border-top: 1px solid #e9efeb;
}
nav button {
  background: none;
  border: none;
  font-size: 11px;
  color: #84928a;
  cursor: pointer;
  flex: 1;
}
nav button span { display: block; font-size: 23px; margin-bottom: 5px; }
nav button.active { color: #23966b; font-weight: bold; }
.page { display: none; }
.page.active { display: block; }
#manualProductModal label {
    display: block;
    font-size: 14px;
    color: #75847b;
    margin-top: 12px;
    margin-bottom: 5px;
}

#manualProductModal input {
    width: 100%;
    padding: 12px;
    border: 1px solid #e3ebe6;
    border-radius: 12px;
    background: #f3f6f4;
    color: #172b22;
    font-size: 16px;
    box-sizing: border-box;
}

#manualProductModal h3 {
    margin-top: 20px;
    margin-bottom: 8px;
    font-size: 16px;
}

#manualPreview {
    background: #eaf5ef;
    color: #23966b;
    padding: 14px;
    border-radius: 12px;
    margin-top: 16px;
    font-size: 14px;
    line-height: 1.6;
}

#manualProductModal button {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    margin-top: 10px;
    cursor: pointer;
    background: #f3f6f4;
    color: #75847b;
}

#manualProductModal #manualConfirm {
    background: #23966b;
    color: white;
    font-weight: bold;
}
.product-tab {
    flex: 1;
    min-width: 0;
    padding: 12px 4px;
    border: none;
    border-radius: 10px;
    background: #f3f6f4;
    color: #75847b;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.product-tab.active {
    background: #23966b;
    color: white;
}

#productResults {
    max-height: 280px;
    overflow-y: auto;
}
/* Тёмная тема FORMA */

body {
    color-scheme: dark;
}

.muted {
    color: #98aaa0 !important;
}

nav {
    background: #1c2420 !important;
    border-color: #303d35 !important;
}

nav button {
    color: #98aaa0;
}

nav button.active {
    color: #42c991;
}

#productModal > div,
#weightModal > div,
#manualProductModal > div {
    background: #1c2420 !important;
    color: #edf3ef !important;
}

input, select, textarea {
    background: #252f29 !important;
    color: #edf3ef !important;
    border-color: #39483e !important;
}

input::placeholder {
    color: #98aaa0;
}

.product-tab {
    background: #303d35;
    color: #98aaa0;
}

.product-tab.active {
    background: #23966b;
    color: white;
}

#manualPreview {
    background: #233b30;
    color: #42c991;
}

#manualProductModal label {
    color: #98aaa0;
}

#manualProductModal button {
    background: #303d35;
    color: #edf3ef;
}

#manualProductModal #manualConfirm {
    background: #23966b;
    color: white;
}
#mealsList .meal-details-content > button {
    background: transparent !important;
    color: #42c991 !important;
    border-color: #42c991 !important;
}

.card [style*="color:#23966b"],
.card [style*="color: #23966b"] {
    color: #42c991 !important;
}

.card [style*="border-top"] {
    border-top-color: #39483e !important;
}

.food-product span {
    color: #98aaa0 !important;
}

hr {
    border-color: #39483e;
}
#productModal button[onclick],
#weightModal button[onclick],
#manualProductModal button[onclick] {
    background: #303d35 !important;
    color: #b4c4ba !important;
}

#weightModal .weight-option {
    background: #303d35;
    color: #edf3ef;
    border-color: #39483e;
}

.weight-unit-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

#productWeightUnit {
    border: 1px solid #39483e;
    border-radius: 10px;
    padding: 8px;
    font-size: 16px;
}

.portion-sizes:not([hidden]) {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.portion-sizes button {
    flex: 1 0 auto;
    padding: 10px 6px;
    border: 1px solid #39483e;
    border-radius: 10px;
    appearance: none;
    background: #233b30;
    color: #42c991;
    cursor: pointer;
}

.portion-sizes button:focus-visible {
    outline: 2px solid #42c991;
    outline-offset: 2px;
}

.product-source a,
.product-label-link {
    color: #42c991;
}

.barcode-overlay:not([hidden]) {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: var(--forma-viewport-top, 0px) 0 auto;
    height: var(--forma-viewport-height, 100dvh);
    z-index: 10000;
    background: rgba(0, 0, 0, 0.75);
    padding: 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.barcode-panel {
    flex: none;
    width: 100%;
    max-width: 420px;
    margin: auto;
    padding: 20px;
    border-radius: 22px;
    background: #1c2420;
}

.barcode-panel h2 { margin: 0 0 12px; font-size: 20px; }
.barcode-panel video {
    width: 100%;
    max-height: 240px;
    border-radius: 12px;
    background: #101211;
    object-fit: contain;
}

.barcode-panel input[type="text"],
.barcode-primary,
.barcode-secondary {
    width: 100%;
    padding: 12px;
    margin-top: 8px;
    border: 1px solid #39483e;
    border-radius: 12px;
    font: inherit;
}

.barcode-primary,
.barcode-secondary { cursor: pointer; }
.barcode-primary { background: #23966b; color: white; font-weight: 600; }
.barcode-secondary { background: #233b30; color: #42c991; }

.product-label-link {
    display: inline-block;
    margin-top: 6px;
    font-size: 12px;
}

#productResults > div {
    border-bottom-color: #39483e !important;
}

#productResults [style*="color:#75847b"],
#productResults [style*="color: #75847b"] {
    color: #98aaa0 !important;
}
body {
    color: #c5d3ca;
}

#productModal > div,
#weightModal > div,
#manualProductModal > div {
    color: #c5d3ca !important;
}

input, select, textarea {
    color: #c5d3ca !important;
}

#weightModal .weight-option {
    background: #303d35 !important;
    color: #42c991 !important;
    border-color: #39483e !important;
}



#previewCalories {
    color: #42c991 !important;
}

#previewProtein,
#previewFat,
#previewCarbs {
    color: #c5d3ca !important;
}

#confirmProductButton,
#manualConfirm,
#manualProductButton {
    color: #dce8e0 !important;
}
/* Быстрые действия */
#home .action {
    background: #1b241e !important;
    color: #c5d3ca !important;
    border: 1px solid #303d35;
    padding: clamp(6px, calc((100dvh - 600px) / 10), 22px) 12px;
}

#home .action small {
    color: #98afa3 !important;
}

/* Полоска прогресса калорий */
#home .bar {
    background: #303d35 !important;
}

#home .bar .fill {
    background: #23966b !important;
}
/* Цвет иконок продуктов */
.food-product button {
    color: #98aaa0 !important;
}

.food-product button svg {
    color: #98aaa0 !important;
    stroke: #98aaa0 !important;
}
#weightModal {
    box-sizing: border-box;
    max-height: var(--forma-viewport-height, 100dvh);
    overflow-y: auto;
}

#weightModal > div {
    box-sizing: border-box;
    flex-shrink: 0;
}
body:has(#weightModal[style*="display: flex"]),
body:has(#weightModal[style*="display:flex"]) {
    overflow: hidden;
}

#weightModal {
    overscroll-behavior: contain;
    touch-action: pan-y;
}

#weightModal > div {
    overscroll-behavior: contain;
}

body:has(#manualProductModal[style*="display: flex"]) nav,
body:has(#manualProductModal[style*="display:flex"]) nav {
    visibility: hidden;
}

body:has(#manualProductModal[style*="display: flex"]),
body:has(#manualProductModal[style*="display:flex"]) {
    overflow: hidden;
}

#manualProductModal > div {
    overscroll-behavior: contain;
}
/* Блокировка фоновой прокрутки */
html:has(#productModal[style*="display: flex"]),
html:has(#productModal[style*="display:flex"]),
html:has(#dishModal[style*="display: flex"]),
html:has(#dishModal[style*="display:flex"]),
body:has(#productModal[style*="display: flex"]),
body:has(#productModal[style*="display:flex"]),
body:has(#dishModal[style*="display: flex"]),
body:has(#dishModal[style*="display:flex"]) {
    overflow: hidden !important;
    overscroll-behavior: none;
}

#productModal,
#dishModal,
#productModal > div,
#dishModal > div,
#productResults {
    overscroll-behavior: contain;
}
#mealsList .card h2 button,
#mealsList .food-product button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    width: 44px !important;
    height: 44px !important;
    padding: 6px !important;
    margin: 0 !important;
    background: transparent !important;
    border: none !important;
    color: #98aaa0 !important;
}


#mealsList .card h2 button svg,
#mealsList .food-product button svg {
    width: 22px !important;
    height: 22px !important;
    display: block;
}
/* Иконки в списке продуктов */
#productResults button:has(svg) {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: #98aaa0 !important;
}

#productResults button svg {
    color: #98aaa0 !important;
    stroke: #98aaa0 !important;
    width: 22px !important;
    height: 22px !important;
}
#mealsList .food-product {
    text-align: left;
}

#mealsList .food-product span {
    text-align: left;
}

#mealsList .food-product button:first-of-type {
    margin-left: auto !important;
}

#mealsList .food-product {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

#mealsList .food-product span {
    width: 100%;
}

#copyMealModal label {
    display: block;
    font-size: 15px;
    margin-top: 16px;
    margin-bottom: 8px;
    color: #c5d3ca;
}

#copyMealModal input {
    display: block;
    width: 100% !important;
    min-width: 0;
    min-height: 48px;
    padding: 12px;
    box-sizing: border-box;
    background: #233b30;
    color: #c5d3ca;
    border: 1px solid #43594c;
    border-radius: 12px;
    font-size: 16px;
    color-scheme: dark;
}

#copyMealModal input:focus {
    outline: none;
    border-color: #42c991;
    box-shadow: 0 0 0 1px #42c991;
}

#copyMealModal button,
#copyConflictModal button {
    display: block;
    width: 100% !important;
    min-height: 48px;
    padding: 14px !important;
    box-sizing: border-box;
    border-radius: 12px;
    font-size: 17px !important;
    font-weight: 600;
    margin-top: 12px;
    cursor: pointer;
}

#copyMealConfirm {
    background: #23966b !important;
    color: white !important;
    border: none !important;
}

#copyMealModal button:last-of-type {
    background: transparent !important;
    color: #98aaa0 !important;
    border: 1px solid #43594c !important;
}

#copyConflictModal button span {
    font-size: 14px !important;
    font-weight: 400;
    line-height: 1.4;
    margin-top: 6px !important;
}

#copyConflictModal select {
    font-size: 16px;
    min-height: 48px;
}

#copyMealModal,
#copyConflictModal {
    max-height: var(--forma-viewport-height, 100dvh);
    overflow-y: auto;
}

#copyMealDate {
    height: 48px !important;
    min-height: 48px !important;
    padding: 0 12px !important;
    box-sizing: border-box;
    line-height: normal !important;
    font-size: 16px !important;
}

#copyMealDate::-webkit-date-and-time-value {
    margin: 0;
    padding: 0;
    line-height: 46px;
    text-align: left;
}
#dishModal label {
    display: block;
    font-size: 16px;
    color: #c5d3ca;
    margin-top: 18px;
    margin-bottom: 8px;
}

#dishModal input {
    display: block;
    width: 100%;
    min-height: 52px;
    padding: 14px;
    box-sizing: border-box;
    background: #232e28;
    color: #c5d3ca;
    border: 1px solid #46584e;
    border-radius: 12px;
    font-size: 16px;
    outline: none;
}

#dishModal input:focus {
    border-color: #42c991;
    outline: none;
    box-shadow: none;
}

#dishModal input::placeholder {
    color: #98aaa0;
}

#dishModal button {
    font-size: 17px !important;
    min-height: 50px;
    box-sizing: border-box;
}

#dishModal {
    max-height: var(--forma-viewport-height, 100dvh);
    overscroll-behavior: contain;
}

#dishModal > div {
    max-height: 100% !important;
    flex-shrink: 0;
    overflow-y: auto;
}
#dishModal input[type="checkbox"] {
    accent-color: #23966b;
    width: 22px;
    height: 22px;
    min-height: 22px;
    padding: 0;
    margin: 0 8px 0 0;
    display: inline-block;
    vertical-align: middle;
    cursor: pointer;
}
body:has(#calendarModal[style*="display: flex"]),
body:has(#calendarModal[style*="display:flex"]) {
    overflow: hidden !important;
}

#calendarModal,
#calendarModal > div {
    overscroll-behavior: contain;
    touch-action: pan-y;
}
/* Единый стиль активных полей ввода */
input:not([type="checkbox"]):not([type="radio"]):focus,
textarea:focus,
select:focus {
    outline: none !important;
    border-color: #42c991 !important;
    box-shadow: 0 0 0 1px #42c991 !important;
    caret-color: #42c991;
}

input,
textarea,
select {
    -webkit-tap-highlight-color: transparent;
}

input::selection,
textarea::selection {
    background: #23966b;
    color: #ffffff;
}
/* Единый стиль иконок ингредиентов */
#dishIngredients button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    flex-shrink: 0;
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
    color: #98aaa0 !important;
}

#dishIngredients button svg {
    width: 22px !important;
    height: 22px !important;
    stroke: currentColor;
    display: block;
}
/* Адаптивный главный экран FORMA */

.app:has(#home.active) {
    min-height: var(--forma-viewport-height, 100dvh);
    padding-top: clamp(8px, 2dvh, 25px);
    padding-bottom: 85px;
}

#home .card {
    margin-top: clamp(8px, 1.5dvh, 20px);
    padding: clamp(12px, 2dvh, 22px) 22px;
}

#home .card h2 {
    margin-bottom: clamp(8px, 1.5dvh, 16px);
}

#home .calories {
    margin: clamp(6px, 1dvh, 15px) 0;
}

#home .macros {
    margin-top: clamp(8px, 1.5dvh, 20px);
}

#home > h3 {
    margin-top: clamp(10px, 2dvh, 30px) !important;
    margin-bottom: clamp(8px, 1.5dvh, 18px);
}

#home .actions {
    gap: clamp(6px, 1dvh, 12px);
}

#home .action {
    padding: clamp(6px, calc((100dvh - 600px) / 10), 22px) 12px;
}

#home .action .emoji {
    margin-bottom: clamp(4px, 0.8dvh, 12px);
}

#home .action small {
    margin-top: clamp(3px, 0.6dvh, 7px);
}
/* Independent meal disclosure; totals remain outside the collapsible area. */
.meal-header { display: flex; align-items: flex-start; gap: 4px; }
.meal-header h2 { flex: 1; min-width: 0; overflow-wrap: anywhere; margin-bottom: 0; }
.meal-toggle { flex: 0 0 44px; width: 44px; height: 44px; padding: 0; border: 0; background: transparent; color: #98aaa0; cursor: pointer; display: grid; place-items: center; }
.meal-toggle svg { transform: rotate(180deg); transition: transform 180ms ease; }
.meal-collapsed .meal-toggle svg { transform: rotate(0); }
.meal-details { display: grid; grid-template-rows: 1fr; transition: grid-template-rows 180ms ease; }
.meal-details-content { min-height: 0; overflow: hidden; }
.meal-collapsed .meal-details { grid-template-rows: 0fr; }
.meal-collapsed .meal-details-content { visibility: hidden; transition: visibility 0s 180ms; }
#mealsList .meal-summary { margin-bottom: 0 !important; }
@media (prefers-reduced-motion: reduce) { .meal-details, .meal-toggle svg, .meal-collapsed .meal-details-content { transition: none; } }

/* Prevent native scroll anchoring from moving the tapped meal header. */
html:has(#food.active) { overflow-anchor: none; }
#food::after { content: ""; display: block; height: var(--meal-scroll-reserve, 0px); pointer-events: none; }
