/* ==========================================================================
   NAKAGORI DATA CENTER — Light / Dark / System Cyber BI Design System
   로고 컬러 시스템:
   - 메인 포인트: Cyber Electric Violet (#7C3AED Light / #A855F7 Dark)
   - 보조 포인트: Lens Sparkle Cyan    (#0891B2 Light / #22D3EE Dark)
   - 강조 하이라이트: Pixel Blonde Gold (#D97706 Light / #FACC15 Dark)
   ========================================================================== */

:root {
  color-scheme: light;
  --bg-canvas: #f7f5fd;
  --bg-surface: #ffffff;
  --bg-subtle: #f1eefb;
  --bg-hover: #f5f3ff;
  --border-light: #e5e0f4;
  --border-muted: #d1c7eb;
  --text-primary: #17122b;
  --text-secondary: #4a4268;
  --text-muted: #706791;

  --brand-primary: #7c3aed;
  --brand-primary-hover: #6d28d9;
  --brand-primary-soft: #f5f3ff;
  --brand-primary-border: #ddd6fe;
  --brand-secondary: #0891b2;
  --brand-secondary-soft: #ecfeff;
  --brand-gold: #d97706;
  --brand-dark-btn: #1e1638;
  --brand-dark-btn-hover: #2d2154;

  --roas-bg: #fff1f5;
  --roas-border: #fda4af;
  --roas-text: #e11d48;
  --roas-sub: rgba(225, 29, 72, 0.78);

  --table-header-bg: #f8f6fe;
  --table-accent-bg: #f3effd;
  --table-accent-text: #6d28d9;
  --table-row-hover: #f6f3ff;

  --doc-border: #7c3aed;
  --doc-h2: #5b21b6;
  --doc-th-bg: #f5f3ff;
  --doc-th-text: #4c1d95;
  --doc-quote-bg: #f3f0ff;
}

html.dark {
  color-scheme: dark;
  --bg-canvas: #0a0714;
  --bg-surface: #130f24;
  --bg-subtle: #1c1635;
  --bg-hover: rgba(168, 85, 247, 0.14);
  --border-light: #282047;
  --border-muted: #3b2f66;
  --text-primary: #f4f1ff;
  --text-secondary: #d0c8ea;
  --text-muted: #988ec2;

  --brand-primary: #9333ea;
  --brand-primary-hover: #a855f7;
  --brand-primary-soft: rgba(168, 85, 247, 0.18);
  --brand-primary-border: rgba(168, 85, 247, 0.42);
  --brand-secondary: #22d3ee;
  --brand-secondary-soft: rgba(34, 211, 238, 0.15);
  --brand-gold: #facc15;
  --brand-dark-btn: #7c3aed;
  --brand-dark-btn-hover: #9333ea;

  --roas-bg: rgba(225, 29, 72, 0.14);
  --roas-border: rgba(244, 63, 94, 0.44);
  --roas-text: #fb7185;
  --roas-sub: rgba(251, 113, 133, 0.86);

  --table-header-bg: #100c1f;
  --table-accent-bg: rgba(168, 85, 247, 0.18);
  --table-accent-text: #d8b4fe;
  --table-row-hover: rgba(168, 85, 247, 0.09);

  --doc-border: #a855f7;
  --doc-h2: #c084fc;
  --doc-th-bg: rgba(168, 85, 247, 0.2);
  --doc-th-text: #e9d5ff;
  --doc-quote-bg: rgba(34, 211, 238, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: 'Pretendard Variable', 'Pretendard', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.18s ease, color 0.18s ease;
}

code,
pre,
.font-mono {
  font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* 카드 스타일 */
.bi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: 0.9rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.18s ease;
}

.bi-card:hover {
  border-color: var(--brand-primary-border);
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.1);
}

html.dark .bi-card {
  box-shadow: 0 3px 14px rgba(5, 2, 15, 0.45);
}

html.dark .bi-card:hover {
  box-shadow: 0 6px 20px rgba(147, 51, 234, 0.16);
}

/* ROAS 강조 카드 */
.bi-card-roas {
  background: var(--roas-bg);
  border: 1px solid var(--roas-border);
  border-radius: 0.9rem;
  box-shadow: 0 1px 2px rgba(225, 29, 72, 0.06);
}

/* 사이드바 네비게이션 */
.side-nav-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 0.65rem;
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 500;
  transition: all 0.15s ease;
  text-align: left;
}

.side-nav-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.side-nav-btn.active {
  background: linear-gradient(135deg, var(--brand-primary), #6d28d9);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 3px 12px rgba(124, 58, 237, 0.3);
}

html.dark .side-nav-btn.active {
  background: linear-gradient(135deg, #9333ea, #7c3aed);
  box-shadow: 0 3px 14px rgba(168, 85, 247, 0.35);
}

.side-sub-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  width: 100%;
  padding: 0.45rem 0.7rem 0.45rem 1.85rem;
  border-radius: 0.55rem;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  transition: all 0.14s ease;
  text-align: left;
}

.side-sub-item:hover {
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
}

.side-sub-item.active {
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
  font-weight: 700;
}

/* 3단계 테마 전환기 (Light / Dark / System) */
.theme-switcher {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: 0.7rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
}

.theme-opt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.38rem 0.35rem;
  border-radius: 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.15s ease;
  cursor: pointer;
}

.theme-opt-btn:hover {
  color: var(--text-primary);
}

.theme-opt-btn.active {
  background: var(--bg-surface);
  color: var(--brand-primary);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
}

html.dark .theme-opt-btn.active {
  background: rgba(168, 85, 247, 0.24);
  color: #e9d5ff;
  box-shadow: none;
}

/* 인풋 & 셀렉트 공통 테마 대응 */
.light-input {
  background: var(--bg-surface);
  border: 1px solid var(--border-muted);
  color: var(--text-primary);
  border-radius: 0.55rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.light-input:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.18);
}

.light-input::placeholder {
  color: var(--text-muted);
}

html.dark .light-input {
  background: #100c1f;
  border-color: #3b2f66;
  color: #f4f1ff;
}

/* 메인 브랜드 버튼 (Cyber Electric Violet) */
.btn-brand {
  background: var(--brand-primary);
  color: #ffffff;
  transition: all 0.16s ease;
}

.btn-brand:hover:not(:disabled) {
  background: var(--brand-primary-hover);
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.36);
}

.btn-brand:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* 조회 버튼 */
.btn-dark-solid {
  background: var(--brand-dark-btn);
  color: #ffffff;
  transition: all 0.15s ease;
}

.btn-dark-solid:hover:not(:disabled) {
  background: var(--brand-dark-btn-hover);
}

/* 드래그 앤 드롭 존 */
.dropzone {
  border: 2px dashed var(--border-muted);
  background: var(--bg-subtle);
  transition: all 0.18s ease;
}

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--brand-primary);
  background: var(--brand-primary-soft);
}

/* 드래그 앤 드롭 위젯 (KPI 카드 & 차트 카드) */
.draggable-widget {
  cursor: grab;
  position: relative;
}

.draggable-widget:active {
  cursor: grabbing;
}

.draggable-widget.dragging {
  opacity: 0.45;
  transform: scale(0.985);
}

.draggable-widget.drag-over-target {
  outline: 2px dashed var(--brand-primary);
  outline-offset: 2px;
  background: var(--brand-primary-soft);
}

/* 데이터 테이블 */
.data-table-wrap {
  overflow: auto;
  border-radius: 0.75rem;
  border: 1px solid var(--border-light);
  background: var(--bg-surface);
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8rem;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--table-header-bg);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
  text-align: left;
}

.data-table thead th.col-accent-soft {
  background: var(--table-accent-bg);
  color: var(--table-accent-text);
}

.data-table tbody td {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  white-space: nowrap;
}

.data-table tbody tr:hover td {
  background: var(--table-row-hover);
}

/* 게임 비교 체크박스 필 */
.game-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  border-radius: 9999px;
  background: var(--bg-surface);
  border: 1px solid var(--border-muted);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.game-chip:hover {
  border-color: var(--brand-primary);
  color: var(--text-primary);
}

.game-chip.selected {
  background: var(--brand-primary-soft);
  color: var(--text-primary);
  font-weight: 600;
}

.game-color-dot {
  width: 9px;
  height: 9px;
  border-radius: 9999px;
  display: inline-block;
  flex-shrink: 0;
}

/* Google Calendar 스타일 월간 그리드 */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-top: 1px solid var(--border-light);
  border-left: 1px solid var(--border-light);
  background: var(--bg-surface);
  border-radius: 0.75rem;
  overflow: hidden;
}

.cal-day-header {
  padding: 0.55rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
  background: var(--table-header-bg);
  border-right: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
}

.cal-cell {
  min-height: 112px;
  padding: 0.45rem;
  border-right: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-surface);
  cursor: pointer;
  transition: background 0.14s ease;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.cal-cell:hover {
  background: var(--bg-hover);
}

.cal-cell.other-month {
  background: var(--bg-subtle);
  opacity: 0.58;
}

.cal-event-chip {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.18rem 0.42rem;
  border-radius: 0.35rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: filter 0.12s ease;
}

.cal-event-chip:hover {
  filter: brightness(0.95);
}

/* AI 슬라이드 드로어 & Canvas 문서 뷰어 */
.ai-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  width: min(460px, 96vw);
  background: var(--bg-surface);
  border-left: 1px solid var(--border-light);
  box-shadow: -12px 0 36px rgba(15, 23, 42, 0.2);
  transform: translateX(100%);
  transition: transform 0.26s cubic-bezier(0.16, 1, 0.3, 1), width 0.26s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}

.ai-drawer.open {
  transform: translateX(0);
}

.ai-drawer.split-view {
  width: min(1160px, 96vw);
}

/* Canvas 문서 서식 (라이트 & 다크 자동 대응 + PDF 인쇄용 라이트 강제 클래스) */
.doc-prose {
  color: var(--text-primary);
  font-size: 0.88rem;
  line-height: 1.72;
}

.doc-prose h1 {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0.2rem 0 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--doc-border);
}

.doc-prose h2 {
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--doc-h2);
  margin: 1.35rem 0 0.5rem;
}

.doc-prose h3 {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 1rem 0 0.35rem;
}

.doc-prose p {
  margin: 0.45rem 0;
}

.doc-prose ul,
.doc-prose ol {
  margin: 0.45rem 0 0.75rem 1.25rem;
}

.doc-prose ul {
  list-style-type: disc;
}

.doc-prose ol {
  list-style-type: decimal;
}

.doc-prose li {
  margin: 0.25rem 0;
}

.doc-prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.85rem 0;
  font-size: 0.8rem;
}

.doc-prose th,
.doc-prose td {
  border: 1px solid var(--border-muted);
  padding: 0.45rem 0.65rem;
  text-align: left;
}

.doc-prose th {
  background: var(--doc-th-bg);
  color: var(--doc-th-text);
  font-weight: 700;
}

.doc-prose blockquote {
  border-left: 3px solid var(--doc-border);
  background: var(--doc-quote-bg);
  padding: 0.5rem 0.85rem;
  margin: 0.75rem 0;
  color: var(--text-secondary);
}

/* 로그인 오버레이 배경 (로고의 사이버 그리드 · 일렉트릭 바이올렛 · 시안 · 골드 글로우) */
.auth-overlay-bg {
  background:
    radial-gradient(circle at 18% 20%, rgba(124, 58, 237, 0.16), transparent 46%),
    radial-gradient(circle at 82% 80%, rgba(8, 145, 178, 0.15), transparent 46%),
    radial-gradient(circle at 82% 18%, rgba(234, 179, 8, 0.1), transparent 36%),
    linear-gradient(rgba(124, 58, 237, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124, 58, 237, 0.045) 1px, transparent 1px),
    rgba(247, 245, 253, 0.96);
  background-size: auto, auto, auto, 28px 28px, 28px 28px, auto;
  backdrop-filter: blur(8px);
}

html.dark .auth-overlay-bg {
  background:
    radial-gradient(circle at 18% 20%, rgba(147, 51, 234, 0.28), transparent 46%),
    radial-gradient(circle at 82% 80%, rgba(34, 211, 238, 0.18), transparent 46%),
    radial-gradient(circle at 80% 18%, rgba(250, 204, 21, 0.1), transparent 34%),
    linear-gradient(rgba(168, 85, 247, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(168, 85, 247, 0.08) 1px, transparent 1px),
    rgba(10, 7, 20, 0.97);
  background-size: auto, auto, auto, 28px 28px, 28px 28px, auto;
}

.anon-toggle-pill.locked {
  cursor: not-allowed !important;
  opacity: 0.92;
  border-color: rgba(8, 145, 178, 0.45) !important;
  background-color: rgba(34, 211, 238, 0.09) !important;
}

/* PDF 내보내기 시 다크 모드여도 깨끗한 백지 문서로 렌더링 */
.pdf-print-light {
  background: #ffffff !important;
  color: #17122b !important;
  border-color: #e5e0f4 !important;
  --text-primary: #17122b;
  --text-secondary: #4a4268;
  --border-muted: #d1c7eb;
  --doc-border: #7c3aed;
  --doc-h2: #5b21b6;
  --doc-th-bg: #f5f3ff;
  --doc-th-text: #4c1d95;
  --doc-quote-bg: #f3f0ff;
}

/* 상태 도트 */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 9999px;
  display: inline-block;
}

.status-dot.online {
  background: #06b6d4;
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.24);
}

.status-dot.local {
  background: #eab308;
  box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.24);
}

/* ==========================================================================
   Dark Mode Comprehensive Utility Harmonization (Cyber Obsidian-Violet)
   ========================================================================== */
html.dark body {
  background-color: #0a0714 !important;
  color: #f4f1ff !important;
}

html.dark #sidebar,
html.dark header,
html.dark .modal-surface,
html.dark #ai-doc-paper {
  background-color: #130f24 !important;
  border-color: #282047 !important;
}

html.dark header {
  background-color: rgba(19, 15, 36, 0.94) !important;
}

html.dark .bg-white,
html.dark .bg-white\/95,
html.dark .bg-white\/80 {
  background-color: #130f24 !important;
}

html.dark .bg-slate-50,
html.dark .bg-slate-50\/70,
html.dark .bg-slate-100,
html.dark .bg-slate-100\/70 {
  background-color: #19142e !important;
}

html.dark .hover\:bg-slate-50:hover,
html.dark .hover\:bg-slate-100:hover,
html.dark .hover\:bg-slate-200:hover {
  background-color: #241d42 !important;
}

html.dark .border-slate-100,
html.dark .border-slate-200,
html.dark .border-slate-200\/80 {
  border-color: #282047 !important;
}

html.dark .text-slate-900,
html.dark .text-slate-800 {
  color: #f4f1ff !important;
}

html.dark .text-slate-700 {
  color: #d0c8ea !important;
}

html.dark .text-slate-600,
html.dark .text-slate-500 {
  color: #9e94c8 !important;
}

html.dark .text-slate-400 {
  color: #7469a0 !important;
}

html.dark .bg-brand-50,
html.dark .bg-brand-50\/80,
html.dark .bg-brand-50\/30,
html.dark .bg-brand-100 {
  background-color: rgba(168, 85, 247, 0.17) !important;
}

html.dark .hover\:bg-brand-100:hover,
html.dark .hover\:bg-brand-50\/70:hover,
html.dark .hover\:bg-brand-50:hover {
  background-color: rgba(168, 85, 247, 0.27) !important;
}

html.dark .border-brand-200,
html.dark .border-brand-300 {
  border-color: rgba(168, 85, 247, 0.38) !important;
}

html.dark .text-brand-800,
html.dark .text-brand-700,
html.dark .text-brand-600 {
  color: #c084fc !important;
}

html.dark .bg-teal-50,
html.dark .bg-teal-100,
html.dark .bg-emerald-50,
html.dark .bg-emerald-100 {
  background-color: rgba(34, 211, 238, 0.15) !important;
}

html.dark .border-teal-200,
html.dark .border-emerald-200 {
  border-color: rgba(34, 211, 238, 0.35) !important;
}

html.dark .text-teal-800,
html.dark .text-teal-700,
html.dark .text-emerald-800,
html.dark .text-emerald-700 {
  color: #22d3ee !important;
}

html.dark .bg-sky-50,
html.dark .bg-sky-100 {
  background-color: rgba(56, 189, 248, 0.16) !important;
}

html.dark .border-sky-200 {
  border-color: rgba(56, 189, 248, 0.36) !important;
}

html.dark .text-sky-800,
html.dark .text-sky-700 {
  color: #38bdf8 !important;
}

html.dark .bg-amber-50,
html.dark .bg-amber-100 {
  background-color: rgba(250, 204, 21, 0.15) !important;
}

html.dark .border-amber-200 {
  border-color: rgba(250, 204, 21, 0.36) !important;
}

html.dark .text-amber-800,
html.dark .text-amber-700 {
  color: #facc15 !important;
}

html.dark .bg-rose-50,
html.dark .bg-rose-100 {
  background-color: rgba(244, 63, 94, 0.16) !important;
}

html.dark .border-rose-200 {
  border-color: rgba(244, 63, 94, 0.36) !important;
}

html.dark .text-rose-800,
html.dark .text-rose-700,
html.dark .text-rose-600 {
  color: #fb7185 !important;
}

html.dark .text-blue-600 {
  color: #60a5fa !important;
}

html.dark .text-red-600 {
  color: #f87171 !important;
}

/* 시장 벤치마크 ON/OFF 토글 스위치 */
.mk-toggle {
  display: inline-flex;
  align-items: center;
}

.mk-toggle-track {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 19px;
  border-radius: 9999px;
  background: var(--border-muted);
  transition: background-color 0.18s ease;
}

.mk-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 9999px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.25);
  transition: transform 0.18s ease;
}

.mk-toggle input:checked + .mk-toggle-track {
  background: var(--brand-secondary);
}

.mk-toggle input:checked + .mk-toggle-track .mk-toggle-thumb {
  transform: translateX(15px);
}

/* 헤더 익명 모드 활성 상태 강조 */
.anon-toggle-pill.active {
  background: var(--brand-secondary-soft) !important;
  border-color: var(--brand-secondary) !important;
  color: var(--brand-secondary) !important;
}

.anon-toggle-pill.active .anon-icon {
  color: var(--brand-secondary) !important;
}

/* Export 형식 선택 라디오 카드 */
.export-format-card input:checked + .export-format-box {
  border-color: var(--brand-primary) !important;
  background: var(--brand-primary-soft) !important;
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.18);
}

/* PDF 내보내기 인쇄 친화적 페이지 분할 방지 */
.pdf-avoid-break {
  break-inside: avoid;
  page-break-inside: avoid;
}

/* 애니메이션 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.view-fade {
  animation: fadeIn 0.18s ease-out;
}

/* 스크롤바 (라이트 & 다크 대응) */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-track {
  background: var(--bg-subtle);
}

::-webkit-scrollbar-thumb {
  background: var(--border-muted);
  border-radius: 9999px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
