/* 투자 대시보드 — 색상값은 dataviz 레퍼런스 팔레트를 따른다.
   다크는 라이트를 뒤집은 게 아니라 어두운 표면용으로 따로 고른 단계다. */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;          /* 카드 표면 */
  --plane:     #f9f9f7;          /* 페이지 바닥 */
  --ink-1:     #0b0b0b;
  --ink-2:     #52514e;
  --ink-3:     #898781;
  --grid:      #e1e0d9;
  --axis:      #c3c2b7;
  --border:    rgba(11, 11, 11, .10);
  --border-strong: rgba(11, 11, 11, .18);

  /* 발산형(상승↔하락) 램프. 중간은 무채색이어야 "변화 없음"으로 읽힌다. */
  --neutral:   #f0efec;
  --red-1: #f6d9d8;  --red-2: #eba9a8;  --red-3: #e34948;  --red-4: #b02b2a;
  --blue-1: #cde2fb; --blue-2: #86b6ef; --blue-3: #2a78d6; --blue-4: #184f95;
  /* 미국식(초록↑/빨강↓)용. 색만으로는 구분이 어려운 조합이라
     히트맵은 칸마다 숫자를 함께 찍어 색이 유일한 단서가 되지 않게 한다. */
  --green-1: #d7ead7; --green-2: #8ac98a; --green-3: #0ca30c; --green-4: #076b07;

  --accent:    #2a78d6;
  --accent-ink: #ffffff;
  --good:      #006300;

  --radius: 14px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --plane:     #0d0d0d;
    --ink-1:     #ffffff;
    --ink-2:     #c3c2b7;
    --ink-3:     #898781;
    --grid:      #2c2c2a;
    --axis:      #383835;
    --border:    rgba(255, 255, 255, .10);
    --border-strong: rgba(255, 255, 255, .20);
    --neutral:   #383835;
    --red-1: #4a2422;  --red-2: #8a3b39;  --red-3: #e66767;  --red-4: #f39b9b;
    --blue-1: #16304f; --blue-2: #24568f; --blue-3: #3987e5; --blue-4: #86b6ef;
  --green-1: #16301a; --green-2: #205f28; --green-3: #2fae3f; --green-4: #74d17f;
    --accent:    #3987e5;
    --accent-ink: #0b0b0b;
    --good:      #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --plane:     #0d0d0d;
  --ink-1:     #ffffff;
  --ink-2:     #c3c2b7;
  --ink-3:     #898781;
  --grid:      #2c2c2a;
  --axis:      #383835;
  --border:    rgba(255, 255, 255, .10);
  --border-strong: rgba(255, 255, 255, .20);
  --neutral:   #383835;
  --red-1: #4a2422;  --red-2: #8a3b39;  --red-3: #e66767;  --red-4: #f39b9b;
  --blue-1: #16304f; --blue-2: #24568f; --blue-3: #3987e5; --blue-4: #86b6ef;
  --green-1: #16301a; --green-2: #205f28; --green-3: #2fae3f; --green-4: #74d17f;
  --accent:    #3987e5;
  --accent-ink: #0b0b0b;
  --good:      #0ca30c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink-1);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ─────────────────────────────── 상단 바 */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.stamp { margin: 2px 0 0; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; font: inherit; font-size: 13px;
  color: var(--ink-1); background: var(--surface-1);
  border: 1px solid var(--border-strong); border-radius: 999px;
  cursor: pointer; white-space: nowrap;
}
.chip:hover:not(:disabled) { border-color: var(--ink-3); }
.chip:disabled { opacity: .5; cursor: default; }
.chip-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip.is-busy { opacity: .6; pointer-events: none; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch-up { background: var(--red-3); }
body.convention-us .swatch-up { background: var(--good); }

.banner {
  margin: 12px 16px 0; padding: 10px 14px;
  border: 1px solid var(--border-strong); border-left: 3px solid var(--red-3);
  border-radius: var(--radius-sm); background: var(--surface-1);
  font-size: 13px; color: var(--ink-2);
}

/* ─────────────────────────────── 레이아웃 */

.grid {
  display: grid; gap: 14px;
  grid-template-columns: 1fr;
  padding: 14px 16px 32px;
  max-width: 1560px; margin: 0 auto;
}
@media (min-width: 1000px) {
  .grid {
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    grid-template-areas: "heat ind" "news watch" "pf pf";
  }
  .card-heatmap   { grid-area: heat; }
  .card-indicators{ grid-area: ind; }
  .card-news      { grid-area: news; }
  .card-watchlist { grid-area: watch; }
  .card-portfolio { grid-area: pf; }
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  min-width: 0;
}
.card-head {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.card h2 { margin: 0; font-size: 14px; font-weight: 650; letter-spacing: -.005em; }
.card-note { margin: -4px 0 10px; font-size: 12px; color: var(--ink-3); }

/* ─────────────────────────────── 탭 */

.tabs { display: flex; gap: 2px; padding: 2px; background: var(--plane);
        border: 1px solid var(--border); border-radius: 999px; }
.tabs-scroll { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.tabs-scroll::-webkit-scrollbar { display: none; }
.tab {
  padding: 5px 11px; font: inherit; font-size: 12.5px; color: var(--ink-2);
  background: none; border: 0; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--surface-1); color: var(--ink-1); font-weight: 600;
                             box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.tab.is-failed { color: var(--ink-3); }
.tab.is-failed::after { content: " ⚠"; }

/* ─────────────────────────────── 히트맵 */

.heatmap-wrap { width: 100%; }
#heatmap { width: 100%; height: auto; display: block; border-radius: var(--radius-sm); overflow: hidden; }
.hm-cell { cursor: default; }
.hm-cell rect { stroke: var(--surface-1); stroke-width: 2; }
.hm-cell:hover rect { stroke: var(--ink-1); stroke-width: 2; }
.hm-label { font-size: 11px; font-weight: 600; pointer-events: none; }
.hm-sub { font-size: 10px; pointer-events: none; font-variant-numeric: tabular-nums; }

.legend { display: flex; align-items: center; gap: 8px; margin-top: 10px;
          font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.legend-steps { display: flex; gap: 2px; }
.legend-steps i { width: 22px; height: 10px; border-radius: 2px; display: block; }

/* ─────────────────────────────── 지표 타일 */

.tiles { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.tile {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 11px; min-width: 0; background: var(--surface-1);
}
.tile-name { font-size: 11.5px; color: var(--ink-2); display: flex; gap: 5px;
             align-items: center; justify-content: space-between; }
.tile-name b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; margin-top: 3px; }
.tile-val { font-size: 19px; font-weight: 640; letter-spacing: -.02em; line-height: 1.15; }
.tile-val .unit { font-size: 12px; font-weight: 500; color: var(--ink-2); margin-left: 1px; }
.tile-delta { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile-spark { margin-top: 6px; height: 30px; }
.tile-foot { font-size: 10.5px; color: var(--ink-3); margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile-warn { color: var(--red-3); font-weight: 600; }

.spark { width: 100%; height: 100%; display: block; overflow: visible; }
.spark-line { fill: none; stroke: var(--ink-3); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark-dot { r: 2.5; stroke: var(--surface-1); stroke-width: 1.5; }

/* ─────────────────────────────── 뉴스 */

.news { display: flex; flex-direction: column; }
.news-item { display: block; padding: 9px 2px; border-bottom: 1px solid var(--grid);
             color: inherit; text-decoration: none; }
.news-item:last-child { border-bottom: 0; }
.news-item:hover .news-title { text-decoration: underline; text-underline-offset: 2px; }
.news-title { font-size: 13.5px; line-height: 1.45; }
.news-meta { font-size: 11px; color: var(--ink-3); margin-top: 3px;
             display: flex; gap: 8px; flex-wrap: wrap; }
.news-src { display: flex; align-items: center; justify-content: space-between;
            gap: 10px; margin-bottom: 6px; font-size: 11.5px; color: var(--ink-3); }
.news-src a { color: var(--accent); text-decoration: none; }
.news-src a:hover { text-decoration: underline; }

/* ─────────────────────────────── 주요주 / 표 */

.rows { display: flex; flex-direction: column; }
.row {
  display: grid; grid-template-columns: minmax(0,1fr) 76px 66px 62px;
  gap: 8px; align-items: center;
  padding: 8px 2px; border-bottom: 1px solid var(--grid);
}
.row:last-child { border-bottom: 0; }
.row-name { min-width: 0; }
.row-name b { display: block; font-size: 13px; font-weight: 600;
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-name span { font-size: 10.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.row-price { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }
.row-delta { text-align: right; font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.row-spark { height: 26px; }
@media (max-width: 460px) { .row { grid-template-columns: minmax(0,1fr) 72px 62px; } .row-spark { display: none; } }

.up   { color: var(--red-3); }
.down { color: var(--blue-3); }
.flat { color: var(--ink-3); }
body.convention-us .up   { color: var(--good); }
body.convention-us .down { color: var(--red-3); }

/* ─────────────────────────────── 빈 상태 */

.empty { padding: 22px 4px; color: var(--ink-2); font-size: 13px; max-width: 62ch; }
.empty-title { font-size: 14px; font-weight: 650; color: var(--ink-1); margin: 0 0 6px; }
.empty p { margin: 0 0 12px; }
.skeleton { height: 13px; border-radius: 4px; background: var(--grid); margin: 9px 0; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .45 } }

/* ─────────────────────────────── 툴팁 */

.tooltip {
  position: fixed; z-index: 60; pointer-events: none; opacity: 0;
  transform: translate(-50%, calc(-100% - 10px));
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--ink-1); color: var(--surface-1);
  font-size: 12px; line-height: 1.45; max-width: 240px;
  box-shadow: 0 6px 20px rgba(0,0,0,.22);
  transition: opacity .1s ease;
}
.tooltip[data-show="1"] { opacity: 1; }
.tooltip b { display: block; font-size: 12.5px; margin-bottom: 2px; }
.tooltip dl { margin: 3px 0 0; display: grid; grid-template-columns: auto auto;
              gap: 1px 10px; font-variant-numeric: tabular-nums; }
.tooltip dt { opacity: .72; }
.tooltip dd { margin: 0; text-align: right; }

.foot { padding: 0 16px 26px; font-size: 11.5px; color: var(--ink-3); text-align: center; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
