:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --sidebar: #ffffff;
  --sidebar-border: #ececf0;
  --text: #1a1a1a;
  --text-muted: #8a8a93;
  --text-soft: #b6b6bf;
  --primary: #5C5CE0;
  --primary-soft: #ECECFB;
  --primary-strong: #4A4ACB;
  --border: #ececf0;
  --line: #f0f0f3;
  --series-payment: #6C6CEA;
  --series-ad: #5BB9E8;
  --series-contribution: #6FD6CF;
  --series-cost: #F5C786;
  --series-fee: #F39A88;
  --series-shipping: #EE7E92;
  --series-revenue: #DC5D6F;
  --series-variable: #B85AB1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  display: grid;
  grid-template-columns: 96px 1fr;
  min-height: 100vh;
  position: relative;
}

/* ========== Sidebar ========== */
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  padding: 18px 0 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}

.sidebar-nav {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.sidebar-bottom {
  margin-top: auto;
}

.nav-item {
  width: 72px;
  padding: 10px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border-radius: 12px;
  color: var(--text-muted);
  text-decoration: none;
  transition: background .15s, color .15s;
  position: relative;
}

.nav-item:hover {
  background: #f6f6fa;
  color: var(--text);
}

.nav-icon {
  width: 44px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f4f4f8;
  color: #6e6e78;
}

.nav-item.active .nav-icon {
  background: var(--primary);
  color: white;
}

.nav-item.active .nav-label {
  color: var(--primary);
  font-weight: 600;
}

.nav-label {
  font-size: 11px;
  letter-spacing: -0.2px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.badge-n {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #6E5CE0;
  color: white;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
}

/* ========== Main ========== */
.main {
  padding: 28px 36px 60px;
  min-width: 0;
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  letter-spacing: -0.4px;
}

.help {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--primary);
  font-weight: 500;
}

.help-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
}

.header-controls {
  display: flex;
  gap: 10px;
}

.brand-select,
.date-range {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}

.brand-select:hover,
.date-range:hover {
  border-color: #d4d4dc;
}

.brand-select-bars {
  width: 30px;
  height: 28px;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brand-select-name {
  min-width: 120px;
  font-weight: 500;
}

.brand-select-caret {
  color: var(--text-muted);
  display: inline-flex;
}

.date-range-icon {
  color: var(--primary);
  display: inline-flex;
}

.date-range-text {
  font-weight: 500;
}

/* ========== Card ========== */
.card {
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 24px 28px 28px;
  position: relative;
}

.tabs {
  display: flex;
  gap: 28px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}

.tab {
  background: none;
  border: none;
  padding: 8px 2px 14px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
  font-family: inherit;
  letter-spacing: -0.2px;
}

.tab.active {
  color: var(--primary);
  font-weight: 700;
}

.tab.active::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--primary);
  border-radius: 2px;
}

.metric-summary {
  margin-bottom: 8px;
}

.metric-period {
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
}

.metric-name {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 6px;
}

.metric-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.6px;
}

.chart-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 4px;
}

.chart-tool {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s;
}

.chart-tool:hover {
  background: #f3f3f7;
  color: var(--text);
}

.chart-wrap {
  position: relative;
  height: 360px;
  margin-bottom: 24px;
}

/* ========== Formula ========== */
.formula {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  background: #fcfcfd;
}

.formula-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.formula-cell {
  flex: 1 1 0;
  min-width: 0;
}

.formula-op {
  flex: 0 0 18px;
}

.formula-values {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.formula-cell {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.2px;
}

.formula-cell.highlight {
  color: var(--primary);
  font-weight: 700;
}

.formula-op {
  text-align: center;
  font-size: 16px;
  color: var(--text-soft);
  font-weight: 400;
}

.formula-labels .formula-cell .label {
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
}

.formula-labels .formula-cell.highlight .label {
  color: var(--primary);
  font-weight: 700;
}

.formula-labels .formula-cell .pct {
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
}

/* ========== Floating chat ========== */
.chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(92, 92, 224, 0.35);
  transition: transform .15s;
}

.chat-fab:hover {
  transform: translateY(-2px);
}

/* ========== Dropdown ========== */
.dropdown {
  position: relative;
}

.dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(20, 20, 30, 0.12);
  padding: 6px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dropdown-panel-wide { min-width: 200px; }

.dropdown-panel[hidden] { display: none; }

.dropdown-item {
  background: none;
  border: none;
  text-align: left;
  padding: 9px 12px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background .12s, color .12s;
}

.dropdown-item:hover {
  background: #f4f4fa;
}

.dropdown-item.is-selected {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

@media (max-width: 1100px) {
  .formula-row { flex-wrap: wrap; }
  .formula-op { display: none; }
  .formula-values { border-bottom: 1px dashed var(--line); }
}
