:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #fbfcfe;
  --border: #e7e9f0;
  --text: #1a1d29;
  --muted: #7a8194;
  --brand: #4f46e5;
  --brand-soft: #eef0fe;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.04);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1017;
    --panel: #171a23;
    --panel-2: #1c2029;
    --border: #262a36;
    --text: #e7e9f0;
    --muted: #8b93a7;
    --brand: #7c78ff;
    --brand-soft: #23233a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", "Noto Sans KR", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; margin: 4px 0 0; }

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

/* Sidebar */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 6px 22px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 14px; }
.brand-text span { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px;
  color: var(--muted); font-weight: 500; font-size: 13.5px;
  transition: background .12s, color .12s;
}
.nav-item .ico { opacity: .6; font-size: 12px; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); }
.nav-item.active .ico { opacity: 1; }
.sidebar-foot {
  margin-top: auto; display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted); padding: 8px 6px 0;
}
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); flex: none; }
.sync-dot.ok { background: var(--green); }
.sync-dot.err { background: var(--red); }

/* Main */
.main { padding: 24px 28px 40px; max-width: 1900px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; }
.topbar-left { display: flex; align-items: center; gap: 14px; }
.menu-btn { background: var(--panel); border: 1px solid var(--border); color: var(--text); width: 38px; height: 38px; border-radius: 9px; font-size: 17px; cursor: pointer; display: grid; place-items: center; flex: none; }
.menu-btn:hover { background: var(--panel-2); }
.topbar-actions { display: flex; gap: 10px; }

/* 사이드바 접기 */
.app.collapsed { grid-template-columns: 1fr; }
.app.collapsed .sidebar { display: none; }
.select {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 8px 12px; font: inherit; font-size: 13px; outline: none;
}
.select:focus { border-color: var(--brand); }
.btn {
  background: var(--brand); color: #fff; border: none; border-radius: 9px;
  padding: 8px 16px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: filter .12s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { filter: brightness(.95); }

/* Cards */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; margin-bottom: 18px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }

/* 대시보드 비교 섹션 */
.sec-title { font-size: 14px; font-weight: 700; margin: 4px 0 12px; letter-spacing: -0.01em; }
.sec-title .muted { font-weight: 400; font-size: 12.5px; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
/* 내용이 길어 좁아지면 카드가 줄바꿈되며 최소폭 유지(잘림 방지) */
.kpi-grid.cmp3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.kpi-grid.cmp2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.kpi-value { overflow-wrap: anywhere; }
.kpi { padding: 18px 20px; margin: 0; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 5px; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 8px; letter-spacing: -0.02em; }
.kpi-delta { font-size: 12.5px; margin-top: 6px; color: var(--muted); font-weight: 500; }
.kpi-delta.up { color: var(--green); }
.kpi-delta.down { color: var(--red); }
.kpi-vat { display: inline-block; margin-top: 7px; font-size: 10.5px; font-weight: 700; color: var(--brand); background: var(--brand-soft); padding: 1px 8px; border-radius: 999px; letter-spacing: .02em; }
.kpi-vat:empty { display: none; }
.hint { color: var(--muted); cursor: help; font-size: 11px; }

/* Charts */
.chart-card .chart-wrap { position: relative; height: 300px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.two-col .chart-wrap { height: 260px; }

/* Table */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: var(--panel-2); }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; background: var(--panel-2); }
.table tr.grp td { background: var(--brand-soft); font-weight: 700; color: var(--text); border-bottom: 1px solid var(--border); }
.table tr.sumrow td { background: var(--panel-2); font-weight: 700; border-bottom: 2px solid var(--border); }
.table tr.grp-toggle { cursor: pointer; }
.table tr.grp-toggle:hover td { filter: brightness(0.98); }
.table .caret { display: inline-block; width: 15px; color: var(--brand); font-size: 9px; vertical-align: middle; }
.table td.neg { color: var(--red); }
.table td.pos { color: var(--green); }
/* 채널별 판매량 표: 여백 축소 + 머리글 줄바꿈 + 상품명 말줄임 → 가로 잘림 완화 */
#prodTable th, #prodTable td { padding: 7px 8px; font-size: 13px; }
#prodTable th { white-space: normal; line-height: 1.25; }
/* 표 셀에는 max-width가 안 먹으므로 내부 span으로 말줄임 */
#prodTable td.pname span { display: inline-block; max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
/* 매장 칩 (다중 선택) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.chips:empty { display: none; }
.chip-item { display: inline-flex; align-items: center; gap: 4px; background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 3px 6px 3px 12px; font-size: 12.5px; font-weight: 600; }
.chip-item button { border: none; background: transparent; color: var(--brand); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 3px; }
.chip-item button:hover { color: var(--red); }
.badge { padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.ok { background: rgba(22,163,74,.12); color: var(--green); }
.badge.low { background: rgba(217,119,6,.14); color: var(--amber); }
.badge.out { background: rgba(220,38,38,.12); color: var(--red); }

.head-controls { display: flex; gap: 8px; }

/* 버튼 변형 */
.btn.ghost { background: var(--panel); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--panel-2); filter: none; }

/* 카테고리 탭 */
.tabs {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px;
  border-bottom: 1px solid var(--border); padding-bottom: 0;
}
.tab {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  background: transparent; border: none; border-bottom: 2px solid transparent;
  padding: 8px 14px 10px; cursor: pointer; color: var(--muted);
  font: inherit; font-size: 14px; font-weight: 600; border-radius: 8px 8px 0 0;
  transition: color .12s, background .12s, border-color .12s;
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-sub { font-size: 11px; font-weight: 500; color: var(--muted); opacity: .85; }
.tab.active .tab-sub { color: var(--brand); }

/* 월 탭 (pill) */
.month-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 18px; }
.mtab {
  padding: 5px 13px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--panel); color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.mtab:hover { background: var(--panel-2); color: var(--text); }
.mtab.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* 세그먼트 토글 (매출/이익) */
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; gap: 2px; }
.seg-btn {
  border: none; background: transparent; color: var(--muted);
  font: inherit; font-size: 12.5px; font-weight: 600; padding: 5px 14px;
  border-radius: 7px; cursor: pointer; transition: background .12s, color .12s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--brand); color: #fff; }

/* 창고별 요약 */
.wh-summary { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 16px; }
.wh-card {
  border: 1px solid var(--border); border-radius: 11px; padding: 12px 14px;
  background: var(--panel-2); cursor: pointer; transition: border-color .12s, transform .06s;
}
.wh-card:hover { border-color: var(--brand); }
.wh-card.active { border-color: var(--brand); background: var(--brand-soft); }
.wh-card .wh-name { font-size: 12.5px; color: var(--muted); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.wh-card .wh-tag { font-size: 10px; padding: 1px 6px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.wh-card .wh-tag.prod { background: rgba(217,119,6,.14); color: var(--amber); }
.wh-card .wh-val { font-size: 17px; font-weight: 700; margin-top: 7px; letter-spacing: -0.01em; }
.wh-card .wh-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

.foot { margin-top: 8px; font-size: 12.5px; }

/* 가로 스크롤 부드럽게 (모바일 표) */
.table-wrap { -webkit-overflow-scrolling: touch; }

/* ===== 태블릿/모바일 ===== */
@media (max-width: 1000px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; align-items: center;
    flex-wrap: wrap; gap: 10px; padding: 12px 16px;
  }
  .brand { padding: 0; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 4px; flex-basis: 100%; order: 3; }
  .nav-item { padding: 8px 11px; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; }
  .kpi-grid, .kpi-grid.cmp3, .kpi-grid.cmp2 { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .wh-summary { grid-template-columns: repeat(2, 1fr); }
  .main { padding: 16px; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  h1 { font-size: 18px; }
  .chart-wrap { height: 260px; }
  .two-col .chart-wrap { height: 240px; }
}

/* ===== 폰 ===== */
@media (max-width: 560px) {
  .sidebar { gap: 8px; padding: 10px 12px; }
  .brand-mark { width: 30px; height: 30px; font-size: 15px; }
  .brand-text { display: none; }               /* 로고만 */
  .nav-item .ico { display: none; }
  .nav-item { font-size: 13px; padding: 7px 10px; }
  .main { padding: 12px; }
  .kpi-grid, .kpi-grid.cmp3, .kpi-grid.cmp2, .wh-summary { grid-template-columns: 1fr; }
  .card { padding: 14px 15px; margin-bottom: 14px; }
  .kpi { padding: 15px; }
  .kpi-value { font-size: 22px; }
  .chart-wrap { height: 220px; }
  .card-head { flex-wrap: wrap; }
  .head-controls { flex-wrap: wrap; }
  .tab { padding: 7px 10px; font-size: 13px; }
  .seg-btn { padding: 5px 11px; }
  h1 { font-size: 17px; }
  .foot { font-size: 11.5px; }
}
