/* ════════════════════════════════════════════════════════
 * page-monthly-summary-bem.css — Turn B
 * ────────────────────────────────────────────────────────
 * monthly_summary_analysis.html 的 BEM 命名層
 * 與 page-monthly-summary.css (token 化) 配對使用
 * 載入順序：tokens → page-monthly-summary.css → 本檔
 *
 * 命名前綴：ms- (monthly-summary)
 * ════════════════════════════════════════════════════════ */

/* ── 0. 頁面 scope ─────────────────────────────────────── */
.ms-page {
  --ms-card-bg:        rgba(250, 246, 238, 0.94);
  --ms-card-border:    var(--momo-border-light);
  --ms-card-radius:    var(--momo-radius-md, 8px);
  --ms-head-bg:        var(--momo-surface-2, rgba(250, 247, 240, 0.88));
  --ms-icon:           var(--momo-warm-caramel);
}

/* ── 1. Loading overlay（重命名替換原 .loading-overlay） ─ */
.ms-loading {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 14px;
  background: rgba(250, 246, 238, 0.78);
  backdrop-filter: blur(4px);
  color: var(--momo-text-secondary);
  font-family: var(--momo-font-mono);
  font-size: var(--momo-text-meta, 12px);
  letter-spacing: 0.04em;
}
.ms-loading[style*="flex"] { display: flex !important; }
.ms-loading__spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--momo-warm-caramel-soft);
  border-top-color: var(--momo-warm-caramel);
  border-radius: 50%;
  animation: ms-spin 0.9s linear infinite;
}
.ms-loading__text { text-transform: uppercase; }
@keyframes ms-spin { to { transform: rotate(360deg); } }

/* ── 2. Page head ─────────────────────────────────────── */
.ms-page-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--momo-space-3, 16px);
  align-items: center;
  padding: var(--momo-space-5, 22px);
  border: 1px solid var(--momo-border-strong);
  border-radius: var(--ms-card-radius);
  background: var(--momo-surface-raised);
  box-shadow: var(--momo-shadow-soft);
}
.ms-page-head__main { display: flex; flex-direction: column; gap: 6px; }
.ms-page-head__title {
  display: flex; align-items: center; gap: 10px; margin: 0;
  color: var(--momo-text-primary);
  font-family: var(--momo-font-display);
  font-size: clamp(1.45rem, 2vw, 2.08rem);
  font-weight: var(--momo-font-weight-black, 800);
}
.ms-page-head__icon { color: var(--ms-icon); }
.ms-page-head__sub {
  margin: 0;
  color: var(--momo-text-secondary);
  font-size: var(--momo-text-body, 14px);
}
.ms-page-head__sub code { background: transparent; color: inherit; }

/* ── 2.1 Decision strip ─────────────────────────────── */
.ms-action-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  margin: var(--momo-space-3, 16px) 0;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--momo-border-subtle);
  border-radius: var(--ms-card-radius);
  background: var(--momo-surface-raised);
  box-shadow: var(--momo-shadow-soft);
}
.ms-action-strip__label {
  color: var(--momo-text-secondary);
  font-size: 0.76rem;
  font-weight: 800;
}
.ms-action-strip strong {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  min-height: 2rem;
  padding: 0.34rem 0.58rem;
  border: 1px solid color-mix(in srgb, var(--momo-warm-caramel) 24%, var(--momo-border-subtle));
  border-radius: 999px;
  background: rgba(250, 246, 238, 0.78);
  color: var(--momo-text-primary);
  font-size: 0.82rem;
  font-weight: 800;
}
.ms-action-strip strong i { color: var(--momo-warm-caramel); }

/* ── 3. Tag / pill ────────────────────────────────────── */
.ms-tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--momo-font-mono);
  font-weight: var(--momo-font-weight-bold, 700);
}
.ms-tag--mono {
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--momo-warm-caramel-soft);
  color: var(--momo-warm-caramel);
  font-size: 0.92em;
}
.ms-tag--pill {
  padding: 6px 10px;
  border: 1px solid var(--momo-border);
  border-radius: 999px;
  background: rgba(250, 246, 238, 0.7);
  color: var(--momo-text-secondary);
  font-size: var(--momo-text-meta, 12px);
}

/* ── 4. Filter card ───────────────────────────────────── */
.ms-filter-card {
  position: sticky;
  top: 12px;
  z-index: 30;
}
.ms-filter-group__label {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--momo-font-display);
  font-size: var(--momo-text-label, 11px);
  font-weight: var(--momo-font-weight-semibold, 600);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 248, 239, 0.78) !important;
}
.ms-filter-group__btn {
  width: 100%;
}
/* 5 個 filter 群組各自的左側色條（語意暗示） */
.ms-filter-group { position: relative; }
.ms-filter-group::before {
  content: "";
  position: absolute;
  left: -2px; top: 26px; bottom: 6px;
  width: 2px;
  border-radius: 2px;
  opacity: 0.85;
}
.ms-filter-group--year::before   { background: var(--momo-warm-caramel); }
.ms-filter-group--month::before  { background: var(--momo-warm-honey); }
.ms-filter-group--area::before   { background: var(--momo-warm-olive); }
.ms-filter-group--vendor::before { background: var(--momo-warm-clay); }
.ms-filter-group--trade::before  { background: var(--momo-warm-apricot); }

.ms-filter-card__refresh {
  background: var(--momo-page-accent);
  color: var(--momo-page-inverse);
  border: 1px solid var(--momo-page-accent-dark);
  font-weight: var(--momo-font-weight-bold, 700);
  border-radius: var(--ms-card-radius);
  transition: filter 0.15s ease;
}
.ms-filter-card__refresh:hover {
  filter: brightness(0.94);
  color: var(--momo-page-inverse);
}

/* ── 5. Highlight grid (Top 3) ────────────────────────── */
.ms-highlight {
  border-radius: var(--ms-card-radius);
  overflow: hidden;
  border-top: 3px solid transparent;
}
.ms-highlight__head {
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--ms-card-border);
  display: flex; align-items: center;
}
.ms-highlight__title {
  margin: 0;
  font-size: var(--momo-text-body, 14px);
  font-weight: var(--momo-font-weight-bold, 700);
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--momo-text-primary);
}
/* 取代 bg-primary / bg-success / bg-warning 三色 → 暖系語意 */
.ms-highlight--accent { border-top-color: var(--momo-warm-caramel); }
.ms-highlight--accent .ms-highlight__head {
  background: var(--momo-surface-raised);
}
.ms-highlight--olive  { border-top-color: var(--momo-warm-olive); }
.ms-highlight--olive  .ms-highlight__head {
  background: var(--momo-surface-raised);
}
.ms-highlight--honey  { border-top-color: var(--momo-warm-honey); }
.ms-highlight--honey  .ms-highlight__head {
  background: var(--momo-surface-raised);
  color: var(--momo-text-primary);
}
.ms-highlight__table tbody tr:last-child td { border-bottom: 0; }

/* ── 6. Chart card 共用容器 ───────────────────────────── */
.ms-chart-card {
  border: 1px solid var(--ms-card-border) !important;
  border-radius: var(--ms-card-radius);
  background: var(--ms-card-bg);
  box-shadow: var(--momo-shadow-soft);
}
.ms-chart-card__head {
  background: var(--ms-head-bg) !important;
  border-bottom: 1px solid var(--ms-card-border);
  padding: 1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ms-chart-card__title {
  margin: 0;
  font-weight: var(--momo-font-weight-bold, 700);
  font-size: var(--momo-text-title, 17px);
  color: var(--momo-text-primary);
  display: inline-flex; align-items: center; gap: 8px;
}
.ms-chart-card__icon { color: var(--ms-icon); }
.ms-chart-card__canvas { width: 100%; }
.ms-chart-card__table {
  border-color: var(--ms-card-border) !important;
  font-family: var(--momo-font-mono);
  font-size: var(--momo-text-meta, 12px);
  table-layout: fixed;
  width: 100%;
}
.ms-chart-card__table th,
.ms-chart-card__table td {
  border-color: var(--ms-card-border) !important;
  min-width: 0;
  padding: 0.42rem 0.35rem !important;
  line-height: 1.28;
  overflow-wrap: anywhere;
  white-space: normal !important;
  word-break: break-word;
}
.ms-chart-card__scroll { max-height: 200px; overflow-y: auto; }

.ms-chart-card .table-responsive,
.ms-special .table-responsive {
  overflow: visible;
}

.ms-chart-card__table td:first-child,
.ms-chart-card__table th:first-child {
  width: 5.5rem;
}

/* ── 7. Special area card（4 個分類專屬） ─────────────── */
.ms-special {
  border-radius: var(--ms-card-radius);
  border: 1px solid var(--ms-card-border) !important;
  background: var(--ms-card-bg);
  box-shadow: var(--momo-shadow-soft);
  overflow: hidden;
}
.ms-special__head {
  background: var(--ms-head-bg) !important;
  border-bottom: 1px solid var(--ms-card-border);
  padding: 1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ms-special__title {
  margin: 0;
  font-weight: var(--momo-font-weight-bold, 700);
  font-size: var(--momo-text-title, 17px);
  display: inline-flex; align-items: center; gap: 8px;
}
/* 4 個變體：取代 border-info / border-success / border-warning / border-danger */
.ms-special--info     { border-left: 4px solid var(--momo-warm-caramel) !important; }
.ms-special--info     .ms-special__title { color: var(--momo-warm-caramel); }
.ms-special--olive    { border-left: 4px solid var(--momo-warm-olive, #6f7a4a) !important; }
.ms-special--olive    .ms-special__title { color: var(--momo-warm-olive, #6f7a4a); }
.ms-special--honey    { border-left: 4px solid var(--momo-warm-honey) !important; }
.ms-special--honey    .ms-special__title { color: var(--momo-warm-honey); }
.ms-special--mahogany { border-left: 4px solid var(--momo-warm-mahogany, #7a3b2c) !important; }
.ms-special--mahogany .ms-special__title { color: var(--momo-warm-mahogany, #7a3b2c); }

/* ── 8. Data table ────────────────────────────────────── */
.ms-data-table {
  border: 1px solid var(--ms-card-border) !important;
  border-radius: var(--ms-card-radius);
  background: var(--ms-card-bg);
  box-shadow: var(--momo-shadow-soft);
}
.ms-data-table__head {
  background: var(--momo-on-accent, #fff8ef) !important;
  border-bottom: 1px solid var(--ms-card-border);
  padding: 1rem 1.25rem;
  display: flex; justify-content: space-between; align-items: center;
}
.ms-data-table__title {
  margin: 0;
  font-weight: var(--momo-font-weight-bold, 700);
  font-size: var(--momo-text-title, 17px);
  display: inline-flex; align-items: center; gap: 8px;
}
.ms-data-table__import {
  border-color: var(--momo-warm-caramel);
  color: var(--momo-warm-caramel);
  font-family: var(--momo-font-mono);
}
.ms-data-table__import:hover {
  background: var(--momo-warm-caramel);
  color: var(--momo-on-accent, #fff8ef);
}
.ms-data-table__table thead th {
  background: var(--ms-head-bg) !important;
  color: var(--momo-text-secondary);
  font-family: var(--momo-font-display);
  font-size: var(--momo-text-label, 11px);
  font-weight: var(--momo-font-weight-black, 800);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--ms-card-border);
}

/* ── 9. 響應式 ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .ms-page {
    gap: var(--momo-space-3);
  }

  .ms-action-strip strong {
    width: 100%;
    justify-content: flex-start;
  }

  .ms-page-head {
    grid-template-columns: 1fr;
    padding: var(--momo-space-4);
  }

  .ms-page-head__title {
    align-items: flex-start;
    font-size: 1.5rem;
    line-height: 1.2;
  }

  .ms-page-head__sub,
  .ms-page-head__sub code {
    overflow-wrap: anywhere;
  }

  .ms-filter-card {
    position: static;
    padding: var(--momo-space-3);
  }

  .ms-filter-group::before {
    top: 30px;
    bottom: 4px;
  }

  .ms-filter-card__refresh {
    min-height: 42px;
  }

  .ms-chart-card,
  .ms-special,
  .ms-data-table {
    margin-bottom: var(--momo-space-3) !important;
  }

  .ms-chart-card__head,
  .ms-special__head,
  .ms-data-table__head {
    align-items: flex-start;
    flex-direction: column;
    gap: var(--momo-space-2);
    padding: var(--momo-space-3);
  }

  .ms-chart-card__title,
  .ms-special__title,
  .ms-data-table__title {
    align-items: flex-start;
    font-size: var(--momo-text-base);
    line-height: 1.35;
  }

  .ms-chart-card .card-body,
  .ms-special .card-body {
    overflow: hidden;
    padding: var(--momo-space-3);
  }

  .ms-chart-card__canvas {
    height: 300px !important;
    min-height: 260px;
  }

  #vendorRankingChart {
    height: 620px !important;
  }

  #divisionDistChart,
  #priceRangeChart {
    height: 280px !important;
  }

  #bcgMatrixChart,
  #priceVolumeScatterChart,
  #seasonalityHeatmapChart,
  #areaRankingChart,
  #specialChart,
  #bodyCareChart,
  #makeupFragranceChart,
  #privacyInfantChart {
    height: 320px !important;
  }

  .ms-chart-card .table-responsive,
  .ms-chart-card__scroll,
  #compareChartDataTable,
  #specialChartDataTable,
  #bodyCareChartDataTable,
  #makeupFragranceChartDataTable,
  #privacyInfantChartDataTable {
    display: none !important;
  }

  .ms-data-table__import {
    justify-content: center;
    width: 100%;
    min-height: 40px;
  }

  .ms-data-table .card-body {
    padding: var(--momo-space-2);
  }

  .ms-data-table .table-responsive {
    border: 1px solid var(--ms-card-border);
    border-radius: var(--momo-radius-md);
    overflow: visible;
    -webkit-overflow-scrolling: touch;
  }

  .ms-data-table__table {
    width: 100% !important;
    min-width: 0;
    font-size: var(--momo-text-xs);
  }

  .ms-data-table__table thead {
    display: none;
  }

  .ms-data-table__table,
  .ms-data-table__table tbody,
  .ms-data-table__table tr,
  .ms-data-table__table td {
    display: block;
    width: 100% !important;
  }

  .ms-data-table__table tr {
    padding: var(--momo-space-3);
    background: var(--momo-bg-surface);
    border-top: 1px solid var(--ms-card-border);
  }

  .ms-data-table__table tr:first-child {
    border-top: 0;
  }

  .ms-data-table__table td {
    display: grid;
    grid-template-columns: 6.6rem minmax(0, 1fr);
    gap: var(--momo-space-2);
    align-items: start;
    padding: 0.42rem 0 !important;
    border: 0 !important;
    text-align: left !important;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .ms-data-table__table td::before {
    color: var(--momo-text-tertiary);
    content: "";
    font-family: var(--momo-font-mono);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .ms-data-table__table td:nth-child(1)::before { content: "年/月"; }
  .ms-data-table__table td:nth-child(2)::before { content: "處別"; }
  .ms-data-table__table td:nth-child(3)::before { content: "區"; }
  .ms-data-table__table td:nth-child(4)::before { content: "PM"; }
  .ms-data-table__table td:nth-child(5)::before { content: "品牌"; }
  .ms-data-table__table td:nth-child(6)::before { content: "廠商"; }
  .ms-data-table__table td:nth-child(7)::before { content: "交易"; }
  .ms-data-table__table td:nth-child(8)::before { content: "銷售額"; }
  .ms-data-table__table td:nth-child(9)::before { content: "YoY"; }

  .dataTables_wrapper .row {
    gap: var(--momo-space-2);
    margin-right: 0;
    margin-left: 0;
  }

  .dataTables_wrapper .row > [class*="col-"] {
    padding-right: 0;
    padding-left: 0;
  }

  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    text-align: left !important;
  }

  .dataTables_wrapper .dataTables_filter label,
  .dataTables_wrapper .dataTables_filter input {
    width: 100%;
  }

  .ms-data-table .dataTables_paginate .pagination {
    flex-wrap: wrap;
    justify-content: flex-start !important;
    gap: 0.35rem;
    margin: var(--momo-space-2) 0 0;
  }

  .ms-data-table .dataTables_paginate .page-link {
    padding: 0.32rem 0.5rem;
    font-size: var(--momo-text-xs);
    line-height: 1.2;
  }
}
