:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --card: #ffffff;
  --card2: #fbfcfd;
  --line: #e3e6ea;
  --ink: #1f2328;
  --dim: #6a7178;
  --up: #f04452;
  --down: #3182f6;
  --blue: #3182f6;
  --green: #2fa86d;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --card: #171a20;
  --card2: #1c2027;
  --line: #282d36;
  --ink: #e9ecf1;
  --dim: #9aa2ad;
  --up: #f4675f;
  --down: #6d9bff;
  --blue: #3987e5;
  --green: #3fbb7d;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--dim);
}

input::placeholder {
  color: var(--dim);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

html, body {
  height: 100%;
  overflow: hidden; /* 전체 페이지 바깥 스크롤 완벽 제거 */
}

/* 상단 매크로 배너 */
.macro-banner {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px;
  display: flex;
  gap: 20px;
  overflow-x: auto;
  white-space: nowrap;
  font-size: 13px;
  height: 38px;
}
.macro-item { display: flex; gap: 6px; align-items: center; }
.macro-label { color: var(--dim); }
.macro-val { font-weight: 600; }

/* 메인 관제탑 3분할 레이아웃 (PC 와이드 - 상단 바 높이 정밀 차감) */
.dashboard-grid {
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  height: calc(100vh - 71px); /* 매크로바 38px + 유저바 33px = 71px */
  overflow: hidden;
}

/* 좌측 패널 (자산 요약 + 종목 리스트) */
.left-panel {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  background: var(--card);
}
.account-box {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card2);
}
.acc-title { font-size: 12px; color: var(--dim); }
.acc-total { font-size: 22px; font-weight: 700; margin: 4px 0; }
.acc-sub { font-size: 13px; display: flex; justify-content: space-between; }

.stock-list {
  flex: 1;
  overflow-y: auto;
}
.stock-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background 0.15s;
}
.stock-item:hover, .stock-item.active { background: var(--card2); }
.st-name { font-weight: 600; font-size: 14px; }
.st-ticker { font-size: 11px; color: var(--dim); }
.st-price { text-align: right; }
.st-cur { font-weight: 700; font-size: 15px; }
.st-chg { font-size: 12px; font-weight: 600; }
.up { color: var(--up); }
.down { color: var(--down); }

/* 중앙 패널 (실시간 SVG 차트) */
.center-panel {
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow-y: auto;
}
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.chart-title { font-size: 18px; font-weight: 700; }
.timeframe-group {
  display: flex;
  gap: 4px;
  background: var(--card2);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.tf-btn {
  background: none;
  border: none;
  color: var(--dim);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tf-btn:hover {
  color: var(--ink);
}
.tf-btn.active {
  background: var(--card);
  color: var(--blue);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.chart-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  height: 410px;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* 네모 상자 밖으로 내용이 절대 삐져나가지 않도록 차단 */
}
.chart-stats-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11.5px;
  padding: 5px 10px;
  margin-bottom: 8px;
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow-x: auto;
  white-space: nowrap;
  user-select: none;
}
.cs-item {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  color: var(--dim);
}
.cs-item strong {
  font-weight: 700;
  color: var(--ink);
}
.cs-item strong.up { color: var(--up); }
.cs-item strong.down { color: var(--down); }
.svg-container { flex: 1; width: 100%; position: relative; user-select: none; overflow: hidden; cursor: grab; touch-action: none; }
.mobile-back-btn { display: none; }
svg { width: 100%; height: 100%; overflow: visible; }
.chart-tooltip {
  display: none;
  position: absolute;
  pointer-events: none;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 10;
  transform: translate(-50%, -120%);
  white-space: nowrap;
}

/* 우측 패널 (Gemini AI 피드) */
.right-panel {
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  background: var(--card);
}
.feed-header {
  padding: 14px 16px;
  font-weight: 700;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
}
.feed-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.feed-card {
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  font-size: 13px;
}
.feed-time { font-size: 11px; color: var(--dim); margin-bottom: 4px; }
.feed-title { font-weight: 700; margin-bottom: 6px; }
.feed-desc { white-space: pre-wrap; font-family: inherit; font-size: 12px; line-height: 1.6; color: var(--ink); }

/* 모바일 반응형 1열 수직 플로우 모드 (화면 폭 900px 이하) */
@media (max-width: 900px) {
  html, body {
    height: auto !important;
    min-height: 100% !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  /* 상단 매크로 배너: 가로 스크롤 대신 2~3줄 자동 래핑 */
  .macro-banner {
    height: auto !important;
    min-height: 38px;
    flex-wrap: wrap !important;
    gap: 6px 14px !important;
    padding: 8px 12px !important;
    white-space: normal !important;
    overflow-x: visible !important;
    font-size: 11.5px !important;
  }
  .macro-item {
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
  }

  /* 3분할 그리드 -> 수직 1열 플로우 */
  .dashboard-grid {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* 1. 좌측 패널 (자산 요약 + 종목 목록) */
  .left-panel {
    border-right: none !important;
    border-bottom: 1px solid var(--line);
    height: auto !important;
    overflow: visible !important;
  }
  .stock-list {
    max-height: 280px;
    overflow-y: auto;
  }
  .stock-item {
    padding: 13px 14px;
  }

  /* 2. 중앙 차트 패널 (종목 클릭 시 아래에 바로 표시) */
  .center-panel {
    display: flex !important;
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    height: auto !important;
    overflow: visible !important;
  }
  .chart-box {
    height: 380px;
    padding: 10px 8px;
  }
  .chart-title {
    font-size: 16px;
  }
  .timeframe-group {
    gap: 2px;
    padding: 2px;
  }
  .tf-btn {
    padding: 3px 6px;
    font-size: 11px;
  }
  .mobile-back-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    background: var(--card2);
    border: 1px solid var(--line);
    color: var(--blue);
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
  }

  /* 3. 우측 AI 분석 피드 (모바일 최하단 배치) */
  .right-panel {
    display: flex !important;
    border-left: none !important;
    border-top: 1px solid var(--line);
    max-height: 380px;
    overflow: visible;
  }
}
