// Isolate popup from header colors while respecting light/dark mode
.overlay, .overlay * {
  color: var(--text-primary) !important;
  
  mat-icon {
    color: var(--text-primary) !important;
  }
}

// Specific element overrides
.overlay {
  .popup-content {
    color: var(--text-primary) !important;
  }
  
  .search-input {
    color: var(--text-primary) !important;
    
    &::placeholder {
      color: #999 !important;
    }
  }
  
  .search-icon,
  .clear-icon,
  .close-btn mat-icon {
    color: var(--text-primary) !important;
  }
  
  .view-btn mat-icon {
    color: var(--text-primary) !important;
    
    &.active mat-icon {
      color: #fff !important;
    }
  }
  
  .welcome-title,
  .card-title,
  .card-title-large,
  .list-title {
    color: var(--text-primary) !important;
  }
}
.modulebtn {
  background: none;
  border: 0;
  cursor: pointer;
  align-items: center;
  display: flex;
}

.moduleicon {
  width: calc(var(--button-height-s) * 1px) !important;
  height: calc(var(--button-height-s) * 1px) !important;
  font-size: calc(var(--button-height-s) * 1px) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-brandPrimary);

  &:hover {
    border-radius: calc(var(--size-radius-s) * 1px) !important;
    background-color: var(--bg-subtle) !important;
    color: var(--action-primary-default) !important;
    transform: translateY(-1px);
  }

  &:disabled,
  &.disabled {
    cursor: not-allowed;
    pointer-events: none;
    background-color: transparent !important;
    color: var(--text-disabled) !important;
  }
}

/* Overlay for the popup */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  isolation: isolate;
}

.popup-content {
  background-color: var(--mat-sys-background, #ffffff);
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0px 8px 24px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  width: 1298px;
  max-width: 1400px;
  height: auto;
  max-height: 95vh;
  position: relative;
  z-index: 1001;
  overflow: hidden;
}
.top-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  width: 100%;
  position: relative;
}

.welcome-section {
  justify-self: start;
  min-width: 0;
}
.welcome-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 2px 0;
  color: var(--text-primary, #1f1f1f);
  line-height: 1.2;
  white-space: nowrap;
}

.welcome-subtitle {
  font-size: 12px;
  color: var(--theme-text-secondary, #666);
  margin: 0;
  font-weight: 400;
  white-space: nowrap;
}
.search-container {
  position: relative;
  width: 360px;
  justify-self: center;
  
  .clear-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    font-size: 20px;
    width: 20px;
    height: 20px;
    color: #5f6368;
    transition: color 0.2s;
    z-index: 10;
    
    &:hover {
      color: #202124;
    }
  }
}

.search-input {
  padding-right: 40px;
}
.right-section {
  display: flex;
  align-items: center;
  gap: 4px;
}
.close-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: #818181;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
  flex-shrink: 0;
  margin-left: 280px;

  &:hover {
    color: #333;
  }

  mat-icon {
    font-size: 24px;
    width: 24px;
    height: 24px;
  }
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 20px;
  width: 20px;
  height: 20px;
  z-index: 10;
}
.search-input {
  width: 100%;
  padding: 12px 40px 12px 40px;
  border-radius: 24px;
  font-size: 14px;
  outline: none;
  transition: all 0.2s ease;
  background-color: #f9f6fe;
  color: var(--text-primary, #1f1f1f);
  box-shadow: 0px 2px 4px 0px #00000033;


  &::placeholder {
    color: #999;
  }

  &:focus {
    background-color: #fff;
    border:1px solid var(--action-primary-default);
    box-shadow: 0 0 0 3px rgba(103, 58, 183, 0.1);
  }
}
.view-toggle {
  display: flex;
  gap: 2px;
  // background-color: #f5f5f5;
  border-radius: 8px;
  padding: 4px;
  flex-shrink: 0;
}
.view-btn {
  height:40px;
  width:48px;
  background: none;
  border: 0.5px solid #818181;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  color: #666;
  min-width: 44px;
  box-shadow: -1px 2px 2px 0px #00000026;
  margin-left:8px;

  mat-icon {
    font-size: 21px;
    width: 22px;
    height: 22px;
    color: #3D3D3D;
  }

  &:hover {
    background-color: #e8e8e8;
    color: #333;
  }

  &.active {
    background-color: var(--theme-primary,var(--action-primary-default));
    color: #fff;
    border:none;
    mat-icon {
      color:#fff;
    }
    
  }

  &:focus {
    border: 2px solid var(--theme-primary,var(--action-primary-default)) !important;
    outline-offset: 2px;
  }
}
.scrollable {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  padding-right: 8px;
  min-height: 480px;

  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
  }

  &::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;

    &:hover {
      background: #555;
    }
  }
}

/* Grid View */
.modules-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
  padding: 4px;
  width: 100%;
}

.module-card {
  background-color: var(--mat-sys-background, #fff);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(187, 187, 187, 0.08);
  display: flex;
  flex-direction: column;
  border: 1px solid #1A1A1A26;
  height: 202px;
  width: 284px;

  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  }

  &:focus {
     border-color: var(--theme-primary, var(--action-primary-default)) !important;
     background-color: #fff;
    box-shadow: 0 0 0 3px rgba(103, 58, 183, 0.1);
    outline: none !important;
  }
}

.card-image {
  width: 100%;
  height: 108px;
  overflow: hidden;
  background-color: #f0f0f0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;

  &.placeholder {
    background: linear-gradient(135deg, #e0e0e0 0%, #f5f5f5 100%);

    &::after {
      content: '';
      position: absolute;
      width: 60px;
      height: 60px;
    }
  }

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
    display: block;
  }
}

.module-card:hover .card-image img {
  transform: scale(1.05);
}

.card-content {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  height:100px;
  padding-left: 12px;
  padding-top: 10px;
  padding-bottom: 10px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 0px 0;
  color: var(--text-primary, #1f1f1f);
  line-height: 1.3;
}

.card-description {
  font-size: 12px;
  color: var(--text-primary);
  line-height: 1.4;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  // -webkit-box-orient: vertical;
  // overflow: hidden;
  text-overflow: ellipsis;
}

/* List View */
.list-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px;
  width: 100%;
}

.list-item {
  background-color: var(--mat-sys-background, #fff);
  border-radius: 10px;
  padding: 16px 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  gap: 16px;
  border: 2px solid transparent!important;

  &:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    transform: translateX(4px);
  }

  &:focus {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    transform: translateX(4px);
  }
}

.list-icon {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 8px;
  background: linear-gradient(135deg, #e0e0e0 0%, #f5f5f5 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

.list-content {
  flex: 1;
  min-width: 0;
}

.list-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px 0;
  color: var(--text-primary, #1f1f1f);
  line-height: 1.3;
}

.list-description {
  font-size: 13px;
  color: var(--theme-text-secondary, #666);
  line-height: 1.4;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-arrow {
  color: #999;
  display: flex;
  align-items: center;
  transition: transform 0.2s ease;

  mat-icon {
    font-size: 24px;
    width: 24px;
    height: 24px;
  }
}

.list-item:hover .list-arrow {
  transform: translateX(4px);
  color: var(--theme-primary, #673ab7);
}

/* Card View (Large Cards) */
.card-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 16px;
  padding: 4px;
  width: 100%;
}

/* NEW: Style the clickable card in the card-grid so it has a 1px black border,
   image above and the text centered below the image. */
.card-grid>div {
  /* ensures we target the element you render in template (the anonymous div around image+content) */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 12px;
  border: 1px solid #1A1A1A26;
  border-radius: 10px;
  background-color: var(--mat-sys-background, #fff);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  /* keep it accessible for keyboard focus */
  outline: none;
}

.card-grid>div:focus {
  box-shadow: 0 0 0 3px rgba(103, 58, 183, 0.08);
  border-color: #000;
}

.module-card.large {
  height: auto;
}

/* keep the existing image area but center the svg/img nicely */
.card-image-large {
  width: 100%;
  height: 120px;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}

.card-image-large img {
  width: 85px;
  height: 86px;
  object-fit: contain;
  /* contain keeps icons from being cropped */
  transition: transform 0.3s ease;
  display: block;
}

/* hover zoom but confined */
.card-grid>div:hover .card-image-large img {
  transform: scale(1.05);
}

.card-content-large {
  padding: 6px 8px 0 8px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.card-title-large {
  font-size: 14px;
  font-weight: 600;
  margin: 6px 0 0 0;
  color: var(--text-primary, #1f1f1f);
  line-height: 1.3;
  white-space: normal;
  word-break: break-word;
}

/* If you want a smaller description under the title, this will keep it centered */
.card-description-large {
  font-size: 11px;
  color: var(--theme-text-secondary, #666);
  line-height: 1.4;
  margin: 6px 0 0 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* No Results State */
.no-results {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--theme-text-secondary, #666);
  min-height: 400px;

  .no-results-icon {
    font-size: 64px;
    width: 64px;
    height: 64px;
    color: #ccc;
    margin-bottom: 16px;
  }

  h3 {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: var(--text-primary, #1f1f1f);
  }

  p {
    font-size: 14px;
    margin: 0;
    color: var(--theme-text-secondary, #999);
  }
}

/* Responsive Design */
@media (min-width: 1201px) {
  .modules-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .card-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (max-width: 1200px) {
  .modules-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .card-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .modules-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .popup-content {
    width: 90vw;
  }
}

@media (max-width: 768px) {
  .popup-content {
    padding: 20px;
    width: 95vw;
  }

  .top-bar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
    align-items: stretch;
  }

  .welcome-section {
    width: 100%;
    text-align: center;
  }

  .welcome-title {
    font-size: 20px;
  }

  .welcome-subtitle {
    font-size: 12px;
  }

  .search-container {
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
  }

  .right-section {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
  }

  .close-btn {
  position: static;
}

  .modules-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }

  .card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }

  .card-image {
    height: 140px;
  }

  .card-image-large {
    height: 100px;
  }

  .card-content {
    padding: 14px;
  }

  .card-content-large {
    padding: 10px;
  }

  .card-title {
    font-size: 15px;
  }

  .card-title-large {
    font-size: 13px;
  }

  .card-description {
    font-size: 11px;
  }

  .card-description-large {
    font-size: 10px;
  }

  .list-icon {
    width: 48px;
    height: 48px;
    min-width: 48px;
  }

  .list-item {
    padding: 14px 16px;
  }

  .list-title {
    font-size: 15px;
  }

  .list-description {
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .popup-content {
    padding: 16px;
  }

  .top-bar {
    gap: 10px;
  }

  .welcome-title {
    font-size: 18px;
  }

  .welcome-subtitle {
    font-size: 11px;
  }

  .search-container {
    width: 100%;
    max-width: 100%;
  }

  .modules-grid {
    grid-template-columns: 1fr;
  }

  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .view-toggle {
    padding: 3px;
    gap: 2px;
  }

  .view-btn {
    padding: 6px 10px;

    mat-icon {
      font-size: 18px;
      width: 18px;
      height: 18px;
    }
  }
}
.title-with-icon {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.module-title-icon {
  width: 20px;
  height: 20px;
  filter: brightness(0) saturate(100%) invert(24%) sepia(0%) saturate(0%) hue-rotate(0deg) brightness(94%) contrast(88%);
  flex-shrink: 0;
}

.list-title-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.module-list-title-icon {
  width: 24px;
  height: 24px;
  filter: brightness(0) saturate(100%) invert(24%) sepia(0%) saturate(0%) hue-rotate(0deg) brightness(94%) contrast(88%);
  flex-shrink: 0;
}
/* Responsive Design */
@media (min-width: 1201px) {
  .modules-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .card-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (max-width: 1200px) {
  .modules-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .card-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .close-btn {
    margin-left: 150px;
  }
}

@media (max-width: 900px) {
  .modules-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .popup-content {
    width: 90vw;
    padding: 24px;
  }

  .top-bar {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .welcome-section {
    text-align: center;
    justify-self: center;
  }

  .search-container {
    width: 100%;
    max-width: 400px;
    justify-self: center;
  }

  .right-section {
    justify-content: center;
    justify-self: center;
    width: 100%;
  }

  .close-btn {
    margin-left: 8px;
  }
}

@media (max-width: 768px) {
  .popup-content {
    padding: 20px;
    width: 95vw;
  }

  .top-bar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
    align-items: stretch;
  }

  .welcome-section {
    width: 100%;
    text-align: center;
  }

  .welcome-title {
    font-size: 18px;
  }

  .welcome-subtitle {
    font-size: 11px;
  }

  .search-container {
    width: 100%;
    max-width: 100%;
    margin: 0;
  }

  .right-section {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    width: 100%;
  }

  .view-toggle {
    flex: 1;
    justify-content: center;
    max-width: 200px;
  }

  .close-btn {
    position: static;
    margin-left: 0;
  }

  .modules-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }

  .card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }

  .module-card {
    width: 100%;
    height: auto;
    min-height: 200px;
  }

  .card-image {
    height: 120px;
  }

  .card-image-large {
    height: 90px;
  }

  .card-image-large img {
    width: 70px;
    height: 70px;
  }

  .card-content {
    padding: 12px;
  }

  .card-content-large {
    padding: 8px;
  }

  .card-title {
    font-size: 14px;
  }

  .card-title-large {
    font-size: 12px;
  }

  .card-description {
    font-size: 11px;
    -webkit-line-clamp: 2;
  }

  .module-title-icon {
    width: 16px;
    height: 16px;
  }

  .list-icon {
    width: 48px;
    height: 48px;
    min-width: 48px;
  }

  .list-item {
    padding: 12px 16px;
  }

  .list-title {
    font-size: 14px;
  }

  .list-description {
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .popup-content {
    padding: 16px;
    max-height: 90vh;
  }

  .top-bar {
    gap: 10px;
    margin-bottom: 16px;
  }

  .welcome-title {
    font-size: 16px;
  }

  .welcome-subtitle {
    font-size: 10px;
  }

  .search-container {
    width: 100%;
  }

  .search-input {
    padding: 10px 36px 10px 36px;
    font-size: 13px;
  }

  .search-icon {
    font-size: 18px;
    width: 18px;
    height: 18px;
    left: 10px;
  }

  .clear-icon {
    font-size: 18px;
    width: 18px;
    height: 18px;
    right: 10px;
  }

  .right-section {
    flex-direction: row;
    gap: 6px;
  }

  .view-toggle {
    padding: 3px;
    gap: 2px;
    flex: 1;
    max-width: 150px;
  }

  .view-btn {
    padding: 6px 8px;
    min-width: 36px;

    mat-icon {
      font-size: 18px;
      width: 18px;
      height: 18px;
    }
  }

  .close-btn {
    padding: 2px;
    
    mat-icon {
      font-size: 20px;
      width: 20px;
      height: 20px;
    }
  }

  .modules-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .module-card {
    width: 100%;
    height: auto;
  }

  .card-image {
    height: 140px;
  }

  .card-image-large {
    height: 80px;
  }

  .card-image-large img {
    width: 60px;
    height: 60px;
  }

  .card-title {
    font-size: 13px;
  }

  .card-title-large {
    font-size: 11px;
  }

  .card-description {
    font-size: 10px;
  }

  .module-title-icon {
    width: 14px;
    height: 14px;
  }

  .title-with-icon {
    gap: 6px;
  }

  .scrollable {
    min-height: 350px;
  }
}

@media (max-width: 360px) {
  .popup-content {
    padding: 12px;
  }

  .welcome-title {
    font-size: 14px;
  }

  .welcome-subtitle {
    font-size: 9px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .view-btn {
    padding: 5px 6px;
    min-width: 32px;
  }
}