/* ==========================================================================
   JANG MART BI 2.0 - Core Design System & Stylesheet
   Vanilla CSS with Glassmorphism, Dual Theme, Responsive Grid
   ========================================================================== */

:root {
  /* 다크 테마 기본 팔레트 */
  --bg-primary: #0a0e17;
  --bg-surface: #111827;
  --bg-card: rgba(22, 30, 49, 0.72);
  --bg-card-hover: rgba(30, 41, 67, 0.88);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(99, 102, 241, 0.35);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --color-primary: #6366f1;
  --color-primary-light: #818cf8;
  --color-accent: #38bdf8;
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-gold: #fbbf24;
  --color-purple: #c084fc;
  
  --card-radius: 16px;
  --transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.35), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

/* 라이트 테마 변수 */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.88);
  --bg-card-hover: #ffffff;
  --border-color: rgba(0, 0, 0, 0.08);
  --border-highlight: rgba(99, 102, 241, 0.25);
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.06), 0 4px 6px -2px rgba(15, 23, 42, 0.04);
}

/* 리셋 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(56, 189, 248, 0.1) 0px, transparent 50%);
  background-attachment: fixed;
}

.dashboard-wrapper {
  max-width: 1440px;
  margin: 0 auto;
  padding: 32px 24px 60px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ==================== 헤더 영역 ==================== */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-badge {
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
  padding: 8px 14px;
  border-radius: 10px;
  letter-spacing: 0.05em;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
}

.title-group h1 {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 2px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.data-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: 9999px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: var(--color-success);
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.theme-toggle-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: var(--transition);
}

.theme-toggle-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--color-primary);
}

/* ==================== 3단 탭 네비게이션 ==================== */
.tab-navigation {
  display: flex;
  gap: 10px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  padding: 6px;
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition);
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(56, 189, 248, 0.15));
  border: 1px solid var(--border-highlight);
  color: var(--text-primary);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.tab-content {
  display: none;
  flex-direction: column;
  gap: 24px;
  animation: fadeIn 0.3s ease;
}

.tab-content.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================== 필터 바 ==================== */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
}

.filter-label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.filter-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.filter-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.filter-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

/* ==================== 5대 KPI 카드 그리드 ==================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.kpi-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.6), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.kpi-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-highlight);
  background: var(--bg-card-hover);
}

.kpi-card:hover::before {
  opacity: 1;
}

.highlight-card {
  border-color: rgba(251, 191, 36, 0.3);
  background: linear-gradient(145deg, rgba(251, 191, 36, 0.08), var(--bg-card));
}

.kpi-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.kpi-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.kpi-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
}

.kpi-badge.positive { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.kpi-badge.highlight { background: rgba(56, 189, 248, 0.15); color: #38bdf8; }
.kpi-badge.neutral { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }
.kpi-badge.primary { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
.kpi-badge.gold { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }

.kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.kpi-value {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-family: 'Plus Jakarta Sans', 'Pretendard', sans-serif;
  color: var(--text-primary);
}

.kpi-value small {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: 3px;
}

.kpi-divider {
  color: var(--text-muted);
  font-size: 1.2rem;
}

.kpi-subval {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-gold);
}

.kpi-subtext {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
}

.kpi-subtext strong {
  color: var(--text-primary);
}

.meta-tag {
  color: var(--text-muted);
}

/* ==================== 요약 배너 ==================== */
.summary-banner {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.15), rgba(6, 182, 212, 0.15));
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px 24px;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  gap: 16px;
}

.banner-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.92rem;
}

.banner-title {
  color: var(--text-secondary);
}

.banner-num {
  font-weight: 700;
  color: var(--text-primary);
}

/* ==================== 차트 그리드 & 카드 ==================== */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.chart-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.chart-card.col-span-2 {
  grid-column: span 2;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
}

.chart-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
}

.chart-header p {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.chart-legend-custom {
  display: flex;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

.sales-dot { background-color: #6366f1; }
.orders-dot { background-color: #38bdf8; }

.canvas-container {
  position: relative;
  width: 100%;
  height: 280px;
}

.donut-box {
  height: 260px;
}

/* ==================== TAB 2: RFM 등급 카드 ==================== */
.rfm-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}

.rfm-grade-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

.rfm-grade-card:hover {
  transform: translateY(-4px);
  background: var(--bg-card-hover);
}

.rfm-grade-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}

.rfm-grade-card.grade-a::before { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
.rfm-grade-card.grade-b::before { background: linear-gradient(90deg, #818cf8, #6366f1); }
.rfm-grade-card.grade-c::before { background: linear-gradient(90deg, #38bdf8, #0ea5e9); }
.rfm-grade-card.grade-d::before { background: linear-gradient(90deg, #94a3b8, #64748b); }

.grade-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.grade-tag {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.grade-badge {
  font-size: 0.78rem;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 9999px;
}

.grade-a .grade-badge { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }
.grade-b .grade-badge { background: rgba(99, 102, 241, 0.2); color: #818cf8; }
.grade-c .grade-badge { background: rgba(56, 189, 248, 0.2); color: #38bdf8; }
.grade-d .grade-badge { background: rgba(148, 163, 184, 0.2); color: #94a3b8; }

.grade-count {
  font-size: 1.9rem;
  font-weight: 800;
  font-family: 'Plus Jakarta Sans', sans-serif;
}

.grade-count small {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.grade-count .pct {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 6px;
}

.grade-metrics {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.84rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-color);
  padding-top: 12px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
}

.metric-row strong {
  color: var(--text-primary);
}

.grade-action {
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text-secondary);
  border-left: 3px solid var(--color-primary);
}

/* ==================== TAB 3: 테이블 섹션 ==================== */
.table-section {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-title-row h3 {
  font-size: 1.15rem;
  font-weight: 800;
}

.section-title-row p {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.badge-accent {
  background: rgba(99, 102, 241, 0.15);
  color: var(--color-primary-light);
  border: 1px solid var(--border-highlight);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 9999px;
}

.table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th, .data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  text-align: left;
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: rgba(255, 255, 255, 0.02);
}

.data-table tbody tr {
  transition: var(--transition);
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.04);
}

.text-right { text-align: right; }
.text-center { text-align: center; }

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 24px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

.rank-1 { background: rgba(251, 191, 36, 0.25); color: #fbbf24; border: 1px solid rgba(251, 191, 36, 0.4); }
.rank-2 { background: rgba(148, 163, 184, 0.25); color: #cbd5e1; }
.rank-3 { background: rgba(217, 119, 6, 0.25); color: #f59e0b; }

.cat-pill {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
}

.status-pill {
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
}

.status-pill.best { background: rgba(239, 68, 68, 0.2); color: #f87171; }
.status-pill.hot { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.status-pill.steady { background: rgba(16, 185, 129, 0.2); color: #34d399; }

.highlight-text {
  font-weight: 800;
  color: var(--text-primary);
  font-family: 'Plus Jakarta Sans', sans-serif;
}

/* ==================== 푸터 ==================== */
.dashboard-footer {
  text-align: center;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* ==================== 반응형 미디어 쿼리 ==================== */
@media (max-width: 1024px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .chart-card.col-span-2 {
    grid-column: span 1;
  }
}

@media (max-width: 768px) {
  .dashboard-wrapper {
    padding: 20px 14px 40px;
  }
  .tab-navigation {
    flex-direction: column;
  }
  .title-group h1 {
    font-size: 1.35rem;
  }
  .summary-banner {
    flex-direction: column;
    align-items: flex-start;
  }
}
