/* ═══════════════════════════════════════════════════
   CheeseStock — 스타일시트 v5.0
   4열 레이아웃: 사이드바 | 차트+수익률 | 패턴설명 | 재무지표
   디자인 시스템: 8단계 타이포그래피 + 4px 간격 스케일
   Pretendard + JetBrains Mono (OFL 1.1)
   차트 배경: #131722 (investing.com 벤치마크)
   ═══════════════════════════════════════════════════ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* ── 색상 4계층 ── */
  --bg:           #0A0A0A;
  --panel:        #141414;
  --bg-element:   #1E1E1E;
  --bg-elevated:  #282828;

  --border:       #252525;
  --border-subtle: rgba(255,255,255,0.07);

  --accent:       #A08830;  /* [UX] 밝기 54%→44%: 블랙/골드 테마에 맞게 어둡게 */
  --up:           #E05050;
  --down:         #5086DC;
  --neutral:      #ffeb3b;

  /* ── 텍스트 3계층 ── */
  --text:         #E8E8E8;
  --text-sub:     #A0A0A0;
  --text-muted:   #808080;

  /* ── 폰트 ── */
  --font-sans:    'Pretendard', 'Segoe UI', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;

  /* ── 8단계 타이포그래피 ── */
  --fs-hero:      28px;
  --fs-display:   20px;
  --fs-heading:   16px;
  --fs-title:     14px;
  --fs-body:      12px;
  --fs-caption:   11px;
  --fs-micro:     10px;
  --fs-nano:      10px;  /* [FIX] 9px→10px: 최소 가독성 기준 충족 */

  /* ── 간격 (4px 스케일) ── */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px;  --sp-4: 16px;  --sp-5: 24px;

  /* ── 레이아웃 ── */
  --header-h:         40px;
  --toolbar-h:        32px;
  --sidebar-w:        260px;
  --sidebar-collapsed: 0px;
  --pattern-panel-w:  240px;
  --rpanel-w:         380px;

  /* ── 차트 배경 (investing.com 벤치마크) ── */
  --chart-bg:         #131722;

  /* ── 사이드바 컨트롤 토큰 ── */
  --ctrl-h-sm:    24px;
  --ctrl-h-md:    28px;
  --ctrl-radius:  6px;
  --ctrl-font:    11px;

  /* ── 기타 ── */
  --radius:       4px;
  --radius-lg:    6px;
  --transition:   .15s ease;
  --min-touch:    28px;
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}


/* ═══ HEADER ══════════════════════════════════════ */

#header {
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid #333;
  display: flex; align-items: center;
  padding: 0 var(--sp-3); gap: var(--sp-2);
  position: relative;
  z-index: 500;
}

#sidebar-toggle {
  background: none; border: none; color: var(--text-sub);
  font-size: 18px; cursor: pointer;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius); transition: all var(--transition);
  line-height: 1; min-width: 36px; min-height: 36px;
  display: flex; align-items: center; justify-content: center;
}
#sidebar-toggle:hover { color: var(--accent); background: var(--bg-element); }
#sidebar-toggle:active { transform: scale(0.92); }
#sidebar-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

#logo {
  font-size: var(--fs-title); font-weight: 700; color: #fff;
  letter-spacing: 0.5px; white-space: nowrap;
}
#logo .logo-cheese { color: var(--accent); }
#logo span { font-weight: 700; }

/* ── SEARCH ── */
#search-wrap { position: relative; flex: 1; max-width: min(320px, 30vw); min-width: 120px; }
#search-input {
  width: 100%; height: 32px;
  background: var(--bg-element); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 6px var(--sp-3) 6px 32px;
  color: var(--text); font-size: var(--fs-body);
  font-family: var(--font-sans); outline: none; transition: border var(--transition);
}
#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(160,136,48,0.15);
}
#search-icon {
  position: absolute; left: var(--sp-2); top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 13px;
}

#search-dropdown {
  display: none; position: absolute; top: 100%; left: 0; right: 0;
  margin-top: 4px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg); z-index: 501; max-height: 260px; overflow-y: auto;
}
#search-dropdown.show { display: block; }
#search-dropdown::-webkit-scrollbar { width: 5px; }
#search-dropdown::-webkit-scrollbar-track { background: transparent; }
#search-dropdown::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
#search-dropdown::-webkit-scrollbar-thumb:hover { background: var(--accent); }
.search-item {
  padding: var(--sp-2) var(--sp-3); cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--sp-2); font-size: var(--fs-body); min-height: var(--min-touch);
}
.search-item:hover { background: var(--bg-element); }
.search-item .code { color: var(--text-muted); font-size: var(--fs-micro); }
.market-tag { font-size: var(--fs-micro); padding: 2px var(--sp-1); border-radius: 3px; font-weight: 600; }
.market-tag.kospi { background: rgba(41,98,255,0.15); color: #5b8af5; }
.market-tag.kosdaq { background: rgba(156,39,176,0.15); color: #ce93d8; }

/* ── TICKER ── */
#ticker-strip { margin-left: auto; display: flex; gap: var(--sp-4); align-items: center; }
.ticker-item { display: flex; flex-direction: column; align-items: flex-end; }
.ticker-name { font-size: var(--fs-micro); color: var(--text-muted); }
.ticker-val { font-size: var(--fs-body); font-weight: 600; font-family: var(--font-mono); }
.up { color: var(--up); }
.dn { color: var(--down); }

/* ── MARKET STATE BADGE ── */
.market-state {
  font-size: var(--fs-micro); font-weight: 700; letter-spacing: .5px;
  padding: 2px 8px; border-radius: 3px; white-space: nowrap;
  line-height: 1.4;
}
.market-state.open     { background: rgba(224,80,80,0.15); color: var(--up); }
.market-state.pre      { background: rgba(255,235,59,0.12); color: var(--neutral); }
.market-state.after    { background: rgba(255,235,59,0.12); color: var(--neutral); }
.market-state.closed   { background: rgba(112,112,112,0.15); color: var(--text-muted); }


/* ═══ MAIN LAYOUT (4열, 1행) ═══════════════════════ */

#main {
  display: grid;
  grid-template-columns:
    minmax(0, var(--sidebar-w))       /* A열: 좌측 메뉴 */
    minmax(360px, 1fr)                /* B열: 차트 + 수익률 */
    minmax(200px, var(--pattern-panel-w))  /* C열: 기술적 패턴 설명 */
    minmax(260px, var(--rpanel-w));   /* D열: 손익지표 */
  grid-template-rows: 1fr;
  height: calc(100vh - var(--header-h));
  max-height: calc(100vh - var(--header-h));
  min-width: 800px;
  gap: 0;
  transition: grid-template-columns .25s ease;
}
#main.sidebar-collapsed {
  grid-template-columns:
    var(--sidebar-collapsed)
    minmax(360px, 1fr)
    minmax(200px, var(--pattern-panel-w))
    minmax(260px, var(--rpanel-w));
}

#sidebar       { grid-column: 1; grid-row: 1; }
#chart-area    { grid-column: 2; grid-row: 1; }
#pattern-panel { grid-column: 3; grid-row: 1; }
#right-panel   { grid-column: 4; grid-row: 1; }


/* ═══ A열: SIDEBAR ═══════════════════════════════
   v7.0 전면 재구축: controls/body 분리, 필터 칩,
   segment control, view toggle, 2행/compact 아이템,
   최근 본 종목, 스파크라인, 패턴 모드
   ════════════════════════════════════════════════ */

#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: width .25s ease;
  width: var(--sidebar-w);
  min-width: 0;
  min-height: 0; /* grid item이 콘텐츠 밀어내지 않도록 */
}
#main.sidebar-collapsed #sidebar {
  width: var(--sidebar-collapsed);
  border-right: none;
}

/* ── 1. Controls 영역 (검색 + 정렬 + 필터) ── */
.sb-controls {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

/* ── 2. 검색 입력 (pill 형태) ── */
.sb-search-wrap {
  padding: var(--sp-2);
}
#sb-search-input {
  width: 100%;
  height: var(--ctrl-h-md);
  background: var(--bg-element);
  border: 1px solid var(--border);
  border-radius: var(--ctrl-radius);
  padding: 0 var(--sp-3);
  color: var(--text);
  font-size: var(--ctrl-font);
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  box-sizing: border-box;
}
#sb-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(160,136,48,0.15);
}
#sb-search-input::placeholder {
  color: var(--text-muted);
}

/* ── 3. 정렬+필터 행 (통합) ── */
.sb-sort-filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 var(--sp-2);
  margin-bottom: var(--sp-1);
}
.sb-sort-filter-row .sb-sort-select {
  flex: 1;
  min-width: 0;
}
/* 정렬 방향 토글 */
.sb-sort-dir {
  width: var(--ctrl-h-sm);
  height: var(--ctrl-h-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-element);
  border: 1px solid var(--border);
  border-radius: var(--ctrl-radius);
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  transition: all .15s ease;
  flex-shrink: 0;
  padding: 0;
}
.sb-sort-dir:hover { color: var(--accent); border-color: var(--accent); }

/* 기존 래퍼 (하위호환) */
.sb-sort-wrap {
  padding: 0 var(--sp-2);
  margin-bottom: var(--sp-1);
}
.sb-sort-select {
  width: 100%;
  height: var(--ctrl-h-md);
  background: var(--bg-element);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--ctrl-radius);
  padding: 0 24px 0 8px;
  font-family: var(--font-sans);
  font-size: var(--ctrl-font);
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23808080'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color var(--transition);
  line-height: var(--ctrl-h-md);
}
.sb-sort-select:hover {
  border-color: var(--text-muted);
}
.sb-sort-select:focus {
  border-color: var(--accent);
  outline: none;
}
.sb-sort-select option {
  background: var(--bg-card);
  color: var(--text);
}

/* ── 4. 필터 칩 ── */
.sb-filter-chips {
  padding: 0 var(--sp-2);
  margin-bottom: var(--sp-1);
}
.sb-chip {
  flex-shrink: 0;
  font-size: var(--ctrl-font);
  font-family: var(--font-sans);
  font-weight: 600;
  padding: 0 8px;
  border-radius: var(--ctrl-radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  height: var(--ctrl-h-sm);
  line-height: var(--ctrl-h-sm);
  display: inline-flex;
  align-items: center;
}
.sb-chip:hover {
  color: var(--text-sub);
  border-color: var(--text-muted);
}
.sb-chip:active { transform: scale(0.95); }
.sb-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sb-chip.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(160,136,48,0.08);
}
/* 대량거래 토글 버튼 */
.sb-vol-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-element);
  border: 1px solid var(--border);
  border-radius: var(--ctrl-radius);
  color: var(--text-sub);
  font-family: var(--font-sans);
  font-size: var(--ctrl-font);
  height: var(--ctrl-h-sm);
  line-height: var(--ctrl-h-sm);
  padding: 0 12px;
  cursor: pointer;
  transition: all .15s ease;
}
.sb-vol-toggle:hover {
  border-color: var(--accent);
  color: var(--text);
}
.sb-vol-toggle.active {
  background: rgba(160,136,48,0.18);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
/* 사이드바 컨트롤 focus-visible 2px 통일 */
.sb-sort-select:focus-visible,
.sb-vol-toggle:focus-visible,
.sb-chip:focus-visible,
.sb-view-opt:focus-visible,
.sb-sort-dir:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* 대량거래 인라인 뱃지 */
.sb-vol-badge {
  display: inline-block;
  font-size: 9px;
  color: #FF6B35;
  margin-left: 2px;
  vertical-align: middle;
  opacity: 0.85;
}

/* ── 5. 보기 모드 컨트롤 ── */
.sb-view-controls {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
/* 세그먼트 3아이콘 그룹 */
.sb-view-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--ctrl-radius);
  overflow: hidden;
}
.sb-view-opt {
  flex: 1;
  height: var(--ctrl-h-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all .15s ease;
  padding: 0 4px;
  white-space: nowrap;
}
.sb-view-opt:last-child { border-right: none; }
.sb-view-opt.active {
  background: var(--bg-elevated);
  color: var(--accent);
}
.sb-view-opt:hover:not(.active) {
  background: var(--bg-element);
  color: var(--text-sub);
}
.sb-pattern-only-chip {
  margin-left: auto;
  font-size: var(--fs-nano);
}

/* ── 6. 본문 (스크롤 영역) ── */
.sb-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}
/* 사이드바 전용 얇은 스크롤바 */
.sb-body::-webkit-scrollbar { width: 4px; }
.sb-body::-webkit-scrollbar-track { background: transparent; }
.sb-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
.sb-body::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── 7. 섹션 ── */
.sb-section {
  border-bottom: 1px solid var(--border);
}

/* ── 8. 섹션 헤더 (접기/펼치기) ── */
.sb-header {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 7px 10px;
  cursor: pointer;
  user-select: none;
  font-size: var(--fs-caption);
  font-weight: 700;
  color: var(--text);
  background: var(--bg-element);
  transition: background var(--transition);
  letter-spacing: 0.02em;
}
.sb-header:hover { background: var(--bg-elevated); }
.sb-header:active { background: rgba(160,136,48,0.08); }

/* 섹션 접기/펼치기 화살표 */
.sb-header::before {
  content: '\25BC'; /* ▼ */
  font-size: 7px;
  color: var(--text-muted);
  transition: transform .2s ease;
  flex-shrink: 0;
  line-height: 1;
}
.sb-header.collapsed::before {
  transform: rotate(-90deg);
}
/* 섹션 접기: 헤더 collapsed 시 다음 .sb-list 숨김 */
.sb-header.collapsed + .sb-list {
  max-height: 0 !important;
  overflow: hidden;
}

/* ── 9. 시장 지수 값 ── */
.sb-index-val {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  color: var(--text-sub);
  font-weight: 600;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

/* ── 10. 종목 수 배지 ── */
.sb-count {
  margin-left: auto;
  font-size: var(--fs-micro);
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 50%;
  min-width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  font-family: var(--font-mono);
}

/* ── 11. 종목 리스트 컨테이너 ── */
.sb-list {
  max-height: 2000px;
  overflow: hidden;
  transition: max-height .25s ease;
}

/* ── 12. 종목 아이템 — DETAILED 모드 (기본) ──
   Row 1: sb-name ... sb-price
   Row 2: sb-mcap / sb-sparkline / sb-volume / sb-rsi ... sb-change
   Pattern names: hover tooltip via data-patterns attr (S6)
   ──────────────────────────────────────────── */
.sb-item {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  padding: 6px 10px;
  cursor: pointer;
  font-size: var(--fs-body);
  border-bottom: 1px solid var(--border-subtle);
  transition: background .12s ease, border-left-color .15s ease;
  white-space: nowrap;
  min-height: 38px;
  gap: 3px var(--sp-2);
  border-left: 3px solid transparent;
  position: relative;
}
.sb-item:hover {
  background: var(--bg-element);
  border-left-color: rgba(160,136,48,0.6);
}
.sb-item:hover .sb-name {
  color: #fff;
}
.sb-item.active {
  background: rgba(160,136,48,0.10);
  border-left-color: var(--accent);
}
.sb-item.active .sb-name { font-weight: 700; color: #fff; }
.sb-item.active .sb-price { color: var(--text); }
.sb-item.active .sb-code { color: var(--text-sub); }
/* 키보드 포커스 */
.sb-item.kb-focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: rgba(160,136,48,0.08);
}
/* 드래그 피드백 */
.sb-item[draggable]:active { opacity: 0.5; }
.sb-item.sb-dragging {
  opacity: 0.3;
  background: var(--bg-element);
}
.sb-item.sb-drag-over-top {
  border-top: 2px solid var(--accent);
}
.sb-item.sb-drag-over-bottom {
  border-bottom: 2px solid var(--accent);
}

/* Row 1 — min-width:0 필수: grid 자식의 flex가 overflow를 허용하도록 */
.sb-row1 { display: flex; align-items: center; gap: var(--sp-1); grid-column: 1 / -1; min-width: 0; }
.sb-row2 { display: flex; align-items: center; gap: var(--sp-1); grid-column: 1 / -1; min-width: 0; }

/* ── 13. 종목명 — flex:1 + min-width:0으로 긴 이름 말줄임, 가격/등락률 고정 보장 ── */
.sb-name {
  grid-column: 1;
  grid-row: 1;
  flex: 1;
  min-width: 0;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  font-size: var(--fs-body);
  line-height: 1.35;
}

/* ── 14. 가격 — 항상 중립색, 절대 빨강/파랑 금지 ── */
.sb-price {
  grid-column: 2;
  grid-row: 1;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: var(--fs-caption);
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
  color: #CCC;
  line-height: 1.3;
  font-feature-settings: "tnum";
}

/* ── 15. 종목코드 ── */
.sb-code {
  grid-column: 1;
  grid-row: 2;
  font-size: var(--fs-nano);
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
  line-height: 1.3;
}

/* ── 16. 거래량 ── */
.sb-volume {
  font-size: var(--fs-nano);
  color: #888;
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
}

/* ── 17. RSI 뱃지 ── */
.sb-rsi {
  font-size: var(--fs-nano);
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-feature-settings: "tnum";
}
.sb-rsi.over { color: var(--up); }
.sb-rsi.under { color: var(--down); }

/* ── 18. 등락률 pill ── */
.sb-change {
  grid-column: 2;
  grid-row: 2;
  font-size: var(--fs-micro);
  font-weight: 700;
  font-family: var(--font-mono);
  text-align: right;
  color: var(--text-muted);
  padding: 1px 5px;
  border-radius: 3px;
  line-height: 1.3;
  background: transparent;
  transition: background var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
  font-feature-settings: "tnum";
}
/* 등락률: 상승 — 빨간 배경 틴트 */
.sb-change.up {
  color: var(--up);
  background: rgba(224,80,80,0.14);
}
/* 등락률: 하락 — 파란 배경 틴트 */
.sb-change.dn {
  color: var(--down);
  background: rgba(80,134,220,0.14);
}

/* ── 19. 스파크라인 ── */
.sb-spark-wrap {
  position: relative;
  width: 48px;
  height: 16px;
  flex-shrink: 0;
  display: block;
  vertical-align: middle;
}
.sb-sparkline {
  width: 48px;
  height: 16px;
  flex-shrink: 0;
  display: block;
  vertical-align: middle;
  border-radius: 2px;
}
/* 스파크라인 로딩 shimmer (데이터 미도착) */
.sb-spark-wrap.loading .sb-sparkline {
  background: linear-gradient(
    90deg,
    var(--bg-element) 0%,
    var(--bg-elevated) 40%,
    var(--bg-element) 80%
  );
  background-size: 400px 100%;
  animation: shimmer 1.5s infinite linear;
}
/* 스파크라인 데이터 타입 레이블 (30D / 오늘) */
.sb-spark-label {
  position: absolute;
  right: -1px;
  bottom: -8px;
  font-size: 7px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  opacity: 0.7;
  line-height: 1;
  pointer-events: none;
  letter-spacing: -.2px;
}

/* ── 20. 시가총액 (S3) ── */
.sb-mcap {
  font-family: var(--font-mono);
  font-size: var(--fs-nano);
  color: var(--text-muted);
  font-feature-settings: "tnum";
}

/* ── 20b. 패턴명 호버 툴팁 (S6) ── */
.sb-item[data-patterns]:hover::after {
  content: attr(data-patterns);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  transform: translateX(-50%);
  background: var(--bg-elevated);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: var(--fs-nano);
  font-style: italic;
  white-space: nowrap;
  z-index: 50;
  pointer-events: none;
}

/* ── 21. 미니멀 모드 (sb-minimal) ── */
#sidebar.sb-minimal .sb-item {
  padding: 4px 10px;
  min-height: var(--min-touch);
  grid-template-rows: auto;
  grid-template-columns: 1fr;
  gap: 0;
}
#sidebar.sb-minimal .sb-row1 {
  display: flex;
  align-items: center;
  gap: 4px;
}
#sidebar.sb-minimal .sb-price {
  flex-shrink: 0;
  font-size: var(--fs-nano);
  white-space: nowrap;
}
#sidebar.sb-minimal .sb-row2 { display: none; }
#sidebar.sb-minimal .sb-code { display: none; }

/* ── 21b. 기본 모드 (클래스 없음) ──
   row1: 종목명 + 가격
   row2: 등락률 + 거래량만 (RSI, 스파크라인, 코드 숨김)
   ────────────────────────── */
#sidebar:not(.sb-minimal):not(.sb-analysis) .sb-sparkline { display: none; }
#sidebar:not(.sb-minimal):not(.sb-analysis) .sb-spark-wrap { display: none; }
#sidebar:not(.sb-minimal):not(.sb-analysis) .sb-rsi { display: none; }
#sidebar:not(.sb-minimal):not(.sb-analysis) .sb-code { display: none; }
#sidebar:not(.sb-minimal):not(.sb-analysis) .sb-row3 { display: none; }

/* ── 21c. 분석 모드 (sb-analysis) ── 모든 항목 표시
   row2를 2행 grid로 재배치:
   1행: 스파크라인(좌) + 등락률(우)
   2행: 시총 + 거래량 + RSI (작은 메타 정보)
   ────────────────────────────────────────── */
#sidebar.sb-analysis .sb-item {
  padding: 5px 8px 5px 10px;
  gap: 2px var(--sp-2);
}
#sidebar.sb-analysis .sb-row2 {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 6px;
  align-items: center;
}
/* 스파크라인 래퍼: 1행 좌측 */
#sidebar.sb-analysis .sb-spark-wrap {
  grid-column: 1;
  grid-row: 1;
  width: 48px;
  height: 16px;
}
#sidebar.sb-analysis .sb-sparkline {
  width: 44px;
  height: 14px;
}
/* 등락률: 1행 우측 끝 */
#sidebar.sb-analysis .sb-change {
  grid-column: 3;
  grid-row: 1;
  flex-shrink: 0;
  white-space: nowrap;
  justify-self: end;
}
/* 시총/거래량/RSI: 2행, 중앙~우측에 자연 배치 */
#sidebar.sb-analysis .sb-mcap,
#sidebar.sb-analysis .sb-volume,
#sidebar.sb-analysis .sb-rsi {
  grid-row: 2;
  font-size: 9px;
  line-height: 1.2;
}
#sidebar.sb-analysis .sb-mcap   { grid-column: 1; color: var(--text-sub); }
#sidebar.sb-analysis .sb-volume { grid-column: 2; }
#sidebar.sb-analysis .sb-rsi    { grid-column: 3; justify-self: end; }

/* ── 22. "N개 더보기" 버튼 ── */
.sb-load-more {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px var(--sp-3);
  font-size: var(--fs-micro);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  border: none;
  background: none;
  width: 100%;
  transition: color var(--transition), background var(--transition);
  letter-spacing: 0.01em;
}
.sb-load-more:hover {
  color: var(--accent);
  background: var(--bg-element);
}
.sb-load-more:active {
  background: var(--bg-elevated);
  transform: scale(0.98);
}
.sb-load-more:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

/* ── 22b. 가상 스크롤 (R13) ── */
.sb-virtual-spacer { width: 100%; }
.sb-virtual-content { width: 100%; will-change: transform; }

/* ── 23. 최근 본 종목 섹션 ── */
.sb-recent-section {
  background: rgba(160,136,48,0.03);
}
.sb-recent-section .sb-header {
  background: rgba(160,136,48,0.06);
}
.sb-recent-section .sb-header:hover {
  background: rgba(160,136,48,0.12);
}
.sb-recent-section .sb-item:hover .sb-remove {
  opacity: 1;
}
.sb-remove {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition), background var(--transition);
  border-radius: 50%;
}
.sb-remove:hover {
  color: var(--up);
  background: rgba(224,80,80,0.2);
}
.sb-remove:active {
  transform: translateY(-50%) scale(0.9);
}

/* ── 24. 가격 Flash 애니메이션 (사이드바 전용) ── */
.sb-price.price-flash-up { animation: priceFlashUp 0.5s ease-out; }
.sb-price.price-flash-down { animation: priceFlashDown 0.5s ease-out; }


/* ═══ B열: CHART AREA ═══════════════════════════ */

#chart-area {
  background: #131722;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: inset 1px 0 0 rgba(42,46,57,0.3), inset -1px 0 0 rgba(42,46,57,0.3);
  min-height: 0; /* flex/grid item이 콘텐츠 밀어내지 않도록 */
  padding-left: 1px;
}
#main.sidebar-collapsed #chart-area {
  padding-left: var(--sp-1);
  border-left: 1px solid var(--border);
}

/* ── 종목 정보 헤더 ── */
#stock-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-1) var(--sp-3);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; gap: var(--sp-3);
  min-height: 40px;
  background: var(--panel);
}

.sh-left {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0;
}
.sh-identity {
  display: flex; align-items: center; gap: var(--sp-2);
  white-space: nowrap; line-height: 1.2;
  position: relative; /* 연결 설정 패널 기준점 */
}
.sh-name {
  font-size: var(--fs-heading); font-weight: 700; color: #fff;
  letter-spacing: -0.01em; line-height: 1.35;
}
.sh-code {
  font-size: var(--fs-caption); color: var(--text-muted);
  font-family: var(--font-mono);
}
.sh-market {
  font-size: var(--fs-micro); padding: 2px 6px; border-radius: 3px;
  background: rgba(41,98,255,0.15); color: #5b8af5; font-weight: 600;
  line-height: 1.2;
}
.sh-market.kosdaq { background: rgba(156,39,176,0.15); color: #ce93d8; }

.sh-price-row {
  display: flex; align-items: baseline; gap: var(--sp-2);
  margin-top: 1px;
}
.sh-price {
  font-size: var(--fs-display); font-weight: 700; font-family: var(--font-mono);
  letter-spacing: -0.03em;
  transition: background-color 0.3s ease;
  padding: 2px var(--sp-2); border-radius: var(--radius);
  line-height: 1.1;
}
.sh-price.up { color: var(--up); }
.sh-price.dn { color: var(--down); }
.sh-change {
  font-size: 13px; font-weight: 700; font-family: var(--font-mono);
  padding: var(--sp-1) var(--sp-2); border-radius: var(--radius);
  transition: background-color 0.3s ease;
  letter-spacing: -0.01em;
  border: 1px solid transparent;
  line-height: 1.2; white-space: nowrap;
}
.sh-change.up {
  background: rgba(224, 80, 80, 0.18);
  color: var(--up);
  border-color: rgba(224, 80, 80, 0.25);
}
.sh-change.dn {
  background: rgba(80, 134, 220, 0.18);
  color: var(--down);
  border-color: rgba(80, 134, 220, 0.25);
}

.sh-details {
  display: flex; gap: var(--sp-2); align-items: center;
  flex-shrink: 0;
}
.sh-detail-item {
  display: flex; flex-direction: column; align-items: flex-end; gap: 1px;
  padding: var(--sp-1) var(--sp-2);
  background: var(--bg-element); border-radius: var(--radius);
  min-width: 68px;
}
.sh-detail-label {
  font-size: var(--fs-nano); color: var(--text-muted);
  letter-spacing: 0.06em; font-weight: 600;
  text-transform: uppercase;
}
.sh-detail-value {
  font-size: var(--fs-caption); font-weight: 700; font-family: var(--font-mono);
  color: var(--text); letter-spacing: -0.02em;
}
.sh-detail-value.sh-high { color: var(--up); }
.sh-detail-value.sh-low { color: var(--down); }

/* ── 차트 툴바 ── */
#chart-toolbar {
  height: var(--toolbar-h); display: flex; align-items: center;
  padding: 0 var(--sp-3); gap: var(--sp-1);
  border-bottom: 1px solid var(--border); flex-shrink: 0; overflow: hidden;
  background: var(--bg-element);
}
.sep { width: 1px; height: 18px; background: var(--border); margin: 0 var(--sp-1); flex-shrink: 0; }
#chart-toolbar .sep { background: #333; }

.tf-btn, .ct-btn, .ind-btn {
  background: transparent; border: 1px solid transparent; border-radius: var(--radius);
  padding: var(--sp-1) var(--sp-2); color: var(--text-muted); cursor: pointer;
  font-size: var(--fs-caption); font-weight: 500;
  transition: all var(--transition); white-space: nowrap; flex-shrink: 0;
  min-height: var(--min-touch); line-height: 1.2;
}
.tf-btn:hover, .ct-btn:hover, .ind-btn:hover { color: var(--text); background: var(--bg-element); }
.tf-btn.active, .ct-btn.active, .ind-btn.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.pattern-btn { border-color: rgba(160,136,48,0.3); }
.pattern-btn.active { background: rgba(160,136,48,0.2) !important; border-color: var(--accent) !important; color: var(--accent) !important; }

/* ── 지표 드롭다운 ── */
.ind-dropdown-wrap { position: relative; flex-shrink: 0; }
.ind-dropdown-btn {
  background: transparent; border: 1px solid transparent; border-radius: var(--radius);
  padding: var(--sp-1) var(--sp-2); color: var(--text-muted); cursor: pointer;
  font-size: var(--fs-caption); font-weight: 500; font-family: var(--font-sans);
  transition: all var(--transition); white-space: nowrap;
  min-height: var(--min-touch); line-height: 1.2;
}
.ind-dropdown-btn:hover { color: var(--text); background: var(--bg-element); }
.ind-dropdown-btn.has-active { color: var(--accent); border-color: rgba(160,136,48,0.3); }
.ind-dropdown-menu {
  display: none; position: absolute; top: 100%; left: 0;
  margin-top: var(--sp-1);
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg); z-index: 120;
  min-width: 160px; padding: var(--sp-1) 0;
  max-height: min(70vh, 460px); overflow-y: auto;  /* 13+ 지표 항목 스크롤 지원 */
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.ind-dropdown-menu.show { display: block; }
.ind-check {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3); cursor: pointer;
  font-size: var(--fs-caption); color: var(--text-sub);
  transition: background var(--transition); white-space: nowrap;
  min-height: var(--min-touch); user-select: none;
}
.ind-check:hover { background: var(--bg-element); color: var(--text); }
.ind-check input[type="checkbox"] {
  width: 13px; height: 13px; accent-color: var(--accent);
  cursor: pointer; margin: 0; flex-shrink: 0;
}

/* ── 차트 래퍼 ── */
#chart-wrap {
  flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative;
  min-height: 0;
}
#main-chart-container {
  flex: 1; position: relative; min-height: 200px;
  background: var(--chart-bg);
  margin-left: 40px;  /* 드로잉 툴바 폭만큼 여백 */
}

/* ═══ 드로잉 툴바 (좌측 수직) ═══ */
.draw-toolbar {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 40px; z-index: 30;
  background: #161616;
  border-right: 1px solid #252525;
  display: flex; flex-direction: column;
  align-items: center; padding: 8px 0; gap: 2px;
}
.draw-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 4px;
  color: #808080; cursor: pointer;
  position: relative; transition: all 0.12s ease-out;
}
.draw-btn:hover { color: #B0B0B0; background: rgba(255,255,255,0.06); }
.draw-btn.active {
  color: #A08830;
  background: rgba(160,136,48,0.10);
}
.draw-btn.active::before {
  content: ''; position: absolute; left: 0; top: 4px; bottom: 4px;
  width: 2px; background: #A08830; border-radius: 1px;
}
.draw-btn:active { transform: scale(0.96); }
.draw-sep { width: 20px; height: 1px; background: #252525; margin: 4px 0; }

/* 색상 버튼 내부 원의 기본 채우기 (현재 선택 색상 반영은 JS에서) */
.draw-color-btn svg circle:last-child { fill: #C9A84C; }

/* ── 색상 선택기 팝업 ── */
.draw-color-picker {
  position: absolute; left: 44px; top: 0;
  background: #1E1E1E; border: 1px solid #333;
  border-radius: 6px; padding: 6px; z-index: 35;
  display: flex; flex-direction: column; gap: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
.draw-color-swatch {
  width: 22px; height: 22px; border-radius: 3px;
  cursor: pointer; border: 2px solid transparent;
  transition: transform 0.1s ease, border-color 0.1s ease;
}
.draw-color-swatch.active { border-color: #fff; }
.draw-color-swatch:hover { transform: scale(1.15); }

/* 드로잉 모드일 때 차트 커서 변경 */
#main-chart-container.drawing-mode { cursor: crosshair; }
#main-chart-container.select-mode { cursor: default; }
#main-chart-container.select-mode:active { cursor: grabbing; }

/* 드로잉 툴바가 있을 때 내부 요소들의 왼쪽 여백 조정 */
#chart-wrap .sub-chart-wrap { margin-left: 40px; }
#chart-wrap #ohlc-bar { left: calc(40px + var(--sp-2)); }
#chart-wrap #pattern-summary-wrap { margin-left: 40px; }
#chart-wrap #pattern-history-bar { margin-left: 40px; }
.sub-chart-wrap { flex-shrink: 0; position: relative; }
.sub-chart {
  height: clamp(50px, 8vh, 80px); position: relative;
  border-top: 1px solid var(--border);
  background: var(--chart-bg);
  box-shadow: inset 0 1px 0 rgba(42,46,57,0.4);
}
.sub-chart-label {
  position: absolute; top: var(--sp-1); left: calc(40px + var(--sp-2));  /* 드로잉 툴바 40px 고려 */
  font-size: var(--fs-caption); font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text); z-index: 10; pointer-events: none;
  letter-spacing: 0.05em;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  padding: 2px var(--sp-2);
  background: rgba(19,23,34,0.82);
  border-radius: var(--radius);
  border: 1px solid rgba(42,46,57,0.3);
  line-height: 1.3;
}


/* ═══ C열: PATTERN PANEL (기술적 패턴 설명) ═══════ */

#pattern-panel {
  background: var(--panel);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-x: hidden; overflow-y: auto;
  min-height: 0; /* grid item이 콘텐츠 밀어내지 않도록 */
}

/* ── 패턴 패널 토글 버튼 (1200px 이하에서만 표시) ── */
#pp-toggle {
  display: none;              /* 큰 화면에서 숨김, @media에서 flex로 전환 */
  position: fixed;
  top: calc(var(--header-h) + var(--toolbar-h) + 60px);
  right: 0;
  z-index: 91;
  width: 28px; height: 56px;
  align-items: center; justify-content: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition), right .25s ease;
  box-shadow: -2px 0 8px rgba(0,0,0,0.3);
}
#pp-toggle:hover {
  background: var(--bg-elevated);
}
#pp-toggle .pp-toggle-icon {
  display: inline-block;
  transition: transform .25s ease;
  font-size: 11px;
  line-height: 1;
}
/* 패널 열렸을 때 화살표 방향 전환 + 패널 너비만큼 왼쪽으로 이동 */
#pp-toggle.pp-open .pp-toggle-icon {
  transform: rotate(180deg);
}
#pp-toggle.pp-open {
  right: min(280px, 80vw);
}

/* 패널 뒤 백드롭 (1024px 이하) */
#pp-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 89;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity .25s ease;
}
#pp-backdrop.pp-bd-visible {
  display: block;
  opacity: 1;
}

.pp-header {
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-body); font-weight: 600;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.03em; flex-shrink: 0;
}

.pp-content {
  flex: 1; padding: var(--sp-2);
  display: flex; flex-direction: column;
  gap: var(--sp-2);
  overflow-x: hidden; overflow-y: auto;
}

/* ── 패턴 카드 (교과서 스타일) ── */
.pp-card {
  background: var(--bg-element);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: var(--sp-3);
  border-left: 3px solid var(--text-muted);
  transition: border-color var(--transition), box-shadow var(--transition),
              background-color var(--transition);
  position: relative;
}
.pp-card + .pp-card {
  margin-top: var(--sp-2);
}
.pp-card:hover {
  background: var(--bg-elevated);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.pp-card.buy { border-left-color: var(--up); }
.pp-card.sell { border-left-color: var(--down); }
.pp-card.neutral { border-left-color: var(--neutral); }

/* 매수/매도 카드 상단 미세 그라데이션 */
.pp-card.buy::before {
  content: ''; position: absolute; inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(224,80,80,0.04) 0%, transparent 40%);
  pointer-events: none;
}
.pp-card.sell::before {
  content: ''; position: absolute; inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(80,134,220,0.04) 0%, transparent 40%);
  pointer-events: none;
}

.pp-card-header {
  display: flex; align-items: center;
  gap: var(--sp-2); margin-bottom: var(--sp-1);
}
.pp-card-signal {
  font-size: var(--fs-nano); font-weight: 700;
  padding: 2px 8px; border-radius: 3px;
  letter-spacing: 0.06em; text-transform: uppercase;
  flex-shrink: 0; white-space: nowrap;
}
.pp-card-signal.buy { background: rgba(224,80,80,0.15); color: var(--up); }
.pp-card-signal.sell { background: rgba(80,134,220,0.15); color: var(--down); }
.pp-card-signal.neutral { background: rgba(255,235,59,0.12); color: var(--neutral); }

.pp-card-name {
  font-size: var(--fs-body); font-weight: 700; color: #fff;
  line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 교과서 패턴 다이어그램 */
.pp-card-diagram {
  margin: var(--sp-1) 0;
  background: var(--bg); border-radius: var(--radius);
  padding: var(--sp-1);
  display: flex; justify-content: center;
}
.pp-diagram-canvas {
  width: 100%; height: 70px; display: block;
}

/* 카테고리 라벨 */
.pp-card-category {
  font-size: var(--fs-nano); color: var(--text-muted);
  letter-spacing: 0.03em; display: block;
  margin-bottom: var(--sp-2);
  padding-bottom: var(--sp-1);
  border-bottom: 1px solid var(--border-subtle);
}

/* 신뢰도 바 */
.pp-conf-wrap {
  display: flex; align-items: center; gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}
.pp-conf-label {
  font-size: var(--fs-nano); color: var(--text-muted);
  flex-shrink: 0; min-width: 32px;
}
.pp-conf-bar-track {
  flex: 1; height: 5px;
  background: var(--bg); border-radius: 3px; overflow: hidden;
}
.pp-conf-bar-fill {
  height: 100%; border-radius: 3px;
  transition: width 0.5s cubic-bezier(0.22,1,0.36,1);
}
.pp-conf-bar-fill.buy { background: var(--up); }
.pp-conf-bar-fill.sell { background: var(--down); }
.pp-conf-bar-fill.neutral { background: var(--neutral); }
.pp-conf-val {
  font-family: var(--font-mono); font-size: var(--fs-micro);
  font-weight: 700; color: var(--text); min-width: 28px; text-align: right;
  font-feature-settings: "tnum";
}

/* 패턴 설명 텍스트 */
.pp-card-desc {
  font-size: var(--fs-caption); color: var(--text-sub);
  line-height: 1.65; margin-bottom: var(--sp-2);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: keep-all;
}

/* 시장 심리 해설 */
.pp-card-psych {
  margin: var(--sp-2) 0; padding: var(--sp-2) var(--sp-3);
  background: rgba(160,136,48,0.04);
  border-radius: var(--radius);
  border-left: 2px solid var(--accent);
}
.pp-psych-label {
  font-size: var(--fs-nano); font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.06em;
  display: block; margin-bottom: var(--sp-1);
}
.pp-card-psych p {
  font-size: var(--fs-micro); color: var(--text-sub);
  line-height: 1.65; margin: 0;
  word-break: keep-all;
}

/* 손절/목표 */
.pp-card-risk {
  display: flex; gap: var(--sp-3); margin-top: var(--sp-2);
  padding: var(--sp-2);
  background: var(--bg); border-radius: var(--radius);
  font-size: var(--fs-micro); font-family: var(--font-mono);
  font-feature-settings: "tnum";
}
.pp-risk-sl, .pp-risk-tp {
  display: flex; align-items: center; gap: var(--sp-1);
}
.pp-risk-sl::before {
  content: ''; width: 6px; height: 6px;
  border-radius: 50%; background: var(--down); flex-shrink: 0;
}
.pp-risk-tp::before {
  content: ''; width: 6px; height: 6px;
  border-radius: 50%; background: var(--up); flex-shrink: 0;
}
.pp-risk-sl { color: var(--down); font-weight: 600; }
.pp-risk-tp { color: var(--up); font-weight: 600; }

/* 통계 행 */
.pp-card-stats {
  display: flex; flex-direction: column; gap: 0;
  margin-top: var(--sp-2);
  background: var(--bg); border-radius: var(--radius);
  overflow: hidden;
}
.pp-stat-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px var(--sp-2);
  transition: background var(--transition);
}
.pp-stat-row:nth-child(even) {
  background: rgba(255,255,255,0.015);
}
.pp-stat-row:hover {
  background: rgba(255,255,255,0.04);
}
.pp-stat-label {
  font-size: var(--fs-nano); color: var(--text-muted);
  flex-shrink: 0;
}
.pp-stat-bar-wrap {
  flex: 1; height: 4px;
  background: var(--bg-element); border-radius: 2px; overflow: hidden;
  margin: 0 var(--sp-2);
}
.pp-stat-bar {
  height: 100%; background: var(--accent);
  border-radius: 2px; transition: width 0.4s ease;
}
.pp-stat-value {
  font-family: var(--font-mono); font-size: var(--fs-micro);
  font-weight: 700; color: var(--text);
  min-width: 36px; text-align: right;
  font-feature-settings: "tnum";
}
.pp-stat-value.up { color: var(--up); }
.pp-stat-value.dn { color: var(--down); }

/* 무효화 조건 */
.pp-card-invalid {
  margin-top: var(--sp-2); padding: var(--sp-2) var(--sp-3);
  background: rgba(80,134,220,0.05);
  border-radius: var(--radius);
  border-left: 2px solid rgba(80,134,220,0.5);
}
.pp-invalid-label {
  font-size: var(--fs-nano); font-weight: 700;
  color: rgba(80,134,220,0.8);
  text-transform: uppercase; letter-spacing: 0.06em;
  display: block; margin-bottom: var(--sp-1);
}
.pp-card-invalid p {
  font-size: var(--fs-micro); color: var(--text-sub);
  line-height: 1.65; margin: 0;
  word-break: keep-all;
}

/* ── 합류 분석 ── */
.pp-confluence {
  background: var(--bg-element);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: var(--sp-2) var(--sp-3);
  margin-top: auto;
}
.pp-confluence-title {
  font-size: var(--fs-micro); font-weight: 700;
  color: var(--accent); letter-spacing: 0.04em;
  text-transform: uppercase; margin-bottom: var(--sp-2);
}
.pp-confluence-items {
  display: flex; flex-direction: column; gap: 2px;
}
.pp-conf-item {
  font-size: var(--fs-caption); padding: 2px 0;
  display: flex; align-items: center; gap: var(--sp-1);
}
.pp-conf-item::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}
.pp-conf-item.match { color: var(--text); }
.pp-conf-item.match::before { background: var(--up); }
.pp-conf-item.miss { color: var(--text-muted); }
.pp-conf-item.miss::before { background: var(--text-muted); }
.pp-conf-score {
  margin-top: var(--sp-2); padding-top: var(--sp-1);
  border-top: 1px solid var(--border-subtle);
  font-size: var(--fs-caption); color: var(--text-sub);
}
.pp-score-value {
  font-family: var(--font-mono); font-weight: 700;
  font-size: var(--fs-title); color: var(--accent);
}

/* 빈 상태 */
.pp-empty {
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  flex: 1;
  color: var(--text-muted); font-size: var(--fs-caption);
  line-height: 1.8; padding: var(--sp-5);
  min-height: 120px;
  opacity: 0.6;
}


/* ═══ D열: RIGHT PANEL (주요재무지표) ═════════════ */

#right-panel {
  background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  min-height: 0; /* grid item이 콘텐츠 밀어내지 않도록 */
}

.rp-header {
  padding: var(--sp-2) var(--sp-3); font-size: var(--fs-body); font-weight: 600;
  color: var(--accent); border-bottom: 1px solid var(--border);
  letter-spacing: 0.03em; flex-shrink: 0;
}
#fin-content {
  flex: 1; padding: var(--sp-2) var(--sp-3); overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; gap: 0;
  scrollbar-gutter: stable;  /* [FIX] Windows 17px 스크롤바 레이아웃 시프트 방지 */
}
.fin-period-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--sp-2);
}
.fin-period-label {
  font-size: var(--fs-body); font-weight: 700; font-family: var(--font-mono);
  color: var(--text);
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}
.fin-period-type {
  font-size: var(--fs-micro); color: var(--text-muted);
}
.fin-section-title {
  font-size: var(--fs-caption); font-weight: 500; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-top: var(--sp-2); margin-bottom: var(--sp-1);
  padding-bottom: 2px; border-bottom: 1px solid var(--border-subtle);
}
.fin-section-title:first-of-type { margin-top: 0; }
.fin-row {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 2px 0;
}
.fin-row-label {
  font-size: var(--fs-body); color: var(--text-sub);
}
.fin-row-value {
  font-size: var(--fs-body); font-weight: 700; font-family: var(--font-mono);
  color: var(--text);
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}
.fin-row-value.up { color: var(--up); }
.fin-row-value.dn { color: var(--down); }
.fin-unit {
  font-size: var(--fs-micro); font-weight: 400; color: var(--text-muted);
  margin-left: 1px; letter-spacing: 0;
  font-family: var(--font-sans);
}
.fin-row-sub {
  display: flex; gap: var(--sp-2); padding: 0 0 var(--sp-1);
}
.fin-change {
  font-size: var(--fs-micro); font-family: var(--font-mono);
  color: var(--text-muted);
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}
.fin-change.up { color: #C06060; }
.fin-change.dn { color: #6090C0; }
.fin-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: var(--sp-2); margin-top: 2px;
}
.fin-grid-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--sp-2) var(--sp-2); background: var(--bg-element);
  border-radius: var(--radius);
  transition: background var(--transition);
}
.fin-grid-item:hover { background: var(--bg-elevated); }
.fin-grid-label {
  font-size: var(--fs-micro); color: var(--text-muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 2px;
}
.fin-grid-value {
  font-size: var(--fs-body); font-weight: 700; font-family: var(--font-mono);
  color: var(--text);
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.fin-grid-value.up { color: var(--up); }
.fin-grid-value.dn { color: var(--down); }

/* 투자판단 점수 */
.fin-score-item { grid-column: span 1; }
.fin-score {
  font-size: var(--fs-body); font-weight: 700;
}
.fin-score.score-high { color: var(--up); }
.fin-score.score-mid  { color: var(--accent); }
.fin-score.score-low  { color: var(--down); }
.fin-grade-a  { color: var(--up); }
.fin-grade-b  { color: var(--accent); }
.fin-grade-c  { color: var(--text-muted); }
.fin-grade-d  { color: var(--down); }

.fin-grid-2col {
  grid-template-columns: 1fr 1fr;
}

.fin-score-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2);
  margin: 0 0 var(--sp-2);
  background: var(--bg-element);
  border-radius: var(--ctrl-radius);
  border-left: 3px solid var(--accent);
}

.fin-score-main {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.fin-score-main .fin-score {
  font-size: var(--fs-heading);
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent);
}

.fin-score-grade,
#fin-grade {
  font-size: var(--fs-body);
  font-weight: 700;
  font-family: var(--font-mono);
}

.fin-score-note {
  font-size: var(--fs-nano);
  color: var(--text-muted);
  text-align: right;
  max-width: 60%;
}

.fin-spark-wrap {
  margin-top: var(--sp-2);
}
.fin-spark-label {
  font-size: var(--fs-micro); color: var(--text-muted);
  display: block; margin-bottom: 2px;
}
.fin-source {
  font-size: var(--fs-micro); color: var(--text-muted);
  text-align: right; letter-spacing: 0.02em;
}
#opm-sparkline { width: 100%; height: 80px; margin-top: 2px; display: block; }

/* ── PER 밴드 차트 ── */
.fin-per-band-wrap {
  padding: 0 var(--sp-1);
  margin-bottom: var(--sp-2);
}
#fin-per-band {
  width: 100%;
  display: block;
}

/* ── 신규 재무 섹션 (업종비교 / 주주) ── */
.fin-compare, .fin-peers, .fin-news {
  padding: 0 var(--sp-2);
  margin-bottom: var(--sp-2);
}
.fin-compare-placeholder {
  color: var(--text-muted);
  font-size: var(--fs-micro);
  text-align: center;
  padding: var(--sp-3);
  opacity: 0.5;
}
.fin-compare-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-1);
}
.fin-compare-sector {
  font-size: var(--fs-micro);
  color: var(--accent);
  font-weight: 600;
}
.fin-compare-count {
  font-size: var(--fs-micro);
  color: var(--text-muted);
}
.fin-compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-micro);
  font-family: var(--font-mono);
}
.fin-compare-table th {
  color: var(--text-muted);
  font-weight: 500;
  text-align: right;
  padding: 2px 4px;
  border-bottom: 1px solid var(--border-subtle);
}
.fin-compare-table th:first-child {
  text-align: left;
}
.fin-cmp-label {
  color: var(--text-sub);
  font-family: var(--font-sans);
  padding: 3px 4px;
}
.fin-cmp-val {
  text-align: right;
  padding: 3px 4px;
  color: var(--text);
  font-feature-settings: "tnum";
}
.fin-cmp-good { color: #6BCB77; }
.fin-cmp-bad { color: #C06060; }

/* ── 동종업종 비교 (Peer Group) ── */
.fin-peers {
  padding: 0 var(--sp-2);
  margin-bottom: var(--sp-2);
}
.fin-peer-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-micro);
}
.fin-peer-table th {
  color: var(--text-muted);
  font-weight: 500;
  text-align: right;
  padding: 2px 3px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--fs-nano);
}
.fin-peer-table th.fin-peer-name {
  text-align: left;
}
.fin-peer-val {
  text-align: right;
  padding: 3px 3px;
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
  color: var(--text-sub);
  font-size: var(--fs-micro);
}
.fin-peer-name {
  padding: 3px 3px;
  font-family: var(--font-sans);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fin-peer-current {
  background: rgba(160,136,48,0.08);
}
.fin-peer-me {
  color: var(--accent);
  font-weight: 600;
}
.fin-peer-link {
  color: var(--text-sub);
  cursor: pointer;
  text-decoration: none;
}
.fin-peer-link:hover {
  color: var(--accent);
  text-decoration: underline;
}
.fin-peer-mcap {
  color: var(--text-muted);
}

/* ═══ 재무 info 툴팁 (CSS-only) ═══════════════════ */

.fin-info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 12px; height: 12px;
  font-size: 10px; font-style: normal; font-weight: 400;
  color: var(--text-muted); cursor: help;
  position: relative; vertical-align: middle;
  margin-left: 1px; line-height: 1;
  transition: color var(--transition);
}
.fin-info:hover { color: var(--accent); }

.fin-info::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%);
  width: max-content; max-width: 180px;
  padding: var(--sp-2);
  background: rgba(20, 20, 20, 0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-sub); font-size: var(--fs-caption);
  font-family: var(--font-sans); font-weight: 400;
  line-height: 1.5; letter-spacing: 0;
  white-space: normal; text-align: left;
  z-index: 200; pointer-events: none;
  opacity: 0; visibility: hidden;
  transition: opacity .15s, visibility .15s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
.fin-info::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px); left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: rgba(20, 20, 20, 0.96);
  z-index: 201; pointer-events: none;
  opacity: 0; visibility: hidden;
  transition: opacity .15s, visibility .15s;
}
.fin-info:hover::after,
.fin-info:hover::before {
  opacity: 1; visibility: visible;
}


/* ═══ 추이 차트 섹션 ═════════════════════════════ */

.fin-trend-section {
  margin-top: var(--sp-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius); overflow: hidden;
}
.fin-trend-header {
  display: flex; align-items: center; gap: var(--sp-1);
  padding: 2px var(--sp-2);
  background: var(--bg-element);
}
.fin-trend-title {
  font-size: var(--fs-micro); font-weight: 600;
  color: var(--text-muted); letter-spacing: 0.04em;
  text-transform: uppercase; flex-shrink: 0;
}
.fin-trend-tabs {
  display: flex; gap: 2px; flex: 1;
}
.fin-trend-tab {
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 1px var(--sp-1); color: var(--text-muted);
  font-size: var(--fs-micro); font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer; transition: all var(--transition);
  line-height: 1.3; white-space: nowrap;
}
.fin-trend-tab:hover { color: var(--text); background: var(--bg-elevated); }
.fin-trend-tab.active {
  color: var(--accent); background: rgba(160,136,48,0.12);
  border-color: rgba(160,136,48,0.3);
}
.fin-trend-toggle {
  background: none; border: none;
  color: var(--text-muted); font-size: 10px;
  cursor: pointer; padding: 1px var(--sp-1);
  transition: transform .2s, color var(--transition);
  line-height: 1; flex-shrink: 0;
}
.fin-trend-toggle:hover { color: var(--text); }
.fin-trend-toggle.collapsed { transform: rotate(-90deg); }
.fin-trend-body {
  padding: 2px var(--sp-2) var(--sp-1);
  transition: max-height .25s ease, padding .25s ease;
  max-height: 72px; overflow: hidden;
}
.fin-trend-body.collapsed {
  max-height: 0; padding-top: 0; padding-bottom: 0;
}
#fin-trend-canvas {
  width: 100%; height: 56px; display: block;
}


/* ═══ 면책 조항 ═════════════════════════════════ */

.fin-footer {
  margin-top: auto; padding-top: var(--sp-1);
}
.fin-disclaimer {
  margin-bottom: var(--sp-1);
}
.fin-disclaimer-toggle {
  background: none; border: none;
  color: var(--text-muted); font-size: var(--fs-caption);
  cursor: pointer; padding: 0;
  font-family: var(--font-sans);
  transition: color var(--transition);
}
.fin-disclaimer-toggle:hover { color: var(--text-sub); }
.fin-disclaimer-body {
  max-height: 0; overflow: hidden;
  transition: max-height .25s ease, margin .25s ease;
  font-size: var(--fs-micro); color: var(--text-muted);
  line-height: 1.6; margin-top: 0;
}
.fin-disclaimer-body.show {
  max-height: 80px; margin-top: var(--sp-1);
}


/* ═══ 패턴/시그널 호버 툴팁 ═════════════════════ */

.pattern-tooltip {
  display: none; position: absolute; z-index: 50;
  pointer-events: none;
  background: rgba(20, 20, 20, 0.94);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-2);
  min-width: 180px; max-width: 260px;
  backdrop-filter: blur(8px);
  font-size: var(--fs-caption);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.pattern-tooltip.show { display: block; }
.pt-header {
  display: flex; align-items: center; gap: var(--sp-1);
  margin-bottom: var(--sp-1);
  padding-bottom: var(--sp-1);
  border-bottom: 1px solid var(--border-subtle);
}
.pt-name { font-weight: 700; color: #fff; font-size: var(--fs-body); }
.pt-signal {
  font-size: var(--fs-micro); padding: 1px 5px; border-radius: 3px; font-weight: 700;
}
.pt-signal.buy { background: rgba(224,80,80,0.2); color: var(--up); }
.pt-signal.sell { background: rgba(80,134,220,0.2); color: var(--down); }
.pt-signal.neutral { background: rgba(255,235,59,0.15); color: var(--neutral); }
.pt-conf {
  margin-left: auto;
  font-family: var(--font-mono); font-weight: 700;
  font-size: var(--fs-caption);
}
.pt-desc { color: var(--text-sub); font-size: var(--fs-micro); line-height: 1.5; margin-bottom: var(--sp-1); }
.pt-meta {
  display: flex; flex-wrap: wrap; gap: var(--sp-2);
  font-size: var(--fs-micro); font-family: var(--font-mono); color: var(--text-muted);
}
.pt-meta span { white-space: nowrap; }
.pt-meta .pt-sl { color: var(--down); }
.pt-meta .pt-tp { color: var(--up); }
.pt-academic {
  font-size: var(--fs-nano); color: var(--text-muted);
  line-height: 1.5; margin-bottom: var(--sp-1);
  padding: var(--sp-1); background: rgba(255,255,255,0.02);
  border-radius: var(--radius); border-left: 2px solid var(--accent);
}
/* ── 예측 영역 (Forecast) ── */
.pt-forecast {
  margin-bottom: var(--sp-1);
  padding: 3px var(--sp-1);
  background: rgba(255,255,255,0.02);
  border-radius: var(--radius);
}
.pt-forecast-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: var(--fs-micro); font-family: var(--font-mono);
  margin-bottom: 3px;
}
.pt-forecast-ret { font-weight: 700; }
.pt-forecast-ret.up { color: var(--up); }
.pt-forecast-ret.dn { color: var(--down); }
.pt-forecast-rr { color: var(--text-muted); font-size: var(--fs-nano); }
.pt-rr-bar {
  height: 3px; border-radius: 2px; overflow: hidden;
  background: rgba(80,134,220,0.25);
}
.pt-rr-reward {
  height: 100%; border-radius: 2px;
  background: rgba(150,220,200,0.7);
}
/* ── 과거 수익률 (Backtest) ── */
.pt-backtest {
  display: flex; align-items: center; gap: var(--sp-1);
  font-size: var(--fs-nano); font-family: var(--font-mono);
  color: var(--text-muted);
  padding: 2px var(--sp-1);
  margin-bottom: var(--sp-1);
  background: rgba(255,255,255,0.015);
  border-radius: var(--radius);
  border-left: 2px solid rgba(200,200,200,0.15);
}
.pt-bt-label { white-space: nowrap; }
.pt-bt-ret { font-weight: 700; white-space: nowrap; }
.pt-bt-ret.up { color: var(--up); }
.pt-bt-ret.dn { color: var(--down); }
.pt-bt-win { white-space: nowrap; color: var(--accent); }


/* ═══ 패턴 목록 (상세 팝업 내) ═══════════════════ */

#pattern-list { flex: 1; overflow-y: auto; padding: var(--sp-2); }
.pattern-empty {
  display: flex; align-items: center; justify-content: center;
  height: 60px; color: var(--text-muted); font-size: var(--fs-caption);
}

.pattern-item {
  padding: var(--sp-2); border-radius: var(--radius); margin-bottom: var(--sp-1);
  background: rgba(255,255,255,0.02); border-left: 3px solid var(--text-muted);
  transition: all var(--transition); cursor: pointer;
}
.pattern-item:hover { background: rgba(255,255,255,0.04); }
.pattern-item:active { transform: scale(0.98); }
.pattern-item.buy { border-left-color: var(--up); }
.pattern-item.sell { border-left-color: var(--down); }
.pattern-item.neutral { border-left-color: var(--neutral); }

.pattern-header { display: flex; align-items: center; gap: var(--sp-1); margin-bottom: var(--sp-1); }
.pattern-name { font-size: var(--fs-body); font-weight: 700; color: #fff; }
.pattern-signal { font-size: var(--fs-micro); padding: 2px 6px; border-radius: 3px; font-weight: 700; }
.pattern-signal.buy { background: rgba(224,80,80,0.15); color: var(--up); }
.pattern-signal.sell { background: rgba(80,134,220,0.15); color: var(--down); }
.pattern-signal.neutral { background: rgba(255,235,59,0.15); color: var(--neutral); }
.pattern-strength { font-size: var(--fs-micro); color: var(--text-muted); margin-left: auto; }
.pattern-conf {
  font-size: var(--fs-caption); font-weight: 700; font-family: var(--font-mono);
  margin-left: auto; margin-right: var(--sp-1);
  position: relative; padding-bottom: 4px;
}
.pattern-conf::after {
  content: '';
  position: absolute; bottom: 0; left: 0;
  height: 2px; border-radius: 1px;
  width: var(--conf-pct, 0%);
  background: currentColor; opacity: 0.5;
  transition: width 0.3s ease;
}
.pattern-desc { font-size: var(--fs-micro); color: var(--text-sub); line-height: 1.5; }
.pattern-risk {
  display: flex; gap: var(--sp-2); font-size: var(--fs-micro); font-family: var(--font-mono);
  color: var(--text-muted); margin-top: var(--sp-1); padding-top: var(--sp-1);
  border-top: 1px solid var(--border-subtle);
}
.pattern-risk span { white-space: nowrap; }
.confluence-badge { color: var(--neutral); font-weight: 600; }


/* ═══ 시그널 필터 드롭다운 ═══════════════════════ */

.ind-dropdown-section-title {
  font-size: var(--fs-micro); font-weight: 600; color: var(--text-muted);
  padding: var(--sp-1) var(--sp-3); letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--sp-1);
}
.sf-check { gap: 4px; }
.sf-check .sf-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
  display: inline-block;
  transition: opacity var(--transition);
}
.sf-check input[type="checkbox"]:not(:checked) + .sf-dot { opacity: 0.25; }
.sf-check input[type="checkbox"]:not(:checked) ~ span:last-child { opacity: 0.4; }


/* ═══ 패턴 요약 바 (차트 하단) ═══════════════════ */

#pattern-summary-wrap {
  flex-shrink: 0; position: relative;
}
#pattern-summary-bar {
  height: 28px;
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 0 var(--sp-3);
  background: var(--bg-element);
  border-top: 1px solid var(--border);
  font-size: var(--fs-caption);
  box-shadow: 0 -1px 0 rgba(0,0,0,0.15);
}
.psb-icon { font-size: 8px; color: var(--accent); line-height: 1; }
.psb-text {
  color: var(--text-sub); flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.psb-text .psb-count { color: var(--accent); font-weight: 700; }
.psb-text .psb-top { color: #fff; font-weight: 600; }
.psb-text .psb-conf { font-family: var(--font-mono); font-weight: 700; }
.psb-text .psb-conf.high { color: var(--up); }
.psb-text .psb-conf.mid { color: var(--accent); }
.psb-text .psb-conf.low { color: var(--down); }
.psb-detail-btn {
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); font-size: var(--fs-micro);
  padding: 2px var(--sp-2); border-radius: var(--radius);
  cursor: pointer; font-family: var(--font-sans);
  transition: all var(--transition); white-space: nowrap;
}
.psb-detail-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ── 패턴 요약 바 호버 툴팁 (작업 3) ── */
.psb-top[data-tooltip] {
  position: relative; cursor: help;
  border-bottom: 1px dotted rgba(255,255,255,0.2);
}
.psb-top[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%);
  width: max-content; max-width: 260px;
  padding: var(--sp-2) var(--sp-3);
  background: rgba(20, 20, 20, 0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-sub); font-size: var(--fs-micro);
  font-family: var(--font-sans); font-weight: 400;
  line-height: 1.6; letter-spacing: 0;
  white-space: normal; text-align: left;
  z-index: 200; pointer-events: none;
  opacity: 0; visibility: hidden;
  transition: opacity .15s, visibility .15s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6);
}
.psb-top[data-tooltip]::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 4px); left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(20, 20, 20, 0.96);
  z-index: 201; pointer-events: none;
  opacity: 0; visibility: hidden;
  transition: opacity .15s, visibility .15s;
}
.psb-top[data-tooltip]:hover::after,
.psb-top[data-tooltip]:hover::before {
  opacity: 1; visibility: visible;
}


/* ═══ 패턴 과거 수익률 바 (차트 하단) ═══════════ */

#pattern-history-bar {
  flex-shrink: 0;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-3); height: 28px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  font-size: var(--fs-caption);
  overflow-x: auto; overflow-y: hidden;
  white-space: nowrap;
}
.ph-item {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  flex-shrink: 0;
}
.ph-item + .ph-item { padding-left: var(--sp-2); border-left: 1px solid var(--border); }
.ph-name { color: var(--text); font-weight: 600; font-size: var(--fs-caption); }
.ph-count { color: var(--text-muted); font-size: var(--fs-micro); font-family: var(--font-mono); }
.ph-return { font-weight: 700; font-family: var(--font-mono); font-size: var(--fs-caption); }
.ph-return.up { color: var(--up); }
.ph-return.dn { color: var(--down); }
.ph-return.flat { color: var(--text-muted); }
.ph-winrate { color: var(--text-sub); font-size: var(--fs-micro); font-family: var(--font-mono); }


/* ═══ 패턴 상세 팝업 (요약 바 위로 펼침) ════════ */

.pattern-detail-popup {
  display: none;
  position: absolute;
  bottom: 100%; left: 0; right: 0;
  max-height: 280px;
  background: rgba(20, 20, 20, 0.96);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  z-index: 60;
  backdrop-filter: blur(12px);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.6);
  flex-direction: column; overflow: hidden;
}
.pattern-detail-popup.show { display: flex; }
.pdp-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.pdp-title {
  font-size: var(--fs-body); font-weight: 700; color: var(--accent);
}
.pdp-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 18px; cursor: pointer; line-height: 1;
  padding: 0 var(--sp-1); transition: color var(--transition);
}
.pdp-close:hover { color: var(--text); }
.pdp-body {
  flex: 1; overflow-y: auto; padding: var(--sp-2) var(--sp-3);
  max-height: 260px;
}


/* ═══ 과거 수익률 영역 (B열 하단) ════════════════ */

#return-stats-area {
  flex-shrink: 0;
  min-height: 0;
  max-height: 180px;
  border-top: 2px solid var(--border);
  background: var(--panel);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.rs-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.rs-title {
  font-size: var(--fs-caption); font-weight: 700;
  color: var(--accent); letter-spacing: 0.03em;
}
.rs-period-tabs {
  display: flex; gap: 2px;
}
.rs-tab {
  background: transparent;
  border: 1px solid transparent; border-radius: var(--radius);
  padding: 2px var(--sp-2); color: var(--text-muted);
  font-size: var(--fs-micro); font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer; transition: all var(--transition);
}
.rs-tab:hover { color: var(--text); background: var(--bg-elevated); }
.rs-tab.active {
  color: var(--accent);
  background: rgba(160,136,48,0.12);
  border-color: rgba(160,136,48,0.3);
}

.rs-body {
  flex: 1; padding: var(--sp-2) var(--sp-3);
  overflow-y: auto; overflow-x: hidden;
}

.rs-grid {
  display: flex; flex-direction: column; gap: var(--sp-1);
}
.rs-row {
  display: grid;
  grid-template-columns: 80px 1fr 56px 50px 40px;
  align-items: center; gap: var(--sp-2);
  height: 24px;
}
.rs-pattern-name {
  font-size: var(--fs-caption); font-weight: 600;
  color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rs-bar-wrap {
  height: 14px; background: var(--bg-element);
  border-radius: 2px; overflow: hidden; position: relative;
}
.rs-bar {
  height: 100%; border-radius: 2px;
  transition: width 0.4s ease; min-width: 2px;
}
.rs-bar.up { background: var(--up); opacity: 0.7; }
.rs-bar.dn { background: var(--down); opacity: 0.7; }
.rs-return {
  font-family: var(--font-mono); font-size: var(--fs-caption);
  font-weight: 700; text-align: right;
}
.rs-return.up { color: var(--up); }
.rs-return.dn { color: var(--down); }
.rs-winrate {
  font-family: var(--font-mono); font-size: var(--fs-nano);
  color: var(--text-sub); text-align: right;
}
.rs-count {
  font-family: var(--font-mono); font-size: var(--fs-nano);
  color: var(--text-muted); text-align: right;
}

.rs-footer {
  padding: var(--sp-1) var(--sp-3);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.rs-note {
  font-size: 9px; color: var(--text-muted); font-style: italic;
}

/* ── 백테스트 수익률 테이블 ── */
.php-table {
  width: 100%; border-collapse: collapse;
  margin-top: var(--sp-2);
  font-size: var(--fs-micro); font-family: var(--font-mono);
  font-feature-settings: "tnum";
}
.php-table thead {
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--panel);
  z-index: 1;
}
.php-table th {
  color: var(--text-muted); font-weight: 600;
  text-align: center; padding: 5px 3px;
  font-size: var(--fs-nano); letter-spacing: 0.02em;
  white-space: nowrap;
  font-family: var(--font-sans);
}
.php-th-name { text-align: left !important; min-width: 56px; }
.php-th-count { min-width: 24px; }
.php-table td {
  text-align: center; padding: 5px 3px;
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--transition);
}
.php-table tbody tr:hover td {
  background: rgba(255,255,255,0.03);
}
.php-name {
  text-align: left !important; font-weight: 600;
  font-family: var(--font-sans); font-size: var(--fs-caption);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 72px;
}
.php-name.up { color: var(--up); }
.php-name.dn { color: var(--down); }
.php-count {
  color: var(--text-muted); font-size: var(--fs-nano);
}
.php-ret {
  font-weight: 600;
  font-feature-settings: "tnum";
}
.php-ret.up { color: var(--up); }
.php-ret.dn { color: var(--down); }
.php-ret.php-sig {
  font-weight: 800;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 2px;
}
.php-ret.php-sig.up { text-decoration-color: var(--up); }
.php-ret.php-sig.dn { text-decoration-color: var(--down); }
.php-wr {
  font-weight: 600;
  font-feature-settings: "tnum";
}
.php-wr.up { color: var(--up); }
.php-wr.dn { color: var(--down); }

/* WLS 기대수익 + 신뢰구간 열 */
.php-expected {
  font-weight: 600; font-size: var(--fs-nano);
}
.php-expected.up { color: var(--up); }
.php-expected.dn { color: var(--down); }
.php-ci {
  font-size: 9px; color: var(--text-muted);
  white-space: nowrap; letter-spacing: -0.3px;
}
/* 95% CI가 0을 포함 → 통계적 비유의: muted + italic */
.php-ci-muted { color: var(--text-muted); font-style: italic; opacity: 0.6; }

/* 백테스트 진입 시점 안내 텍스트 */
.php-entry-note {
  font-size: 9px; color: var(--text-muted); opacity: 0.5;
  text-align: right; padding: 2px 4px 0; margin-bottom: 2px;
}

/* 표본 부족 경고 아이콘 (테이블 행 내) */
.php-sample-warn {
  display: inline-block; margin-left: 2px;
  font-size: 9px; vertical-align: super;
  color: var(--neutral); cursor: help;
}

/* ── 누적수익률 곡선 캔버스 ── */
.php-curve-wrap {
  margin-top: var(--sp-2);
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--sp-1);
}
.php-curve-wrap canvas {
  display: block; width: 100%;
}


/* ═══ OHLC 바 ════════════════════════════════════ */

#ohlc-bar {
  position: absolute; top: var(--sp-2); left: var(--sp-2); z-index: 20;
  display: flex; align-items: center; gap: 3px;
  font-family: var(--font-mono); font-size: var(--fs-body);
  pointer-events: none;
  background: rgba(19,23,34,0.92);
  padding: var(--sp-1) var(--sp-3); border-radius: var(--radius);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(42,46,57,0.3);
  line-height: 1.4;
}
.ohlc-label {
  color: var(--text-muted); font-weight: 700; margin-left: var(--sp-2);
  letter-spacing: 0.03em; font-size: var(--fs-caption);
}
.ohlc-label:first-child { margin-left: 0; }
#ohlc-bar .ohlc-label:nth-child(9) { margin-left: var(--sp-3); }
.ohlc-val { color: var(--text); font-weight: 700; letter-spacing: -0.02em; margin-left: 2px; }
.ohlc-val.up { color: var(--up); }
.ohlc-val.dn { color: var(--down); }
.ohlc-key { color: var(--text-muted); font-size: var(--fs-micro); font-weight: 500; }
/* RSI/MACD 값 앞에 구분 간격 */
#ohlc-rsi, #ohlc-macd { margin-left: var(--sp-3); }

/* ═══ 스크린샷 버튼 ════════════════════════════════ */
.sh-action-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition);
  flex-shrink: 0;
  line-height: 1;
}
.sh-action-btn:hover {
  color: var(--text);
  background: var(--border);
  border-color: var(--accent);
}


/* ═══ 라이브 상태 ════════════════════════════════ */

.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0;  /* flex 컨텍스트에서 vertical-align/display:inline-block 불필요 */
}
.live-dot.live { background: #4caf50; box-shadow: 0 0 6px rgba(76,175,80,0.6); animation: livePulse 2s infinite; }
.live-dot.ws { background: #00bcd4; box-shadow: 0 0 6px rgba(0,188,212,0.6); animation: livePulse 2s infinite; }
.live-dot.file { background: #8bc34a; }
.live-dot.demo { background: #ff9800; }
.live-dot.offline { background: #f44336; }
@keyframes livePulse { 0%,100% { opacity:1; } 50% { opacity:0.4; } }
.live-label {
  font-size: var(--fs-micro); font-weight: 700; letter-spacing: .5px;
  margin-left: 2px; vertical-align: middle; line-height: 1;
}
.live-label.live { color: #4caf50; }
.live-label.ws { color: #00bcd4; }
.live-label.file { color: #8bc34a; }
.live-label.demo { color: #ff9800; }
.live-label.offline { color: #f44336; }

/* 데이터 수신 시각 표시 */
.data-freshness {
  font-size: var(--fs-nano); color: var(--text-muted);
  font-family: var(--font-mono); line-height: 1;
  /* margin-left 제거 — 부모 .sh-identity의 gap이 간격 처리 */
}

/* ═══ 로딩 Shimmer 피드백 ════════════════════════ */

@keyframes shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

.chart-loading {
  position: relative; pointer-events: none;
}
.chart-loading::after {
  content: '';
  position: absolute; inset: 0; z-index: 50;
  background: linear-gradient(
    90deg,
    var(--bg-element) 0%,
    var(--bg-elevated) 40%,
    var(--bg-element) 80%
  );
  background-size: 800px 100%;
  animation: shimmer 1.5s infinite linear;
  border-radius: var(--radius); opacity: 0.7;
}
.chart-loading::before {
  content: '데이터 로딩 중...';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 51;
  color: var(--text-muted); font-size: var(--fs-body);
  font-family: var(--font-sans); font-weight: 600;
  letter-spacing: 0.05em;
}


/* ═══ 가격 변화 Flash 애니메이션 ═════════════════ */

@keyframes priceFlashUp {
  0%   { background-color: rgba(224, 80, 80, 0.35); }
  100% { background-color: transparent; }
}
@keyframes priceFlashDown {
  0%   { background-color: rgba(80, 134, 220, 0.35); }
  100% { background-color: transparent; }
}
.price-flash-up {
  animation: priceFlashUp 0.6s ease-out;
  border-radius: var(--radius);
}
.price-flash-down {
  animation: priceFlashDown 0.6s ease-out;
  border-radius: var(--radius);
}
/* (sb-price flash은 사이드바 섹션에서 정의됨) */


/* ═══ Tabular Figures 전역 적용 ═══════════════════
   모든 숫자 데이터에 고정폭 숫자를 적용하여
   열 정렬이 흐트러지지 않도록 합니다.
   Pretendard & JetBrains Mono 모두 tnum 지원.
   ════════════════════════════════════════════════ */

.fin-row-value, .fin-grid-value,
.sh-price, .sb-price, .sb-change,
.php-ret, .php-wr, .php-count, .php-expected, .php-ci,
.ohlc-val, .sh-detail-value,
.rs-return, .rs-winrate, .rs-count,
.ticker-val,
.ph-return, .ph-count, .ph-winrate {
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}


/* ═══ 패턴 그룹 헤더 (사이드바 패턴별 정렬) ═══════
   sb-sort-select value="pattern" 선택 시
   sidebar.js가 패턴 타입별 그룹으로 종목을 묶음.
   ════════════════════════════════════════════════ */

.sb-pattern-group {
  padding: var(--sp-1) 0;
}
.sb-pattern-group + .sb-pattern-group {
  border-top: 1px solid var(--border-subtle);
}
.sb-pattern-group-header {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--fs-nano); font-weight: 700;
  color: var(--accent); letter-spacing: 0.04em;
  text-transform: uppercase;
}
.sb-pattern-group-header::before {
  content: ''; width: 3px; height: 12px;
  border-radius: 2px; background: var(--accent);
  flex-shrink: 0;
}
.sb-pattern-group-count {
  font-family: var(--font-mono); font-size: var(--fs-nano);
  color: var(--text-muted); font-weight: 400;
  margin-left: auto;
}

/* 종목 옆 작은 패턴 pill (패턴별 정렬 모드) */
.sb-pattern-badge {
  display: inline-flex; align-items: center;
  font-size: var(--fs-nano); font-weight: 700;
  padding: 1px 4px; border-radius: 2px;
  letter-spacing: 0.04em; text-transform: uppercase;
  line-height: 1.4; flex-shrink: 0;
  white-space: nowrap;
}
.sb-pattern-badge.buy {
  background: rgba(224,80,80,0.12);
  color: var(--up);
}
.sb-pattern-badge.sell {
  background: rgba(80,134,220,0.12);
  color: var(--down);
}
.sb-pattern-badge.neutral {
  background: rgba(255,235,59,0.10);
  color: var(--neutral);
}

/* ── 패턴 카테고리 pill (캔들/지표/거래량) ── */
.sb-cat-pills {
  display: inline-flex; align-items: center;
  gap: 2px; margin-left: 4px;
  vertical-align: middle;
  flex-shrink: 0;
}
.sb-cat-pill {
  display: inline-flex; align-items: center;
  font-size: var(--fs-nano); font-weight: 700;
  padding: 1px 4px; border-radius: 3px;
  line-height: 1.5; white-space: nowrap;
  letter-spacing: -0.02em;
}
.sb-cat-pill.candle {
  background: rgba(224,80,80,0.15);
  color: var(--up);
}
.sb-cat-pill.indicator {
  background: rgba(160,136,48,0.15);
  color: var(--accent);
}
.sb-cat-pill.volume {
  background: rgba(80,134,220,0.15);
  color: var(--down);
}

/* 패턴 모드에서 sb-name 폭 유연하게 (pill 공간 확보) */
.sb-item.has-pattern .sb-name {
  display: inline-flex; align-items: center;
  max-width: none;
}

/* (패턴별 정렬 — 드롭다운으로 전환됨, 서브필터 제거) */


/* ═══ 수익률 바 차트 (승률 가로 바) ════════════════
   rs-grid 내 각 패턴 행에서 승률을 시각적 바로 표현.
   rs-bar-wrap > rs-bar > rs-bar-fill 3단 구조.
   ════════════════════════════════════════════════ */

.rs-bar-fill {
  height: 100%; border-radius: 2px;
  min-width: 1px;
  transition: width 0.5s cubic-bezier(0.22,1,0.36,1);
}
.rs-bar-fill.up {
  background: linear-gradient(90deg, rgba(224,80,80,0.5), var(--up));
}
.rs-bar-fill.dn {
  background: linear-gradient(90deg, rgba(80,134,220,0.5), var(--down));
}
.rs-bar-fill.neutral {
  background: linear-gradient(90deg, rgba(255,235,59,0.3), var(--neutral));
}

/* 바 안에 퍼센트 라벨 (선택적 — JS에서 생성 시) */
.rs-bar-label {
  position: absolute; right: 3px; top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono); font-size: 7px;
  font-weight: 700; color: rgba(255,255,255,0.7);
  line-height: 1; pointer-events: none;
  font-feature-settings: "tnum";
}


/* ═══ 스크롤바 (최소화) ═════════════════════════ */

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #333; }


/* ═══ 워치리스트 (즐겨찾기) ═══════════════════════ */

.watchlist-star {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; min-height: 28px;
  background: none; border: none; color: var(--text-sub);
  font-size: 18px; cursor: pointer; padding: 2px 6px;
  transition: color 0.15s, transform 0.15s;
  line-height: 1;
}
.watchlist-star:hover { color: var(--accent); transform: scale(1.2); }
.watchlist-star.active { color: var(--accent); }


/* ═══ 지표 파라미터 팝업 ═══════════════════════════ */

.ind-param-popup {
  position: fixed; z-index: 1000;
  background: var(--bg-element, #1E1E1E); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; min-width: 180px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.ind-param-title {
  font-size: var(--fs-caption); font-weight: 600; color: var(--text);
  margin-bottom: 8px; border-bottom: 1px solid var(--border); padding-bottom: 4px;
}
.ind-param-row { display: flex; align-items: center; justify-content: space-between; margin: 4px 0; }
.ind-param-row label { font-size: var(--fs-micro); color: var(--text-sub); }
.ind-param-row input {
  width: 50px; padding: 2px 6px; font-size: var(--fs-micro);
  background: var(--bg-elevated, #282828); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px; text-align: right;
  font-family: var(--font-mono);
}
.ind-param-row input:focus { border-color: var(--accent); outline: none; }
.ind-param-actions { display: flex; gap: 6px; margin-top: 8px; }
.ind-param-btn {
  flex: 1; padding: 4px 8px; font-size: var(--fs-micro);
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg-elevated, #282828); color: var(--text-sub); cursor: pointer;
}
.ind-param-btn.primary { background: var(--accent); color: #000; border-color: var(--accent); }
.ind-param-btn:hover { opacity: 0.8; }
.ind-btn.param-custom { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; }

/* 지표 체크박스 라벨에 커스텀 표시 */
.ind-check.param-custom { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; }


/* ═══ 반응형 4단계 ══════════════════════════════ */

/* ── 1440px: D열 축소, 패턴 패널 축소 ── */
@media (max-width: 1440px) {
  :root {
    --rpanel-w: 340px;
    --pattern-panel-w: 220px;
  }
  .fin-info::after { max-width: 160px; }
}

/* ── 1366px: 중간 해상도 (노트북) ── */
@media (max-width: 1366px) {
  :root {
    --sidebar-w: 220px;
    --pattern-panel-w: 210px;
    --rpanel-w: 300px;
  }
}

/* ── 1200px: 사이드바 축소, 패턴/재무 패널 축소 ── */
@media (max-width: 1200px) {
  :root {
    --sidebar-w: 200px;
    --rpanel-w: 280px;
    --pattern-panel-w: 200px;
  }
  .sb-index-val { display: none; }
  .sb-sort-select { font-size: var(--fs-nano); }
  .sh-details { gap: var(--sp-1); }
  .sh-detail-item { min-width: 60px; padding: 3px var(--sp-1); }
  #fin-trend-canvas { height: 60px; }
  .fin-trend-body { max-height: 80px; }
  .fin-info::after { max-width: 150px; }
  .pp-card-desc { -webkit-line-clamp: 2; }
  .pp-card-psych { display: none; }
  .pp-card-invalid { display: none; }
  .pp-card { padding: var(--sp-2); }

  /* C열: 그리드에서 빠져 오버레이 슬라이드 패널로 전환 */
  #main {
    grid-template-columns:
      minmax(0, var(--sidebar-w))
      minmax(360px, 1fr)
      0px
      minmax(240px, var(--rpanel-w));
  }
  #main.sidebar-collapsed {
    grid-template-columns:
      var(--sidebar-collapsed)
      minmax(360px, 1fr)
      0px
      minmax(240px, var(--rpanel-w));
  }

  #pattern-panel {
    position: fixed;
    top: var(--header-h);
    right: 0;
    width: min(280px, 80vw);
    height: calc(100vh - var(--header-h));
    z-index: 90;
    transform: translateX(100%);
    transition: transform .25s ease, box-shadow .25s ease;
    box-shadow: none;
    border-left: 1px solid var(--border);
  }
  #pattern-panel.pp-visible {
    transform: translateX(0);
    box-shadow: -4px 0 20px rgba(0,0,0,0.5);
  }

  /* 패널 토글 버튼 표시 */
  #pp-toggle { display: flex; }
}

/* ── 1024px: 사이드바 접힘 ── */
@media (max-width: 1024px) {
  #main {
    grid-template-columns: 0px 1fr 0px minmax(180px, 240px);
    min-width: 0;
  }
  #sidebar { width: 0; border-right: none; }

  .ticker-item:last-child { display: none; }
  .sh-details { display: none; }
  /* [FIX] 추이 차트: 완전 숨김 대신 축소 표시 */
  .fin-trend-section { max-height: 100px; overflow: hidden; }
  .fin-trend-section .fin-trend-tabs { font-size: var(--fs-nano); }
  .fin-grid { grid-template-columns: 1fr 1fr; }  /* 180px 패널에서 3열→2열 */
  #return-stats-area { display: none; }
}

/* ── 768px: 모바일 — 사이드바 드로어, D열 바텀시트 ── */
@media (max-width: 768px) {
  /* 모바일: 드로잉 툴바 + 색상 선택기 숨김, 여백 제거 */
  .draw-toolbar { display: none; }
  .draw-color-picker { display: none !important; }
  #main-chart-container { margin-left: 0 !important; }
  #chart-wrap .sub-chart-wrap { margin-left: 0; }
  #chart-wrap #ohlc-bar { left: var(--sp-2); }
  #chart-wrap #pattern-summary-wrap { margin-left: 0; }
  #chart-wrap #pattern-history-bar { margin-left: 0; }
  #chart-wrap .sub-chart-label { left: var(--sp-2); }  /* 툴바 숨김 시 라벨 위치 복원 */

  #main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    min-width: 320px;
  }

  /* ── A열: 사이드바 → 좌측 드로어 오버레이 ── */
  #sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    width: min(280px, 80vw);
    height: calc(100vh - var(--header-h));
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .25s ease, box-shadow .25s ease;
    box-shadow: none;
    border-right: 1px solid var(--border);
    overflow-y: auto;
  }
  #sidebar.sb-drawer-open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
  /* 사이드바 열릴 때 grid-template에 의한 width:0 무시 */
  #main.sidebar-collapsed #sidebar {
    width: min(280px, 80vw);
    border-right: 1px solid var(--border);
  }

  /* 사이드바 백드롭 */
  #sb-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-h);
    z-index: 199;
    background: rgba(0,0,0,0.4);
    opacity: 0;
    transition: opacity .25s ease;
  }
  #sb-backdrop.sb-bd-visible {
    display: block;
    opacity: 1;
  }

  /* ── D열: 바텀시트 오버레이 ── */
  #right-panel {
    display: flex !important;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: min(60vh, 480px);
    z-index: 190;
    transform: translateY(100%);
    transition: transform .3s ease, box-shadow .3s ease;
    box-shadow: none;
    border-top: 1px solid var(--border);
    border-left: none;
    border-radius: 12px 12px 0 0;
    overflow-y: auto;
  }
  #right-panel.rp-sheet-open {
    transform: translateY(0);
    box-shadow: 0 -4px 24px rgba(0,0,0,0.5);
  }

  /* 바텀시트 핸들 바 (시각적 그립) */
  #right-panel::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: var(--text-muted);
    border-radius: 2px;
    margin: var(--sp-2) auto var(--sp-1);
    opacity: 0.5;
    flex-shrink: 0;
  }

  /* 바텀시트 백드롭 */
  #rp-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 189;
    background: rgba(0,0,0,0.35);
    opacity: 0;
    transition: opacity .25s ease;
  }
  #rp-backdrop.rp-bd-visible {
    display: block;
    opacity: 1;
  }

  /* 재무지표 토글 버튼 (모바일 전용) */
  #fin-toggle {
    display: flex;
  }

  /* ── B열: 차트 전체 너비 ── */
  .sh-price { font-size: var(--fs-display); }
  .sh-name { font-size: var(--fs-title); }
  #stock-header { min-height: 40px; padding: var(--sp-2) var(--sp-3); }
  .sh-details { display: none; }

  /* 툴바: 가로 스크롤 (wrap 대신) */
  #chart-toolbar {
    overflow-x: auto; overflow-y: hidden;
    flex-wrap: nowrap;
    height: var(--toolbar-h);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;            /* Firefox */
  }
  #chart-toolbar::-webkit-scrollbar { display: none; }

  /* 타임프레임 버튼 간격 축소 */
  .tf-btn { padding: var(--sp-1) 6px; font-size: var(--fs-micro); }
  .ct-btn { padding: var(--sp-1) 6px; font-size: var(--fs-micro); }

  #ticker-strip { gap: var(--sp-2); }
  .ticker-val { font-size: var(--fs-caption); }
  .sub-chart { height: 70px; }
  #main-chart-container { min-height: 180px; }

  /* 헤더 로고 축소 */
  #logo { font-size: var(--fs-body); letter-spacing: 1px; }

  /* 검색 바 축소 */
  #search-wrap { min-width: 80px; }
}

/* ── 480px: 초소형 모바일 ── */
@media (max-width: 480px) {
  #ticker-strip { display: none; }
  #search-wrap { max-width: none; flex: 1; }
  #logo { display: none; }
  .tf-btn { padding: var(--sp-1) 4px; }
  #stock-header { gap: var(--sp-1); }
  .sh-price { font-size: var(--fs-heading); }
  .sh-change { font-size: var(--fs-caption); }
}

/* ── 재무지표 토글 버튼: 데스크톱에서 숨김 ── */
#fin-toggle {
  display: none;
  position: fixed;
  bottom: var(--sp-3);
  right: var(--sp-3);
  z-index: 191;
  width: 44px; height: 44px;
  align-items: center; justify-content: center;
  background: var(--accent);
  color: #0A0A0A;
  border: none;
  border-radius: 50%;
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(160,136,48,0.4);
  transition: transform var(--transition), background var(--transition);
}
#fin-toggle:hover { transform: scale(1.1); }
#fin-toggle:active { transform: scale(0.95); }
#fin-toggle.rp-open {
  background: var(--text-muted);
  color: var(--bg);
}

/* ── 사이드바/재무 백드롭: 데스크톱에서 숨김 ── */
#sb-backdrop, #rp-backdrop {
  display: none;
}

/* ── 세로가 약간 짧은 화면 (소형 노트북) ── */
@media (max-height: 800px) {
  #stock-header { min-height: 36px; padding: 2px var(--sp-3); }
  .sub-chart { height: clamp(45px, 7vh, 70px); }
  #return-stats-area { max-height: 120px; }
}

/* ── 세로가 짧은 화면 (가로로 긴 모니터) ── */
@media (max-height: 700px) {
  #stock-header { min-height: 36px; padding: 2px var(--sp-3); }
  .sh-price { font-size: var(--fs-heading); }
  .sh-details { display: none; }
  .sub-chart { height: 60px; }
  #main-chart-container { min-height: 160px; }
  .rp-header { padding: var(--sp-1) var(--sp-2); }
  .pp-header { padding: var(--sp-1) var(--sp-2); }
  .fin-grid { grid-template-columns: 1fr 1fr 1fr; gap: 2px; }
  .fin-grid-item { padding: 2px var(--sp-1); }
  .fin-section-title { margin-top: var(--sp-1); margin-bottom: 2px; }
}

/* ── 세로가 매우 긴 화면 (세로 모니터) ── */
@media (min-height: 1200px) {
  #main-chart-container { min-height: 400px; }
  .sub-chart { height: 120px; }
}

/* ── 가로가 매우 넓은 화면 (울트라와이드) ── */
@media (min-width: 2000px) {
  :root {
    --sidebar-w: 240px;
    --rpanel-w: 420px;
    --pattern-panel-w: 300px;
  }
  /* sb-name은 flex:1로 자동 조절되므로 max-width 불필요 */
  #main-chart-container { min-height: 400px; }
}

/* ═══════════════════════════════════════════════════
   TOAST 알림
   ═══════════════════════════════════════════════════ */

#toast-container {
  position: fixed;
  bottom: var(--sp-5);
  right: var(--sp-5);
  z-index: 10000;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 240px;
  max-width: 380px;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-caption);
  line-height: 1.4;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  animation: toastSlideIn 0.3s ease-out;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.toast-dismiss {
  opacity: 0;
  transform: translateX(20px);
}

.toast-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

/* 타입별 좌측 보더 + 아이콘 색상 */
.toast.toast-info    { border-left: 3px solid var(--down); }
.toast.toast-success { border-left: 3px solid var(--accent); }
.toast.toast-warning { border-left: 3px solid var(--neutral); }
.toast.toast-error   { border-left: 3px solid var(--up); }

.toast.toast-info    .toast-icon { background: var(--down);    color: #fff; }
.toast.toast-success .toast-icon { background: var(--accent);  color: #0A0A0A; }
.toast.toast-warning .toast-icon { background: var(--neutral); color: #0A0A0A; }
.toast.toast-error   .toast-icon { background: var(--up);      color: #fff; }

.toast-msg {
  flex: 1;
  word-break: keep-all;
}

.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: var(--fs-title);
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  transition: color var(--transition);
}
.toast-close:hover { color: var(--text); }

@keyframes toastSlideIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}


/* ═══ 온보딩 툴팁 투어 (5단계) ═══════════════════════ */

/* 반투명 오버레이 — pointer-events:none으로 앱 사용 차단 안 함 */
.onboarding-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 9998;
  pointer-events: none;
  animation: obFadeIn .3s ease;
}

/* 하이라이트된 요소: 오버레이 위로 올라오며 골드 글로우 */
.onboarding-highlight {
  position: relative;
  z-index: 9999 !important;
  box-shadow:
    0 0 0 3px rgba(160, 136, 48, 0.55),
    0 0 16px rgba(160, 136, 48, 0.25);
  border-radius: 4px;
  pointer-events: auto;
  transition: box-shadow .25s ease;
}

/* 툴팁 카드 */
.onboarding-tooltip {
  position: fixed;
  z-index: 10000;
  background: var(--bg-element, #1E1E1E);
  border: 1px solid var(--accent, #A08830);
  border-radius: 8px;
  padding: 16px;
  max-width: 280px;
  width: max-content;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  animation: obSlideIn .25s ease;
  font-family: var(--font-sans, 'Pretendard', sans-serif);
}

/* 툴팁 화살표 (CSS triangle) */
.onboarding-tooltip::before {
  content: '';
  position: absolute;
  width: 10px; height: 10px;
  background: var(--bg-element, #1E1E1E);
  border: 1px solid var(--accent, #A08830);
  transform: rotate(45deg);
}

/* 화살표 위치 변형 */
.onboarding-tooltip[data-pos="right"]::before {
  left: -6px; top: 20px;
  border-right: none; border-top: none;
}
.onboarding-tooltip[data-pos="bottom"]::before {
  top: -6px; left: 24px;
  border-bottom: none; border-right: none;
}
.onboarding-tooltip[data-pos="left"]::before {
  right: -6px; top: 20px;
  border-left: none; border-bottom: none;
}
.onboarding-tooltip[data-pos="center"]::before {
  display: none; /* 중앙 배치 시 화살표 숨김 */
}

.ob-text {
  color: var(--text, #E0E0E0);
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 12px;
}

.ob-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ob-counter {
  color: var(--text-muted, #808080);
  font-size: 11px;
  font-family: var(--font-mono, monospace);
}

.ob-skip {
  background: none;
  border: none;
  color: var(--text-muted, #808080);
  cursor: pointer;
  font-size: 11px;
  margin-left: auto;
  padding: 4px 8px;
  font-family: var(--font-sans, sans-serif);
  transition: color .15s;
}
.ob-skip:hover { color: var(--text-sub, #A0A0A0); }

.ob-next {
  padding: 6px 16px;
  background: var(--accent, #A08830);
  color: #0A0A0A;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans, sans-serif);
  transition: opacity .15s, transform .1s;
}
.ob-next:hover { opacity: 0.9; }
.ob-next:active { transform: scale(0.97); }

/* 진행 바 (스텝 하단) */
.ob-progress {
  display: flex;
  gap: 4px;
  margin-top: 10px;
}
.ob-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border, #252525);
  transition: background .2s;
}
.ob-dot.active {
  background: var(--accent, #A08830);
}
.ob-dot.done {
  background: rgba(160, 136, 48, 0.4);
}

@keyframes obFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes obSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* (기술적 등급 게이지 CSS — 전체 제거됨) */


/* ═══ 앱 로딩 오버레이 ═══ */
.app-loading-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-main, #0A0A0A);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  transition: opacity 0.4s ease-out;
}
.app-loading-overlay.fade-out {
  opacity: 0; pointer-events: none;
}
.app-loading-overlay.hidden { display: none; }
.app-loading-content { text-align: center; }
.app-loading-spinner {
  width: 40px; height: 40px; margin: 0 auto 16px;
  border: 3px solid rgba(160,136,48,0.2);
  border-top-color: #A08830;
  border-radius: 50%;
  animation: loadingSpin 0.8s linear infinite;
}
@keyframes loadingSpin { to { transform: rotate(360deg); } }
.app-loading-text {
  font-size: 18px; font-weight: 600; color: var(--text, #E0E0E0);
  font-family: var(--font-main, 'Pretendard', sans-serif);
  margin-bottom: 8px;
}
.app-loading-sub {
  font-size: 12px; color: var(--text-muted, #707070);
  font-family: var(--font-main, 'Pretendard', sans-serif);
}


/* ═══ 연결 설정 버튼 ══════════════════════════════ */
.conn-settings-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 14px; cursor: pointer; padding: 2px 4px;
  transition: color 0.15s;
}
.conn-settings-btn:hover { color: var(--accent); }

/* ═══ 연결 설정 드롭다운 패널 ═════════════════════ */
.conn-panel {
  position: absolute; top: calc(100% + 4px); right: 0;
  background: var(--bg-elevated, #1E1E1E); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; min-width: 280px; z-index: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.conn-panel-title {
  font-size: var(--fs-caption); font-weight: 600; color: var(--text);
  margin-bottom: 8px; padding-bottom: 4px; border-bottom: 1px solid var(--border);
}
.conn-label { font-size: var(--fs-micro); color: var(--text-sub); margin-bottom: 4px; display: block; }
.conn-panel-row, .conn-guide-row { display: flex; gap: 6px; margin-bottom: 8px; }
.conn-input {
  flex: 1; padding: 6px 8px; font-size: var(--fs-caption);
  background: var(--bg-element, #282828); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  font-family: var(--font-mono);
}
.conn-input:focus { border-color: var(--accent); outline: none; }
.conn-btn {
  padding: 6px 12px; font-size: var(--fs-caption); border-radius: 4px;
  cursor: pointer; border: 1px solid var(--border); white-space: nowrap;
  transition: opacity 0.15s;
}
.conn-btn:hover { opacity: 0.8; }
.conn-btn.primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.conn-btn.secondary { background: var(--bg-element, #282828); color: var(--text-sub); }
.conn-panel-status { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; font-size: var(--fs-micro); }
.conn-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.conn-dot.ok { background: #4caf50; }
.conn-dot.pending { background: #ff9800; }
.conn-dot.fail { background: #f44336; }
.conn-panel-modes { display: flex; gap: 6px; }

/* ═══ 연결 가이드 (로딩 오버레이 내) ═════════════ */
.conn-guide { text-align: center; max-width: 360px; margin-top: 24px; }
.conn-guide-title { font-size: 16px; font-weight: 600; color: var(--text, #E0E0E0); margin-bottom: 16px; }
.conn-guide-row { justify-content: center; }
.conn-guide-row .conn-input { max-width: 220px; }
.conn-guide-or { color: var(--text-muted, #707070); font-size: 11px; margin: 12px 0; }
.conn-guide-alts { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }
.conn-guide-help {
  text-align: left; font-size: 11px; color: var(--text-muted, #707070);
  background: rgba(255,255,255,0.03); border-radius: 6px; padding: 10px 14px;
}
.conn-guide-help p { margin: 4px 0; }
.conn-guide-help code { color: var(--accent, #A08830); font-family: var(--font-mono); }

/* ═══ TradingView 출처 표기 ═══════════════════════ */

.tv-attribution {
  position: fixed; bottom: 4px; left: 50%; transform: translateX(-50%);
  font-size: 9px; color: var(--text-muted); opacity: 0.4; z-index: 1;
  pointer-events: auto; white-space: nowrap;
}
.tv-attribution a { color: var(--text-muted); text-decoration: none; }
.tv-attribution a:hover { color: var(--text-sub); }

/* ═══ 접근성: prefers-reduced-motion ═════════════ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
