:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev2: #21262d;
  --border: #30363d;
  --text: #c9d1d9;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --up: #3fb950;
  --down: #f85149;
  --warn: #d29922;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f6f8fa;
  --bg-elev2: #eaeef2;
  --border: #d0d7de;
  --text: #1f2328;
  --text-dim: #656d76;
  --accent: #0969da;
  --up: #1a7f37;
  --down: #cf222e;
  --warn: #9a6700;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; }

header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--bg-elev);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 18px; font-weight: 600; }
.brand span { margin-left: 6px; }
.header-right button { background: none; border: none; color: var(--text); font-size: 18px; cursor: pointer; }

main {
  display: grid;
  grid-template-columns: 240px 1fr 320px;
  height: calc(100vh - 53px);
}
@media (max-width: 1000px) {
  main { grid-template-columns: 1fr; grid-template-rows: auto auto auto; }
  .sidebar, .chat-panel { max-height: 30vh; overflow-y: auto; }
}

/* Sidebar */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  overflow-y: auto;
}
.add-section { padding: 12px; border-bottom: 1px solid var(--border); }
.add-section form { display: flex; gap: 6px; }
.add-section select, .add-section input {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 6px 8px; border-radius: 6px; font-size: 13px;
}
.add-section select { width: 70px; }
.add-section input { flex: 1; min-width: 0; }
.add-section button {
  background: var(--accent); color: white; border: none; padding: 6px 10px;
  border-radius: 6px; cursor: pointer; font-size: 13px;
}
.hint { font-size: 11px; color: var(--text-dim); margin-top: 6px; }
.hint code { background: var(--bg); padding: 1px 4px; border-radius: 3px; }

.watchlist-section { padding: 12px; }
.watchlist-section h3 { margin: 0 0 8px 0; font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.watchlist-section h3 span { float: right; color: var(--text); font-weight: normal; }

#watchlist { list-style: none; padding: 0; margin: 0; }
#watchlist li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: 6px; cursor: pointer; margin-bottom: 4px;
}
#watchlist li:hover { background: var(--bg-elev2); }
#watchlist li.active { background: var(--bg-elev2); box-shadow: inset 3px 0 0 var(--accent); }
#watchlist .sym { font-weight: 600; }
#watchlist .market-tag { font-size: 10px; color: var(--text-dim); border: 1px solid var(--border); padding: 1px 4px; border-radius: 3px; margin-right: 6px; }
#watchlist .name { font-size: 11px; color: var(--text-dim); }
#watchlist .remove-btn { background: none; border: none; color: var(--text-dim); cursor: pointer; opacity: 0; transition: opacity 0.2s; padding: 0 4px; }
#watchlist li:hover .remove-btn { opacity: 1; }
#watchlist .remove-btn:hover { color: var(--down); }

/* Main */
.main-content { overflow-y: auto; padding: 24px; }
.empty { text-align: center; margin-top: 80px; color: var(--text-dim); }
.empty h2 { color: var(--text); }
.quick-add { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.quick-add button {
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  padding: 8px 14px; border-radius: 20px; cursor: pointer; font-size: 13px;
}
.quick-add button:hover { background: var(--bg-elev2); border-color: var(--accent); }

.hidden { display: none !important; }

.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.detail-header h1 { margin: 0; font-size: 22px; }
.meta { display: flex; gap: 12px; font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.state { padding: 1px 6px; border-radius: 3px; }
.state.REGULAR { background: var(--up); color: white; }
.state.CLOSED, .state.POSTPOST, .state.PREPRE { background: var(--text-dim); color: white; }
.state.PRE, .state.POST { background: var(--warn); color: white; }
.price-block { text-align: right; }
.price { font-size: 28px; font-weight: 700; }
.change { font-size: 14px; margin-top: 4px; }
.change.up { color: var(--up); }
.change.down { color: var(--down); }

.tab-bar { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 16px; gap: 4px; }
.tab { background: none; border: none; color: var(--text-dim); padding: 10px 16px; cursor: pointer; font-size: 13px; border-bottom: 2px solid transparent; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.indicators-row { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.indicator { background: var(--bg-elev); padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); min-width: 80px; }
.indicator-label { font-size: 11px; color: var(--text-dim); }
.indicator-value { font-size: 16px; font-weight: 600; margin-top: 2px; }

#kline-chart { width: 100%; height: 420px; background: var(--bg-elev); border-radius: 8px; border: 1px solid var(--border); }

.ai-controls { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.primary { background: linear-gradient(135deg, #58a6ff, #1f6feb); color: white; border: none; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600; }
.primary:disabled { opacity: 0.6; cursor: not-allowed; }
.primary:hover:not(:disabled) { transform: translateY(-1px); }

.ai-result { background: var(--bg-elev); border: 1px solid var(--border); padding: 20px; border-radius: 8px; min-height: 200px; }
.ai-sentiment { font-size: 24px; font-weight: 700; }
.ai-sentiment.up { color: var(--up); }
.ai-sentiment.down { color: var(--down); }
.ai-sentiment.neutral { color: var(--text-dim); }
.ai-sec { margin-top: 16px; }
.ai-sec h4 { margin: 0 0 6px 0; font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.ai-sec ul { margin: 0; padding-left: 18px; }
.ai-sec p { margin: 0; line-height: 1.6; }

.news-list { display: flex; flex-direction: column; gap: 10px; }
.news-item { background: var(--bg-elev); border: 1px solid var(--border); padding: 14px; border-radius: 8px; }
.news-item a { color: var(--text); text-decoration: none; font-weight: 500; }
.news-item a:hover { color: var(--accent); }
.news-meta { font-size: 11px; color: var(--text-dim); margin-top: 6px; }

.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item { background: var(--bg-elev); border: 1px solid var(--border); padding: 14px; border-radius: 8px; font-size: 13px; }
.history-item .h-ts { font-size: 11px; color: var(--text-dim); }
.history-item .h-summary { margin-top: 6px; line-height: 1.6; }

/* Chat panel */
.chat-panel { border-left: 1px solid var(--border); background: var(--bg-elev); display: flex; flex-direction: column; }
.chat-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.chat-header h3 { margin: 0; font-size: 14px; }
.chat-header button { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 14px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 10px 12px; border-radius: 8px; max-width: 90%; line-height: 1.5; font-size: 13px; }
.msg.user { align-self: flex-end; background: var(--accent); color: white; }
.msg.assistant { align-self: flex-start; background: var(--bg-elev2); }
.msg.system { align-self: center; background: transparent; color: var(--text-dim); font-size: 11px; text-align: center; }
.msg.loading { align-self: flex-start; background: var(--bg-elev2); color: var(--text-dim); font-style: italic; }

.chat-input { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 6px; }
.chat-input input { flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 8px 12px; border-radius: 6px; font-size: 13px; }
.chat-input button { background: var(--accent); color: white; border: none; padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; }

/* Recommend button */
.recommend-btn {
  width: 100%; margin-top: 8px; padding: 10px;
  background: linear-gradient(135deg, #a78bfa, #6366f1); color: white;
  border: none; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.recommend-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3); }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  animation: fadeIn 0.2s;
}
.modal-content {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px;
  width: 90%; max-width: 800px; max-height: 90vh; display: flex; flex-direction: column;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 24px; cursor: pointer; }
.modal-body { padding: 20px 24px; overflow-y: auto; }
.recommend-controls { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 12px; align-items: end; margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.form-row { display: flex; flex-direction: column; gap: 4px; }
.form-row label { font-size: 11px; color: var(--text-dim); }
.form-row select { background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 6px 8px; border-radius: 6px; font-size: 13px; }
@media (max-width: 700px) { .recommend-controls { grid-template-columns: 1fr 1fr; } .recommend-controls > button { grid-column: span 2; } }

.recommend-result { min-height: 100px; }
.rec-explain { background: var(--bg-elev2); padding: 12px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; color: var(--text-dim); }
.rec-pick {
  background: var(--bg-elev2); border: 1px solid var(--border);
  padding: 14px; border-radius: 8px; margin-bottom: 10px;
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
}
.rec-rank { font-size: 22px; font-weight: 700; color: var(--accent); min-width: 32px; text-align: center; }
.rec-info .rec-title { font-weight: 600; margin-bottom: 2px; }
.rec-info .rec-meta { font-size: 11px; color: var(--text-dim); }
.rec-info .rec-reason { margin-top: 6px; font-size: 13px; line-height: 1.5; }
.rec-info .rec-risk { margin-top: 4px; font-size: 12px; color: var(--warn); }
.rec-score { font-size: 22px; font-weight: 700; }
.rec-actions { display: flex; gap: 6px; margin-top: 8px; }
.rec-actions button { background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 11px; }
.rec-actions button:hover { background: var(--bg-elev); border-color: var(--accent); }
