/* Theme View — 카드 그리드 스타일 */

:root {
  --up: #d33;
  --down: #1a73e8;
  --flat: #888;
  --bg: #f6f7fb;
  --card: #ffffff;
  --line: #e7e8ee;
  --text: #1f2330;
  --muted: #6b7280;
  --leader-bg: #fff8d6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Malgun Gothic", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
}

#theme-view {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px;
}

.tv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
  flex-wrap: nowrap;
  gap: 8px;
}

.tv-title {
  font-size: 22px;
  font-weight: 700;
  color: #06b3b9;
}

.tv-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tv-controls label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
}

.tv-controls select,
.tv-controls button {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  font-size: 14px;
  cursor: pointer;
}

#tv-meta {
  color: var(--muted);
  font-size: 13px;
  margin-left: 6px;
}

/* Grid */
.tv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (min-width: 1100px) {
  .tv-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Card */
.tv-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.tv-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #06b3b9;
  color: #fff;
}

.tv-card-name {
  font-weight: 700;
  font-size: 17px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #fff;
}

/* (★ 마크 제거) */

/* 즐겨찾기 별 */
.tv-fav {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 19px;
  line-height: 1;
  padding: 0 2px;
  color: rgba(255, 255, 255, 0.55);
  transition: color 0.15s, transform 0.1s;
}
.tv-fav:hover { color: #ffd84a; transform: scale(1.1); }
.tv-fav.is-on { color: #ffd84a; }
.tv-card.is-fav {
  box-shadow: 0 0 0 1px #ffd84a;
}

.tv-card-avg {
  font-weight: 700;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  padding: 2px 8px;
  border-radius: 4px;
  line-height: 1.5;
}
.tv-card-avg.up { background: #ffe2e2; color: #d33; }
.tv-card-avg.down { background: #e3eefe; color: #1a73e8; }
.tv-card-avg.flat { background: rgba(255, 255, 255, 0.85); color: #555; }

.tv-card-issue {
  padding: 2px 10px 6px;
  color: var(--muted);
  font-size: 13px;
  height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tv-sum-large {
  color: var(--text);
  font-weight: 700;
}

.tv-card-cells {
  display: grid;
  grid-template-columns: 1fr;
}

.tv-cell {
  border-top: 1px solid var(--line);
  padding: 5px 8px 6px;
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.tv-cell.is-leader {
  background: var(--leader-bg);
}

.tv-cell-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  min-width: 0;
}
.tv-cell-row:nth-child(2) {
  gap: 6px;
}
.tv-cell-row:nth-child(2) .tv-cell-amount {
  margin-left: auto;
}

.tv-cell-name {
  font-weight: 600;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 0 1 auto;
  min-width: 0;
}

.tv-cell.is-leader .tv-cell-name::before { content: "👑 "; }

.tv-cell-chg {
  font-weight: 700;
  font-size: 16px;
  flex: 0 0 auto;
  margin-left: auto;
}
.tv-cell-chg.up { color: #d33; }
.tv-cell-chg.down { color: #1a73e8; }
.tv-cell-chg.flat { color: #666; }

.tv-cell-price {
  color: var(--text);
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.tv-cell-amount {
  color: var(--muted);
  font-size: 13px;
  flex: 0 0 auto;
  white-space: nowrap;
}
.tv-cell-amount.is-large {
  color: var(--text);
  font-weight: 700;
}

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

/* 청록 헤더 위에서도 한국 관례 유지: 상승=빨강, 하락=파랑 (가독성 위해 살짝 밝은 톤) */
.tv-card-header .up { color: #ff3b3b; }
.tv-card-header .down { color: #1e88ff; }
.tv-card-header .flat { color: rgba(255, 255, 255, 0.85); }

/* 오늘 일봉 미니 캔들 — 가격/거래대금 행 아래 풀폭 가로 */
.tv-mini-candle-wrap {
  margin-top: 4px;
  width: 100%;
  background: #dde1e8;
  border-radius: 3px;
  padding: 1px 0;
}
.tv-mini-candle {
  width: 100%;
  height: 14px;
  display: block;
}

/* flash on price change */
@keyframes tv-flash-up {
  0% { background-color: rgba(221, 51, 51, 0.18); }
  100% { background-color: transparent; }
}
@keyframes tv-flash-down {
  0% { background-color: rgba(26, 115, 232, 0.18); }
  100% { background-color: transparent; }
}
.tv-flash-up { animation: tv-flash-up 1s ease-out; }
.tv-flash-down { animation: tv-flash-down 1s ease-out; }

.tv-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 40px;
}

/* WS/REST 데이터 소스 표시 */
.tv-src {
  font-size: 11px;
  margin-left: 4px;
  vertical-align: middle;
}
.tv-src-ws { color: #2bb24c; }
.tv-src-rest { color: #b0b6c2; }

/* VI 배지 */
.tv-vi {
  display: inline-block;
  margin-left: 4px;
  padding: 0 4px;
  font-size: 12px;
  font-weight: 700;
  background: #ffefb0;
  color: #b15a00;
  border-radius: 3px;
  border: 1px solid #f0c46d;
}

/* 활성 테마 RT 배지 */
.tv-active {
  display: inline-block;
  margin-left: 6px;
  padding: 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  border-radius: 2px;
  vertical-align: middle;
}
.tv-card.is-active {
  box-shadow: 0 0 0 1px rgba(26, 115, 232, 0.18);
}

/* 뉴스 1줄 — 공간에 맞춰 ellipsis, 셀 높이를 늘리지 않음 */
.tv-news {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 11px;
  color: #6b7484;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  min-width: 0;
}
.tv-news:hover { color: var(--text); }
.tv-news-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 10px;
}
.tv-news-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 카드 헤더 우측 영역 (뉴스개수 + 평균등락률) */
.tv-card-meta {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}
.tv-news-cnt {
  font-size: 12px;
  color: #fff;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 3px;
  padding: 0 4px;
  font-weight: 600;
}

/* 클릭 가능한 셀 */
.tv-cell { cursor: pointer; }
.tv-cell:hover { background: #f7f9fd; }
.tv-cell.is-leader:hover { background: #fff3b8; }
.tv-cell .tv-news { cursor: pointer; }

/* 종목 상세 모달 */
.tv-modal[hidden] { display: none !important; }
.tv-modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.tv-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(20, 25, 40, 0.45);
}
.tv-modal-panel {
  position: relative;
  background: #fff;
  border-radius: 8px;
  width: min(900px, 92vw);
  max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.tv-modal-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}
#tv-modal-title { flex: 1 1 auto; }
.tv-modal-period button {
  border: 1px solid var(--line);
  background: #fff;
  padding: 3px 8px;
  margin-left: 4px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.tv-modal-period button.is-on { background: #1a73e8; color: #fff; border-color: #1a73e8; }
.tv-modal-close {
  border: none; background: transparent;
  font-size: 22px; cursor: pointer; color: var(--muted);
  width: 28px; height: 28px;
}
.tv-modal-body { padding: 14px; overflow: auto; }
.tv-modal-loading { text-align: center; color: var(--muted); padding: 40px; }
.tv-chart svg { display: block; width: 100%; height: auto; }
.tv-chart-meta {
  display: flex; gap: 16px; margin-bottom: 8px;
  color: var(--muted); font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.tv-chart-meta b { color: var(--text); }

/* ============ 모바일 (≤600px) — 카드 4개 한 화면, 1줄 헤더 ============ */
@media (max-width: 600px) {
  body { font-size: 12px; }
  #theme-view { padding: 6px; }

  /* 1줄 헤더 강제 + 컨트롤 압축 */
  .tv-header {
    padding: 4px 0 6px;
    margin-bottom: 6px;
    gap: 4px;
    overflow: hidden;
  }
  .tv-title { font-size: 13px; flex: 0 0 auto; }
  .tv-controls { gap: 3px; flex: 1 1 auto; justify-content: flex-end; }
  .tv-controls label {
    font-size: 10px;
    gap: 2px;
  }
  .tv-controls select,
  .tv-controls button {
    padding: 1px 4px;
    font-size: 10px;
    border-radius: 3px;
  }
  /* 새로고침은 아이콘만 */
  #tv-refresh .tv-btn-label { display: none; }
  #tv-refresh { font-size: 14px; padding: 1px 6px; line-height: 1; }
  #tv-meta { display: none; }

  /* 카드 그리드 — 1열 유지하되 카드 자체를 압축 */
  .tv-grid { gap: 6px; }

  /* 카드 헤더 압축 */
  .tv-card-header { padding: 4px 8px; }
  .tv-card-name { font-size: 12px; gap: 4px; }
  .tv-card-issue {
    padding: 1px 8px 3px;
    font-size: 9px;
    height: auto;
    line-height: 1.2;
  }
  .tv-card-avg { font-size: 11px; padding: 1px 5px; border-radius: 3px; }
  .tv-news-cnt { display: none; }
  .tv-active { font-size: 8px; padding: 0 3px; margin-left: 4px; }
  .tv-fav { font-size: 14px; padding: 0; }  /* 즐겨찾기 모바일에서도 표시 (살짝 작게) */

  /* 셀 압축 */
  .tv-cell { padding: 3px 6px 3px; }
  .tv-cell-row { gap: 4px; }
  .tv-cell-name { font-size: 11px; }
  .tv-cell-chg { font-size: 11px; }
  .tv-cell-price { font-size: 11px; }
  .tv-cell-amount { font-size: 9px; }
  .tv-src { display: none; }

  /* 일봉 살짝 줄임 */
  .tv-mini-candle-wrap { margin-top: 2px; }
  .tv-mini-candle { height: 8px; }

  /* 뉴스: 압축해서 표시 */
  .tv-news { font-size: 9px; margin-top: 2px; gap: 4px; }
  .tv-news-time { font-size: 8px; }

  /* 모달 풀스크린 */
  .tv-modal-panel {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
  .tv-modal-header { padding: 8px 10px; }
  .tv-modal-body { padding: 8px; }
}
