/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a1f2e;
  --bg-card-hover: #1e2537;
  --bg-input: #0d1321;
  --border: #2a3040;
  --border-light: #3a4050;

  --text-primary: #f1f3f5;
  --text-secondary: #9aa0b0;
  --text-muted: #6b7280;

  --accent-blue: #3b82f6;
  --accent-blue-hover: #2563eb;
  --accent-cyan: #06b6d4;
  --accent-purple: #8b5cf6;

  --bullish: #ef4444;
  --bullish-bg: rgba(239, 68, 68, 0.12);
  --bearish: #22c55e;
  --bearish-bg: rgba(34, 197, 94, 0.12);
  --flat: #9aa0b0;

  --gold: #f59e0b;
  --gold-bg: rgba(245, 158, 11, 0.12);

  --font-sans: 'Inter', 'Noto Sans TC', system-ui, -apple-system, sans-serif;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

html { scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 1400px; margin: 0 auto; padding: 0 20px; }
.desktop-only { display: block; }
@media (max-width: 768px) { .desktop-only { display: none; } }

/* === Navbar === */
.navbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.nav-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.nav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
}
.logo-icon { font-size: 24px; }
.logo-text {
  font-size: 20px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--bullish) 0%, var(--gold) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.logo-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  background: var(--accent-blue);
  border-radius: 20px;
  color: white;
  letter-spacing: 0.5px;
}
.update-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}
.update-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-cyan);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* === Hero === */
.hero {
  padding: 48px 0 32px;
  text-align: center;
}
.hero-title { margin-bottom: 12px; }
.hero-title-main {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #ef4444 0%, #f59e0b 50%, #ef4444 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-title-sub {
  display: block;
  font-size: 16px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: 4px;
  letter-spacing: 4px;
}
.hero-desc {
  color: var(--text-muted);
  font-size: 15px;
  max-width: 600px;
  margin: 0 auto 28px;
}
.hero-stats {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 28px;
  min-width: 140px;
}
.stat-value {
  display: block;
  font-size: 24px;
  font-weight: 700;
  color: var(--accent-cyan);
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* === Section === */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.section-title {
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-icon { font-size: 22px; }
.filter-actions, .result-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.filter-count, .result-count {
  font-size: 14px;
  color: var(--text-secondary);
  background: var(--bg-card);
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  font-family: var(--font-sans);
}
.btn-primary {
  background: var(--accent-blue);
  color: white;
}
.btn-primary:hover { background: var(--accent-blue-hover); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.btn-ghost:hover {
  color: var(--text-primary);
  background: var(--bg-card);
  border-color: var(--border);
}
.btn-outline {
  background: transparent;
  color: var(--accent-cyan);
  border: 1px solid var(--border);
}
.btn-outline:hover {
  background: rgba(6, 182, 212, 0.1);
  border-color: var(--accent-cyan);
}
.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--bullish);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

/* === Filter Grid === */
.filters {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
}
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}
.filter-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  user-select: none;
}
.filter-item:hover {
  border-color: var(--border-light);
  background: var(--bg-card-hover);
}
.filter-item.active {
  border-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.06);
  box-shadow: 0 0 0 1px rgba(6, 182, 212, 0.3);
}
.filter-item.active .filter-checkbox {
  background: var(--accent-cyan);
  border-color: var(--accent-cyan);
}
.filter-item.active .filter-checkbox::after {
  opacity: 1;
}
.filter-checkbox {
  width: 18px;
  height: 18px;
  min-width: 18px;
  border: 2px solid var(--border-light);
  border-radius: 4px;
  margin-top: 2px;
  position: relative;
  transition: all 0.2s;
}
.filter-checkbox::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s;
}
.filter-info { flex: 1; min-width: 0; }
.filter-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}
.filter-name .filter-num {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  margin-right: 4px;
}
.filter-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* === Loading === */
.loading-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* === Empty & Error States === */
.empty-state, .error-state {
  text-align: center;
  padding: 60px 20px;
}
.empty-icon, .error-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3, .error-state h3 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--text-secondary);
}
.empty-state p, .error-state p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 16px;
}

/* === Table === */
.table-wrapper {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  overflow-x: auto;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table thead {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.data-table th {
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color 0.2s;
}
.data-table th:hover { color: var(--text-primary); }
.sort-arrow { font-size: 10px; margin-left: 2px; opacity: 0.5; }
.data-table th.sorted .sort-arrow { opacity: 1; color: var(--accent-cyan); }
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody tr {
  transition: background 0.15s;
}
.data-table tbody tr:hover {
  background: var(--bg-card-hover);
}
.data-table tbody tr:last-child td { border-bottom: none; }

/* Stock price colors */
.up { color: var(--bullish); }
.down { color: var(--bearish); }
.flat { color: var(--flat); }

.stock-code {
  font-weight: 700;
  color: var(--accent-cyan);
  cursor: pointer;
}
.stock-code:hover { text-decoration: underline; }
.stock-name { font-weight: 500; }

.change-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 13px;
}
.change-badge.up {
  background: var(--bullish-bg);
  color: var(--bullish);
}
.change-badge.down {
  background: var(--bearish-bg);
  color: var(--bearish);
}
.change-badge.flat {
  background: rgba(154, 160, 176, 0.12);
  color: var(--flat);
}

.volume-cell { font-weight: 500; }

.market-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.market-badge.twse {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
}
.market-badge.tpex {
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
}

.match-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.match-tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--gold-bg);
  color: var(--gold);
  border: 1px solid rgba(245, 158, 11, 0.2);
  white-space: nowrap;
}

.stock-row-highlight {
  animation: rowFlash 0.6s ease;
}
@keyframes rowFlash {
  0% { background: rgba(6, 182, 212, 0.1); }
  100% { background: transparent; }
}

/* === Footer === */
.footer {
  margin-top: 48px;
  padding: 28px 0;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
}
.footer-content {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}
.footer-disclaimer { margin-top: 6px; font-size: 12px; color: var(--text-muted); }
.footer-tech { margin-top: 4px; }
.footer-update { text-align: right; }

/* === Toast === */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
  z-index: 999;
  pointer-events: none;
  max-width: 360px;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.error { border-left: 3px solid var(--bullish); }
.toast.success { border-left: 3px solid var(--bearish); }
.toast.info { border-left: 3px solid var(--accent-cyan); }

/* === Responsive === */
@media (max-width: 768px) {
  .hero-title-main { font-size: 28px; }
  .hero-desc { font-size: 14px; }
  .hero-stats { gap: 8px; }
  .stat-card { padding: 12px 16px; min-width: 100px; }
  .stat-value { font-size: 20px; }
  .filter-grid {
    grid-template-columns: 1fr;
  }
  .filters { padding: 16px; }
  .section-header { flex-direction: column; align-items: flex-start; }
  .filter-actions, .result-actions { width: 100%; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 10px; }
  .nav-container { padding: 0 12px; }
  .logo-badge { display: none; }
  .footer-content { flex-direction: column; }
  .footer-update { text-align: left; }
}

/* === Smooth transitions === */
.fade-enter { opacity: 0; transform: translateY(8px); }
.fade-enter-active { opacity: 1; transform: translateY(0); transition: all 0.3s; }
