/* Tracker Mini App styles. Design language: Telegram-native section lists on
   the official theme variables, so light/dark and custom themes come free.
   Every var() carries a fallback for plain-browser development. */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f0f2f5);
  --section: var(--tg-theme-section-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111318);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --subtitle: var(--tg-theme-subtitle-text-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2ea6ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-accent-text-color, #2ea6ff);
  --destructive: var(--tg-theme-destructive-text-color, #e53935);
  --separator: var(--tg-theme-section-separator-color, rgba(0,0,0,.08));
  --radius: 14px;
}

/* Dark fallback for browser dev only; inside Telegram the theme vars win. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #18222d);
    --bg2: var(--tg-theme-secondary-bg-color, #131c26);
    --section: var(--tg-theme-section-bg-color, #1f2b38);
    --text: var(--tg-theme-text-color, #e9edf1);
    --hint: var(--tg-theme-hint-color, #7d8b99);
    --subtitle: var(--tg-theme-subtitle-text-color, #7d8b99);
    --separator: var(--tg-theme-section-separator-color, rgba(255,255,255,.07));
  }
}

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

html, body {
  background: var(--bg2);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.35;
  height: 100%;
}

#app { display: flex; flex-direction: column; min-height: 100vh; min-height: var(--tg-viewport-stable-height, 100vh); }

.screen {
  flex: 1;
  padding: 12px 12px calc(72px + var(--tg-safe-area-inset-bottom, 0px));
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  animation: screen-in .18s ease-out;
}
@keyframes screen-in { from { opacity: .55; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- header ---------- */

.header { padding: 10px 4px 14px; display: flex; align-items: center; gap: 10px; }
.header h1 { font-size: 24px; font-weight: 700; flex: 1; }
.header .sub { color: var(--hint); font-size: 14px; }
.back-btn {
  border: none; background: none; color: var(--link); font-size: 22px;
  cursor: pointer; padding: 4px 8px 4px 0; display: none;
}
body.no-tg .back-btn.visible { display: block; }

/* Streak chip */
.streak {
  background: var(--section); border-radius: 999px; padding: 6px 12px;
  font-size: 14px; font-weight: 600; white-space: nowrap;
}

/* ---------- sections & rows (Telegram settings-list look) ---------- */

.section { background: var(--section); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.section-title {
  color: var(--subtitle); font-size: 13px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .4px; padding: 0 16px 6px; margin-top: 2px; display: flex; align-items: center; gap: 6px;
}
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  min-height: 52px; cursor: pointer; position: relative;
}
.row + .row::before {
  content: ""; position: absolute; left: 56px; right: 0; top: 0;
  height: 1px; background: var(--separator);
}
.row:active { background: rgba(128,128,128,.08); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-size: 16px; overflow-wrap: anywhere; }
.row .subtitle { color: var(--hint); font-size: 13px; margin-top: 1px; overflow-wrap: anywhere; }
.row .chevron { color: var(--hint); font-size: 15px; }

/* ---------- check circles (the core interaction) ---------- */

.check {
  width: 28px; height: 28px; min-width: 28px; border-radius: 50%;
  border: 2px solid var(--hint); display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: transparent; transition: all .15s ease;
}
.row.checked .check { background: var(--accent); border-color: var(--accent); color: var(--accent-text); animation: pop .25s ease; }
.row.checked .title { color: var(--hint); text-decoration: line-through; text-decoration-color: rgba(128,128,128,.5); }
@keyframes pop { 0% { transform: scale(.7); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }

/* Frequency chip */
.chip {
  font-size: 11px; font-weight: 600; color: var(--subtitle);
  background: rgba(128,128,128,.12); padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}

/* ---------- goal cards ---------- */

.goal-card { display: flex; align-items: center; gap: 12px; padding: 14px; cursor: pointer; }
.goal-emoji {
  width: 44px; height: 44px; min-width: 44px; border-radius: 12px; background: rgba(128,128,128,.1);
  display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.goal-card .pct { font-weight: 700; font-size: 15px; color: var(--link); }

.progress-track { height: 6px; background: rgba(128,128,128,.15); border-radius: 999px; margin-top: 8px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s ease; }

.badge-coached {
  font-size: 11px; font-weight: 700; color: var(--accent-text); background: var(--accent);
  padding: 2px 8px; border-radius: 999px; margin-left: 6px;
}

/* ---------- milestone path (goal detail) ---------- */

.path-item { display: flex; gap: 12px; padding: 0 14px; }
.path-rail { display: flex; flex-direction: column; align-items: center; width: 28px; min-width: 28px; }
.path-dot {
  width: 26px; height: 26px; border-radius: 50%; background: rgba(128,128,128,.15);
  color: var(--subtitle); font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; margin-top: 14px;
}
.path-item.done .path-dot { background: var(--accent); color: var(--accent-text); }
.path-line { flex: 1; width: 2px; background: var(--separator); }
.path-body { flex: 1; padding: 12px 0 6px; min-width: 0; }
.path-body .ms-title { font-weight: 600; font-size: 16px; cursor: pointer; }
.path-body .ms-unlocks { color: var(--hint); font-size: 13px; margin: 2px 0 6px; }
.path-body .row { padding: 8px 0; min-height: 44px; }
.path-body .row + .row::before { left: 40px; }

/* Quote blocks: the Dive's why / wired / reflection */
.quote { padding: 12px 16px; border-left: 3px solid var(--accent); margin: 0 14px 12px; }
.quote .q-label { color: var(--subtitle); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.quote .q-text { font-size: 14px; margin-top: 3px; }

/* ---------- buttons ---------- */

.btn {
  display: block; width: 100%; border: none; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-text);
  font-size: 16px; font-weight: 600; padding: 14px; cursor: pointer; margin-bottom: 14px;
}
.btn:active { opacity: .85; }
.btn.secondary { background: var(--section); color: var(--link); }
.btn.destructive { background: var(--section); color: var(--destructive); }
.add-row { color: var(--link); font-size: 15px; padding: 10px 0; cursor: pointer; background: none; border: none; text-align: left; }

/* In Telegram the native MainButton replaces in-page primary buttons. */
body:not(.no-tg) .btn.tg-main-replaced { display: none; }

/* ---------- forms ---------- */

.field { margin-bottom: 14px; }
.field label { display: block; color: var(--subtitle); font-size: 13px; font-weight: 600; margin: 0 4px 6px; }
.field input, .field textarea, .field select {
  width: 100%; border: none; border-radius: var(--radius); background: var(--section);
  color: var(--text); font-size: 16px; padding: 13px 14px; outline: none; font-family: inherit;
}
.field textarea { min-height: 72px; resize: vertical; }

.emoji-row { display: flex; gap: 8px; flex-wrap: wrap; }
.emoji-opt {
  width: 44px; height: 44px; border-radius: 12px; border: 2px solid transparent;
  background: var(--section); font-size: 22px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.emoji-opt.selected { border-color: var(--accent); }

.seg { display: flex; background: var(--section); border-radius: var(--radius); padding: 3px; }
.seg button {
  flex: 1; border: none; background: none; color: var(--text); font-size: 14px; font-weight: 600;
  padding: 9px 4px; border-radius: 11px; cursor: pointer;
}
.seg button.selected { background: var(--accent); color: var(--accent-text); }

/* ---------- empty states & upsell ---------- */

.empty { text-align: center; padding: 44px 24px; color: var(--hint); }
.empty .big { font-size: 44px; margin-bottom: 10px; }
.empty h2 { color: var(--text); font-size: 18px; margin-bottom: 6px; }
.empty p { font-size: 14px; }

.upsell { padding: 14px; opacity: .75; }
.upsell .u-head { font-weight: 700; font-size: 15px; }
.upsell .u-text { color: var(--hint); font-size: 13px; margin-top: 3px; }
.upsell .u-soon {
  display: inline-block; margin-top: 8px; font-size: 11px; font-weight: 700;
  color: var(--subtitle); background: rgba(128,128,128,.12); padding: 2px 8px; border-radius: 999px;
}

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex;
  background: var(--tg-theme-bottom-bar-bg-color, var(--section));
  border-top: 1px solid var(--separator);
  padding-bottom: var(--tg-safe-area-inset-bottom, 0px);
}
.tab {
  flex: 1; border: none; background: none; color: var(--hint);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 600; padding: 8px 0 6px; cursor: pointer;
}
.tab.active { color: var(--link); }
.tab-icon { font-size: 20px; }
body.detail-open .tabbar { display: none; }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: rgba(30,30,30,.92); color: #fff; font-size: 14px;
  padding: 10px 16px; border-radius: 10px; max-width: 86vw; z-index: 30;
  transition: opacity .25s ease;
}
.toast.hidden { opacity: 0; pointer-events: none; }
