/* ===== CRM Dashboard Styles — Redesigned ===== */

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

.dash-header {
  text-align: center;
  margin-bottom: 24px;
}

.dash-title {
  font-size: 1.8rem;
  color: var(--ace-navy);
  margin: 0 0 4px;
}

.dash-subtitle {
  color: var(--ace-text-muted);
  font-size: 0.9rem;
  margin: 0;
}

/* ── Filter Bar ── */
.dash-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  background: #f8f9fa;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
}

.dash-filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dash-filter-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ace-text-secondary);
  text-transform: uppercase;
}

.dash-input {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.9rem;
  min-width: 140px;
  background: #fff;
}

.dash-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--ace-navy);
  color: #fff;
  transition: background 0.2s;
}

.dash-btn:hover { background: #024a72; }

.dash-btn-secondary {
  background: #95a5a6;
}

.dash-btn-secondary:hover { background: var(--ace-text-muted); }

/* ── KPI Cards ── */
.dash-kpi-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.dash-kpi {
  background: #fff;
  border: 1px solid #e8ecf0;
  border-radius: 10px;
  padding: 20px 16px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.dash-kpi-accent {
  border-left: 4px solid var(--ace-coral);
}

.dash-kpi-val {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--ace-navy);
  margin-bottom: 4px;
}

.dash-kpi-label {
  font-size: 0.75rem;
  color: var(--ace-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ══════════════════════════════════════════
   SECTION TOGGLE SYSTEM (+/-)
   ══════════════════════════════════════════ */

.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 (shared)
   ══════════════════════════════════════════ */

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

.dash-matrix {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
}

.dash-matrix th {
  background: #f8f9fa;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ace-text-secondary);
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
  text-align: right;
}

.dash-matrix th:first-child {
  text-align: left;
}

.dash-matrix td {
  padding: 8px 14px;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: #334155;
}

.dash-matrix td:first-child {
  font-weight: 600;
  color: var(--ace-text);
  text-align: left;
}

.dash-matrix tbody tr:hover td {
  background: rgba(0,59,92,0.03);
}

/* Total column emphasis */
.dash-matrix th.col-total,
.dash-matrix td.col-total {
  background: rgba(248,250,252,0.8);
  font-weight: 700;
}

/* ══════════════════════════════════════════
   CHANNEL BREAKDOWN MATRICES (2x2 grid)
   ══════════════════════════════════════════ */

.dash-matrix-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.dash-matrix-card {
  background: #fff;
  border: 1px solid #e8ecf0;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  transition: transform 0.15s, box-shadow 0.15s;
}

.dash-matrix-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

.dash-matrix-card__header {
  padding: 14px 18px;
  border-bottom: 1px solid #f1f5f9;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ace-text);
}

.dash-matrix-card__header .accent-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dash-matrix-card .dash-matrix-scroll {
  padding: 0 4px 8px;
}

/* Brand color accents */
.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-navy); }

/* ══════════════════════════════════════════
   UNIQUE CARD BRANDING
   ══════════════════════════════════════════ */

.dash-matrix-card--category .dash-matrix-card__header {
  background: var(--ace-grad-table-head);
  border-bottom-color: transparent;
  color: var(--ace-text-inverse);
}

.dash-matrix-card--cs {
  border-top: 3px solid var(--ace-navy);
}
.dash-matrix-card--cs .dash-matrix-card__header {
  background: var(--ace-grad-table-head);
  color: var(--ace-text-inverse);
}

.dash-matrix-card--motts {
  border-top: 3px solid var(--ace-kdp-red);
}
.dash-matrix-card--motts .dash-matrix-card__header {
  background: linear-gradient(90deg, #C41230, #e0243f);
  color: var(--ace-text-inverse);
}

.dash-matrix-card--tt {
  border-top: 3px solid var(--ace-amber);
}
.dash-matrix-card--tt .dash-matrix-card__header {
  background: linear-gradient(90deg, var(--ace-amber), #f0a050);
  color: var(--ace-text);
}

/* ══════════════════════════════════════════
   EXPANDABLE BRAND ROWS
   ══════════════════════════════════════════ */

.brand-expandable {
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

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

.expand-arrow {
  display: inline-block;
  font-size: 0.65rem;
  transition: transform 0.15s ease;
  color: #94a3b8;
  width: 12px;
  text-align: center;
}

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

.banner-sub-row {
  background: #f8fafc;
}

.banner-sub-row td {
  font-size: 0.78rem !important;
  color: var(--ace-text-secondary) !important;
  padding-top: 6px !important;
  padding-bottom: 6px !important;
  border-bottom-color: #f1f5f9 !important;
}

.banner-sub-row td:first-child {
  font-weight: 500 !important;
  color: #94a3b8 !important;
}

.banner-indent {
  padding-left: 28px !important;
}

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

/* ══════════════════════════════════════════
   ROS EXPANDABLE (Channel Market Share)
   ══════════════════════════════════════════ */

.ros-expandable {
  cursor: pointer;
  user-select: none;
}

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

.ros-expand-arrow {
  display: inline-block;
  font-size: 0.65rem;
  transition: transform 0.15s ease;
  color: #94a3b8;
  width: 12px;
  text-align: center;
  margin-right: 4px;
}

.channel-sub-row {
  background: #f0f7ff;
}

.channel-sub-row td {
  font-size: 0.78rem !important;
  color: #4a6fa5 !important;
  padding-top: 6px !important;
  padding-bottom: 6px !important;
  border-bottom-color: #e3edf7 !important;
}

.channel-sub-row td:first-child {
  font-weight: 500 !important;
  color: #94a3b8 !important;
}

.channel-indent {
  padding-left: 28px !important;
  font-style: italic;
}

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

/* ══════════════════════════════════════════
   INTERNAL BRAND MATRIX
   ══════════════════════════════════════════ */

.dash-matrix-group-header td {
  background: var(--ace-text) !important;
  color: #fff !important;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 10px 14px;
  border-bottom: none !important;
  text-align: left;
}

.dash-matrix .brand-row td {
  font-size: 0.8rem;
}

/* ══════════════════════════════════════════
   RANK BADGES
   ══════════════════════════════════════════ */

.dash-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 800;
  background: #f1f5f9;
  color: var(--ace-text-secondary);
}

.dash-rank-top3 {
  background: linear-gradient(135deg, var(--ace-navy), #0a5f8a);
  color: #fff;
}

/* ══════════════════════════════════════════
   YOY COLORING
   ══════════════════════════════════════════ */

.dash-yoy-positive { color: var(--ace-positive); font-weight: 600; }
.dash-yoy-negative { color: var(--ace-negative); font-weight: 600; }

/* ══════════════════════════════════════════
   BRAND TABLE (Enhanced)
   ══════════════════════════════════════════ */

.dash-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.dash-table th {
  background: #f1f3f5;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: #495057;
  border-bottom: 2px solid #dee2e6;
  white-space: nowrap;
}

.dash-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #f1f3f5;
  white-space: nowrap;
  color: #333;
  font-variant-numeric: tabular-nums;
}

.dash-table tbody tr:hover {
  background: #f8f9fa;
}

.dash-table tbody tr.sbp-row-abg {
  background: #E5F8FF;
}

.dash-table tbody tr.sbp-row-abg:hover {
  background: #D0F0FF;
}

.dash-table tbody tr.sbp-row-kdp {
  background: #FDECEC;
}

.dash-table tbody tr.sbp-row-kdp:hover {
  background: #F8D0D0;
}

.dash-table tbody tr.sbp-row-corby {
  background: #FDF0DB;
}

.dash-table tbody tr.sbp-row-corby:hover {
  background: #FAE2B8;
}

.dash-row-highlight {
  background: #fff5f5 !important;
  font-weight: 600;
}

.dash-row-highlight td {
  color: var(--ace-negative);
}

.dash-row-divider td {
  background: #f8fafc;
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ace-text-secondary);
  padding: 8px 12px;
  border-bottom: 2px solid #e2e8f0;
}

.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
   ══════════════════════════════════════════ */

.dash-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--ace-overlay);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  gap: 12px;
  font-size: 0.9rem;
  color: rgba(255,255,255,0.7);
}

.dash-spinner {
  width: 36px;
  height: 36px;
  border: 4px solid rgba(255,255,255,0.15);
  border-top-color: var(--ace-blue);
  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: 768px) {
  .dash-matrix-grid {
    grid-template-columns: 1fr;
  }
  .dash-kpi-row {
    grid-template-columns: repeat(3, 1fr);
  }
  .dash-filters {
    flex-direction: column;
  }
  .dash-input {
    min-width: unset;
    width: 100%;
  }
  .dash-title {
    font-size: 1.4rem;
  }
}

@media (max-width: 480px) {
  .dash-kpi-row {
    grid-template-columns: repeat(2, 1fr);
  }
  .dash-kpi-val {
    font-size: 1.3rem;
  }
  .dash-daterange-input {
    min-width: 0;
    width: 100%;
  }
}

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

/* ══════════════════════════════════════════
   DIVISION FILTER BUTTONS
   ══════════════════════════════════════════ */

.dash-division-filters {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 8px 0;
}

.dash-filter-bar {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.dash-div-btn {
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: var(--ace-text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.dash-div-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.dash-div-active {
  background: var(--ace-navy) !important;
  color: #fff !important;
  border-color: var(--ace-navy) !important;
}

/* ══════════════════════════════════════════
   INNOVATION TOGGLE
   ══════════════════════════════════════════ */

.dash-innovation-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ace-text-secondary);
  cursor: pointer;
  user-select: none;
}

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

/* ══════════════════════════════════════════
   DATE RANGE PICKER
   ══════════════════════════════════════════ */

.dash-date-range-group {
  flex: 1;
  max-width: 420px;
}

.dash-date-range-wrap {
  position: relative;
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 0 12px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.dash-date-range-wrap:hover,
.dash-date-range-wrap:focus-within {
  border-color: #023C5B;
  box-shadow: 0 0 0 2px rgba(2, 60, 91, 0.15);
}

.dash-date-icon {
  color: #64748b;
  flex-shrink: 0;
  margin-right: 8px;
}

.dash-daterange-input {
  border: none !important;
  background: transparent !important;
  min-width: 240px;
  padding: 8px 0 !important;
  cursor: pointer;
  font-weight: 500;
  color: #023C5B;
}

.dash-daterange-input:focus {
  outline: none;
}

/* Quick-preset buttons */
.dash-date-presets {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.dash-preset-btn {
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.dash-preset-btn:hover {
  background: #023C5B;
  color: #fff;
  border-color: #023C5B;
}

.dash-preset-btn.is-active {
  background: #023C5B;
  color: #fff;
  border-color: #023C5B;
}

/* Flatpickr theme overrides */
.flatpickr-calendar {
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  border: 1px solid #e2e8f0;
  font-family: inherit;
}

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

.flatpickr-months .flatpickr-month {
  background: #023C5B;
  color: #fff;
  border-radius: 10px 10px 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: #023C5B;
  border-color: #023C5B;
}

.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: #023C5B;
}

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

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

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