/* ==========================================================================
   经营数据分析系统 - 移动端优先主样式（清新明亮现代商务白 + 质感卡片）
   ========================================================================== */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-gradient: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  
  --success: #10b981;
  --success-bg: #ecfdf5;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-sub: #94a3b8;
  
  --bg-main: #f8fafc;
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-pill: 9999px;
  
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 12px -2px rgb(0 0 0 / 0.06), 0 2px 6px -2px rgb(0 0 0 / 0.04);
  --shadow-lg: 0 12px 24px -4px rgb(37 99 235 / 0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(at 0% 0%, rgba(219, 234, 254, 0.4) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(241, 245, 249, 0.6) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
}

/* 顶部导航与状态栏 */
.app-header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: #ffffff;
  padding: 20px 16px 24px;
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
  box-shadow: 0 8px 20px -4px rgba(37, 99, 235, 0.3);
  position: relative;
  overflow: hidden;
}

.app-header::after {
  content: '';
  position: absolute;
  top: -40px;
  right: -40px;
  width: 150px;
  height: 150px;
  background: radial-gradient(circle, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0) 70%);
  border-radius: 50%;
  pointer-events: none;
}

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

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(8px);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.export-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #ffffff;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all 0.2s ease;
}

.export-btn:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.35);
}

.export-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.export-modal-content {
  background: #ffffff;
  border-radius: var(--radius-md);
  max-width: 92%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

.export-modal-header {
  padding: 14px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 700;
}

.export-modal-body {
  padding: 12px;
  overflow-y: auto;
  text-align: center;
  -webkit-overflow-scrolling: touch;
}

.export-modal-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.export-modal-tip {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* 导出专用容器 (离屏高保真渲染完整长图，兼顾移动端 Safari/WebView 兼容性) */
#exportPosterContainer {
  position: fixed;
  left: 0;
  top: 0;
  z-index: -999;
  opacity: 0.001;
  pointer-events: none;
  width: 480px; /* 专为手机高清长图设计的固定基准宽度 */
  background: #f8fafc;
  color: #0f172a;
  padding: 18px 14px 28px;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", sans-serif;
}

.month-selector {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  padding: 3px;
  border-radius: var(--radius-pill);
}

.month-tab-btn {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.month-tab-btn.active {
  background: #ffffff;
  color: var(--primary-dark);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.header-title {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 4px;
  letter-spacing: -0.3px;
}

.header-desc {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
}

/* 主内容容器 */
.app-container {
  max-width: 680px;
  margin: -14px auto 0;
  padding: 0 14px;
}

/* 卡片通用样式 (优化内边距与呼吸感) */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  padding: 18px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(226, 232, 240, 0.8);
  position: relative;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f1f5f9;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 14px;
  background: var(--primary);
  border-radius: 2px;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}

.badge-primary { background: var(--primary-light); color: var(--primary); border: 1px solid #bfdbfe; }
.badge-success { background: var(--success-bg); color: var(--success); border: 1px solid #bbf7d0; }
.badge-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #fef08a; }
.badge-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.badge-ai {
  background: linear-gradient(135deg, #f5f3ff 0%, #eff6ff 100%);
  color: #7c3aed;
  border: 1px solid #ddd6fe;
}

/* 核心指标看板 Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.kpi-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 12px;
  transition: transform 0.15s ease;
}

.kpi-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.kpi-sub {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.trend-up {
  color: #ef4444; /* 经营数据正向增长红标 */
  font-weight: 600;
}

.trend-down {
  color: #10b981;
  font-weight: 600;
}

/* 环比对比卡片 */
.mom-card {
  background: linear-gradient(180deg, #f0fdf4 0%, #ffffff 100%);
  border: 1px solid #bbf7d0;
}

.mom-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  text-align: center;
}

.mom-item {
  background: rgba(255, 255, 255, 0.9);
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid #e2e8f0;
}

.mom-item-title {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.mom-item-val {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-main);
}

.mom-item-rate {
  font-size: 11px;
  font-weight: 600;
  margin-top: 2px;
}

/* AI 智能经营复盘卡片 (明亮高级浅紫蓝底) */
.ai-diagnosis-card {
  background: linear-gradient(145deg, #fdf4ff 0%, #f0f9ff 100%);
  border: 1px solid #e9d5ff;
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.ai-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.ai-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: #6b21a8;
}

.ai-item {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(233, 213, 255, 0.6);
}
.ai-item:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.ai-tag {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  height: fit-content;
  margin-top: 2px;
}
.tag-surge { background: #ffe4e6; color: #e11d48; border: 1px solid #fecdd3; }
.tag-finance { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.tag-alert { background: #fef3c7; color: #b45309; border: 1px solid #fde68a; }

.ai-text {
  font-size: 12px;
  color: #334155;
  line-height: 1.6;
}
.ai-text strong {
  color: #0f172a;
}

/* 图表容器 */
.chart-container {
  position: relative;
  width: 100%;
  height: 240px;
  margin: 10px 0;
}

.chart-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 10px;
  scrollbar-width: none;
}
.chart-tabs::-webkit-scrollbar { display: none; }

.chart-tab-btn {
  border: 1px solid var(--border-color);
  background: #ffffff;
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
}

.chart-tab-btn.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

/* 渠道占比与进度条 */
.progress-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.progress-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

.progress-track {
  height: 7px;
  background: #f1f5f9;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 表格移动端优化与冻结首列 */
.table-scroll-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 10px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: #ffffff;
  position: relative;
}

.custom-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  line-height: 1.45;
  text-align: left;
}

.custom-table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.custom-table td {
  padding: 11px 12px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text-main);
  white-space: nowrap;
}

.custom-table tr:last-child td {
  border-bottom: none;
}

/* 核心优化：手机横向滚动时，第一列（表头/渠道/指标/日期）固定在左侧 */
.custom-table th:first-child,
.custom-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background-color: #ffffff;
  box-shadow: 2px 0 6px -2px rgba(0, 0, 0, 0.08);
}

.custom-table th:first-child {
  background-color: #f8fafc;
  z-index: 3;
}

/* 语义化高亮行与首列背景统一管理（彻底防止横滑透底） */
.custom-table tr.tr-subtotal {
  background-color: #f8fafc;
  font-weight: 600;
}
.custom-table tr.tr-subtotal td:first-child {
  background-color: #f8fafc !important;
}

.custom-table tr.tr-total {
  background-color: #eff6ff;
  font-weight: 700;
  color: #1d4ed8;
}
.custom-table tr.tr-total td:first-child {
  background-color: #eff6ff !important;
}

.custom-table tr.tr-success {
  background-color: #f0fdf4;
  font-weight: 600;
}
.custom-table tr.tr-success td:first-child {
  background-color: #f0fdf4 !important;
}

.custom-table tr.tr-sky {
  background-color: #f0f9ff;
  font-weight: 700;
  color: #0369a1;
}
.custom-table tr.tr-sky td:first-child {
  background-color: #f0f9ff !important;
}

/* 兼容内联样式选择器兜底 */
.custom-table tr[style*="background:#f8fafc"] td:first-child,
.custom-table tr[style*="background: #f8fafc"] td:first-child {
  background-color: #f8fafc !important;
}

.custom-table tr[style*="background:#eff6ff"] td:first-child,
.custom-table tr[style*="background: #eff6ff"] td:first-child {
  background-color: #eff6ff !important;
}

.custom-table tr[style*="background:#f0fdf4"] td:first-child,
.custom-table tr[style*="background: #f0fdf4"] td:first-child {
  background-color: #f0fdf4 !important;
}

.custom-table tr[style*="background:#f0f9ff"] td:first-child,
.custom-table tr[style*="background: #f0f9ff"] td:first-child {
  background-color: #f0f9ff !important;
}

.custom-table .text-right {
  text-align: right;
}

.custom-table .bold {
  font-weight: 600;
}

/* 财务资金卡片特别定制 */
.fund-summary-box {
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.fund-box-item {
  display: flex;
  flex-direction: column;
}

.fund-box-title {
  font-size: 11px;
  color: #0369a1;
  font-weight: 600;
}

.fund-box-val {
  font-size: 20px;
  font-weight: 800;
  color: #0c4a6e;
  letter-spacing: -0.5px;
}

/* 底部浮动控制栏/标签栏 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(56px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 100;
  max-width: 680px;
  margin: 0 auto;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 8px;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
  background: transparent;
}

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

.nav-item svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}
