/* ═══════════════════════════════════════════════════════════════════
   JackyBot — Telegram Mini App  ·  Premium Diary UI v2
   ═══════════════════════════════════════════════════════════════════ */

/* ── Theme (Telegram injects --tg-theme-*, dark fallbacks) ──────── */
:root {
  --bg:           var(--tg-theme-bg-color, #000000);
  --text:         var(--tg-theme-text-color, #ffffff);
  --hint:         var(--tg-theme-hint-color, #98989f);
  --link:         var(--tg-theme-link-color, #64d2ff);
  --btn-bg:       var(--tg-theme-button-color, #0a84ff);
  --btn-text:     var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #1c1c1e);
  --section-bg:   var(--tg-theme-section-bg-color, #1c1c1e);
  --separator:    var(--tg-theme-section-separator-color, rgba(255,255,255,0.06));

  --radius:     16px;
  --gap:        14px;
  --pad:        16px;
  --tabbar-h:   56px;
  --header-h:   0px;  /* no fixed header — hero scrolls */

  --mood-great:  #30d158;
  --mood-good:   #64d2ff;
  --mood-mid:    #ff9f0a;
  --mood-low:    #ff453a;

  --card-bg:     rgba(255,255,255,0.06);
  --card-border: rgba(255,255,255,0.08);
  --glass:       rgba(0,0,0,0.65);
}

/* ── Reset ───────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  padding-bottom: calc(var(--tabbar-h) + 24px);
}

/* ── Hero Header (scrolls with content) ──────────────────────────── */
.hero {
  position: relative;
  padding: 24px var(--pad) 20px;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg,
    rgba(10,132,255,0.22) 0%,
    rgba(100,210,255,0.10) 40%,
    transparent 70%);
  pointer-events: none;
}

.hero-content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 14px;
}

.hero-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
  background: var(--card-bg);
}

.hero-avatar-placeholder {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--btn-bg), #5856d6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.hero-text { flex: 1; min-width: 0; }

.hero-greeting {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.hero-date {
  font-size: 0.78rem;
  color: var(--hint);
  margin-top: 2px;
}

/* quick stats row */
.hero-stats {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: 2px;
}
.hero-stats::-webkit-scrollbar { display: none; }

.hero-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.hero-chip-emoji { font-size: 0.9rem; }

/* ── Bottom Tab Bar ──────────────────────────────────────────────── */
#tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  justify-content: space-around;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid rgba(255,255,255,0.12);
  height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  color: var(--hint);
  font-family: inherit;
  font-size: 0.6rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.tabbar-item.active { color: var(--btn-bg); }

.tabbar-item.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 2px;
  border-radius: 0 0 2px 2px;
  background: var(--btn-bg);
}

.tabbar-icon {
  width: 22px;
  height: 22px;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tabbar-item.active .tabbar-icon { transform: scale(1.12); }

/* ── Main Content ────────────────────────────────────────────────── */
#content {
  padding: 0 var(--pad) var(--gap);
  min-height: 50vh;
}

/* ── View Transition ─────────────────────────────────────────────── */
.view-enter { animation: fadeUp 0.25s ease-out; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Loading ─────────────────────────────────────────────────────── */
.loading-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5rem 0;
  gap: 12px;
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid rgba(255,255,255,0.08);
  border-top-color: var(--btn-bg);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text { font-size: 0.8rem; color: var(--hint); }

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: var(--gap);
  margin-bottom: 12px;
  border: 1px solid var(--card-border);
}

.card-title {
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}

.card-subtitle {
  font-size: 0.75rem;
  color: var(--hint);
  margin-top: 6px;
}

/* ── Diary Cards ─────────────────────────────────────────────────── */
.diary-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--card-border);
  position: relative;
  overflow: hidden;
}

.diary-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
}

.diary-card.mood-great::before { background: var(--mood-great); }
.diary-card.mood-good::before  { background: var(--mood-good); }
.diary-card.mood-mid::before   { background: var(--mood-mid); }
.diary-card.mood-low::before   { background: var(--mood-low); }
.diary-card.mood-none::before  { background: rgba(255,255,255,0.12); }

.diary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.diary-date {
  font-weight: 600;
  font-size: 0.82rem;
}

.diary-mood { font-size: 1.2rem; }

.diary-text {
  font-size: 0.84rem;
  line-height: 1.65;
  color: rgba(255,255,255,0.82);
}

.diary-text.collapsed {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.diary-expand {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--btn-bg);
  cursor: pointer;
  font-weight: 600;
  border: none;
  background: none;
  padding: 0;
  font-family: inherit;
}

.diary-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.diary-footer > span {
  font-size: 0.7rem;
  color: var(--hint);
}

/* ── Section Headers ─────────────────────────────────────────────── */
.section-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--hint);
  margin: 18px 0 8px;
}

.section-title:first-child { margin-top: 4px; }

/* ── List items ──────────────────────────────────────────────────── */
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 0;
  font-size: 0.84rem;
  border-bottom: 0.5px solid var(--separator);
}

.list-item:last-child { border-bottom: none; }

/* ── Badges ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 0.65rem;
  font-weight: 600;
  border-radius: 20px;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
}

.badge.primary { background: rgba(10,132,255,0.18); color: var(--btn-bg); }
.badge.success { background: rgba(48,209,88,0.14); color: var(--mood-great); }
.badge.warning { background: rgba(255,159,10,0.14); color: var(--mood-mid); }
.badge.danger  { background: rgba(255,69,58,0.14); color: var(--mood-low); }

/* ── Progress ────────────────────────────────────────────────────── */
.progress {
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
  margin: 6px 0;
}

.progress-bar {
  height: 100%;
  border-radius: 2px;
  background: var(--btn-bg);
  transition: width 0.5s ease-out;
}

.progress-bar.warning { background: var(--mood-mid); }
.progress-bar.danger  { background: var(--mood-low); }
.progress-bar.success { background: var(--mood-great); }

/* ── Stats Grid ──────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 14px 8px 12px;
  text-align: center;
}

.stat-emoji { font-size: 1.3rem; margin-bottom: 2px; }

.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.stat-label {
  font-size: 0.65rem;
  color: var(--hint);
  margin-top: 1px;
  font-weight: 500;
}

/* ── Chart area ──────────────────────────────────────────────────── */
.chart-container {
  position: relative;
  height: 180px;
  margin: 12px 0 4px;
}

/* ── Habit items ─────────────────────────────────────────────────── */
.habit-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 0.5px solid var(--separator);
}

.habit-item:last-child { border-bottom: none; }

.habit-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.6rem;
  transition: all 0.2s;
}

.habit-check.done {
  background: var(--mood-great);
  border-color: var(--mood-great);
  color: #fff;
}

.habit-info { flex: 1; min-width: 0; }
.habit-name { font-size: 0.84rem; font-weight: 500; }
.habit-streak { font-size: 0.72rem; color: var(--hint); }

/* ── Goal cards ──────────────────────────────────────────────────── */
.goal-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: var(--gap);
  margin-bottom: 10px;
}

.goal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.goal-title { font-weight: 600; font-size: 0.84rem; }
.goal-pct { font-weight: 700; font-size: 0.82rem; color: var(--btn-bg); }

/* ── Empty states ────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem 2rem;
  text-align: center;
}

.empty-icon { font-size: 3.5rem; margin-bottom: 16px; }
.empty-title { font-size: 1rem; font-weight: 600; margin-bottom: 6px; }

.empty-text {
  font-size: 0.82rem;
  color: var(--hint);
  line-height: 1.55;
  max-width: 260px;
}

/* ── Expense layout ──────────────────────────────────────────────── */
.expense-total {
  font-size: 2.2rem;
  font-weight: 700;
  text-align: center;
  padding: 8px 0 0;
  letter-spacing: -0.04em;
}

.budget-item { margin: 10px 0; }

.budget-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.budget-cat { font-weight: 500; }
.budget-nums { color: var(--hint); font-size: 0.78rem; }

/* ── AI usage ────────────────────────────────────────────────────── */
.ai-model {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--separator);
}

.ai-model:last-child { border-bottom: none; }
.ai-model-name { font-size: 0.82rem; font-weight: 500; }
.ai-model-calls { font-size: 0.78rem; color: var(--hint); }

/* ── Quick actions (optional floating) ───────────────────────────── */
.quick-actions {
  display: flex;
  gap: 8px;
  margin: 14px 0;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.quick-actions::-webkit-scrollbar { display: none; }

.quick-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 20px;
  background: rgba(10,132,255,0.12);
  border: 1px solid rgba(10,132,255,0.2);
  color: var(--btn-bg);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s, background 0.15s;
}

.quick-btn:active { transform: scale(0.96); background: rgba(10,132,255,0.2); }

/* ── Scrollbar hide ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 0; height: 0; }

/* ═══════════════════════════════════════════════════════════════════
   Login Page (PWA standalone, outside Telegram)
   ═══════════════════════════════════════════════════════════════════ */

.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  padding: 2rem var(--pad);
  text-align: center;
}

.login-logo { margin-bottom: 24px; }

.login-icon {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  box-shadow: 0 8px 32px rgba(10,132,255,0.3);
}

.login-title {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 0.9rem;
  color: var(--hint);
  margin-bottom: 40px;
}

.login-methods {
  width: 100%;
  max-width: 320px;
}

.login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 24px;
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  border: none;
}

.login-btn:active { transform: scale(0.97); }

.login-btn-primary {
  background: linear-gradient(135deg, #0a84ff, #5856d6);
  color: #fff;
  box-shadow: 0 4px 16px rgba(10,132,255,0.35);
}

.login-hint {
  margin-top: 20px;
  font-size: 0.8rem;
  color: var(--hint);
  line-height: 1.55;
}

.login-hint strong {
  color: var(--btn-bg);
}

/* ═══════════════════════════════════════════════════════════════════
   Light Theme (standalone PWA outside Telegram)
   Applied when NOT inside Telegram (no --tg-theme vars)
   ═══════════════════════════════════════════════════════════════════ */

@media (prefers-color-scheme: light) {
  :root:not([data-tg-theme]) {
    --bg:           #f2f2f7;
    --text:         #1c1c1e;
    --hint:         #8e8e93;
    --link:         #007aff;
    --btn-bg:       #007aff;
    --btn-text:     #ffffff;
    --secondary-bg: #ffffff;
    --section-bg:   #ffffff;
    --separator:    rgba(0,0,0,0.08);
    --card-bg:      rgba(0,0,0,0.03);
    --card-border:  rgba(0,0,0,0.06);
    --glass:        rgba(242,242,247,0.85);
  }

  :root:not([data-tg-theme]) .diary-text { color: rgba(0,0,0,0.72); }
  :root:not([data-tg-theme]) .diary-card.mood-none::before { background: rgba(0,0,0,0.12); }
  :root:not([data-tg-theme]) .loading-spinner { border-color: rgba(0,0,0,0.08); }
  :root:not([data-tg-theme]) #tabbar { border-top-color: rgba(0,0,0,0.08); }
  :root:not([data-tg-theme]) .hero-avatar { border-color: rgba(0,0,0,0.1); }
  :root:not([data-tg-theme]) .badge { background: rgba(0,0,0,0.05); color: rgba(0,0,0,0.6); }
}
