/* ── Design Tokens ──────────────────────────────────────────── */
:root {
  --bg:           #F0F4F8;
  --surface:      #FFFFFF;
  --surface-alt:  #F8FAFC;
  --border:       #E2E8F0;
  --border-focus: #3B82F6;
  --text:         #0F172A;
  --text-muted:   #64748B;
  --text-light:   #94A3B8;
  --primary:      #2563EB;
  --primary-light:#EFF6FF;
  --primary-dark: #1D4ED8;
  --green:        #059669;
  --green-bg:     #ECFDF5;
  --red:          #DC2626;
  --red-bg:       #FEF2F2;
  --gold:         #D97706;
  --gold-bg:      #FFFBEB;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow-sm:    0 1px 2px rgba(15,23,42,0.06);
  --shadow:       0 1px 3px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.04);
  --shadow-md:    0 4px 12px rgba(15,23,42,0.08), 0 2px 4px rgba(15,23,42,0.04);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
               "Noto Sans TC", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Navigation ──────────────────────────────────────────────── */
.nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  height: 58px;
  box-shadow: var(--shadow-sm);
}

.nav-brand {
  font-size: 18px;
  font-weight: 800;
  color: var(--primary);
  text-decoration: none;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 8px;
}
.nav-brand::before {
  content: "📈";
  font-size: 20px;
}

.nav-links {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  position: relative;
}
.nav-link:hover {
  background: var(--primary-light);
  color: var(--primary);
}
.nav-link.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

/* ── Container ───────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px;
}

/* ── Page Header ─────────────────────────────────────────────── */
.page-header {
  margin-bottom: 24px;
}
.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}
.page-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Search Bar ──────────────────────────────────────────────── */
.search-bar {
  position: relative;
  margin-bottom: 28px;
}
.search-bar::before {
  content: "🔍";
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 15px;
  pointer-events: none;
  z-index: 1;
}
.search-bar input {
  width: 100%;
  padding: 13px 16px 13px 42px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow-sm);
}
.search-bar input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.search-bar input::placeholder { color: var(--text-light); }

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  max-height: 340px;
  overflow-y: auto;
  overflow-x: hidden;
}
.search-dropdown::-webkit-scrollbar { width: 4px; }
.search-dropdown::-webkit-scrollbar-track { background: transparent; }
.search-dropdown::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid var(--border);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--primary-light); }

.search-item-symbol {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
  min-width: 80px;
}
.search-item-name {
  color: var(--text);
  font-size: 14px;
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.search-item-market {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--primary-light);
  color: var(--primary);
  letter-spacing: 0.03em;
}

/* ── Section Title ───────────────────────────────────────────── */
.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 14px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::before {
  content: "";
  display: block;
  width: 3px;
  height: 14px;
  background: var(--primary);
  border-radius: 2px;
  flex-shrink: 0;
}

/* ── Data Table ──────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.data-table th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr {
  transition: background 0.12s;
}
.data-table tbody tr:hover td {
  background: #F8FAFF;
}

.sym-link {
  font-family: "SF Mono", "Fira Code", monospace;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  font-size: 13px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  transition: background 0.15s;
  display: inline-block;
}
.sym-link:hover {
  background: #DBEAFE;
  text-decoration: none;
}

.cell-name { color: var(--text-muted); font-size: 13px; }
.cell-price {
  font-family: "SF Mono", monospace;
  font-weight: 700;
  font-size: 14px;
}
.cell-change {
  font-family: "SF Mono", monospace;
  font-size: 13px;
  font-weight: 600;
}

.up   { color: var(--green); }
.down { color: var(--red); }

.up-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--green-bg);
  color: var(--green);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  font-family: "SF Mono", monospace;
}
.down-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--red-bg);
  color: var(--red);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  font-family: "SF Mono", monospace;
}


/* ── States ──────────────────────────────────────────────────── */
.loading {
  text-align: center;
  color: var(--text-muted);
  padding: 56px 20px;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.loading::before {
  content: "";
  display: block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 56px 20px;
  font-size: 15px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-state::before {
  content: "📋";
  display: block;
  font-size: 36px;
  margin-bottom: 12px;
}

.hidden { display: none !important; }

/* ── Toast ───────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--text);
  color: #fff;
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 999;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  max-width: 320px;
}
#toast.error { background: var(--red); }
#toast.hidden { opacity: 0; transform: translateY(8px); }

/* ── News ────────────────────────────────────────────────────── */
.news-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.news-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  transition: box-shadow 0.15s, transform 0.15s;
  box-shadow: var(--shadow-sm);
}
.news-item:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.news-item-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.news-source {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 9px;
  border-radius: 20px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-shrink: 0;
}
.news-date {
  font-size: 12px;
  color: var(--text-light);
  margin-left: auto;
}
.news-title {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  line-height: 1.45;
  margin-bottom: 6px;
  transition: color 0.15s;
}
.news-title:hover { color: var(--primary); }
.news-summary {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
}

/* ── Watchlist Market Sections ──────────────────────────────── */
#tw-section + #us-section { margin-top: 32px; }

.wl-market-title { margin-bottom: 14px; }

/* ── Watchlist Card Grid ─────────────────────────────────────── */
.wl-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
@media (max-width: 1024px) { .wl-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 720px)  { .wl-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 440px)  { .wl-grid { grid-template-columns: 1fr; } }

.wl-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: box-shadow 0.15s, transform 0.15s;
}
.wl-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.wl-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.wl-symbol {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.wl-symbol:hover { background: #DBEAFE; }

.wl-name {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
}

.wl-price {
  font-family: "SF Mono", monospace;
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.wl-change { margin-top: 2px; margin-bottom: 10px; }

.neutral-badge {
  display: inline-block;
  background: var(--surface-alt);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  font-family: "SF Mono", monospace;
}

.wl-spark {
  flex: 1;
  display: flex;
  align-items: flex-end;
  min-height: 48px;
}
.wl-spark svg { width: 100%; height: 48px; display: block; }
.spark-empty {
  width: 100%;
  height: 48px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
}

.btn-remove {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.btn-remove:hover {
  color: var(--red);
  background: var(--red-bg);
}
