/* ========================================
   Sidebar Styles - Centralized
   ======================================== */

/* CSS Variables for Sidebar (should be defined in main CSS or :root) */
/* --sidebar-width-collapsed: 60px; */
/* --sidebar-width-expanded: 250px; */
/* --sidebar-transition: 0.15s ease-out; */
/* --sidebar-background: #1E293B; */

/* Sidebar - Collapsible Design (Fixed position for overlay on hover) */
.sidebar {
    grid-area: sidebar;
    background: var(--sidebar-background, #1E293B);
    padding: 0;
    width: var(--sidebar-width-collapsed, 60px);
    overflow: hidden;
    transition: width var(--sidebar-transition, 0.15s ease-out);
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* 호버 시 사이드바만 확장 (콘텐츠 영역은 그대로) */
/* pinned 상태에서는 호버 효과 무시 (이미 확장됨) */
.sidebar:not(.pinned):hover,
.sidebar.expanded {
    width: var(--sidebar-width-expanded, 250px);
}

/* 메인 레이아웃에 사이드바 공간 확보 */
.main-layout {
    display: block;
    min-height: 100vh;
    padding-left: var(--sidebar-width-collapsed, 60px);
    transition: padding-left var(--sidebar-transition, 0.15s ease-out);
}

/* 고정 시에는 콘텐츠 영역도 조정 */
.main-layout.sidebar-pinned {
    padding-left: var(--sidebar-width-expanded, 250px);
}

/* Sidebar Profile */
.sidebar-profile {
    display: flex;
    align-items: center;
    justify-content: center;
    /* gap 제거 - width:0일 때도 공간 차지하는 문제 해결 */
    padding: 16px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: background 0.15s ease-out, padding 0.15s ease-out, justify-content 0.15s ease-out;
    position: relative;
    flex-shrink: 0;
}

.sidebar:hover .sidebar-profile,
.sidebar.expanded .sidebar-profile,
.sidebar.pinned .sidebar-profile {
    justify-content: flex-start;
    padding: 16px;
}

.sidebar-profile:hover {
    background: rgba(59, 130, 246, 0.1);
}

.profile-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-blue, #3B82F6), #0969DA);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.sidebar-profile-info {
    opacity: 0;
    width: 0;
    overflow: hidden;
    transition: opacity var(--sidebar-transition, 0.15s ease-out), width var(--sidebar-transition, 0.15s ease-out), margin-left var(--sidebar-transition, 0.15s ease-out);
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-left: 0; /* 접힌 상태에서는 margin 제거 - 아바타 중앙정렬 */
}

.sidebar:hover .sidebar-profile-info,
.sidebar.expanded .sidebar-profile-info,
.sidebar.pinned .sidebar-profile-info {
    opacity: 1;
    width: auto;
    margin-left: 12px; /* 펼친 상태에서만 margin 적용 */
}

.sidebar-profile-info .profile-name {
    color: var(--white, #FFFFFF);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.sidebar-profile-info .profile-role {
    color: #94A3B8;
    font-size: 12px;
    white-space: nowrap;
}

/* Sidebar Pin Toggle */
.sidebar-pin-toggle {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    display: none;  /* 기본적으로 숨김 - 접힌 상태에서 프로필 중앙정렬 보장 */
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s ease-out, transform 0.15s ease-out, color 0.15s ease-out;
    cursor: pointer;
    color: #94A3B8;
    font-size: 12px;
    border-radius: 4px;
    z-index: 10;
}

.sidebar-pin-toggle:hover {
    color: var(--white, #FFFFFF);
    background: rgba(255, 255, 255, 0.1);
}

/* 호버/확장/고정 시에만 핀 토글 표시 */
.sidebar:hover .sidebar-pin-toggle,
.sidebar.expanded .sidebar-pin-toggle,
.sidebar.pinned .sidebar-pin-toggle {
    display: flex;
    opacity: 1;
}

.sidebar.pinned .sidebar-pin-toggle {
    color: var(--primary-blue, #3B82F6);
    transform: rotate(45deg);
}

/* Sidebar Pinned State */
.sidebar.pinned {
    width: var(--sidebar-width-expanded, 250px);
}

.sidebar.pinned .sidebar-label,
.sidebar.pinned .sidebar-profile-info {
    opacity: 1;
    width: auto;
}

/* Sidebar Profile Tooltip */
.sidebar:not(:hover):not(.expanded):not(.pinned) .sidebar-profile::after {
    content: attr(title);
    position: absolute;
    left: calc(var(--sidebar-width-collapsed, 60px) + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: #1E293B;
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease-out, visibility 0.15s ease-out;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.sidebar:not(:hover):not(.expanded):not(.pinned) .sidebar-profile:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Sidebar Navigation */
.sidebar-nav {
    list-style: none;
    padding: 16px 0;
    margin: 0;
    flex: 1;
    overflow-y: auto;
}

.sidebar-item {
    margin-bottom: 4px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: #94A3B8;
    text-decoration: none;
    transition: all 0.15s ease-out;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    cursor: pointer;
}

.sidebar-link:hover,
.sidebar-link.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--white, #FFFFFF);
    border-right: 3px solid var(--primary-blue, #3B82F6);
}

.sidebar-icon {
    min-width: 28px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-label {
    opacity: 0;
    width: 0;
    overflow: hidden;
    transition: opacity var(--sidebar-transition, 0.15s ease-out), width var(--sidebar-transition, 0.15s ease-out);
}

.sidebar:hover .sidebar-label,
.sidebar.expanded .sidebar-label {
    opacity: 1;
    width: auto;
}

/* Sidebar Footer - Logout */
.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 0;
    flex-shrink: 0;
    position: relative;
    z-index: 20;
}

.sidebar-footer .sidebar-link.logout {
    color: #94A3B8;
    pointer-events: auto;
}

.sidebar-footer .sidebar-link.logout:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error-red, #EF4444);
    border-right: 3px solid var(--error-red, #EF4444);
}

/* Sidebar Tooltip for collapsed state */
.sidebar:not(:hover):not(.expanded) .sidebar-link {
    position: relative;
}

.sidebar:not(:hover):not(.expanded):not(.pinned) .sidebar-link::after {
    content: attr(title);
    position: absolute;
    left: calc(var(--sidebar-width-collapsed, 60px) + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: #1E293B;
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.sidebar:not(:hover):not(.expanded):not(.pinned) .sidebar-link:hover::after {
    opacity: 1;
    visibility: visible;
}

/* ========================================
   Responsive Styles
   ======================================== */

/* Tablet (768px ~ 1024px) - Touch device support */
@media (min-width: 769px) and (max-width: 1024px) {
    /* 태블릿에서도 동일한 오버레이 방식 유지 */
    .main-layout {
        padding-left: var(--sidebar-width-collapsed, 60px);
    }
    
    .main-layout.sidebar-pinned {
        padding-left: var(--sidebar-width-expanded, 250px);
    }
}

/* Touch device detection - tap to toggle instead of hover */
@media (hover: none) and (pointer: coarse) {
    .sidebar:hover {
        width: var(--sidebar-width-collapsed, 60px);
    }
    
    .sidebar:hover .sidebar-label,
    .sidebar:hover .sidebar-profile-info {
        opacity: 0;
        width: 0;
    }
    
    .sidebar.expanded {
        width: var(--sidebar-width-expanded, 250px);
    }
    
    .sidebar.expanded .sidebar-label,
    .sidebar.expanded .sidebar-profile-info {
        opacity: 1;
        width: auto;
    }
    
    /* Disable tooltip on touch devices */
    .sidebar:not(:hover):not(.expanded):not(.pinned) .sidebar-link::after,
    .sidebar:not(:hover):not(.expanded):not(.pinned) .sidebar-profile::after {
        display: none;
    }
    
    /* Show toggle button for touch devices */
    .sidebar-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 100%;
        padding: 12px 16px;
        color: #94A3B8;
        cursor: pointer;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .sidebar-toggle:hover {
        color: var(--white, #FFFFFF);
        background: rgba(59, 130, 246, 0.1);
    }
    
    .sidebar-toggle i {
        font-size: 18px;
        transition: transform 0.15s ease-out;
    }
    
    .sidebar.expanded .sidebar-toggle i {
        transform: rotate(180deg);
    }
}

/* Mobile (768px 이하) - 사이드바 숨김, padding 제거 */
@media (max-width: 768px) {
    .main-layout {
        padding-left: 0 !important;
    }
    
    .main-layout.sidebar-pinned {
        padding-left: 0 !important;
    }
}
