/* J.A.R.V.I.S. Command Center — deliberate single dark look */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222221;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;      /* JARVIS blue */
  --accent-soft: rgba(57, 135, 229, 0.15);
  --up: #e66767;          /* 상승 (한국 관례: 빨강) */
  --down: #3987e5;        /* 하락 (파랑) */
  --good: #0ca30c;
  --warn: #fab219;
  --critical: #d03b3b;
  --ma20: #c98500;
  --ma50: #9085e9;
  --rsi: #199e70;
  --radius: 12px;
  font-size: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── 헤더 ─────────────────────────────── */
header {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  background: linear-gradient(180deg, #141414, #0f0f0f);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; }
.reactor {
  width: 18px; height: 18px; border-radius: 50%;
  background: radial-gradient(circle, #bfe0ff 0%, var(--accent) 45%, rgba(57,135,229,.15) 75%);
  box-shadow: 0 0 12px 2px rgba(57, 135, 229, 0.55);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { box-shadow: 0 0 10px 2px rgba(57,135,229,.45);} 50% { box-shadow: 0 0 20px 5px rgba(57,135,229,.8);} }
.brand h1 { font-size: 17px; letter-spacing: 5px; font-weight: 700; }
.brand h1 span { color: var(--accent); }
.chips { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chip {
  padding: 3px 10px; border-radius: 20px; font-size: 11.5px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 6px;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.chip.on .dot { background: var(--good); box-shadow: 0 0 6px var(--good); }
.chip.paper .dot { background: var(--warn); }
.chip.live .dot { background: var(--critical); box-shadow: 0 0 6px var(--critical); }
.spacer { flex: 1; }
.total-box { text-align: right; }
.total-box .label { font-size: 10.5px; color: var(--muted); letter-spacing: 1px; }
.total-box .value { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; transition: color 0.4s; }
.total-box .delta { font-size: 12px; font-variant-numeric: tabular-nums; }
.total-sep { width: 1px; height: 30px; background: var(--border); margin: 0 4px; }
.pos { color: var(--up); } .neg { color: var(--down); } .flat { color: var(--ink-2); }

/* 토글 스위치 */
.switch { position: relative; width: 36px; height: 20px; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; border-radius: 20px;
  background: var(--baseline); transition: 0.25s; border: 1px solid var(--border);
}
.slider::before {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  left: 2px; top: 2px; background: var(--ink-2); transition: 0.25s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(16px); background: #fff; }

/* ── 메인 그리드 ───────────────────────── */
main {
  flex: 1; display: grid;
  grid-template-columns: 260px 1fr 340px;
  gap: 10px; padding: 10px; min-height: 0;
}
#left-col { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
#watchlist-panel { flex: 1; min-height: 0; }
#activity-panel { height: 215px; flex-shrink: 0; }

/* 라이브 활동 피드 */
.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--critical);
  display: inline-block; animation: live-pulse 1.6s ease-in-out infinite;
}
@keyframes live-pulse { 0%,100% { opacity: 1; box-shadow: 0 0 0 0 rgba(208,59,59,.5);} 50% { opacity: .55; box-shadow: 0 0 0 5px rgba(208,59,59,0);} }
#activity-feed { flex: 1; overflow-y: auto; padding: 6px 10px; }
.act-item {
  display: flex; gap: 7px; padding: 4px 0; font-size: 11px; line-height: 1.5;
  border-bottom: 1px solid rgba(255,255,255,0.04); color: var(--ink-2);
  animation: act-in 0.3s ease;
}
@keyframes act-in { from { opacity: 0; transform: translateY(-4px);} to { opacity: 1; transform: none;} }
.act-item .a-ts { color: var(--muted); flex-shrink: 0; font-variant-numeric: tabular-nums; font-size: 10px; padding-top: 1px; }
.act-item.k-buy { color: var(--up); }
.act-item.k-sell { color: var(--ink); }
.act-item.k-alert { color: var(--warn); }
.act-item.k-scan { color: var(--muted); }
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column; min-height: 0;
}
.panel-title {
  padding: 9px 13px; font-size: 11px; letter-spacing: 2px; color: var(--muted);
  border-bottom: 1px solid var(--border); text-transform: uppercase;
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.panel-title .grow { flex: 1; }

/* 워치리스트 */
#watchlist { overflow-y: auto; flex: 1; }
.w-item {
  padding: 9px 13px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,0.04);
  transition: background 0.15s;
}
.w-item:hover { background: var(--surface-2); }
.w-item.active { background: var(--accent-soft); border-left: 2px solid var(--accent); }
.w-row1 { display: flex; justify-content: space-between; align-items: baseline; }
.w-sym { font-weight: 600; font-size: 12.5px; }
.w-price { font-variant-numeric: tabular-nums; font-size: 12.5px; }
.w-row2 { display: flex; justify-content: space-between; align-items: center; margin-top: 3px; }
.w-chg { font-size: 11px; font-variant-numeric: tabular-nums; }
.w-livechg { font-size: 10px; margin-left: 4px; font-variant-numeric: tabular-nums; }
.score-pill {
  font-size: 10px; padding: 1px 7px; border-radius: 10px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.score-pill.buy { background: rgba(230,103,103,.15); color: var(--up); }
.score-pill.sell { background: rgba(57,135,229,.18); color: var(--down); }
.score-pill.hold { background: rgba(137,135,129,.15); color: var(--muted); }

/* 중앙: 차트 */
#center { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
/* 차트에 바닥값을 준다. 예전엔 min-height:0 이라 아래 '신호 분석' 패널이
   내용만큼 커지면서 차트를 0px까지 눌러버렸고, body가 overflow:hidden이라
   차트 헤더(종목명·가격·기간버튼)가 위아래로 잘려 보였다. */
#chart-panel { flex: 1 1 0; min-height: clamp(180px, 30vh, 260px); }
#chart-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; flex-shrink: 0; }
#chart-symbol { font-size: 16px; font-weight: 700; }
#chart-price { font-size: 16px; font-variant-numeric: tabular-nums; }
#chart-chg { font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tf-group { display: flex; gap: 4px; margin-left: auto; }
.tf-btn, .ghost-btn {
  background: transparent; color: var(--ink-2); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 7px; cursor: pointer; font-size: 11.5px;
  font-family: inherit;
}
.tf-btn:hover, .ghost-btn:hover { background: var(--surface-2); color: var(--ink); }
.tf-btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
#chart-wrap { flex: 1; position: relative; min-height: 0; padding: 4px 0 0 0; }
#chart-canvas { width: 100%; height: 100%; display: block; cursor: crosshair; }
#chart-tooltip {
  position: absolute; pointer-events: none; display: none;
  background: rgba(13,13,13,0.94); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 11px; font-size: 11.5px; line-height: 1.65; z-index: 10;
  font-variant-numeric: tabular-nums; box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.chart-legend {
  position: absolute; top: 6px; left: 10px; display: flex; gap: 12px;
  font-size: 10.5px; color: var(--ink-2); z-index: 5;
}
.chart-legend .key { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend .swatch { width: 10px; height: 3px; border-radius: 2px; }

/* 신호 패널 */
/* 신호 패널은 '줄어들 수 있어야' 한다. 근거 목록과 기법 확신도 막대가 늘어나도
   차트를 밀어내는 대신 이 패널 안에서 스크롤되게 한다(화면이 짧을 때 특히 중요). */
#signal-panel { flex: 0 1 auto; min-height: 0; max-height: 46%; }
#signal-body { display: flex; gap: 16px; padding: 12px 16px; align-items: center;
  overflow-y: auto; min-height: 0; }
#gauge-box { flex-shrink: 0; text-align: center; }
#gauge-label { font-size: 13px; font-weight: 700; margin-top: -6px; }
#gauge-score { font-size: 10.5px; color: var(--muted); }
#signal-reasons { font-size: 12px; line-height: 1.7; color: var(--ink-2); min-width: 0; }
#strategy-badge {
  display: inline-flex; align-items: center; gap: 6px; margin-bottom: 6px;
  padding: 3px 12px; border-radius: 14px; font-size: 11.5px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent);
}
#strategy-badge .sb-state { font-weight: 400; color: var(--ink-2); font-size: 10.5px; }
#signal-reasons li { list-style: none; display: flex; gap: 7px; align-items: baseline; flex-wrap: wrap; }
/* 근거별 기여도 — 문장만으로는 '왜 이 점수인지' 알 수 없어 막대로 보여준다 */
#signal-reasons .r-txt { flex: 1 1 auto; min-width: 0; }
#signal-reasons .r-pts { flex: 0 0 auto; font-size: 10.5px; font-variant-numeric: tabular-nums; opacity: .9; }
#signal-reasons .r-bar { flex: 0 0 100%; height: 3px; background: rgba(255,255,255,.06);
  border-radius: 2px; overflow: hidden; margin: 1px 0 3px 37px; }
#signal-reasons .r-bar-fill { display: block; height: 100%; border-radius: 2px; opacity: .75; }
#signal-reasons .r-bar-fill.up { background: var(--up); }
#signal-reasons .r-bar-fill.down { background: var(--down); }
#signal-reasons .r-dir { font-size: 9px; flex-shrink: 0; width: 30px; text-align: center; border-radius: 4px; padding: 0 3px; }
.r-dir.buy { background: rgba(230,103,103,.15); color: var(--up); }
.r-dir.sell { background: rgba(57,135,229,.18); color: var(--down); }
.r-dir.neutral { background: rgba(137,135,129,.15); color: var(--muted); }
#trade-btns { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.trade-btn {
  padding: 8px 18px; border-radius: 9px; border: none; cursor: pointer;
  font-weight: 700; font-size: 13px; font-family: inherit; color: #fff;
}
.trade-btn.buy { background: var(--critical); }
.trade-btn.buy:hover { filter: brightness(1.15); }
.trade-btn.sell { background: #1c5cab; }
.trade-btn.sell:hover { filter: brightness(1.15); }

/* 채팅 */
#chat-panel { min-height: 0; }
#chat-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 9px 12px; border-radius: 12px; font-size: 12.8px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.jarvis { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.jarvis.thinking { color: var(--muted); font-style: italic; }
.msg.jarvis.streaming::after {
  content: "▍"; color: var(--accent); animation: cursor-blink 0.9s step-start infinite;
}
@keyframes cursor-blink { 50% { opacity: 0; } }
.msg .msg-tag { display: block; font-size: 9.5px; color: var(--accent); letter-spacing: 2px; margin-bottom: 3px; }
#chat-input-row { display: flex; gap: 7px; padding: 10px; border-top: 1px solid var(--border); flex-shrink: 0; align-items: center; }
#chat-text {
  flex: 1; background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px;
  font-size: 13px; font-family: inherit; outline: none;
}
#chat-text:focus { border-color: var(--accent); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--ink-2); cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.icon-btn:hover { color: var(--ink); border-color: var(--accent); }
.icon-btn.mic-on {
  background: var(--critical); color: #fff; border-color: var(--critical);
  animation: mic-pulse 1.4s ease-in-out infinite;
}
@keyframes mic-pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(208,59,59,.5);} 50% { box-shadow: 0 0 0 7px rgba(208,59,59,0);} }
.icon-btn.tts-on { color: var(--accent); border-color: var(--accent); }
#voice-status { font-size: 10.5px; color: var(--muted); padding: 0 12px 8px; min-height: 15px; }
.mic-meter {
  display: inline-block; width: 70px; height: 7px; vertical-align: middle;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px;
  overflow: hidden; margin-left: 6px;
}
.mic-meter span { display: block; height: 100%; width: 0; background: var(--good); transition: width 0.08s; border-radius: 4px; }

/* ── 하단 탭 ───────────────────────────── */
#bottom { flex-shrink: 0; padding: 0 10px 10px; }
/* 고정 240px이면 노트북처럼 세로가 짧은 화면에서 위쪽 차트가 설 자리를 잃는다.
   화면 높이에 비례시키되 너무 납작해지지 않게 하한을 둔다. */
#bottom .panel { height: clamp(170px, 27vh, 240px); }
#tab-bar { display: flex; gap: 2px; padding: 6px 8px 0; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: transparent; border: none; color: var(--muted); padding: 7px 14px;
  cursor: pointer; font-size: 12px; font-family: inherit; border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
#tab-content { flex: 1; overflow: auto; padding: 10px 14px; }

table.data { width: 100%; border-collapse: collapse; font-size: 12px; }
table.data th {
  text-align: left; color: var(--muted); font-weight: 500; padding: 5px 10px;
  border-bottom: 1px solid var(--grid); position: sticky; top: -10px; background: var(--surface);
  font-size: 11px;
}
table.data td { padding: 6px 10px; border-bottom: 1px solid rgba(255,255,255,0.04); font-variant-numeric: tabular-nums; }
table.data .num { text-align: right; }

.journal-item { padding: 6px 4px; border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 12px; display: flex; gap: 10px; }
.journal-item .j-ts { color: var(--muted); flex-shrink: 0; font-size: 11px; font-variant-numeric: tabular-nums; }
.journal-item .j-kind { color: var(--accent); flex-shrink: 0; font-size: 10.5px; width: 62px; }

.news-item { padding: 8px 4px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.news-item a { color: var(--ink); text-decoration: none; font-size: 12.8px; font-weight: 500; }
.news-item a:hover { color: var(--accent); }
.news-item .n-meta { font-size: 10.5px; color: var(--muted); margin-top: 2px; }

.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.stat-tile {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; min-width: 120px;
}
.stat-tile .s-label { font-size: 10.5px; color: var(--muted); letter-spacing: 0.5px; }
.stat-tile .s-value { font-size: 18px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }

.weight-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: 12px; }
.weight-row .w-name { width: 90px; color: var(--ink-2); }
.weight-bar-track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.weight-bar { height: 100%; background: var(--accent); border-radius: 4px; }
.weight-row .w-val { width: 44px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }

#equity-canvas, #bt-canvas { width: 100%; height: 150px; display: block; }
.empty-note { color: var(--muted); font-size: 12.5px; padding: 20px; text-align: center; }

/* 자비스의 현재 판단 (왜 안 사는지) */
.waiting-box {
  border: 1px solid var(--border); border-left: 3px solid var(--muted);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 12px;
  font-size: 12.5px; line-height: 1.7; background: var(--surface-2);
}
.waiting-box.buy { border-left-color: var(--up); }
.waiting-box.wait { border-left-color: var(--accent); }

/* 새 엔진 성적 배너 */
.epoch-box {
  background: linear-gradient(90deg, rgba(57,135,229,.12), transparent);
  border: 1px solid var(--accent); border-left-width: 3px;
  border-radius: 10px; padding: 9px 14px; margin-bottom: 10px;
  font-size: 12.5px; line-height: 1.7;
}

/* 자비스 방패 — 안전장치 상태 카드 */
.shield-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.shield-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--good); border-radius: 10px; padding: 10px 13px;
}
.shield-card .sh-head { font-size: 12.5px; font-weight: 600; margin-bottom: 4px; }
.shield-card .sh-desc { font-size: 11px; color: var(--muted); line-height: 1.5; }
.shield-card.sh-active { border-left-color: var(--warn); }
.shield-card.sh-active .sh-head { color: var(--warn); }
.shield-card.sh-hit { border-left-color: var(--critical); }
.shield-card.sh-hit .sh-head { color: var(--critical); }

/* 포지션 리스크 레인 — 손절선 ↔ 익절선 사이 현재 위치 */
.risk-lane {
  position: relative; height: 8px; min-width: 130px; border-radius: 4px;
  background: linear-gradient(90deg,
    rgba(57,135,229,.45) 0%, rgba(57,135,229,.15) 35%,
    rgba(137,135,129,.2) 50%,
    rgba(230,103,103,.15) 65%, rgba(230,103,103,.45) 100%);
  border: 1px solid var(--border);
}
.risk-lane .rl-mid {
  position: absolute; left: 40%; top: -2px; bottom: -2px; width: 1px;
  background: var(--muted); opacity: .5;
}
.risk-lane .rl-fill {
  position: absolute; top: -3px; width: 3px; height: 14px; border-radius: 2px;
  background: #fff; box-shadow: 0 0 5px rgba(255,255,255,.7);
  transform: translateX(-1.5px); transition: left .5s ease;
}

/* 로그인 오버레이 */
#login-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(8, 8, 8, 0.92); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 36px 40px; width: 320px; text-align: center;
  box-shadow: 0 12px 48px rgba(0,0,0,.6);
}
.login-reactor {
  width: 44px; height: 44px; border-radius: 50%; margin: 0 auto 16px;
  background: radial-gradient(circle, #bfe0ff 0%, var(--accent) 45%, rgba(57,135,229,.15) 75%);
  box-shadow: 0 0 22px 4px rgba(57,135,229,.6); animation: pulse 2.4s ease-in-out infinite;
}
.login-box h2 { font-size: 18px; letter-spacing: 4px; margin-bottom: 6px; }
.login-box p { font-size: 12px; color: var(--muted); margin-bottom: 18px; }
.login-box input {
  width: 100%; padding: 11px 14px; border-radius: 9px; font-size: 14px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink);
  outline: none; margin-bottom: 12px; font-family: inherit;
}
.login-box input:focus { border-color: var(--accent); }
.login-box button {
  width: 100%; padding: 11px; border-radius: 9px; border: none; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 700; font-family: inherit;
}
.login-box button:hover { filter: brightness(1.1); }
#login-err { font-size: 12px; color: var(--critical); margin-top: 10px; min-height: 16px; }

/* 급변 알림 토스트 */
#toast-box {
  position: fixed; top: 60px; right: 16px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; font-size: 12.5px; font-weight: 600;
  opacity: 0; transform: translateX(20px); transition: all 0.35s;
  box-shadow: 0 6px 20px rgba(0,0,0,.5); max-width: 300px;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-up { border-left: 3px solid var(--up); }
.toast-down { border-left: 3px solid var(--down); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--baseline); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1100px) {
  main { grid-template-columns: 200px 1fr; }
  #chat-col { display: none; }
}
