:root {
  color-scheme: light;
  --bg: #f4f6f1;
  --card: #ffffff;
  --ink: #1c2923;
  --muted: #68756e;
  --line: #dfe6df;
  --soft: #edf3ed;
  --accent: #2f6b54;
  --accent-dark: #245340;
  --accent-soft: #e1eee5;
  --gold: #b87827;
  --danger: #a13d36;
  --shadow: 0 8px 28px rgba(32, 55, 43, .055);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
a { color: var(--accent); }
button, a, input, select, summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid rgba(47, 107, 84, .3); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.topbar { min-height: 76px; padding: 12px max(24px, calc((100vw - 1240px)/2)); display: flex; align-items: center; gap: 28px; background: rgba(255,255,255,.88); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(14px); }
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 11px; flex: none; }
.brand-mark, .bot-avatar { display: grid; place-items: center; background: var(--accent); color: white; font-weight: 750; letter-spacing: -.04em; }
.brand-mark { width: 44px; height: 44px; border-radius: 14px; font-size: 18px; }
.brand strong { display: block; font-size: 16px; line-height: 1.25; }
.brand small { display: block; color: var(--muted); margin-top: 2px; font-size: 12px; }
.main-nav { display: flex; align-items: center; gap: 5px; margin: auto; }
.nav-button { border: 0; background: transparent; color: var(--muted); padding: 9px 14px; border-radius: 10px; font-weight: 550; }
.nav-button:hover { background: var(--soft); color: var(--ink); }
.nav-button.active { background: var(--accent-soft); color: var(--accent-dark); }
.nav-button span { display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 4px; margin-left: 3px; border-radius: 10px; background: var(--accent); color: white; font-size: 11px; }
.core-status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.core-status i { width: 7px; height: 7px; border-radius: 50%; background: #4b9472; box-shadow: 0 0 0 4px #e4f1e8; }
.core-status.loading i { background: var(--gold); box-shadow: 0 0 0 4px #f6ecdd; animation: pulse 1.4s infinite; }
.core-status.error { color: var(--danger); }
.core-status.error i { background: var(--danger); box-shadow: 0 0 0 4px #f5e4e2; }
@keyframes pulse { 50% { opacity: .35; } }

main { max-width: 1240px; margin: 0 auto; padding: 36px 24px 60px; }
.view { animation: enter .22s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 36px; margin: 0 0 28px; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 750; letter-spacing: .09em; text-transform: uppercase; margin: 0 0 6px; }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(28px, 3.2vw, 42px); line-height: 1.12; letter-spacing: -.035em; margin-bottom: 10px; }
h2 { font-size: 20px; line-height: 1.25; letter-spacing: -.015em; margin-bottom: 0; }
.hero > div:first-child { max-width: 690px; }
.hero p:last-child { color: var(--muted); max-width: 630px; margin: 0; font-size: 16px; }
.hero-example { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; max-width: 360px; padding-bottom: 4px; color: var(--muted); font-size: 12px; }
.hero-example span { background: white; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
.hero-example b { font-weight: 400; color: #9ba59f; }
.hero-example strong { color: var(--accent); white-space: nowrap; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 24px; align-items: start; }
.main-column { display: grid; gap: 20px; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.bot-card, .catalog-card, .meal-card { padding: 22px; }
.bot-message { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 17px; }
.bot-avatar { flex: none; width: 36px; height: 36px; border-radius: 11px; font-size: 13px; }
.bot-message strong { font-size: 15px; }
.bot-message p { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
.quick-form { display: flex; gap: 9px; }
input, select { border: 1px solid #d6dfd7; border-radius: 10px; background: white; color: var(--ink); min-height: 42px; padding: 9px 12px; }
input::placeholder { color: #939e97; }
input:hover, select:hover { border-color: #b9c8bc; }
input:focus, select:focus { border-color: var(--accent); outline: 3px solid rgba(47,107,84,.1); }
.quick-form input { flex: 1; min-width: 0; padding-left: 15px; }
.primary, .secondary { min-height: 42px; border-radius: 10px; padding: 9px 16px; font-weight: 650; border: 1px solid transparent; }
.primary { background: var(--accent); color: white; }
.primary:hover:not(:disabled) { background: var(--accent-dark); }
.secondary { background: white; color: var(--accent); border-color: #bfcfc2; }
.secondary:hover:not(:disabled) { background: var(--soft); }
.text-button { border: 0; background: none; padding: 3px; color: var(--accent); font-weight: 600; font-size: 13px; }
.text-button:hover { text-decoration: underline; }
.danger { color: var(--danger); }
.examples { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; font-size: 12px; }
.examples > span { color: var(--muted); margin-right: 2px; }
.examples button { border: 0; background: var(--soft); color: var(--accent-dark); border-radius: 7px; padding: 4px 8px; }
.examples button:hover { background: var(--accent-soft); }
.parse-notices { display: grid; gap: 4px; }
.parse-notices:not(:empty) { margin-top: 12px; padding: 10px 12px; border-radius: 9px; background: #f5f8f4; color: var(--muted); font-size: 12px; }
.parse-notices .notice-error { color: var(--danger); }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 17px; }
.section-heading .eyebrow { margin-bottom: 4px; }
.filters { display: grid; grid-template-columns: 1fr 210px; gap: 9px; }
.filters select { width: 100%; }
.search-field { position: relative; }
.search-field svg { position: absolute; left: 12px; top: 12px; width: 18px; height: 18px; fill: none; stroke: #849088; stroke-width: 1.7; }
.search-field input { width: 100%; padding-left: 39px; }
.product-results { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; margin-top: 14px; }
.product-option { display: flex; align-items: center; text-align: left; gap: 10px; min-width: 0; border: 1px solid var(--line); background: white; border-radius: 11px; padding: 11px 12px; }
.product-option:hover { border-color: #9db9a5; background: #f8fbf8; }
.product-option > span { min-width: 0; flex: 1; }
.product-option strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.product-option small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; font-size: 11px; }
.product-option b { display: grid; place-items: center; width: 25px; height: 25px; flex: none; border-radius: 8px; background: var(--soft); color: var(--accent); font-size: 18px; font-weight: 450; }
.product-option.custom-product b { color: var(--gold); background: #f8f0e4; }
.no-products { color: var(--muted); padding: 14px 4px 2px; grid-column: 1/-1; }
.empty-meal { text-align: center; color: var(--muted); padding: 20px 10px 12px; }
.empty-meal p { margin: 8px 0 0; font-size: 13px; }
.empty-icon { display: grid; place-items: center; width: 36px; height: 36px; border: 1px dashed #b7c5b9; color: var(--accent); border-radius: 50%; margin: auto; font-size: 20px; }
.meal-rows { display: grid; gap: 0; }
.meal-row { display: grid; grid-template-columns: minmax(150px, 1fr) 86px minmax(120px, .7fr) 68px 28px; gap: 9px; align-items: center; padding: 13px 0; border-top: 1px solid #edf0ec; }
.meal-row:first-child { border-top: 0; padding-top: 0; }
.meal-product { min-width: 0; }
.meal-product strong { display: block; font-size: 13px; line-height: 1.35; }
.meal-product small { display: block; color: var(--muted); font-size: 10px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal-row input, .meal-row select { width: 100%; min-height: 38px; padding: 7px 8px; font-size: 13px; }
.meal-xe { text-align: right; color: var(--accent); white-space: nowrap; font-size: 14px; }
.icon-button { border: 0; background: none; color: var(--muted); width: 30px; height: 30px; border-radius: 8px; font-size: 22px; line-height: 1; }
.icon-button:hover { background: #f6ecea; color: var(--danger); }

.summary-card { padding: 24px; position: sticky; top: 98px; }
.total { display: flex; align-items: baseline; gap: 9px; margin: 2px 0 8px; }
.total strong { color: var(--accent); font-size: 58px; line-height: 1.05; letter-spacing: -.055em; font-weight: 720; }
.total span { color: var(--accent); font-size: 22px; font-weight: 650; }
.carbs-total { display: flex; justify-content: space-between; padding: 11px 0; border-top: 1px solid var(--line); font-size: 14px; }
.carbs-total strong { font-weight: 650; }
.xe-setting { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; margin-bottom: 14px; }
.xe-setting select { min-height: 25px; padding: 1px 3px; border-radius: 6px; font-size: 11px; }
.xe-setting > span { display: inline-grid; place-items: center; border: 1px solid #bbc6bd; border-radius: 50%; width: 15px; height: 15px; margin-left: 2px; cursor: help; }
.category-totals { display: grid; gap: 7px; }
.category-totals:not(:empty) { padding: 13px 0; border-top: 1px solid var(--line); }
.category-line { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; font-size: 11px; color: var(--muted); }
.category-line strong { color: var(--ink); font-size: 12px; white-space: nowrap; }
.calc-error { color: var(--danger); font-size: 12px; }
.calc-error:not(:empty) { padding: 10px; background: #fbefed; border-radius: 8px; margin: 10px 0; }
.insulin-details { margin-top: 16px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.insulin-details summary { list-style: none; cursor: pointer; padding: 15px 23px 15px 0; position: relative; }
.insulin-details summary::-webkit-details-marker { display: none; }
.insulin-details summary::after { content: '+'; position: absolute; right: 2px; top: 18px; color: var(--accent); font-size: 20px; }
.insulin-details[open] summary::after { content: '−'; }
.insulin-details summary span { display: block; font-weight: 650; font-size: 14px; }
.insulin-details summary small { color: var(--muted); font-size: 11px; }
.insulin-body { padding: 0 0 16px; }
.insulin-body > label:not(.check-label), .correction-fields label, dialog label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; margin-bottom: 10px; }
.insulin-body input, dialog input { width: 100%; min-height: 38px; font-size: 13px; }
.check-label { display: flex; align-items: flex-start; gap: 8px; color: var(--ink); font-size: 12px; margin: 12px 0; }
.check-label input { width: 16px; height: 16px; min-height: 0; margin: 1px 0 0; accent-color: var(--accent); }
.correction-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.correction-fields label:last-child { grid-column: 1/-1; }
.medical-note { color: var(--muted); font-size: 10px; line-height: 1.5; margin: 8px 0 12px; }
.dose-result { background: var(--soft); border-radius: 10px; padding: 10px 12px; }
.dose-result > div { display: flex; justify-content: space-between; padding: 4px 0; font-size: 12px; }
.dose-result .dose-total { border-top: 1px solid #cbdacf; margin-top: 5px; padding-top: 9px; color: var(--accent-dark); }
.dose-total strong { font-size: 16px; }
.summary-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.action-note { color: var(--accent); text-align: center; font-size: 11px; margin: 8px 0 0; min-height: 16px; }
.privacy-note { display: flex; justify-content: center; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; margin: 12px 0 0; }
.privacy-note svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.5; }

.narrow-view { max-width: 900px; margin: 0 auto; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 25px; }
.page-heading p:last-child { color: var(--muted); margin: 0; }
.big-empty { padding: 55px 24px; text-align: center; }
.big-empty > span { color: var(--accent); font-size: 38px; }
.big-empty h2 { margin: 10px 0; }
.big-empty p { color: var(--muted); margin-bottom: 22px; }
.history-list { display: grid; gap: 12px; }
.history-item { padding: 20px 22px; }
.history-top { display: flex; justify-content: space-between; gap: 16px; }
.history-date { color: var(--muted); font-size: 12px; }
.history-total { color: var(--accent); font-size: 23px; white-space: nowrap; }
.history-products { color: var(--muted); margin: 8px 0 12px; font-size: 13px; }
.history-actions { display: flex; gap: 16px; }
.help-card { padding: 28px 32px; }
.help-card h2 { margin: 25px 0 12px; }
.help-card h2:first-child { margin-top: 0; }
.help-card p { color: #536159; }
.formula { background: var(--accent-soft); color: var(--accent-dark); border-radius: 11px; padding: 16px 18px; font: 600 17px/1.65 ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.secondary-formula { background: var(--soft); font-size: 14px; }
.warning { margin-top: 22px; padding: 15px 17px; border-left: 3px solid var(--gold); background: #fbf5e9; color: #6b542f; font-size: 13px; }

footer { max-width: 1240px; margin: 0 auto; padding: 22px 24px 30px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 20px; color: var(--muted); font-size: 11px; }
dialog { width: min(440px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 18px; padding: 0; color: var(--ink); box-shadow: 0 25px 80px rgba(20,40,28,.2); }
dialog::backdrop { background: rgba(20,35,27,.38); backdrop-filter: blur(3px); }
dialog form { padding: 24px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; }
.full-width { width: 100%; }
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 50; background: #203c2e; color: white; border-radius: 11px; padding: 11px 18px; box-shadow: 0 8px 30px rgba(0,0,0,.18); font-size: 13px; animation: enter .18s ease-out; }

@media (max-width: 1050px) {
  .topbar { gap: 16px; }
  .core-status span { display: none; }
  .workspace { grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; }
  .hero-example { display: none; }
  .meal-row { grid-template-columns: minmax(120px, 1fr) 75px 115px 62px 25px; gap: 6px; }
}
@media (max-width: 820px) {
  .topbar { padding: 10px 16px; flex-wrap: wrap; gap: 8px 14px; position: relative; }
  .brand { margin-right: auto; }
  .brand-mark { width: 38px; height: 38px; border-radius: 12px; }
  .main-nav { order: 3; width: 100%; justify-content: center; border-top: 1px solid var(--line); padding-top: 7px; }
  .nav-button { flex: 1; padding: 7px 8px; }
  main { padding: 25px 16px 45px; }
  .workspace { grid-template-columns: 1fr; }
  .summary-card { position: static; }
  .hero { margin-bottom: 22px; }
  .hero h1 { font-size: 32px; }
  .meal-row { grid-template-columns: minmax(130px, 1fr) 80px minmax(110px,.8fr) 65px 28px; }
}
@media (max-width: 560px) {
  .brand strong { font-size: 14px; }
  .brand small { font-size: 10px; }
  .core-status { display: none; }
  .nav-button { font-size: 12px; }
  h1 { font-size: 29px; }
  .hero p:last-child { font-size: 14px; }
  .bot-card, .catalog-card, .meal-card { padding: 17px; }
  .quick-form { display: grid; grid-template-columns: 1fr; }
  .quick-form .primary { width: 100%; }
  .examples > span { width: 100%; }
  .filters { grid-template-columns: 1fr; }
  .product-results { grid-template-columns: 1fr; }
  .section-heading { align-items: center; }
  .section-heading h2 { font-size: 18px; }
  .meal-row { grid-template-columns: 1fr 74px 28px; gap: 8px; padding: 14px 0; }
  .meal-product { grid-column: 1/3; }
  .meal-row > .remove-row { grid-column: 3; grid-row: 1; }
  .meal-row > .quantity-input { grid-column: 1; grid-row: 2; }
  .meal-row > .unit-select { grid-column: 2/4; grid-row: 2; }
  .meal-xe { grid-column: 1/4; grid-row: 3; text-align: left; padding-left: 2px; }
  .summary-card { padding: 22px; }
  .total strong { font-size: 52px; }
  .page-heading { display: block; }
  .help-card { padding: 22px 18px; }
  .formula { font-size: 13px; padding: 13px; }
  footer { display: grid; gap: 5px; padding: 20px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; }
}
