/* 
 * 尚荣定制管理系统 - 统一的左侧导航栏样式
 * 所有页面都应该使用这个统一的样式
 * 
 * 响应式设计说明：
 * - 桌面端 (>1200px): 完整侧边栏 150px
 * - 平板横屏 (1024px-1200px): 压缩侧边栏 140px
 * - 平板竖屏 (768px-1024px): 紧凑折叠 60px  
 * - 手机端 (<768px): 抽屉式侧边栏 (可隐藏)
 */

/* 防止页面闪烁：在侧边栏加载前隐藏body内容 */
body:not(.sidebar-ready) {
    visibility: hidden;
}

body.sidebar-ready {
    visibility: visible;
}

/* 确保body和html没有默认的margin和padding，消除顶部空白 */
html, body {
    margin: 0 !important;
    padding: 0 !important;
    height: 100%;
    /* 防止顶部出现空白条 */
    overflow-x: hidden;
}

/* 消除主内容区顶部空白 - 确保 header/横幅紧贴视口顶部 */
.main-content {
    padding-top: 0 !important;
    margin-top: 0 !important;
}
.main-content > *:first-child {
    margin-top: 0 !important;
}

:root {
    --primary-color: #3498db;
    --secondary-color: #2ecc71;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    --info-color: #1abc9c;
    --dark-color: #34495e;
    --light-color: #ecf0f1;
    --gray-color: #95a5a6;
    --white-color: #ffffff;
    --sidebar-width: 150px;           /* 桌面端宽度 */
    --sidebar-tablet-landscape: 140px; /* 平板横屏宽度 */
    --sidebar-tablet-portrait: 60px;   /* 平板竖屏宽度 */
    --sidebar-mobile-width: 280px;      /* 手机端抽屉宽度 */
    --header-height: 60px;
    --card-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    --transition-speed: 0.3s;
}

/* ========================================
   桌面端侧边栏样式 (>1200px)
   ======================================== */
/* 侧边栏：菜单与用户信息垂直居中，用户信息紧接在菜单下方 */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    min-height: 100vh;
    height: 100vh;
    background-color: #2c3e50;
    color: var(--light-color);
    transition: all var(--transition-speed) ease;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch; /* iOS 弹性滚动 */
    z-index: 900;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important; /* 菜单与用户信息整体垂直居中 */
    align-items: stretch;
    /* 底部安全区：避免 iPhone 刘海/Home 指示条遮挡 */
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.sidebar-header {
    padding: 15px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 15px;
}

/* 侧边栏菜单 - 与用户信息一起垂直居中 */
.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0 0 8px 0; /* 与用户信息区保持小间距 */
    padding-top: 0;
    margin-top: 0;
}

.sidebar-item {
    position: relative;
    margin-bottom: 2px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    color: var(--light-color);
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-size: 0.95rem;
    line-height: 1.5;
}

.sidebar-link:hover, 
.sidebar-link.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--white-color);
    border-left: 3px solid var(--primary-color);
}

.sidebar-link.disabled {
    opacity: 0.5;
    color: #999;
    cursor: not-allowed;
    background-color: rgba(255, 255, 255, 0.05);
}

.sidebar-link.disabled:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-left: none;
    cursor: not-allowed;
}

.sidebar-link i {
    margin-right: 15px;
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
}

.sidebar-link span {
    font-size: 0.95rem;
}

.sidebar-title {
    padding: 12px 15px 5px;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--gray-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 用户信息区域：紧接在菜单下方，与菜单一起垂直居中（覆盖 Bootstrap mt-auto） */
.sidebar-user {
    padding: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: 0 !important; /* 覆盖 mt-auto，紧贴菜单下方 */
    flex-shrink: 0;
}

.sidebar .user-info {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}

.sidebar .user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #fff;
    margin-right: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dark-color);
}

.sidebar .user-name {
    font-weight: 600;
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.4;
}

/* 退出登录按钮：确保足够大的可点击区域 */
#sidebarLogoutBtn {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
}

.sidebar .user-role {
    color: var(--gray-color);
    font-size: 0.8rem;
    margin: 0;
    line-height: 1.4;
}

/* ========================================
   主内容区域 - 适配侧边栏
   使用 position:fixed 确保主内容紧贴视口顶部，消除顶部空白
   ======================================== */
.main-content {
    position: fixed !important;
    top: 0 !important;
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    margin: 0 !important;
    padding: 0 !important;
    transition: all var(--transition-speed) ease;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* 统一的header样式 */
.header {
    background: linear-gradient(to right, #2c3e50, #3498db, var(--dark-color));
    color: white;
    padding: 15px 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    margin: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
}

.header .logo {
    font-size: 24px;
    font-weight: bold;
    display: flex;
    align-items: center;
}

.header .logo i {
    margin-right: 10px;
}

.header .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header .user-info img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid white;
}

.main-content > .header + * {
    padding-top: 20px;
}

.main-content > .header ~ * {
    padding-left: 20px;
    padding-right: 20px;
}

/* 首个子元素（非 header、非 welcome-banner）无顶部 padding，避免顶部空白；welcome-banner 需保留顶部间距 */
.main-content > *:first-child:not(.header):not(.welcome-banner) {
    padding: 0 20px 20px 20px;
}

.main-content > .header {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

/* ========================================
   平板横屏适配 (1024px - 1200px)
   iPad Pro 11英寸 横屏模式
   ======================================== */
@media (min-width: 1024px) and (max-width: 1200px) {
    :root {
        --sidebar-width: var(--sidebar-tablet-landscape);
    }
    
    .sidebar {
        width: var(--sidebar-width);
    }
    
    /* 平板横屏：显示完整文字 */
    .sidebar-title,
    .sidebar-link span,
    .sidebar .user-details {
        display: block;
    }
    
    .sidebar-link {
        justify-content: flex-start;
        padding: 10px 12px;
    }
    
    .sidebar-link i {
        margin-right: 12px;
        width: 18px;
        font-size: 1rem;
    }
    
    .sidebar-link span {
        font-size: 0.9rem;
    }
    
    .main-content {
        left: var(--sidebar-width);
    }
    
    .sidebar-menu {
        padding-top: 0;
    }
}

/* ========================================
   平板竖屏适配 (768px - 1024px)
   iPad Pro 11英寸 竖屏模式
   ======================================== */
@media (min-width: 768px) and (max-width: 1024px) {
    :root {
        --sidebar-width: var(--sidebar-tablet-portrait);
    }
    
    .sidebar {
        width: var(--sidebar-width);
        z-index: 1030;
    }
    
    /* 平板竖屏：只显示图标，隐藏文字 */
    .sidebar-title,
    .sidebar-link span,
    .sidebar .user-details {
        display: none;
    }
    
    .sidebar-link {
        justify-content: center;
        padding: 12px 8px;
    }
    
    .sidebar-link i {
        margin-right: 0;
        width: 24px;
        font-size: 1.2rem;
    }
    
    .main-content {
        left: var(--sidebar-width);
    }
    
    .sidebar-user {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 10px 5px;
    }
    
    .sidebar .user-info {
        justify-content: center;
        margin-bottom: 8px;
    }
    
    .sidebar .user-avatar {
        margin-right: 0;
        width: 36px;
        height: 36px;
    }
    
    #sidebarLogoutBtn {
        margin-top: 8px;
        width: 100%;
        display: flex;
        justify-content: center;
    }
    
    #sidebarLogoutBtn span {
        display: none;
    }
    
    .sidebar-menu {
        padding-top: 0;
    }
    
    /* 平板竖屏：用户信息区域上移，避免小屏时被遮挡 */
    .sidebar {
        padding-bottom: max(env(safe-area-inset-bottom), 60px);
    }
    
    .sidebar-user {
        margin-top: 0;
    }
    
    .header .logo {
        font-size: 20px;
    }
    
    .main-content > .header ~ * {
        padding-left: 15px;
        padding-right: 15px;
    }
}

/* ========================================
   手机端适配 (< 768px)
   iPhone 12 Pro Max 等移动设备
   ======================================== */
@media (max-width: 767.98px) {
    /* 抽屉式侧边栏 - 默认隐藏 */
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-mobile-width);
        transition: transform 0.3s ease;
        position: fixed;
        z-index: 1050;
        top: 0;
        left: 0;
        height: 100vh;
        box-shadow: 4px 0 15px rgba(0, 0, 0, 0.2);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    /* 侧边栏内部布局 - 手机端显示完整 */
    .sidebar-title,
    .sidebar-link span,
    .sidebar .user-details {
        display: block;
    }
    
    .sidebar-link {
        justify-content: flex-start;
        padding: 12px 20px;
    }
    
    .sidebar-link i {
        margin-right: 15px;
        width: 24px;
        font-size: 1.2rem;
    }
    
    .sidebar-link span {
        font-size: 1rem;
    }
    
    .sidebar-user {
        display: block;
        padding: 15px 20px;
    }
    
    .sidebar .user-info {
        display: flex;
        align-items: center;
        margin-bottom: 12px;
    }
    
    .sidebar .user-avatar {
        margin-right: 12px;
        width: 44px;
        height: 44px;
    }
    
    .sidebar .user-name {
        font-size: 1rem;
    }
    
    .sidebar .user-role {
        font-size: 0.85rem;
    }
    
    #sidebarLogoutBtn {
        margin-top: 12px;
        width: 100%;
        /* 移动端：增大点击区域，符合 iOS 44pt 最小触控尺寸建议 */
        min-height: 44px;
        padding: 12px 20px;
        display: flex;
        align-items: center;
    }
    
    #sidebarLogoutBtn span {
        display: inline;
    }
    
    .sidebar-menu {
        padding-top: 0;
    }
    
    /* 移动端：用户信息区域上移，避免被底部遮挡（增加底部内边距，确保系统管理员/退出登录始终可见可点） */
    .sidebar {
        padding-bottom: max(env(safe-area-inset-bottom), 80px);
    }
    
    .sidebar-user {
        margin-top: 0;
    }
    
    /* 主内容区域 - 移动端侧边栏隐藏，主内容占满全屏 */
    .main-content {
        left: 0 !important;
    }
    
    .main-content > .header ~ * {
        padding-left: 12px;
        padding-right: 12px;
    }
    
    .main-content > *:first-child:not(.header) {
        padding: 12px;
    }
    
    /* 移动端菜单按钮 - 默认显示 */
    .mobile-menu-btn {
        display: flex !important;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 1040;
        background: linear-gradient(135deg, #3498db, #2980b9);
        color: white;
        border: none;
        padding: 10px 14px;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(52, 152, 219, 0.4);
        cursor: pointer;
        align-items: center;
        gap: 8px;
        font-size: 14px;
        font-weight: 500;
        transition: all 0.2s ease;
    }
    
    .mobile-menu-btn:hover {
        background: linear-gradient(135deg, #2980b9, #1f6391);
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(52, 152, 219, 0.5);
    }
    
    .mobile-menu-btn:active {
        transform: translateY(0);
    }
    
    .mobile-menu-btn i {
        font-size: 16px;
    }
    
    /* 遮罩层 */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1045;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }
    
    /* header调整 - 为菜单按钮留空间 */
    .header {
        padding: 12px 0;
        padding-left: 50px;
    }
    
    .header .logo {
        font-size: 18px;
    }
    
    .header .logo span {
        display: none;
    }
    
    .header .user-info img {
        width: 32px;
        height: 32px;
    }
    
    .header-container {
        padding: 0 12px;
    }
}

/* ========================================
   小屏手机适配 (< 480px)
   iPhone SE、iPhone mini 等
   ======================================== */
@media (max-width: 479.98px) {
    :root {
        --sidebar-mobile-width: 260px;
    }
    
    .sidebar-link {
        padding: 10px 15px;
    }
    
    .sidebar-link i {
        margin-right: 12px;
        width: 20px;
        font-size: 1.1rem;
    }
    
    .sidebar-link span {
        font-size: 0.95rem;
    }
    
    .mobile-menu-btn {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .main-content > .header ~ * {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    .main-content > *:first-child:not(.header) {
        padding: 10px;
    }
    
    .header {
        padding-left: 45px;
    }
    
    .header .logo {
        font-size: 16px;
    }
}
