/**
 * base.css — 重置样式 + 设计变量 + 通用组件
 * 所有页面共享的基础样式
 */

/* ===== 设计变量 ===== */
:root {
  /* 主色 */
  --color-primary: #006489;
  --color-primary-light: #00B8D9;
  --color-primary-dark: #003A52;
  --gradient-primary: linear-gradient(135deg, #006489 0%, #00B8D9 100%);

  /* 功能色 */
  --color-success: #10B981;
  --color-warning: #FF9500;
  --color-error: #EF4444;

  /* 文字 */
  --color-ink: #1A1A1A;
  --color-muted: #6B7280;
  --color-placeholder: #9CA3AF;

  /* 背景 */
  --color-bg: #FFFFFF;
  --color-card: #FFFFFF;
  --color-border: #E8ECF1;
  --color-divider: #F3F4F6;

  /* 标签色 */
  --color-empathy-bg: #F3EBF1;
  --color-empathy-text: #8B5E83;
  --color-breakthrough-bg: #E8F4F8;
  --color-breakthrough-text: #006489;

  /* 圆角 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* 间距 */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;

  /* 阴影 */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 100, 137, 0.06);
  --shadow-lg: 0 8px 32px rgba(0, 100, 137, 0.08);

  /* 字体 */
  --font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC',
    'Noto Sans CJK SC', 'WenQuanYi Micro Hei', sans-serif;

  /* 安全区 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* 标题栏高度（含安全区） */
  --header-height: calc(52px + var(--safe-top));
}

/* ===== 重置 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.6;
  color: var(--color-ink);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

input, textarea, button {
  font-family: inherit;
  font-size: inherit;
  border: none;
  outline: none;
  background: none;
}
a {
  color: inherit;
  text-decoration: none;
}
img {
  display: block;
  max-width: 100%;
}
ul, ol {
  list-style: none;
}

/* ===== 页面滑动过渡动画 ===== */
@keyframes pageSlideInRight {
  from { transform: translateX(30%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes pageSlideInLeft {
  from { transform: translateX(-30%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes pageSlideOutRight {
  from { transform: translateX(0); opacity: 1; }
  to   { transform: translateX(30%); opacity: 0; }
}
@keyframes pageSlideOutLeft {
  from { transform: translateX(0); opacity: 1; }
  to   { transform: translateX(-30%); opacity: 0; }
}

.app-page {
  animation-duration: 0.3s;
  animation-timing-function: cubic-bezier(0.22, 0.61, 0.36, 1);
  /* 不使用 animation-fill-mode: both，否则 transform 会持久化
     创建新的 containing block，导致 position: fixed 失效 */
}

/* 前进：从右侧滑入 */
.app-page.slide-forward {
  animation-name: pageSlideInRight;
}
/* 后退：从左侧滑入 */
.app-page.slide-back {
  animation-name: pageSlideInLeft;
}

/* 退场动画（点击导航前触发） */
.app-page.slide-exit-forward {
  animation-name: pageSlideOutLeft;
  animation-fill-mode: forwards;
}
.app-page.slide-exit-back {
  animation-name: pageSlideOutRight;
  animation-fill-mode: forwards;
}

/* ===== 通用容器 ===== */
.app-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  padding-bottom: calc(60px + var(--safe-bottom));
}

.app-page.no-tabbar {
  padding-bottom: var(--safe-bottom);
}

/* ===== 统一页面标题栏（固定悬浮） ===== */
.page-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  padding-left: 12px;
  padding-right: 12px;
  background: rgba(247, 248, 250, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  z-index: 100;
}

.page-header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-ink);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}

/* ===== TabBar ===== */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(60px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--color-card);
  border-top: 1px solid var(--color-divider);
  display: flex;
  z-index: 100;
}

.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.tabbar-item:not(.active) {
  opacity: 0.6;
}

.tabbar-item svg {
  width: 26px;
  height: 26px;
}

.tabbar-item span {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-placeholder);
}

.tabbar-item.active span {
  color: var(--color-primary);
}

/* ===== 按钮 ===== */
.btn-primary {
  background: var(--gradient-primary);
  color: #FFFFFF;
  font-size: 16px;
  font-weight: 600;
  height: 48px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
  width: 100%;
}

.btn-primary:active {
  opacity: 0.7;
  transform: scale(0.98);
}

.btn-primary:disabled {
  background: var(--color-border);
  color: var(--color-placeholder);
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--color-card);
  color: var(--color-ink);
  font-size: 15px;
  font-weight: 500;
  height: 44px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}

.btn-secondary:active {
  opacity: 0.7;
  transform: scale(0.98);
}

/* ===== 卡片 ===== */
.card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: var(--shadow-sm);
}

/* ===== 输入框 ===== */
.input-field {
  width: 100%;
  height: 48px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0 16px;
  font-size: 15px;
  color: var(--color-ink);
  transition: border-color 0.15s;
}

.input-field:focus {
  border-color: var(--color-primary);
}

.input-field::placeholder {
  color: var(--color-placeholder);
}

/* ===== 加载动画 ===== */
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===== 弹窗遮罩 ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-overlay.center {
  align-items: center;
}

.modal-sheet {
  background: var(--color-bg);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.modal-overlay.show .modal-sheet {
  transform: translateY(0);
}

.modal-overlay.center .modal-sheet {
  border-radius: var(--radius-lg);
  transform: scale(0.9);
  opacity: 0;
}

.modal-overlay.center.show .modal-sheet {
  transform: scale(1);
  opacity: 1;
}

/* ===== 状态点 ===== */
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.green { background: var(--color-success); }
.status-dot.gray { background: #D1D5DB; }
.status-dot.red { background: var(--color-error); }

.status-dot.pulsing {
  display: flex;
  gap: 3px;
  background: none;
  width: auto;
  height: auto;
}

.status-dot.pulsing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-primary-light);
  animation: dotPulse 1.2s infinite ease-in-out;
}

.status-dot.pulsing span:nth-child(2) { animation-delay: 0.2s; }
.status-dot.pulsing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.2); }
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.75);
  color: #FFFFFF;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 14px;
  z-index: 999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  max-width: 80%;
  text-align: center;
}

.toast.show {
  opacity: 1;
}

/* ===== 空状态 ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.3;
  fill: none;
  stroke: currentColor;
}

.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-ink);
  margin-bottom: 8px;
}

.empty-state-desc {
  font-size: 14px;
  color: var(--color-muted);
}

/* ===== 移动端适配 ===== */
@media (min-width: 481px) {
  .app-page,
  .tabbar,
  .modal-sheet {
    max-width: 480px;
    margin: 0 auto;
  }

  .page-header {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
  }

  .tabbar {
    left: 50%;
    transform: translateX(-50%);
  }

  .chat-input-bar {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
  }
}
