/**
 * 安宸康养平台 v2 前端公共样式
 * 适老化设计 + X5内核兼容（禁用flex，使用block+绝对定位）
 * 版本: v1.0 | 日期: 2026-10-09
 */

/* ===== CSS变量 ===== */
:root {
  --color-primary: #1A5276;
  --color-primary-hover: #134058;
  --color-secondary: #2D8C87;
  --color-accent: #C8962E;
  --color-text-primary: #1A1A1A;
  --color-text-secondary: #4A4A4A;
  --color-text-muted: #6B6B6B;
  --color-text-placeholder: #8C8C8C;
  --color-bg: #FFFFFF;
  --color-surface: #F5F7FA;
  --color-border: #D1D5DB;
  --color-border-focus: #1A5276;
  --color-success: #2D8C87;
  --color-warning: #D97706;
  --color-danger: #DC2626;
  --color-info: #3B82F6;
  --color-voice-bg: #1A5276;
  --color-voice-shadow: rgba(26,82,118,0.3);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --shadow-voice: 0 4px 16px rgba(26,82,118,0.25);

  --tab-height: 64px;
  --safe-bottom: 16px;
}

/* ===== 全局重置 ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 18px;
  line-height: 1.6;
  color: var(--color-text-primary);
  background: var(--color-bg);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* 禁用flex - X5兼容 */
body, .app-container, .page, .tab-bar, .tab-item,
.header, .content, .card, .card-body {
  display: block;
}

/* ===== 类型阶梯（适老化18px起） ===== */
.text-display { font-size: 28px; font-weight: 700; line-height: 1.25; }
.text-h1 { font-size: 24px; font-weight: 700; line-height: 1.3; }
.text-h2 { font-size: 20px; font-weight: 600; line-height: 1.35; }
.text-h3 { font-size: 18px; font-weight: 600; line-height: 1.4; }
.text-body { font-size: 18px; font-weight: 400; line-height: 1.6; }
.text-body-sm { font-size: 16px; font-weight: 400; line-height: 1.5; }
.text-caption { font-size: 14px; font-weight: 400; line-height: 1.4; }
.text-price { font-size: 24px; font-weight: 700; line-height: 1.2; color: var(--color-accent); }
.text-price-unit { font-size: 16px; font-weight: 400; line-height: 1.2; }

/* ===== 颜色工具类 ===== */
.text-primary { color: var(--color-primary); }
.text-secondary { color: var(--color-text-secondary); }
.text-muted { color: var(--color-text-muted); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.text-accent { color: var(--color-accent); }

/* ===== 间距工具类 ===== */
.m-4 { margin: 16px; }
.m-6 { margin: 24px; }
.p-4 { padding: 16px; }
.p-6 { padding: 24px; }
.pt-4 { padding-top: 16px; }
.pb-4 { padding-bottom: 16px; }
.pb-safe { padding-bottom: calc(var(--tab-height) + var(--safe-bottom) + 80px); }

/* ===== 应用容器 ===== */
.app-container {
  position: relative;
  width: 100%;
  min-height: 100vh;
  background: var(--color-bg);
}

/* ===== 页面容器 ===== */
.page {
  display: none;
  width: 100%;
  min-height: 100vh;
  padding-bottom: calc(var(--tab-height) + var(--safe-bottom) + 80px);
}

.page.active {
  display: block;
}

/* ===== 顶部导航栏 ===== */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--color-bg);
  border-bottom: 1px solid #E5E7EB;
  padding: 12px 16px;
}

.header-title {
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
}

.header-with-search {
  padding: 8px 16px;
}

/* ===== 搜索栏 ===== */
.search-bar {
  width: 100%;
  height: 48px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  padding: 0 16px;
  position: relative;
}

.search-bar:focus-within {
  border-color: var(--color-border-focus);
}

.search-bar input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--color-text-primary);
  outline: none;
}

.search-bar input::placeholder {
  color: var(--color-text-placeholder);
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  pointer-events: none;
}

.search-bar input {
  padding-left: 32px;
}

/* ===== 底部Tab导航 ===== */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: var(--tab-height);
  background: var(--color-bg);
  border-top: 1px solid #E5E7EB;
  padding-bottom: var(--safe-bottom);
}

.tab-bar-inner {
  width: 100%;
  height: 100%;
  display: flex;
}

.tab-item {
  flex: 1;
  height: 100%;
  padding-top: 8px;
  text-align: center;
  cursor: pointer;
  -webkit-touch-callout: none;
}

.tab-icon {
  width: 24px;
  height: 24px;
  margin: 0 auto 4px;
  display: block;
  pointer-events: none;
}

.tab-icon svg {
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.tab-label {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--color-text-muted);
}

.tab-item.active .tab-label {
  color: var(--color-primary);
  font-weight: 700;
}

.tab-item.active .tab-icon svg {
  stroke: var(--color-primary);
  fill: var(--color-primary);
}

.tab-badge {
  position: absolute;
  top: 4px;
  right: calc(10% - 8px);
  min-width: 18px;
  height: 18px;
  background: var(--color-danger);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius-full);
  text-align: center;
  line-height: 18px;
  padding: 0 5px;
}

/* ===== 悬浮语音按钮 ===== */
.voice-button {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tab-height) + var(--safe-bottom) + 16px);
  z-index: 999;
  width: 64px;
  height: 64px;
  background: var(--color-voice-bg);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-voice);
  cursor: pointer;
  text-align: center;
  line-height: 64px;
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: none;
}

.voice-button:active {
  transform: scale(0.95);
}

.voice-button.recording {
  animation: voice-pulse 1.5s ease-in-out infinite;
}

@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(26,82,118,0.4); }
  50% { box-shadow: 0 0 0 16px rgba(26,82,118,0); }
}

.voice-button svg {
  width: 28px;
  height: 28px;
  vertical-align: middle;
  fill: #fff;
}

/* ===== 卡片组件 ===== */
.card {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin: 16px;
  overflow: hidden;
}

.card-header {
  padding: 16px;
  border-bottom: 1px solid var(--color-surface);
}

.card-body {
  padding: 16px;
}

.card-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--color-surface);
}

/* ===== 按钮组件 ===== */
.btn {
  display: inline-block;
  min-width: 48px;
  min-height: 48px;
  padding: 12px 24px;
  font-size: 18px;
  font-weight: 500;
  text-align: center;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-primary:active {
  background: var(--color-primary-hover);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1px solid var(--color-border);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}

.btn-block {
  display: block;
  width: calc(100% - 32px);
  margin: 16px;
}

.btn-lg {
  height: 56px;
  line-height: 32px;
  font-size: 18px;
  font-weight: 600;
}

/* ===== 标签/徽章 ===== */
.tag {
  display: inline-block;
  padding: 4px 10px;
  font-size: 14px;
  border-radius: var(--radius-full);
  background: #F0F9FF;
  color: var(--color-primary);
  margin-right: 8px;
  margin-bottom: 4px;
}

.tag-success { background: #ECFDF5; color: var(--color-success); }
.tag-warning { background: #FFFBEB; color: var(--color-warning); }
.tag-danger { background: #FEF2F2; color: var(--color-danger); }

/* ===== 分段控制器 ===== */
.segment-control {
  display: inline-block;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--color-bg);
}

.segment-item {
  display: inline-block;
  padding: 8px 16px;
  font-size: 16px;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  border: none;
  background: transparent;
  min-height: 40px;
  min-width: 60px;
}

.segment-item.active {
  background: var(--color-primary);
  color: #fff;
}

/* ===== 输入框 ===== */
.input {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  font-size: 18px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  outline: none;
  -webkit-appearance: none;
}

.input:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(26,82,118,0.15);
}

.input-error {
  border-color: var(--color-danger);
  background: #FEF2F2;
}

/* ===== 列表项 ===== */
.list-item {
  padding: 16px;
  border-bottom: 1px solid var(--color-surface);
  background: var(--color-bg);
  min-height: 48px;
}

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

/* ===== 图片容器 ===== */
.img-wrap {
  overflow: hidden;
  background: var(--color-surface);
}

.img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ===== 骨架屏 ===== */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s linear infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
}

.empty-state-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 16px;
  opacity: 0.4;
}

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

/* ===== 底部固定栏 ===== */
.bottom-bar {
  position: fixed;
  bottom: calc(var(--tab-height) + var(--safe-bottom));
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--color-bg);
  border-top: 1px solid #E5E7EB;
  padding: 12px 16px;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.05);
}

/* ===== 步骤条 ===== */
.step-bar {
  padding: 16px;
  text-align: center;
  border-bottom: 1px solid var(--color-surface);
}

.step-item {
  display: inline-block;
  position: relative;
  padding: 0 24px;
  font-size: 16px;
}

.step-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-border);
  margin: 0 auto 8px;
}

.step-item.active .step-dot {
  background: var(--color-primary);
}

.step-item.done .step-dot {
  background: var(--color-success);
}

/* ===== Toast提示 ===== */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 16px 24px;
  border-radius: var(--radius-md);
  font-size: 18px;
  text-align: center;
  max-width: 80%;
  word-break: break-all;
}

/* ===== Loading ===== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1999;
  background: rgba(255,255,255,0.7);
  text-align: center;
  padding-top: 40vh;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--color-surface);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

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

/* ===== 工具类 ===== */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.float-left { float: left; }
.float-right { float: right; }
.clearfix::after { content: ''; display: table; clear: both; }

/* 单行/多行省略 */
.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ellipsis-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 点击反馈 */
.touch-feedback:active {
  opacity: 0.7;
}

/* ===== 滚动优化 ===== */
.scroll-container {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* ===== 打印样式 ===== */
@media print {
  .tab-bar, .voice-button, .bottom-bar {
    display: none !important;
  }
  .page {
    display: block !important;
    padding-bottom: 0;
  }
}
