/* ─────────────────────────────────────────────
   Precision Macro Design System
   Font: Inter | Theme: White / Slate
   Up: Red #F03E3E | Down: Blue #1971C2
───────────────────────────────────────────── */

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

:root {
  --bg:           #ffffff;
  --bg-dim:       #f8f9ff;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #0d1c2d;
  --text-muted:   #64748b;
  --text-label:   #94a3b8;
  --up:           #f03e3e;
  --up-bg:        #fff5f5;
  --down:         #1971c2;
  --down-bg:      #e7f5ff;
  --neutral:      #64748b;
  --neutral-bg:   #f1f5f9;
  --primary:      #0d1c2d;
  --radius-sm:    4px;
  --radius-md:    8px;
  --radius-lg:    12px;
  --radius-full:  9999px;
  --shadow-sm:    0 1px 4px rgba(13,28,45,0.06);
  --shadow-md:    0 4px 12px rgba(13,28,45,0.08);
  --max-w:        1280px;
  --gutter:       24px;
  font-family: 'Inter', system-ui, sans-serif;
  font-feature-settings: 'tnum' 1;
}

body {
  background: var(--bg-dim);
  color: var(--text);
  min-height: 100vh;
}

/* ── 헤더 ── */
#main-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
}
.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--gutter);
  height: 56px;
  display: flex;
  align-items: center;
  gap: 32px;
}
.site-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  color: var(--text);
}

/* ── 탭 ── */
.tab-nav {
  display: flex;
  gap: 0;
  flex: 1;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0 16px;
  height: 56px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover  { color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

.last-updated {
  font-size: 12px;
  color: var(--text-label);
  white-space: nowrap;
}

/* ── 메인 ── */
main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 32px var(--gutter);
}

/* ── 검색창 ── */
.search-wrap {
  position: relative;
  max-width: 480px;
  margin: 0 auto 32px;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 15px;
  pointer-events: none;
}
#search-input {
  width: 100%;
  height: 44px;
  padding: 0 16px 0 42px;
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
#search-input:focus { border: 1px solid var(--primary); }
#search-input::placeholder { color: var(--text-label); }

/* ── 그룹 헤더 ── */
.group-header {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 32px 0 16px;
  padding-left: 4px;
  letter-spacing: -0.01em;
}
.card-grid {
  display: block;
}
.card-grid-inner {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--gutter);
}

/* ── 지표 카드 ── */
.ind-card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: box-shadow 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 148px;
}
.ind-card:hover { box-shadow: var(--shadow-md); background: #fafbff; }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.card-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.4;
}
.card-info-icon {
  font-size: 14px;
  color: var(--text-label);
  cursor: help;
}
.card-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.2;
}
.card-value.manual-pending {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-label);
}
.change-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  width: fit-content;
}
.change-chip.up   { background: var(--up-bg);   color: var(--up);   }
.change-chip.down { background: var(--down-bg);  color: var(--down); }
.change-chip.flat { background: var(--neutral-bg); color: var(--neutral); }

/* 스파크라인 */
.sparkline-wrap { margin-top: 4px; height: 44px; }
.sparkline-wrap canvas { width: 100% !important; height: 44px !important; }

/* ── 상세 화면 ── */
.hidden { display: none !important; }

.detail-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.back-btn {
  background: none;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s;
}
.back-btn:hover { background: var(--bg-dim); }
#detail-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  flex: 1;
}
.detail-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* 기간 탭 */
.period-tabs {
  display: flex;
  gap: 0;
  border-bottom: 0.5px solid var(--border);
  margin-bottom: 20px;
}
.period-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: -0.5px;
  transition: color 0.15s, border-color 0.15s;
}
.period-btn:hover  { color: var(--text); }
.period-btn.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

/* 차트 카드 */
.chart-card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
}
.chart-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.chart-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.change-badge {
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
}
.change-badge.up   { background: var(--up-bg);   color: var(--up);   }
.change-badge.down { background: var(--down-bg);  color: var(--down); }
.change-badge.flat { background: var(--neutral-bg); color: var(--neutral); }

.chart-wrap {
  position: relative;
  height: 260px;
}
#detail-chart { width: 100% !important; height: 260px !important; }

/* 테이블 카드 */
.table-card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 32px;
}
.table-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.table-title  { font-size: 14px; font-weight: 600; }
.table-icon   { font-size: 16px; color: var(--text-label); }

#history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
#history-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-label);
  padding: 0 0 10px;
  border-bottom: 0.5px solid var(--border);
}
#history-table th:last-child { text-align: right; }
#history-table td {
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
}
#history-table td:last-child {
  text-align: right;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  font-feature-settings: 'tnum' 1;
}
#history-table tr:last-child td { border-bottom: none; }

.show-more-wrap { text-align: center; margin-top: 16px; }
.show-more-btn {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 32px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}
.show-more-btn:hover { background: var(--bg-dim); }
.show-more-btn.hidden-btn { display: none; }

/* ── 빈 / 로딩 상태 ── */
.loading-state, .empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 0;
  color: var(--text-label);
  font-size: 14px;
}

/* ── 반응형 ── */
@media (max-width: 768px) {
  .header-inner { gap: 16px; padding: 0 16px; }
  .site-title   { font-size: 15px; }
  .tab-btn      { padding: 0 10px; font-size: 13px; }
  .last-updated { display: none; }
  main { padding: 20px 16px; }
  .card-grid-inner { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .ind-card { padding: 14px; min-height: 120px; }
  .card-value { font-size: 20px; }
}
@media (max-width: 480px) {
  .card-grid-inner { grid-template-columns: 1fr 1fr; gap: 10px; }
}
