/* ============================================================
   ЗОЖ Помощник — спокойные зелёные тона, светлая и тёмная темы
   ============================================================ */
:root {
  --bg: #F2F7F3;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #E3F1E7 0%, transparent 60%);
  --card: #FFFFFF;
  --text: #18251D;
  --muted: #617468;
  --primary: #3F9E6B;
  --primary-deep: #2E7D54;
  --primary-ink: #FFFFFF;
  --chip: #E4F2E9;
  --chip-warn: #FBF0DC;
  --chip-warn-text: #9A6A24;
  --border: #DFEAE3;
  --track: #E7F0EA;
  --shadow: 0 12px 32px rgba(33, 84, 56, .08);
  --danger: #C2634F;
  --ring: #3F9E6B;
  --good: #3F9E6B;
  --mid: #D9A23B;
  --low: #C2634F;
}

html[data-theme="dark"] {
  --bg: #0D1512;
  --bg-grad: radial-gradient(1200px 600px at 80% -20%, #15271E 0%, transparent 60%);
  --card: #15211B;
  --text: #EAF3EC;
  --muted: #93A79B;
  --primary: #5CBB87;
  --primary-deep: #4BA374;
  --primary-ink: #0D1512;
  --chip: #1D2F26;
  --chip-warn: #2E2618;
  --chip-warn-text: #D9B578;
  --border: #23352B;
  --track: #1B2821;
  --shadow: 0 12px 32px rgba(0, 0, 0, .35);
  --ring: #5CBB87;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  transition: background-color .25s ease, color .25s ease;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px
           calc(28px + env(safe-area-inset-bottom));
}

.loading { text-align: center; font-size: 42px; padding-top: 40vh; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .4; transform: scale(.92); } }

/* ---------- типографика и контейнеры ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  transition: background-color .25s ease, border-color .25s ease;
}

h1 { font-size: 22px; margin: 2px 0 6px; letter-spacing: -.3px; }
h2 { font-size: 16px; margin: 0 0 12px; letter-spacing: -.2px; }
p  { margin: 6px 0; line-height: 1.45; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.45; }
.center { text-align: center; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin: 4px 2px 14px;
}
.topbar .hello { font-size: 20px; font-weight: 700; letter-spacing: -.3px; }
.topbar .date { color: var(--muted); font-size: 13px; margin-top: 2px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--card);
  color: var(--text); font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s ease, background .2s ease;
}
.icon-btn:active { transform: scale(.92); }

/* ---------- кнопки ---------- */
.btn {
  display: block; width: 100%; padding: 15px 18px;
  border: none; border-radius: 16px; cursor: pointer;
  font-size: 16px; font-weight: 650; letter-spacing: .1px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: #fff; transition: transform .15s ease, opacity .2s ease, box-shadow .2s ease;
  box-shadow: 0 8px 20px rgba(47, 125, 84, .25);
}
html[data-theme="dark"] .btn { color: #0D1512; box-shadow: 0 8px 20px rgba(0,0,0,.4); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; box-shadow: none; }

.btn-ghost {
  background: transparent; color: var(--primary); font-weight: 600;
  border: 1.5px solid var(--border); box-shadow: none;
}
html[data-theme="dark"] .btn-ghost { color: var(--primary); }

.btn-sm { padding: 10px 14px; font-size: 14px; border-radius: 13px; }

/* ---------- формы ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 4px; }
.input {
  width: 100%; padding: 14px 16px; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1.5px solid var(--border); border-radius: 14px;
  outline: none; transition: border-color .15s ease;
  appearance: none; -webkit-appearance: none;
}
.input:focus { border-color: var(--primary); }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--track); padding: 5px; border-radius: 14px; }
.seg-3 { grid-template-columns: 1fr 1fr 1fr; }
.seg button {
  padding: 11px; border: none; border-radius: 10px; cursor: pointer;
  background: transparent; color: var(--muted); font-size: 15px; font-weight: 600;
  transition: all .18s ease;
}
.seg button.active { background: var(--card); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.12); }

.form-error { color: var(--danger); font-size: 13px; margin: 2px 4px 10px; min-height: 16px; }

.badge-demo {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .4px;
  background: var(--chip); color: var(--primary-deep); padding: 4px 9px; border-radius: 8px;
  margin-left: 8px; vertical-align: middle; text-transform: uppercase;
}
html[data-theme="dark"] .badge-demo { color: var(--primary); }

/* ---------- анкета ---------- */
.quiz-progress { height: 7px; background: var(--track); border-radius: 99px; overflow: hidden; margin: 6px 2px 4px; }
.quiz-progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-deep)); border-radius: 99px; transition: width .3s ease; }
.quiz-counter { font-size: 12.5px; color: var(--muted); margin: 0 2px 14px; }

.qcard { animation: slideIn .28s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.q-title { font-size: 19px; font-weight: 700; line-height: 1.35; margin: 2px 0 16px; letter-spacing: -.2px; }

.opt-list { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 15px 16px; border-radius: 15px; cursor: pointer;
  background: var(--card); border: 1.5px solid var(--border);
  color: var(--text); font-size: 15.5px; font-weight: 550;
  transition: border-color .15s ease, background .15s ease, transform .1s ease;
}
.opt:active { transform: scale(.985); }
.opt.picked { border-color: var(--primary); background: var(--chip); }
.opt .dot {
  flex: none; width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--border); transition: all .15s ease;
}
.opt.picked .dot { border-color: var(--primary); background: var(--primary); box-shadow: inset 0 0 0 3.5px var(--card); }

.quiz-back {
  border: none; background: none; color: var(--muted); font-size: 14px;
  cursor: pointer; padding: 6px 2px; margin-bottom: 8px; font-weight: 600;
}

/* ---------- шкала оценки (кольцо) ---------- */
.score-wrap { display: flex; align-items: center; gap: 18px; }
.ring { position: relative; width: 118px; height: 118px; flex: none; }
.ring svg { transform: rotate(-90deg); display: block; }
.ring .track { stroke: var(--track); }
.ring .fill { stroke: var(--ring); stroke-linecap: round; transition: stroke-dashoffset .8s cubic-bezier(.2,.8,.3,1); }
.ring .val {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.ring .val b { font-size: 27px; letter-spacing: -.8px; }
.ring .val span { font-size: 11.5px; color: var(--muted); }

.score-side { flex: 1; min-width: 0; }
.score-side .caption { font-size: 13px; color: var(--muted); margin-bottom: 8px; line-height: 1.4; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--chip); color: var(--primary-deep);
  font-size: 13.5px; font-weight: 650; padding: 7px 12px; border-radius: 12px;
  margin: 3px 6px 3px 0;
}
html[data-theme="dark"] .chip { color: var(--primary); }
.chip.warn { background: var(--chip-warn); color: var(--chip-warn-text); }

/* ---------- цели (чекбоксы) ---------- */
.goals-head { display: flex; justify-content: space-between; align-items: baseline; }
.goals-head .muted { font-size: 12.5px; }

.day-progress { height: 6px; background: var(--track); border-radius: 99px; overflow: hidden; margin: 2px 0 14px; }
.day-progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-deep)); transition: width .35s ease; border-radius: 99px; }

.goal {
  display: flex; align-items: center; gap: 13px; padding: 13px 4px;
  border-bottom: 1px solid var(--border); cursor: pointer; user-select: none;
}
.goal:last-child { border-bottom: none; }
.goal .cb {
  flex: none; width: 27px; height: 27px; border-radius: 10px;
  border: 2px solid var(--border); position: relative;
  transition: all .18s ease;
}
.goal .cb::after {
  content: ""; position: absolute; left: 8px; top: 4px; width: 6px; height: 12px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) scale(0);
  transition: transform .18s ease;
}
html[data-theme="dark"] .goal .cb::after { border-color: #0D1512; }
.goal.done .cb { background: var(--primary); border-color: var(--primary); }
.goal.done .cb::after { transform: rotate(45deg) scale(1); }
.goal .txt { font-size: 15.5px; font-weight: 550; transition: color .2s ease; }
.goal.done .txt { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }

.day-done {
  text-align: center; padding: 12px; border-radius: 14px; margin-top: 10px;
  background: var(--chip); color: var(--primary-deep); font-weight: 650; font-size: 14.5px;
  animation: slideIn .3s ease;
}
html[data-theme="dark"] .day-done { color: var(--primary); }

/* ---------- категории и история ---------- */
.cat-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.cat-row:last-child { margin-bottom: 2px; }
.cat-row .name { width: 118px; flex: none; font-size: 13px; color: var(--muted); }
.cat-row .bar { flex: 1; height: 8px; border-radius: 99px; background: var(--track); overflow: hidden; }
.cat-row .bar i { display: block; height: 100%; border-radius: 99px; transition: width .6s ease; }
.cat-row .num { width: 30px; text-align: right; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar i.great { background: var(--good); } .bar i.good { background: #6FBF8F; }
.bar i.mid { background: var(--mid); } .bar i.low { background: var(--low); }

.hist { display: flex; align-items: flex-end; gap: 8px; height: 84px; margin-top: 6px; }
.hist .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.hist .col i {
  width: 100%; border-radius: 7px 7px 4px 4px; min-height: 4px;
  background: linear-gradient(180deg, var(--primary), var(--primary-deep));
  opacity: .9; transition: height .4s ease;
}
.hist .col.today i { outline: 2px solid var(--primary); outline-offset: 1px; }
.hist .col span { font-size: 10.5px; color: var(--muted); }

/* ---------- советы ---------- */
.tip { display: flex; gap: 11px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.tip:last-child { border: none; }
.tip .ico { flex: none; width: 34px; height: 34px; border-radius: 12px; background: var(--chip); display: flex; align-items: center; justify-content: center; font-size: 16px; }
.tip p { margin: 0; font-size: 14px; line-height: 1.45; }

/* ---------- результат ---------- */
.result-hero { text-align: center; padding: 8px 0 4px; }
.result-hero .ring { width: 150px; height: 150px; margin: 0 auto 8px; }
.result-hero .ring .val b { font-size: 36px; }
.delta-badge { font-size: 14px; font-weight: 700; }
.delta-badge.up { color: var(--good); } .delta-badge.down { color: var(--low); }

/* ---------- модалка / тост / конфетти ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(10, 20, 14, .55);
  backdrop-filter: blur(3px); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .25s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 480px; background: var(--card);
  border-radius: 24px 24px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  animation: up .3s cubic-bezier(.2,.8,.3,1);
  border: 1px solid var(--border); border-bottom: none;
}
@keyframes up { from { transform: translateY(60px); opacity: 0; } }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px); z-index: 60;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px;
  font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: all .25s ease; max-width: 86vw; text-align: center;
}
#toast.show { opacity: .96; transform: translateX(-50%) translateY(0); }

.confetti {
  position: fixed; inset: 0; z-index: 55; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 64px; animation: celebrate 1.4s ease forwards;
}
@keyframes celebrate {
  0% { transform: scale(.3); opacity: 0; }
  25% { transform: scale(1.15); opacity: 1; }
  70% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.1) translateY(-40px); opacity: 0; }
}

.footer-note { text-align: center; margin-top: 18px; }
.link-btn { background: none; border: none; color: var(--muted); font-size: 12.5px; text-decoration: underline; cursor: pointer; padding: 4px; }

.hero-emoji { font-size: 44px; margin-bottom: 6px; }

/* ---------- выбор цели (карточки) ---------- */
.goal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.goal-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 14px; border-radius: 15px; cursor: pointer; text-align: left;
  background: var(--bg); border: 1.5px solid var(--border); color: var(--text);
  transition: all .15s ease; font-family: inherit;
}
.goal-card span { font-size: 22px; }
.goal-card b { font-size: 13.5px; font-weight: 650; line-height: 1.3; }
.goal-card:active { transform: scale(.97); }
.goal-card.active { border-color: var(--primary); background: var(--chip); }

/* ---------- нижний таббар ---------- */
body.has-tabs { }
body.has-tabs #app { padding-bottom: calc(104px + env(safe-area-inset-bottom)); }
.tabbar {
  position: fixed; z-index: 30;
  left: 50%; transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: min(340px, 88vw);
  display: flex; gap: 4px; padding: 5px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 19px; box-shadow: var(--shadow);
  animation: up .3s cubic-bezier(.2,.8,.3,1);
}
.tabbar button {
  flex: 1; padding: 11px 6px; border: none; border-radius: 14px; cursor: pointer;
  background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 650; font-family: inherit;
  transition: all .18s ease;
}
.tabbar button.active { background: var(--chip); color: var(--primary-deep); }
html[data-theme="dark"] .tabbar button.active { color: var(--primary); }

/* ---------- чат ---------- */
.chat-card {
  display: flex; flex-direction: column; padding: 10px;
  height: calc(100vh - 190px - env(safe-area-inset-top));
  min-height: 380px; overflow: hidden;
}
.chat-msgs {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px;
  padding: 8px 4px; -webkit-overflow-scrolling: touch;
}
.bubble {
  max-width: 82%; padding: 11px 14px; font-size: 14.5px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word; animation: slideIn .22s ease;
}
.bubble.user {
  align-self: flex-end; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  border-radius: 17px 17px 7px 17px;
}
html[data-theme="dark"] .bubble.user { color: #0D1512; }
.bubble.ai { align-self: flex-start; background: var(--track); border-radius: 17px 17px 17px 7px; }

.bubble.typing { display: flex; gap: 5px; padding: 14px 16px; }
.bubble.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: dot 1.1s infinite;
}
.bubble.typing span:nth-child(2) { animation-delay: .18s; }
.bubble.typing span:nth-child(3) { animation-delay: .36s; }
@keyframes dot { 0%, 60%, 100% { transform: none; opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }

.chat-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 8px 2px 4px; }
.chat-chip {
  border: 1.5px solid var(--border); background: var(--track); color: var(--text);
  padding: 8px 13px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all .15s ease;
}
.chat-chip:active { transform: scale(.96); border-color: var(--primary); }

.chat-input { display: flex; gap: 8px; padding-top: 10px; }
.chat-input .input { flex: 1; background: var(--track); border-color: transparent; }
.chat-input .input:focus { border-color: var(--primary); background: var(--bg); }
.chat-send { flex: none; width: 50px; padding: 0; font-size: 17px; border-radius: 14px; }
