/* =============================================================
   투자 분석 플랫폼 — 라이트 테마 (토스증권 스타일)
   ============================================================= */

/* ===== Design Tokens ===== */
:root {
  /* 배경 */
  --bg: #f7f8fa;             /* 페이지 배경 (살짝 회색) */
  --bg-card: #ffffff;        /* 카드 흰색 */
  --bg-hover: #f2f4f6;       /* hover */
  --bg-active: #e8eaed;      /* 선택됨 */
  --bg-input: #f9fafb;       /* 인풋 배경 */
  --bg-overlay: rgba(0, 0, 0, .4);

  /* 글자 */
  --text: #191f28;           /* 본문 (진한 검정) */
  --text-strong: #0d0e10;    /* 강조 (제목) */
  --text-secondary: #4e5968; /* 부가 */
  --text-tertiary: #8b95a1;  /* 옅은 */
  --text-quaternary: #b0b8c1;/* 가장 옅은 */
  --text-on-accent: #ffffff;

  /* 테두리 */
  --border: #e5e8eb;
  --border-light: #f2f4f6;
  --border-strong: #d1d6db;
  --border-focus: #3182f6;

  /* 토스 파랑 (액센트) */
  --accent: #3182f6;
  --accent-hover: #1b64da;
  --accent-light: #ecf3fe;
  --accent-bg: #eef5ff;

  /* 상승/매수 = 빨강 (한국 주식 컨벤션) */
  --red: #f04452;
  --red-strong: #d72832;
  --red-light: #fff1f2;
  --red-bg: #fff5f5;

  /* 하락/매도 = 파랑 */
  --blue: #3182f6;
  --blue-strong: #1b64da;
  --blue-light: #ecf3fe;
  --blue-bg: #f0f6ff;

  /* 카테고리 5단계 */
  --cat-strong-buy: #d72832;
  --cat-buy: #f04452;
  --cat-neutral: #8b95a1;
  --cat-sell: #3182f6;
  --cat-strong-sell: #1b64da;

  /* 상태 */
  --green: #0eb87a;
  --green-light: #e0f9f1;
  --orange: #f59e0b;
  --orange-light: #fef5e0;
  --gray: #8b95a1;

  /* 그림자 (토스는 부드러운 그림자) */
  --shadow-xs: 0 1px 2px rgba(20, 30, 51, .04);
  --shadow-sm: 0 1px 3px rgba(20, 30, 51, .06), 0 1px 2px rgba(20, 30, 51, .04);
  --shadow-md: 0 4px 12px rgba(20, 30, 51, .06), 0 1px 3px rgba(20, 30, 51, .04);
  --shadow-lg: 0 8px 24px rgba(20, 30, 51, .08), 0 2px 6px rgba(20, 30, 51, .04);
  --shadow-xl: 0 16px 48px rgba(20, 30, 51, .12);

  /* 모서리 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* 사이드바 폭 */
  --sidebar-width: 240px;

  /* z-index */
  --z-sidebar: 50;
  --z-overlay: 100;
  --z-modal: 500;
  --z-dropdown: 200;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Apple SD Gothic Neo', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button { font-family: inherit; }
input, select, textarea { font-family: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }

/* ===== 햄버거 버튼 (모바일 전용) ===== */
.hamburger-btn {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: calc(var(--z-sidebar) + 1);
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  align-items: center; justify-content: center;
  font-size: 1.1rem;
  color: var(--text);
}
.hamburger-btn:active { background: var(--bg-hover); }

/* ===== 사이드바 오버레이 (모바일에서 사이드바 열렸을 때) ===== */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: var(--bg-overlay);
  z-index: calc(var(--z-sidebar) - 1);
}
.sidebar-overlay.open { display: block; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: var(--z-sidebar);
  overflow-y: auto;
  transition: transform .25s cubic-bezier(.4, 0, .2, 1);
}
.sidebar.hidden { display: none; }
.sidebar-header {
  padding: 24px 20px 16px;
}
.sidebar-header h1 {
  font-size: 1.05rem; font-weight: 800;
  letter-spacing: -.4px;
  color: var(--text-strong);
}
.sidebar-header h1 span { color: var(--accent); }
.sidebar-header .subtitle {
  font-size: .7rem;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.nav-section {
  padding: 8px 12px;
}
.nav-section-label {
  font-size: .65rem; font-weight: 700;
  letter-spacing: .4px;
  color: var(--text-tertiary);
  padding: 8px 12px 6px;
  text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: .9rem; font-weight: 600;
  cursor: pointer;
  transition: background .12s, color .12s;
  color: var(--text-secondary);
  text-decoration: none;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-strong); }
.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 700;
}
.nav-item .icon { font-size: 1.1rem; width: 22px; text-align: center; }

.mode-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-size: .65rem; font-weight: 700;
  margin-top: 12px;
}
.mode-badge.backend { background: var(--green-light); color: var(--green); }
.mode-badge.standalone { background: var(--orange-light); color: var(--orange); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-light);
  margin-top: auto;
}
.user-info {
  font-size: .85rem; font-weight: 700;
  color: var(--text-strong);
  margin-bottom: 8px;
}

/* ===== Main content ===== */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 24px;
  min-height: 100vh;
  min-width: 0;
  overflow-x: hidden;
}
.main.no-sidebar { margin-left: 0; }

.page { display: none; }
.page.active { display: block; }

/* ===== Top bar ===== */
.top-bar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  row-gap: 10px;
}

/* ===== Search box ===== */
.search-box {
  display: flex; align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 12px;
  flex: 1; max-width: 500px;
  position: relative;
  transition: border-color .15s, box-shadow .15s;
}
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.search-box input {
  background: transparent; border: none; outline: none;
  color: var(--text); padding: 11px 8px;
  font-size: .9rem; width: 100%;
}
.search-box input::placeholder { color: var(--text-tertiary); }
.search-box button {
  background: none; border: none; cursor: pointer;
  color: var(--accent); font-size: 1rem; padding: 4px;
}

/* ===== Search dropdown ===== */
.search-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  width: max-content;
  max-width: 500px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  max-height: 360px;
  overflow-y: auto;
  z-index: var(--z-dropdown);
  box-shadow: var(--shadow-lg);
}
.search-dropdown.active { display: block; }
.search-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  transition: background .1s;
  border-bottom: 1px solid var(--border-light);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover, .search-item.highlighted {
  background: var(--accent-bg);
}
.search-item-left { display: flex; align-items: center; gap: 10px; }
.search-symbol {
  font-weight: 700; font-size: .85rem; color: var(--text-strong);
  min-width: 60px;
  font-family: 'JetBrains Mono', 'Consolas', monospace;
}
.search-name { font-size: .85rem; color: var(--text); }
.search-market {
  font-size: .65rem; font-weight: 600;
  padding: 3px 8px; border-radius: var(--radius-sm);
  background: var(--bg-hover);
  color: var(--text-secondary);
}

/* ===== Period buttons ===== */
.period-group { display: flex; gap: 4px; flex-wrap: wrap; }
.period-btn,
.kr-period-btn {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: .8rem; font-weight: 600;
  cursor: pointer; transition: all .12s;
}
.period-btn:hover, .kr-period-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}
.period-btn.active, .kr-period-btn.active {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-xs);
  min-width: 0;
  max-width: 100%;
}
.card-title {
  font-size: .9rem; font-weight: 700;
  color: var(--text-strong);
  margin-bottom: 14px;
  letter-spacing: -.2px;
}

/* ===== Chart areas ===== */
.chart-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 16px; flex-wrap: wrap; gap: 12px;
}
.symbol-name {
  font-size: 1.4rem; font-weight: 800; color: var(--text-strong);
  letter-spacing: -.4px;
}
.symbol-ticker {
  font-size: .8rem; color: var(--text-tertiary);
  font-family: 'JetBrains Mono', 'Consolas', monospace;
}
.current-price {
  font-size: 1.6rem; font-weight: 800; color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}
.price-change {
  font-size: .9rem; font-weight: 700; margin-left: 8px;
  font-variant-numeric: tabular-nums;
}
.price-change.up { color: var(--red); }
.price-change.down { color: var(--blue); }

.chart-wrap { height: 280px; position: relative; margin-bottom: 12px; }
.chart-wrap.volume-chart { height: 80px; }
.chart-container { position: relative; }

/* ===== Grids ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.grid-main { display: grid; grid-template-columns: 1fr 320px; gap: 16px; }
.grid-left { min-width: 0; }
.grid-right { min-width: 0; }

/* ===== Info grid ===== */
.info-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.info-item {
  display: flex; flex-direction: column;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}
.info-label {
  font-size: .72rem; color: var(--text-tertiary); font-weight: 600;
}
.info-value {
  font-size: .95rem; font-weight: 700; color: var(--text-strong); margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.info-value.up, .info-value.net-buy { color: var(--red); }
.info-value.down, .info-value.net-sell { color: var(--blue); }

/* ===== Macro & FX ===== */
.macro-card, .fx-card {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
}
.macro-name, .fx-pair {
  font-size: .72rem; color: var(--text-tertiary); font-weight: 600; margin-bottom: 6px;
}
.macro-value, .fx-rate {
  font-size: 1.15rem; font-weight: 800; color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}
.macro-delta { font-size: .75rem; font-weight: 700; margin-top: 4px; }
.macro-delta.up { color: var(--red); }
.macro-delta.down { color: var(--blue); }

/* ===== Settings ===== */
.setting-row {
  padding: 14px 0;
  border-bottom: 1px solid var(--border-light);
}
.setting-label {
  display: flex; align-items: center; gap: 8px;
  font-size: .9rem; font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-strong);
}
.tier-badge {
  padding: 2px 8px; border-radius: var(--radius-sm);
  font-size: .6rem; font-weight: 700; text-transform: uppercase;
}
.tier-badge.free { background: var(--green-light); color: var(--green); }
.tier-badge.paid { background: var(--accent-light); color: var(--accent); }

.setting-input-group { display: flex; gap: 8px; align-items: center; }
.setting-input {
  flex: 1; background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px;
  color: var(--text); font-size: .85rem;
  outline: none; transition: border-color .12s, box-shadow .12s;
}
.setting-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.setting-input:disabled { background: var(--bg-hover); color: var(--text-tertiary); }
.key-link { font-size: 1rem; }

/* ===== Buttons ===== */
.btn {
  padding: 10px 20px; border-radius: var(--radius-md);
  font-weight: 700; font-size: .85rem;
  border: 1px solid transparent; cursor: pointer;
  transition: all .15s;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
}
.btn-primary {
  background: var(--accent); color: var(--text-on-accent);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary.success { background: var(--green); }

.btn-outline {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--border-strong); background: var(--bg-hover); }

.btn-danger {
  background: var(--red-light); color: var(--red);
  border: 1px solid var(--red-light);
}
.btn-danger:hover { background: var(--red-bg); border-color: var(--red); }

.btn-sm { padding: 7px 14px; font-size: .8rem; }
.btn-icon {
  background: none; border: none;
  color: var(--text-tertiary);
  cursor: pointer; font-size: 1rem;
  padding: 4px 8px; border-radius: var(--radius-sm);
  transition: all .12s;
}
.btn-icon:hover { color: var(--red); background: var(--red-light); }

/* ===== States ===== */
.loading, .empty-state, .error-state {
  text-align: center; padding: 2rem;
  font-size: .9rem; color: var(--text-tertiary);
}
.error-state { color: var(--red); }

/* ===== Portfolio selector ===== */
.portfolio-selector {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.portfolio-dropdown,
.select-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-size: .85rem;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
  min-width: 160px;
}
.portfolio-dropdown:focus,
.select-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* ===== Summary ===== */
.summary-group { margin-bottom: 16px; }
.summary-group:last-child { margin-bottom: 0; }
.summary-group-label {
  font-size: .8rem; font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 8px; padding-left: 2px;
}
.summary-group-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.summary-5cols { grid-template-columns: repeat(5, 1fr) !important; }
.combined-summary {
  border-top: 2px solid var(--border-light);
  padding-top: 14px;
  margin-top: 4px;
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow-xs);
}
.summary-label {
  font-size: .72rem; color: var(--text-tertiary); font-weight: 600; margin-bottom: 6px;
}
.summary-value {
  font-size: 1.2rem; font-weight: 800; color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}
.summary-value.up { color: var(--red); }
.summary-value.down { color: var(--blue); }

.fx-rate-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: .65rem;
  font-weight: 700;
  background: var(--accent-bg);
  color: var(--accent);
  margin-left: 6px;
}

/* ===== Holdings table ===== */
.holdings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
.holdings-table th {
  text-align: left;
  padding: 10px 8px;
  font-size: .72rem; font-weight: 700;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border);
}
.holdings-table td {
  padding: 12px 8px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
}
.holdings-table td.up { color: var(--red); font-weight: 700; }
.holdings-table td.down { color: var(--blue); font-weight: 700; }
.holdings-table td strong { color: var(--text-strong); }

.holdings-section { margin-bottom: 20px; }
.holdings-section:last-child { margin-bottom: 0; }
.holdings-section-label {
  font-size: .9rem; font-weight: 700;
  color: var(--text-strong);
  padding: 8px 4px 10px;
  border-bottom: 2px solid var(--accent-bg);
  margin-bottom: 4px;
  display: flex; align-items: center; gap: 6px;
}
.holdings-section-count {
  font-size: .7rem; font-weight: 600;
  color: var(--text-tertiary);
}
.text-muted { font-size: .75rem; color: var(--text-tertiary); }

/* ===== News ===== */
.news-period-tag,
.news-symbol-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: .6rem; font-weight: 700;
  background: var(--accent-bg);
  color: var(--accent);
  margin-left: 6px;
}
.news-toggle-header {
  cursor: pointer;
  display: flex; align-items: center;
  user-select: none;
  transition: opacity .12s;
}
.news-toggle-header:hover { opacity: .7; }
.news-toggle-arrow {
  margin-left: auto;
  font-size: .75rem;
  color: var(--text-tertiary);
  transition: transform .25s ease;
}
.news-toggle-arrow.open { transform: rotate(90deg); }
.news-collapsible {
  overflow: hidden;
  max-height: 2000px;
  transition: max-height .35s ease;
}
.news-collapsible.collapsed { max-height: 0; }
.news-list { display: flex; flex-direction: column; gap: 4px; }
.news-item {
  display: flex; gap: 12px; padding: 10px 8px;
  border-radius: var(--radius-sm);
  text-decoration: none; color: inherit;
  transition: background .12s;
}
.news-item:hover { background: var(--bg-hover); }
.news-thumb {
  flex-shrink: 0;
  width: 80px; height: 56px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  background-size: cover; background-position: center;
}
.news-body { flex: 1; min-width: 0; }
.news-title {
  font-size: .82rem; font-weight: 600;
  color: var(--text-strong);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.news-summary {
  font-size: .68rem;
  color: var(--text-tertiary);
  margin-top: 3px; line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.news-meta {
  margin-top: 6px;
  display: flex; align-items: center; gap: 8px;
  font-size: .65rem;
}
.news-provider, .news-time { color: var(--text-tertiary); }

/* ===== Form ===== */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: .8rem; font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-overlay);
  z-index: var(--z-modal);
  display: flex;
  align-items: center; justify-content: center;
  padding: 16px;
}
.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-width: 360px;
  max-width: 92vw;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
}
.modal-title {
  font-size: 1.05rem; font-weight: 800; color: var(--text-strong);
  margin-bottom: 16px;
  letter-spacing: -.3px;
}

/* ===== Portfolio search box ===== */
.portfolio-search-box { position: relative; }
.portfolio-search-box input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text); font-size: .85rem;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.portfolio-search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* ===== Auth ===== */
.auth-container {
  min-height: calc(100vh - 48px);
  display: flex; align-items: center; justify-content: center;
}
.auth-card {
  width: 100%; max-width: 380px;
  padding: 32px;
}
.auth-header { text-align: center; margin-bottom: 24px; }
.auth-header h2 {
  font-size: 1.4rem; font-weight: 800;
  color: var(--text-strong);
  letter-spacing: -.5px;
}
.auth-header h2 span { color: var(--accent); }
.auth-header p {
  font-size: .8rem; color: var(--text-tertiary);
  margin-top: 4px;
}
.auth-tab-bar {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1; padding: 10px;
  background: none; border: none; cursor: pointer;
  font-size: .9rem; font-weight: 600;
  color: var(--text-tertiary);
  border-bottom: 2px solid transparent;
  transition: all .12s;
}
.auth-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.auth-error {
  background: var(--red-light);
  color: var(--red);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: .8rem; font-weight: 600;
  margin-top: 12px;
}

/* ===== Optimize page ===== */
.optimize-controls-bar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: .85rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
}
.opt-period-group, .sc-period-group { display: flex; gap: 4px; }
.opt-period-btn, .sc-period-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: .78rem; font-weight: 600;
  cursor: pointer; border-radius: var(--radius-sm);
  transition: all .12s;
}
.opt-period-btn.active, .sc-period-btn.active {
  background: var(--accent); color: var(--text-on-accent);
  border-color: var(--accent);
}
.opt-strategy-group {
  display: flex; gap: 6px; align-items: center;
}
.opt-perf-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  margin-bottom: 1rem;
}
.opt-perf-card { text-align: center; }
.opt-perf-card .card-title { font-size: .85rem; margin-bottom: 12px; }
.opt-perf-metrics { display: flex; flex-direction: column; gap: 6px; }
.opt-metric-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: .82rem; padding: 4px 0;
  border-bottom: 1px solid var(--border-light);
}
.opt-metric-label { color: var(--text-secondary); }
.opt-metric-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.opt-metric-value.positive { color: var(--red); }
.opt-metric-value.negative { color: var(--blue); }
.opt-legend {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
  justify-content: center;
}
.opt-legend-item {
  display: flex; align-items: center; gap: 4px; font-size: .72rem;
  color: var(--text-secondary);
}
.opt-legend-dot { width: 10px; height: 10px; border-radius: 50%; }

/* ===== Heatmap ===== */
.heatmap-container { overflow-x: auto; }
.heatmap-table {
  width: 100%; border-collapse: collapse; font-size: .72rem;
}
.heatmap-table th {
  padding: 6px 4px; font-weight: 600; font-size: .68rem;
  color: var(--text-tertiary);
  max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.heatmap-table td {
  padding: 6px 4px; text-align: center;
  font-weight: 700; font-size: .72rem;
  border: 1px solid var(--border-light);
  min-width: 42px;
}

/* ===== Scenario page ===== */
.sc-summary-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  margin-bottom: 1rem;
}
.sc-summary-card { text-align: center; padding: 16px; }
.sc-summary-label { font-size: .75rem; color: var(--text-tertiary); margin-bottom: 6px; font-weight: 600; }
.sc-summary-value {
  font-size: 1.3rem; font-weight: 800; color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}

/* ===== Stress card ===== */
.stress-card {
  padding: .7rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: .5rem;
}
.stress-card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: .35rem;
}
.stress-name { font-weight: 600; font-size: .85rem; color: var(--text-strong); }
.stress-return { font-weight: 700; font-size: .9rem; font-variant-numeric: tabular-nums; }
.stress-return.positive { color: var(--red); }
.stress-return.negative { color: var(--blue); }
.stress-desc { font-size: .72rem; color: var(--text-secondary); }
.stress-detail { font-size: .72rem; color: var(--text-tertiary); margin-top: .25rem; }

/* =============================================================
   KRX Screener
   ============================================================= */
.scr-meta-bar {
  display: flex; gap: 14px; flex-wrap: wrap;
  padding: 12px 16px;
  margin: 12px 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  font-size: .82rem;
  box-shadow: var(--shadow-xs);
}
.scr-meta-bar .meta-item { display: flex; gap: 6px; align-items: center; }
.scr-meta-bar .meta-label { color: var(--text-tertiary); }
.scr-meta-bar .meta-value {
  color: var(--text-strong); font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.scr-meta-bar .meta-status-success { color: var(--green); }
.scr-meta-bar .meta-status-failed { color: var(--red); }

.scr-table-wrap { overflow-x: auto; max-width: 100%; }
.scr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}
.scr-table thead th {
  position: sticky; top: 0;
  background: var(--bg-card);
  color: var(--text-secondary);
  text-align: right;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: .78rem;
  white-space: nowrap;
  user-select: none;
}
.scr-table thead th:first-child,
.scr-table thead th.col-text { text-align: left; }
.scr-table thead th.sort-desc::after { content: ' ▼'; opacity: .6; font-size: .7em; }
.scr-table thead th.sort-asc::after { content: ' ▲'; opacity: .6; font-size: .7em; }
.scr-table tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-light);
  text-align: right;
  white-space: nowrap;
  color: var(--text);
}
.scr-table tbody td:nth-child(1),
.scr-table tbody td:nth-child(2),
.scr-table tbody td:nth-child(3),
.scr-table tbody td:nth-child(4),
.scr-table tbody td.col-text { text-align: left; }
.scr-table tbody tr:hover { background: var(--bg-hover); }

.scr-table .num-up { color: var(--blue); font-weight: 700; }
.scr-table .num-down { color: var(--red); font-weight: 700; }
.scr-table .net-buy { color: var(--red); font-weight: 700; }
.scr-table .net-sell { color: var(--blue); font-weight: 700; }
.scr-table .ticker-cell {
  font-family: 'JetBrains Mono', 'Consolas', monospace;
  color: var(--text-secondary);
  font-size: .78rem;
}
.scr-table .name-cell { font-weight: 700; color: var(--text-strong); }
.scr-table .flag-win { color: var(--red); font-weight: 700; }
.scr-table .flag-bad { color: var(--blue); font-weight: 700; }
.scr-table .flag-mixed { color: var(--orange); font-weight: 700; }
.scr-table .flag-none { color: var(--text-quaternary); }
.scr-table tbody td.actions-cell {
  display: flex; gap: 4px; justify-content: flex-end;
  padding: 6px 8px;
}

.scr-action-btn {
  font-size: .72rem;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer; white-space: nowrap;
  transition: all .12s;
}
.scr-action-btn:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

#scr-tables { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
#page-screener .card { min-width: 0; max-width: 100%; }

/* 카테고리 라벨 (▲▲ ▲ ─ ▼ ▼▼) */
.scr-table .cat,
.scr-legend .cat {
  font-weight: 700; font-size: .85rem;
  text-align: center; padding: 4px 8px; border-radius: var(--radius-sm);
  display: inline-block; min-width: 32px;
}
.scr-table .cat-strong-buy,
.scr-legend .cat-strong-buy { color: var(--cat-strong-buy); }
.scr-table .cat-buy,
.scr-legend .cat-buy { color: var(--cat-buy); }
.scr-table .cat-neutral,
.scr-legend .cat-neutral { color: var(--cat-neutral); }
.scr-table .cat-sell,
.scr-legend .cat-sell { color: var(--cat-sell); }
.scr-table .cat-strong-sell,
.scr-legend .cat-strong-sell { color: var(--cat-strong-sell); }

.scr-legend {
  display: flex; gap: 10px; flex-wrap: wrap;
  align-items: center; margin: 10px 0 16px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  font-size: .78rem;
  color: var(--text-secondary);
  box-shadow: var(--shadow-xs);
}
.scr-legend .cat {
  background: var(--bg-hover);
}

/* =============================================================
   Mobile Responsive (≤900px = 모바일/태블릿)
   ============================================================= */
@media (max-width: 900px) {
  /* 햄버거 노출 */
  .hamburger-btn { display: flex; }

  /* 사이드바: 슬라이드 패턴 */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
  }
  .sidebar.open { transform: translateX(0); }

  /* 메인은 전체 폭 */
  .main {
    margin-left: 0;
    padding: 60px 16px 24px;  /* 햄버거 버튼 자리 확보 */
  }

  /* 그리드들 → 1열 */
  .grid-main { grid-template-columns: 1fr; }
  .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
  .summary-group-cards { grid-template-columns: 1fr 1fr; }
  .summary-5cols { grid-template-columns: repeat(3, 1fr) !important; }
  .opt-perf-grid { grid-template-columns: 1fr; }
  .sc-summary-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .summary-group-cards { grid-template-columns: 1fr 1fr; }
  .summary-5cols { grid-template-columns: 1fr 1fr !important; }
  .info-grid { grid-template-columns: 1fr; }
  .portfolio-selector { flex-wrap: wrap; }
  .top-bar { row-gap: 8px; }
  .modal-box { min-width: 0; width: 100%; }

  /* 카드 패딩 줄임 */
  .card { padding: 16px; }
  .scr-meta-bar { padding: 10px 12px; gap: 10px; font-size: .75rem; }
  .scr-table { font-size: .74rem; }
  .scr-table thead th { padding: 7px 8px; }
  .scr-table tbody td { padding: 7px 8px; }
  .scr-action-btn { padding: 3px 7px; font-size: .68rem; }

  /* 폰트 크기 약간 축소 */
  .symbol-name { font-size: 1.2rem; }
  .current-price { font-size: 1.3rem; }
}

@media (max-width: 480px) {
  /* 스크리너 액션 컬럼 숨김 (가로 폭 확보) */
  #page-screener .scr-table thead th:last-child,
  #page-screener .scr-table tbody td:last-child { display: none; }

  /* 모달 풀 폭 */
  #scr-action-modal .modal-box {
    min-width: 0;
    width: calc(100vw - 24px);
  }
}

/* =============================================================
   국내 대시보드 — 검색·기간·매크로 등
   ============================================================= */
#page-dashboard-kr .top-bar { flex-wrap: wrap; row-gap: 10px; }
#page-dashboard-kr .top-bar > div { flex-wrap: wrap; row-gap: 6px; }
#page-dashboard-kr .top-bar button,
#page-dashboard-kr .top-bar label { white-space: nowrap; flex-shrink: 0; }

/* =============================================================
   KRX 스크리너 — 모바일 추가 보정
   ============================================================= */
#page-screener .top-bar { flex-wrap: wrap; row-gap: 10px; }
#page-screener .top-bar > div { flex-wrap: wrap; row-gap: 6px; }
#page-screener .top-bar button,
#page-screener .top-bar label { white-space: nowrap; flex-shrink: 0; }

@media (max-width: 768px) {
  #page-screener .top-bar > div { width: 100%; margin-left: 0 !important; }
}

/* =============================================================
   유틸리티
   ============================================================= */
.text-center { text-align: center; }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }

/* ===== AI 추천 페이지 ===== */
.reco-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 0 12px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
}
.reco-tab {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.reco-tab:hover {
  background: var(--bg-card);
  color: var(--text);
}
.reco-tab.active {
  background: rgba(49,130,246,.08);
  border-color: rgba(49,130,246,.25);
  color: var(--accent);
}
.reco-tab-emoji { font-size: 1rem; }
.reco-tab-count {
  background: rgba(0,0,0,.05);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
}
.reco-tab.active .reco-tab-count {
  background: rgba(49,130,246,.18);
  color: var(--accent);
}

.reco-cat-desc {
  font-size: .85rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
  padding: 10px 14px;
  background: rgba(20,30,51,.02);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
}

.reco-commentary {
  background: linear-gradient(135deg, rgba(49,130,246,.04), rgba(49,130,246,.01));
  border: 1px solid rgba(49,130,246,.12);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 18px;
}
.reco-commentary-head {
  font-size: .8rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}
.reco-commentary-body {
  font-size: .88rem;
  line-height: 1.7;
  color: var(--text);
}

.reco-picks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}
.reco-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  transition: all .15s;
}
.reco-card:hover {
  border-color: rgba(49,130,246,.3);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,.04);
}
.reco-card-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}
.reco-card-rank {
  font-size: .85rem;
  font-weight: 800;
  color: var(--accent);
  padding-top: 2px;
}
.reco-card-name-wrap { flex: 1; min-width: 0; }
.reco-card-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reco-card-meta {
  font-size: .7rem;
  color: var(--text-secondary);
  opacity: .7;
}
.reco-card-score {
  display: flex; align-items: center; gap: 6px;
}
.reco-card-grade {
  width: 26px; height: 26px;
  border-radius: 8px;
  color: #fff;
  font-size: .85rem;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.reco-card-total {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
}

.reco-card-reasons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  padding: 10px 12px;
  background: rgba(20,30,51,.02);
  border-radius: 8px;
  margin-bottom: 10px;
}
.reco-reason {
  display: flex;
  justify-content: space-between;
  font-size: .72rem;
}
.reco-reason-k { color: var(--text-secondary); opacity: .75; }
.reco-reason-v { font-weight: 700; color: var(--text); }

.reco-card-actions {
  display: flex; justify-content: flex-end;
}

/* 섹터 분석 */
.reco-section-divider {
  margin: 32px 0 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}
.reco-section-divider h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
}
.sector-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 800px) {
  .sector-grid { grid-template-columns: 1fr; }
}
.sector-row {
  display: grid;
  grid-template-columns: 38px 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: .82rem;
}
.sector-row.top { border-left: 3px solid var(--red); }
.sector-row.bottom { border-left: 3px solid var(--blue); }
.sector-rank { font-weight: 800; color: var(--text-secondary); font-size: .75rem; }
.sector-name { min-width: 0; }
.sector-stats { display: flex; gap: 12px; font-size: .72rem; }
.sector-stats .lbl { color: var(--text-secondary); opacity: .6; margin-right: 3px; }
.sector-picks {
  grid-column: 1 / -1;
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}
.sector-pick {
  font-size: .68rem;
  padding: 2px 8px;
  background: rgba(20,30,51,.04);
  border-radius: 999px;
  color: var(--text);
}

/* 백테스팅 */
.bt-table {
  display: flex; flex-direction: column; gap: 8px;
}
.bt-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1.5fr;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: .8rem;
}
.bt-cat { font-weight: 700; }
.bt-stat .lbl { color: var(--text-secondary); opacity: .6; margin-right: 4px; font-size: .7rem; }
.bt-best { font-size: .72rem; color: var(--text-secondary); }
@media (max-width: 700px) {
  .bt-row { grid-template-columns: 1fr 1fr; }
  .bt-cat { grid-column: 1 / -1; }
  .bt-best { grid-column: 1 / -1; }
}

/* ===== 수급 라벨 카드 (대시보드 분석) ===== */
.flow-label-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.flow-label-head {
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.flow-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-top: 1px solid var(--border);
}
.flow-label-row:first-of-type { border-top: none; }
.flow-label-piv {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text);
}
.flow-label-pair {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.flow-label-chip {
  font-size: .78rem;
  font-weight: 600;
  padding: 3px 10px;
  background: rgba(20,30,51,.04);
  border-radius: 999px;
  color: var(--text);
}

/* ===== Print friendly ===== */
@media print {
  .sidebar, .hamburger-btn, .btn, .top-bar { display: none !important; }
  .main { margin: 0; padding: 0; }
}
