* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Malgun Gothic", "맑은 고딕", sans-serif;
  color: #222;
  background: #f5f5f5;
}
h3 { font-size: 14px; margin: 16px 0 6px; }
h4 { font-size: 13px; margin: 8px 0 4px; }
.note { color: #888888; font-size: 12px; max-width: 900px; }
.note-inline { color: #888888; font-size: 12px; margin-left: 6px; }

/* 앱 셸 */
#app-root { display: flex; flex-direction: column; height: 100vh; }
#tab-bar-row {
  display: flex; align-items: center; background: #e4e4e4;
  border-bottom: 1px solid #ccc; flex-shrink: 0;
}
#tab-strip {
  display: flex; align-items: center; flex: 1 1 auto;
  padding: 0 6px; overflow-x: auto; min-width: 0;
}
.tab-btn {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px; cursor: pointer;
  font-size: 13px; border-right: 1px solid #d3d3d3; white-space: nowrap; user-select: none;
}
.tab-btn.active { background: #fff; font-weight: bold; }
#profile-badge {
  margin: 0 8px 0 auto; padding: 4px 10px; font-size: 12px; color: #555;
  background: #d8d8d8; border-radius: 10px; cursor: pointer; white-space: nowrap;
  flex-shrink: 0;
}
#profile-badge:hover { background: #cfcfcf; }
.tab-close { color: #999; padding: 0 2px; }
.tab-close:hover { color: #c0392b; }
#tab-content { flex: 1; overflow: auto; background: #fff; }
.tab-pane { padding: 15px; height: 100%; box-sizing: border-box; }

/* 시장현황 */
.market-tab { display: flex; gap: 20px; align-items: stretch; }
.market-left { flex: 1 1 680px; min-width: 420px; }
.market-right { flex: 1 1 400px; min-width: 320px; display: flex; flex-direction: column; }
.card-row { display: flex; gap: 8px; flex-wrap: wrap; }
.quote-card {
  border: 1px solid #ccc; border-radius: 3px; padding: 10px; min-width: 110px; cursor: pointer;
}
.quote-card:hover { background: #fafafa; }
.qc-title { font-size: 11px; color: #333; }
.qc-price { font-size: 18px; font-weight: bold; margin-top: 2px; }
.qc-change { font-size: 12px; margin-top: 2px; }
.breadth-summary { font-size: 12px; color: #444; margin: 6px 0 4px; }

.add-row { display: flex; align-items: center; gap: 6px; margin: 6px 0; }
.search-wrap { position: relative; }
.search-popup {
  position: absolute; z-index: 1000; background: #fff; border: 1px solid #999;
  max-height: 220px; overflow-y: auto; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
.search-popup-row { padding: 4px 8px; font-size: 13px; cursor: pointer; }
.search-popup-row:hover { background: #eef4ff; }

.watch-table { border-collapse: collapse; width: 100%; margin-top: 6px; font-size: 13px; }
.watch-table th, .watch-table td { border: 1px solid #ddd; padding: 4px 8px; text-align: center; }
.watch-table tbody tr { cursor: grab; }
.watch-table tbody tr:hover { background: #fafafa; }
.bottom-row { display: flex; align-items: center; gap: 4px; margin-top: 10px; }
.trend-chart-host { flex: 1 1 0; min-height: 0; }
.top-sector-heatmap-host { flex: 1 1 0; min-height: 0; width: 100%; }
.trend-chart-host .chart-canvas { min-height: 0; }

/* 컨텍스트 메뉴 */
.context-menu {
  position: absolute; z-index: 2000; background: #fff; border: 1px solid #999;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); min-width: 160px;
}
.context-menu-item { padding: 6px 12px; font-size: 13px; cursor: pointer; }
.context-menu-item:hover { background: #eef4ff; }

/* 모달 */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.3); z-index: 3000;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: #fff; border-radius: 4px; padding: 16px; width: 340px; max-height: 80vh;
  display: flex; flex-direction: column;
}
.modal-box.wide { width: 560px; }
.modal-box.xwide { width: 760px; }
.modal-list { flex: 1; overflow-y: auto; border: 1px solid #ddd; margin: 8px 0; max-height: 260px; }
.modal-list-item { padding: 6px 10px; font-size: 13px; cursor: pointer; }
.modal-list-item.selected, .modal-list-item:hover { background: #eef4ff; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.sell-timing-content { overflow-y: auto; font-size: 13px; line-height: 1.6; }
.sell-timing-content p { margin: 0 0 10px; }

.pattern-list { flex: 1; overflow-y: auto; margin: 8px 0; }
.pattern-item {
  display: flex; align-items: center; gap: 16px; padding: 12px 4px;
  border-bottom: 1px solid #eee;
}
.pattern-item:last-child { border-bottom: none; }
.pattern-item-diagram { flex: 0 0 140px; width: 140px; }
.pattern-diagram { width: 140px; height: 100px; display: block; }
.pattern-item-text { flex: 1; }
.pattern-item-text h4 { margin: 0 0 4px; font-size: 14px; }
.pattern-item-text p { margin: 0; font-size: 12.5px; line-height: 1.5; color: #444; }

/* 서브탭(주도주 분석/수출입 현황) */
.subtab-strip { display: flex; border-bottom: 1px solid #ccc; margin-bottom: 10px; }
.subtab-btn { padding: 6px 14px; cursor: pointer; font-size: 13px; border: 1px solid transparent; border-bottom: none; }
.subtab-btn.active { background: #fff; border-color: #ccc; font-weight: bold; border-radius: 3px 3px 0 0; }
.table-scroll { max-height: 480px; overflow: auto; border: 1px solid #ddd; }
.table-scroll.tall { max-height: 560px; }
.ranking-table { border-collapse: collapse; width: 100%; font-size: 12px; white-space: nowrap; }
.ranking-table th, .ranking-table td { border: 1px solid #eee; padding: 4px 8px; text-align: center; }
.ranking-table tbody tr:hover { background: #fafafa; }
.ranking-table tr.selected { background: #dbe9ff; }
.ranking-table th.sortable { cursor: pointer; user-select: none; }
.ranking-table th.sortable:hover { background: #f0f0f0; }
.ranking-table th.sortable.sort-asc::after { content: " \25B2"; font-size: 9px; }
.ranking-table th.sortable.sort-desc::after { content: " \25BC"; font-size: 9px; }
.ranking-grid, .sector-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* 개별종목 상세 */
.sd-header { display: flex; align-items: center; gap: 8px; }
.sd-name { font-size: 20px; font-weight: bold; }
.sd-market { color: #888; }
.sd-spacer { flex: 1; }
.sd-header button { margin-left: 4px; }
.sd-top-row { display: flex; align-items: flex-start; gap: 30px; margin: 0 0 20px; }
.sd-price { font-size: 32px; font-weight: bold; }
.sd-change { font-size: 15px; margin-top: 2px; }
.sd-detail-cards { display: flex; gap: 8px; }
.sd-cell { border: 1px solid #ccc; border-radius: 3px; padding: 10px; min-width: 90px; }
.sd-cell-title { color: #888; font-size: 12px; }
.sd-cell-value { font-size: 14px; font-weight: bold; margin-top: 2px; }
.sd-updated { color: #444; font-size: 12px; margin-bottom: 4px; }

/* 기업 실적·밸류에이션을 차트 옆(예전엔 차트 높이만큼만 확보)이 아니라 맨 위
   (가격/상세정보 줄과 같은 높이)부터 시작하게 해서 세로 공간을 넉넉히 쓴다.
   sd-main-row를 좌(가격+차트)/우(기업 실적) 두 열로 나누고, 좌측 열 안에서만
   가격 줄 다음에 차트를 배치한다. */
.sd-main-row { display: flex; align-items: stretch; gap: 15px; margin-top: 20px; }
.sd-left-col { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.sd-left-col .sd-chart-host { flex: 1 1 auto; min-height: 0; }
.sd-fundamentals { flex: 0 0 300px; }
.sd-fundamentals h4 { margin-top: 0; }
.sd-fundamentals .sd-fund-trend-title { margin-top: 15px; }
.sd-fund-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.sd-fund-cell { border: 1px solid #ccc; border-radius: 3px; min-width: 0; padding: 6px 8px; }
.sd-fund-cell-title { color: #888; font-size: 11px; }
.sd-fund-cell-value { font-size: 13px; font-weight: bold; margin-top: 2px; }
.sd-fund-table { font-size: 11px; }
.sd-fund-table th, .sd-fund-table td { padding: 3px 6px; }
.sd-fund-yoy { margin: 6px 0 0; font-size: 12px; font-weight: bold; color: #333; }
.sd-compare-title { margin: 15px 0 5px; }
.sd-compare-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.sd-compare-cell { border: 1px solid #ccc; border-radius: 3px; min-width: 0; padding: 8px; }
.sd-compare-value { font-size: 18px; font-weight: bold; margin-top: 2px; color: #333; }
.sd-compare-sub { font-size: 10px; color: #888; margin-top: 2px; }

/* 차트 패널 */
.chart-panel { display: flex; flex-direction: column; height: 100%; }
.chart-toolbar { display: flex; align-items: center; gap: 6px; }
.chart-tf-btn { padding: 4px 12px; font-size: 12px; cursor: pointer; border: 1px solid #ccc; background: #fff; border-radius: 2px; }
.chart-tf-btn.active { background: #ddd; font-weight: bold; }
.hint { color: #888; font-size: 11px; margin-left: 8px; }
.chart-indicators, .chart-stoploss { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 12px; margin-top: 4px; }
.chart-check { display: flex; align-items: center; gap: 3px; cursor: pointer; }
.chart-stoploss input[type="text"] { width: 50px; }
.chart-canvas { flex: 1; min-height: 480px; margin-top: 8px; }
