/* ============================================================
   market.css — Market Dashboard (God's Eye → KN design)
   Loads AFTER style.css; extends KN base tokens.
   ============================================================ */

/* Market-specific semantic tokens */
:root {
  --m-fear:    #ef4444;   /* KN --danger */
  --m-greed:   #10b981;   /* KN --success */
  --m-neutral: #f59e0b;   /* amber */
  --m-radius:  10px;      /* pulse-chip(10px)과 동일 — 본편 카드(6px)에 가깝게 */

  --m-section-h: 290px;
  --m-metric-h:  118px;
  --text-muted: #a1a1aa;
}

/* ---- Background -------------------------------------------- */
.market-page {
  background:
    radial-gradient(circle at 10% 8%,  rgba(59, 130, 246, 0.12), transparent 32%),
    radial-gradient(circle at 88% 18%, rgba(99, 102, 241, 0.08), transparent 28%),
    var(--bg-main);
  min-height: 100vh;
}

/* Ambient orbs */
.market-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(64px);
  opacity: 0.18;
  pointer-events: none;
  z-index: 0;
}
.market-orb-left  { width: 320px; height: 320px; left: -120px; top: 26%;     background: #3b82f6; }
.market-orb-right { width: 320px; height: 320px; right: -140px; bottom: 12%; background: #6366f1; }

/* ---- Market sub-header (timeframe + AI btn) ---------------- */
.market-subheader {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 1.5rem;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-main);
  position: sticky;
  top: var(--header-h);
  z-index: 9;
  flex-wrap: wrap;
}

.timeframe-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.timeframe-segment {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-focus);
  border-radius: 999px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: rgba(0,0,0,0.3);
  max-width: 100%;
  flex-shrink: 1;
}

.timeframe-segment::-webkit-scrollbar { display: none; }

.timeframe-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.timeframe-btn + .timeframe-btn {
  border-left: 1px solid var(--border-light);
}

.timeframe-btn.active {
  background: var(--primary);
  color: #fff;
}

.timeframe-btn:hover:not(.active) {
  background: var(--surface-hover);
  color: var(--text-primary);
}

/* Right-aligned subheader action group (layout switch / edit / AI) */
.subheader-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-wrap: wrap;
}

/* ---- Layout toolbar ---------------------------------------- */
.layout-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 1.5rem;
  background: rgba(24,24,27,0.6);
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
  position: sticky;
  top: calc(var(--header-h) + 40px);
  z-index: 8;
}

.layout-toolbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.layout-toolbar-note { margin: 0; color: var(--text-muted); font-size: 12px; }

/* ---- Market main area ------------------------------------- */
.market-main {
  /* 좌우 1.5rem: 서브헤더/GNB 콘텐츠 라인과 정렬 (본편 .grid-container와 동일)
     하단 여백은 플로팅 티커(46px + 보더/오프셋)에 가려지지 않을 만큼 확보 */
  padding: 12px 1.5rem 72px;
  position: relative;
  z-index: 1;
}

/* ---- Market Pulse strip ------------------------------------ */
.market-pulse { margin: 2px 0 12px; }

.market-pulse-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.market-pulse-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.market-pulse-sub {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.market-pulse-updated {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-muted);
}

.market-pulse-track {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-focus) transparent;
  -webkit-overflow-scrolling: touch;
}
.market-pulse-track::-webkit-scrollbar { height: 5px; }

.pulse-chip {
  flex: 1 0 auto;
  min-width: 128px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(24,24,27,0.82);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  backdrop-filter: blur(10px);
}

.pulse-chip-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.pulse-chip-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.pulse-chip-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.pulse-chip-change {
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.pulse-up   .pulse-chip-change { color: var(--m-greed); }
.pulse-down .pulse-chip-change { color: var(--m-fear); }
.pulse-flat .pulse-chip-change { color: var(--text-muted); }

.pulse-chip-spark { flex: 0 0 auto; }
.pulse-chip-spark canvas { display: block; }

/* FNG 전용 칩: 톤 색을 값에도 입힌다 */
.pulse-chip-fng.pulse-fear    .pulse-chip-value { color: var(--m-fear); }
.pulse-chip-fng.pulse-greed   .pulse-chip-value { color: var(--m-greed); }
.pulse-chip-fng.pulse-neutral .pulse-chip-value { color: var(--m-neutral); }
.pulse-chip-fng .pulse-chip-change { color: var(--text-muted); }

/* 로딩 스켈레톤 */
.pulse-chip.pulse-loading .pulse-chip-value,
.pulse-chip.pulse-loading .pulse-chip-change {
  color: transparent;
  border-radius: 5px;
  background: linear-gradient(90deg, rgba(255,255,255,0.05) 25%, rgba(255,255,255,0.12) 50%, rgba(255,255,255,0.05) 75%);
  background-size: 200% 100%;
  animation: pulse-shimmer 1.4s ease-in-out infinite;
}

@keyframes pulse-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (max-width: 640px) {
  .pulse-chip { min-width: 118px; padding: 7px 10px; }
  .market-pulse-updated { display: none; }
}

/* ---- Dashboard grid --------------------------------------- */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  /* 본편 .grid-container처럼 카드가 자연 높이를 유지(래그드 하단 허용) —
     style.css .section-card의 height: max-content와 함께 동작 */
  align-items: start;
}

@media (min-width: 768px) {
  .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-card.span-2, .section-card.span-3 { grid-column: span 2; }
}
@media (min-width: 1280px) {
  .dashboard-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .section-card.span-2 { grid-column: span 2; }
  .section-card.span-3 { grid-column: span 3; }
}

/* ---- Section card -----------------------------------------
   본편 style.css의 .section-card(동일 클래스)를 확장한다:
   - hover 시 border-focus 하이라이트 + transition은 본편 규칙을 그대로 상속
   - margin-bottom: 0 — 본편의 1rem(세로 갭이 24px로 벌어지던 누수)을 리셋,
     간격은 grid gap(12px)이 단일하게 담당
   - 그림자는 본편의 플랫 톤에 맞춰 최소화 (orb 배경 위 분리감만) */
.section-card {
  background: rgba(24,24,27,0.82); /* --surface(#18181b) 톤 + orb 투과용 알파 */
  border: 1px solid var(--border-light);
  border-radius: var(--m-radius);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.16);
  padding: 10px;
  margin-bottom: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.section-card.dragging    { opacity: 0.45; border-style: dashed; }
.section-card.drop-target { box-shadow: 0 0 0 2px rgba(59,130,246,0.5) inset; }

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.card-title-row h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.card-title-right { display: flex; align-items: center; gap: 6px; }

/* ---- Chip / badge ----------------------------------------- */
.chip {
  font-size: 10px;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  padding: 2px 7px;
  border-radius: 999px;
}

.chip-primary {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
  font-weight: 700;
}

.chip-muted { color: var(--text-muted); }

/* ---- Flow group chips (매크로/주식/크립토/심리/일정/AI) ------ */
.card-title-left {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.card-title-left h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.group-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.group-chip.group-equity    { color: #7db4fa; background: rgba(59, 130, 246, 0.10); border-color: rgba(59, 130, 246, 0.28); }
.group-chip.group-macro     { color: #fbbf24; background: rgba(245, 158, 11, 0.10); border-color: rgba(245, 158, 11, 0.28); }
.group-chip.group-crypto    { color: #fb923c; background: rgba(249, 115, 22, 0.10); border-color: rgba(249, 115, 22, 0.28); }
.group-chip.group-sentiment { color: #fb7185; background: rgba(244, 63, 94, 0.10);  border-color: rgba(244, 63, 94, 0.28); }
.group-chip.group-event     { color: #34d399; background: rgba(16, 185, 129, 0.10); border-color: rgba(16, 185, 129, 0.28); }
.group-chip.group-ai        { color: #c4b5fd; background: rgba(139, 92, 246, 0.12); border-color: rgba(139, 92, 246, 0.30); }

/* ---- Span controls ---------------------------------------- */
.span-controls { display: none; gap: 4px; }
.section-edit-controls { display: inline-flex; align-items: center; gap: 4px; }
.layout-mode .span-controls { display: inline-flex; }

.section-order-controls { display: none; gap: 2px; }
.layout-mode .section-order-controls { display: inline-flex; }

.order-btn {
  width: 22px; height: 20px; padding: 0;
  border-radius: 5px;
  border: 1px solid var(--border-focus);
  background: rgba(0,0,0,0.4);
  color: var(--text-muted);
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  position: relative;
}
.order-btn::after {
  content: '';
  position: absolute;
  inset: -12px -11px;
}
.order-btn:hover { background: rgba(59,130,246,0.15); color: var(--primary); border-color: var(--primary); }

.span-btn {
  width: 22px; height: 20px; padding: 0;
  border-radius: 5px;
  border: 1px solid var(--border-focus);
  background: rgba(0,0,0,0.4);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  position: relative;
}
.span-btn::after {
  content: '';
  position: absolute;
  inset: -12px -11px;
}

.span-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.section-delete-btn { padding: 0 8px; height: 20px; border-radius: 5px; font-size: 12px; line-height: 1; position: relative; }
.section-delete-btn::after { content: ''; position: absolute; inset: -12px -8px; }

/* ---- [hidden] guard ----------------------------------------
   style.css의 `.btn { display: inline-flex }` 같은 author display 규칙이
   UA의 `[hidden] { display: none }`(UA origin이라 항상 짐)을 덮어써
   비로그인 상태에서 숨겨야 할 레이아웃/편집 버튼이 노출되던 버그 방지.
   (이 페이지의 hidden 속성은 전부 "완전 숨김" 의도 — gnb.js는 .hidden 클래스만 사용) */
[hidden] { display: none !important; }

/* ---- Button aliases (compat with God's Eye HTML) ----------- */
.btn-sm   { padding: 4px 10px !important; font-size: 12px !important; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---- AI 시황분석 잠금(teaser) 상태 — 비로그인 로그인 유도 ----
   .btn.primary 톤을 낮춘 프리미엄 힌트 룩. 클릭은 가능(로그인 유도 모달). */
.btn.ai-teaser {
  position: relative;
  background: rgba(59, 130, 246, 0.12);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.btn.ai-teaser:hover {
  background: rgba(59, 130, 246, 0.22);
  color: #dbeafe;
  border-color: rgba(59, 130, 246, 0.55);
}

.btn.ai-teaser::before {
  content: "🔒";
  font-size: 10px;
  line-height: 1;
}

/* 호버 툴팁 (data-tip) — 터치 기기에서는 클릭 시 모달이 안내를 대신함 */
.btn.ai-teaser::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(9, 9, 11, 0.95);
  border: 1px solid var(--border-focus);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(-2px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.btn.ai-teaser:hover::after,
.btn.ai-teaser:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

@media (hover: none) {
  .btn.ai-teaser::after { display: none; }
}

/* Active nav link for Market tab */
header nav.gnb a.gnb-market-active,
header nav.gnb a[href="/market"]:not([href="/market/api"]):focus {
  color: var(--primary);
}

/* ---- Widget host ------------------------------------------ */
.widget-host {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.4);
  position: relative;
}

/* ---- Widget loading skeleton -------------------------------
   TV 스크립트/iframe 로드 동안 표시. 본편 skeleton(shimmer) 톤 재활용. */
.widget-skeleton {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(9,9,11,0.55);
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.35s ease;
}

.widget-skeleton.widget-skeleton-exit { opacity: 0; }

.widget-skeleton-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 44%;
  max-height: 110px;
}

.widget-skeleton-bars i {
  display: block;
  width: 9px;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(90deg, rgba(255,255,255,0.05) 25%, rgba(255,255,255,0.14) 50%, rgba(255,255,255,0.05) 75%);
  background-size: 200% 100%;
  animation: pulse-shimmer 1.4s ease-in-out infinite;
}

.widget-skeleton-bars i:nth-child(1)  { height: 38%; animation-delay: 0s; }
.widget-skeleton-bars i:nth-child(2)  { height: 55%; animation-delay: 0.08s; }
.widget-skeleton-bars i:nth-child(3)  { height: 44%; animation-delay: 0.16s; }
.widget-skeleton-bars i:nth-child(4)  { height: 68%; animation-delay: 0.24s; }
.widget-skeleton-bars i:nth-child(5)  { height: 52%; animation-delay: 0.32s; }
.widget-skeleton-bars i:nth-child(6)  { height: 80%; animation-delay: 0.4s; }
.widget-skeleton-bars i:nth-child(7)  { height: 62%; animation-delay: 0.48s; }
.widget-skeleton-bars i:nth-child(8)  { height: 90%; animation-delay: 0.56s; }
.widget-skeleton-bars i:nth-child(9)  { height: 70%; animation-delay: 0.64s; }
.widget-skeleton-bars i:nth-child(10) { height: 100%; animation-delay: 0.72s; }
.widget-skeleton-bars i:nth-child(11) { height: 78%; animation-delay: 0.8s; }
.widget-skeleton-bars i:nth-child(12) { height: 58%; animation-delay: 0.88s; }

.widget-skeleton-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

@media (prefers-reduced-motion: reduce) {
  .widget-skeleton-bars i { animation: none; background-position: 50% 0; }
}

.widget-host-main      { height: var(--m-section-h); }
.widget-host-secondary { height: var(--m-section-h); }

.widget-status { margin: 5px 0 0; color: #f59e0b; font-size: 12px; }

/* ---- Yahoo Finance canvas chart (KRX/KOSDAQ 심볼) ----------- */
.yf-chart-body {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.yf-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 12px 4px;
}

.yf-price {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.yf-change {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.yf-change.yf-up   { color: var(--m-greed); }
.yf-change.yf-down { color: var(--m-fear); }
.yf-change.yf-flat { color: var(--text-muted); }

.yf-period {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

.yf-canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}
.yf-canvas-wrap canvas { display: block; position: absolute; inset: 0; }

@media (max-width: 640px) {
  .yf-period { display: none; }
}

/* ---- Fear & Greed card ------------------------------------ */
.fng-body {
  min-height: var(--m-section-h);
  height: var(--m-section-h);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.fng-value          { margin: 0; font-weight: 700; font-size: 50px; line-height: 1; }
.fng-classification, .fng-updated, .fng-status { margin: 0; color: var(--text-muted); }
.fng-status         { font-size: 12px; }

.fng-fear   .fng-value, .fng-fear   .fng-classification { color: var(--m-fear); }
.fng-greed  .fng-value, .fng-greed  .fng-classification { color: var(--m-greed); }
.fng-neutral .fng-value,.fng-neutral .fng-classification{ color: var(--m-neutral); }

/* ---- Metric card ------------------------------------------ */
.metric-body {
  min-height: var(--m-metric-h);
  height: var(--m-metric-h);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.metric-value       { margin: 0; font-weight: 700; font-size: 34px; line-height: 1; }
.metric-classification, .metric-updated { margin: 0; color: var(--text-muted); font-size: 12px; }

.metric-fear   .metric-value, .metric-fear   .metric-classification { color: var(--m-fear); }
.metric-greed  .metric-value, .metric-greed  .metric-classification { color: var(--m-greed); }
.metric-neutral .metric-value,.metric-neutral .metric-classification{ color: var(--m-neutral); }

/* ---- AI report card --------------------------------------- */
.ai-card-body {
  min-height: var(--m-section-h);
  height: var(--m-section-h);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-focus) transparent;
}

.ai-report-placeholder {
  display: flex; align-items: center; justify-content: center;
  height: 100%; padding: 20px; text-align: center;
}
.ai-report-hint { color: var(--text-muted); font-size: 13px; line-height: 1.6; }

.ai-report { display: flex; flex-direction: column; gap: 16px; padding: 4px; }

.ai-report-section-label {
  font-size: 12px; font-weight: 700; color: var(--primary);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 8px; display: flex; align-items: center; gap: 6px;
}

.ai-report-overall {
  background: rgba(255,255,255,0.03); border-radius: 10px;
  padding: 12px; border: 1px solid rgba(255,255,255,0.06);
}

.ai-report-summary { margin: 0; font-size: 13px; line-height: 1.6; color: var(--text-primary); }

.ai-signals-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

.ai-signals-block { padding: 10px; border-radius: 8px; background: rgba(0,0,0,0.2); }
.ai-signals-bull  { border-left: 3px solid var(--m-greed); }
.ai-signals-bear  { border-left: 3px solid var(--m-fear); }

.ai-signals-label { font-size: 12px; font-weight: 700; margin-bottom: 6px; }
.ai-signals-bull .ai-signals-label { color: var(--m-greed); }
.ai-signals-bear .ai-signals-label { color: var(--m-fear); }
.ai-signals-block ul { margin: 0; padding-left: 14px; }
.ai-signals-block li { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }

.ai-report-per-chart, .ai-report-related { display: flex; flex-direction: column; }
.ai-per-chart-list { display: flex; flex-direction: column; gap: 8px; }

.ai-per-chart-item {
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 10px 12px;
}

.ai-per-chart-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.ai-per-chart-symbol { font-weight: 700; font-size: 13px; color: var(--text-primary); }
.ai-per-chart-ticker { font-size: 12px; color: var(--text-muted); }
.ai-per-chart-insight { margin: 0; font-size: 12px; line-height: 1.5; color: var(--text-secondary); }

.ai-related-list { display: flex; flex-direction: column; gap: 6px; }

.ai-related-item {
  display: flex; align-items: center; gap: 8px; font-size: 12px;
  background: rgba(59,130,246,0.04); padding: 6px 10px; border-radius: 6px;
}

.ai-related-symbol { font-weight: 700; color: var(--primary); min-width: 60px; }
.ai-related-name   { color: var(--text-primary); font-weight: 500; }
.ai-related-reason { color: var(--text-muted); font-size: 12px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ---- Calendar --------------------------------------------- */
.calendar-body {
  min-height: var(--m-section-h);
  height: var(--m-section-h);
  display: flex; flex-direction: column; gap: 10px;
  overflow-y: auto; overflow-x: hidden;
}

.calendar-status { color: var(--text-muted); font-size: 13px; text-align: center; margin: auto; }

.calendar-event {
  display: flex; flex-direction: column;
  padding: 10px 12px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border-light);
  border-radius: 8px;
}

.calendar-event-header { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }

.calendar-date {
  font-weight: 600; font-size: 12px; color: var(--primary);
  background: rgba(59,130,246,0.1);
  padding: 2px 6px; border-radius: 4px; white-space: nowrap;
}

.calendar-title { font-weight: 600; font-size: 13px; color: var(--text-primary); line-height: 1.3; flex: 1; min-width: 0; }
.calendar-desc  { font-size: 11px; color: var(--text-muted); line-height: 1.4; margin-bottom: 2px; }


.calendar-meta {
  display: inline-flex; gap: 12px; font-size: 12px;
  color: var(--text-secondary); background: rgba(0,0,0,0.2);
  padding: 4px 8px; border-radius: 6px; width: fit-content;
}

.calendar-fcst  { color: var(--m-greed); }
.calendar-impact { font-size: 11px; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }

/* 중요도(시장 영향도) 시각화: 이벤트 좌측 액센트 + 우측 등급 배지 */
.calendar-event.imp-high   { border-left: 3px solid var(--m-fear); }
.calendar-event.imp-medium { border-left: 3px solid var(--m-neutral); }
.calendar-event.imp-low    { border-left: 3px solid var(--border-light); }

.calendar-imp {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: auto; flex-shrink: 0;
  font-size: 10px; font-weight: 700; letter-spacing: 0.02em;
  padding: 2px 7px; border-radius: 999px; white-space: nowrap;
}
.calendar-imp-dots { font-size: 8px; letter-spacing: 1px; line-height: 1; }
.calendar-imp.imp-high   { color: var(--m-fear);    background: rgba(239,68,68,0.12); }
.calendar-imp.imp-medium { color: var(--m-neutral); background: rgba(245,158,11,0.12); }
.calendar-imp.imp-low    { color: var(--text-muted); background: rgba(255,255,255,0.06); }

/* D-day 칩: 임박한 일정이 먼저 눈에 오게 */
.calendar-dday {
  font-size: 10px; font-weight: 700; white-space: nowrap; flex-shrink: 0;
  color: var(--m-neutral); background: rgba(245,158,11,0.12);
  padding: 2px 6px; border-radius: 4px;
}
.calendar-dday-today {
  color: var(--m-fear); background: rgba(239,68,68,0.14);
  animation: calendar-today-pulse 2.4s ease-in-out infinite;
}
@keyframes calendar-today-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* 지난 일정: 흐리게 뒤로 */
.calendar-event.calendar-past { opacity: 0.5; }
.calendar-event.calendar-past:hover { opacity: 0.85; }

.calendar-past-divider {
  display: flex; align-items: center; gap: 8px;
  margin-top: 6px; font-size: 10px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em;
}
.calendar-past-divider::before,
.calendar-past-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border-light);
}

.calendar-empty-upcoming { font-size: 12px; color: var(--text-muted); padding: 6px 2px; }

.calendar-group { display: flex; flex-direction: column; gap: 6px; }
.calendar-group + .calendar-group { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border-light); }

.calendar-group-header {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 6px; border-radius: 6px;
  background: rgba(59,130,246,0.06);
  margin-bottom: 2px;
}

.country-krw .calendar-group-header { background: rgba(16,185,129,0.06); }

.calendar-group-flag  { font-size: 14px; line-height: 1; }
.calendar-group-label { font-size: 12px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: 0.05em; flex: 1; }
.country-krw .calendar-group-label { color: var(--m-greed); }
.calendar-group-count { font-size: 12px; color: var(--text-muted); background: rgba(255,255,255,0.06); padding: 1px 6px; border-radius: 999px; }

/* ---- Symbol search ---------------------------------------- */
.inline-field-row { display: flex; gap: 6px; align-items: center; }
.inline-field-row .field-input { flex: 1; }

.symbol-search-results {
  margin-top: 8px; max-height: 180px; overflow: auto;
  border: 1px solid var(--border-focus);
  border-radius: 8px;
  background: rgba(0,0,0,0.4);
}

.symbol-search-item {
  width: 100%; border: none;
  border-bottom: 1px solid var(--border-light);
  background: transparent; color: var(--text-primary);
  text-align: left; padding: 8px 10px; cursor: pointer;
}
.symbol-search-item:last-child { border-bottom: none; }
.symbol-search-item:hover { background: rgba(59,130,246,0.08); }
.symbol-search-title { margin: 0; font-size: 12px; }
.symbol-search-meta  { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.symbol-search-empty { margin: 0; padding: 10px; font-size: 12px; color: var(--text-muted); }

/* ---- Ticker bar ------------------------------------------- */
.ticker-host { min-height: 46px; height: 46px; overflow: hidden; }

.ticker-floating {
  position: fixed;
  left: 8px; right: 8px;
  bottom: max(4px, env(safe-area-inset-bottom));
  z-index: 80; pointer-events: none;
}

.ticker-floating-inner {
  background: rgba(9,9,11,0.9);
  border: 1px solid var(--border-focus);
  border-radius: 8px; padding: 0 6px;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 28px rgba(0,0,0,0.4);
  pointer-events: auto;
}

.ticker-floating iframe { width: 100% !important; height: 46px !important; }
.ticker-floating .widget-status { margin: 2px 8px 0; font-size: 9px; }

/* ---- Modals ----------------------------------------------- */
.modal-root {
  position: fixed; inset: 0; z-index: 120;
}

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative; z-index: 1;
  width: min(540px, calc(100vw - 24px));
  margin: 10vh auto 0;
  padding: 18px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.1);
  background: linear-gradient(150deg, rgba(24,24,27,0.96) 0%, rgba(9,9,11,0.98) 100%);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 40px rgba(99,102,241,0.08);
  max-height: calc(90dvh - 10vh);
  overflow-y: auto;
}
@media (max-width: 480px) {
  .modal-panel {
    margin: auto auto 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    max-height: 90dvh;
    overflow-y: auto;
  }
}

.modal-panel h2 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.field-label {
  display: block;
  margin-top: 8px; margin-bottom: 4px;
  color: var(--text-secondary); font-size: 12px;
}

.field-input {
  width: 100%;
  border: 1px solid var(--border-focus);
  border-radius: 8px;
  background: rgba(0,0,0,0.4);
  color: var(--text-primary);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}
.field-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(59,130,246,0.2); }

.field-error { margin: 6px 0 0; color: var(--danger); font-size: 12px; }
.field-select { border: 1px solid var(--border-focus); border-radius: 8px; background: rgba(0,0,0,0.4); color: var(--text-primary); padding: 6px 10px; font-size: 12px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 14px; }

/* AI modal */
.ai-modal-status { margin: 6px 0 10px; color: var(--text-muted); font-size: 12px; }

.ai-suggest-list {
  max-height: 45vh; overflow: auto;
  border: 1px solid var(--border-focus); border-radius: 8px;
}

.ai-suggest-item { display: flex; gap: 8px; align-items: flex-start; padding: 8px; border-bottom: 1px solid var(--border-light); }
.ai-suggest-item:last-child { border-bottom: none; }
.ai-suggest-title  { margin: 0; font-size: 13px; color: var(--text-primary); }
.ai-suggest-symbol { margin: 2px 0 0; color: var(--text-muted); font-size: 12px; }
.ai-suggest-reason { margin: 4px 0 0; color: var(--text-muted); font-size: 12px; }

/* Layout list */
.layout-item {
  cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  margin-bottom: 6px;
  transition: background 0.15s;
}
.layout-item:hover { background: rgba(255,255,255,0.06); }

/* ---- Toast ------------------------------------------------ */
.toast-container {
  position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
  z-index: 150; display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}

.toast {
  min-width: 260px; max-width: 90vw;
  background: rgba(24,24,27,0.95);
  color: var(--text-primary);
  padding: 12px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 500; text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  border: 1px solid var(--border-focus);
  animation: m-toast-enter 0.35s cubic-bezier(0.16,1,0.3,1) forwards;
  opacity: 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}

.toast.toast-error   { border-color: rgba(239,68,68,0.5);  background: rgba(30,8,8,0.96); }
.toast.toast-success { border-color: rgba(16,185,129,0.5); background: rgba(5,25,18,0.96); }
.toast.toast-exit    { animation: m-toast-exit 0.3s cubic-bezier(0.16,1,0.3,1) forwards; }

@keyframes m-toast-enter {
  0%   { opacity: 0; transform: translateY(16px) scale(0.96); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes m-toast-exit {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(16px) scale(0.96); }
}

/* ---- Custom scrollbar for market modals ------------------- */
.custom-scrollbar::-webkit-scrollbar { width: 5px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: var(--border-focus); border-radius: 4px; }

/* ---- Small tablet (641–767 px) --------------------- */
@media (min-width: 641px) and (max-width: 767px) {
  .market-main { padding: 10px 12px 52px; }
}

/* ---- Mobile ---------------------------------------- */
@media (max-width: 640px) {
  :root { --m-section-h: 260px; --m-metric-h: 110px; }
  /* 좌우 1rem: 서브헤더(1rem)·본편 모바일 콘텐츠 라인과 정렬 */
  .market-main { padding: 8px 1rem 68px; }
  .market-subheader { padding: 6px 1rem; }
  .layout-toolbar { padding: 6px 1rem; }
  .inline-field-row { flex-wrap: wrap; }
  .inline-field-row .btn { width: 100%; }
  .ticker-floating { left: 4px; right: 4px; }
}

/* ---- Mobile (≤480px) — 콤팩트 서브헤더 & 터치 타깃 ----------
   style.css의 전역 모바일 규칙(button min-height 44px 등)과 협업:
   탭 타깃은 유지하되, 2행으로 부풀어 sticky로 화면을 점유하던
   서브헤더를 흐름 배치 + 정돈된 2행 구성으로 바꾼다. */
@media (max-width: 480px) {
  /* 고정 해제: 헤더(52px)만 남기고 세로 공간을 콘텐츠에 양보 */
  .market-subheader {
    position: static;
    padding: 8px 1rem;
    row-gap: 8px;
  }

  /* "조회 기간" 텍스트 라벨 숨김 — 세그먼트(1M/3M/6M/1Y)로 자명,
     role=group의 aria-label("차트 조회 기간")이 접근성 라벨을 유지 */
  .timeframe-label { display: none; }

  /* 세그먼트: 한 줄 전체 폭, 버튼 4등분 (min-height 44px는 전역 규칙이 보장) */
  .timeframe-segment { flex: 1 1 100%; display: flex; }
  .timeframe-btn { flex: 1 1 0; padding: 8px 0; }

  /* 액션 버튼(레이아웃/편집/AI): 자기 줄에서 남는 폭을 나눠 채움 —
     비로그인 시 AI teaser가 자연스러운 전폭 CTA가 된다 */
  .subheader-actions { margin-left: 0; width: 100%; }
  .subheader-actions .btn { flex: 1 1 auto; }

  /* 편집 모드 스팬/삭제 컨트롤: 전역 44px 최소높이가 20px 밀집 컨트롤을
     세로로 찢는 것 보정 — 카드 헤더 안 컨트롤이라 30px로 절충 */
  button.span-btn { width: 30px; height: 30px; min-height: 30px; font-size: 12px; }
  button.section-delete-btn { height: 30px; min-height: 30px; }

}
