/* ============================================================
   AI Chinese for Biz Mini App — 全局样式
   基于 TG WebApp 主题变量，自动适配亮/暗模式
   ============================================================ */

/* === CSS 主题变量（非 TG 环境时的回退值）=== */
:root {
  --tg-bg: #ffffff;
  --tg-text: #000000;
  --tg-hint: #999999;
  --tg-link: #2481cc;
  --tg-button: #2481cc;
  --tg-button-text: #ffffff;
  --tg-secondary-bg: #f0f0f0;
  --tg-section-bg: #f8f8f8;
  --tg-accent: #2481cc;
  --tg-destructive: #ec3942;
  --tg-header-bg: #ffffff;

  --radius: 12px;
  --shadow: 0 1px 4px rgba(0,0,0,0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--tg-bg);
  color: var(--tg-text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* === App Shell === */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
}

/* 加载覆盖层 */
#loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  inset: 0;
  background: var(--tg-bg);
  z-index: 9999;
}
.loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--tg-secondary-bg);
  border-top-color: var(--tg-button);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === 顶部栏 === */
.header-bar {
  padding: 12px 16px;
  background: var(--tg-header-bg);
  border-bottom: 1px solid var(--tg-secondary-bg);
  text-align: center;
  font-weight: 600;
  font-size: 17px;
  flex-shrink: 0;
}

/* === 屏幕区域 === */
.screens-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen {
  display: none;
  min-height: 100%;
}
.screen-inner {
  padding: 16px;
  padding-bottom: 80px; /* 为底部 Tab 栏留空间 */
}

/* === 底部 Tab 栏 === */
.tab-bar {
  display: flex;
  background: var(--tg-bg);
  border-top: 1px solid var(--tg-secondary-bg);
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}
.tab-bar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.tab-bar__item--active {
  color: var(--tg-button);
}
.tab-bar__icon {
  font-size: 22px;
  line-height: 1;
  margin-bottom: 2px;
}
.tab-bar__label {
  font-size: 11px;
  color: var(--tg-hint);
  line-height: 1.2;
}
.tab-bar__item--active .tab-bar__label {
  color: var(--tg-button);
  font-weight: 500;
}

/* === 卡片 === */
.card {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card__title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 10px;
  color: var(--tg-text);
}
.card__body {
  color: var(--tg-text);
}

/* === 统计卡片网格 === */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.stat-card {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-card__icon { font-size: 28px; margin-bottom: 4px; }
.stat-card__label { font-size: 12px; color: var(--tg-hint); margin-bottom: 2px; }
.stat-card__value { font-size: 20px; font-weight: 700; color: var(--tg-text); }
.stat-card__sub { font-size: 11px; color: var(--tg-hint); margin-top: 2px; }

/* === 进度条 === */
.progress-bar__label { font-size: 13px; color: var(--tg-hint); margin-bottom: 6px; }
.progress-bar__track {
  height: 8px;
  background: var(--tg-bg);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar__fill {
  height: 100%;
  background: var(--tg-button);
  border-radius: 4px;
  transition: width 0.4s ease;
  min-width: 4px;
}
.progress-bar__text { font-size: 12px; color: var(--tg-hint); margin-top: 4px; text-align: right; }

/* === 按钮 === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  padding: 0 20px;
  height: 42px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: 0.7; }
.btn-primary {
  background: var(--tg-button);
  color: var(--tg-button-text);
}
.btn-secondary {
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  border: 1px solid var(--tg-bg);
}
.btn-outline {
  background: transparent;
  color: var(--tg-link);
  border: 1px solid var(--tg-link);
}
.btn-sm { height: 34px; padding: 0 14px; font-size: 13px; }

/* === 标签 (Tabs) === */
.tabs {
  display: flex;
  background: var(--tg-secondary-bg);
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 12px;
}
.tab {
  flex: 1;
  text-align: center;
  padding: 8px 4px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--tg-hint);
  transition: all 0.15s;
}
.tab--active {
  background: var(--tg-bg);
  color: var(--tg-text);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* === 徽章 === */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
.badge--done { background: #34c759; color: #fff; }
.badge--active { background: var(--tg-button); color: var(--tg-button-text); }
.badge--locked { background: var(--tg-hint); color: #fff; }

/* === 欢迎消息 === */
.welcome-msg {
  font-size: 18px;
  margin-bottom: 14px;
  color: var(--tg-text);
}

/* === 快捷操作 === */
.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.quick-actions .btn { width: 100%; }

/* === 空状态 === */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  text-align: center;
}
.empty-state__icon { font-size: 48px; margin-bottom: 12px; }
.empty-state__message { font-size: 15px; color: var(--tg-hint); margin-bottom: 16px; }
.empty-state .btn { width: auto; }

/* === 用户资料头部 === */
.profile-header {
  text-align: center;
  padding: 20px 0;
  margin-bottom: 16px;
}
.profile-avatar {
  width: 64px; height: 64px;
  background: var(--tg-button);
  color: var(--tg-button-text);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  margin: 0 auto 10px;
}
.profile-name { font-size: 18px; font-weight: 600; }
.profile-username { font-size: 13px; color: var(--tg-hint); }

/* === 设置行 === */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--tg-bg);
}
.setting-row:last-child { border-bottom: none; }
.setting-label { font-size: 15px; }
.setting-select {
  background: var(--tg-bg);
  color: var(--tg-text);
  border: 1px solid var(--tg-hint);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  outline: none;
}

/* === 会员信息 === */
.membership-info { margin-bottom: 10px; }
.membership-type { font-size: 16px; font-weight: 600; }
.membership-usage { font-size: 13px; color: var(--tg-hint); }
.membership-actions { margin-top: 10px; }
.share-desc { font-size: 13px; color: var(--tg-hint); margin-bottom: 10px; line-height: 1.5; }
.share-feedback {
  margin-top: 8px;
  padding: 8px 12px;
  background: #34c759;
  color: #fff;
  border-radius: 6px;
  font-size: 13px;
  text-align: center;
}

/* === 每日挑战卡片 === */
.daily-card { border-left: 3px solid var(--tg-button); }

/* === 滚动条美化 (Webkit) === */
.screens-container::-webkit-scrollbar { width: 4px; }
.screens-container::-webkit-scrollbar-track { background: transparent; }
.screens-container::-webkit-scrollbar-thumb { background: var(--tg-hint); border-radius: 2px; }
