/* ==========================================================================
     User Profile Component
     ========================================================================== */

// Variables
$avatar-border-width: 2px !default;
$avatar-sm-size: 36px !default;
$avatar-md-size: 42px !default;
$avatar-lg-size: 80px !default;
$status-indicator-sm: 10px !default;
$status-indicator-lg: 16px !default;

// Mixins
@mixin avatar($size) {
  position: relative;
  width: $size;
  height: $size;

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border: $avatar-border-width solid var(--bs-border-color);
  }
}

@mixin status-indicator($size) {
  position: absolute;
  right: 0;
  bottom: 0;
  width: $size;
  height: $size;
  background: var(--bs-green);
  border: 2px solid var(--bs-body-bg);
  @include border-radius(50%);
}

@mixin hover-transition {
  @include transition(all);
}

@mixin dark-gradient {
  background: linear-gradient(135deg, #2e2e2e 0%, #1a1a1a 100%);
}

.user-profile {
  position: relative;
  font-size: 0.95rem;
  cursor: pointer;
  &:hover {
    color: var(--sidebar-nav-link-active-color);
    background-color: var(--submenu-hover-bg);
    @include border-radius($border-radius-lg);
  }

  .dropdown-toggle {
    cursor: pointer;
    @include border-radius($border-radius-lg);
    @include hover-transition ();

    &:hover {
      background-color: var(--bs-secondary-bg);
    }

    &::after {
      display: none; // Hide default dropdown arrow
    }
  }

  .avatar {
    @include avatar($avatar-sm-size);

    .online-indicator {
      @include status-indicator($status-indicator-sm);
    }
  }

  .dropdown-menu {
    width: 240px;
    padding: 0.5rem;
    margin-top: 0.5rem;
    border: 1px solid var(--bs-border-color);
    @include border-radius($border-radius-lg);
    box-shadow: 0 4px 12px rgb(0, 0, 0, 0.08);


    .user-info {
      margin-bottom: 0.5rem;
      border-bottom: 1px solid var(--bs-border-color);

      .avatar {
        @include avatar($avatar-md-size);
      }

      h6 {
        font-size: 0.9375rem;
        font-weight: 600;
      }
    }

    .dropdown-item {
      height: 2.35rem;
      padding: 0.5rem 0.25rem;
      font-size: 0.875rem;
      @include border-radius($border-radius);

      i {
        width: 1.5rem;
        font-size: 1.25rem;
        opacity: 0.8;
      }

      &:hover {
        background-color: var(--bs-secondary-bg);
      }

      &.text-danger {
        margin-top: 0.25rem;
        background-color: var(--bs-danger-bg-subtle);
        i {
          color: inherit;
        }

        &:hover {
          color: #fff !important;
          background-color: var(--bs-danger);
        }
      }
      &.btn-upgrade {
        color: var(--bs-primary);
        border: 1px solid var(--bs-primary);
        &:hover {
          color: var(--bs-primary);
          background: var(--bs-primary-bg-subtle);
        }
      }
    }

    .notification-badge {
      padding: 0.125rem 0.5rem;
      font-size: 0.75rem;
      color: var(--bs-white);
      background-color: var(--bs-danger);
      @include border-radius($border-radius-pill);
    }

    .dropdown-divider {
      margin: 0.5rem 0;
      opacity: 0.1;
    }
  }
}


/* User Profile Offcanvas */
.user-profile-offcanvas {
  display: flex;
  flex-direction: column;
  width: 320px;
  height: 100%;
  background: var(--bs-body-bg);
  border: 0;

  /* Top Section */
  .offcanvas-top {
    position: relative;
    background: var(--bs-body-bg);
    border-bottom: 1px dashed var(--bs-border-color);

    .btn-close-custom {
      position: absolute;
      top: 10px;
      left: 10px;
      width: 32px;
      height: 32px;
      color: var(--bs-body-color);
      background: var(--bs-tertiary-bg);
      border: 0;
      @include border-radius(50%);
      @include hover-transition ();

      i {
        font-size: 20px;
        @include transition(transform);
      }

      &:hover {
        color: var(--bs-primary);
        background: var(--bs-primary-bg-subtle);

        i {
          transform: rotate(90deg);
        }
      }
    }

    .user-profile-header {
      padding-bottom: 0.75rem;

      .user-profile-cover {
        height: 80px;
        background: var(--bs-primary-bg-subtle);
      }

      .user-profile-avatar {
        padding-bottom: 1rem;
        margin-top: -40px;

        .avatar-wrapper {
          @include avatar($avatar-lg-size);
          position: relative;
          margin: 0 auto;

          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            border-width: 4px;
            box-shadow: 0 2px 8px rgb(var(--bs-body-color-rgb), 0.1);
          }

          .status-badge {
            @include status-indicator($status-indicator-lg);
            box-shadow: 0 0 0 2px rgb(34, 197, 94, 0.2);

            &.online {
              background: var(--bs-green);
            }
          }
        }
      }

      .user-profile-info {
        .user-name {
          margin-bottom: 0.25rem;
          font-size: 1.25rem;
          font-weight: 600;
          color: var(--bs-emphasis-color);
        }

        .user-email {
          margin-bottom: 0.25rem;
          font-size: 0.875rem;
          color: var(--bs-secondary-color);
        }
      }
    }
  }

  /* Content Section */
  .offcanvas-content {
    flex: 1;
    padding: 0.75rem 1rem;
    overflow-y: auto;
  }

  /* Bottom Section */
  .offcanvas-bottom {
    padding: 0.75rem 1rem;
    background: var(--bs-body-bg);
    border-top: 1px dashed var(--bs-border-color);

    .upgrade-pro-card {
      @include dark-gradient ();
      position: relative;
      padding: 1rem 1.5rem;
      margin-bottom: 1rem;
      overflow: hidden;
      color: var(--bs-white);
      @include border-radius(1rem);

      &::before {
        position: absolute;
        top: 0;
        right: 0;
        width: 160px;
        height: 160px;
        content: '';
        background: radial-gradient(circle, rgb(255, 255, 255, 0.1) 0%, transparent 70%);
        transform: translate(30%, -30%);
      }

      .pro-badge {
        display: inline-flex;
        align-items: center;
        padding: 0.35rem 0.75rem;
        margin-bottom: 0.5rem;
        background: rgb(255, 255, 255, 0.1);
        @include border-radius(1.25rem);

        i {
          margin-right: 0.5rem;
          color: #ffd700;
        }

        span {
          font-size: 0.875rem;
          font-weight: 600;
        }
      }

      h3 {
        margin-bottom: 0.5rem;
        font-size: 1.25rem;
        font-weight: 600;
      }

      p {
        margin-bottom: 0.5rem;
        font-size: 0.875rem;
        opacity: 0.8;
      }

      .feature-list {
        padding: 0;
        margin: 0 0 1.5rem;
        list-style: none;

        li {
          display: flex;
          align-items: center;
          margin-bottom: 0.25rem;
          font-size: 0.875rem;
          opacity: 0.9;

          i {
            margin-right: 0.5rem;
            color: #22c55e;
          }
        }
      }

      .btn-upgrade {
        width: 100%;
        padding: 0.5rem 1rem;
        font-weight: 600;
        color: #1a1a1a;
        background: #ffd700;
        border: 0;
        @include border-radius(0.5rem);
        @include hover-transition ();

        i {
          margin-left: 0.5rem;
          @include transition(transform);
        }

        &:hover {
          background: #ffe44d;
          transform: translateY(-1px);

          i {
            transform: translateX(2px);
          }
        }
      }
    }

    .logout-section {
      .btn-logout {
        width: 100%;
        padding: 0.25rem 1rem;
        font-size: 0.9375rem;
        font-weight: 500;
        color: var(--bs-danger);
        text-decoration: none;
        background: var(--bs-danger-bg-subtle);
        border: 0;
        @include border-radius(0.5rem);
        @include hover-transition ();

        i {
          margin-right: 0.75rem;
          font-size: 1.25rem;
          @include transition(transform);
        }

        &:hover {
          color: #fff;
          background: var(--bs-danger);

          i {
            transform: translateX(-2px);
          }
        }
      }
    }
  }
}

/* Dark mode adjustments */
[data-bs-theme='dark']{
  .user-profile {
    .avatar img {
      border-color: var(--bs-border-color);
    }

    .online-indicator {
      border-color: var(--bs-body-bg);
    }
  }

  .user-profile-offcanvas {
    .upgrade-pro-card {
      background: linear-gradient(135deg, #3a3a3a 0%, #2a2a2a 100%);
    }
  }
}

@media screen and (max-width: 768px) {
  .user-profile {
    .dropdown-menu.show {
      transform: translate3d(4px, -44px, 0) !important;
    }
  }
}
