/* KeyPulse — 인디고/그래프 테마 디자인 시스템 */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ─── CSS 변수 ─────────────────────────────────── */
:root {
  --bg-base:      #0a0f1e;
  --bg-surface:   #111827;
  --bg-card:      #1a2236;
  --bg-hover:     #1e2d45;
  --bg-input:     #0f172a;

  --indigo-400:   #818cf8;
  --indigo-500:   #6366f1;
  --indigo-600:   #4f46e5;
  --indigo-700:   #4338ca;

  --emerald-400:  #34d399;
  --amber-400:    #fbbf24;
  --slate-400:    #94a3b8;
  --slate-300:    #cbd5e1;
  --slate-200:    #e2e8f0;

  --golden:       #f59e0b;
  --golden-bg:    rgba(245,158,11,0.12);

  --border:       rgba(99,102,241,0.15);
  --border-hover: rgba(99,102,241,0.35);

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #475569;

  --shadow-card: 0 4px 24px rgba(0,0,0,0.4), 0 0 0 1px rgba(99,102,241,0.1);
  --shadow-glow: 0 0 30px rgba(99,102,241,0.25);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
}

/* ─── 리셋 & 기본 ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  font-size: 14px;
}

/* ─── 레이아웃 ────────────────────────────────── */
.container { max-width: 1400px; margin: 0 auto; padding: 0 1.5rem; }

/* ─── 헤더 ────────────────────────────────────── */
.header {
  background: rgba(10,15,30,0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0 1.5rem;
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 60px;
  max-width: 1400px;
  margin: 0 auto;
}
.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--indigo-400);
  text-decoration: none;
  letter-spacing: -0.5px;
}
.logo-icon { font-size: 1.4rem; }
.logo-beta {
  font-size: 0.65rem;
  background: var(--indigo-600);
  color: white;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.nav-links {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
}
.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
}
.nav-link:hover, .nav-link.active {
  color: var(--text-primary);
  background: var(--bg-card);
}

/* ─── 카드 ────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
  transition: border-color var(--transition);
}
.card:hover { border-color: var(--border-hover); }
.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 1rem;
}

/* ─── 버튼 ────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--indigo-500), var(--indigo-600));
  color: white;
  box-shadow: 0 2px 12px rgba(99,102,241,0.35);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--indigo-400), var(--indigo-500));
  box-shadow: 0 4px 20px rgba(99,102,241,0.5);
  transform: translateY(-1px);
}
.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
  color: var(--text-primary);
  border-color: var(--border-hover);
  background: var(--bg-hover);
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 0.4rem 0.75rem;
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-card); }
.cat-btn-active {
  background: rgba(99,102,241,0.18) !important;
  border-color: var(--indigo-400) !important;
  color: var(--indigo-400) !important;
  font-weight: 600;
}
.lang-toggle {
  background: rgba(99,102,241,0.12);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.lang-toggle:hover { background: rgba(99,102,241,0.22); color: var(--text-primary); }
.btn-danger {
  background: rgba(239,68,68,0.15);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.3);
}
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.btn-icon { padding: 0.5rem; min-width: 36px; justify-content: center; }

/* ─── 입력 ────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 0.5rem; }
.form-label { font-size: 0.875rem; font-weight: 500; color: var(--text-secondary); }

textarea, input[type="text"], input[type="password"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  padding: 0.625rem 0.875rem;
  width: 100%;
  outline: none;
}
textarea:focus, input:focus {
  border-color: var(--indigo-500);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
textarea {
  resize: vertical;
  min-height: 100px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  line-height: 1.8;
}

/* ─── Freshness 태그 ──────────────────────────── */
.freshness {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 500;
  white-space: nowrap;
}
.freshness-live   { background: rgba(52,211,153,0.15); color: var(--emerald-400); }
.freshness-cache  { background: rgba(251,191,36,0.15);  color: var(--amber-400); }
.freshness-stale  { background: rgba(148,163,184,0.1);  color: var(--slate-400); }

/* ─── 황금 키워드 배지 ────────────────────────── */
.golden-badge {
  background: var(--golden-bg);
  color: var(--golden);
  border: 1px solid rgba(245,158,11,0.3);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}
.golden-row { background: rgba(245,158,11,0.05) !important; }

/* ─── 경쟁도 배지 ─────────────────────────────── */
.comp-high   { color: #f87171; }
.comp-medium { color: var(--amber-400); }
.comp-low    { color: var(--emerald-400); }

/* ─── 샘플 배지 ───────────────────────────────── */
.sample-badge {
  background: rgba(99,102,241,0.1);
  color: var(--indigo-400);
  border: 1px solid rgba(99,102,241,0.25);
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 500;
}

/* ─── 테이블 ──────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
table {
  width: 100%;
  border-collapse: collapse;
}
thead th {
  background: var(--bg-surface);
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border);
  transition: color var(--transition);
}
thead th:hover { color: var(--text-primary); }
thead th .sort-icon { margin-left: 4px; opacity: 0.5; }
thead th.sorted { color: var(--indigo-400); }
thead th.sorted .sort-icon { opacity: 1; }

tbody tr {
  border-bottom: 1px solid rgba(99,102,241,0.06);
  cursor: pointer;
  transition: background var(--transition);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
tbody tr.selected { background: rgba(99,102,241,0.1); border-left: 3px solid var(--indigo-500); }
tbody td {
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  word-break: keep-all;
}
/* 키워드 컬럼: 줄바꿈 금지 + 최소 너비 */
tbody td:first-child,
thead th:first-child {
  min-width: 130px;
  white-space: nowrap;
}
/* 숫자 컬럼: 줄바꿈 금지로 키워드 컬럼 공간 확보 */
.num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* ─── 게이지 바 ───────────────────────────────── */
.gauge-wrap { width: 100%; background: var(--bg-surface); border-radius: 999px; height: 8px; overflow: hidden; }
.gauge-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.6s cubic-bezier(0.4,0,0.2,1);
}
.gauge-normal  { background: linear-gradient(90deg, var(--indigo-600), var(--indigo-400)); }
.gauge-warning { background: linear-gradient(90deg, var(--amber-400), #f97316); }
.gauge-danger  { background: linear-gradient(90deg, #ef4444, #f97316); }

/* ─── 모달 ────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 2rem;
  max-width: 560px;
  width: 100%;
  box-shadow: var(--shadow-glow);
  animation: modal-in 0.2s ease;
  max-height: 90vh;
  overflow-y: auto;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0.25rem;
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text-primary); }

/* ─── 차트 컨테이너 ───────────────────────────── */
.chart-container { position: relative; width: 100%; }
.chart-container canvas { max-width: 100%; }

/* ─── 통계 카드 ───────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; }
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.stat-label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 500; }
.stat-value { font-size: 1.75rem; font-weight: 800; font-family: 'JetBrains Mono', monospace; color: var(--indigo-400); }
.stat-sub { font-size: 0.75rem; color: var(--text-muted); }

/* ─── 토스트 알림 ─────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.875rem 1.25rem;
  min-width: 260px;
  font-size: 0.875rem;
  animation: toast-in 0.25s ease;
  box-shadow: var(--shadow-card);
}
@keyframes toast-in { from { opacity:0; transform: translateX(16px); } to { opacity:1; transform: none; } }
.toast-success { border-left: 3px solid var(--emerald-400); }
.toast-error   { border-left: 3px solid #f87171; }
.toast-info    { border-left: 3px solid var(--indigo-400); }

/* ─── 가이드 투어 하이라이트 ──────────────────── */
.tour-highlight {
  outline: 2px solid var(--indigo-400) !important;
  outline-offset: 4px;
  border-radius: var(--radius-md);
  box-shadow: 0 0 0 6px rgba(99,102,241,0.15) !important;
  transition: outline 0.3s, box-shadow 0.3s;
}
.tour-tooltip {
  position: fixed;
  background: var(--indigo-600);
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 999;
  max-width: 280px;
  box-shadow: var(--shadow-glow);
  animation: modal-in 0.2s ease;
}
.tour-tooltip::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 1.5rem;
  width: 12px;
  height: 12px;
  background: var(--indigo-600);
  transform: rotate(45deg);
}

/* ─── 로딩 ────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(99,102,241,0.2);
  border-top-color: var(--indigo-400);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: skeleton-wave 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-wave { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ─── 반응형 ──────────────────────────────────── */
/* ─── 반응형 레이아웃 클래스 (인라인 그리드 → 클래스로) ─── */
.dash-main { display: grid; grid-template-columns: 380px 1fr; gap: 1.5rem; align-items: start; }
.dash-main > div { min-width: 0; }   /* 자식이 내용폭으로 팽창 방지 → 넓은 테이블이 컨테이너 내에서 좌우 스크롤 */
.dash-aside { position: sticky; top: 80px; }
.admin-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

/* 태블릿·모바일: 2단 → 1단 세로 적층 */
@media (max-width: 860px) {
  .dash-main { grid-template-columns: 1fr; }
  .dash-aside { position: static; top: auto; }
  .admin-2col { grid-template-columns: 1fr; }
}

/* 모바일 */
@media (max-width: 768px) {
  .header-inner { gap: 0.6rem; flex-wrap: wrap; height: auto; padding-top: 0.5rem; padding-bottom: 0.5rem; }
  .nav-links { margin-left: 0; }
  .nav-link span:last-child { display: none; }   /* 텍스트만 숨기고 이모지 유지 */
  #status-bar > div { flex-wrap: wrap; gap: 0.4rem 1rem; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .modal { padding: 1.25rem; }
  .container { padding: 0 1rem; }
  body { font-size: 13px; }
}

/* ─── 스크롤바 ────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--indigo-500); }

/* ─── 유틸리티 ───────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-4 { margin-bottom: 1rem; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-indigo { color: var(--indigo-400); }
.text-emerald { color: var(--emerald-400); }
.text-amber { color: var(--amber-400); }
.font-mono { font-family: 'JetBrains Mono', monospace; }
.font-bold { font-weight: 700; }
.hidden { display: none !important; }
.w-full { width: 100%; }
