/* === Matrix View === */
.matrix-controls {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  align-items: center;
}

.matrix-legend {
  display: flex;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
  font-size: var(--font-size-sm);
  flex-wrap: wrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.legend-swatch {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-xs);
}

.legend-swatch--yes {
  background: #d4edda;
  color: var(--color-success);
}

.legend-swatch--no {
  background: #fce4ec;
  color: var(--color-error);
}

.legend-swatch--partial {
  background: #fff3cd;
  color: #856404;
}

.legend-swatch--planned {
  background: #cce5ff;
  color: #004085;
}

.legend-swatch--unknown {
  background: var(--color-gray-2);
  color: var(--color-gray-50);
}

/* === Matrix Table Wrapper === */
.matrix-wrapper {
  overflow-x: auto;
  border: 1px solid var(--color-gray-3);
  border-radius: var(--radius-lg);
  background: var(--color-white);
}

/* === Matrix Table === */
.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
  min-width: 800px;
}

.matrix-table th,
.matrix-table td {
  padding: var(--space-2) var(--space-3);
  text-align: center;
  border-bottom: 1px solid var(--color-gray-2);
  border-right: 1px solid var(--color-gray-2);
}

.matrix-table th:last-child,
.matrix-table td:last-child {
  border-right: none;
}

/* Sticky first column */
.matrix-table th:first-child,
.matrix-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--color-white);
  text-align: left;
  min-width: 200px;
  max-width: 250px;
  font-weight: var(--font-weight-semibold);
  border-right: 2px solid var(--color-gray-3);
}

/* Sticky header row */
.matrix-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--color-primary-darker);
  color: var(--color-white);
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
  font-size: var(--font-size-xs);
  padding: var(--space-3);
}

.matrix-table thead th:first-child {
  z-index: 4;
  background: var(--color-primary-darker);
  color: var(--color-white);
}

/* Category group header */
.matrix-category-row td {
  background: var(--color-gray-2);
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-sm);
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-right: none;
}

.matrix-category-row td:first-child {
  background: var(--color-gray-2);
}

/* Criterion name */
.criterion-name {
  display: block;
}

.criterion-weight {
  font-size: var(--font-size-xs);
  color: var(--color-gray-50);
  font-weight: var(--font-weight-normal);
}

.criterion-weight--critical {
  color: var(--color-error);
  font-weight: var(--font-weight-semibold);
}

.criterion-weight--important {
  color: var(--color-status-pilot);
}

/* === Matrix Cells === */
.matrix-cell {
  cursor: pointer;
  transition: background 0.1s;
  min-width: 60px;
}

.matrix-cell:hover {
  filter: brightness(0.95);
}

.matrix-cell--yes {
  background: #d4edda;
  color: var(--color-success);
  font-weight: var(--font-weight-bold);
}

.matrix-cell--no {
  background: #fce4ec;
  color: var(--color-error);
  font-weight: var(--font-weight-bold);
}

.matrix-cell--partial {
  background: #fff3cd;
  color: #856404;
  font-weight: var(--font-weight-bold);
}

.matrix-cell--planned {
  background: #cce5ff;
  color: #004085;
  font-weight: var(--font-weight-bold);
}

.matrix-cell--unknown {
  background: var(--color-gray-1);
  color: var(--color-gray-30);
}

/* === Tool Score Row === */
.matrix-score-row td {
  font-weight: var(--font-weight-bold);
  background: var(--color-gray-2);
  border-top: 2px solid var(--color-gray-3);
}

.matrix-score-row td:first-child {
  background: var(--color-gray-2);
}

/* === Tool Column Header (rotated for narrow columns) === */
.matrix-table thead th.tool-header {
  min-width: 80px;
  max-width: 100px;
}

.tool-header-name {
  display: block;
  font-size: var(--font-size-xs);
}

/* === Popover (modal for notes) === */
.matrix-popover {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
  z-index: 200;
  max-width: 400px;
  width: 90%;
}

.matrix-popover-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 199;
}

.matrix-popover h3 {
  font-size: var(--font-size-md);
  margin-bottom: var(--space-2);
}

.matrix-popover p {
  font-size: var(--font-size-sm);
  color: var(--color-gray-70);
  margin-bottom: var(--space-2);
}

.matrix-popover .popover-close {
  background: none;
  border: 1px solid var(--color-gray-3);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  margin-top: var(--space-3);
}

.matrix-popover .popover-close:hover {
  background: var(--color-gray-2);
}

/* === Print === */
@media print {
  .matrix-controls, .matrix-legend {
    break-after: avoid;
  }
  .matrix-table th:first-child,
  .matrix-table td:first-child {
    position: static;
  }
  .matrix-table thead th {
    position: static;
    background: var(--color-gray-70) !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .matrix-cell--yes, .matrix-cell--no, .matrix-cell--partial, .matrix-cell--planned {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
