/* ═══════════════════════════════════════════════════════════
   단기매매 대시보드

   설계 원칙
   1. 색은 정보일 때만 쓴다. 손익은 초록/빨강, 그 외는 무채색.
   2. 위계는 크기와 여백으로 만든다. 박스를 겹치지 않는다.
   3. 숫자는 등폭으로 자릿수를 맞춘다. 표는 눈으로 훑는 물건이다.
   4. 장이 밤에 열리므로(한국시간 22:30~05:00) 다크가 기본이다.
   ═══════════════════════════════════════════════════════════ */

:root {
  /* 배경 — 순검정 대신 아주 옅은 청회색. 장시간 봐도 덜 피로하다 */
  --bg:        #101215;
  --surface:   #16191d;
  --surface-2: #1c2025;
  --line:      #262b31;
  --line-soft: #1e2227;

  /* 글자 */
  --text:      #e4e7ea;
  --text-dim:  #9aa1aa;
  --text-mute: #6b727b;

  /* 강조 — 선택·활성에만. 채도를 낮춰 손익 색과 다투지 않게 한다 */
  --accent:    #6f96d1;
  --accent-dim: rgba(111, 150, 209, .13);

  /* 손익 */
  --up:        #46b17f;
  --down:      #dd6058;
  --flat:      var(--text-mute);
  --warn:      #c79a4b;

  --radius: 8px;
  --gap: 16px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont,
               "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* 숫자는 어디서나 등폭 — 표에서 자릿수가 흔들리면 읽기 어렵다 */
.figure, .figure-sub, td, .metric dd, .stat-num, input {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ── 상단바 ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 52px;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: baseline; gap: 9px; }
.brand strong { font-size: 14px; font-weight: 620; letter-spacing: -.01em; }
.brand .muted { font-size: 11px; }
.brand .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  align-self: center;
}

.topbar nav { display: flex; gap: 2px; margin-left: 8px; }
.topbar nav a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  padding: 5px 11px;
  border-radius: 6px;
  transition: color .12s, background .12s;
}
.topbar nav a:hover { color: var(--text); background: var(--surface-2); }
.topbar nav a.on { color: var(--text); background: var(--surface-2); }

.clock {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
}
.tzl { color: var(--text-mute); font-size: 10.5px; }

/* 시장 상태 — 알약 대신 점 하나로. 배지가 많으면 다 안 보인다 */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 550;
  color: var(--text-dim);
  background: none; padding: 0;
}
.badge::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-mute);
}
.badge.open    { color: var(--up); }
.badge.open::before {
  background: var(--up);
  box-shadow: 0 0 0 3px rgba(70, 177, 127, .16);
}
.badge.pre     { color: var(--warn); }
.badge.pre::before { background: var(--warn); }
.badge.holiday { color: var(--down); }
.badge.holiday::before { background: var(--down); }

/* ── 레이아웃 ───────────────────────────────────────────── */
main {
  max-width: 1560px;
  margin: 0 auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.row { display: flex; gap: var(--gap); flex-wrap: wrap; }
.row > .card { flex: 1 1 380px; }
.spacer { flex: 1; }

/* ── 패널 ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
}

.card h2 {
  margin: 0;
  padding: 13px 18px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.card h2 .muted, .card h2 .sub { font-weight: 400; }

/* 패널 본문은 h2 다음 요소들에 패딩을 준다 (자체 패딩이 있는 것은 제외) */
.card > *:not(h2):not(table):not(.scroll):not(.hero):not(.metrics):not(.chart) {
  padding-left: 18px; padding-right: 18px;
}
.card > *:last-child:not(h2):not(table):not(.scroll):not(.metrics):not(.chart) {
  padding-bottom: 16px;
}

/* ── 계좌 요약 ──────────────────────────────────────────── */
.hero {
  display: flex;
  align-items: flex-start;
  gap: 44px;
  padding: 20px 18px 18px;
  flex-wrap: wrap;
}
.hero-block { display: flex; flex-direction: column; gap: 3px; }
.hero-block.narrow { min-width: 90px; }
.hero-side {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}

.label {
  font-size: 11px;
  color: var(--text-mute);
  letter-spacing: .02em;
}
.figure {
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -.022em;
  line-height: 1.15;
}
.figure-sub { font-size: 11.5px; color: var(--text-mute); }

/* 보조 지표 — 큰 숫자 아래 조용한 한 줄 */
.metrics {
  display: flex;
  margin: 0;
  border-top: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.metric {
  padding: 11px 18px;
  border-right: 1px solid var(--line-soft);
  min-width: 118px;
}
.metric:last-child { border-right: none; }
.metric dt { font-size: 11px; color: var(--text-mute); margin-bottom: 2px; }
.metric dd { margin: 0; font-size: 14px; font-weight: 550; }

/* ── 표 ─────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
th {
  padding: 9px 10px;
  text-align: right;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-mute);
  letter-spacing: .02em;
  white-space: nowrap;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
}
td {
  padding: 9px 10px;
  text-align: right;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
th:first-child, td:first-child { padding-left: 18px; }
th:last-child,  td:last-child  { padding-right: 18px; }
td.l, th.l { text-align: left; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255, 255, 255, .017); }

.scroll { max-height: 620px; overflow: auto; }

/* 종목 코드 */
.tk { font-weight: 620; letter-spacing: -.01em; }
.sub  { font-size: 11px; color: var(--text-mute); line-height: 1.4; }
.muted { color: var(--text-dim); }
.up   { color: var(--up); }
.down { color: var(--down); }
.warn { color: var(--warn); }
.krw  { font-size: 10.5px; color: var(--text-mute); margin-top: 1px; }

/* 상태 표시 — 채운 알약 대신 얇은 테두리. 개수가 많아도 시끄럽지 않다 */
.pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-dim);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.pill.go { color: var(--accent); border-color: rgba(111, 150, 209, .38); }
.pill.no { color: var(--text-mute); }

/* 선정된 종목 — 배경 대신 왼쪽 선 하나 */
tr.top-pick td { background: var(--accent-dim); }
tr.top-pick td:first-child { box-shadow: inset 2px 0 0 var(--accent); }

.rank { display: inline-block; min-width: 16px; color: var(--text-mute); }
.rank.in { color: var(--accent); font-weight: 650; }

/* ── 버튼 ───────────────────────────────────────────────── */
button {
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 13px;
  transition: border-color .12s, background .12s, color .12s;
}
button:hover:not(:disabled) { border-color: #343a42; background: #21262c; }
button:active:not(:disabled) { transform: translateY(.5px); }
button:disabled { opacity: .4; cursor: not-allowed; }

button.primary {
  background: var(--accent); border-color: var(--accent); color: #0d1116; font-weight: 550;
}
button.primary:hover:not(:disabled) { background: #7ea3da; border-color: #7ea3da; }

button.buy  { color: var(--up);   border-color: rgba(70, 177, 127, .42); background: rgba(70, 177, 127, .1); }
button.buy:hover:not(:disabled)  { background: rgba(70, 177, 127, .18); border-color: var(--up); }
button.sell { color: var(--down); border-color: rgba(221, 96, 88, .35);  background: rgba(221, 96, 88, .08); }
button.sell:hover:not(:disabled) { background: rgba(221, 96, 88, .16); border-color: var(--down); }

button.sm { padding: 3px 9px; font-size: 11.5px; }

.tabs { display: flex; gap: 1px; background: var(--line); border-radius: 6px; padding: 1px; }
.tabs button { border: none; border-radius: 5px; background: transparent; color: var(--text-dim); }
.tabs button:hover { background: var(--surface-2); }
.tabs button.on { background: var(--surface-2); color: var(--text); font-weight: 550; }

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding-top: 12px; }

/* ── 입력 ───────────────────────────────────────────────── */
.field {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 11px; color: var(--text-mute);
  min-width: 150px; flex: 1;
}
.field input, .field select {
  font: inherit; font-size: 13px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  width: 100%;
  transition: border-color .12s;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--accent);
}
.field input:disabled { opacity: .4; }
.field select { cursor: pointer; }

/* 2단계 선별 설정 — 박스 대신 왼쪽 선으로 묶는다 */
.stage-box {
  margin-top: 16px;
  padding-left: 14px !important;
  border-left: 2px solid var(--line);
}
.stage-title {
  font-size: 11.5px; font-weight: 600; color: var(--text-dim);
  margin-bottom: 2px;
}

#settings-panel { border-top: 1px solid var(--line-soft); padding-top: 16px; margin-top: 0; }

/* ── 매수 근거 / 채점 ───────────────────────────────────── */
.ev {
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 13px 15px;
  margin: 4px 0 8px;
}
.ev-row {
  margin-bottom: 8px;
  display: flex; gap: 9px; align-items: center; flex-wrap: wrap;
}
.ev-k {
  color: var(--text-mute); font-size: 11px;
  min-width: 128px;
}
.ev-table { width: auto; font-size: 11.5px; }
.ev-table td, .ev-table th {
  border: none;
  padding: 3px 18px 3px 0;
  text-align: left;
  background: none;
}
.ev-table thead th {
  position: static;
  color: var(--text-mute);
  font-size: 10.5px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-soft);
}
.ev-table tbody tr:hover td { background: none; }
.ev-table tr.chk-no td { opacity: .45; }

/* 지표 한 쌍 — 배지 대신 라벨+값. 개수가 많아도 시끄럽지 않다 */
.kv { font-size: 11.5px; margin-right: 15px; white-space: nowrap; }
.kv i {
  font-style: normal; color: var(--text-mute);
  margin-right: 5px; font-size: 10.5px;
}

/* 점수 막대 */
.bar {
  width: 76px; height: 3px; border-radius: 2px;
  background: var(--line); overflow: hidden;
}
.bar-fill { height: 100%; background: var(--accent); border-radius: 2px; }

/* 접기/펼치기 */
details.why summary,
details.trades summary {
  cursor: pointer;
  color: var(--text-mute);
  font-size: 10.5px;
  list-style: none;
  padding: 1px 0;
  transition: color .12s;
}
details.why summary::-webkit-details-marker,
details.trades summary::-webkit-details-marker { display: none; }
details.why summary:hover,
details.trades summary:hover { color: var(--accent); }
details.why summary::after { content: ' ▾'; opacity: .5; }
details.why[open] summary::after { content: ' ▴'; opacity: .5; }
details.trades table { margin-top: 8px; }

/* ── 자산 곡선 ──────────────────────────────────────────── */
.chart { width: 100%; height: 200px; display: block; padding: 4px 18px 12px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 1.75; }
.chart .area { fill: rgba(111, 150, 209, .09); }
.chart .base { stroke: var(--line); stroke-dasharray: 2 4; }

/* ── 기타 ───────────────────────────────────────────────── */
.empty {
  color: var(--text-mute);
  text-align: center;
  padding: 34px 0;
  font-size: 12.5px;
}

.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(14px);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 12.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: rgba(221, 96, 88, .5); color: var(--down); }

/* 스크롤바 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #2a2f36; border-radius: 5px;
  border: 2px solid var(--surface);
}
::-webkit-scrollbar-thumb:hover { background: #363c44; }

/* ── 좁은 화면 ──────────────────────────────────────────── */
@media (max-width: 860px) {
  .topbar { height: auto; padding: 10px 14px; flex-wrap: wrap; gap: 10px; }
  .clock { margin-left: 0; width: 100%; gap: 12px; flex-wrap: wrap; }
  main { padding: 14px; }
  .hero { gap: 26px; padding: 16px 14px; }
  .figure { font-size: 23px; }
  .metric { min-width: 50%; border-right: none; }
  th:first-child, td:first-child { padding-left: 14px; }
  th:last-child,  td:last-child  { padding-right: 14px; }
}
