/* ===================================================
   석탄 시황 대시보드 · CSS
   =================================================== */

/* ── 변수 (라이트 모드) ── */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface2: #f8f9fa;
  --border: #e5e7eb;
  --border2: #d1d5db;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-hint: #9ca3af;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-bg: #eff6ff;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --orange: #f97316;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 4px 12px rgba(0,0,0,.08);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Noto Sans KR', 'Inter', -apple-system, sans-serif;
}

/* ── 다크 모드 ── */
body.dark {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222535;
  --border: #2d3148;
  --border2: #3d4160;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-hint: #64748b;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --accent-bg: #1e3a5f;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow: 0 4px 12px rgba(0,0,0,.4);
}

/* ── 리셋 & 베이스 ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg);
  line-height: 1.6;
  transition: background .25s, color .25s;
  min-height: 100vh;
}

/* ── 헤더 ── */
#main-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.logo-mark {
  width: 32px; height: 32px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
  flex-shrink: 0;
}
.header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}
.header-sub {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 1px;
}
.header-right { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface2); color: var(--text-primary); }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 메인 컨테이너 ── */
#main-content {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── 배너 ── */
.banner-section { }
.banner-inner {
  background: var(--accent-bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
}
.banner-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.banner-text strong { color: var(--text-primary); font-weight: 600; }
.link-btn {
  background: none; border: none;
  color: var(--accent); cursor: pointer;
  font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 3px;
  padding: 0; margin-left: 4px;
  transition: color .15s;
}
.link-btn:hover { color: var(--accent-hover); text-decoration: underline; }

/* ── 카드 ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

/* ── 카드 헤더 ── */
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.card-title-group { display: flex; flex-direction: column; gap: 3px; }
.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}
.card-title .title-sub {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
}
.card-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
}
.card-hint {
  font-size: 11px;
  color: var(--text-hint);
}
.card-footnote {
  font-size: 11px;
  color: var(--text-hint);
  margin-top: 10px;
  line-height: 1.5;
}
.unit-label {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
}
.badge-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 500;
  background: #dcfce7;
  color: #15803d;
  border-radius: 4px;
  padding: 2px 6px;
  margin-left: 6px;
  vertical-align: middle;
}
body.dark .badge-tag { background: #14532d; color: #4ade80; }

/* ── 기간 필터 버튼 ── */
.period-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.period-btn {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.period-btn:hover {
  background: var(--surface2);
  color: var(--text-primary);
}
.period-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── 차트 ── */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 280px;
}
.chart-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-top: 12px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── 상세 데이터 테이블 ── */
.table-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.search-input {
  padding: 6px 10px;
  font-size: 12px;
  font-family: var(--font);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text-primary);
  outline: none;
  width: 160px;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--accent); }
.row-count {
  font-size: 11px;
  color: var(--text-hint);
  white-space: nowrap;
}
.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 420px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
#data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
#data-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}
#data-table th {
  background: var(--surface2);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11.5px;
  padding: 9px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  line-height: 1.3;
}
#data-table th:first-child { text-align: left; }
.th-unit {
  font-weight: 400;
  font-size: 10px;
  color: var(--text-hint);
}
#data-table td {
  padding: 7px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  white-space: nowrap;
}
#data-table td:first-child { text-align: left; color: var(--text-secondary); }
#data-table tbody tr:hover { background: var(--surface2); }
#data-table tbody tr:last-child td { border-bottom: none; }
.td-positive { color: var(--danger) !important; font-weight: 500; }
.td-negative { color: var(--accent) !important; font-weight: 500; }
.loading-cell {
  text-align: center !important;
  color: var(--text-hint) !important;
  padding: 24px !important;
  font-size: 13px;
}

/* ── 주요 뉴스 ── */
.news-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.news-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  transition: background .15s;
}
.news-card:hover { background: var(--surface2); }
.news-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.news-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--surface2);
  color: var(--text-secondary);
}
.news-tag.cn { background: #fef3c7; color: #92400e; }
.news-tag.id { background: #fce7f3; color: #9d174d; }
.news-tag.global { background: #dbeafe; color: #1e40af; }
.news-tag.au { background: #d1fae5; color: #065f46; }
body.dark .news-tag.cn { background: #451a03; color: #fbbf24; }
body.dark .news-tag.id { background: #500724; color: #f9a8d4; }
body.dark .news-tag.global { background: #1e3a8a; color: #93c5fd; }
body.dark .news-tag.au { background: #022c22; color: #34d399; }
.news-sentiment {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}
.news-sentiment.up { background: #fee2e2; color: #dc2626; }
.news-sentiment.dn { background: #dbeafe; color: #2563eb; }
.news-sentiment.nt { background: var(--surface2); color: var(--text-secondary); }
body.dark .news-sentiment.up { background: #450a0a; color: #f87171; }
body.dark .news-sentiment.dn { background: #1e3a8a; color: #93c5fd; }
.news-date {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-hint);
}
.news-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  line-height: 1.4;
}
.news-body {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.news-source {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--accent);
  margin-top: 6px;
  text-decoration: none;
}
.news-source:hover { text-decoration: underline; }

/* ── 수급 지표 ── */
.kpi-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.kpi-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.kpi-item:last-child { border-bottom: none; }
.kpi-left { display: flex; flex-direction: column; gap: 2px; }
.kpi-name {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-primary);
}
.kpi-period {
  font-size: 11px;
  color: var(--text-hint);
}
.kpi-right { display: flex; align-items: center; gap: 10px; text-align: right; }
.kpi-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.kpi-unit {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 2px;
}
.kpi-yoy {
  font-size: 11.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 2px;
}
.kpi-yoy.pos { color: var(--danger); }
.kpi-yoy.neg { color: var(--accent); }
.kpi-tag {
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 3px;
  font-weight: 600;
  background: var(--surface2);
  color: var(--text-hint);
}
.kpi-tag.cn { background: #fef3c7; color: #92400e; }
.kpi-tag.id { background: #fce7f3; color: #9d174d; }
body.dark .kpi-tag.cn { background: #451a03; color: #fbbf24; }
body.dark .kpi-tag.id { background: #500724; color: #f9a8d4; }

/* ── 푸터 ── */
#main-footer {
  text-align: center;
  padding: 20px 20px 32px;
  font-size: 11px;
  color: var(--text-hint);
  line-height: 1.7;
  max-width: 900px;
  margin: 0 auto;
}
.footer-sub { color: var(--text-hint); }

/* ── 북방항구 재고 토글 버튼 ── */
.port-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.port-toggle-btn:hover {
  background: var(--surface2);
  color: var(--text-primary);
  border-color: var(--accent);
}
.port-toggle-btn.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── 로딩 오버레이 ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 900;
  display: none;
  align-items: center;
  justify-content: center;
}
.loading-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}
.loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.loading-text {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ── 헤더 데이터 상태 ── */
.data-status {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
  transition: all .2s;
}
.status-ok      { background:#dcfce7; color:#15803d; }
.status-loading { background:#dbeafe; color:#1d4ed8; }
.status-error   { background:#fee2e2; color:#dc2626; }
body.dark .status-ok      { background:#14532d; color:#4ade80; }
body.dark .status-loading { background:#1e3a8a; color:#93c5fd; }
body.dark .status-error   { background:#450a0a; color:#f87171; }

/* ── 에러 배너 ── */
.error-banner {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 12.5px;
  color: #dc2626;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.6;
}
.error-banner svg { flex-shrink: 0; margin-top: 2px; }
body.dark .error-banner { background: #450a0a; border-color: #7f1d1d; color: #fca5a5; }

/* ── 반응형 ── */
@media (max-width: 640px) {
  .header-inner { padding: 0 14px; }
  #main-content { padding: 12px 12px 32px; gap: 12px; }
  .card { padding: 14px; }
  .card-header { flex-direction: column; align-items: flex-start; }
  .period-btns { flex-wrap: wrap; }
  .chart-wrap { height: 220px; }
  .kpi-value { font-size: 14px; }
  .search-input { width: 120px; }
  .table-controls { flex-direction: column; align-items: flex-start; }
}
