/* layout.css - 全站共用側邊欄、頂部工具列與全域樣式 */

:root {
    /* 顏色調整 */
    --primary-color: #2e7d32; /* 深綠色，作為側邊欄背景和主要互動色 */
    --primary-hover-color: #388e3c; /* 較亮的綠色，用於懸停/活動狀態 */
    --secondary-color: #7f8c8d; /* 較深的灰藍色 */
    --secondary-hover-color: #6c7a7b;
    --danger-color: #c0392b;
    --success-color: #27ae60;
    --warning-color: #e67e22;
    --text-dark-color: #2c3e50;
    --text-light-color: #666;
    --bg-light-color: #f8f9fa;
    --bg-white-color: #ffffff;
    --border-color: #dcdcdc;
    --border-radius-sm: 4px;
    --border-radius-md: 8px;
    --border-radius-lg: 12px;
    
    /* 側邊欄專用顏色 */
    --sidebar-bg-color: var(--primary-color);
    --sidebar-text-color: #ffffff;
    --sidebar-active-bg-color: var(--primary-hover-color);
    --sidebar-hover-text-color: #ffffff;
    --sidebar-header-bg-color: #276b2a; /* 側邊欄頭部更深的綠色 */

    /* 頂部工具列專用顏色 */
    --top-bar-bg-color: #ffffff;
    --top-bar-border-color: #e0e0e0;

    /* 陰影調整 */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);

    /* 側邊欄和頂部工具列的尺寸 */
    --sidebar-width: 250px;
    --top-bar-height: 60px;
}

/* 全域基礎樣式 */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: "Noto Sans TC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-light-color);
    color: var(--text-dark-color);
    line-height: 1.6;
    /* padding-left 和 padding-top 將由 JS 動態設定 */
    padding-left: var(--sidebar-width); /* 預留側邊欄空間 */
    padding-top: var(--top-bar-height); /* 預留頂部工具列空間 */
}

/* 移除 #app-layout 的 CSS 規則，因為它不再需要 */
/* #app-layout {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999;
} */

/* 側邊欄樣式 */
#sidebar-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100%;
    background: var(--sidebar-bg-color);
    color: var(--sidebar-text-color);
    transition: all 0.3s;
    box-shadow: var(--shadow-md);
    z-index: 1000; /* 確保側邊欄在所有內容之上 */
}

#sidebar {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px;
    background: var(--sidebar-header-bg-color);
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo-icon {
    width: 40px;
    height: 40px;
    fill: var(--sidebar-text-color); /* 確保 SVG 圖標顏色正確 */
}

.sidebar-logo-text {
    font-size: 24px;
    font-weight: 700;
    color: var(--sidebar-text-color);
}

#sidebar ul.components {
    padding: 20px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-grow: 1; /* 讓導航列表佔滿剩餘空間 */
}

#sidebar ul li {
    padding: 0;
    margin: 0;
}

#sidebar ul li a {
    padding: 15px 20px;
    font-size: 1.1em;
    display: block;
    color: var(--sidebar-text-color);
    text-decoration: none;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 10px;
}

#sidebar ul li a:hover {
    color: var(--sidebar-hover-text-color);
    background: var(--sidebar-active-bg-color);
    border-left: 5px solid var(--sidebar-text-color); /* 懸停時左側邊框 */
    padding-left: 15px; /* 調整 padding 保持視覺平衡 */
}

#sidebar ul li.active > a, #sidebar ul li.active > a:hover {
    color: var(--sidebar-hover-text-color);
    background: var(--sidebar-active-bg-color);
    border-left: 5px solid var(--sidebar-text-color); /* 活動狀態左側邊框 */
    padding-left: 15px; /* 調整 padding 保持視覺平衡 */
}

#sidebar ul li a i {
    margin-right: 10px;
    font-size: 1.2em;
}

/* 頂部工具列樣式 */
#content-top-bar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width); /* 位於側邊欄右側 */
    width: calc(100% - var(--sidebar-width)); /* 佔據剩餘寬度 */
    height: var(--top-bar-height);
    background: var(--top-bar-bg-color);
    border-bottom: 1px solid var(--top-bar-border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: flex-end; /* 工具按鈕靠右對齊 */
    padding: 0 20px;
    z-index: 998; /* 確保在側邊欄之下，但仍在內容之上 */
}

.top-bar-actions {
    display: flex;
    gap: 10px;
}

/* 全域容器與卡片樣式 */
.container { max-width: 1600px; margin: 0 auto; padding: 0 15px; }
.content-box, .card {
    background-color: var(--bg-white-color);
    padding: 25px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 25px;
    border: 1px solid var(--border-color);
}

/* 全域標題樣式 */
h1 { font-size: 32px; color: var(--text-dark-color); margin-bottom: 30px; font-weight: 700; }
h2 { font-size: 24px; color: var(--text-dark-color); margin-bottom: 20px; padding-bottom: 10px; border-bottom: 1px solid var(--border-color); font-weight: 600; }
h3 { font-size: 20px; color: var(--text-dark-color); margin-bottom: 15px; font-weight: 600; }
h4 { font-size: 18px; color: var(--text-dark-color); margin-bottom: 10px; font-weight: 500; }

/* 全域表單元素樣式 */
input, select, button, textarea {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    font-size: 16px;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.2); /* 使用 primary-color 的 RGB 值 */
    outline: none;
}
label { font-weight: 500; margin-bottom: 8px; color: var(--text-dark-color); display: block; }

/* 全域按鈕樣式 */
.btn, .action-btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn-primary { background-color: var(--primary-color); color: white; }
.btn-primary:hover { background-color: var(--primary-hover-color); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-primary:active { transform: translateY(0); box-shadow: none; }

.btn-secondary { background-color: var(--secondary-color); color: white; }
.btn-secondary:hover { background-color: var(--secondary-hover-color); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-secondary:active { transform: translateY(0); box-shadow: none; }

.btn-success { background-color: var(--success-color); color: white; }
.btn-success:hover { background-color: #219d57; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-success:active { transform: translateY(0); box-shadow: none; }

.btn-danger, button.danger { background-color: var(--danger-color); color: white; }
.btn-danger:hover, button.danger:hover { background-color: #a93226; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-danger:active, button.danger:active { transform: translateY(0); box-shadow: none; }

.btn-warning { background-color: var(--warning-color); color: white; }
.btn-warning:hover { background-color: #d38a1a; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-warning:active { transform: translateY(0); box-shadow: none; }

.btn:disabled, .action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* 全域表格樣式 */
.table-wrapper { 
    overflow-x: auto; 
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--border-color);
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px; text-align: left; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
th { 
    background-color: #e9ecef;
    font-weight: 600; 
    color: var(--text-dark-color);
    position: sticky; 
    top: 0; 
    z-index: 1; 
    white-space: nowrap;
}
tr:hover { background-color: #f0f2f5; }

/* 全域 Modal 樣式 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.6);
    justify-content: center;
    align-items: center;
}
.modal-content {
    background-color: #fefefe;
    padding: 30px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 800px;
    animation: fadeIn 0.3s ease-out;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-20px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}
.modal-header h2 { margin: 0; color: var(--text-dark-color); font-size: 24px; }
.close-button, .close-btn {
    color: #888;
    font-size: 32px;
    font-weight: normal;
    cursor: pointer;
    background: none;
    border: none;
    transition: color 0.2s ease;
}
.close-button:hover, .close-btn:hover { color: var(--danger-color); }
.modal-footer { margin-top: 25px; display: flex; justify-content: flex-end; gap: 10px; }

/* 全域 Toast 通知樣式 */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: var(--success-color);
    color: white;
    padding: 15px 25px;
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-md);
    z-index: 1001;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease-out;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* 全域錯誤訊息樣式 */
.error-message {
    color: var(--danger-color);
    background-color: #fef2f2;
    border: 1px solid #fccaca;
    padding: 12px 18px;
    margin-bottom: 15px;
    border-radius: var(--border-radius-md);
    font-size: 0.95em;
    display: none;
    text-align: left;
    font-weight: 500;
}

/* 響應式調整 */
@media (max-width: 992px) {
    /* 在小螢幕上，側邊欄可以考慮隱藏或變成可切換的 */
    #sidebar-wrapper {
        left: calc(-1 * var(--sidebar-width)); /* 預設隱藏 */
        /* 可以添加一個按鈕來切換 sidebar 的 'left: 0;' */
    }
    body {
        padding-left: 0; /* 移除側邊欄的 padding */
    }
    #content-top-bar {
        left: 0;
        width: 100%;
        justify-content: center; /* 工具按鈕居中 */
    }
    .top-bar-actions {
        flex-wrap: wrap;
        justify-content: center;
    }
}
