/**
 * Reports UI modernization — Phase 8A.1
 * All rules scoped under #reportsView.reports-modern.
 * Presentation only. No !important. No global input/select/button/table/body.
 */

#reportsView.reports-modern {
  --reports-gap: 12px;
  --reports-radius: 8px;
  --reports-control: 36px;
  --reports-touch: 44px;
  --reports-ink: var(--ds-color-ink, var(--ink, #24262d));
  --reports-muted: var(--ds-color-muted, var(--muted, #6b7280));
  --reports-line: var(--ds-color-line, var(--line, #e5e7eb));
  --reports-surface: #fff;
  --reports-surface-quiet: #f8f9fa;
  --reports-accent: var(--ds-color-accent, var(--accent, #0f766e));
  --reports-accent-soft: color-mix(in srgb, var(--reports-accent) 10%, transparent);
  max-width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--reports-gap);
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}

#reportsView.reports-modern *,
#reportsView.reports-modern *::before,
#reportsView.reports-modern *::after {
  box-sizing: border-box;
}

/* —— Header —— */
#reportsView.reports-modern .reports-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 16px;
  margin: 0;
}

#reportsView.reports-modern .reports-page-header__copy {
  min-width: 0;
  flex: 1 1 220px;
}

#reportsView.reports-modern .reports-page-header__title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--reports-ink);
  line-height: 1.25;
}

#reportsView.reports-modern .reports-page-header__sub {
  margin: 4px 0 0;
  font-size: 0.875rem;
  line-height: 1.4;
  max-width: 42rem;
}

#reportsView.reports-modern .reports-page-header__actions.view-page-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
  flex: 0 1 auto;
}

#reportsView.reports-modern .reports-page-header__actions .ghost-button,
#reportsView.reports-modern .reports-page-header__actions .primary-button {
  min-height: var(--reports-control);
  min-width: 44px;
  padding: 0 14px;
  border-radius: var(--reports-radius);
  box-shadow: none;
  font-weight: 550;
}

#reportsView.reports-modern .reports-page-header__actions .ghost-button {
  border: 1px solid var(--reports-line);
  background: var(--reports-surface);
  color: var(--reports-ink);
}

#reportsView.reports-modern .reports-page-header__actions .primary-button {
  border: 1px solid var(--reports-accent);
  background: var(--reports-accent);
  color: #fff;
}

#reportsView.reports-modern .reports-page-header__actions .primary-button:disabled,
#reportsView.reports-modern .reports-page-header__actions .ghost-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* —— Filters —— */
#reportsView.reports-modern .reports-filters {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--reports-line);
  border-radius: var(--reports-radius);
  background: var(--reports-surface-quiet);
}

#reportsView.reports-modern .report-toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(12rem, 1.4fr);
  gap: 10px 12px;
  align-items: end;
  margin: 0;
}

#reportsView.reports-modern .report-toolbar label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  min-width: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--reports-muted);
  letter-spacing: 0.01em;
}

#reportsView.reports-modern .report-toolbar select,
#reportsView.reports-modern .report-toolbar input {
  width: 100%;
  min-height: var(--reports-control);
  margin: 0;
  padding: 0 10px;
  border: 1px solid var(--reports-line);
  border-radius: 6px;
  background: var(--reports-surface);
  color: var(--reports-ink);
  font-size: 0.875rem;
  font-weight: 500;
}

#reportsView.reports-modern .report-toolbar label.report-search {
  position: relative;
  display: block;
  flex-direction: unset;
  gap: 0;
  min-height: var(--reports-control);
  padding: 0;
  border: 1px solid var(--reports-line);
  border-radius: 6px;
  background: var(--reports-surface);
  font-size: 0;
  font-weight: 400;
  color: inherit;
  letter-spacing: 0;
  overflow: hidden;
}

#reportsView.reports-modern .report-toolbar label.report-search > span {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  display: block;
  width: 1rem;
  height: 1rem;
  margin: 0;
  line-height: 1rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--reports-muted);
  pointer-events: none;
}

#reportsView.reports-modern .report-toolbar label.report-search input,
#reportsView.reports-modern .report-toolbar label.report-search #reportProductSearchInput {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: var(--reports-control);
  height: var(--reports-control);
  margin: 0;
  border: 0;
  border-radius: 6px;
  padding: 0 10px 0 2rem;
  background: transparent;
  box-shadow: none;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: var(--reports-control);
  -webkit-appearance: none;
  appearance: none;
}

#reportsView.reports-modern .report-toolbar label.report-search #reportProductSearchInput::-webkit-search-decoration,
#reportsView.reports-modern .report-toolbar label.report-search #reportProductSearchInput::-webkit-search-cancel-button,
#reportsView.reports-modern .report-toolbar label.report-search #reportProductSearchInput::-webkit-search-results-button,
#reportsView.reports-modern .report-toolbar label.report-search #reportProductSearchInput::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

#reportsView.reports-modern .reports-filters__search {
  grid-column: auto;
}

/* —— KPI —— */
#reportsView.reports-modern .reports-kpis-section {
  margin: 0;
}

#reportsView.reports-modern .report-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

#reportsView.reports-modern .report-kpi {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 14px 14px 14px 16px;
  border: 1px solid var(--reports-line);
  border-radius: var(--reports-radius);
  background: var(--reports-surface);
  overflow: hidden;
  min-width: 0;
}

#reportsView.reports-modern .report-kpi::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--reports-accent);
}

#reportsView.reports-modern .report-kpi:nth-child(4n + 2)::before {
  background: #2563eb;
}

#reportsView.reports-modern .report-kpi:nth-child(4n + 3)::before {
  background: #b45309;
}

#reportsView.reports-modern .report-kpi:nth-child(4n + 4)::before {
  background: #7c3aed;
}

#reportsView.reports-modern .report-kpi__label,
#reportsView.reports-modern .report-kpi span {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--reports-muted);
  line-height: 1.3;
}

#reportsView.reports-modern .report-kpi__value,
#reportsView.reports-modern .report-kpi strong {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--reports-ink);
  line-height: 1.2;
  word-break: break-word;
}

#reportsView.reports-modern .report-kpi__hint,
#reportsView.reports-modern .report-kpi small {
  font-size: 0.75rem;
  color: var(--reports-muted);
  line-height: 1.35;
}

/* —— Analytics —— */
#reportsView.reports-modern .reports-analytics {
  margin: 0;
  min-width: 0;
}

#reportsView.reports-modern .report-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 12px;
  margin: 0;
  align-items: start;
}

#reportsView.reports-modern .reports-col-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

#reportsView.reports-modern .report-layout > .reports-col-main,
#reportsView.reports-modern .report-layout > .report-side {
  align-self: start;
  height: auto;
  min-width: 0;
}

#reportsView.reports-modern .reports-card,
#reportsView.reports-modern .report-chart,
#reportsView.reports-modern .report-mini-list {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--reports-line);
  border-radius: var(--reports-radius);
  background: var(--reports-surface);
  min-width: 0;
}

#reportsView.reports-modern .reports-card__heading,
#reportsView.reports-modern .report-chart .panel-heading,
#reportsView.reports-modern .report-mini-heading,
#reportsView.reports-modern .report-table-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 12px;
  margin: 0 0 10px;
}

#reportsView.reports-modern .report-chart h3,
#reportsView.reports-modern .report-mini-heading h3,
#reportsView.reports-modern .report-table-tools h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--reports-ink);
}

#reportsView.reports-modern .report-chart .panel-heading span,
#reportsView.reports-modern .report-mini-heading span,
#reportsView.reports-modern .report-table-tools span {
  font-size: 0.75rem;
  color: var(--reports-muted);
}

#reportsView.reports-modern .report-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

#reportsView.reports-modern .report-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  min-width: 0;
}

#reportsView.reports-modern .report-bar-row {
  display: grid;
  grid-template-columns: minmax(4.5rem, 5.5rem) minmax(0, 1fr) minmax(5.5rem, auto);
  gap: 8px 10px;
  align-items: center;
  margin: 0;
  font-size: 0.8rem;
}

#reportsView.reports-modern .report-bar-row > span {
  color: var(--reports-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#reportsView.reports-modern .report-bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--reports-surface-quiet);
  border: 1px solid var(--reports-line);
  overflow: hidden;
  min-width: 0;
}

#reportsView.reports-modern .report-bar-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--reports-accent), color-mix(in srgb, var(--reports-accent) 70%, #2563eb));
}

#reportsView.reports-modern .report-bar-row strong {
  text-align: right;
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--reports-ink);
  white-space: nowrap;
}

#reportsView.reports-modern .report-mini-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  gap: 2px 10px;
  padding: 8px 0;
  border-top: 1px solid var(--reports-line);
  align-items: baseline;
}

#reportsView.reports-modern .report-mini-row:first-of-type {
  border-top: 0;
}

#reportsView.reports-modern .report-mini-row > span {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 550;
  color: var(--reports-ink);
}

#reportsView.reports-modern .report-mini-row > strong {
  grid-column: 2;
  grid-row: 1;
  font-size: 0.875rem;
  color: var(--reports-ink);
}

#reportsView.reports-modern .report-mini-row > small {
  grid-column: 1 / -1;
  grid-row: 2;
  color: var(--reports-muted);
}

/* —— Matrix —— */
#reportsView.reports-modern .reports-matrix-section {
  margin: 0;
  min-width: 0;
}

#reportsView.reports-modern .report-table-wrap {
  margin: 0;
  padding: 0;
  border: 1px solid var(--reports-line);
  border-radius: var(--reports-radius);
  background: var(--reports-surface);
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
}

#reportsView.reports-modern .reports-matrix-desktop {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

#reportsView.reports-modern .reports-matrix-mobile {
  display: none;
}

#reportsView.reports-modern .report-matrix {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  table-layout: auto;
}

#reportsView.reports-modern .report-matrix th,
#reportsView.reports-modern .report-matrix td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--reports-line);
  text-align: left;
  font-size: 0.8125rem;
  vertical-align: top;
  white-space: nowrap;
}

#reportsView.reports-modern .report-matrix th:nth-child(2),
#reportsView.reports-modern .report-matrix td:nth-child(2) {
  white-space: normal;
  min-width: 10rem;
  max-width: 18rem;
}

#reportsView.reports-modern .report-matrix thead th {
  position: sticky;
  top: 0;
  background: var(--reports-surface-quiet);
  font-weight: 650;
  color: var(--reports-muted);
  z-index: 1;
}

#reportsView.reports-modern .report-matrix tfoot td {
  font-weight: 650;
  background: var(--reports-surface-quiet);
}

#reportsView.reports-modern .reports-matrix-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--reports-line);
}

#reportsView.reports-modern .reports-matrix-card:last-child {
  border-bottom: 0;
}

#reportsView.reports-modern .reports-matrix-card--total {
  background: var(--reports-surface-quiet);
}

#reportsView.reports-modern .reports-matrix-card__head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

#reportsView.reports-modern .reports-matrix-card__month {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--reports-muted);
}

#reportsView.reports-modern .reports-matrix-card__product {
  font-size: 0.95rem;
  color: var(--reports-ink);
  word-break: break-word;
}

#reportsView.reports-modern .reports-matrix-card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 12px;
  font-size: 0.8125rem;
  color: var(--reports-muted);
}

#reportsView.reports-modern .reports-matrix-card__meta strong {
  color: var(--reports-ink);
  font-size: 0.9rem;
}

#reportsView.reports-modern .reports-matrix-card__reps {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 4px;
  border-top: 1px dashed var(--reports-line);
}

#reportsView.reports-modern .reports-matrix-card__rep {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.8125rem;
}

#reportsView.reports-modern .reports-matrix-card__rep span {
  color: var(--reports-muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

#reportsView.reports-modern .empty-state,
#reportsView.reports-modern .muted-text {
  color: var(--reports-muted);
}

/* —— Responsive —— */
@media (max-width: 1280px) {
  #reportsView.reports-modern .report-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #reportsView.reports-modern .reports-filters__search {
    grid-column: 1 / -1;
  }

  #reportsView.reports-modern .report-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1024px) {
  #reportsView.reports-modern .report-layout {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  /* Flatten left column so order is trend → side lists → matrix */
  #reportsView.reports-modern .reports-col-main {
    display: contents;
  }

  #reportsView.reports-modern .report-chart {
    order: 1;
  }

  #reportsView.reports-modern .report-side {
    order: 2;
  }

  #reportsView.reports-modern .reports-matrix-section {
    order: 3;
  }

  #reportsView.reports-modern .report-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  #reportsView.reports-modern {
    gap: 10px;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  #reportsView.reports-modern .reports-page-header__title {
    font-size: 1.2rem;
  }

  #reportsView.reports-modern .reports-page-header__actions .ghost-button,
  #reportsView.reports-modern .reports-page-header__actions .primary-button {
    min-height: var(--reports-touch);
  }

  #reportsView.reports-modern .report-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #reportsView.reports-modern .report-toolbar select,
  #reportsView.reports-modern .report-toolbar input:not(#reportProductSearchInput),
  #reportsView.reports-modern .report-toolbar label.report-search {
    min-height: var(--reports-touch);
  }

  #reportsView.reports-modern .report-toolbar label.report-search input,
  #reportsView.reports-modern .report-toolbar label.report-search #reportProductSearchInput {
    min-height: var(--reports-touch);
    height: var(--reports-touch);
    line-height: var(--reports-touch);
    padding-left: 2.25rem;
  }

  #reportsView.reports-modern .report-toolbar label.report-search > span {
    left: 12px;
  }

  #reportsView.reports-modern .reports-filters__search {
    grid-column: 1 / -1;
  }

  #reportsView.reports-modern .report-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #reportsView.reports-modern .report-bar-row {
    grid-template-columns: minmax(3.75rem, 4.75rem) minmax(0, 1fr);
  }

  #reportsView.reports-modern .report-bar-row strong {
    grid-column: 1 / -1;
    text-align: left;
  }

  #reportsView.reports-modern .reports-matrix-desktop {
    display: none;
  }

  #reportsView.reports-modern .reports-matrix-mobile {
    display: flex;
    flex-direction: column;
  }

  #reportsView.reports-modern .report-table-wrap {
    overflow: visible;
  }
}

@media (max-width: 430px) {
  #reportsView.reports-modern .report-kpis {
    grid-template-columns: 1fr;
  }

  #reportsView.reports-modern .report-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  #reportsView.reports-modern .report-kpi__value,
  #reportsView.reports-modern .report-kpi strong {
    font-size: 1.1rem;
  }
}
