// 布局樣式

// 主要布局容器
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
  
  // 側邊欄
  .layout-sidebar {
    width: 240px;
    background-color: $sidebar-bg;
    color: $sidebar-text-color;
    display: flex;
    flex-direction: column;
    transition: width $transition-duration-base;
    z-index: $z-index-top;
    
    &.collapsed {
      width: 64px;
    }
    
    @include respond-to(md) {
      position: fixed;
      top: 0;
      left: 0;
      bottom: 0;
      transform: translateX(-100%);
      
      &.mobile-show {
        transform: translateX(0);
      }
    }
    
    .sidebar-header {
      padding: $spacing-lg;
      border-bottom: 1px solid rgba(255, 255, 255, 0.1);
      @include flex-center;
      
      .logo {
        display: flex;
        align-items: center;
        color: white;
        font-size: $font-size-large;
        font-weight: bold;
        text-decoration: none;
        
        .logo-icon {
          width: 32px;
          height: 32px;
          margin-right: $spacing-sm;
          background: linear-gradient(45deg, $primary-color, lighten($primary-color, 10%));
          border-radius: $border-radius-base;
          @include flex-center;
          color: white;
        }
        
        .logo-text {
          transition: opacity $transition-duration-base;
          
          .collapsed & {
            opacity: 0;
            width: 0;
            overflow: hidden;
          }
        }
      }
    }
    
    .sidebar-menu {
      flex: 1;
      padding: $spacing-lg 0;
      overflow-y: auto;
      @include custom-scrollbar(rgba(255, 255, 255, 0.3), transparent, 4px);
      
      .menu-item {
        display: block;
        padding: $spacing-md $spacing-lg;
        color: $sidebar-text-color;
        text-decoration: none;
        transition: all $transition-duration-fast;
        position: relative;
        
        &:hover {
          background-color: rgba(255, 255, 255, 0.1);
          color: white;
        }
        
        &.active {
          background-color: rgba($primary-color, 0.2);
          color: $primary-color;
          
          &::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 3px;
            background-color: $primary-color;
          }
        }
        
        .menu-icon {
          width: 20px;
          margin-right: $spacing-sm;
          text-align: center;
          transition: margin-right $transition-duration-base;
          
          .collapsed & {
            margin-right: 0;
          }
        }
        
        .menu-text {
          transition: opacity $transition-duration-base;
          
          .collapsed & {
            opacity: 0;
            width: 0;
            overflow: hidden;
          }
        }
      }
    }
    
    .sidebar-footer {
      padding: $spacing-lg;
      border-top: 1px solid rgba(255, 255, 255, 0.1);
      
      .collapse-toggle {
        width: 100%;
        padding: $spacing-sm;
        background: transparent;
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: $border-radius-base;
        color: $sidebar-text-color;
        cursor: pointer;
        transition: all $transition-duration-fast;
        
        &:hover {
          background-color: rgba(255, 255, 255, 0.1);
          border-color: rgba(255, 255, 255, 0.3);
        }
      }
    }
  }
  
  // 主要內容區
  .layout-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: $bg-color-page;
    
    // 頂部導航欄
    .layout-header {
      height: 60px;
      background-color: $header-bg;
      border-bottom: 1px solid $border-color-lighter;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
      @include flex-between;
      padding: 0 $spacing-lg;
      z-index: $z-index-normal;
      
      @include respond-to(md) {
        padding: 0 $spacing-md;
      }
      
      .header-left {
        display: flex;
        align-items: center;
        
        .menu-toggle {
          display: none;
          padding: $spacing-sm;
          background: transparent;
          border: none;
          cursor: pointer;
          margin-right: $spacing-md;
          
          @include respond-to(md) {
            display: block;
          }
        }
        
        .breadcrumb {
          display: flex;
          align-items: center;
          font-size: $font-size-base;
          color: $text-color-secondary;
          
          .breadcrumb-item {
            &:not(:last-child)::after {
              content: '/';
              margin: 0 $spacing-sm;
              color: $text-color-placeholder;
            }
            
            &:last-child {
              color: $text-color-primary;
              font-weight: 500;
            }
          }
        }
      }
      
      .header-right {
        display: flex;
        align-items: center;
        gap: $spacing-md;
        
        .notification-bell {
          position: relative;
          cursor: pointer;
          padding: $spacing-sm;
          border-radius: $border-radius-base;
          transition: background-color $transition-duration-fast;
          
          &:hover {
            background-color: $bg-color-light;
          }
          
          .badge {
            position: absolute;
            top: 2px;
            right: 2px;
            width: 8px;
            height: 8px;
            background-color: $danger-color;
            border-radius: 50%;
          }
        }
        
        .user-avatar {
          cursor: pointer;
          
          .avatar-button {
            display: flex;
            align-items: center;
            padding: $spacing-sm;
            border-radius: $border-radius-base;
            transition: background-color $transition-duration-fast;
            
            &:hover {
              background-color: $bg-color-light;
            }
            
            .avatar {
              width: 32px;
              height: 32px;
              border-radius: 50%;
              background: linear-gradient(45deg, $primary-color, lighten($primary-color, 10%));
              @include flex-center;
              color: white;
              font-weight: bold;
              margin-right: $spacing-sm;
              
              @include respond-to(sm) {
                margin-right: 0;
              }
            }
            
            .user-info {
              @include respond-to(sm) {
                display: none;
              }
              
              .user-name {
                font-size: $font-size-base;
                font-weight: 500;
                color: $text-color-primary;
                line-height: 1.2;
              }
              
              .user-role {
                font-size: $font-size-small;
                color: $text-color-secondary;
                line-height: 1.2;
              }
            }
          }
        }
      }
    }
    
    // 內容區域
    .layout-content {
      flex: 1;
      overflow: hidden;
      position: relative;
      
      .content-wrapper {
        height: 100%;
        overflow: auto;
        padding: $spacing-lg;
        
        @include respond-to(md) {
          padding: $spacing-md;
        }
        
        @include respond-to(sm) {
          padding: $spacing-sm;
        }
      }
    }
  }
}

// 移動設備遮罩
.mobile-mask {
  display: none;
  
  @include respond-to(md) {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: $z-index-top - 1;
    opacity: 0;
    visibility: hidden;
    transition: all $transition-duration-base;
    
    &.show {
      opacity: 1;
      visibility: visible;
    }
  }
}

// 登入頁面布局
.login-layout {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  @include flex-center;
  padding: $spacing-lg;
  
  .login-container {
    width: 100%;
    max-width: 400px;
    background: white;
    border-radius: $border-radius-base * 2;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    
    .login-header {
      background: linear-gradient(45deg, $primary-color, lighten($primary-color, 10%));
      padding: $spacing-xxl;
      text-align: center;
      color: white;
      
      .login-logo {
        width: 64px;
        height: 64px;
        margin: 0 auto $spacing-lg;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 50%;
        @include flex-center;
        font-size: $font-size-extra-large;
        font-weight: bold;
      }
      
      .login-title {
        font-size: $font-size-extra-large;
        font-weight: bold;
        margin-bottom: $spacing-sm;
      }
      
      .login-subtitle {
        font-size: $font-size-base;
        opacity: 0.9;
      }
    }
    
    .login-body {
      padding: $spacing-xxl;
    }
    
    .login-footer {
      padding: $spacing-lg $spacing-xxl;
      background-color: $bg-color-light;
      text-align: center;
      color: $text-color-secondary;
      font-size: $font-size-small;
    }
  }
}

// 頁面標題區域
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: $spacing-lg;
  padding-bottom: $spacing-md;
  border-bottom: 1px solid $border-color-lighter;
  
  @include respond-to(sm) {
    flex-direction: column;
    align-items: flex-start;
    gap: $spacing-md;
  }
  
  .page-title {
    font-size: $font-size-extra-large;
    font-weight: bold;
    color: $text-color-primary;
    margin: 0;
  }
  
  .page-actions {
    display: flex;
    gap: $spacing-sm;
  }
}

// 內容卡片
.content-card {
  @include card-style;
  
  &:not(:last-child) {
    margin-bottom: $spacing-lg;
  }
  
  .card-header {
    @include flex-between;
    margin-bottom: $spacing-lg;
    padding-bottom: $spacing-md;
    border-bottom: 1px solid $border-color-lighter;
    
    .card-title {
      font-size: $font-size-large;
      font-weight: 600;
      color: $text-color-primary;
      margin: 0;
    }
    
    .card-actions {
      display: flex;
      gap: $spacing-sm;
    }
  }
  
  .card-body {
    // 內容樣式由具體組件定義
  }
  
  .card-footer {
    margin-top: $spacing-lg;
    padding-top: $spacing-md;
    border-top: 1px solid $border-color-lighter;
    @include flex-between;
  }
}