* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: #222;
  background: #f5f6f8;
  font-size: 13px;
  overflow-x: hidden;   /* 페이지 본문은 가로 스크롤 금지(표는 .table-wrap 내부에서 스크롤) */
}
.app-header {
  background: #1f2937;
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.app-header h1 { font-size: 18px; margin: 0; }
.app-header .subtitle { font-size: 12px; color: #9ca3af; }
.btn-portfolio { margin-left: auto; padding: 5px 12px; font-size: 12px; border: 1px solid #f59e0b; background: #f59e0b; color: #fff; border-radius: 6px; cursor: pointer; font-weight: 600; }
.btn-portfolio:hover { background: #d97706; }
.tl-add-pf { padding: 3px 10px; font-size: 12px; border: 1px solid #f59e0b; background: #fffbeb; color: #b45309; border-radius: 6px; cursor: pointer; }
.tl-add-pf:hover { background: #fef3c7; }
.pf-table { width: 100%; }
.pf-table td { cursor: pointer; }
.pf-table tbody tr:hover { background: #f1f7ff; }
.pf-code { font-size: 10px; color: #9ca3af; }
.pf-del { font-size: 11px; padding: 2px 7px; border: 1px solid #e5a5a5; background: #fff; color: #b91c1c; border-radius: 4px; cursor: pointer; }
.pf-total { margin-top: 8px; font-size: 13px; text-align: right; }
.pf-total .up { color: #d32f2f; } .pf-total .down { color: #1565c0; }
.pf-table .up { color: #d32f2f; } .pf-table .down { color: #1565c0; }
.mode-switch { margin-left: 8px; display: inline-flex; border: 1px solid #4b5563; border-radius: 6px; overflow: hidden; }
.mode-btn { padding: 5px 12px; font-size: 12px; color: #cbd5e1; text-decoration: none; background: #374151; }
.mode-btn + .mode-btn { border-left: 1px solid #4b5563; }
.mode-btn.active { background: #16a34a; color: #fff; font-weight: 700; }
.mode-banner { background: #ecfdf5; color: #065f46; font-size: 12px; padding: 6px 16px; border-bottom: 1px solid #a7f3d0; }
.mode-banner .mode-note { color: #4b5563; }
/* 상업용: 투자자매매동향·증권사리포트 섹션 숨김 */
body.mode-commercial .sec-investor, body.mode-commercial .sec-research { display: none; }

.layout { display: flex; align-items: flex-start; gap: 14px; padding: 14px; }
.filter-panel {
  width: 260px;
  flex: 0 0 260px;
  background: #fff;
  border: 1px solid #e2e5ea;
  border-radius: 8px;
  padding: 12px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  position: sticky;
  top: 14px;
}
.result-area { flex: 1; min-width: 0; max-width: 100%; }

.filter-group { margin-bottom: 12px; }
.filter-group-title { display: block; font-weight: 600; margin-bottom: 4px; font-size: 12px; color: #374151; }
.range-pair { display: flex; align-items: center; gap: 4px; }
.range-pair input { width: 100%; }
.range-sep { color: #9ca3af; }
input[type="number"], select.multi {
  padding: 4px 6px;
  border: 1px solid #cbd0d8;
  border-radius: 4px;
  font-size: 12px;
  width: 100%;
}
select.multi { min-height: 90px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }

.filter-btns { display: flex; gap: 8px; margin-top: 8px; }
.btn-primary, .btn-ghost {
  flex: 1; padding: 7px; border-radius: 5px; cursor: pointer; font-size: 13px; border: 1px solid transparent;
}
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-ghost { background: #fff; border-color: #cbd0d8; color: #374151; }

.preset-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.preset-label { font-weight: 600; color: #6b7280; }
.preset-btn {
  padding: 6px 12px; border-radius: 16px; border: 1px solid #2563eb;
  background: #eff6ff; color: #1d4ed8; cursor: pointer; font-size: 12px;
}
.preset-btn:hover { background: #dbeafe; }
.preset-btn.active {
  background: #2563eb; color: #fff; font-weight: 600;
  box-shadow: 0 1px 3px rgba(37,99,235,.4);
}

/* AND/OR 조합 토글 */
.combine-seg { display: inline-flex; border: 1px solid #cbd0d8; border-radius: 6px; overflow: hidden; }
.combine-btn {
  padding: 5px 10px; border: none; background: #fff; color: #6b7280;
  cursor: pointer; font-size: 11px; font-weight: 700; letter-spacing: .3px;
}
.combine-btn + .combine-btn { border-left: 1px solid #cbd0d8; }
.combine-btn.active { background: #1f2937; color: #fff; }
.preset-note { font-size: 11px; color: #b45309; background: #fffbeb; padding: 3px 8px; border-radius: 4px; }
.preset-reset {
  padding: 5px 10px; border-radius: 6px; border: 1px solid #cbd0d8;
  background: #fff; color: #4b5563; cursor: pointer; font-size: 12px;
}
.preset-reset:hover { background: #f3f4f6; border-color: #9ca3af; }

/* 그룹 모드에서 좌측 폼 비활성 표시 */
.filter-panel form.dimmed { opacity: .45; pointer-events: none; filter: grayscale(.3); }

/* 중요 지표 색상 강조 */
.cell-name { font-weight: 600; color: #111827; }
.cell-code { color: #6b7280; font-variant-numeric: tabular-nums; }
.hl-val { color: #15803d; }
.hl-strong { color: #166534; font-weight: 700; }
.strong { font-weight: 700; }

.result-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.result-meta { font-weight: 600; color: #111827; }
.btn-csv { padding: 6px 12px; border: 1px solid #16a34a; background: #16a34a; color: #fff; border-radius: 5px; cursor: pointer; }
.btn-csv:hover { background: #15803d; }

.table-wrap { background: #fff; border: 1px solid #e2e5ea; border-radius: 8px; overflow-x: auto; }
#result-table { width: 100%; border-collapse: collapse; font-size: 12px; }
#result-table th, #result-table td { padding: 7px 9px; border-bottom: 1px solid #eef0f3; white-space: nowrap; }
#result-table thead th { background: #f8fafc; text-align: left; position: sticky; top: 0; font-weight: 600; color: #374151; }
#result-table th.sortable { cursor: pointer; user-select: none; }
#result-table th.sortable:hover { background: #eef2f7; }
#result-table tbody tr { cursor: pointer; }
#result-table tbody tr:hover { background: #f1f7ff; }
.num-cell { text-align: right; font-variant-numeric: tabular-nums; }
/* 숫자 헤더도 우측정렬해 데이터와 열 정합 맞춤 */
#result-table thead th.num-head { text-align: right; }
.search-input { width: 100%; padding: 5px 7px; border: 1px solid #cbd0d8; border-radius: 4px; font-size: 12px; }
.field-hint { font-size: 10px; color: #9ca3af; margin-top: 3px; }
.muted { color: #c2c8d0; }
/* 기술적 신호 필터 */
.sig-subtitle { font-size: 11px; font-weight: 700; margin: 4px 0 2px; }
.sig-subtitle.sig-entry { color: #15803d; }
.sig-subtitle.sig-exit { color: #d32f2f; }
.sig-checks { gap: 4px 8px; }
.sig-checks .check { font-size: 11px; }
.up { color: #d32f2f; }
.down { color: #1565c0; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 12px 0; }
.pager button { padding: 5px 12px; border: 1px solid #cbd0d8; background: #fff; border-radius: 5px; cursor: pointer; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager-info { color: #374151; }

/* 모달 */
.modal { position: fixed; inset: 0; z-index: 100; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.modal-box {
  position: relative; background: #fff; max-width: 900px; margin: 30px auto;
  border-radius: 10px; padding: 20px; max-height: calc(100vh - 60px); overflow-y: auto;
}
.modal-close { position: absolute; top: 12px; right: 14px; border: none; background: none; font-size: 26px; cursor: pointer; color: #6b7280; line-height: 1; }
.detail-section { margin-top: 16px; }
.detail-section h3 { font-size: 14px; margin: 0 0 8px; padding-bottom: 4px; border-bottom: 2px solid #e5e7eb; }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 24px; margin: 0; }
.kv > dt { grid-column: 1; color: #6b7280; padding: 3px 0; border-bottom: 1px dotted #eee; }
.kv > dd { grid-column: 2; margin: 0; text-align: right; font-variant-numeric: tabular-nums; padding: 3px 0; border-bottom: 1px dotted #eee; }
.biz-summary { margin-top: 10px; color: #4b5563; line-height: 1.5; font-size: 12px; }

/* 투자정보 색상 강조: 빨강=긍정(저평가), 파랑=이상(적자/악화) */
.kv > dd.pos { color: #d32f2f; }
.kv > dd.pos-strong { color: #d32f2f; font-weight: 700; }
.kv > dd.neg { color: #1565c0; }
.kv > dd.neg-strong { color: #1565c0; font-weight: 700; }
.kv > dd.up { color: #d32f2f; }
.kv > dd.down { color: #1565c0; }

/* 기술적 신호 배지(상세) */
.sig-scores { margin-bottom: 8px; font-size: 12px; }
.sig-score-entry { color: #166534; font-weight: 700; margin-right: 6px; }
.sig-score-exit { color: #d32f2f; font-weight: 700; }
.sig-meta { color: #6b7280; margin-left: 8px; }
.tech-levels { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 4px; }
.tech-levels .tl { background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 6px; padding: 4px 10px; font-size: 12px; }
.tech-levels .tl-k { color: #6b7280; margin-right: 5px; }
.tech-levels .tl b { font-variant-numeric: tabular-nums; }
.tech-levels .tl-target { background: #fef2f2; border-color: #fecaca; }
.tech-levels .tl-target b { color: #d32f2f; }
.tech-levels .tl-stop { background: #eff6ff; border-color: #bfdbfe; }
.tech-levels .tl-stop b { color: #1565c0; }
.tech-ref { margin-bottom: 6px; }
.tl-rec { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 4px 0; }
.tl-rec-label { font-size: 12px; font-weight: 600; color: #6b7280; }
.rec-chip { padding: 3px 9px; border-radius: 14px; border: 1px solid #cbd0d8; background: #fff; cursor: pointer; font-size: 11px; color: #374151; }
.rec-chip:hover { background: #f3f4f6; }
.rec-chip.reco { border-color: #f59e0b; background: #fffbeb; }
.rec-chip.active { background: #2563eb; color: #fff; border-color: #2563eb; }
.rec-chip.active .rec-d { color: #dbeafe; }
.rec-chip .rec-d { color: #9ca3af; }
.rec-chip:disabled { opacity: .45; cursor: default; }
.tl-controls { display: flex; flex-wrap: wrap; gap: 10px; margin: 4px 0 6px; font-size: 12px; }
.tl-ctrl { color: #4b5563; }
.tl-ctrl select { font-size: 12px; padding: 2px 4px; border: 1px solid #cbd0d8; border-radius: 4px; }
.tl-ctrl select:disabled { opacity: .5; }
.tl-myprice { font-size: 12px; padding: 2px 5px; width: 92px; border: 1px solid #f59e0b; border-radius: 4px; }
.tl-pnl { width: 100%; margin-top: 4px; font-size: 12px; color: #374151; background: #fffbeb; border: 1px solid #fde68a; border-radius: 6px; padding: 5px 10px; }
.tl-pnl .up { color: #d32f2f; } .tl-pnl .down { color: #1565c0; }
.tech-levels .tl-pct { font-size: 11px; color: #6b7280; }
.tech-method { margin: 4px 0 6px; font-size: 12px; }
.tech-method > summary { cursor: pointer; color: #2563eb; font-weight: 600; }
.tech-method .tm-body { margin-top: 6px; padding: 8px 10px; background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 6px; line-height: 1.5; }
.tech-method .tm-body p { margin: 0 0 6px; }
.tech-method .tm-ref { color: #6b7280; }
.tech-method .tm-warn { color: #b45309; }
.sig-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.sig-badge { padding: 3px 9px; border-radius: 14px; font-size: 12px; cursor: help; border: 1px solid transparent; }
.sig-badge.entry { background: #dcfce7; color: #166534; border-color: #86efac; }
.sig-badge.exit { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }

/* 재무 테이블 */
.fin-block { margin-bottom: 14px; overflow-x: auto; }
.fin-title { font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 4px; }
.fin-table th { white-space: nowrap; }
.fin-table td.pos { color: #d32f2f; }
.fin-table td.pos-strong { color: #d32f2f; font-weight: 700; }
.fin-table td.neg { color: #1565c0; }
.fin-table td.neg-strong { color: #1565c0; font-weight: 700; }

.mini-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.mini-table th, .mini-table td { padding: 5px 8px; border-bottom: 1px solid #eef0f3; white-space: nowrap; }
.mini-table thead th { background: #f8fafc; text-align: left; }
.mini-table thead th.num { text-align: right; }

/* 좁은 화면: 세로 스택으로 전환(가로 넘침 방지) */
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .filter-panel {
    width: 100%; flex: none; position: static;
    max-height: none; overflow-y: visible;
  }
  .app-header { flex-wrap: wrap; }
}

.chart-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; }
.chart-range-btn, .chart-period-btn { padding: 4px 12px; border: 1px solid #cbd0d8; background: #fff; border-radius: 14px; cursor: pointer; font-size: 12px; }
.chart-range-btn.active, .chart-period-btn.active { background: #1f2937; color: #fff; border-color: #1f2937; }
.chart-period { display: inline-flex; gap: 4px; margin-left: 4px; padding-left: 8px; border-left: 1px solid #e5e7eb; }
.chart-indicators { display: inline-flex; flex-wrap: wrap; gap: 8px; margin-left: 6px; padding-left: 8px; border-left: 1px solid #e5e7eb; font-size: 11px; }
.chart-indicators .ind { display: inline-flex; align-items: center; gap: 3px; cursor: pointer; font-weight: 600; }
.chart-indicators .ind input { cursor: pointer; }
.ind-ma5 { color: #f59e0b; } .ind-ma20 { color: #16a34a; } .ind-ma60 { color: #8b5cf6; }
.ind-ma120 { color: #64748b; } .ind-bb { color: #1565c0; }
.chart-caption { font-size: 10px; color: #9ca3af; margin-top: 4px; }
.lw-chart { width: 100%; height: 360px; position: relative; border: 1px solid #eef0f3; border-radius: 6px; background: #fff; overflow: hidden; }
.lw-tooltip {
  position: absolute; z-index: 6; pointer-events: none;
  background: rgba(255,255,255,.96); border: 1px solid #d1d5db; border-radius: 5px;
  padding: 5px 9px; font-size: 11px; line-height: 1.45; color: #333;
  box-shadow: 0 2px 8px rgba(0,0,0,.15); white-space: nowrap;
}
