/* ===== Layout CSS - Sell Pilot ===== */
/* 전체 레이아웃 구조를 담당하는 스타일 */

/* =========================== */
/* 기본 레이아웃 */
/* =========================== */

body {
    font-family: var(--font-family-primary);
    background-color: var(--color-bg-body);
    color: var(--color-text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.layout {
    display: flex;
    flex: 1;
    min-height: 0;
    /* ✅ Phase 3.52: flexbox overflow 방지 - 자식이 부모를 밀어내지 않도록 */
}

/* =========================== */
/* 사이드바 레이아웃 */
/* =========================== */

.sidebar {
    width: var(--sidebar-width);
    background: var(--color-bg-sidebar);
    color: var(--color-text-white);
    transition: width var(--transition-base);
    overflow: hidden;
    /* 하드웨어 가속 활성화 (성능 개선) */
    will-change: width;
    transform: translateZ(0);
}

.sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
}

/* 축소 시 텍스트 숨김 (아이콘만 표시) */
.sidebar.collapsed .menu-label,
.sidebar.collapsed .sidebar-header h2,
.sidebar.collapsed .badge {
    opacity: 0;
    visibility: hidden;
    width: 0;
    overflow: hidden;
    transition: opacity 0.15s, visibility 0.15s;
}

/* 축소되지 않은 상태에서 텍스트 표시 */
.sidebar:not(.collapsed) .menu-label,
.sidebar:not(.collapsed) .sidebar-header h2,
.sidebar:not(.collapsed) .badge {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.15s 0.15s, visibility 0.15s 0.15s;
}

/* 메뉴 리스트 스타일 */
.menu-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.menu-list.level-0 {
    padding: var(--spacing-md) 0;
}

.menu-list.level-1 {
    padding-left: var(--spacing-xl);
    background: rgba(0, 0, 0, 0.1);
}

.menu-list.level-2 {
    padding-left: var(--spacing-2xl);
    background: rgba(0, 0, 0, 0.15);
}

.sidebar-header {
    padding: var(--spacing-lg) var(--spacing-xl);  /* 상하 패딩 줄임 */
    background: var(--color-bg-sidebar-hover);
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 50px;  /* 최소 높이 설정 */
}

.sidebar-header h2 {
    font-size: var(--font-size-base);  /* 헤더 폰트 크기 축소 */
    font-weight: var(--font-weight-semibold);
    margin: 0;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--color-text-white);
    cursor: pointer;
    font-size: var(--font-size-md);  /* lg(18px) → md(15px) */
    padding: var(--spacing-sm);
}

/* 축소 시 헤더 중앙 정렬 */
.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: var(--spacing-lg) 0;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    font-size: var(--font-size-sm);  /* md(15px) → sm(12px) */
}

.menu-item {
    position: relative;
}

.menu-link {
    display: flex;
    align-items: center;
    padding: 10px 15px;  /* 기존 --padding-input(12px 15px)에서 약간 줄임 */
    color: var(--color-text-white);
    text-decoration: none;
    transition: background var(--transition-fast);
    cursor: pointer;
}

/* 축소 시 아이콘 완전 중앙 정렬 */
.sidebar.collapsed .menu-link {
    justify-content: center;
    padding: 10px 0;
    display: block;  /* flex → block으로 변경 */
    text-align: center;  /* 중앙 정렬 */
}

.menu-link:hover {
    background: var(--color-bg-sidebar-hover);
}

.menu-link.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.menu-link.disabled:hover {
    background: transparent;
}

/* 활성 메뉴 스타일 */
.menu-item.active > .menu-link {
    background: var(--color-bg-sidebar-active);
    font-weight: var(--font-weight-semibold);
}

/* 하위 메뉴가 있는 경우 */
.menu-item.has-children.expanded > .menu-list {
    display: block;
}

.menu-item.has-children:not(.expanded) > .menu-list {
    display: none;
}

/* 축소 시 모든 하위 메뉴 완전 숨김 (!important로 강제) */
.sidebar.collapsed .menu-list.level-1,
.sidebar.collapsed .menu-list.level-2 {
    display: none !important;
    max-height: 0 !important;
    overflow: hidden !important;
    opacity: 0 !important;
    visibility: hidden !important;
}

/* 미구현 배지 */
.menu-link .badge {
    margin-left: auto;
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-xs);
}

.menu-icon {
    margin-right: var(--spacing-base);
    width: 18px;  /* 20px → 18px */
    font-size: var(--font-size-md);  /* 아이콘 크기 조정 */
    flex-shrink: 0;  /* 축소 방지 */
    display: inline-block;  /* inline-block으로 설정 */
}

/* 축소 시 아이콘 중앙 정렬 및 마진 제거 */
.sidebar.collapsed .menu-icon {
    margin-right: 0;
    display: block;  /* block으로 변경하여 완전 중앙 정렬 */
    width: 100%;  /* 전체 너비 사용 */
}

.menu-arrow {
    margin-left: auto;
    transition: transform var(--transition-fast);
    font-size: var(--font-size-xs);  /* 화살표 크기 축소 */
}

.menu-arrow.expanded {
    transform: rotate(90deg);
}

/* 축소 시 화살표 숨김 */
.sidebar.collapsed .menu-arrow {
    display: none;
}

.submenu {
    background: var(--color-bg-sidebar-active);
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition-base) ease-out;
    font-size: var(--font-size-sm);  /* base(13px) → sm(12px) */
}

.submenu.open {
    max-height: 500px;
}

.submenu-link {
    display: block;
    padding: 8px 15px 8px 45px;  /* 패딩 조정 */
    color: var(--color-text-light);
    text-decoration: none;
    transition: background var(--transition-fast);
}

.submenu-link:hover {
    background: var(--color-bg-sidebar-hover);
    color: var(--color-text-white);
}

/* =========================== */
/* 메인 컨테이너 */
/* =========================== */

.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    /* ✅ Phase 3.52: flexbox overflow 방지 */
}

/* =========================== */
/* 헤더 레이아웃 */
/* =========================== */

.header {
    background: linear-gradient(135deg, var(--color-primary-gradient-start) 0%, var(--color-primary-gradient-end) 100%);
    color: var(--color-text-white);
    padding: var(--padding-card);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-base);
    min-height: var(--header-height);
    position: relative;  /* 원래대로 복원 */
}

.header h1 {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    margin: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-xl);
}

.user-menu {
    position: relative;
}

.user-button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: var(--color-text-white);
    padding: var(--padding-btn);
    border-radius: var(--border-radius-xl);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    transition: background var(--transition-fast);
}

.user-button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--color-bg-white);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all var(--transition-base);
    z-index: var(--z-index-dropdown);
}

.user-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: block;
    padding: var(--spacing-lg) var(--spacing-xl);
    color: var(--color-text-primary);
    text-decoration: none;
    transition: background var(--transition-fast);
}

.dropdown-item:hover {
    background: var(--color-bg-light);
}

/* =========================== */
/* 콘텐츠 영역 */
/* =========================== */

.content {
    flex: 1 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: var(--color-bg-white);
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
    /* ✅ Phase 2.9.6: height 제거 - flexbox가 자동 계산하도록 수정 (헤더 고정 구조) */
    /* ✅ Phase 3.52: min-height: 0 추가 - flexbox overflow 방지 */
}

.content-header {
    margin-bottom: var(--spacing-2xl);
    padding-bottom: var(--spacing-xl);
    border-bottom: 1px solid var(--color-border-light);
}

.content-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    margin: 0 0 var(--spacing-md) 0;
}

.content-subtitle {
    color: var(--color-text-muted);
    font-size: var(--font-size-base);
    margin: 0;
}

/* =========================== */
/* 반응형 레이아웃 */
/* =========================== */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: calc(-1 * var(--sidebar-width));  /* ✅ Phase 2.7.16: 변수 사용으로 변경 */
        top: 0;
        bottom: 0;
        z-index: var(--z-index-fixed);
        transition: left var(--transition-base);
    }
    
    .sidebar.show {
        left: 0;
    }
    
    .sidebar.collapsed {
        width: var(--sidebar-width);
        left: -280px;
    }
    
    .sidebar.collapsed.show {
        left: 0;
    }
    
    .main-container {
        margin-left: 0;
    }
    
    .header {
        padding: var(--spacing-lg) var(--spacing-xl);
    }
    
    .header h1 {
        font-size: var(--font-size-lg);
    }
    
    .content {
        padding: var(--spacing-xl);
    }
}

@media (max-width: 480px) {
    .header-right {
        gap: var(--spacing-base);
    }
    
    .user-button {
        padding: var(--spacing-sm) var(--spacing-base);
        font-size: var(--font-size-sm);
    }
    
    .content {
        padding: var(--spacing-lg);
    }
}

/* =========================== */
/* 접근성 개선 */
/* =========================== */

@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .menu-arrow,
    .submenu,
    .user-dropdown {
        transition: none;
    }
}

/* 키보드 네비게이션을 위한 포커스 스타일 */
.menu-link:focus,
.submenu-link:focus,
.user-button:focus,
.dropdown-item:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* 스크린 리더를 위한 숨김 텍스트 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* =========================== */
/* FOUC 방지: 사이드바 초기 렌더링 */
/* =========================== */

/* 초기 HTML의 빈 sidebar div 숨김 (JS 실행 전) */
.sidebar:not(.sidebar-new) {
    opacity: 0;
    pointer-events: none;
}

/* JS 초기화 완료 후 부드럽게 표시 */
.sidebar-new {
    opacity: 1;
    transition: opacity 0.15s ease-in;
}