:root {
  color-scheme: light;
  --bg: #ffffff; --card: #ffffff; --ink: #1c2a12; --muted: #56654a; --line: #e3e8dc;
  --brand: #7DBE2B; --brand-d: #3F7A12; --brand-soft: #e6f3d0; --on-brand: #ffffff;
  --good: #2f7d1d; --good-bg: #e3f4d8; --warn: #8a5a00; --warn-bg: #fff1cf; --bad: #b3261e; --bad-bg: #fde4e1;
  --chart: #3F7A12; --chart-2: #7DBE2B; --grid: #e4ead9; --shadow: 0 1px 2px rgba(30,50,10,.06), 0 4px 14px rgba(30,50,10,.06);
  --radius: 16px; --tabh: 62px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  padding-bottom: calc(var(--tabh) + env(safe-area-inset-bottom));
}
body.noTabs { padding-bottom: 24px; }
.top { position: sticky; top: 0; z-index: 5; background: var(--card); color: var(--ink); border-bottom: 1px solid var(--line); padding: calc(8px + env(safe-area-inset-top)) 0 8px; }
.top .bar { display: flex; align-items: center; gap: 10px; max-width: 640px; margin-inline: auto; padding-inline: 16px; }
.top .bar img { width: 34px; height: 34px; object-fit: contain; }
.top h1 { margin: 0; font-size: 18px; font-weight: 650; }
.logout { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border: 1.5px solid var(--line);
  border-radius: 10px; background: var(--card); color: var(--muted); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.logout:hover { color: var(--bad); border-color: var(--bad); }
.logout[hidden] { display: none; }
.logout svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
main { max-width: 640px; margin: 0 auto; padding: 16px; outline: none; }
#view:focus, #view:focus-visible { outline: none; }
h2 { font-size: 20px; margin: 0 0 8px; }
h3 { font-size: 16px; margin: 0 0 6px; }
p { margin: 0 0 10px; }
a { color: var(--brand-d); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 380px) { .grid2 { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card.accent { background: var(--brand-soft); border-color: transparent; }
.big { font-size: 34px; font-weight: 700; line-height: 1.1; letter-spacing: -.5px; }
.stat { display: flex; flex-direction: column; }
.stat .k { font-size: 12px; color: var(--muted); text-transform: none; }
.stat .v { font-size: 20px; font-weight: 650; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--brand-soft); color: var(--brand-d); white-space: nowrap; }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.ml { background: #e6e9ff; color: #3a3fa8; }

.alert { border-radius: 12px; padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.info { background: var(--brand-soft); color: var(--ink); }

label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
input, select, button { font: inherit; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=url], input[type=time], select {
  width: 100%; min-height: 46px; padding: 8px 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.field { margin-bottom: 12px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
.check input { flex: none; width: 22px; height: 22px; margin-top: 2px; accent-color: var(--brand-d); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border: 0; border-radius: 12px; background: var(--brand-d); color: var(--on-brand); font-weight: 650; cursor: pointer; text-decoration: none; }
.btn:hover { filter: brightness(1.08); }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--brand-d); border: 1.5px solid var(--brand-d); }
.btn.soft { background: var(--brand-soft); color: var(--brand-d); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; filter: none; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; min-width: 32px; min-height: 32px; }
.icon-btn:hover { color: var(--bad); }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--line); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 10px; border-radius: 10px; font-weight: 650; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs[hidden] { display: none; }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--tabh); font-size: 11.5px; color: var(--muted); text-decoration: none; font-weight: 600; }
.tabs a[aria-current=page] { color: var(--brand-d); }
.tabs svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.progress { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand-d); border-radius: 99px; }

.day { border-left: 5px solid var(--brand); }
.item { padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
details summary { cursor: pointer; font-size: 14px; color: var(--brand-d); font-weight: 600; margin-top: 4px; }
details p { margin: 6px 0 0; font-size: 14px; color: var(--muted); }

.list > a, .list > .li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.list > :first-child { border-top: 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
.tablewrap { overflow-x: auto; }

.rating { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.rating button { border: 2px solid var(--line); background: var(--card); color: var(--ink); border-radius: 12px; padding: 8px 2px; cursor: pointer; font-size: 12px; line-height: 1.2; min-height: 64px; }
.rating button b { display: block; font-size: 22px; }
.rating button[aria-pressed=true] { border-color: var(--brand-d); background: var(--brand-soft); }

.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .line { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--chart); stroke: var(--card); stroke-width: 2; }
.chart .bar { fill: var(--chart-2); }
.chart .bar.last { fill: var(--chart); }
.chart .ref { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:focus-visible { outline: none; stroke: var(--brand); stroke-width: 2; }
.tip { position: absolute; pointer-events: none; transform: translate(-50%, -110%); background: var(--ink); color: var(--bg); padding: 4px 8px; border-radius: 8px; font-size: 12px; white-space: nowrap; z-index: 3; }

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand-d); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }

.offline { position: sticky; top: 0; z-index: 9; background: var(--bad); color: #fff; text-align: center; padding: 6px 10px; font-size: 14px; }
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabh) + 14px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 20; pointer-events: none; padding: 0 16px; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); max-width: 480px; }
.toast.bad { background: var(--bad); color: #fff; }
.disclaimer { font-size: 12.5px; color: var(--muted); }
.hero { text-align: center; padding: 24px 0 8px; }
.hero .logo { width: 120px; height: auto; }
.hero h2 { margin-top: 12px; }

.eqgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 14px; margin: -4px 0 12px; }
.eqgrid .check { font-size: 14px; margin: 0; }
.guide .steps { white-space: pre-line; font-size: 14px; color: var(--ink); line-height: 1.6; }
.video { position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000; margin-top: 8px; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.chip.soft { background: #f1f5ea; color: var(--ink); font-weight: 500; }
.card.today { border: 2px solid var(--brand); }
.rest { position: sticky; top: 64px; z-index: 4; background: var(--brand-soft); border-color: transparent; }
.rest[hidden] { display: none; }
textarea { width: 100%; min-height: 110px; padding: 8px 12px; border-radius: 12px; border: 1.5px solid var(--line); font: inherit; }
.steps { white-space: pre-line; }
.admintabs { display: flex; gap: 4px; background: var(--line); padding: 4px; border-radius: 14px; overflow-x: auto; }
.admintabs a { flex: 1; text-align: center; white-space: nowrap; padding: 10px 14px; border-radius: 11px; font-weight: 650;
  color: var(--muted); text-decoration: none; }
.admintabs a[aria-selected=true] { background: var(--card); color: var(--brand-d); box-shadow: var(--shadow); }
.badge { display: inline-block; min-width: 20px; margin-left: 6px; padding: 0 6px; border-radius: 99px; background: var(--bad);
  color: #fff; font-size: 12px; line-height: 20px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.card.link { text-decoration: none; color: inherit; }
.card.link:hover { border-color: var(--brand); }
.warn-text { color: var(--bad); }
.tabs .brand { display: none; }

/* ---------- Desktop (≥1024px): зүүн талын цэс, өргөн контент ---------- */
@media (min-width: 1024px) {
  :root { --side: 248px; }
  body { padding-bottom: 32px; padding-left: var(--side); background: #f7f9f4; }
  body.noTabs { padding-left: 0; background: var(--bg); }
  main, .top .bar { max-width: 720px; }
  body.wide main, body.wide .top .bar { max-width: 1160px; }
  main { padding: 24px 32px; }
  .top { background: rgba(255,255,255,.9); backdrop-filter: blur(8px); }
  .top .bar { padding-inline: 32px; min-height: 44px; }
  .top h1 { font-size: 22px; }
  body:not(.noTabs) .top .bar img { display: none; }   /* лого зүүн цэсэнд байна */

  .tabs { top: 0; right: auto; width: var(--side); flex-direction: column; gap: 4px; padding: 20px 14px;
          border-top: 0; border-right: 1px solid var(--line); }
  .tabs .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; font-weight: 700; font-size: 17px; color: var(--ink); }
  .tabs .brand img { width: 40px; height: 40px; object-fit: contain; }
  .tabs a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 46px; padding: 0 14px;
            font-size: 15px; border-radius: 12px; }
  .tabs a:hover { background: #f1f5ea; color: var(--ink); }
  .tabs a[aria-current=page] { background: var(--brand-soft); color: var(--brand-d); }
  .tabs svg { width: 22px; height: 22px; }
  .toasts { bottom: 24px; padding-left: var(--side); }
  body.noTabs .toasts { padding-left: 0; }

  .card { padding: 20px; }
  /* Нүүр: 2 багана, BMI карт зүүн талд 2 мөр эзэлнэ */
  .dash { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; align-items: start; }
  .dash > * + * { margin-top: 0; }
  .dash > h2 { grid-column: 1 / -1; font-size: 26px; }
  .dash > .today { grid-column: 1 / -1; }
  .dash > .card.accent { grid-row: span 2; align-self: stretch; }
  .dash > :last-child { grid-column: 1 / -1; }
  /* Хөтөлбөр: өдрүүд хажуу хажуудаа */
  .days { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; align-items: start; }
  .days > * + * { margin-top: 0; }
  /* Явц: график 2 баганаар */
  .charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
}
@media (max-width: 1023px) {
  .days > * + *, .charts > * + * { margin-top: 12px; }
}

/* ---------- Popup цонх ---------- */
.modal { width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 18px;
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(20, 35, 10, .25); }
.modal::backdrop { background: rgba(20, 30, 12, .45); }
.modal-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-body { padding: 18px 20px 20px; }
.modal-success { text-align: center; padding: 18px 0 6px; }
.modal-check { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 50%; background: var(--good-bg); color: var(--good);
  font-size: 34px; line-height: 64px; font-weight: 700; }
.thumb { width: 44px; height: 44px; object-fit: contain; border-radius: 8px; background: #f3f5ef; border: 1px solid var(--line); }
.thumb.empty { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; }
.imgpick { display: flex; align-items: center; gap: 14px; }
.imgpick img { width: 96px; height: 96px; object-fit: contain; border-radius: 12px; border: 1px solid var(--line); background: #f3f5ef; }
.eqgrid .check img { width: 28px; height: 28px; object-fit: contain; border-radius: 6px; flex: none; }

/* ---------- Тоног төхөөрөмжийн том картууд ---------- */
.eqcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.eqcard { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 10px 12px;
  border: 2px solid var(--line); border-radius: 16px; background: var(--card); color: var(--ink); font: inherit; font-size: 14px;
  font-weight: 600; text-align: center; cursor: pointer; min-height: 150px; }
.eqcard img, .eqcard .eqnoimg { width: 84px; height: 84px; object-fit: contain; }
.eqcard .eqnoimg { display: flex; align-items: center; justify-content: center; border-radius: 12px; background: #f1f5ea; color: var(--muted); font-size: 28px; }
.eqcard:hover { border-color: var(--brand); }
.eqcard[aria-pressed=true] { border-color: var(--brand-d); background: var(--brand-soft); }
.eqtick { position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 50%; background: var(--brand-d); color: #fff;
  font-style: normal; font-size: 14px; line-height: 24px; display: none; }
.eqcard[aria-pressed=true] .eqtick { display: block; }
@media (max-width: 380px) { .eqcards { grid-template-columns: 1fr 1fr; } }
