/* ===== CSS 테마 변수 ===== */
:root {
  --bg-page:       #f0f4f8;
  --bg-card:       #ffffff;
  --bg-info:       #e8f0fe;
  --bg-accent:     #eff6ff;
  --bg-warn:       #fefce8;
  --text-primary:  #1f2937;
  --text-secondary:#6b7280;
  --text-muted:    #9ca3af;
  --text-accent:   #1a56db;
  --text-danger:   #dc2626;
  --text-warn:     #854d0e;
  --border:        #d1d5db;
  --border-light:  #e5e7eb;
  --border-info:   #bfdbfe;
  --border-warn:   #fde047;
  --accent:        #1a56db;
  --shadow:        rgba(0,0,0,0.08);
  --header-grad:   linear-gradient(135deg, #1a56db, #0e3fa3);
  --step-bg:       #f8fafc;
  --step-num-bg:   #1a56db;
  --step-num-text: #ffffff;
  --step-hl:       #dbeafe;
  --ref-bg:        #f8fafc;
}

[data-theme="dark"] {
  --bg-page:       #0f172a;
  --bg-card:       #1e293b;
  --bg-info:       #1e3a5f;
  --bg-accent:     #172554;
  --bg-warn:       #1c1a05;
  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;
  --text-accent:   #93c5fd;
  --text-danger:   #fca5a5;
  --text-warn:     #fde047;
  --border:        #334155;
  --border-light:  #1e293b;
  --border-info:   #1d4ed8;
  --border-warn:   #713f12;
  --accent:        #3b82f6;
  --shadow:        rgba(0,0,0,0.4);
  --header-grad:   linear-gradient(135deg, #1e3a8a, #1e40af);
  --step-bg:       #0f172a;
  --step-num-bg:   #3b82f6;
  --step-num-text: #ffffff;
  --step-hl:       #1e3a5f;
  --ref-bg:        #1e293b;
}

/* ===== 기본 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Noto Sans KR', 'Apple SD Gothic Neo', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background 0.25s, color 0.25s;
}

/* ===== 헤더 ===== */
header {
  background: var(--header-grad);
  color: #fff;
  padding: 1.5rem 1rem 0;
  text-align: center;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}

header h1 { font-size: 1.6rem; }

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-left: auto;
}

/* 환율 위젯 */
.exchange-widget {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 0.3rem 0.8rem;
  font-size: 0.82rem;
  white-space: nowrap;
}

.exchange-widget__rate { font-weight: 700; }
.exchange-widget__time { opacity: 0.75; font-size: 0.75rem; }

.btn-icon {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  opacity: 0.8;
  transition: opacity 0.2s;
}
.btn-icon:hover { opacity: 1; }

/* 다크모드 토글 */
.theme-toggle {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 1.1rem;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.theme-toggle:hover { background: rgba(255,255,255,0.25); }

.subtitle {
  font-size: 0.88rem;
  opacity: 0.8;
  margin-bottom: 1.2rem;
}

/* ===== 탭 네비게이션 ===== */
nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 0 0.5rem;
}

.tab-btn {
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.85);
  border: none;
  padding: 0.6rem 1.1rem;
  font-size: 0.88rem;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  transition: background 0.15s, color 0.15s;
}
.tab-btn:hover  { background: rgba(255,255,255,0.22); color: #fff; }
.tab-btn.active { background: var(--bg-page); color: var(--accent); font-weight: 700; }

/* ===== 메인 ===== */
main {
  max-width: 740px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.tab-content         { display: none; }
.tab-content.active  { display: block; }

.tab-content > h2 {
  font-size: 1.25rem;
  color: var(--text-accent);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent);
}

/* ===== 안내 박스 ===== */
.info-box {
  background: var(--bg-info);
  border-left: 4px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.4rem;
  font-size: 0.88rem;
}
.info-box strong { display: block; margin-bottom: 0.4rem; color: var(--text-accent); }
.info-box ul     { list-style: none; }
.info-box li     { padding: 0.2rem 0 0.2rem 1rem; position: relative; }
.info-box li::before { content:'·'; position:absolute; left:0; color:var(--accent); font-weight:700; }

/* ===== 폼 ===== */
.calculator-form {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 1.4rem;
  box-shadow: 0 2px 8px var(--shadow);
  margin-bottom: 1.5rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}
.form-group input,
.form-group select {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.97rem;
  background: var(--bg-card);
  color: var(--text-primary);
  transition: border-color 0.2s;
  outline: none;
}
.form-group input:focus,
.form-group select:focus { border-color: var(--accent); }

.calc-btn {
  width: 100%;
  padding: 0.8rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
  margin-top: 0.4rem;
}
.calc-btn:hover  { filter: brightness(1.1); }
.calc-btn:active { transform: scale(0.98); }

/* ===== 결과 박스 ===== */
.result-box { background: var(--bg-card); border-radius: 12px; padding: 1.4rem; box-shadow: 0 2px 8px var(--shadow); }
.result-box.hidden { display: none; }
.result-box > h3 {
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 0.8rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-light);
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.45rem 0;
  font-size: 0.91rem;
  border-bottom: 1px solid var(--border-light);
  gap: 1rem;
}
.result-row:last-child { border-bottom: none; }
.result-row .label { color: var(--text-secondary); }
.result-row .value { font-weight: 600; text-align: right; }

.result-row.tax .label,
.result-row.tax .value { color: var(--text-danger); }

.result-row.highlight {
  background: var(--bg-accent);
  margin: 0.5rem -1.4rem 0;
  padding: 0.7rem 1.4rem;
  border-radius: 8px;
  border-bottom: none;
}
.result-row.highlight .label { color: var(--text-accent); font-weight: 700; }
.result-row.highlight .value { color: var(--text-accent); font-size: 1.05rem; }

.note-box {
  background: var(--bg-warn);
  border: 1px solid var(--border-warn);
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
  margin-top: 1rem;
  font-size: 0.83rem;
  color: var(--text-warn);
  line-height: 1.6;
}

/* ===== 계산 과정 ===== */
.calc-steps {
  margin-top: 1.5rem;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 1.4rem;
  box-shadow: 0 2px 8px var(--shadow);
}
.calc-steps__title {
  font-size: 1rem;
  color: var(--text-accent);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border-info);
}

.calc-step {
  display: flex;
  gap: 0.85rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border-light);
}
.calc-step:last-child { border-bottom: none; }

.calc-step--total {
  background: var(--step-hl);
  margin: 0.5rem -1.4rem 0;
  padding: 0.85rem 1.4rem;
  border-radius: 8px;
  border-bottom: none;
}

.step-num {
  flex-shrink: 0;
  width: 1.7rem;
  height: 1.7rem;
  background: var(--step-num-bg);
  color: var(--step-num-text);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  margin-top: 0.1rem;
}
.calc-step--total .step-num { background: var(--text-accent); }

.step-body { flex: 1; }
.step-title    { font-weight: 700; font-size: 0.93rem; margin-bottom: 0.25rem; }
.step-formula  { font-size: 0.83rem; color: var(--text-secondary); margin-bottom: 0.2rem; }
.step-calc     { font-size: 0.85rem; color: var(--text-secondary); font-family: monospace; background: var(--step-bg); padding: 0.25rem 0.5rem; border-radius: 4px; margin-bottom: 0.25rem; }
.step-result   { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }
.step-result--hl { color: var(--text-accent); font-size: 1.05rem; }
.step-note     { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ===== 비교 카드 (연금복권 등) ===== */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}
.compare-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem;
}
.compare-card.best { border-color: var(--accent); }
.compare-card__title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-accent);
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-light);
}
.compare-card .result-row { font-size: 0.85rem; }

/* ===== 생키 차트 ===== */
.sankey-section {
  margin-top: 1.5rem;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 1.2rem 1.4rem;
  box-shadow: 0 2px 8px var(--shadow);
}
.sankey-section__title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.sankey-wrap {
  height: 230px;
  border-radius: 8px;
  background: var(--step-bg);
}

/* ===== 복권→배당주 연계 CTA ===== */
.cta-connect {
  margin-top: 1.2rem;
  background: linear-gradient(135deg, #1a56db, #7c3aed);
  border-radius: 12px;
  padding: 1.1rem 1.4rem;
  color: #fff;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}
.cta-connect__body { flex: 1; min-width: 0; }
.cta-connect__label { font-size: 0.82rem; opacity: 0.85; margin-bottom: 0.2rem; }
.cta-connect__amount { font-size: 1.15rem; font-weight: 800; }
.cta-connect__btn {
  background: #fff;
  color: #1a56db;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.2rem;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.cta-connect__btn:hover  { opacity: 0.88; }
.cta-connect__btn:active { transform: scale(0.97); }

/* 배당주 탭: 복권 연계 안내 배너 */
.from-lottery-banner {
  display: none;
  background: linear-gradient(135deg, #1a56db22, #7c3aed22);
  border: 1.5px solid #7c3aed55;
  border-radius: 10px;
  padding: 0.85rem 1.1rem;
  margin-bottom: 1.2rem;
  font-size: 0.88rem;
  color: var(--text-accent);
  line-height: 1.6;
}
.from-lottery-banner.visible { display: block; }

/* ===== 참고자료 ===== */
.references {
  max-width: 740px;
  margin: 0 auto 2rem;
  padding: 0 1rem;
}
.references__inner {
  background: var(--ref-bg);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 1.2rem 1.4rem;
}
.references h3 {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}
.ref-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.4rem 1.5rem;
  list-style: none;
}
.ref-list li { font-size: 0.82rem; }
.ref-list a {
  color: var(--text-accent);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.ref-list a:hover { text-decoration: underline; }
.ref-list a::before { content: '↗'; font-size: 0.75rem; opacity: 0.7; }

/* ===== 푸터 ===== */
footer {
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.9;
}

/* ===== 히스토리 드로어 ===== */
.history-drawer {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.35s ease, padding 0.2s ease;
}
.history-drawer.open {
  max-height: 420px;
}
.history-drawer__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.2rem 0.5rem;
  border-bottom: 1px solid var(--border-light);
}
.history-drawer__header h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}
.hist-clear-btn {
  background: none;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
}
.hist-clear-btn:hover { color: var(--text-danger); border-color: var(--text-danger); }
.history-panel {
  padding: 0.6rem 1.2rem 1rem;
  overflow-y: auto;
  max-height: 310px;
}
.hist-empty {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  padding: 1.5rem 0;
}
.hist-entry {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border-light);
  gap: 0.75rem;
  cursor: pointer;
}
.hist-entry:last-child { border-bottom: none; }
.hist-entry:hover .hist-summary { color: var(--text-accent); }
.hist-meta { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; min-width: 0; }
.hist-type {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.hist-summary {
  font-size: 0.82rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s;
}
.hist-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.hist-restore-btn {
  background: none;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  font-size: 0.72rem;
  color: var(--text-accent);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.hist-restore-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ===== DRIP 차트 ===== */
.drip-chart-wrap {
  width: 100%;
  height: 360px;
  margin-top: 1.25rem;
  border-radius: 10px;
  overflow: hidden;
}
.drip-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin: 1.25rem 0;
}
.drip-stat-card {
  background: var(--bg-info);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}
.drip-stat-card .label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}
.drip-stat-card .value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}
.drip-stat-card .value.green { color: #16a34a; }
.drip-stat-card .value.blue  { color: #2563eb; }
[data-theme="dark"] .drip-stat-card .value.green { color: #4ade80; }
[data-theme="dark"] .drip-stat-card .value.blue  { color: #60a5fa; }

/* ===== 반응형 ===== */
@media (max-width: 520px) {
  header h1 { font-size: 1.25rem; }
  .header-top { justify-content: center; }
  .header-controls { width: 100%; justify-content: center; }
  .tab-btn { padding: 0.5rem 0.7rem; font-size: 0.8rem; }
  main { padding: 1.25rem 0.75rem; }
  .form-row { grid-template-columns: 1fr; }
  .compare-grid { grid-template-columns: 1fr; }
}
