:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --positive: #dc2626;
  --negative: #16a34a;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: radial-gradient(circle at top right, rgba(15, 118, 110, 0.08), transparent 30rem), var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}
button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(226, 232, 240, 0.9);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
}
.topbar-inner, .container { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.topbar-inner { min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { display: flex; align-items: center; gap: 11px; min-width: max-content; }
.brand-mark { display: grid; place-items: center; }
.brand-text h1 { margin: 0; font-size: 19px; letter-spacing: -0.02em; }
.brand-text p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.search-wrap { position: relative; display: flex; gap: 8px; width: min(520px, 52vw); }
.search-wrap input {
  width: 100%; min-width: 0; padding: 11px 13px; color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; outline: none; background: var(--surface); transition: border-color .2s, box-shadow .2s;
}
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12); }
.search-hint {
  position: absolute; left: 0; top: calc(100% + 6px); width: calc(100% - 76px); padding: 8px 10px;
  color: #991b1b; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; font-size: 12px; box-shadow: var(--shadow);
}
.btn { padding: 9px 14px; border: 1px solid transparent; border-radius: 10px; font-weight: 650; }
.btn-primary { color: white; background: var(--accent); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { color: var(--muted); background: transparent; border-color: var(--border); }

.container { padding: 24px 0 40px; }
.status-row { display: flex; align-items: center; gap: 10px; min-height: 36px; margin-bottom: 14px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; border-radius: 999px;
  color: #166534; background: #dcfce7; font-size: 12px; font-weight: 700;
}
.status-pill[data-state="loading"], .status-pill[data-state="warning"] { color: #92400e; background: #fef3c7; }
.status-pill[data-state="error"] { color: #991b1b; background: #fee2e2; }
.quote-time { color: var(--muted); font-size: 12px; }
.agent-status { color: #1d4ed8; background: #dbeafe; }
.agent-status[data-state="error"] { color: #991b1b; background: #fee2e2; }
.agent-status[data-state="warning"] { color: #92400e; background: #fef3c7; }
.spacer { flex: 1; }
.toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { position: relative; width: 38px; height: 22px; border-radius: 999px; background: #cbd5e1; transition: background .2s; }
.toggle-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: white; box-shadow: 0 1px 3px rgba(15, 23, 42, .18); transition: transform .2s;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }
.error-banner { margin-bottom: 14px; padding: 12px 14px; color: #991b1b; background: #fef2f2; border: 1px solid #fecaca; border-radius: 12px; font-size: 13px; }
.error-banner button { margin-left: 8px; color: inherit; border: 0; background: transparent; font-weight: 700; text-decoration: underline; }

.watchlist { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.quote-card, .skeleton-card { min-height: 190px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.quote-card {
  padding: 18px; box-shadow: 0 1px 2px rgba(15, 23, 42, .02);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; outline: none;
}
.quote-card:hover, .quote-card:focus-visible { transform: translateY(-2px); border-color: #cbd5e1; box-shadow: var(--shadow); }
.quote-card:focus-visible { box-shadow: 0 0 0 3px rgba(15, 118, 110, .15), var(--shadow); }
.quote-card-head { display: flex; justify-content: space-between; gap: 12px; }
.quote-card h3 { margin: 0; font-size: 16px; }
.quote-card-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.market-tag { height: fit-content; padding: 3px 7px; color: var(--accent-strong); background: #ccfbf1; border-radius: 999px; font-size: 10px; font-weight: 800; }
.quote-price { margin-top: 18px; font-size: 28px; font-weight: 750; letter-spacing: -0.03em; }
.quote-change { display: flex; gap: 10px; margin-top: 2px; font-size: 13px; font-weight: 650; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.green-up.positive { color: var(--negative); }
.green-up.negative { color: var(--positive); }
.flat { color: var(--muted); }
.quote-mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0 0; padding-top: 13px; border-top: 1px solid var(--border); }
.quote-mini div { min-width: 0; }
.quote-mini dt { color: var(--muted); font-size: 10px; }
.quote-mini dd { margin: 2px 0 0; overflow: hidden; font-size: 12px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.skeleton-grid { display: contents; }
.skeleton-card { position: relative; overflow: hidden; background: #f8fafc; }
.skeleton-card::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.85), transparent); animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.empty-state { grid-column: 1 / -1; margin: 0; padding: 32px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface); }

.detail-panel { margin-top: 18px; padding: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); scroll-margin-top: 94px; }
.detail-head { display: grid; grid-template-columns: 1fr auto auto; align-items: start; gap: 18px; }
.detail-head h2 { margin: 0; font-size: 21px; }
.detail-code { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.detail-price { text-align: right; }
.detail-last { display: block; font-size: 26px; font-weight: 760; line-height: 1.1; }
.detail-change { display: block; margin-top: 4px; font-size: 12px; font-weight: 650; }
.detail-meta { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; margin-top: 20px; padding: 12px; border-radius: 12px; background: var(--surface-2); }
.meta-item { min-width: 0; }
.meta-label { display: block; color: var(--muted); font-size: 10px; }
.meta-item > span:last-child { display: block; margin-top: 2px; overflow: hidden; font-size: 12px; font-weight: 650; text-overflow: ellipsis; }
.kline-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 22px; }
.kline-title { font-size: 14px; font-weight: 700; }
.kline-range { display: flex; gap: 4px; }
.range-btn { padding: 5px 9px; color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: 8px; font-size: 11px; }
.range-btn:hover, .range-btn.active { color: var(--accent-strong); background: #f0fdfa; border-color: #99f6e4; }
.kline-chart { height: 330px; margin-top: 8px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #fff; }
.kline-canvas { display: block; }
.chart-empty { height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.chart-source { margin: 8px 2px 0; color: var(--muted); font-size: 10px; }
.footer { margin-top: 28px; padding: 18px 0 6px; color: var(--muted); border-top: 1px solid var(--border); font-size: 11px; }
.footer p { margin: 4px 0; }
.footer-meta { opacity: .8; }

@media (max-width: 900px) {
  .watchlist { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-meta { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .topbar-inner { min-height: 0; padding: 12px 0; align-items: stretch; flex-direction: column; gap: 10px; }
  .brand-text p { display: none; }
  .search-wrap { width: 100%; }
  .container { padding-top: 16px; }
  .watchlist { grid-template-columns: 1fr; }
  .detail-head { grid-template-columns: 1fr auto; }
  .detail-price { grid-row: 2; grid-column: 1 / -1; text-align: left; }
  .detail-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kline-chart { height: 300px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
