/**
 * Dashboard 增强样式
 * 包含：时间筛选、模态框、移动端适配、动画效果
 */

/* ========== 基础变量 ========== */
:root {
  --primary: #667eea;
  --primary-dark: #5a6fd6;
  --secondary: #764ba2;
  --success: #52c41a;
  --warning: #faad14;
  --error: #f5222d;
  --text-primary: #333;
  --text-secondary: #666;
  --text-muted: #999;
  --bg-page: #f5f7fa;
  --bg-card: #fff;
  --border-color: #e8e8e8;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.16);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

/* ========== 时间筛选器 ========== */
.filter-container {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: rgba(255,255,255,0.15);
  border-radius: var(--radius-md);
}

.time-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-label {
  color: rgba(255,255,255,0.9);
  font-size: 0.9rem;
  font-weight: 500;
}

.time-btn {
  padding: 0.4rem 0.8rem;
  border: 1px solid rgba(255,255,255,0.3);
  background: transparent;
  color: rgba(255,255,255,0.9);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.time-btn:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.5);
}

.time-btn.active {
  background: white;
  color: var(--primary);
  border-color: white;
  font-weight: 500;
}

/* ========== 模态框 ========== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: white;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow: hidden;
  animation: slideUp 0.3s ease;
}

.modal-content.large {
  max-width: 900px;
}

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

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  max-height: calc(90vh - 120px);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
}

/* 日期选择器样式 */
.date-inputs {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.date-inputs label {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.date-inputs input[type="date"] {
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.quick-ranges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.quick-ranges button {
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border-color);
  background: white;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.quick-ranges button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ========== 按钮样式 ========== */
.btn-primary {
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-secondary {
  padding: 0.5rem 1rem;
  background: white;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  border-color: var(--text-secondary);
}

/* ========== 下钻详情表格 ========== */
.detail-table {
  margin-top: 1.5rem;
  overflow-x: auto;
}

.detail-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.detail-table th,
.detail-table td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.detail-table th {
  font-weight: 600;
  color: var(--text-secondary);
  background: #fafafa;
}

.detail-table tr:hover {
  background: #fafafa;
}

/* ========== 全局加载 ========== */
.global-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255,255,255,0.9);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
  z-index: 9999;
}

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

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

/* ========== Toast 提示 ========== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  padding: 0.75rem 1.5rem;
  background: var(--error);
  color: white;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  box-shadow: var(--shadow-md);
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ========== 移动端菜单 ========== */
.mobile-menu-btn {
  display: none;
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 1.25rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.mobile-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1001;
  pointer-events: none;
}

.mobile-sidebar.active {
  pointer-events: auto;
}

.sidebar-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0);
  transition: background 0.3s ease;
}

.mobile-sidebar.active .sidebar-overlay {
  background: rgba(0,0,0,0.5);
}

.sidebar-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 280px;
  height: 100%;
  background: white;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  box-shadow: var(--shadow-lg);
}

.mobile-sidebar.active .sidebar-content {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.sidebar-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
}

.sidebar-nav a {
  padding: 0.875rem 1.25rem;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.95rem;
  transition: all 0.2s;
}

.sidebar-nav a:hover {
  background: #f5f5f5;
  color: var(--primary);
}

/* ========== 移动端抽屉 ========== */
.mobile-drawer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  pointer-events: none;
}

.mobile-drawer.active {
  pointer-events: auto;
}

.drawer-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0);
  transition: background 0.3s ease;
}

.mobile-drawer.active .drawer-overlay {
  background: rgba(0,0,0,0.5);
}

.drawer-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 1.5rem;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.mobile-drawer.active .drawer-content {
  transform: translateY(0);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.drawer-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.drawer-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.detail-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
  text-align: center;
}

.detail-label {
  text-align: center;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

/* ========== 响应式适配 ========== */
@media (max-width: 768px) {
  body.mobile {
    font-size: 14px;
  }
  
  .mobile .header {
    padding: 1rem;
  }
  
  .mobile .header h1 {
    font-size: 1.4rem;
  }
  
  .mobile .mobile-menu-btn {
    display: flex;
  }
  
  .mobile .filter-container {
    margin-top: 0.5rem;
    padding: 0.5rem;
  }
  
  .mobile .time-filter {
    gap: 0.25rem;
  }
  
  .mobile .time-btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
  }
  
  .mobile .container {
    padding: 0.75rem;
  }
  
  .mobile .stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
  }
  
  .mobile .stat-card {
    padding: 0.875rem;
  }
  
  .mobile .stat-value {
    font-size: 1.25rem;
  }
  
  .mobile .chart-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .mobile .chart-card {
    padding: 1rem;
    border-radius: var(--radius-md);
  }
  
  .mobile .chart-container {
    height: 280px;
  }
  
  .mobile .chart-title {
    font-size: 1rem;
  }
  
  .mobile .auto-refresh-status {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
    padding: 0.5rem;
  }
  
  /* 模态框移动端适配 */
  .modal {
    padding: 0.5rem;
    align-items: flex-end;
  }
  
  .modal-content {
    max-height: 85vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: slideUpMobile 0.3s ease;
  }
  
  @keyframes slideUpMobile {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  
  .modal-header {
    padding: 1rem;
  }
  
  .modal-body {
    padding: 1rem;
    max-height: calc(85vh - 100px);
  }
  
  .detail-table {
    font-size: 0.8rem;
  }
  
  .detail-table th,
  .detail-table td {
    padding: 0.5rem;
  }
}

@media (max-width: 480px) {
  .mobile .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .mobile .stat-card {
    padding: 0.75rem;
  }
  
  .mobile .stat-label {
    font-size: 0.7rem;
  }
  
  .mobile .stat-value {
    font-size: 1.1rem;
  }
  
  .mobile .stat-change {
    font-size: 0.65rem;
  }
  
  .mobile .chart-container {
    height: 240px;
  }
}

/* ========== 横屏优化 ========== */
@media (max-width: 768px) and (orientation: landscape) {
  .mobile .chart-container {
    height: 220px;
  }
  
  .mobile .stats-row {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ========== 图表tooltip优化 ========== */
.mobile .echarts-tooltip {
  font-size: 12px !important;
  padding: 8px 12px !important;
  border-radius: 8px !important;
}

/* ========== 性能优化 ========== */
.chart-container {
  contain: layout style paint;
}

.stat-card {
  will-change: transform;
}

/* ========== 无障碍 ========== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========== 深色模式支持 ========== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-page: #1a1a1a;
    --bg-card: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border-color: #404040;
  }
  
  body {
    background: var(--bg-page);
  }
  
  .chart-card,
  .stat-card {
    background: var(--bg-card);
  }
  
  .stat-value {
    color: var(--text-primary);
  }
}
