.risk-matrix-container {
  font-family: 'Inter', system-ui, sans-serif;
  width: 100%;
  padding: 2rem 1rem;
  background: #f8fafc;
  box-sizing: border-box;
}

.header {
  margin-bottom: 1.5rem;
  margin-top: 0.62rem;
  display: flex;
  justify-content: space-between;

  .title {
    color: #1e293b;
    font-weight: 600;
    font-size: 1.8rem;
    margin-bottom: 0.25rem;
  }

  .subtitle {
    color: #64748b;
    font-size: 0.95rem;
  }
}

.matrix-controls {
  margin-bottom: 1.5rem;

  .legend {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;

    .legend-item {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.25rem 0.75rem;
      background: white;
      border-radius: 20px;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);

      .legend-color {
        width: 12px;
        height: 12px;
        border-radius: 3px;
      }

      .legend-label {
        font-size: 0.8rem;
        color: #475569;
      }
    }
  }
}

.matrix-wrapper {
  background: white;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  padding: 0.75rem;
  overflow: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  /* Smooth scrolling on iOS */
}

.risk-matrix {
  border-collapse: separate;
  border-spacing: 2px;
  width: 100%;
  table-layout: fixed;
  /* Important for responsive behavior */

  th,
  td {
    padding: 0.5rem;
    text-align: center;
    vertical-align: middle;
    background: white;
  }
}

.axis-corner {
  background: #f8fafc !important;
  width: 80px;

  .axis-label {
    color: #64748b;
    font-size: 0.75rem;
    line-height: 1.3;
  }
}

.impact-header,
.likelihood-header {
  background: #f8fafc !important;
  position: sticky;
  top: 0;
  z-index: 2;
  width: auto;

  .header-content {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;

    .level-name {
      font-weight: 500;
      color: #1e293b;
      font-size: 0.8rem;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .calculation-basis {
      font-size: 0.7rem;
      color: #64748b;
    }
  }
}

.risk-cell {
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  position: relative;
  aspect-ratio: 1/1;
  /* Maintain square cells */

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.08);
    z-index: 1;
  }

  .cell-content {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    height: 100%;
    justify-content: center;
    padding: 15px;

    .calculated-value {
      font-weight: 600;
      font-size: 1rem;
      color: rgba(0, 0, 0, 0.9);
      line-height: 1;
    }

    .risk-class-name {
      font-size: 0.7rem;
      font-weight: 500;
      color: rgba(0, 0, 0, 0.7);
      line-height: 1.2;
      max-width: 90%;
      margin: 0 auto;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.modal-content {
  background: white;
  border-radius: 16px;
  padding: 1.5rem;
  width: 90%;
  max-width: 420px;
  animation: modalSlideIn 0.2s ease-out;

  .modal-header {
    margin-bottom: 1rem;

    h3 {
      margin: 0 0 0.25rem;
      color: #1e293b;
      font-size: 1.25rem;
    }

    .modal-subheader {
      color: #64748b;
      font-size: 0.85rem;
    }

    .close-btn {
      position: absolute;
      top: 1rem;
      right: 1rem;
      background: none;
      border: none;
      font-size: 1.5rem;
      color: #94a3b8;
      cursor: pointer;
      padding: 0.25rem;
      transition: color 0.2s;

      &:hover {
        color: #475569;
      }
    }
  }
}

.risk-class-options {
  display: grid;
  gap: 0.75rem;

  .risk-class-option {
    padding: 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;

    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 3px 12px rgba(0, 0, 0, 0.1);
    }

    .risk-class-label {
      font-weight: 500;
      font-size: 0.95rem;
      margin-bottom: 0.25rem;
    }

    .risk-class-score {
      font-size: 0.8rem;
      opacity: 0.9;
    }
  }
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}



/* Media queries for different screen sizes */
@media (max-width: 1200px) {
  .risk-matrix {
    /* Scale down slightly on medium screens */
    font-size: 0.95rem;
  }

  .risk-cell .cell-content .calculated-value {
    font-size: 0.9rem;
  }

  .risk-cell .cell-content .risk-class-name {
    font-size: 0.65rem;
  }
}

@media (max-width: 992px) {

  /* More aggressive scaling for tablets */
  .matrix-wrapper {
    padding: 0.5rem;
  }

  .risk-matrix th,
  .risk-matrix td {
    padding: 0.35rem;
  }

  .axis-corner {
    width: 60px;
  }

  .impact-header .header-content .level-name,
  .likelihood-header .header-content .level-name {
    font-size: 0.75rem;
  }

  .impact-header .header-content .calculation-basis,
  .likelihood-header .header-content .calculation-basis {
    font-size: 0.65rem;
  }
}

@media (max-width: 768px) {

  /* Mobile optimization */
  .risk-matrix-container {
    padding: 1rem 0.5rem;
  }

  .header .title {
    font-size: 1.5rem;
  }

  .risk-matrix {
    border-spacing: 1px;
  }

  .risk-matrix th,
  .risk-matrix td {
    padding: 0.25rem;
  }

  .axis-corner {
    width: 50px;

    .axis-label {
      font-size: 0.65rem;
    }
  }

  .risk-cell .cell-content .calculated-value {
    font-size: 0.8rem;
  }

  .risk-cell .cell-content .risk-class-name {
    font-size: 0.6rem;
  }
}

/* For very small screens or extremely dense matrices */
@media (max-width: 576px) {

  .risk-matrix th,
  .risk-matrix td {
    padding: 0.2rem;
  }

  .impact-header .header-content .level-name,
  .likelihood-header .header-content .level-name {
    font-size: 0.7rem;
  }

  .impact-header .header-content .calculation-basis,
  .likelihood-header .header-content .calculation-basis {
    display: none;
    /* Hide score on very small screens */
  }

  .risk-cell .cell-content .calculated-value {
    font-size: 0.75rem;
  }

  .risk-cell .cell-content .risk-class-name {
    display: none;
    /* Hide risk class name on very small screens */
  }
}

.unit-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;

  label {
    color: #475569;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0px;
  }

  .unit-dropdown {
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background-color: white;
    font-size: 0.85rem;
    color: #1e293b;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;

    &:focus {
      border-color: #94a3b8;
      box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.1);
    }
  }
}