/* ===== CRM Dashboard Styles ===== */

/* ── Base Layout ── */
.dash-wrap {
  margin: 20px 0;
  padding: 0 24px 40px;
  font-family: 'Point', 'Aribau Grotesk', Arial, sans-serif;
}

/* ══════════════════════════════════════════
   /dashboard ON THE REPORTS DESIGN SYSTEM
   ──────────────────────────────────────────
   The CRM Sales Dashboard renders inside the shared `.rp` shell
   (reports.css: rp-band / rp-filter / rp-kpi / rp-card / rp-tbl / rp-delta).
   Everything below that is prefixed `.dash-rp` is the dashboard-only skin on
   top of that system. `.dash-section*`, `.dash-toggle` and `.dash-wrap` are
   ALSO used by gc-sales, promo-tracker, volume-estimations, on-product-overview
   and gc-declines, so their base rules further down stay as they are and the
   dashboard overrides them only under `.dash-rp`.
   ══════════════════════════════════════════ */

/* index.css sets `body { text-align: center }` and every SPA view inherits it;
   the report shell assumes a left default (titles, text columns). */
.dash-rp { text-align: left; }

.dash-rp .rp-content { transition: opacity 0.15s ease; }
.dash-rp.is-loading .rp-content { opacity: 0.55; pointer-events: none; }

/* ── Filter bar (an .rp-filter) ── */
.dash-rp .dash-filters { row-gap: 10px; }

.dash-rp .dash-date-range-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 250px;
  padding: 0 12px;
  background: var(--ace-surface-hover);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.dash-rp .dash-date-range-wrap:hover,
.dash-rp .dash-date-range-wrap:focus-within {
  background: #fff;
  border-color: var(--ace-blue);
  box-shadow: 0 0 0 3px rgba(90, 200, 242, 0.22);
}

.dash-rp .dash-date-icon {
  color: var(--ace-text-muted);
  flex-shrink: 0;
}

/* flatpickr's altInput inherits this class from the original input */
.dash-rp .dash-daterange-input {
  border: 0;
  background: transparent;
  outline: 0;
  min-width: 190px;
  padding: 7px 0;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--ace-navy);
  cursor: pointer;
}

.dash-rp .dash-date-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* ── Section cards (scoped overrides of the shared .dash-section) ── */
.dash-rp .dash-section {
  margin: 0 0 16px;
  border-radius: 14px;
  border: 1px solid rgba(2, 60, 91, 0.06);
  box-shadow: 0 4px 16px rgba(2, 60, 91, 0.06);
}

.dash-rp .dash-section__head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--ace-border);
}

.dash-rp .dash-section.is-collapsed .dash-section__head {
  border-bottom: 0;
  padding-bottom: 14px;
}

.dash-rp .dash-section__title {
  align-items: center;
  gap: 10px;
}

.dash-rp .dash-section__title h2 {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.1px;
  color: var(--ace-navy);
}

.dash-rp .dash-section__meta {
  font-size: 11px;
  font-weight: 600;
  color: var(--ace-text-muted);
  opacity: 1;
}

.dash-rp .dash-toggle {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--ace-border);
  background: var(--ace-surface-hover);
  color: var(--ace-text-secondary);
  font-size: 1rem;
  line-height: 1;
}

.dash-rp .dash-toggle:hover {
  transform: none;
  background: var(--ace-ice);
  color: var(--ace-navy);
}

.dash-rp .dash-section__body { padding: 16px 18px; }
.dash-rp .dash-section__body.is-flush { padding: 0; }

/* Controls strip at the top of a flush section (brand chips, division chips,
   scope picker). Sits between the card head and the table. */
.dash-rp .dash-sec-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--ace-border);
  background: #fff;
}

.dash-rp .dash-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* JS-owned active state on the chip groups (.dash-div-btn / .dash-ch-btn).
   (0,3,0) so it beats .rp-chip:hover without !important. */
.dash-rp .rp-chip.dash-div-active {
  background: var(--ace-navy);
  color: #fff;
}

.dash-rp .dash-innovation-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding: 5px 12px 5px 9px;
  border-radius: 999px;
  background: var(--ace-surface-hover);
  font-size: 12px;
  font-weight: 700;
  color: var(--ace-text-secondary);
  cursor: pointer;
  user-select: none;
}

.dash-rp .dash-innovation-toggle:hover { color: var(--ace-navy); }

.dash-rp .dash-innovation-toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--ace-navy);
  cursor: pointer;
}

/* ── Tables (all are .rp-tbl; these are the dashboard-only row types) ── */
.dash-rp .rp-tbl th,
.dash-rp .rp-tbl td { white-space: nowrap; }

.dash-rp .rp-tbl td:first-child { font-weight: 600; }

.dash-rp .rp-tbl th.col-total { color: var(--ace-navy); }
.dash-rp .rp-tbl td.col-total {
  background: #f7faff;
  font-weight: 800;
  color: var(--ace-navy);
}

.dash-rp .dash-na { color: var(--ace-text-muted); }

/* "vs Category" comparison rows under the Channel Breakdown matrix */
.dash-rp .rp-tbl tr.dash-vs-cat td { font-size: 12px; padding-top: 7px; padding-bottom: 7px; }
.dash-rp .rp-tbl tr.dash-vs-cat td.dash-vs-cat-label {
  padding-left: 32px;
  font-weight: 500;
  color: var(--ace-text-muted);
}

/* Skeleton rows while the first load is in flight */
.dash-rp .dash-skel-row td { padding: 14px; }
.dash-rp .dash-skel-row .rp-skeleton,
.dash-rp .dash-skel-block .rp-skeleton { margin-bottom: 0; }
.dash-rp .dash-skel-block { padding: 14px 18px; }

/* Rank badge */
.dash-rp .dash-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--ace-surface-hover);
  color: var(--ace-text-secondary);
}

.dash-rp .dash-rank-top3 {
  background: var(--ace-navy);
  color: #fff;
}

/* Cottage Springs row */
.dash-rp .rp-tbl tr.dash-row-highlight { background: var(--ace-ice); }
.dash-rp .rp-tbl tr.dash-row-highlight:hover { background: #d9f1fb; }
.dash-rp .rp-tbl tr.dash-row-highlight td {
  color: var(--ace-navy);
  font-weight: 700;
}
.dash-rp .rp-tbl tr.dash-row-highlight td:first-child { box-shadow: inset 3px 0 0 var(--ace-blue); }

/* Group strips: "Other Internal Brands", ABG / Corby / KDP headers */
.dash-rp .rp-tbl tr.dash-row-divider td,
.dash-rp .rp-tbl tr.dash-matrix-group-header td {
  background: #f7faff;
  color: var(--ace-navy);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-align: left;
  padding: 8px 14px;
  border-top: 1px solid var(--ace-border);
  border-bottom: 1px solid var(--ace-border);
}

/* Expandable brand rows -> banner sub-rows; ROS -> channel sub-rows */
.brand-expandable,
.ros-expandable {
  cursor: pointer;
  user-select: none;
}

.brand-expandable {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.brand-expandable:hover,
.ros-expandable:hover { color: var(--ace-navy); }

.expand-arrow,
.ros-expand-arrow {
  display: inline-block;
  width: 12px;
  font-size: 0.65rem;
  text-align: center;
  color: var(--ace-text-muted);
  transition: transform 0.15s ease;
}

.ros-expand-arrow { margin-right: 4px; }

.brand-row--expanded .expand-arrow { transform: rotate(90deg); }

.dash-rp .rp-tbl tr.banner-sub-row,
.dash-rp .rp-tbl tr.channel-sub-row { background: var(--ace-surface-alt); }

.dash-rp .rp-tbl tr.banner-sub-row td,
.dash-rp .rp-tbl tr.channel-sub-row td {
  padding-top: 7px;
  padding-bottom: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ace-text-secondary);
}

.dash-rp .rp-tbl tr.channel-sub-row td { color: #4a6fa5; }

.dash-rp .rp-tbl tr.banner-sub-row td.banner-indent,
.dash-rp .rp-tbl tr.channel-sub-row td.channel-indent {
  padding-left: 32px;
  color: var(--ace-text-muted);
}

.dash-rp .rp-tbl tr.channel-sub-row td.channel-indent { font-style: italic; }

.banner-sub-row.is-hidden,
.channel-sub-row.is-hidden { display: none; }

/* Sales by Product: supplier stripe + faint tint (ABG blue / KDP red / Corby amber) */
.dash-rp .rp-tbl tr.sbp-product-row { cursor: pointer; }
.dash-rp .rp-tbl tr.sbp-row-abg   { background: rgba(90, 200, 242, 0.07); }
.dash-rp .rp-tbl tr.sbp-row-kdp   { background: rgba(196, 18, 48, 0.05); }
.dash-rp .rp-tbl tr.sbp-row-corby { background: rgba(246, 180, 114, 0.10); }
.dash-rp .rp-tbl tr.sbp-row-abg:hover   { background: rgba(90, 200, 242, 0.14); }
.dash-rp .rp-tbl tr.sbp-row-kdp:hover   { background: rgba(196, 18, 48, 0.09); }
.dash-rp .rp-tbl tr.sbp-row-corby:hover { background: rgba(246, 180, 114, 0.18); }
.dash-rp .rp-tbl tr.sbp-row-abg td:first-child   { box-shadow: inset 3px 0 0 var(--ace-blue); }
.dash-rp .rp-tbl tr.sbp-row-kdp td:first-child   { box-shadow: inset 3px 0 0 var(--ace-kdp-red); }
.dash-rp .rp-tbl tr.sbp-row-corby td:first-child { box-shadow: inset 3px 0 0 var(--ace-amber); }

.dash-rp .rp-tbl tr.sbp-channel-row td { font-size: 12px; }
.dash-rp .sbp-arrow { font-size: 0.7em; color: var(--ace-text-muted); }

/* ── Channel Breakdown inner card (built by _renderSingleChannelCard) ──
   Flat inside its section: the brand identity is the swatch, not a banner. */
.dash-rp .dash-matrix-card {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.dash-rp .dash-matrix-card__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--ace-text-secondary);
  border-bottom: 1px solid var(--ace-border-soft);
}

.dash-rp .dash-matrix-card__header .accent-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Brand swatch colours (bare classes; kdp-manager also uses .accent-dot) */
.accent-category { background: var(--ace-text-secondary); }
.accent-cs { background: var(--ace-navy); }
.accent-motts { background: var(--ace-kdp-red); }
.accent-tt { background: var(--ace-amber); }

/* ── Banner Analysis ── */
.dash-rp .dash-multi { position: relative; }

.dash-rp .dash-multi__btn {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 190px;
  max-width: 320px;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--ace-surface-hover);
  color: var(--ace-navy);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.dash-rp .dash-multi__btn:hover,
.dash-rp .dash-multi__btn[aria-expanded="true"] { background: var(--ace-ice); }

.dash-multi__btn > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dash-multi__caret {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--ace-text-secondary);
  flex: none;
}

.dash-multi__panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  min-width: 240px;
  max-height: 320px;
  overflow-y: auto;
  padding: 6px 0;
  background: #fff;
  border: 1px solid rgba(2, 60, 91, 0.08);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(2, 60, 91, 0.16);
}

.dash-multi__head {
  padding: 8px 12px 4px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ace-text-muted);
}

/* Qualified with the panel so no global `label` rule can restyle the options
   (an earlier layout had them under a rule that uppercased every brand name). */
.dash-multi__panel .dash-multi__opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  color: var(--ace-text);
  cursor: pointer;
}

.dash-multi__panel .dash-multi__opt:hover { background: var(--ace-surface-hover); }

.dash-multi__panel .dash-multi__opt input {
  flex: none;
  cursor: pointer;
  accent-color: var(--ace-navy);
}

.dash-multi__loading {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--ace-text-muted);
}

.dash-multi__foot {
  margin-top: 6px;
  padding: 6px 12px 2px;
  border-top: 1px solid var(--ace-border);
}

.dash-multi__clear {
  background: none;
  border: 0;
  padding: 0;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--ace-blue-hover);
  cursor: pointer;
}

.dash-rp .dash-banner-note {
  padding: 10px 18px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ace-text-secondary);
  border-bottom: 1px solid var(--ace-border-soft);
}

.dash-rp .dash-banner-note:empty { display: none; }

.dash-rp .dash-banner-note.is-warning {
  background: #fff8e6;
  color: var(--ace-text);
  box-shadow: inset 3px 0 0 var(--ace-amber);
}

/* ══════════════════════════════════════════
   SECTION TOGGLE SYSTEM (+/-)
   Shared with gc-sales, promo-tracker, volume-estimations,
   on-product-overview and gc-declines. Do not restyle here; the
   dashboard's look is the `.dash-rp` block above.
   ══════════════════════════════════════════ */

.dash-section {
  border-radius: 16px;
  margin: 14px 0;
  overflow: hidden;
  background: #fff;
  border: 1px solid #e8ecf0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.dash-section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  cursor: default;
}

.dash-section__title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.dash-section__title h2,
.dash-section__title h3 {
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 1rem;
  color: var(--ace-text);
}

.dash-section__meta {
  font-size: 12px;
  opacity: 0.6;
  white-space: nowrap;
}

.dash-toggle {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.10);
  background: rgba(248,249,250,0.9);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  user-select: none;
  flex: 0 0 auto;
  color: var(--ace-text-secondary);
  transition: transform 0.15s, background 0.15s;
}

.dash-toggle:hover {
  transform: translateY(-1px);
  background: #e2e8f0;
}

.dash-toggle:active {
  transform: translateY(0px);
}

.dash-toggle[data-state="open"]::before { content: "\2212"; }
.dash-toggle[data-state="closed"]::before { content: "+"; }

.dash-section__body {
  padding: 0 20px 20px 20px;
}

.dash-section.is-collapsed .dash-section__body {
  display: none;
}

.dash-section.is-collapsed .dash-section__head {
  padding-bottom: 14px;
}

/* ══════════════════════════════════════════
   MATRIX TABLES (scroll wrappers)
   ══════════════════════════════════════════ */

.dash-matrix-scroll,
.dash-table-scroll {
  overflow-x: auto;
}

/* ══════════════════════════════════════════
   CHART CARDS
   ══════════════════════════════════════════ */

.dash-chart-wrap {
  /* Reserve the chart's space before Chart.js paints so async chart loads
     don't shift the layout. Tracks the ~2:1 responsive canvas up to the
     320px cap below (at desktop widths the reserve equals final height). */
  min-height: clamp(160px, 40vw, 320px);
}

.dash-chart-wrap canvas {
  max-height: 320px;
}

/* ══════════════════════════════════════════
   LOADING
   A floating pill, not a full-screen scrim: the sections keep their place
   and dim (.dash-rp.is-loading) while a refresh is in flight.
   ══════════════════════════════════════════ */

.dash-loading {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 8px 12px;
  background: #fff;
  border: 1px solid rgba(2, 60, 91, 0.08);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(2, 60, 91, 0.16);
  font-size: 12px;
  font-weight: 700;
  color: var(--ace-navy);
}

.dash-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--ace-ice);
  border-top-color: var(--ace-navy);
  border-radius: 50%;
  animation: dash-spin 0.7s linear infinite;
}

@keyframes dash-spin {
  to { transform: rotate(360deg); }
}

/* ══════════════════════════════════════════
   ENTRANCE ANIMATION
   ══════════════════════════════════════════ */

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

.dash-section {
  /* fill-mode BOTH, not forwards: with forwards, delayed sections paint
     fully visible during their animation-delay, snap to opacity 0 when the
     delay expires, then fade back in: a flash-and-jump on every initial
     render. `both` applies the `from` keyframe during the delay. */
  animation: dashFadeUp 0.4s ease both;
}

.dash-section:nth-child(2) { animation-delay: 0.08s; }
.dash-section:nth-child(3) { animation-delay: 0.16s; }
.dash-section:nth-child(4) { animation-delay: 0.24s; }
.dash-section:nth-child(5) { animation-delay: 0.32s; }
.dash-section:nth-child(6) { animation-delay: 0.40s; }
.dash-section:nth-child(7) { animation-delay: 0.48s; }
.dash-section:nth-child(8) { animation-delay: 0.56s; }
.dash-section:nth-child(9) { animation-delay: 0.64s; }
.dash-section:nth-child(10) { animation-delay: 0.72s; }

/* ══════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════ */

@media (max-width: 640px) {
  .dash-rp .dash-date-range-wrap { min-width: 100%; }
  .dash-rp .dash-daterange-input { min-width: 0; width: 100%; }
  .dash-rp .rp-spacer,
  .dash-rp .rp-divider { display: none; }
  .dash-rp .dash-sec-tools { padding: 10px 14px; }
  .dash-rp .dash-innovation-toggle { margin-left: 0; }
  .dash-rp .dash-multi__btn { min-width: 0; max-width: 100%; }

  /* Two-month flatpickr is 580px wide; cap it on phones so the calendar
     never blows out the viewport. */
  .flatpickr-calendar.showTwoMonths {
    width: auto !important;
    max-width: calc(100vw - 12px);
  }
}

/* ══════════════════════════════════════════
   DATE RANGE PICKER (flatpickr theme)
   ══════════════════════════════════════════ */

.flatpickr-calendar {
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(2, 60, 91, 0.18);
  border: 1px solid rgba(2, 60, 91, 0.08);
  font-family: inherit;
}

.flatpickr-calendar.open {
  z-index: 9999;
}

.flatpickr-months .flatpickr-month {
  background: var(--ace-navy);
  color: #fff;
  border-radius: 12px 12px 0 0;
}

.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year {
  color: #fff;
  font-weight: 600;
}

.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
  fill: #fff;
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
  background: var(--ace-navy);
  border-color: var(--ace-navy);
}

.flatpickr-day.inRange {
  background: rgba(2, 60, 91, 0.12);
  border-color: transparent;
  box-shadow: -5px 0 0 rgba(2, 60, 91, 0.12), 5px 0 0 rgba(2, 60, 91, 0.12);
}

.flatpickr-day.today {
  border-color: var(--ace-navy);
}

.flatpickr-day:hover {
  background: rgba(2, 60, 91, 0.08);
}

.flatpickr-calendar.showTwoMonths {
  width: 580px;
}

.flatpickr-calendar.showTwoMonths .flatpickr-months {
  border-radius: 12px 12px 0 0;
}
