/* ============================================================
   style.css - 매크로 대시보드 다크 테마
   ============================================================ */

:root {
  --bg:          #0a0f1e;
  --surface:     #111827;
  --surface-2:   #1e293b;
  --border:      #1f2d40;
  --border-2:    #2d3f55;
  --text:        #f1f5f9;
  --text-muted:  #94a3b8;
  --text-faint:  #475569;
  --accent:      #3b82f6;
  --positive:    #22c55e;
  --negative:    #ef4444;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  font-size: 14px;
}

/* ── 스크롤바 ─────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }

/* ── 헤더 ─────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 15, 30, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.logo-icon {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.header-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.header-spacer { flex: 1; }

.header-time {
  font-size: 12px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 5px;
}

.data-date-label {
  font-size: 11px;
  color: var(--text-faint);
}

#data-date {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.live-dot {
  width: 6px;
  height: 6px;
  background: var(--positive);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── 아이콘 버튼 ────────────────────── */
.icon-btn {
  background: none;
  border: 1px solid var(--border-2);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all 0.15s;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-2);
}

/* ── API 키 배너 ─────────────────────── */
.api-key-banner {
  display: none;
  align-items: center;
  gap: 12px;
  background: rgba(234,179,8,0.08);
  border: 1px solid rgba(234,179,8,0.3);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  margin: 16px 24px 0;
  font-size: 13px;
  color: #fbbf24;
}

.api-key-banner button {
  background: rgba(234,179,8,0.15);
  border: 1px solid rgba(234,179,8,0.4);
  color: #fbbf24;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  margin-left: auto;
  white-space: nowrap;
  transition: background 0.15s;
}

.api-key-banner button:hover { background: rgba(234,179,8,0.25); }

/* ── 컨트롤 바 (sticky) ─────────────── */
.controls {
  position: sticky;
  top: 56px;           /* 헤더 높이 */
  z-index: 99;
  background: rgba(10, 15, 30, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.range-group {
  display: flex;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.range-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 5px 11px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
}

.range-btn:hover { color: var(--text); background: var(--surface-2); }
.range-btn.active { background: var(--accent); color: white; }

.controls-spacer { flex: 1; }

.refresh-status {
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  flex-shrink: 0;
}
.refresh-status.loading { color: #fbbf24; }
.refresh-status.live    { color: var(--positive); }
.refresh-status.cached  { color: var(--text-faint); }

.category-filter {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.cat-filter-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
}

.cat-filter-btn:hover { border-color: var(--border-2); color: var(--text); }
.cat-filter-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(59,130,246,0.08); }

/* ── 메인 그리드 ──────────────────── */
.main-content {
  padding: 20px 24px 40px;
  max-width: 1600px;
  margin: 0 auto;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
  .controls { padding: 10px 16px; }
  .main-content { padding: 12px 16px 40px; }
  .header { padding: 0 16px; }
  .header-time {
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    line-height: 1.3;
  }
}

/* ── 차트 카드 ─────────────────────── */
.chart-card--wide {
  grid-column: 1 / -1;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chart-card:hover {
  border-color: var(--border-2);
  box-shadow: var(--shadow);
}

/* 카드 헤더 */
.card-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.card-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.category-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  flex: 1;
}

.card-badges {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

.card-desc {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.card-value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.card-current {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.card-change {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.card-change.positive { color: var(--positive); }
.card-change.negative { color: var(--negative); }

.card-secondary {
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
  white-space: nowrap;
}

.card-market-status {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  align-self: center;
  letter-spacing: 0.2px;
}

.card-mdd {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  align-self: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text-muted);
}
.card-mdd[data-negative="moderate"] { color: #f97316; border-color: #f9731655; }
.card-mdd[data-negative="severe"]   { color: var(--negative); border-color: #ef444455; }

/* 차트 영역 */
.chart-area {
  height: 200px;
  width: 100%;
  padding: 8px 0 0;
}

/* 카드 푸터 */
.card-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.normalize-group {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px;
}

.norm-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.12s;
}

.norm-btn:hover { color: var(--text); background: var(--surface-2); }
.norm-btn.active { background: var(--accent); color: white; }


.updated-label {
  font-size: 10px;
  color: var(--text-faint);
}

/* ── 상태 배지 ─────────────────────── */
.status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}

.status-badge.loading { background: rgba(148,163,184,0.12); color: #94a3b8; }
.status-badge.live    { background: rgba(34,197,94,0.12);  color: #22c55e; }
.status-badge.cached  { background: rgba(59,130,246,0.12); color: #60a5fa; }
.status-badge.static  { background: rgba(234,179,8,0.12);  color: #fbbf24; }
.status-badge.error   { background: rgba(239,68,68,0.12);  color: #f87171; }

/* ── 읽는 법 패널 ──────────────────── */
.reading-panel {
  padding: 12px 20px 14px;
  border-top: 1px solid var(--border);
  background: rgba(15,23,42,0.6);
}
.reading-panel ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.reading-panel li {
  font-size: 13px;
  color: #94a3b8;
  line-height: 1.6;
  padding-left: 16px;
  position: relative;
}
.reading-panel li::before {
  content: '·';
  position: absolute;
  left: 4px;
  color: var(--accent);
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
}

/* ── 설정 모달 ─────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 24px;
  width: min(480px, calc(100vw - 32px));
  box-shadow: 0 8px 48px rgba(0,0,0,0.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h2 { font-size: 16px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus { border-color: var(--accent); }

.form-hint {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 5px;
  line-height: 1.5;
}

.form-hint a { color: var(--accent); text-decoration: none; }
.form-hint a:hover { text-decoration: underline; }

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: #2563eb; }

.btn-outline {
  background: none;
  border: 1px solid var(--border-2);
  color: var(--text-muted);
}

.btn-outline:hover { background: var(--surface-2); color: var(--text); }

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── 빈 상태 / 에러 ────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-faint);
  font-size: 12px;
  gap: 6px;
}

/* ── 테마 버튼 ─────────────────────── */
.theme-btn {
  background: none;
  border: 1px solid var(--border-2);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.theme-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* ── 라이트 테마 ────────────────────── */
[data-theme="light"] {
  --bg:         #f8fafc;
  --surface:    #ffffff;
  --surface-2:  #f1f5f9;
  --border:     #e2e8f0;
  --border-2:   #cbd5e1;
  --text:       #0f172a;
  --text-muted: #475569;
  --text-faint: #94a3b8;
  --shadow:     0 4px 24px rgba(0,0,0,0.08);
}

[data-theme="light"] .header {
  background: rgba(248, 250, 252, 0.92);
}

[data-theme="light"] .controls {
  background: rgba(248, 250, 252, 0.96);
}

[data-theme="light"] .reading-panel {
  background: rgba(241, 245, 249, 0.8);
}

[data-theme="light"] ::-webkit-scrollbar-track { background: #f8fafc; }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: #cbd5e1; }

/* ── 푸터 ─────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  text-align: center;
  font-size: 11px;
  color: var(--text-faint);
}

.site-footer a { color: var(--text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--text); }
