// role-management.component.scss

// Global variables for consistent styling
$primary-color: #007bff;
$secondary-color: #6c757d;
$danger-color: #dc3545;
$success-color: #28a745;
$background-color: #f5f7fb;
$card-background: #ffffff;
$border-color: #e5e7eb;
$shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
$border-radius: 6px;
$padding: 20px;
$font-family: 'Inter', sans-serif;

// Wrapper for the entire layout
.role-management-wrapper {
  font-family: $font-family;
  background-color: $background-color;
  min-height: 100vh;
  width: 100%; // Ensure the wrapper takes the full viewport width
  box-sizing: border-box;

  // Main content area (takes full width)
  .main-content {
    padding: $padding;
    width: 100%; // Take the full width of the parent
    max-width: 100%; // Remove the max-width constraint to allow full stretching
    margin: 0; // Remove centering to stretch to edges
    overflow-x: auto; // Keep horizontal scrolling for wide tables
    box-sizing: border-box;

    .header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 24px;

      h1 {
        font-size: 1.5rem;
        font-weight: 600;
        color: #1a202c;
        margin: 0;
      }

      p {
        font-size: 0.875rem;
        color: $secondary-color;
        margin: 4px 0 0;
      }

      .add-member-btn {
        background-color: $primary-color;
        color: white;
        border: none;
        padding: 8px 16px;
        border-radius: $border-radius;
        font-size: 0.875rem;
        font-weight: 500;
        cursor: pointer;
        transition: background-color 0.2s;

        &:hover {
          background-color: darken($primary-color, 10%);
        }
      }
    }

    // Role form container (for adding/editing roles)
    .role-form-container {
      background: $card-background;
      padding: $padding;
      border: 1px solid $border-color;
      border-radius: $border-radius;
      margin-bottom: 24px;
      box-shadow: $shadow;

      h2 {
        font-size: 1.25rem;
        font-weight: 600;
        color: #1a202c;
        margin-bottom: 16px;
      }

      form {
        display: flex;
        flex-direction: column;
        gap: 16px;

        .form-group {
          display: flex;
          flex-direction: column;

          label {
            font-size: 0.875rem;
            font-weight: 500;
            color: $secondary-color;
            margin-bottom: 8px;
          }

          input,
          textarea {
            padding: 8px 12px;
            border: 1px solid $border-color;
            border-radius: $border-radius;
            font-size: 0.875rem;
            transition: border-color 0.2s;

            &:focus {
              outline: none;
              border-color: $primary-color;
            }
          }

          textarea {
            resize: vertical;
            min-height: 80px;
          }

          .error-message {
            color: $danger-color;
            font-size: 0.75rem;
            margin-top: 4px;
          }
        }

        .form-actions {
          display: flex;
          gap: 12px;
          justify-content: flex-end;

          .cancel-btn,
          .submit-btn {
            padding: 8px 16px;
            border: none;
            border-radius: $border-radius;
            font-size: 0.875rem;
            font-weight: 500;
            cursor: pointer;
            transition: background-color 0.2s;
          }

          .cancel-btn {
            background-color: $secondary-color;
            color: white;

            &:hover {
              background-color: darken($secondary-color, 10%);
            }
          }

          .submit-btn {
            background-color: $primary-color;
            color: white;

            &:hover {
              background-color: darken($primary-color, 10%);
            }

            &[disabled] {
              background-color: lighten($secondary-color, 20%);
              cursor: not-allowed;
            }
          }
        }
      }
    }

    // Permissions table
    .permissions-table-container {
      background: $card-background;
      border: 1px solid $border-color;
      border-radius: $border-radius;
      box-shadow: $shadow;
      width: 100%; // Ensure the table takes the full width of its parent

      .table-header {
        border-bottom: 1px solid $border-color;
        padding: 12px 20px;

        .table-title {
          font-size: 0.875rem;
          font-weight: 500;
          color: $secondary-color;
        }

        .roles-header {
          display: flex;
          margin-top: 12px;

          .role-column {
            flex: 1;
            font-size: 0.875rem;
            font-weight: 600;
            color: #1a202c;
            padding: 8px 12px;
            text-align: center;

            &:first-child {
              flex: 2;
              text-align: left;
            }
          }
        }
      }

      .permissions-table {
        width: 100%; // Ensure the table content stretches to fit the container

        .permission-group {
          .group-header {
            background: lighten($background-color, 2%);
            padding: 12px 20px;
            font-size: 0.875rem;
            font-weight: 600;
            color: $secondary-color;
            border-bottom: 1px solid $border-color;
            text-transform: uppercase;
          }

          .permission-row {
            display: flex;
            border-bottom: 1px solid $border-color;

            .permission-name {
              flex: 2;
              padding: 12px 20px;
              font-size: 0.875rem;
              color: #1a202c;
            }

            .role-column {
              flex: 1;
              padding: 12px;
              text-align: center;

              input[type="checkbox"] {
                width: 16px;
                height: 16px;
                cursor: pointer;
                accent-color: $primary-color;
              }
            }
          }
        }
      }
    }
  }
}

// Responsive design
@media (max-width: 768px) {
  .role-management-wrapper {
    .main-content {
      padding: 16px;
    }
  }
}