/* AI Trading Agent V1.2 — stock.golive.wiki
   모바일 우선. 다크 테마. 모의/실거래를 색과 배지로 명확히 구분한다. */

:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --bg-elev: #121821;
  --bg-elev2: #1a2230;
  --line: #232d3d;
  --line-soft: #1b2430;
  --fg: #e8eef7;
  --fg-dim: #93a1b5;
  --fg-mute: #64748b;

  --up: #16c784;
  --down: #ea3943;
  --accent: #3b82f6;
  --accent-dim: #1e3a8a;
  --paper: #f59e0b;
  --paper-bg: rgba(245, 158, 11, .12);
  --live: #ef4444;
  --warn: #f59e0b;
  --danger: #ef4444;

  --r: 14px;
  --r-sm: 10px;
  --gap: 12px;
  --pad: 16px;
  --topbar-h: 52px;
  --tabbar-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Pretendard", "Noto Sans KR", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ── 부팅 ─────────────────────────────────────────── */
.boot {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: var(--bg); z-index: 100;
}
.boot-logo { font-size: 44px; animation: pulse 1.6s ease-in-out infinite; }
.boot-text { color: var(--fg-mute); font-size: 13px; }
@keyframes pulse { 0%,100% { opacity: .45; transform: scale(.96); } 50% { opacity: 1; transform: scale(1); } }

/* ── 앱 레이아웃 ───────────────────────────────────── */
#app {
  display: flex; flex-direction: column;
  height: 100dvh; max-width: 720px; margin: 0 auto;
  background: var(--bg);
}

.topbar {
  flex: 0 0 auto; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--pad);
  border-bottom: 1px solid var(--line-soft);
  background: rgba(11,15,20,.92);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: baseline; gap: 7px; }
.brand { font-size: 15px; font-weight: 700; letter-spacing: -.02em; }
.ver { font-size: 10px; color: var(--fg-mute); font-weight: 600;
       background: var(--bg-elev2); padding: 2px 6px; border-radius: 5px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.badge {
  font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 20px;
  letter-spacing: .01em; white-space: nowrap;
}
.badge-paper { background: var(--paper-bg); color: var(--paper); border: 1px solid rgba(245,158,11,.35); }
.badge-live  { background: rgba(239,68,68,.14); color: var(--live); border: 1px solid rgba(239,68,68,.4); }
.badge-off   { background: var(--bg-elev2); color: var(--fg-mute); border: 1px solid var(--line); }

.kill-btn {
  font-size: 12px; font-weight: 700; padding: 7px 12px; border-radius: 9px;
  background: rgba(239,68,68,.14); color: #ff7b72;
  border: 1px solid rgba(239,68,68,.35);
  transition: background .15s;
}
.kill-btn:active { background: rgba(239,68,68,.28); }
.kill-btn[aria-pressed="true"] { background: var(--danger); color: #fff; }

.kill-banner {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 11px var(--pad); font-size: 13px;
  background: rgba(239,68,68,.14); color: #ff9b95;
  border-bottom: 1px solid rgba(239,68,68,.3);
}
.kill-banner strong { color: #ff7b72; }
.kill-banner button {
  margin-left: auto; font-size: 12px; font-weight: 700;
  padding: 5px 11px; border-radius: 8px;
  background: rgba(239,68,68,.25); color: #ffb4af;
  border: 1px solid rgba(239,68,68,.4);
}

.view {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: var(--pad); padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 20px);
}

.tabbar {
  flex: 0 0 auto; height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--line-soft);
  background: rgba(11,15,20,.96);
  backdrop-filter: blur(12px);
  position: sticky; bottom: 0; z-index: 20;
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--fg-mute); font-size: 10px; font-weight: 600;
  transition: color .15s; padding: 6px 0;
}
.tab-ico { font-size: 17px; line-height: 1; }
.tab[aria-selected="true"] { color: var(--accent); }

/* ── 공통 카드 ─────────────────────────────────────── */
.card {
  background: var(--bg-elev); border: 1px solid var(--line-soft);
  border-radius: var(--r); padding: 14px; margin-bottom: var(--gap);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.card-title { font-size: 13px; font-weight: 700; color: var(--fg-dim);
              text-transform: uppercase; letter-spacing: .04em; }
.card-note { font-size: 11px; color: var(--fg-mute); }

.section-title { font-size: 17px; font-weight: 700; margin: 4px 0 14px; letter-spacing: -.02em; }

/* ── 지표 그리드 ───────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat {
  background: var(--bg-elev); border: 1px solid var(--line-soft);
  border-radius: var(--r-sm); padding: 12px 13px;
}
.stat-label { font-size: 11px; color: var(--fg-mute); margin-bottom: 5px; font-weight: 600; }
.stat-value { font-size: 19px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 11px; color: var(--fg-mute); margin-top: 3px; }

.up { color: var(--up); }
.down { color: var(--down); }
.dim { color: var(--fg-dim); }
.mute { color: var(--fg-mute); }
.num { font-variant-numeric: tabular-nums; }

/* ── 종목 행 ───────────────────────────────────────── */
.sym-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px; border-bottom: 1px solid var(--line-soft);
}
.sym-row:last-child { border-bottom: none; }
.sym-main { flex: 1 1 auto; min-width: 0; }
.sym-ticker { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.sym-name { font-size: 11px; color: var(--fg-mute); overflow: hidden;
            text-overflow: ellipsis; white-space: nowrap; }
.sym-price { text-align: right; font-variant-numeric: tabular-nums; }
.sym-px { font-size: 15px; font-weight: 600; }
.sym-chg { font-size: 11px; font-weight: 600; }

.spark { width: 62px; height: 26px; flex: 0 0 auto; }

/* ── 버튼 ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border-radius: var(--r-sm); font-size: 14px; font-weight: 600;
  background: var(--bg-elev2); color: var(--fg); border: 1px solid var(--line);
  transition: opacity .15s, background .15s;
}
.btn:active { opacity: .75; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-buy { background: var(--up); border-color: var(--up); color: #04160e; }
.btn-sell { background: var(--down); border-color: var(--down); color: #fff; }
.btn-ghost { background: transparent; }
.btn-block { display: flex; width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 12.5px; border-radius: 8px; }
.btn-row { display: flex; gap: 8px; }

/* ── 폼 ───────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field-label { display: block; font-size: 12px; font-weight: 600;
               color: var(--fg-dim); margin-bottom: 7px; }
.input {
  width: 100%; padding: 12px 14px; border-radius: var(--r-sm);
  background: var(--bg-elev2); border: 1px solid var(--line); color: var(--fg);
  font-size: 15px;
}
.input:focus { outline: none; border-color: var(--accent); }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg-btn {
  padding: 12px; border-radius: var(--r-sm); font-size: 14px; font-weight: 700;
  background: var(--bg-elev2); border: 1px solid var(--line); color: var(--fg-dim);
}
.seg-btn[aria-pressed="true"][data-side="buy"] { background: rgba(22,199,132,.16);
  border-color: var(--up); color: var(--up); }
.seg-btn[aria-pressed="true"][data-side="sell"] { background: rgba(234,57,67,.16);
  border-color: var(--down); color: var(--down); }

/* ── 안전 검사 목록 ────────────────────────────────── */
.checks { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; }
.check-ico { flex: 0 0 auto; font-weight: 700; }
.check-ok .check-ico { color: var(--up); }
.check-bad .check-ico { color: var(--down); }
.check-txt { color: var(--fg-dim); }
.check-bad .check-txt { color: #ff9b95; }

/* ── 주문 목록 ─────────────────────────────────────── */
.order-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 4px; border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.order-row:last-child { border-bottom: none; }
.side-tag {
  font-size: 10px; font-weight: 800; padding: 3px 7px; border-radius: 5px;
  letter-spacing: .03em;
}
.side-buy { background: rgba(22,199,132,.16); color: var(--up); }
.side-sell { background: rgba(234,57,67,.16); color: var(--down); }
.status-tag { font-size: 10px; font-weight: 700; padding: 3px 7px; border-radius: 5px;
              background: var(--bg-elev2); color: var(--fg-mute); }
.status-filled { background: rgba(22,199,132,.14); color: var(--up); }
.status-rejected { background: rgba(234,57,67,.14); color: var(--down); }

/* ── 빈 상태 ───────────────────────────────────────── */
.empty { text-align: center; padding: 34px 16px; color: var(--fg-mute); }
.empty-ico { font-size: 30px; opacity: .5; margin-bottom: 10px; }
.empty-txt { font-size: 13px; line-height: 1.6; }

/* ── 채팅 ─────────────────────────────────────────── */
.chat-wrap { display: flex; flex-direction: column; height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - var(--safe-b) - 32px); }
.chat-log { flex: 1 1 auto; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 10px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 16px; font-size: 14.5px;
       line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.msg-user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.msg-bot { align-self: flex-start; background: var(--bg-elev2); border-bottom-left-radius: 5px; }
.msg-sys {
  align-self: stretch; background: transparent; color: var(--fg-mute);
  font-size: 12px; text-align: center; padding: 4px 8px;
}
/* 오류는 좌측 정렬 카드로 — 중앙 정렬된 작은 글씨는 읽기 어렵다. */
.msg-error {
  align-self: stretch; background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.3); color: #ffb4af;
  border-radius: var(--r-sm); font-size: 13px; text-align: left;
  padding: 11px 13px; line-height: 1.5;
}
.msg-error .err-title { font-weight: 700; display: block; margin-bottom: 3px; color: #ff9b95; }
.chat-input-row {
  flex: 0 0 auto; display: flex; gap: 8px; padding-top: 10px;
  border-top: 1px solid var(--line-soft);
}
/* 입력창이 남는 폭을 차지하고, 전송 버튼은 글자가 쪼개지지 않게 고정 폭 */
.chat-input-row .input { flex: 1 1 auto; min-width: 0; }
.chat-input-row .btn {
  flex: 0 0 auto; white-space: nowrap; padding-left: 18px; padding-right: 18px;
}

/* ── 토스트 ───────────────────────────────────────── */
.toast {
  /* 하단 탭바 위에 띄운다. 채팅 입력창은 그 위에 있으므로
     토스트가 입력창을 가리지 않도록 충분히 아래에 배치한다. */
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
  transform: translateX(-50%);
  transition: bottom .18s ease;
  max-width: min(92vw, 480px);
  padding: 11px 18px; border-radius: 11px; font-size: 13px; font-weight: 500;
  background: var(--bg-elev2); border: 1px solid var(--line); color: var(--fg);
  box-shadow: 0 8px 28px rgba(0,0,0,.5); z-index: 60;
  animation: toast-in .2s ease-out;
}
.toast-err { background: rgba(239,68,68,.16); border-color: rgba(239,68,68,.4); color: #ffb4af; }
.toast-ok { background: rgba(22,199,132,.14); border-color: rgba(22,199,132,.35); color: #6ee7b7; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
/* 채팅 화면은 하단에 입력창이 있어 하단 토스트가 입력창을 가린다.
   이 화면에서만 토스트를 상단(헤더 아래)으로 보낸다. */
body.route-chat .toast {
  bottom: auto; top: calc(var(--topbar-h) + 56px);
  animation: toast-in-top .2s ease-out;
}
@keyframes toast-in-top { from { opacity: 0; transform: translate(-50%, -8px); } }

/* ── 시트 (주문 확인) ──────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 80; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.65); animation: fade-in .18s; }
.sheet-panel {
  position: relative; width: 100%; max-width: 720px;
  background: var(--bg-elev); border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  padding: 20px var(--pad) calc(20px + var(--safe-b));
  max-height: 88dvh; overflow-y: auto;
  animation: sheet-up .24s cubic-bezier(.2,.9,.3,1);
}
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-up { from { transform: translateY(100%); } }

.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--line);
              margin: 0 auto 16px; }
.sheet-title { font-size: 17px; font-weight: 700; margin: 0 0 4px; }
.sheet-sub { font-size: 12.5px; color: var(--fg-mute); margin: 0 0 16px; }

.paper-notice {
  display: flex; gap: 9px; align-items: flex-start;
  background: var(--paper-bg); border: 1px solid rgba(245,158,11,.3);
  border-radius: var(--r-sm); padding: 11px 13px; font-size: 12.5px;
  color: #fcd34d; margin-bottom: 16px; line-height: 1.5;
}

.kv { display: flex; justify-content: space-between; padding: 9px 0;
      border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.kv:last-of-type { border-bottom: none; }
.kv-k { color: var(--fg-mute); }
.kv-v { font-weight: 600; font-variant-numeric: tabular-nums; }

.disclaimer { font-size: 11px; color: var(--fg-mute); line-height: 1.55;
              margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line-soft); }

/* ── 전략 카드 ─────────────────────────────────────── */
.strat-card { background: var(--bg-elev); border: 1px solid var(--line-soft);
              border-radius: var(--r); padding: 14px; margin-bottom: 10px; }
.strat-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.strat-name { font-size: 14px; font-weight: 700; }
.strat-meta { display: flex; gap: 14px; font-size: 11.5px; color: var(--fg-mute); }

.progress { height: 3px; background: var(--line-soft); border-radius: 2px; overflow: hidden; margin-top: 12px; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 2px; transition: width .3s; }

@media (min-width: 560px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
}
