/* ================================================================
   工具类 - Utilities
   包含：响应式工具、打印样式、动画工具
   ================================================================ */

/* ============= 响应式断点 ============= */
:root {
  --breakpoint-xs: 0px;
  --breakpoint-sm: 480px;
  --breakpoint-md: 768px;
  --breakpoint-lg: 1024px;
  --breakpoint-xl: 1280px;
  --breakpoint-2xl: 1536px;
}

/* ============= 大屏幕 (1280px+) ============= */
@media (min-width: 1280px) {
  .main-content {
    max-width: 1280px;
    padding: 2rem 1.5rem;
  }
  
  .results-grid,
  .sites-grid {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 2rem;
  }
}

/* ============= 中大屏幕 (1024px - 1279px) ============= */
@media (max-width: 1279px) and (min-width: 1024px) {
  .main-content {
    padding: 1.5rem 1rem;
  }
  
  .results-grid,
  .sites-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.75rem;
  }
}

/* ============= 中等屏幕 (768px - 1023px) ============= */
@media (max-width: 1023px) and (min-width: 768px) {
  .nav-container {
    padding: 0 1rem;
    height: 64px;
  }
  
  .nav-brand .brand-text {
    font-size: 1.25rem;
  }
  
  .main-content {
    padding: 1.5rem 1rem;
  }
  
  .hero {
    padding: 2rem 0;
    margin-bottom: 3rem;
  }
  
  .hero-title {
    font-size: 2rem;
  }
  
  .section-header {
    flex-direction: column;
    align-items: stretch;
  }
  
  .connection-status {
    top: 72px;
    right: 1rem;
    font-size: 0.85rem;
  }
}

/* ============= 小屏幕 (最大767px) ============= */
@media (max-width: 767px) {
  .nav-brand .brand-text {
    display: none;
  }
  
  .main-content {
    padding: 1rem 0.75rem;
  }
  
  .hero-title {
    font-size: 1.75rem;
  }
  
  section {
    padding: 1.5rem;
  }
  
  .results-grid,
  .favorites-grid,
  .sites-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* ============= 超小屏幕 (最大479px) ============= */
@media (max-width: 479px) {
  section {
    padding: 1rem;
  }
  
  .btn,
  .action-btn {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
  }
}

/* ============= 动画工具类 ============= */
.animate-fade-in {
  animation: fadeIn 0.3s ease-in-out;
}

.animate-slide-in {
  animation: slideIn 0.3s ease;
}

.animate-spin {
  animation: spin 1s linear infinite;
}

.animate-pulse {
  animation: pulse 2s infinite;
}

/* ============= 打印样式 ============= */
@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  
  @page {
    margin: 2cm;
    size: A4;
  }
  
  /* 隐藏不需要打印的元素 */
  .navbar,
  .modal,
  .loading,
  .toast,
  .connection-status,
  button,
  .action-btn,
  .form-actions,
  .dropdown {
    display: none !important;
  }
  
  /* 基础布局调整 */
  body {
    font-family: 'Times New Roman', serif;
    font-size: 12pt;
    line-height: 1.4;
    color: #000;
    background: #fff;
  }
  
  .main-content {
    max-width: none;
    padding: 0;
    margin: 0;
  }
  
  /* 标题优化 */
  h1, h2, h3, h4, h5, h6 {
    color: #000;
    page-break-after: avoid;
    margin-top: 24pt;
    margin-bottom: 12pt;
  }
  
  h1 { font-size: 18pt; }
  h2 { font-size: 16pt; }
  h3 { font-size: 14pt; }
  
  /* 链接处理 */
  a {
    color: #000;
  }
  
  a[href^="http"]:after {
    content: " (" attr(href) ")";
    font-size: 10pt;
    color: #666;
  }
  
  /* 避免分页 */
  .result-item,
  .favorite-item,
  .site-item,
  section {
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 12pt;
  }
  
  /* 表格优化 */
  table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 12pt;
    break-inside: avoid;
  }
  
  th, td {
    border: 1px solid #000;
    padding: 6pt;
    text-align: left;
  }
  
  th {
    background-color: #f0f0f0 !important;
    font-weight: bold;
  }
  
  /* 网格布局调整 */
  .results-grid,
  .favorites-grid,
  .sites-grid {
    display: block;
  }
  
  .result-item,
  .favorite-item,
  .site-item {
    display: block;
    border: 1px solid #000;
    padding: 12pt;
    margin-bottom: 12pt;
    background: none;
    box-shadow: none;
  }
}

/* ============= 高对比度模式 ============= */
@media (prefers-contrast: high) {
  :root {
    --bg-primary: #ffffff;
    --bg-secondary: #f0f0f0;
    --bg-tertiary: #e0e0e0;
    --text-primary: #000000;
    --text-secondary: #333333;
    --border-color: #333333;
    --accent-primary: #0066cc;
    --accent-hover: #004499;
  }
  
  [data-theme="dark"] {
    --bg-primary: #000000;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #333333;
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --border-color: #cccccc;
  }
  
  .btn,
  .action-btn,
  .result-item,
  .site-item {
    border-width: 2px;
  }
}

/* ============= 减少动画偏好 ============= */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  
  .spinner {
    animation: none;
    border: 4px solid var(--accent-primary);
  }
  
  .status-dot {
    animation: none;
  }
}

/* ============= 触摸设备优化 ============= */
@media (hover: none) and (pointer: coarse) {
  .btn,
  .action-btn {
    min-height: 48px;
    min-width: 48px;
    padding: 1rem 1.5rem;
  }
  
  .nav-link {
    padding: 1rem 1.25rem;
  }
}

/* ============= 方向查询 ============= */
@media (orientation: portrait) {
  .hero {
    padding: 2rem 0;
  }
}

@media (orientation: landscape) {
  .hero {
    padding: 3rem 0;
  }
}

/* ============= 通用工具类 ============= */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }
.p-4 { padding: 2rem; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }

.w-full { width: 100%; }
.h-full { height: 100%; }

.hidden { display: none; }
.block { display: block; }
.inline-block { display: inline-block; }

.opacity-50 { opacity: 0.5; }
.opacity-75 { opacity: 0.75; }

.cursor-pointer { cursor: pointer; }
.cursor-not-allowed { cursor: not-allowed; }

.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }

.rounded { border-radius: var(--radius-md); }
.rounded-full { border-radius: 9999px; }

.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

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

.bg-primary { background: var(--bg-primary); }
.bg-secondary { background: var(--bg-secondary); }
.bg-tertiary { background: var(--bg-tertiary); }
.bg-accent { background: var(--accent-primary); }
.bg-success { background: var(--success-color); }
.bg-warning { background: var(--warning-color); }
.bg-error { background: var(--error-color); }

/* ============= 过渡工具类 ============= */
.transition { transition: var(--transition-base); }
.transition-all { transition: all var(--transition-base); }
.transition-colors { transition: color var(--transition-base), background-color var(--transition-base); }
.transition-transform { transition: transform var(--transition-base); }

/* ============= 变换工具类 ============= */
.scale-105:hover { transform: scale(1.05); }
.scale-95:hover { transform: scale(0.95); }
.translate-y-1:hover { transform: translateY(-0.25rem); }
.translate-y-2:hover { transform: translateY(-0.5rem); }
.rotate-180 { transform: rotate(180deg); }

/* ============= 字体工具类 ============= */
.font-normal { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }