/* ============================================================
   기본 리셋 & 변수
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg2: #161922;
  --bg3: #1e2231;
  --border: #2a2f42;
  --text: #e2e8f0;
  --text2: #8a8fa8;
  --blue: #4f8ef7;
  --green: #34d399;
  --red: #f87171;
  --orange: #fb923c;
  --radius: 10px;
  --sidebar-w: 360px;
}

html, body { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ============================================================
   레이아웃
   ============================================================ */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── 사이드바 ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px 20px 40px;
  gap: 16px;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

#backtest-form,
#trading-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#result,
#t-result {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── 메인 영역 ── */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ============================================================
   카드 공통
   ============================================================ */
.card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text2);
}

/* ============================================================
   폼 요소
   ============================================================ */
.form-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.form-row label {
  width: 120px;
  flex-shrink: 0;
  color: var(--text2);
  font-size: 13px;
}

.form-row input[type="number"],
.form-row input[type="text"],
.form-row input[type="date"] {
  flex: 1;
  min-width: 90px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.form-row input:focus {
  border-color: var(--blue);
}

.hint {
  font-size: 11px;
  color: var(--text2);
  flex-basis: 100%;
  padding-left: 130px;
}

/* ── 시장 토글 ── */
.toggle-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.toggle-btn {
  padding: 8px 18px;
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.toggle-btn.active {
  background: var(--blue);
  color: #fff;
}

/* ── 심볼 입력 ── */
.symbol-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
}
.symbol-input-wrap input { flex: 1; }
.symbol-status {
  font-size: 12px;
  white-space: nowrap;
}
.symbol-status.ok  { color: var(--green); }
.symbol-status.ng  { color: var(--red); }
.symbol-status.checking { color: var(--text2); }

/* ── 토글 스위치 ── */
.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 22px;
  cursor: pointer;
  transition: background 0.2s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.switch input:checked + .slider { background: var(--blue); }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* ── 비율 입력 ── */
.ratio-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.ratio-item {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
.tier-label {
  font-size: 11px;
  color: var(--text2);
  width: 22px;
  flex-shrink: 0;
}
.ratio-input,
.t-ratio-input {
  flex: 1;
  width: 0;
  min-width: 0;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  outline: none;
  text-align: right;
}
.ratio-item span:last-child { font-size: 12px; color: var(--text2); }

.ratio-sum-row {
  font-size: 12px;
  color: var(--text2);
  text-align: right;
}
.ratio-sum-row .ok { color: var(--green); margin-left: 4px; }
.ratio-sum-row .ng { color: var(--red); margin-left: 4px; }

/* ── 실행 버튼 ── */
.run-btn {
  width: 100%;
  padding: 14px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  margin-top: 4px;
}
.run-btn:hover { opacity: 0.88; }
.run-btn:active { transform: scale(0.98); }

/* ============================================================
   결과 영역
   ============================================================ */

/* ── Placeholder ── */
.placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text2);
}
.placeholder-icon { font-size: 48px; }

/* ── 로딩 ── */
.loading {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text2);
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 에러 ── */
.error-box {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--red);
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── 숨김 ── */
.hidden { display: none !important; }

/* ── 요약 카드 ── */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.summary-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sc-label { font-size: 12px; color: var(--text2); }
.sc-value { font-size: 22px; font-weight: 700; }

/* ── 색상 헬퍼 ── */
.pos { color: var(--green); }
.neg { color: var(--red); }

/* ── 차트 카드 ── */
.chart-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.chart-card h2 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text2);
}
.chart-wrap {
  position: relative;
  height: 260px;
}

/* ── 테이블 카드 (시즌 요약 / 체결 내역 공통) ── */
.table-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.table-card h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.trade-count {
  font-size: 12px;
  font-weight: 400;
  color: var(--text2);
}
.open-badge {
  font-size: 11px;
  font-weight: 600;
  background: rgba(251, 146, 60, 0.15);
  color: var(--orange);
  border: 1px solid rgba(251, 146, 60, 0.3);
  border-radius: 4px;
  padding: 2px 7px;
}
.table-scroll {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  text-align: left;
  padding: 7px 10px;
  background: var(--bg3);
  color: var(--text2);
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  white-space: nowrap;
}
tbody tr:hover { background: rgba(79, 142, 247, 0.04); }

/* ── 배지 ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.badge.buy    { background: rgba(52, 211, 153, 0.15); color: var(--green); }
.badge.sell   { background: rgba(79, 142, 247, 0.15); color: var(--blue); }
.badge.forced { background: rgba(248, 113, 113, 0.15); color: var(--red); }

/* ============================================================
   탭 네비게이션
   ============================================================ */
.tab-nav {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.tab-nav .tab-btn {
  flex: 1;
  padding: 10px 0;
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  text-align: center;
}
.tab-nav .tab-btn.active {
  background: var(--blue);
  color: #fff;
  font-weight: 600;
}
.tab-nav .tab-btn:not(.active):hover {
  background: var(--bg3);
  color: var(--text);
}

/* ── 사이드바 탭 패널 ── */
.sidebar-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sidebar-panel.hidden { display: none !important; }

/* ── 메인 탭 패널 ── */
.main-panel { display: contents; }
.main-panel.hidden { display: none !important; }

/* ── 섹션 레이블 ── */
.section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text2);
  margin-bottom: 4px;
}

/* ── 4열 카드 그리드 (자산 수익률) ── */
.summary-cards-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

/* ============================================================
   반응형
   ============================================================ */
@media (max-width: 900px) {
  .app { flex-direction: column; height: auto; overflow: visible; }
  .sidebar { width: 100%; min-width: unset; border-right: none; border-bottom: 1px solid var(--border); }
  .main { padding: 16px; }
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
  .summary-cards-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 500px) {
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
  .ratio-grid { grid-template-columns: repeat(2, 1fr); }
}
