/**
 * 响应式设计样式
 * @file responsive.css
 * @description 提供全面的响应式设计支持，确保在各种设备上的良好体验
 */

/* ========== 断点定义 ========== */
:root {
  /* 屏幕断点 */
  --screen-xs: 480px;    /* 超小屏幕 */
  --screen-sm: 576px;    /* 小屏幕 */
  --screen-md: 768px;    /* 中等屏幕 */
  --screen-lg: 992px;    /* 大屏幕 */
  --screen-xl: 1200px;   /* 超大屏幕 */
  --screen-xxl: 1600px;  /* 超超大屏幕 */
  
  /* 移动端优化变量 */
  --mobile-padding: 12px;
  --mobile-margin: 8px;
  --mobile-font-size: 14px;
  --mobile-button-height: 40px;
  --mobile-input-height: 40px;
  
  /* 触摸友好的最小点击区域 */
  --touch-target-min: 44px;
}

/* ========== 全局响应式基础 ========== */
* {
  box-sizing: border-box;
}

body {
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch; /* iOS 平滑滚动 */
}

/* ========== 移动端基础布局 ========== */
@media (max-width: 768px) {
  /* 页面标题区域 */
  .page-header {
    flex-direction: column;
    gap: 12px;
    align-items: stretch !important;
  }
  
  .page-header h1 {
    font-size: 20px;
    margin-bottom: 8px;
  }
  
  .page-actions {
    justify-content: center;
  }
  
  /* 搜索区域移动端优化 */
  .search-area {
    flex-direction: column;
    gap: 8px;
  }
  
  .search-input {
    width: 100% !important;
  }
  
  .search-buttons {
    display: flex;
    gap: 8px;
    width: 100%;
  }
  
  .search-buttons .ant-btn {
    flex: 1;
    height: var(--mobile-button-height);
  }
  
  /* 表格移动端优化 */
  .ant-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .ant-table {
    min-width: 600px; /* 确保表格在小屏幕上可滚动 */
  }
  
  .ant-table-thead > tr > th {
    padding: 8px 4px;
    font-size: 12px;
  }
  
  .ant-table-tbody > tr > td {
    padding: 8px 4px;
    font-size: 12px;
  }
  
  /* 操作按钮移动端优化 */
  .table-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  
  .table-actions .ant-btn {
    width: 100%;
    height: 32px;
    font-size: 12px;
  }
  
  /* 模态框移动端优化 */
  .ant-modal {
    margin: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    top: 0 !important;
    padding-bottom: 0 !important;
  }
  
  .ant-modal-content {
    border-radius: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
  }
  
  .ant-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
  }
  
  .ant-modal-footer {
    border-top: 1px solid #f0f0f0;
    padding: 12px 16px;
  }
  
  .ant-modal-footer .ant-btn {
    height: var(--mobile-button-height);
    margin: 0 4px;
  }
  
  /* 表单移动端优化 */
  .ant-form-item-label {
    font-size: var(--mobile-font-size);
  }
  
  .ant-input,
  .ant-input-number,
  .ant-select-selector,
  .ant-picker {
    height: var(--mobile-input-height) !important;
    font-size: var(--mobile-font-size);
  }
  
  .ant-select-selection-item {
    line-height: calc(var(--mobile-input-height) - 2px);
  }
  
  /* 卡片组件移动端优化 */
  .ant-card {
    margin-bottom: 12px;
  }
  
  .ant-card-head {
    padding: 0 12px;
    min-height: 48px;
  }
  
  .ant-card-body {
    padding: 12px;
  }
  
  /* 分页器移动端优化 */
  .ant-pagination {
    text-align: center;
    margin-top: 16px;
  }
  
  .ant-pagination-item,
  .ant-pagination-prev,
  .ant-pagination-next {
    min-width: var(--touch-target-min);
    height: var(--touch-target-min);
    line-height: var(--touch-target-min);
  }
}

/* ========== 平板端优化 (768px - 992px) ========== */
@media (min-width: 768px) and (max-width: 992px) {
  .page-header {
    padding: 16px 20px;
  }
  
  .ant-table-thead > tr > th,
  .ant-table-tbody > tr > td {
    padding: 12px 8px;
  }
  
  .ant-modal {
    width: 90vw !important;
    max-width: 800px !important;
  }
  
  .search-area {
    flex-wrap: wrap;
    gap: 12px;
  }
  
  .search-input {
    min-width: 250px;
    flex: 1;
  }
}

/* ========== 大屏幕优化 (>1600px) ========== */
@media (min-width: 1600px) {
  .page-container {
    max-width: 1400px;
    margin: 0 auto;
  }
  
  .dashboard-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .chart-container {
    height: 500px;
  }
}

/* ========== 移动端导航优化 ========== */
@media (max-width: 768px) {
  /* 侧边栏移动端优化 */
  .ant-layout-sider {
    position: fixed !important;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1001;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  
  .ant-layout-sider.ant-layout-sider-collapsed {
    transform: translateX(-100%);
  }
  
  .ant-layout-sider:not(.ant-layout-sider-collapsed) {
    transform: translateX(0);
  }
  
  /* 移动端顶部栏 */
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
    position: sticky;
    top: 0;
    z-index: 1000;
  }
  
  .mobile-menu-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--touch-target-min);
    height: var(--touch-target-min);
    border: none;
    background: transparent;
    cursor: pointer;
  }
  
  .mobile-title {
    font-size: 18px;
    font-weight: 600;
    color: #262626;
  }
  
  /* 内容区域移动端调整 */
  .ant-layout-content {
    padding: 12px !important;
    margin-left: 0 !important;
  }
  
  /* 面包屑移动端优化 */
  .ant-breadcrumb {
    font-size: 12px;
    margin-bottom: 8px;
  }
}

/* ========== 移动端表格优化 ========== */
@media (max-width: 576px) {
  .responsive-table {
    display: block;
  }
  
  .responsive-table .ant-table-wrapper {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
  
  .responsive-table .ant-table {
    display: block;
    min-width: auto;
  }
  
  .responsive-table .ant-table-thead {
    display: none; /* 在超小屏幕上隐藏表头 */
  }
  
  .responsive-table .ant-table-tbody {
    display: block;
  }
  
  .responsive-table .ant-table-row {
    display: block;
    border: 1px solid #f0f0f0;
    border-radius: 8px;
    margin-bottom: 12px;
    padding: 12px;
    background: #fff;
  }
  
  .responsive-table .ant-table-cell {
    display: block;
    border: none;
    padding: 4px 0;
    text-align: left !important;
  }
  
  .responsive-table .ant-table-cell:before {
    content: attr(data-label) ": ";
    font-weight: 600;
    color: #595959;
    min-width: 80px;
    display: inline-block;
  }
}

/* ========== 移动端图表优化 ========== */
@media (max-width: 768px) {
  .chart-container {
    height: 300px !important;
    margin-bottom: 16px;
  }
  
  .dashboard-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px;
  }
  
  .stat-card {
    padding: 12px !important;
  }
  
  .stat-card .stat-value {
    font-size: 20px !important;
  }
  
  .stat-card .stat-label {
    font-size: 12px !important;
  }
}

/* ========== 移动端地图优化 ========== */
@media (max-width: 768px) {
  .map-container {
    height: 60vh !important;
    margin: 0 -12px;
  }
  
  .map-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  
  .map-controls .ant-btn {
    width: var(--touch-target-min);
    height: var(--touch-target-min);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* ========== 移动端性能优化 ========== */
@media (max-width: 768px) {
  /* 减少阴影效果以提升性能 */
  .ant-card,
  .ant-modal-content,
  .ant-drawer-content {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
  }
  
  /* 优化动画性能 */
  .ant-table-tbody > tr:hover > td {
    background: #f5f5f5 !important;
  }
  
  /* 禁用某些在移动端不必要的动画 */
  .ant-table-tbody > tr {
    transition: none !important;
  }
}

/* ========== 触摸设备优化 ========== */
@media (hover: none) and (pointer: coarse) {
  /* 为触摸设备优化点击区域 */
  .ant-btn,
  .ant-input,
  .ant-select-selector,
  .ant-picker,
  .ant-table-row {
    min-height: var(--touch-target-min);
  }
  
  /* 移除悬停效果，因为触摸设备不需要 */
  .ant-btn:hover,
  .ant-table-tbody > tr:hover > td {
    background: inherit !important;
  }
  
  /* 触摸反馈 */
  .ant-btn:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
}

/* ========== 横屏模式优化 ========== */
@media (max-width: 768px) and (orientation: landscape) {
  .mobile-header {
    padding: 8px 16px;
  }
  
  .chart-container {
    height: 40vh !important;
  }
  
  .ant-modal-content {
    height: 100vh;
  }
}

/* ========== 可访问性改进 ========== */
@media (prefers-reduced-motion: reduce) {
  /* 为喜欢减少动画的用户提供静态体验 */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========== 高对比度模式支持 ========== */
@media (prefers-contrast: high) {
  .ant-btn-primary {
    background: #000 !important;
    border-color: #000 !important;
  }
  
  .ant-table-thead > tr > th {
    background: #f0f0f0 !important;
    border: 1px solid #d9d9d9 !important;
  }
}

/* ========== 深色模式基础支持 ========== */
@media (prefers-color-scheme: dark) {
  .ant-layout {
    background: #141414 !important;
  }
  
  .ant-layout-content {
    background: #000 !important;
  }
  
  .ant-card {
    background: #1f1f1f !important;
    border-color: #434343 !important;
  }
  
  .ant-table-wrapper {
    background: #1f1f1f !important;
  }
}

/* ========== 特定组件移动端优化 ========== */

/* 分页器移动端优化 */
@media (max-width: 576px) {
  .ant-pagination {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
  }
  
  .ant-pagination-options {
    display: none; /* 隐藏页面大小选择器 */
  }
  
  .ant-pagination-simple {
    margin: 8px 0;
  }
}

/* 标签移动端优化 */
@media (max-width: 768px) {
  .ant-tag {
    margin: 2px;
    padding: 0 8px;
    font-size: 12px;
  }
}

/* 统计卡片移动端优化 */
@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  
  .stats-grid .ant-col {
    margin-bottom: 8px;
  }
}

/* 图表容器移动端优化 */
@media (max-width: 768px) {
  .charts-row {
    flex-direction: column;
  }
  
  .chart-card {
    margin-bottom: 16px;
  }
  
  .chart-card .ant-card-body {
    padding: 12px;
  }
}

/* ========== 自定义移动端布局类 ========== */
.mobile-container {
  padding: var(--mobile-padding);
}

.mobile-hidden {
  display: none;
}

.mobile-only {
  display: none;
}

@media (max-width: 768px) {
  .mobile-hidden {
    display: none !important;
  }
  
  .mobile-only {
    display: block;
  }
  
  .mobile-flex {
    display: flex !important;
  }
  
  .mobile-full-width {
    width: 100% !important;
  }
  
  .mobile-text-center {
    text-align: center !important;
  }
}

/* ========== 加载状态移动端优化 ========== */
@media (max-width: 768px) {
  .ant-spin-container {
    min-height: 200px;
  }
  
  .ant-empty {
    margin: 32px 0;
  }
  
  .ant-empty-description {
    font-size: var(--mobile-font-size);
  }
}

/* ========== 消息提示移动端优化 ========== */
@media (max-width: 768px) {
  .ant-message {
    top: 20px !important;
  }
  
  .ant-message-notice {
    margin-bottom: 8px;
  }
  
  .ant-notification {
    width: calc(100vw - 32px) !important;
    margin-right: 16px !important;
  }
}

/* ========== 菜单移动端优化 ========== */
@media (max-width: 768px) {
  .ant-menu-item {
    height: 48px;
    line-height: 48px;
    padding: 0 16px !important;
  }
  
  .ant-menu-item-icon {
    font-size: 16px;
  }
  
  .ant-menu-submenu-title {
    height: 48px;
    line-height: 48px;
    padding: 0 16px !important;
  }
}

/* ========== 工具提示移动端优化 ========== */
@media (max-width: 768px) {
  .ant-tooltip {
    font-size: 12px;
  }
  
  /* 在移动端禁用工具提示，因为没有悬停 */
  .ant-tooltip-hidden-arrow {
    display: none !important;
  }
}

/* ========== 表单布局移动端优化 ========== */
@media (max-width: 768px) {
  .ant-row {
    margin: 0 !important;
  }
  
  .ant-col {
    padding: 0 4px !important;
    margin-bottom: 12px;
  }
  
  .ant-form-item {
    margin-bottom: 16px;
  }
  
  .ant-form-item-control {
    width: 100%;
  }
}

/* ========== 调试辅助类 ========== */
.debug-breakpoint {
  position: fixed;
  top: 10px;
  left: 10px;
  background: rgba(255, 0, 0, 0.8);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  z-index: 9999;
  font-family: monospace;
}

.debug-breakpoint:after {
  content: 'Desktop';
}

@media (max-width: 1600px) {
  .debug-breakpoint:after {
    content: 'XL';
  }
}

@media (max-width: 1200px) {
  .debug-breakpoint:after {
    content: 'LG';
  }
}

@media (max-width: 992px) {
  .debug-breakpoint:after {
    content: 'MD';
  }
}

@media (max-width: 768px) {
  .debug-breakpoint:after {
    content: 'SM';
  }
}

@media (max-width: 576px) {
  .debug-breakpoint:after {
    content: 'XS';
  }
}
