// 全局变量定义
$primary-color: #165DFF;
$primary-dark: #0E42CB;
$secondary-color: #4E5BA6;
$success-color: #00B42A;
$warning-color: #FF7D00;
$danger-color: #F53F3F;
$text-primary: #1D2129;
$text-secondary: #4E5969;
$text-tertiary: #86909C;
$border-color: #E5E6EB;
$background-primary: #FFFFFF;
$background-secondary: #F2F3F5;
$background-tertiary: #F7F8FA;
$shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
$shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
$shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.1);
$border-radius: 8px;
$transition: all 0.3s ease;

// 顶部导航栏
.top-navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 72px; // 扩大导航栏高度
  background-color: $background-primary;
  border-bottom: 1px solid $border-color;
  box-shadow: $shadow-md; // 增加阴影效果
  position: sticky;
  top: 0;
  z-index: 1000;

  .navbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
  }

  .menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: $text-primary;
    padding: 8px;
    transition: $transition;

    &:hover {
      color: $primary-color;
    }
  }

  .app-title {
    font-size: 24px; // 放大标题字体
    font-weight: 700;
    color: $text-primary;
  }

  .navbar-center {
    flex: 1;
    max-width: 500px;
    margin: 0 20px;
  }

  .search-container {
    display: flex;
    align-items: center;
    background-color: $background-tertiary;
    border-radius: $border-radius;
    padding: 6px 12px;
    border: 1px solid $border-color;

    .search-input {
      flex: 1;
      background: none;
      border: none;
      outline: none;
      padding: 6px 8px;
      font-size: 14px;
      color: $text-primary;

      &::placeholder {
        color: $text-tertiary;
      }
    }

    .search-button {
      background: none;
      border: none;
      cursor: pointer;
      color: $text-secondary;
      padding: 4px;
      transition: $transition;

      &:hover {
        color: $primary-color;
      }
    }
  }

  .navbar-right {
    display: flex;
    align-items: center;
    gap: 16px;

    .notification-btn {
      position: relative;
      background: none;
      border: none;
      cursor: pointer;
      color: $text-secondary;
      padding: 8px;
      border-radius: 8px;
      transition: all 0.2s ease-in-out;
      white-space: nowrap;

      &:hover {
        color: $primary-color;
        background-color: rgba(22, 93, 255, 0.08);
        transform: translateY(-1px);
      }

      &:active {
        transform: translateY(0);
        background-color: rgba(22, 93, 255, 0.12);
      }

      &:focus {
        outline: 2px solid rgba(22, 93, 255, 0.3);
        outline-offset: 2px;
      }

      .notification-badge {
        position: absolute;
        top: 0;
        right: 0;
        background-color: $danger-color;
        color: white;
        font-size: 12px;
        padding: 2px 6px;
        border-radius: 10px;
        min-width: 18px;
        text-align: center;
        box-shadow: 0 2px 4px rgba(245, 63, 63, 0.3);
      }
    }

    .user-profile {
      display: flex;
      align-items: center;
      gap: 8px;

      .user-avatar {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        object-fit: cover;
      }

      .user-name {
        font-size: 14px;
        font-weight: 500;
        color: $text-primary;
      }
    }
  }
}

// 主要内容区
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

// 左侧侧边栏
.sidebar {
  width: 220px;
  background-color: $background-primary;
  border-right: 1px solid $border-color;
  display: flex;
  flex-direction: column;
  transition: $transition;

  .sidebar-nav {
    flex: 1;
    padding: 16px 0;

    .nav-item {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 12px 24px;
      color: $text-secondary;
      text-decoration: none;
      border-left: 3px solid transparent;
      transition: $transition;
      position: relative;

      &:hover {
        background-color: $background-tertiary;
        color: $primary-color;
        transform: translateX(2px);
      }

      &.active {
        color: white;
        background-color: $primary-color;
        border-left-color: $primary-color;
        font-weight: 600;
        box-shadow: 0 4px 8px color-mix(in srgb, $primary-color 20%, transparent);
        transform: translateX(2px);

        svg {
          stroke-width: 2.5;
        }
      }
    }
  }

  .sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid $border-color;

    .storage-info {
      margin-bottom: 16px;
      font-size: 12px;
      color: $text-tertiary;
    }

    .logout-btn {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 12px;
      background: none;
      border: 1px solid $border-color;
      border-radius: $border-radius;
      color: $text-secondary;
      cursor: pointer;
      font-size: 14px;
      transition: $transition;

      &:hover {
        background-color: $background-tertiary;
        border-color: $danger-color;
        color: $danger-color;
      }

      &:active {
        transform: scale(0.98);
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
      }
    }
  }

  &.collapsed {
    width: 0;
    overflow: hidden;
  }
}

// 中间内容区
.content-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  transition: $transition;

  &.expanded {
    width: 100%;
  }
}

// 全局按钮点击反馈样式
button,
.btn-primary,
.nav-item,
.view-all-link,
.logout-btn {
  &:active {
    transform: scale(0.98);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.1s ease;
  }
}

.btn-primary {
  &:active {
    background-color: $primary-dark;
    transform: scale(0.98);
    box-shadow: 0 2px 4px color-mix(in srgb, $primary-color 40%, transparent);
  }
}

.search-button,
.menu-toggle,
.notification-btn {
  &:active {
    transform: scale(0.95);
  }
}

// 通知按钮样式增强
.notification-btn {
  &:active {
    transform: scale(0.95);
    box-shadow: 0 0 0 2px color-mix(in srgb, $primary-color 20%, transparent);
  }
  
  // 确保通知按钮有足够的z-index，以免被下拉菜单遮挡
  position: relative;
  z-index: 1001;
}

// 通知下拉菜单
.notification-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  width: 360px;
  background-color: $background-primary;
  border-radius: $border-radius;
  box-shadow: $shadow-lg;
  z-index: 1000;
  border: 1px solid $border-color;
  overflow: hidden;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.notification-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid $border-color;
  background-color: $background-tertiary;

  h3 {
    font-size: 16px;
    font-weight: 600;
    color: $text-primary;
    margin: 0;
  }

  .close-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: $text-secondary;
    padding: 4px;
    transition: $transition;

    &:hover {
      color: $text-primary;
    }

    &:active {
      transform: scale(0.9);
    }
  }
}

.notification-list {
  max-height: 400px;
  overflow-y: auto;

  .notification-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid $border-color;
    transition: $transition;

    &:hover {
      background-color: $background-tertiary;
    }

    &:last-child {
      border-bottom: none;
    }

    .notification-icon {
      flex-shrink: 0;
      width: 32px;
      height: 32px;
      border-radius: 50%;
      background-color: color-mix(in srgb, $primary-color 10%, transparent);
      display: flex;
      align-items: center;
      justify-content: center;
      color: $primary-color;
      margin-top: 2px;
    }

    .notification-content {
      flex: 1;

      p {
        margin: 0;
        font-size: 14px;
        color: $text-secondary;
        line-height: 1.4;
      }
    }
  }
}

.notification-footer {
  padding: 12px 20px;
  text-align: center;
  background-color: $background-tertiary;
  border-top: 1px solid $border-color;

  .view-all {
    color: $primary-color;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: $transition;

    &:hover {
      text-decoration: underline;
      color: $primary-dark;
    }
  }
}

// 响应式设计
@media (max-width: 1024px) {
  .sidebar {
    width: 200px;
  }
}

@media (max-width: 768px) {
  .top-navbar {
    padding: 0 16px;

    .menu-toggle {
      display: block;
    }

    .app-title {
      font-size: 18px;
    }

    .navbar-center {
      display: none;
    }
  }

  .sidebar {
    position: fixed;
    top: 64px;
    left: 0;
    height: calc(100vh - 64px);
    z-index: 900;
    transform: translateX(0);

    &.collapsed {
      transform: translateX(-100%);
    }
  }

  .content-wrapper {
    padding: 16px;
    margin-left: 0;
  }
}

@media (max-width: 480px) {
  .top-navbar {
    height: 56px;

    .navbar-right {
      gap: 12px;
    }
  }

  .sidebar {
    top: 56px;
    height: calc(100vh - 56px);
  }

  .content-wrapper {
    padding: 12px;
  }
}