/* 비트코인 위험 알리미
   - 국가 위기경보(관심·주의·경계·심각)의 색 체계를 빌려 와, 경보판 하나에만 강한 색을 쓴다.
   - 나머지 화면은 차분한 회색 톤으로 두어 경보판이 가장 먼저 눈에 들어오게 한다. */
:root {
  --bg: #edf0f3;
  --panel: #ffffff;
  --ink: #18212d;
  --muted: #5d6978;
  --line: #d9dfe6;
  --navy: #18212d;
  --accent: #18212d;      /* 버튼·선택 상태: 경보 색과 겹치지 않게 먹색 */
  --accent-ink: #ffffff;
  --up: #d23c3c;          /* 한국식: 상승 빨강 */
  --down: #2a6fdb;        /* 하락 파랑 */
  --user: #18212d;
  --bot: #f1f3f6;
  --field: #ffffff;
  --head: #f6f8fa;
  --soft-accent: #eef2f7;
  --grid: #e6eaef;
  --price: #2b4c7e;
  --ma: #9aa7b8;
  --radius: 10px;
  --banner-bg: #fff4e0; --banner-ink: #7a4a00; --banner-line: #f6d49a;

  /* 위험 단계 색 */
  --lv-safe: #2e8b57;
  --lv-watch: #2f6fde;
  --lv-caution: #e3a008;
  --lv-warning: #e2620a;
  --lv-severe: #c81e3a;

  --display: "Black Han Sans", "IBM Plex Sans KR", sans-serif;
  --body: "IBM Plex Sans KR", "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}
[data-theme="dark"] {
  --bg: #0f141b;
  --panel: #171e28;
  --ink: #e5eaf0;
  --muted: #93a0b1;
  --line: #283241;
  --navy: #0b1017;
  --accent: #e5eaf0;
  --accent-ink: #0f141b;
  --user: #2b4c7e;
  --bot: #1f2834;
  --field: #111821;
  --head: #1b2330;
  --soft-accent: #1f2a38;
  --grid: #232c39;
  --price: #8fb3ea;
  --ma: #5d6b80;
  --up: #ff6b6b;
  --down: #6aa4ff;
  --banner-bg: #2b2414; --banner-ink: #f6d49a; --banner-line: #5a4316;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.55;
}
:focus-visible { outline: 2px solid var(--lv-watch); outline-offset: 2px; }
.small { font-size: 12px; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- 상단 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; }
.siren {
  width: 14px; height: 14px; border-radius: 50%; background: var(--lv-severe);
  box-shadow: 0 0 0 4px rgba(200, 30, 58, 0.25);
}
h1 { margin: 0; white-space: nowrap; font-family: var(--display); font-weight: 400; font-size: 22px; letter-spacing: 0.5px; }
.sub { margin: 0; font-size: 13px; color: #aab5c4; }
.top-right { display: flex; align-items: center; gap: 8px; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pill-wait { background: #344255; color: #e2e8f0; }
.pill-ok { background: #1f6f47; color: #fff; }
.pill-bad { background: #a33; color: #fff; }
.theme-btn {
  border: 1px solid #3a475a; background: transparent; color: #e2e8f0; border-radius: 999px;
  padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.theme-btn:hover { background: #253247; }

.banner {
  margin: 12px 24px 0; padding: 10px 14px; border-radius: var(--radius);
  background: var(--banner-bg); color: var(--banner-ink); border: 1px solid var(--banner-line); font-size: 14px;
}

/* ---------- 경보판 ---------- */
.alarm {
  --lv: #6b7686; --lv-ink: #ffffff;
  background: var(--lv); color: var(--lv-ink);
  transition: background-color 0.6s ease;
  scroll-margin-top: 0;
}
.alarm[data-level="safe"] { --lv: var(--lv-safe); }
.alarm[data-level="watch"] { --lv: var(--lv-watch); }
.alarm[data-level="caution"] { --lv: var(--lv-caution); --lv-ink: #1f1600; }
.alarm[data-level="warning"] { --lv: var(--lv-warning); }
.alarm[data-level="severe"] { --lv: var(--lv-severe); }
.alarm-inner {
  display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 32px; align-items: center;
  max-width: 1280px; margin: 0 auto; padding: 32px 24px 36px;
}
.alarm-kicker { margin: 0; font-size: 15px; font-weight: 500; opacity: 0.85; }
.alarm-level {
  margin: 2px 0 6px; font-family: var(--display); font-weight: 400;
  font-size: clamp(72px, 13vw, 148px); line-height: 0.95; letter-spacing: 2px;
}
.alarm-desc { margin: 0; font-size: clamp(17px, 2vw, 21px); font-weight: 500; max-width: 34em; }
.alarm-meta { margin: 8px 0 0; font-size: 14px; opacity: 0.85; font-variant-numeric: tabular-nums; }
.alarm-btn {
  margin-top: 18px; border: 2px solid currentColor; background: transparent; color: inherit;
  border-radius: 999px; padding: 8px 18px; font: inherit; font-weight: 700; cursor: pointer;
}
.alarm-btn:hover { background: rgba(255, 255, 255, 0.16); }
.alarm[data-level="caution"] .alarm-btn:hover { background: rgba(0, 0, 0, 0.08); }

/* 경보 기둥: 아래가 안전, 위가 심각 */
.scale { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.scale li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 14px; border-radius: 6px; font-weight: 700; font-size: 15px;
  background: rgba(255, 255, 255, 0.14); color: inherit; opacity: 0.55;
}
.alarm[data-level="caution"] .scale li { background: rgba(0, 0, 0, 0.08); }
.scale li::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor; opacity: 0.35; }
.scale li.on {
  opacity: 1; background: #ffffff; color: var(--lv);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  animation: light-up 0.7s ease-out both;
}
.alarm[data-level="caution"] .scale li.on { color: #8a5d00; }
.scale li.on::after { opacity: 1; }
.alarm[data-level="severe"] .scale li.on::after { animation: pulse 1.4s ease-in-out infinite; }
@keyframes light-up { from { opacity: 0.55; transform: scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { opacity: 0.2; } }
@media (prefers-reduced-motion: reduce) {
  .alarm, .scale li.on, .scale li.on::after { animation: none; transition: none; }
}

/* ---------- 근거 · 성적표 · 뉴스 ---------- */
.risk-grid {
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(0, 1fr); gap: 16px;
  max-width: 1280px; margin: 0 auto; padding: 20px 24px 0;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
h2 { margin: 0 0 10px; font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
h3 { margin: 18px 0 8px; font-size: 14px; font-weight: 700; color: var(--muted); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }

.reasons { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.reasons li { position: relative; padding-left: 22px; overflow-wrap: anywhere; }
.reasons li.muted { padding-left: 0; }
.reasons.minus li:not(.muted)::before { content: "▼"; position: absolute; left: 0; color: var(--down); font-size: 12px; top: 3px; }
.reasons.plus li:not(.muted)::before { content: "▲"; position: absolute; left: 0; color: var(--up); font-size: 12px; top: 3px; }
#neutralReasons { margin: 14px 0 0; }

.score-panel > .muted { margin: -4px 0 6px; }
.score-row { display: flex; flex-direction: column; gap: 2px; padding: 12px 0; border-top: 1px solid var(--line); }
.score-row:first-of-type { border-top: 0; }
.score-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.score-big { font-size: 34px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.score-mid { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bars { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 4px; }
.bar-line { display: grid; grid-template-columns: 78px minmax(0, 1fr) 58px; gap: 8px; align-items: center; font-size: 13px; }
.bar-name { color: var(--muted); }
.bar-track { position: relative; height: 10px; background: var(--bot); border-radius: 5px; }
.bar-track::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--muted); opacity: 0.6; }
.bar-track i { position: absolute; top: 0; bottom: 0; border-radius: 5px; width: 0; }
.bar-track i.neg { background: var(--down); }
.bar-track i.pos { background: var(--up); }
.bar-line b { text-align: right; font-variant-numeric: tabular-nums; }

.news-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.news-list a { color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.news-list a:hover { text-decoration: underline; }
.news-list small { display: block; color: var(--muted); font-size: 12px; }
.alert-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.alert-list li:not(.muted) { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.alert-list small { color: var(--muted); }
.lv-tag { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 4px; color: #fff; background: var(--lv-safe); }
.lv-tag.step-1 { background: var(--lv-watch); }
.lv-tag.step-2 { background: var(--lv-caution); color: #1f1600; }
.lv-tag.step-3 { background: var(--lv-warning); }
.lv-tag.step-4 { background: var(--lv-severe); }

/* ---------- 데이터 요약 ---------- */
.summary {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 2fr); gap: 12px;
  max-width: 1280px; margin: 0 auto; padding: 16px 24px 0;
}
.stat { background: var(--panel); border-radius: var(--radius); padding: 12px 14px; border: 1px solid var(--line); min-width: 0; }
.stat .label { display: block; font-size: 12px; color: var(--muted); }
.stat .value { display: block; font-size: 17px; font-weight: 700; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.stat.wide .value { font-size: 15px; }

/* ---------- 그래프 ---------- */
.insight { margin: 16px max(24px, calc((100% - 1232px) / 2)) 0; }
.range { display: flex; gap: 6px; flex-wrap: wrap; }
.insight-body { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 16px; align-items: stretch; }
.chart-box { position: relative; min-width: 0; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.sw-price { background: var(--price); }
.sw-ma { background: var(--ma); }
#chart { width: 100%; height: auto; display: block; }
#chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
#chart .grid { stroke: var(--grid); stroke-width: 1; }
#chart .price { fill: none; stroke: var(--price); stroke-width: 2; }
#chart .area { fill: var(--price); opacity: 0.07; }
#chart .ma { fill: none; stroke: var(--ma); stroke-width: 1.5; stroke-dasharray: 4 3; }
#chart .cursor { stroke: var(--muted); stroke-width: 1; }
#chart .dot { fill: var(--price); stroke: var(--panel); stroke-width: 2; }
.chart-tip {
  position: absolute; top: 24px; pointer-events: none; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); white-space: nowrap;
}
.mini-stats { display: flex; flex-direction: column; gap: 10px; }
.mini { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; flex: 1; }
.mini .label { display: block; font-size: 12px; color: var(--muted); }
.mini .value { display: block; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mini small { color: var(--muted); font-size: 12px; }

/* ---------- 대화 · 채팅 · 데이터 ---------- */
.layout {
  display: grid; grid-template-columns: 240px minmax(0, 1fr) 400px; gap: 16px;
  max-width: 1280px; margin: 0 auto; padding: 16px 24px; align-items: start;
}

.btn {
  border: 0; border-radius: 8px; padding: 9px 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 700; white-space: nowrap;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-small { padding: 6px 10px; font-size: 13px; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); width: 100%; margin-top: 10px; }
.btn-line { background: transparent; color: var(--ink); border: 1px solid var(--line); text-decoration: none; display: inline-block; }
.btn-line:hover { border-color: var(--ink); filter: none; }
.export { display: flex; gap: 6px; }
.link-btn { background: none; border: 0; padding: 2px 4px; color: var(--muted); cursor: pointer; font: inherit; font-size: 13px; }
.link-btn:hover { color: var(--ink); text-decoration: underline; }
.link-btn.danger:hover { color: var(--up); }

.conv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 62vh; overflow-y: auto; }
.conv-item {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); cursor: pointer;
}
.conv-item:hover { background: var(--bot); }
.conv-item.active { border-color: var(--ink); background: var(--soft-accent); }
.conv-item .t { flex: 1; min-width: 0; }
.conv-item .t strong { display: block; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .t small { color: var(--muted); font-size: 12px; }

.chat { display: flex; flex-direction: column; height: calc(100vh - 160px); min-height: 480px; max-height: 760px; }
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px 10px; }
.msg { max-width: 84%; padding: 10px 13px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--bot); border-bottom-left-radius: 4px; }
.msg.error { align-self: flex-start; background: #fdecec; color: #8a1f1f; }
.msg.intro { color: var(--muted); white-space: normal; }
.tools-used { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; white-space: normal; }
.tools-used span {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
}
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--field); border-radius: 999px; padding: 5px 11px;
  font: inherit; font-size: 13px; cursor: pointer; color: var(--ink);
}
.chip:hover { border-color: var(--ink); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chat-form { display: flex; gap: 8px; }
input {
  font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--field); color: var(--ink); min-width: 0; width: 100%; color-scheme: light dark;
}
input:focus { outline: 2px solid var(--lv-watch); outline-offset: -1px; border-color: transparent; }

.add-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
.add-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.add-form .memo { grid-column: 1 / -1; }
.add-form .btn { grid-column: 1 / -1; }
.form-msg { min-height: 20px; margin: 6px 0; font-size: 13px; }
.form-msg.ok { color: #1f7a4d; }
.form-msg.err { color: #c33; }
.table-wrap { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
col.c-date { width: 96px; } col.c-value { width: 104px; } col.c-act { width: 78px; }
th, td { padding: 7px 6px; white-space: nowrap; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: var(--head); font-weight: 500; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.memo-cell { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
tr.editing input { padding: 5px 4px; font-size: 12px; }
tr.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--soft-accent); } to { background: transparent; } }

/* ---------- 철학 ---------- */
.creed { max-width: 1280px; margin: 8px auto 0; padding: 28px 24px 32px; border-top: 1px solid var(--line); }
.creed-line { margin: 0 0 18px; font-family: var(--display); font-size: clamp(26px, 4vw, 38px); line-height: 1.2; }
.creed-rules { margin: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; }
.creed-rules dt { font-weight: 700; margin-bottom: 4px; }
.creed-rules dd { margin: 0; color: var(--muted); font-size: 14px; }
.foot { margin: 24px 0 0; color: var(--muted); font-size: 12px; }
.foot a { color: inherit; }

/* ---------- 반응형 ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr); }
  .data { grid-column: 1 / -1; }
  .risk-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .feed-panel { grid-column: 1 / -1; }
  .creed-rules { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .topbar, .summary, .layout, .risk-grid, .creed { padding-left: 16px; padding-right: 16px; }
  .alarm-inner { grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 24px 16px 28px; }
  .scale { flex-direction: row-reverse; }
  .scale li { flex: 1; justify-content: center; padding: 8px 4px; font-size: 13px; }
  .scale li::after { display: none; }
  .risk-grid { grid-template-columns: minmax(0, 1fr); }
  .insight { margin-left: 16px; margin-right: 16px; }
  .insight-body { grid-template-columns: minmax(0, 1fr); }
  .mini-stats { flex-direction: row; flex-wrap: wrap; }
  .mini { min-width: 140px; }
  .sub { display: none; }
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .banner { margin-left: 16px; margin-right: 16px; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat.wide { grid-column: 1 / -1; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .chat { height: 70vh; }
  .conv-list { max-height: 220px; }
  .creed-rules { grid-template-columns: minmax(0, 1fr); }
}
