:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --muted: #64748b;
  --text: #0f172a;
  --accent: #6366f1;
  --border: #e2e8f0;
  --green: #10b981;
  --yellow: #f59e0b;
  --red: #ef4444;
  --shadow: rgba(15, 23, 42, 0.08);
  --shadow-lg: rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, 'Apple Color Emoji', 'Segoe UI Emoji';
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%),
              radial-gradient(circle at 20% 50%, rgba(120, 119, 198, 0.3), transparent 50%),
              radial-gradient(circle at 80% 80%, rgba(99, 102, 241, 0.2), transparent 50%),
              var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px var(--shadow);
  z-index: 10;
  gap: 16px;
  flex-wrap: wrap;
}
.header-left { display: flex; flex-direction: column; gap: 4px; }
.app-header h1 { font-size: 20px; margin: 0; letter-spacing: 0.3px; }
.controls { display: flex; align-items: center; gap: 16px; }

/* 语言切换器 */
.lang-switcher {
  display: flex;
  gap: 4px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 8px;
}

.lang-btn {
  padding: 6px 12px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.lang-btn:hover {
  background: #e2e8f0;
  color: #475569;
}

.lang-btn.active {
  background: white;
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
@media (max-width: 640px) {
  .app-header { padding: 16px; }
  .app-header h1 { font-size: 18px; }
}
.btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s ease;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}
.btn:hover {
  background: #4f46e5;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
  transform: translateY(-1px);
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .6; cursor: not-allowed; box-shadow: none; }
.btn.loading { position: relative; padding-left: 36px; }
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
}
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }
.muted { color: var(--muted); font-size: 12px; }

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

@media (max-width: 768px) {
  .container { padding: 16px; }
  .btn { padding: 8px 12px; font-size: 14px; }
  .btn.loading { padding-left: 32px; }
  .spinner { left: 12px; width: 12px; height: 12px; }
}

/* Tab导航 */
.tab-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: white;
  padding: 8px;
  border-radius: 12px;
  box-shadow: 0 2px 8px var(--shadow);
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: 2px solid transparent;
  background: transparent;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn:hover {
  background: #f8fafc;
  color: #475569;
}

.tab-btn.active {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.tab-flag { 
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 20px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  position: relative;
  overflow: hidden;
}

/* 越南国旗 - 红色背景 + 黄星 */
.tab-flag[data-flag="VN"] {
  background: linear-gradient(180deg, #da251d 0%, #da251d 100%);
}
.tab-flag[data-flag="VN"]::before {
  content: "★";
  color: #ffcd00;
  font-size: 14px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* 台湾旗 - 红蓝白 */
.tab-flag[data-flag="TW"] {
  background: linear-gradient(180deg, #fe0000 0%, #fe0000 50%, #000095 50%, #000095 100%);
}
.tab-flag[data-flag="TW"]::before {
  content: "TW";
  font-size: 9px;
  color: white;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* 泰国国旗 - 红白蓝条纹 */
.tab-flag[data-flag="TH"] {
  background: 
    linear-gradient(180deg, 
      #a51931 0%, #a51931 16.67%,
      white 16.67%, white 33.33%,
      #2d2a4a 33.33%, #2d2a4a 66.67%,
      white 66.67%, white 83.33%,
      #a51931 83.33%, #a51931 100%
    );
}
.tab-flag[data-flag="TH"]::before {
  content: "TH";
  font-size: 9px;
  color: white;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
  background: rgba(0,0,0,0.3);
  padding: 1px 3px;
  border-radius: 2px;
}
.tab-name { font-size: 15px; }

@media (max-width: 640px) {
  .tab-btn { padding: 10px 12px; }
  .tab-flag { font-size: 18px; }
  .tab-name { font-size: 13px; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
  box-shadow: 0 4px 16px var(--shadow-lg);
  overflow: hidden;
  will-change: transform;
}

.data-card {
  animation: fadeIn 0.3s ease;
}

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

/* 平滑滚动 */
html {
  scroll-behavior: smooth;
}

.card-header-info {
  display: flex;
  gap: 32px;
  padding: 20px 24px;
  background: linear-gradient(135deg, #f8fafc, #ffffff);
  border-bottom: 1px solid var(--border);
}

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

.info-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.3px;
}

.info-value {
  font-size: 16px;
  color: var(--text);
  font-weight: 600;
}

@media (max-width: 640px) {
  .card-header-info { padding: 16px; gap: 20px; flex-wrap: wrap; }
}

/* 表格样式 */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  will-change: scroll-position;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  table-layout: fixed;
}

.data-table thead {
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table th {
  padding: 16px 20px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  color: #475569;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table tbody tr {
  border-bottom: 1px solid #f1f5f9;
  transition: background-color 0.15s ease;
}

.data-table tbody tr:hover {
  background: #f8fafc;
  cursor: default;
}

.data-table tbody tr:active {
  background: #f1f5f9;
}

.data-table td {
  padding: 16px 20px;
  color: var(--text);
  vertical-align: middle;
}

/* 列宽度和对齐 */
.col-rank { width: 80px; text-align: center; }
th.col-rank, td.col-rank { text-align: center; }

.col-domain { width: 25%; min-width: 200px; text-align: left; }
th.col-domain, td.col-domain { text-align: left; }

.col-country-req { width: 11%; text-align: right; }
th.col-country-req, td.col-country-req { text-align: right; }

.col-uv { width: 10%; text-align: right; }
th.col-uv, td.col-uv { text-align: right; }

.col-total-req { width: 11%; text-align: right; }
th.col-total-req, td.col-total-req { text-align: right; }

.col-percent { width: 8%; text-align: right; }
th.col-percent, td.col-percent { text-align: right; }

.col-quality { width: 10%; text-align: center; }
th.col-quality, td.col-quality { text-align: center; }

.col-cache { width: 10%; text-align: center; }
th.col-cache, td.col-cache { text-align: center; }

.col-score { width: 10%; text-align: center; }
th.col-score, td.col-score { text-align: center; }

/* 排名徽章 */
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #e2e8f0;
  color: #475569;
  font-weight: 700;
  font-size: 14px;
}

.rank-badge.rank-1 { 
  background: linear-gradient(135deg, #fbbf24, #f59e0b); 
  color: #78350f; 
  box-shadow: 0 2px 12px rgba(251, 191, 36, 0.4); 
}
.rank-badge.rank-2 { 
  background: linear-gradient(135deg, #94a3b8, #cbd5e1); 
  color: #1e293b; 
  box-shadow: 0 2px 12px rgba(148, 163, 184, 0.4); 
}
.rank-badge.rank-3 { 
  background: linear-gradient(135deg, #fb923c, #f97316); 
  color: #7c2d12; 
  box-shadow: 0 2px 12px rgba(251, 146, 60, 0.4); 
}

/* 域名容器 */
.domain-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

/* 域名链接 */
.domain-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 15px;
  transition: color 0.2s ease;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.domain-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* 站点标题 */
.site-title {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 400;
  line-height: 1.4;
  font-family: 'Inter', 'Segoe UI', 'Segoe UI Emoji', 'Noto Color Emoji', 'Apple Color Emoji', system-ui, sans-serif;
}

.site-title.loading {
  color: #cbd5e1;
  font-style: italic;
}

.site-title.error {
  color: #ef4444;
  font-size: 11px;
}

/* 数值单元格 */
.cell-number {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}

/* 百分比 */
.cell-percent {
  color: #64748b;
  font-weight: 600;
  font-size: 14px;
}

/* UV质量 */
.quality-badge {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  min-width: 60px;
  text-align: center;
}

.quality-high { background: #d1fae5; color: #065f46; }
.quality-medium { background: #fef3c7; color: #92400e; }
.quality-low { background: #fee2e2; color: #991b1b; }

/* 缓存率 */
.cache-badge {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  min-width: 60px;
  text-align: center;
}

.cache-high { background: #dbeafe; color: #1e40af; }
.cache-medium { background: #e0e7ff; color: #4338ca; }
.cache-low { background: #fce7f3; color: #9f1239; }

/* 评分 */
.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 17px;
  font-weight: 700;
  margin: 0 auto;
}

.score-excellent { background: linear-gradient(135deg, #10b981, #059669); color: white; box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3); }
.score-good { background: linear-gradient(135deg, #3b82f6, #2563eb); color: white; box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }
.score-fair { background: linear-gradient(135deg, #f59e0b, #d97706); color: white; box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3); }
.score-poor { background: linear-gradient(135deg, #ef4444, #dc2626); color: white; box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3); }

@media (max-width: 768px) {
  .data-table { font-size: 13px; }
  .data-table th { padding: 12px 14px; font-size: 11px; }
  .data-table td { padding: 14px; }
  .col-domain { min-width: 160px; }
  .cell-number { font-size: 14px; }
  .domain-link { font-size: 14px; }
  .quality-badge, .cache-badge { font-size: 11px; padding: 4px 8px; min-width: 50px; }
  .score-badge { width: 44px; height: 44px; font-size: 15px; }
  .rank-badge { width: 28px; height: 28px; font-size: 13px; }
}

.toast {
  position: fixed; left: 50%; top: 20px; transform: translateX(-50%);
  background: white; border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 10px; 
  box-shadow: 0 8px 24px var(--shadow-lg);
  font-weight: 500;
}

.skeleton-row {
  animation: shimmer 1.2s infinite;
}

.skeleton-row td {
  padding: 14px 16px;
}

.skeleton-cell {
  height: 16px;
  background: linear-gradient(90deg, #f1f5f9, #e2e8f0, #f1f5f9);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: shimmer 1.2s infinite;
}

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

.empty-state, .error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  gap: 12px;
}
.empty-icon, .error-icon { font-size: 48px; opacity: 0.5; }
.empty-text, .error-text { color: var(--muted); font-size: 15px; font-weight: 500; }
.retry-btn {
  margin-top: 8px;
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.retry-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(124,58,237,0.4); }
.retry-btn:active { transform: translateY(0); }


