:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3350;
  --accent: #4f8ef7;
  --accent-hover: #3a7af5;
  --danger: #e05252;
  --success: #4caf85;
  --text: #e2e6f0;
  --text-muted: #7a82a0;
  --font: 'Pretendard', 'Noto Sans KR', sans-serif;
  --header-h: 52px;
  --chart-header-h: 46px;
}

/* ── 스크롤바 ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
::-webkit-scrollbar-corner { background: transparent; }
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Header ── */
header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  z-index: 10;
}
header h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }

/* ── Workspace: 좌/우 분할 ── */
#workspace {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── 좌측 패널 ── */
#left-panel {
  width: 320px;
  min-width: 240px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 16px;
  border-right: 1px solid var(--border);
}

/* ── 중간 패널 ── */
#middle-panel {
  width: 260px;
  min-width: 180px;
  max-width: 600px;
  flex-shrink: 0;
  overflow: hidden;
  padding: 0;
  border-right: 1px solid var(--border);
  display: none;
  flex-direction: column;
}
#middle-panel.open { display: flex; }

.mp-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}
.mp-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 0;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.mp-tab:hover { color: var(--text); }
.mp-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.mp-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 4px 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.mp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.mp-title { font-size: 14px; font-weight: 700; }
.mp-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 18px; cursor: pointer; padding: 0 4px; line-height: 1;
}
.mp-close:hover { color: var(--text); }
.mp-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
}
#result-card-content {
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
#result-card-content > #result-info { flex-shrink: 0; }
#result-card-content > .table-wrap {
  flex: 1;
  min-height: 0;
  max-height: none;
}
#panel-resizer-2 {
  width: 1px;
  flex-shrink: 0;
  cursor: col-resize;
  background: var(--border);
  transition: background 0.15s;
  position: relative;
  z-index: 5;
  display: none;
}
#panel-resizer-2::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: -3px; right: -3px;
  cursor: col-resize;
}
#middle-panel.open ~ #panel-resizer-2 { display: block; }
#panel-resizer-2:hover,
#panel-resizer-2:active {
  background: var(--accent);
}

/* ── 관심종목 ── */
.wl-empty { font-size: 12px; color: var(--text-muted); padding: 6px 0; }

.wl-folder { margin-bottom: 6px; }

.wl-folder-hd {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 4px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.wl-folder-hd:hover { background: var(--surface2); }

.wl-arrow { font-size: 9px; color: var(--text-muted); width: 10px; flex-shrink: 0; }
.wl-fname { font-size: 13px; font-weight: 600; flex: 1; }

.wl-folder-bd {
  padding-left: 10px;
  border-left: 2px solid var(--border);
  margin: 3px 0 4px 7px;
}

.wl-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 4px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.1s;
}
.wl-item:hover { background: var(--surface2); }

/* ── 폴더 선택 팝업 ── */
#folder-picker {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 160px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
#folder-picker.open { display: block; }

.fp-empty { font-size: 12px; color: var(--text-muted); padding: 6px 8px; }
.fp-sep { height: 1px; background: var(--border); margin: 4px 0; }

.fp-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  padding: 6px 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.1s;
}
.fp-item:hover  { background: var(--border); }
.fp-item.fp-exists { color: var(--text-muted); cursor: default; }
.fp-item.fp-new { color: var(--accent); }

/* ── 조건 추가 드롭다운 ── */
.add-cond-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 150px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.add-cond-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  padding: 7px 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.1s;
}
.add-cond-item:hover { background: var(--border); }
.add-ind-item {
  display: block; width: 100%; background: none; border: none;
  color: var(--text); padding: 5px 10px; text-align: left;
  cursor: pointer; border-radius: 4px; font-size: 12px; white-space: nowrap;
}
.add-ind-item:hover { background: var(--border); }

/* ── 범위 필터 행 ── */
.range-row { gap: 6px; }
.range-field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  padding: 0 4px;
}
/* 브라우저 기본 number 스피너 제거 (다크 테마와 불일치) */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

.range-input {
  width: 56px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 5px;
  font-size: 11px;
}
.range-sep {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── 오프셋 입력 ── */
.offset-wrap {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: 4px;
}
.tf-toggle {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.tf-toggle.tf-weekly {
  border-color: var(--accent);
  color: var(--accent);
}
.offset-input {
  width: 34px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 4px;
  font-size: 12px;
  text-align: center;
}
.offset-label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── 프리셋 저장 팝업 ── */
.ps-save-picker {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  min-width: 180px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.ps-save-picker input[type=text] {
  width: 100%;
  box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 12px;
  margin-bottom: 4px;
}
.ps-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  transition: background 0.1s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.ps-item:hover { background: var(--border); }
.ps-item.ps-new { color: var(--accent); }

/* ── 패널 리사이저 ── */
#panel-resizer {
  width: 1px;
  flex-shrink: 0;
  cursor: col-resize;
  background: var(--border);
  transition: background 0.15s;
  position: relative;
  z-index: 5;
}
#panel-resizer::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: -3px; right: -3px;
  cursor: col-resize;
}
#panel-resizer:hover,
#panel-resizer:active {
  background: var(--accent);
}

/* ── 우측 차트 패널 ── */
#chart-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ── 차트 헤더 ── */
#chart-header {
  height: var(--chart-header-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#chart-fund-row {
  display: none;
  align-items: center;
  padding: 2px 12px 4px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#chart-ticker-info {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.chart-name-text {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
  color: var(--text);
  cursor: pointer;
  transition: color 0.15s;
}
.chart-name-text:hover { color: var(--accent); }

#chart-ticker-badge {
  font-size: 13px;
  font-weight: 600;
  padding: 2px 10px;
  color: var(--text-secondary);
}

#chart-market-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
}

.market-badge-kospi  { background: rgba(79,142,247,.2);  color: #6aa2ff; border-color: rgba(79,142,247,.4); }
.market-badge-kosdaq { background: rgba(155,114,245,.2); color: #b08ef7; border-color: rgba(155,114,245,.4); }
.market-badge-us     { background: rgba(76,175,133,.2);  color: #5cc89a; border-color: rgba(76,175,133,.4); }
.market-badge-crypto { background: rgba(245,185,50,.2);  color: #f5c040; border-color: rgba(245,185,50,.4); }

/* ── 펀더멘탈 태그 ── */
.fund-tags {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 6px;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
}
.fund-tag {
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.fund-tag .fund-label { color: var(--text-muted); }
.fund-tag .fund-val   { color: var(--text); font-weight: 600; margin-left: 2px; }
.fund-sep { color: var(--border); margin: 0 2px; }

/* ── 차트 컨트롤 버튼 그룹 ── */
.btn-group {
  display: flex;
  gap: 2px;
}

.ctrl-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.ctrl-btn:hover { background: var(--surface2); color: var(--text); }
.ctrl-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
  align-self: center;
}

/* ── 드로잉 툴바 ── */
#drawing-toolbar {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.draw-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  border-radius: 5px;
  width: 30px;
  height: 26px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.draw-btn:hover { background: var(--surface2); color: var(--text); border-color: var(--border); }
.draw-btn.active { background: var(--surface2); color: var(--accent); border-color: var(--accent); }

/* ── 차트 컨테이너 ── */
#tv-container {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

#chart-canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ── 타임존 선택기 (X축 우측) ── */
#tz-selector {
  position: absolute;
  bottom: 1px;
  right: 10px;
  z-index: 105;
  height: 25px;
  display: flex;
  align-items: center;
}
#tz-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 2px 8px;
  font-size: 10px;
  cursor: pointer;
  transition: color 0.15s;
}
#tz-btn:hover { color: var(--text); }
#tz-menu {
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 0;
  min-width: 120px;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.4);
}
.tz-option {
  padding: 5px 12px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}
.tz-option:hover { background: var(--surface2); color: var(--text); }
.tz-option.active { color: var(--accent); font-weight: 600; }

/* ── 플레이스홀더 ── */
#chart-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 14px;
  background: var(--bg);
  z-index: 2;
}

.placeholder-icon {
  font-size: 48px;
  opacity: 0.4;
}

/* ── 로딩 스피너 ── */
#chart-loading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 17, 23, 0.7);
  z-index: 20;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── 차트 인라인 레전드 (TradingView 스타일) ── */
#chart-hover-info {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  color: var(--text);
  max-width: calc(100% - 80px);
}

.hi-row1 {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.hi-row2 {
  display: flex;
  flex-direction: column;
  gap: 1px;
  pointer-events: auto;
}

.hi-name {
  font-weight: 700;
  font-size: 13px;
}

.hi-ticker-sm {
  font-size: 11px;
  color: var(--text-muted);
}

.hi-sep {
  color: var(--border);
  font-size: 11px;
}

.hi-date {
  color: var(--text-muted);
  font-size: 11px;
}

.hi-item {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 12px;
}

.hi-lbl {
  color: var(--text-muted);
  font-size: 11px;
}

.hi-chg {
  font-size: 12px;
  font-weight: 600;
}

.hi-ind-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
}
.hi-ind-row .hi-icon-btn { display: none; }
.hi-ind-row:hover .hi-icon-btn { display: flex; }
.hi-ind-faded { opacity: 0.4; }
.hi-ind-label { letter-spacing: 0.2px; }
.hi-ind-val { color: var(--text); font-weight: 500; }

.hi-icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  line-height: 1;
  opacity: 0.5;
  transition: opacity 0.12s, color 0.12s;
}
.hi-icon-btn:hover { opacity: 1; color: var(--text); }
.hi-ind-del { font-size: 14px; font-weight: 700; }
.hi-ind-del:hover { color: var(--danger) !important; }

.hi-add-row { padding: 2px 4px; }
.hi-add-ind {
  background: none;
  border: none;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.12s, background 0.12s;
}
.hi-add-ind:hover { color: var(--text); background: rgba(255,255,255,0.07); }

.hi-dot {
  width: 10px;
  height: 2px;
  border-radius: 1px;
  flex-shrink: 0;
  display: inline-block;
}

/* ── 지표 설정 패널 ── */
.isp-select, .isp-number {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 12px;
  outline: none;
}
.isp-select { width: 80px; }
.isp-number { width: 64px; }
.tma-section-lbl {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 6px 0 2px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* ── Badge ── */
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

/* ── Status bar ── */
#status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.status-item { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.dot.green  { background: var(--success); }
.dot.yellow { background: #f5c842; animation: pulse 1s infinite; }
.dot.orange { background: #ff9640; }
.dot.red    { background: var(--danger); }

.status-badge {
  font-size: 9px;
  font-weight: 600;
  padding: 0 6px;
  height: 15px;
  line-height: 15px;
  border-radius: 8px;
  letter-spacing: 0;
  text-transform: none;
  display: inline-flex;
  align-items: center;
}
.status-badge.green  { background: rgba(76,175,133,0.18); color: #4caf85; }
.status-badge.yellow { background: rgba(245,200,66,0.18); color: #f5c842; }
.status-badge.orange { background: rgba(255,150,64,0.18); color: #ff9640; }
.status-badge.red    { background: rgba(224,82,82,0.18);  color: #e05252; }
.status-badge.blue   { background: rgba(82,130,224,0.18); color: #5282e0; }
.status-badge.retrying { animation: badge-blink 1.2s ease-in-out infinite; }
@keyframes badge-blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}
#data-retry-spin { animation: spin-icon 1.2s linear infinite; display: inline-block; }
@keyframes spin-icon {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ── Data status card header ── */
#data-status-title {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 0;
}
.dstatus-left { display: flex; align-items: center; gap: 8px; cursor: pointer; flex: 1; user-select: none; }
.dstatus-caret { font-size: 9px; color: var(--text-muted); transition: transform 0.15s; display: inline-block; width: 10px; }
#data-status-card.collapsed .dstatus-caret { transform: rotate(-90deg); }
#data-status-card.collapsed #data-status-body { display: none; }
#data-status-card:not(.collapsed) #data-status-body { margin-top: 10px; }

.btn.btn-compact { font-size: 11px; padding: 0 10px; border-radius: 4px; height: 19px; line-height: 19px; font-weight: 600; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

#progress-bar-wrap {
  width: 100%; height: 3px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
  display: none;
  margin-top: 8px;
}
#progress-bar { height: 100%; background: var(--accent); transition: width 0.3s; }

/* ── 마켓 업데이트 행 ── */
.update-rows { display: flex; flex-direction: column; gap: 5px; margin-top: 6px; }
.update-row  { display: flex; align-items: center; gap: 8px; }
.update-row .btn { font-size: 11px; padding: 3px 8px; }
.update-row .btn-secondary { min-width: 60px; }
.update-time { font-size: 11px; color: var(--text-muted); flex: 1; }
.update-msg  { font-size: 11px; color: var(--text-muted); }

/* ── 마켓 라디오 버튼 ── */
#market-selector { display: flex; gap: 16px; padding: 6px 0 10px; }
.mkt-radio { display: flex; align-items: center; gap: 5px; font-size: 13px; cursor: pointer; user-select: none; }
.mkt-radio input[type=radio] { accent-color: var(--accent); cursor: pointer; }

/* ── Filter builder ── */
.filter-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.filter-row select,
.filter-row input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 11px;
  outline: none;
}
.filter-row select:focus,
.filter-row input:focus { border-color: var(--accent); }
.filter-row select.field-sel { width: 82px; }
.ma-input-wrap { display: inline-flex; align-items: center; gap: 2px; }
.ma-type-sel {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 11px;
  font-weight: 600;
  width: 48px;
}
.ma-period-input {
  width: 34px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 12px;
  text-align: center;
}
.filter-row input.period-input { width: 40px; text-align: center; }
.filter-row select.op-sel    { width: 52px; }
.filter-row .op-label        { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 2px; flex-shrink: 0; }
.filter-row .val-wrap { display: flex; gap: 4px; align-items: center; }
.filter-row .val-wrap input  { width: 84px; }
.filter-row .val-wrap select { width: 100px; }
.val-unit-label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: -2px;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 28px; height: 28px;
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn-icon:hover { border-color: var(--danger); color: var(--danger); }

#filter-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  position: relative;
  align-items: center;
  flex-wrap: wrap;
}
#filter-actions > .btn,
#filter-actions > div > .btn,
#expr-row > .btn {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 5px;
}
.market-check { display: flex; gap: 10px; }
.market-check label { display: flex; align-items: center; gap: 4px; cursor: pointer; font-size: 13px; }

/* ── Buttons ── */
.btn {
  padding: 7px 14px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

/* ── Results ── */
#result-info {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
#result-count { font-weight: 700; color: var(--accent); font-size: 15px; }

.table-wrap { overflow-x: auto; overflow-y: auto; max-height: calc(100vh - 380px); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
th {
  background: var(--surface2);
  padding: 8px 10px;
  text-align: right;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  z-index: 1;
}
th:first-child, th:nth-child(2), th:nth-child(3) { text-align: left; }
th.sorted-asc::after  { content: " ▲"; color: var(--accent); }
th.sorted-desc::after { content: " ▼"; color: var(--accent); }
th:hover { color: var(--text); }

td {
  padding: 7px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td:first-child, td:nth-child(2), td:nth-child(3) { text-align: left; }

tbody tr { cursor: pointer; transition: background 0.1s; }
tbody tr:hover td { background: var(--surface2); }
tbody tr.row-selected td { background: rgba(79,142,247,.12); }
tbody tr.row-selected:hover td { background: rgba(79,142,247,.18); }

.ticker-code { font-family: monospace; color: var(--text-muted); font-size: 11px; }
#result-table .ticker-code { display: block; width: 56px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticker-name { font-weight: 600; display: block; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.market-kospi  { color: #4f8ef7; font-size: 10px; font-weight: 600; }
.market-kosdaq { color: #9b72f5; font-size: 10px; font-weight: 600; }
.market-us     { color: #4caf85; font-size: 10px; font-weight: 600; }
.market-crypto { color: #f5b832; font-size: 10px; font-weight: 600; }
.pos { color: #e05252; }
.neg { color: #4caf85; }
.muted { color: var(--text-muted); }

/* ── Toast / Empty state ── */
#toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 999;
  max-width: 320px;
}
#toast.show { opacity: 1; }
#toast.error { border-color: var(--danger); color: var(--danger); }

.empty-state {
  text-align: center;
  padding: 40px 0;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 32px; margin-bottom: 10px; }

/* ── 조건 라벨 배지 ── */
.cond-label-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  font-family: monospace;
}

/* ── Expression 입력 행 ── */
#expr-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 4px;
  flex-wrap: wrap;
}
.expr-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
#expr-input {
  flex: 1;
  min-width: 140px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  font-family: monospace;
  outline: none;
}
#expr-input:focus { border-color: var(--accent); }
#expr-input.invalid { border-color: var(--danger); }
.expr-error {
  font-size: 11px;
  color: var(--danger);
  white-space: nowrap;
}

/* ── 드로잉 구분선 ── */
.draw-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
  align-self: center;
  margin: 0 2px;
}

/* ── 플로팅 패널 공통 (드로잉 속성 / 지표 설정) ── */
#drawing-props-panel,
#indicator-settings-panel,
#triple-ma-panel,
#fundtag-settings-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px 10px;
  z-index: 1000;
  box-shadow: 0 12px 40px rgba(0,0,0,0.7);
  font-size: 12px;
  user-select: none;
}

.fundtag-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: grab;
}

.fundtag-item:hover { background: var(--surface2); }

.fundtag-item.dragging {
  opacity: 0.4;
  background: var(--surface2);
}

.fundtag-drag {
  color: var(--text-muted);
  font-size: 11px;
  cursor: grab;
  flex-shrink: 0;
}

.fundtag-drag:active { cursor: grabbing; }

#toolbar-settings-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px 10px;
  z-index: 1000;
  box-shadow: 0 12px 40px rgba(0,0,0,0.7);
  font-size: 12px;
  user-select: none;
}

.dpp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
  cursor: move;
}
.dpp-title {
  font-weight: 700;
  font-size: 12px;
  color: var(--text);
}
.dpp-close {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.dpp-close:hover { background: var(--danger); border-color: var(--danger); }

.dpp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.dpp-label {
  color: var(--text-muted);
  min-width: 40px;
  font-size: 11px;
}
.dpp-color-input {
  width: 34px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  background: none;
  padding: 1px;
}
.dpp-range {
  flex: 1;
  accent-color: var(--accent);
  height: 4px;
}
.dpp-unit {
  color: var(--text-muted);
  min-width: 36px;
  text-align: left;
  font-size: 11px;
}
.dpp-check {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
}

/* ── 커스텀 체크박스 ── */
.dpp-check input[type="checkbox"],
input[type="checkbox"].dpp-cb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--border);
  border-radius: 3px;
  background: var(--surface2);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: background 0.15s, border-color 0.15s;
}
.dpp-check input[type="checkbox"]:hover,
input[type="checkbox"].dpp-cb:hover {
  border-color: var(--accent);
}
.dpp-check input[type="checkbox"]:checked,
input[type="checkbox"].dpp-cb:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.dpp-check input[type="checkbox"]:checked::after,
input[type="checkbox"].dpp-cb:checked::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0px;
  width: 5px;
  height: 8px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}
.dpp-text-input {
  flex: 1;
  min-width: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 12px;
  outline: none;
}
.dpp-text-input:focus { border-color: var(--accent); }

.dpp-actions {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.dpp-btn-group {
  display: flex;
  gap: 4px;
}

/* ── 스타일 팝업 (색상·두께·투명도·선스타일) ── */
#style-picker {
  position: fixed;
  z-index: 1100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  width: 236px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.65);
  font-size: 12px;
  user-select: none;
}
.sp-palette-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  margin-bottom: 8px;
}
.sp-palette-cell {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;
  box-sizing: border-box;
  transition: border-color 0.12s, transform 0.1s;
}
.sp-palette-cell:hover { transform: scale(1.15); }
.sp-palette-cell.sp-active { border-color: #fff; }
.sp-custom-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.sp-custom-swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.sp-custom-swatch input[type="color"] {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  padding: 0;
  border: none;
}
.sp-custom-label {
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
}
.sp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}
.sp-label {
  color: var(--text-muted);
  min-width: 38px;
  font-size: 11px;
  flex-shrink: 0;
}
.sp-range {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
  height: 4px;
}
.sp-val {
  color: var(--text-muted);
  min-width: 36px;
  font-size: 11px;
}
.sp-ls-group {
  display: flex;
  gap: 4px;
  flex: 1;
}
.sp-ls-btn {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 4px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s;
}
.sp-ls-btn:hover { background: var(--surface3, #2a2d3a); border-color: var(--text-muted); }
.sp-ls-btn.sp-active { background: var(--accent); border-color: var(--accent); color: #fff; }
/* 스타일 버튼 (패널 내 미리보기) */
.dpp-style-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px 5px 7px;
  cursor: pointer;
  color: var(--text);
  min-width: 0;
  transition: background 0.12s;
}
.dpp-style-btn:hover { background: var(--surface3, #2a2d3a); }
.dpp-style-swatch {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
}
.dpp-style-line-svg { flex: 1; min-width: 0; overflow: visible; }
.dpp-style-thick { font-size: 10px; color: var(--text-muted); flex-shrink: 0; }
.dpp-select {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 12px;
  padding: 3px 6px;
  cursor: pointer;
  outline: none;
}
.dpp-select:focus { border-color: var(--accent); }

.dpp-pos-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.dpp-pos-btn:hover { background: var(--border); color: var(--text); }
.dpp-pos-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── 드로잉 템플릿 ───────────────────────────────────────── */
.dpp-template-section {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.dpp-tpl-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}
.dpp-tpl-default {
  cursor: pointer;
  opacity: 0.8;
}
.dpp-tpl-default:hover { opacity: 1; }

.dpp-tpl-key {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg3);
  border-radius: 3px;
  padding: 1px 4px;
  min-width: 14px;
  text-align: center;
  flex-shrink: 0;
}

.dpp-tpl-name {
  flex: 1;
  font-size: 11px;
  color: var(--accent);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dpp-tpl-name:hover { text-decoration: underline; }

.dpp-tpl-preview {
  width: 22px;
  border-radius: 2px;
  flex-shrink: 0;
  opacity: 0.85;
}

.dpp-tpl-del {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
}
.dpp-tpl-del:hover { color: var(--danger); }

.dpp-tpl-drag {
  color: var(--text-muted);
  cursor: grab;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
  user-select: none;
}
.dpp-tpl-drag:hover { color: var(--text-main); }
.dpp-tpl-drag:active { cursor: grabbing; }

.dpp-tpl-item.dpp-dragging {
  opacity: 0.35;
}

.dpp-tpl-btn {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 11px;
  cursor: pointer;
}
.dpp-tpl-btn:hover { background: var(--border); color: var(--text); }

.dpp-box-pos-grid {
  display: grid;
  grid-template-columns: repeat(3, 24px);
  gap: 2px;
}
.dpp-box-pos-btn {
  width: 24px; height: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.dpp-box-pos-btn:hover { background: var(--border); color: var(--text); }
.dpp-box-pos-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.dpp-box-pos-center {
  width: 24px; height: 24px;
  border: 1px solid var(--border);
  border-radius: 4px;
  opacity: 0.2;
}

.dpp-save-picker {
  min-width: 160px;
  background: #22263a;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px;
  z-index: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.dpp-save-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
}
.dpp-save-row:hover { background: var(--surface2); }
.dpp-save-name { flex: 1; }
.dpp-save-add {
  color: var(--accent);
  border-top: 1px solid var(--border);
  margin-top: 3px;
  padding-top: 7px;
}
.dpp-reset-all-btn {
  display: block;
  width: 100%;
  margin-top: 5px;
  text-align: center;
  color: var(--danger) !important;
  border-color: var(--danger) !important;
  opacity: 0.7;
}
.dpp-reset-all-btn:hover { opacity: 1; background: transparent !important; }

/* ── UI 모달 ──────────────────────────────────────────────────────── */
#ui-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}
#ui-modal-overlay.open { display: flex; }
#ui-modal-box {
  background: #2a2f45;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 10px;
  padding: 22px 24px 18px;
  min-width: 280px;
  max-width: 380px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.8);
}
#ui-modal-msg {
  font-size: 13px;
  color: var(--text);
  white-space: pre-line;
  line-height: 1.65;
  margin-bottom: 16px;
}
.ui-modal-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 6px 10px;
  margin-bottom: 16px;
  outline: none;
}
.ui-modal-input:focus { border-color: var(--accent); }
.ui-modal-btns {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.ui-modal-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 5px 18px;
  font-size: 12px;
  cursor: pointer;
}
.ui-modal-btn:hover { background: var(--border); color: var(--text); }
.ui-modal-ok-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.ui-modal-ok-btn:hover { opacity: 0.85; background: var(--accent); color: #fff; }

/* ── 스냅샷 모달 ── */
#snap-modal-overlay {
  display: none;
  position: fixed;
  top: 50%;
  right: 20px;
  transform: translateY(-50%);
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px 10px;
  z-index: 1000;
  box-shadow: 0 12px 40px rgba(0,0,0,0.7);
  font-size: 12px;
  user-select: none;
}
#snap-modal-overlay.open { display: block; }

/* ── 스냅샷 뱃지 ── */
.snapshot-badge {
  background: rgba(245,200,66,0.2);
  color: #f5c842;
  border: 1px solid rgba(245,200,66,0.4);
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 8px;
  font-weight: 600;
  margin-left: 6px;
}

/* ── 트리 뷰 (관심종목/스냅샷) ── */
.tree-folder {
  user-select: none;
}
.tree-folder-hd {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid transparent;
}
.tree-folder-hd:hover { background: var(--surface2); }
.tree-folder-hd .tree-fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-folder-hd .tree-count { font-size: 10px; color: var(--text-muted); font-weight: 400; margin-left: auto; flex-shrink: 0; }
.tree-items {
  display: none;
}
.tree-folder.open > .tree-items { display: block; }
.tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 28px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  transition: background 0.1s;
}
.tree-item:hover { background: var(--surface2); }
.tree-item .ticker-code { font-size: 11px; color: var(--text-muted); min-width: 52px; flex-shrink: 0; }
.tree-item .tree-item-name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item .tree-item-market { font-size: 10px; flex-shrink: 0; }
.tree-item.drag-over { border-top: 2px solid var(--accent); }
.tree-item.drag-over-above { border-top: 2px solid var(--accent); }
.tree-item.drag-over-below { border-bottom: 2px solid var(--accent); }
.tree-folder-hd.drag-over-folder { background: rgba(79,142,247,0.15); }
.tree-folder-hd.drag-over-inside { background: rgba(79,142,247,0.22); box-shadow: inset 0 0 0 1px rgba(79,142,247,0.6); }
.tree-empty { padding: 12px 16px; font-size: 12px; color: var(--text-muted); }

/* ── Level 1 폴더 아이콘 ── */
.tree-l1-icon {
  display: inline-flex;
  align-items: center;
  width: 15px;
  flex-shrink: 0;
  color: var(--text-muted);
}
.tree-l1-icon svg { display: block; }
.tree-folder.open > .tree-folder-hd .tree-l1-icon { color: var(--accent); }

/* ── Level 1 폴더 자식 커넥터 (서브폴더 + 직속 아이템) ── */
#mp-body > .tree-folder > .tree-items > .tree-item { position: relative; }
#mp-body > .tree-folder > .tree-items > .tree-sub { position: relative; }
/* 세로선: 아이템 */
#mp-body > .tree-folder > .tree-items > .tree-item::before {
  content: ''; position: absolute; left: 18px; top: 0; height: 100%;
  border-left: 1px solid var(--border); pointer-events: none;
}
/* 세로선: 서브폴더 (전체 높이 — 다음 형제 연결) */
#mp-body > .tree-folder > .tree-items > .tree-sub::before {
  content: ''; position: absolute; left: 18px; top: 0; height: 100%;
  border-left: 1px solid var(--border); pointer-events: none; z-index: 1;
}
/* 가로선: 아이템 */
#mp-body > .tree-folder > .tree-items > .tree-item::after {
  content: ''; position: absolute; left: 18px; top: 50%;
  width: 8px; border-top: 1px solid var(--border); pointer-events: none;
}
/* 가로선: 서브폴더 (헤더 중앙) */
#mp-body > .tree-folder > .tree-items > .tree-sub::after {
  content: ''; position: absolute; left: 18px; top: 14px;
  width: 8px; border-top: 1px solid var(--border); pointer-events: none; z-index: 1;
}
/* 마지막 자식: └ 형태 */
#mp-body > .tree-folder > .tree-items > :last-child.tree-item::before { height: 50%; }
#mp-body > .tree-folder > .tree-items > :last-child.tree-sub::before { height: 15px; }

/* ── Level 2 서브폴더 ── */
.tree-sub > .tree-folder-hd { padding-left: 28px; font-weight: 500; font-size: 11px; }
.tree-sub > .tree-folder-hd .tree-l1-icon { width: 13px; }
.tree-sub > .tree-folder-hd .tree-l1-icon svg { width: 12px; height: 10px; }
/* 서브폴더 아이템 */
.tree-sub > .tree-items > .tree-item { padding-left: 38px; position: relative; }
/* ㄴ 커넥터: 세로선 */
.tree-sub > .tree-items > .tree-item::before {
  content: ''; position: absolute; left: 32px; top: 0; height: 100%;
  border-left: 1px solid var(--border); pointer-events: none;
}
/* ㄴ 커넥터: 가로선 */
.tree-sub > .tree-items > .tree-item::after {
  content: ''; position: absolute; left: 32px; top: 50%;
  width: 5px; border-top: 1px solid var(--border); pointer-events: none;
}
/* 마지막 아이템: └ 형태 (세로선 절반) */
.tree-sub > .tree-items > .tree-item:last-child::before { height: 50%; }

/* 폴더 드래그 순서 변경 */
.tree-folder-hd.drag-over-above { border-top: 2px solid var(--accent); }
.tree-folder-hd.drag-over-below { border-bottom: 2px solid var(--accent); }

/* ── 보관함(archive) 폴더 ── */
.tree-archive { border-top: 1px solid var(--border); margin-top: 6px; opacity: 0.75; }
.tree-archive:hover { opacity: 1; }
.tree-archive > .tree-folder-hd .tree-fname { font-style: italic; }
.tree-archive-sub > .tree-folder-hd { padding-left: 28px; font-weight: 500; font-size: 11px; }
.tree-archive-sub > .tree-folder-hd .tree-l1-icon { width: 13px; }
.tree-archive-sub > .tree-folder-hd .tree-l1-icon svg { width: 12px; height: 10px; }
/* 보관함 서브폴더 아이템도 같은 커넥터 */
.tree-archive-sub > .tree-items > .tree-item { padding-left: 38px; position: relative; }
.tree-archive-sub > .tree-items > .tree-item::before {
  content: ''; position: absolute; left: 32px; top: 0; height: 100%;
  border-left: 1px solid var(--border); pointer-events: none;
}
.tree-archive-sub > .tree-items > .tree-item::after {
  content: ''; position: absolute; left: 32px; top: 50%;
  width: 5px; border-top: 1px solid var(--border); pointer-events: none;
}
.tree-archive-sub > .tree-items > .tree-item:last-child::before { height: 50%; }

/* ── 다중 선택 ── */
.tree-item.selected { background: rgba(79,142,247,0.18); }
.tree-item.selected:hover { background: rgba(79,142,247,0.28); }

/* ── 우클릭 컨텍스트 메뉴 ── */
.ctx-menu {
  position: fixed;
  z-index: 10000;
  min-width: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  font-size: 12px;
}
.ctx-menu-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 5px;
  cursor: pointer;
  color: var(--text);
}
.ctx-menu-item:hover { background: var(--surface2); }
.ctx-menu-item.danger { color: var(--danger); }
.ctx-menu-sep { height: 1px; background: var(--border); margin: 3px 4px; }

/* ── 종목 검색 모달 ─────────────────────────────────────────────────── */
#ticker-search-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 10000;
}
#ticker-search-overlay.open { display: block; }
#ticker-search-box {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 480px;
  max-width: 95vw;
  box-shadow: 0 12px 40px rgba(0,0,0,0.7);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
}
#ticker-search-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
  cursor: move;
}
#ticker-search-title {
  font-weight: 700;
  font-size: 12px;
  color: var(--text);
}
#ticker-search-header {
  padding: 10px 12px 10px;
  border-bottom: 1px solid var(--border);
}
#ticker-search-input {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
}
#ticker-search-input:focus { border-color: var(--accent); }
#ticker-search-filters {
  display: flex;
  gap: 14px;
  margin-top: 9px;
  font-size: 12px;
  color: var(--text-muted);
}
#ticker-search-filters label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
}
#ticker-search-filters input[type=checkbox] {
  accent-color: var(--accent);
  cursor: pointer;
}
#ticker-search-results {
  max-height: 340px;
  overflow-y: auto;
  padding: 4px 0;
}
.ticker-search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.1s;
}
.ticker-search-item:hover, .ticker-search-item.selected {
  background: var(--surface2);
}
.ticker-search-item .ts-ticker {
  font-weight: 400;
  color: var(--text);
  width: 90px;
  flex-shrink: 0;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ticker-search-item .ts-name {
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ticker-search-item .ts-market {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 4px;
  font-weight: 600;
  background: var(--surface2);
  color: var(--text-muted);
}
.ts-market.kr { background: rgba(82,168,255,0.15); color: #52a8ff; }
.ts-market.us { background: rgba(72,207,174,0.15); color: #48cfad; }
.ts-market.crypto { background: rgba(255,180,50,0.15); color: #f5b832; }
#ticker-search-empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}
