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

:root {
  --bg-primary: #0b0f19;
  --bg-card: rgba(22, 30, 49, 0.75);
  --bg-card-hover: rgba(30, 41, 67, 0.85);
  --bg-control: rgba(17, 24, 39, 0.7);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.14);
  --border-glow: rgba(99, 102, 241, 0.4);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  /* Brand & Accent Colors */
  --accent-blue: #38bdf8;
  --accent-purple: #818cf8;
  --accent-indigo: #6366f1;
  --accent-emerald: #34d399;
  --accent-amber: #fbbf24;
  --accent-rose: #f43f5e;
  
  /* Segment Colors */
  --color-vip: #3b82f6;
  --color-loyal: #10b981;
  --color-potential: #f59e0b;
  --color-atrisk: #ef4444;

  --font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

body {
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(at 0% 0%, rgba(56, 189, 248, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(129, 140, 248, 0.15) 0px, transparent 50%),
    radial-gradient(at 50% 100%, rgba(52, 211, 153, 0.08) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  padding: 2.5rem 1.5rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.dashboard-container {
  max-width: 1360px;
  margin: 0 auto;
}

/* ========================================== */
/* Header                                     */
/* ========================================== */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 1.25rem;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  font-size: 2rem;
  filter: drop-shadow(0 2px 8px rgba(56, 189, 248, 0.3));
}

.title-group h1 {
  font-size: 1.95rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  background: linear-gradient(135deg, #ffffff 40%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.title-group h1 span {
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--accent-blue);
  -webkit-text-fill-color: var(--accent-blue);
  margin-left: 0.3rem;
}

.title-group p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.45rem;
}

.header-badges {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.9rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  backdrop-filter: blur(8px);
}

.badge.live {
  color: var(--accent-emerald);
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.3);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--accent-emerald);
  margin-right: 7px;
  box-shadow: 0 0 8px var(--accent-emerald);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.2); }
  100% { opacity: 1; transform: scale(1); }
}

/* ========================================== */
/* Control Panel (Tabs & Period Filter)      */
/* ========================================== */
.control-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 2rem;
  padding: 0.85rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 1.25rem;
  backdrop-filter: blur(14px);
  flex-wrap: wrap;
}

/* Tabs Navigation */
.tabs-nav {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 1.15rem;
  border-radius: 0.85rem;
  font-family: var(--font-family);
  font-size: 0.925rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

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

.tab-btn.active {
  color: #ffffff;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25) 0%, rgba(56, 189, 248, 0.2) 100%);
  border-color: rgba(99, 102, 241, 0.45);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.2);
}

.tab-icon {
  font-size: 1.1rem;
}

.tab-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent-blue);
  border: 1px solid rgba(56, 189, 248, 0.35);
}

/* Global Period Filter */
.filter-wrapper {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-left: auto;
  transition: opacity 0.25s ease;
}

.filter-header-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.filter-control-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-control) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E") no-repeat right 0.75rem center;
  background-size: 1rem;
  border: 1px solid var(--border-light);
  border-radius: 0.75rem;
  padding: 0.55rem 2.2rem 0.55rem 0.9rem;
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 170px;
}

.filter-select:hover:not(:disabled) {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.15);
}

.filter-select:focus {
  outline: none;
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

.filter-select optgroup {
  background-color: #0f172a;
  color: var(--text-muted);
  font-weight: 700;
}

.filter-select option {
  background-color: #0f172a;
  color: #fff;
  padding: 0.4rem;
}

.filter-current-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent-blue);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

/* RFM Disabled State Visuals */
.filter-wrapper.disabled {
  opacity: 0.65;
}

.filter-wrapper.disabled .filter-select {
  cursor: not-allowed;
  background-color: rgba(30, 41, 59, 0.4);
  color: var(--text-dim);
  border-color: rgba(255, 255, 255, 0.05);
}

.filter-wrapper.disabled .filter-current-tag {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-dim);
  border-color: transparent;
}

.rfm-snapshot-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
  border: 1px solid rgba(245, 158, 11, 0.35);
  font-size: 0.78rem;
  font-weight: 600;
  animation: fadeIn 0.2s ease-in-out;
}

/* ========================================== */
/* Tab Panes Toggle Structure                 */
/* ========================================== */
.tab-pane {
  display: none;
  animation: tabFadeIn 0.25s ease-out;
}

.tab-pane.active {
  display: block;
}

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

/* ========================================== */
/* KPI Cards Grid & Design System             */
/* ========================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.kpi-grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

.kpi-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 1.25rem;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(14px);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-glow);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.4);
  background: var(--bg-card-hover);
}

.kpi-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.kpi-title {
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.kpi-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
}

.icon-sales { background: rgba(56, 189, 248, 0.15); color: var(--accent-blue); }
.icon-orders { background: rgba(129, 140, 248, 0.15); color: var(--accent-purple); }
.icon-aov { background: rgba(52, 211, 153, 0.15); color: var(--accent-emerald); }
.icon-discount { background: rgba(251, 191, 36, 0.15); color: var(--accent-amber); }
.icon-category { background: rgba(244, 63, 94, 0.15); color: var(--accent-rose); }

.kpi-value {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: #ffffff;
  margin-bottom: 0.4rem;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.kpi-value.updating {
  opacity: 0.3;
  transform: translateY(-2px);
}

.kpi-subtext {
  font-size: 0.825rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.highlight {
  color: var(--accent-emerald);
  font-weight: 600;
}

.highlight-amber {
  color: var(--accent-amber);
  font-weight: 600;
}

.highlight-blue {
  color: var(--accent-blue);
  font-weight: 600;
}

/* ========================================== */
/* Charts Grid                                */
/* ========================================== */
.charts-grid {
  display: grid;
  grid-template-columns: 1.8fr 1.2fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 1.25rem;
  padding: 1.5rem;
  backdrop-filter: blur(14px);
  position: relative;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.chart-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.chart-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  display: block;
}

.chart-container {
  position: relative;
  width: 100%;
  height: 320px;
}

/* Detail Grid (2 Columns / 1 Column) */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.detail-grid.single-col {
  grid-template-columns: 1fr;
}

.detail-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 1.25rem;
  padding: 1.5rem;
  backdrop-filter: blur(14px);
}

.channel-summary-row {
  display: flex;
  gap: 1rem;
  margin-top: 1.25rem;
}

.channel-box {
  flex: 1;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  padding: 1rem 1.2rem;
}

.channel-box .channel-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.channel-box .channel-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  margin-top: 0.4rem;
}

/* Online Store Highlight Card (Module 4) */
.online-highlight-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.12) 0%, rgba(99, 102, 241, 0.12) 100%);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 1rem;
  margin-bottom: 1.25rem;
  backdrop-filter: blur(8px);
}

.online-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-blue);
  background: rgba(56, 189, 248, 0.2);
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  margin-bottom: 0.25rem;
}

.online-highlight-left h4 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
}

.online-highlight-left p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.online-highlight-right {
  text-align: right;
}

.online-amount {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent-blue);
}

.online-share-tag {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

/* ========================================== */
/* RFM Guide Table & Segment Badges           */
/* ========================================== */
.rfm-guide-section {
  margin-top: 1.5rem;
  margin-bottom: 2.5rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: 0.85rem;
  border: 1px solid var(--border-color);
  background: rgba(15, 23, 42, 0.5);
  margin-top: 1rem;
}

.rfm-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.rfm-table th {
  background: rgba(30, 41, 59, 0.7);
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.9rem 1.15rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  user-select: none;
}

.rfm-table th.sortable {
  cursor: pointer;
  transition: all 0.2s ease;
}

.rfm-table th.sortable:hover {
  color: var(--accent-blue);
  background: rgba(30, 41, 59, 0.95);
}

.rfm-table th .sort-icon {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-left: 0.35rem;
  display: inline-block;
  transition: transform 0.2s ease, color 0.2s ease;
}

.rfm-table th.sort-asc .sort-icon {
  color: var(--accent-blue);
}

.rfm-table th.sort-desc .sort-icon {
  color: var(--accent-amber);
}

.rfm-table td {
  padding: 1rem 1.15rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  vertical-align: middle;
}

.rfm-table tr:last-child td {
  border-bottom: none;
}

.rfm-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.sub-share {
  color: var(--text-dim);
  font-size: 0.78rem;
  margin-left: 0.25rem;
}

.segment-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.85rem;
}

.badge-vip { background: rgba(59, 130, 246, 0.2); color: var(--color-vip); border: 1px solid var(--color-vip); }
.badge-loyal { background: rgba(16, 185, 129, 0.2); color: var(--color-loyal); border: 1px solid var(--color-loyal); }
.badge-potential { background: rgba(245, 158, 11, 0.2); color: var(--color-potential); border: 1px solid var(--color-potential); }
.badge-atrisk { background: rgba(239, 68, 68, 0.2); color: var(--color-atrisk); border: 1px solid var(--color-atrisk); }

.action-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: help;
  position: relative;
  transition: all 0.2s ease;
}

.action-tag:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.action-vip { background: rgba(59, 130, 246, 0.12); color: #93c5fd; border: 1px solid rgba(59, 130, 246, 0.3); }
.action-vip:hover { background: rgba(59, 130, 246, 0.22); border-color: rgba(59, 130, 246, 0.5); }

.action-loyal { background: rgba(16, 185, 129, 0.12); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.3); }
.action-loyal:hover { background: rgba(16, 185, 129, 0.22); border-color: rgba(16, 185, 129, 0.5); }

.action-potential { background: rgba(245, 158, 11, 0.12); color: #fcd34d; border: 1px solid rgba(245, 158, 11, 0.3); }
.action-potential:hover { background: rgba(245, 158, 11, 0.22); border-color: rgba(245, 158, 11, 0.5); }

.action-atrisk { background: rgba(239, 68, 68, 0.12); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.3); }
.action-atrisk:hover { background: rgba(239, 68, 68, 0.22); border-color: rgba(239, 68, 68, 0.5); }

.seg-desc-sub {
  display: block;
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

/* ========================================== */
/* Footer                                     */
/* ========================================== */
footer {
  text-align: center;
  padding: 2rem 0;
  border-top: 1px solid var(--border-color);
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ========================================== */
/* Responsive Design (Mobile, Tablet, Desktop)*/
/* ========================================== */
@media (max-width: 1200px) {
  .kpi-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 992px) {
  .charts-grid, 
  .detail-grid {
    grid-template-columns: 1fr;
  }
  
  .kpi-grid-3 {
    grid-template-columns: 1fr;
  }

  .control-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-wrapper {
    margin-left: 0;
    justify-content: space-between;
    width: 100%;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
  }
}

@media (max-width: 768px) {
  body {
    padding: 1.5rem 1rem;
  }

  .tabs-nav {
    overflow-x: auto;
    padding-bottom: 0.25rem;
    width: 100%;
  }

  .tab-btn {
    white-space: nowrap;
    padding: 0.55rem 0.9rem;
    font-size: 0.85rem;
  }

  .filter-wrapper {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .filter-select {
    width: 100%;
  }

  .channel-summary-row {
    flex-direction: column;
  }

  .online-highlight-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .online-highlight-right {
    text-align: left;
  }
}

@media (max-width: 480px) {
  .title-group h1 {
    font-size: 1.4rem;
  }
  
  .title-group h1 span {
    display: block;
    font-size: 1.1rem;
    margin-left: 0;
    margin-top: 0.2rem;
  }

  .kpi-grid,
  .kpi-grid-4,
  .kpi-grid-3 {
    grid-template-columns: 1fr;
  }

  .kpi-value {
    font-size: 1.55rem;
  }
}
