/* PreKOSPI 공통 디자인 토큰 · 헤더/GNB/푸터 · 상태 컴포넌트 (doc/PRD.md §8, §9) */

:root {
  --brand:     #316FEA;
  --bg:        #f7f7f8;
  --surface:   #ffffff;
  --card:      #ffffff;
  --border:    #e6e7ea;
  --text:      #1a1d24;
  --muted:     #6b7280;
  --up:        #d63d3d;   /* 한국 관례: 상승 = 빨강 */
  --down:      #2f6fdd;   /* 하락 = 파랑 */
  --up-bg:     rgba(214, 61, 61, 0.08);
  --down-bg:   rgba(47, 111, 221, 0.08);
  --flat-bg:   rgba(107, 114, 128, 0.08);
  --grid:      #eceef1;
  --warn:      #F59E0B;
  --ok:        #12A150;
  --accent:    var(--brand);
  --accent-bg: rgba(49, 111, 234, 0.08);
  --content-width: 1024px; /* 전체 페이지 공통 콘텐츠 너비 — 페이지별 <style>에서 오버라이드하지 말 것(과거 하드코딩 중복으로 불일치 발생 이력 있음) */
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand:     #6d93f5;
    --bg:        #101114;
    --surface:   #1a1b1f;
    --card:      #1a1b1f;
    --border:    #2a2c32;
    --text:      #e8eaed;
    --muted:     #9aa0a8;
    --up:        #ea5a57;
    --down:      #5b8cf0;
    --up-bg:     rgba(234, 90, 87, 0.12);
    --down-bg:   rgba(91, 140, 240, 0.12);
    --flat-bg:   rgba(154, 160, 168, 0.10);
    --grid:      #24262b;
    --warn:      #fbbf24;
    --ok:        #22c55e;
    --accent:    var(--brand);
    --accent-bg: rgba(109, 147, 245, 0.14);
  }
}

/* 수동 다크모드 토글 (Phase 6) — data-theme 속성이 있으면 시스템 설정(위 @media)보다 우선한다.
   common.js가 페이지 로드 즉시(<head> 파싱 중) localStorage 값을 읽어 속성을 붙이므로
   깜빡임(FOUC) 없이 적용된다. */
:root[data-theme="light"] {
  --brand: #316FEA; --bg: #f7f7f8; --surface: #ffffff; --card: #ffffff; --border: #e6e7ea;
  --text: #1a1d24; --muted: #6b7280; --up: #d63d3d; --down: #2f6fdd;
  --up-bg: rgba(214, 61, 61, 0.08); --down-bg: rgba(47, 111, 221, 0.08); --flat-bg: rgba(107, 114, 128, 0.08);
  --grid: #eceef1; --warn: #F59E0B; --ok: #12A150; --accent: var(--brand); --accent-bg: rgba(49, 111, 234, 0.08);
}
:root[data-theme="dark"] {
  --brand: #6d93f5; --bg: #101114; --surface: #1a1b1f; --card: #1a1b1f; --border: #2a2c32;
  --text: #e8eaed; --muted: #9aa0a8; --up: #ea5a57; --down: #5b8cf0;
  --up-bg: rgba(234, 90, 87, 0.12); --down-bg: rgba(91, 140, 240, 0.12); --flat-bg: rgba(154, 160, 168, 0.10);
  --grid: #24262b; --warn: #fbbf24; --ok: #22c55e; --accent: var(--brand); --accent-bg: rgba(109, 147, 245, 0.14);
}

/* ── 베이스 ─────────────────────────────────────────────────────────── */
.pk-reset, .pk-reset * { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Pretendard',
               'Malgun Gothic', 'Segoe UI', sans-serif;
}
.num { font-variant-numeric: tabular-nums; }
.up   { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }

/* ── Site Header / GNB (PRD §9.1, §7.1) ────────────────────────────── */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.site-header-in {
  max-width: var(--content-width); margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.site-logo {
  display: flex; align-items: baseline; gap: 8px; text-decoration: none;
  font-size: 15px; font-weight: 800; letter-spacing: -0.3px; color: var(--text);
  white-space: nowrap;
}
.site-logo small { font-weight: 500; color: var(--muted); font-size: 11.5px; }

.gnb { display: flex; gap: 2px; }
.gnb a {
  font-size: 13.5px; font-weight: 600; color: var(--muted); text-decoration: none;
  padding: 8px 11px; border-radius: 8px; white-space: nowrap;
}
.gnb a:hover  { color: var(--text); background: var(--flat-bg); }
.gnb a.active { color: var(--brand); background: var(--accent-bg); }

.menu-btn {
  display: none; background: none; border: none; font-size: 20px; line-height: 1;
  color: var(--text); cursor: pointer; padding: 6px 8px; border-radius: 8px;
}
.menu-btn:hover { background: var(--flat-bg); }

.theme-toggle {
  background: none; border: none; font-size: 16px; line-height: 1;
  color: var(--text); cursor: pointer; padding: 6px 8px; border-radius: 8px;
  display: inline-flex; align-items: center;
}
.theme-toggle:hover { background: var(--flat-bg); }

.mobile-menu { display: none; flex-direction: column; border-top: 1px solid var(--border); }
.mobile-menu.open { display: flex; }
.mobile-menu-in { max-width: var(--content-width); margin: 0 auto; padding: 4px 16px 10px; display: flex; flex-direction: column; }
.mobile-menu a {
  padding: 12px 4px; font-size: 14.5px; font-weight: 600; color: var(--text);
  text-decoration: none; border-bottom: 1px solid var(--border);
}
.mobile-menu a:last-child { border-bottom: none; }
.mobile-menu a.active { color: var(--brand); }

@media (max-width: 760px) {
  .gnb-desktop { display: none; }
  .menu-btn { display: block; }
}
@media (min-width: 761px) {
  .mobile-menu { display: none !important; }
}

/* 페이지별 실시간 연결 상태 바 (헤더 아래, 각 페이지 스크립트가 값 갱신) */
.status-bar {
  max-width: var(--content-width); margin: 0 auto; padding: 10px 16px 0;
  display: flex; justify-content: flex-end;
}

/* ── MarketStatusBadge — 6개 상태 (PRD §9.2) ───────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 4px 10px; border-radius: 999px;
  background: var(--flat-bg); white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* 기존 페이지 호환용 (거래 중 = 실시간) */
.badge.live .dot { background: var(--up); animation: pulse 1.6s infinite; }
.badge.live       { color: var(--text); }

/* 정식 6단계 상태 클래스 — 신규 페이지부터 사용 */
.badge.state-open     .dot { background: var(--ok); animation: pulse 1.6s infinite; }
.badge.state-open          { color: var(--text); }
.badge.state-closed        { color: var(--muted); }
.badge.state-pre            { color: var(--muted); }
.badge.state-holiday        { color: var(--muted); }
.badge.state-delayed       .dot { background: var(--warn); }
.badge.state-delayed        { color: var(--warn); background: rgba(245, 158, 11, 0.12); }
.badge.state-error         .dot { background: #fff; }
.badge.state-error          { color: #fff; background: var(--down); }

/* ── 공통 상태 UI — Skeleton / Empty / Error / Holiday (PRD §9.9) ──── */
.pk-skeleton {
  display: inline-block; background: linear-gradient(90deg, var(--flat-bg) 25%, var(--border) 37%, var(--flat-bg) 63%);
  background-size: 400% 100%; animation: pk-skeleton-shine 1.4s ease infinite;
  border-radius: 6px; color: transparent !important;
}
@keyframes pk-skeleton-shine { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.pk-state {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 6px; padding: 32px 16px; color: var(--muted); font-size: 13.5px;
}
.pk-state[hidden] { display: none; }
.pk-state .pk-state-title { font-size: 14.5px; font-weight: 700; color: var(--text); }
.pk-state.pk-state-error .pk-state-title { color: var(--down); }

/* ── Site Footer (PRD §9.1 보조메뉴, §17.2 투자정보 고지) ──────────── */
.site-footer { margin-top: 28px; border-top: 1px solid var(--border); }
.site-footer-in { max-width: var(--content-width); margin: 0 auto; padding: 20px 16px 32px; }
.site-footer-links {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px;
  font-size: 12.5px; margin-bottom: 14px;
}
.site-footer-links a { color: var(--muted); text-decoration: none; }
.site-footer-links a:hover { color: var(--text); }
.site-footer-disc {
  max-width: 620px; margin: 0 auto; font-size: 12px; color: var(--muted);
  line-height: 1.7; text-align: center;
}
.site-footer-brand {
  text-align: center; margin-top: 12px; font-size: 11.5px; color: var(--muted);
}

@media (max-width: 560px) {
  .site-header-in { padding: 10px 16px; }
}

/* ── 공용 레이아웃/콘텐츠 (법적 페이지 등 신규 정적 페이지용) ─────────── */
.wrap { max-width: var(--content-width); margin: 0 auto; padding: 0 16px 48px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 20px; margin-top: 16px;
}
.page-h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.4px; padding: 28px 4px 4px; }
.page-lead { font-size: 14px; color: var(--muted); padding: 0 4px 4px; }

.content h2 { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; margin-bottom: 8px; }
.content h3 { font-size: 14.5px; font-weight: 700; margin: 14px 0 6px; }
.content p { font-size: 14px; color: var(--muted); margin-bottom: 12px; line-height: 1.7; }
.content p:last-child { margin-bottom: 0; }
.content strong { color: var(--text); }
.content ul { margin: 0 0 12px 18px; font-size: 14px; color: var(--muted); line-height: 1.8; }

table.spec { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.spec th, table.spec td { padding: 9px 4px; border-bottom: 1px solid var(--border); text-align: left; }
table.spec tr:last-child th, table.spec tr:last-child td { border-bottom: none; }
table.spec th { color: var(--muted); font-weight: 500; width: 38%; }

details { border-bottom: 1px solid var(--border); }
details:last-of-type { border-bottom: none; }
summary {
  cursor: pointer; padding: 13px 0; font-size: 14.5px; font-weight: 600;
  list-style: none; display: flex; justify-content: space-between; align-items: center;
}
summary::after { content: '+'; color: var(--muted); font-size: 18px; font-weight: 400; }
details[open] summary::after { content: '−'; }
details .a { font-size: 14px; color: var(--muted); padding-bottom: 14px; }
