/* ====================================================
 * WebERP 統一版面佈局 (Layout CSS) - 強度修復版
 * ==================================================== */

/* 1. 主容器：確保左右並排不變形 */
.app-container {
    display: flex !important;
    flex-direction: row !important;
    min-height: 100vh;
    width: 100%;
    background-color: transparent; /* 改為透明以顯露 body 背景漸層 */
    overflow: hidden;
}

/* 2. 側邊欄 (Sidebar) - 固定寬度及樣式 */
.sidebar {
    width: 250px;
    min-width: 250px;
    height: 100vh;
    background: #002244 !important;
    color: #ffffff !important;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 15px rgba(0,0,0,0.1);
    z-index: 100;
    position: sticky;
    top: 0;
}

.sidebar-header {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-header .logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 1px;
}

.sidebar-copyright {
    font-size: 10px;
    color: rgba(255,255,255,0.3);
    font-weight: 400;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
}

/* 折疊選單群組 */
.nav-group {
    display: flex;
    flex-direction: column;
}

.nav-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    font-size: 16px;
    font-weight: 700;
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    letter-spacing: 1px;
}

.nav-group-header:hover {
    color: #ffffff;
    background: rgba(255,255,255,0.05);
}

.nav-group-header i.toggle-icon {
    font-size: 10px;
    transition: transform 0.3s ease;
}

.nav-group.expanded .nav-group-header i.toggle-icon {
    transform: rotate(180deg);
}

.nav-group-items {
    display: flex;
    flex-direction: column;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.nav-group.expanded .nav-group-items {
    max-height: 500px;
}

/* 選單項樣式 - 強制覆寫連結預設值 */
.nav-item {
    display: flex !important;
    align-items: center !important;
    padding: 12px 24px !important;
    color: rgba(255,255,255,0.7) !important;
    text-decoration: none !important;
    font-size: 15px; /* 子選單預設大小 */
    transition: all 0.2s;
    gap: 12px;
}

/* 第一層獨立選單 (如：系統首頁) 加大字體 */
.sidebar-nav > .nav-item {
    font-size: 16px;
    font-weight: 700;
    color: rgba(255,255,255,0.85) !important;
}

/* 子選單縮排 */
.nav-group-items .nav-item {
    padding-left: 48px !important;
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 18px;
}

.nav-item:hover {
    color: #ffffff !important;
    background: rgba(255,255,255,0.1);
}

.nav-item.active {
    color: #ffffff !important;
    background: rgba(59, 130, 246, 0.2);
    border-left: 4px solid #3b82f6;
}

/* 3. 主要內容區 (Main Content) */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; 
    height: 100vh;
}

/* 頂部導覽列 (Top Nav) */
.top-nav {
    height: 64px;
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: #334155; /* 中性深灰色 (Slate 700) */
    color: #ffffff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    z-index: 90;
}

.nav-left, .nav-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

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

.info-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #ffffff;
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
}

.info-item i {
    font-size: 18px;
    color: #ffffff;
    width: 20px;
    text-align: center;
}

/* 頁首標籤樣式 (通用) */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 12px !important;
    font-weight: 600;
    white-space: nowrap;
}

.badge-info {
    background: #e2e8f0;
    color: #475569;
}

.menu-btn {
    background: transparent;
    border: none;
    font-size: 20px;
    color: #ffffff;
    cursor: pointer;
    padding: 4px;
    display: none; /* 桌面版隱藏 (因為側邊欄已顯示) */
    align-items: center;
    justify-content: center;
}

.btn-logout {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #ffffff;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-logout:hover {
    background: #dc2626;
    color: #ffffff;
    border-color: #dc2626;
}

/* 4. 頁首與工具列 (Page Header & Toolbar) */
/* 頂部固定容器 (包裹標題與篩選列) */
.sticky-container {
    position: sticky;
    top: -30px;
    z-index: 110;
    background: rgba(210, 230, 250, 0.95); /* 再加深一點的淡藍色 */
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    margin: -30px -30px 24px -30px;
    padding: 24px 30px 12px 30px;
    border-bottom: 1px solid rgba(0, 51, 102, 0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 12px;
}

.page-title-group {
    flex: 1;
}

.page-title {
    font-size: 28px;
    font-weight: 700;
    color: #003366;
    margin-bottom: 4px;
}

.breadcrumb {
    font-size: 14px;
    color: #64748b;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 篩選列固定樣式 */
.sticky-filter {
    /* 在容器內不再需要單獨 sticky */
    border: 1px solid #003366 !important;
    background: #ffffff !important;
}

/* 表格標題固定 (選配，提升體驗) */
.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #f8fafc;
}

.search-box {
    position: relative;
    width: 100%;
}

.search-box i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    pointer-events: none;
    z-index: 5;
}

.search-box .form-control {
    padding-left: 40px !important;
}

/* 5. 頁面內文高度與滾動 */
.page-body {
    padding: 30px;
    flex: 1;
    overflow-y: auto;
}

/* 6. 表單網格與區塊 (Form Grid & Sections) */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 8px 32px;
}

.section-title {
    font-size: 18px;
    font-weight: 700;
    color: #003366;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1.5px solid rgba(0, 51, 102, 0.1);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 響應式設計補充 */
@media (max-width: 992px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .toolbar-actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    .search-box {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .menu-btn {
        display: flex;
    }
    .sidebar {
        position: fixed;
        left: -250px;
        transition: left 0.3s ease;
    }
    .sidebar.sidebar-open {
        left: 0;
    }
    .header-info {
        gap: 12px;
    }
    .info-item span {
        display: none;
    }
}
