:root {
  --bg: #0f1115;
  --panel: #161a22;
  --border: #232936;
  --text: #e6e8eb;
  --muted: #8a93a6;
  --accent: #4f8cff;
  --pos: #19b478;
  --neg: #e5484d;
  --warn: #f5a623;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Pretendard", "Noto Sans KR", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.brand .tag {
  font-size: 11px; color: var(--muted);
  padding: 2px 6px; border: 1px solid var(--border); border-radius: 8px;
}
.top nav { display: flex; gap: 4px; flex: 1; align-items: center; flex-wrap: wrap; }
.top nav a {
  padding: 6px 10px; border-radius: 6px; color: var(--muted);
}
.top nav a:hover { background: var(--fill-100); color: var(--text); }
.top nav a.active { background: var(--brand-red-soft); color: var(--brand-red); }

/* 매매 메뉴 그룹 — 3개 페이지(시그널매매/단기매매/장기매매) 를 시각적으로 묶음 */
.top nav .nav-group {
  display: inline-flex; gap: 2px; align-items: center;
  padding: 2px 4px; margin: 0 2px;
  background: var(--fill-100); border: 1px solid var(--line); border-radius: 8px;
  position: relative;
}
.top nav .nav-group::before {
  content: "매매";
  font-size: 0.65rem; color: #6b7488; letter-spacing: 1px;
  padding: 0 6px 0 4px;
  border-right: 1px solid #2c3344; margin-right: 2px;
}
.top nav .nav-group a { padding: 6px 8px; }

.hamburger {
  display: none;
  width: 36px; height: 36px;
  padding: 0; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; cursor: pointer;
  flex-direction: column; justify-content: center; align-items: center; gap: 4px;
}
.hamburger span {
  display: block; width: 18px; height: 2px; background: var(--text); border-radius: 1px;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
.hamburger.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.status-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: #fff;
  font-size: 12px; color: var(--muted);
}
.status-pill .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
}
.status-pill.running .dot { background: var(--accent); animation: pulse 1.2s infinite; }
.status-pill.ok      .dot { background: var(--pos); }
.status-pill.failed  .dot { background: var(--neg); }
.status-pill.partial .dot { background: var(--warn); }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(79,140,255,0.55); }
  100% { box-shadow: 0 0 0 8px rgba(79,140,255,0);   }
}

main { padding: 18px; }

.row { display: grid; gap: 14px; }
.row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.card h2 { font-size: 14px; margin: 0 0 8px; color: var(--muted); }
.card .num { font-size: 22px; font-weight: 600; }

.toolbar {
  display: flex; gap: 8px; align-items: center;
  margin-bottom: 10px;
}
.toolbar select, .toolbar input, .toolbar button {
  background: #fff; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; font-size: 13px;
}
.toolbar button { cursor: pointer; }
.toolbar button:hover { border-color: var(--accent); }

table.data {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.data th, table.data td {
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  text-align: right; white-space: nowrap;
}
table.data th { color: var(--muted); font-weight: 500; text-align: right; background: var(--fill-100); position: sticky; top: 50px; }
.tbl-scroll { position: relative; }
.tbl-scroll table.data th { position: static; top: auto; }
table.data th.left, table.data td.left { text-align: left; }
table.data tbody tr:hover { background: var(--fill-100); }
table.data tbody tr.selected { background: var(--brand-red-soft); }
table.data tbody tr.selected:hover { background: var(--brand-red-soft); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }

.bottom {
  padding: 12px 18px;
  display: flex; justify-content: space-between;
  color: var(--muted); font-size: 12px;
  border-top: 1px solid var(--border);
}

.chart-wrap { position: relative; height: 280px; }
/* Top20 막대그래프: 항목 2배라 카드 높이도 ~2배로 늘려 막대 두께 유지 (Top10 과 동일 두께). */
.chart-wrap.chart-wrap-tall { height: 560px; }

.brief-col h3.brief-mkt { margin: 0 0 10px; font-size: 1.05rem; }
.brief-section { margin-bottom: 12px; }
.brief-section:last-child { margin-bottom: 0; }
.brief-stitle { margin: 0 0 6px; font-size: 0.92rem; color: var(--text); font-weight: 600; }
.brief-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
.brief-block { background: var(--fill-100); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; min-width: 0; }
.brief-block h5 { margin: 0 0 6px; font-size: 0.82rem; color: var(--muted); font-weight: 500; }
.brief-block ol { margin: 0; padding-left: 18px; font-size: 0.85rem; }
.brief-block li { margin: 2px 0; }
.brief-block li span { margin-left: 6px; }

/* 시그널 카드 (모바일 전용) */
.sig-cards { display: none; }
.sig-card {
  background: var(--fill-100); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 6px;
}
.sig-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sig-name { font-weight: 600; font-size: 14px; flex: 1; min-width: 0; }
.sig-badge {
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: var(--fill-100); color: var(--ink-700); border: 1px solid var(--line-strong); white-space: nowrap;
}
.sig-badge.sig-continued_buy { background: var(--brand-blue-soft); border-color: transparent; color: var(--brand-blue); }
.sig-badge.sig-accel_buy { background: #FFF4D6; border-color: transparent; color: #8B6500; }
.sig-badge.sig-consensus { background: #EEEAFD; border-color: transparent; color: #5B47C0; }
.sig-badge.sig-single_strong { background: var(--up-soft); border-color: transparent; color: var(--up); }
.sig-badge.sig-multi_signal { background: #FFEDD6; border-color: transparent; color: #C26515; }
.sig-badge.sig-upper-limit { background: var(--brand-red); border-color: transparent; color: #fff; font-weight: 600; }
.upper-limit-row { background: var(--brand-red-soft); }
.upper-limit-row:hover { background: var(--brand-red-soft); }

/* 프리미엄 시그널: 룰/요약 */
.rule-list { margin: 4px 0 10px; padding-left: 18px; font-size: 13px; color: var(--ink-700); }
.rule-list li { margin: 3px 0; }
.rule-list span { color: var(--muted); }
.summary-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 6px; margin-top: 6px;
}
.summary-grid .kv {
  background: var(--fill-100); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; display: flex; flex-direction: column; gap: 2px;
}
.summary-grid .k { font-size: 11px; color: var(--muted); }
.summary-grid .v { font-size: 15px; font-weight: 600; }
.sig-closed { font-size: 11px; color: var(--muted); }
.sig-price { display: flex; align-items: baseline; gap: 6px; font-size: 14px; }
.sig-arrow { color: var(--muted); }
.sig-roi { margin-left: auto; font-size: 15px; }
.sig-mfe { font-size: 12px; }
.sig-meta { font-size: 12px; }
.sig-row { display: flex; flex-direction: column; gap: 4px; padding-top: 6px; border-top: 1px dashed #1e2533; }
.sig-row:first-of-type { border-top: none; padding-top: 0; }
.sig-row-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sig-sib-count {
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: #EEEAFD; border: 1px solid transparent; color: #5B47C0; white-space: nowrap;
}
/* 표 종목 그룹: 같은 종목의 두 번째 row 이후엔 윗 경계선을 점선으로 흐림 */
tr.sig-cont > td { border-top: 1px dashed #1e2533; }

@media (max-width: 720px) {
  body { font-size: 13px; }
  main { padding: 12px; }

  /* 모바일에선 sig-cards 가 함께 있는 페이지(briefing/longterm) 의 표만 숨김.
     실시간/순위/급변 처럼 카드 변환이 없는 페이지는 표를 그대로 노출.
     :has() 셀렉터 미지원 브라우저 대비 — 명시 클래스 .card.has-sig-cards 사용. */
  .card.has-sig-cards #tbl { display: none; }
  .sig-cards { display: flex; flex-direction: column; gap: 8px; }

  .top { padding: 8px 10px; gap: 8px; flex-wrap: wrap; }
  .brand { font-size: 14px; flex: 1; min-width: 0; }
  .brand .tag { display: none; }
  .hamburger { display: flex; order: 2; }
  /* status-pill 은 brand/hamburger 다음 줄로 — 모바일에서 한 줄이 너무 좁아 가독성이 떨어지는 문제 해소. */
  .status-pill {
    order: 3; width: 100%;
    padding: 4px 10px; font-size: 11px;
    justify-content: flex-start;
    margin-top: 4px; padding-top: 6px;
  }
  .top nav {
    order: 4; width: 100%;
    display: none; flex-direction: column; gap: 2px;
    padding-top: 6px; border-top: 1px solid var(--border);
    margin-top: 4px;
  }
  .top nav.open { display: flex; }
  .top nav a {
    padding: 10px 12px; font-size: 14px;
    border-radius: 6px;
  }
  /* 모바일: 매매 그룹도 세로로 + ::before 라벨은 헤더로 표시 */
  .top nav .nav-group {
    display: flex; flex-direction: column; gap: 2px;
    margin: 4px 0; padding: 4px 4px 6px;
  }
  .top nav .nav-group::before {
    border-right: none; border-bottom: 1px solid #2c3344;
    padding: 2px 4px; margin: 0 0 4px;
  }

  .row.two, .row.three { grid-template-columns: 1fr; }

  .card { padding: 12px; overflow-x: auto; }
  .card h2 { font-size: 13px; }
  .card .num { font-size: 18px; }

  .toolbar { flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
  .toolbar label { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
  .toolbar select, .toolbar input, .toolbar button { padding: 5px 8px; font-size: 12px; }

  /* 차트 영역 높이는 데스크탑(280/560px) 그대로 유지 — 모바일에서 막대 두께가 짓눌리는 것 방지. */

  table.data { font-size: 12px; }
  table.data th, table.data td { padding: 6px 8px; }
  table.data th { position: static; top: auto; }

  .brief-col h3.brief-mkt { font-size: 0.98rem; margin: 0 0 8px; }
  .brief-section { margin-bottom: 10px; }
  .brief-stitle { font-size: 0.88rem; }
  .brief-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 6px; }
  .brief-block { padding: 6px 8px; }
  .brief-block h5 { font-size: 0.78rem; }
  .brief-block ol { padding-left: 16px; font-size: 0.8rem; }

  .bottom { padding: 10px 12px; flex-wrap: wrap; gap: 4px; font-size: 11px; }

  .snap-btn { top: 8px !important; right: 8px !important; padding: 3px 8px !important; font-size: 0.75rem !important; }
}

@media (max-width: 480px) {
  .brief-grid { grid-template-columns: 1fr; }
  /* 차트 영역 높이는 데스크탑 값 그대로 유지. */
}

/* 시그널/프리미엄 종목 상세 사이드 패널.
   데스크탑: 우측에서 슬라이드인 (table 의 종목 컬럼 정도 가린 안 남기고 데이터 컬럼만 덮음).
   모바일: 종래대로 카드 아래 표시. */
#detail-card.side-open,
#sn-panel.side-open {
  position: fixed;
  top: 64px;
  right: 0;
  bottom: 0;
  width: min(62vw, 880px);
  margin: 0 !important;
  overflow-y: auto;
  z-index: 50;
  box-shadow: -8px 0 24px rgba(0,0,0,0.5);
  border-left: 1px solid var(--border);
  border-radius: 0;
}
.detail-close {
  position: absolute; top: 10px; right: 12px;
  background: var(--fill-100); color: #e6e8eb; border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 3px 10px; font-size: 0.95rem; cursor: pointer;
  z-index: 1;
}
.detail-close:hover { background: var(--fill-200); }

/* 데스크탑 슬라이드인 패널: 닫기 버튼을 패널의 좌측 경계 한가운데로 튀어나오게.
   카드 자체가 overflow-y:auto 라 내부 absolute 가 잘릴 수 있어 fixed 로 뷰포트 기준 배치. */
#detail-card.side-open .detail-close,
#sn-panel.side-open .detail-close {
  position: fixed;
  top: 50%; right: min(62vw, 880px); left: auto;
  transform: translate(50%, -50%);
  width: 32px; height: 64px;
  padding: 0; font-size: 1.4rem; line-height: 1;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 60;
}

@media (max-width: 720px) {
  /* 모바일은 화면 전체 오버레이 — iframe 이 dvh 기반으로 풀스크린.
     아이폰 사파리에서 iframe height:100% + parent static 조합이 0 으로 잡히는 케이스 회피. */
  #detail-card.side-open,
  #sn-panel.side-open {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0;
    border-left: none;
    box-shadow: none;
    z-index: 100;
    overflow: hidden;
  }
  #sn-panel.side-open #sn-iframe {
    width: 100% !important;
    height: 100vh !important;          /* 모든 모바일 브라우저 폴백 */
    height: 100dvh !important;         /* 지원 브라우저는 주소창 변동 반영 */
    min-height: 100vh !important;
    display: block !important;
  }
  #detail-card.side-open .detail-close,
  #sn-panel.side-open .detail-close {
    position: fixed;
    top: 10px; left: auto; right: 10px;
    transform: none;
    width: 40px; height: 40px;
    padding: 0; font-size: 1.4rem; line-height: 1;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 101;
  }
  body.sn-open { overflow: hidden; }
}
