/* 全局樣式 */
:root {
    --primary-color: #007AFF; /* 藍色 */
    --secondary-color: #F5F5F7; /* 淺灰色 */
    --text-color: #1D1D1F; /* 深灰色 */
    --border-color: #D2D2D7; /* 淺灰色 */
    --success-color: #34C759; /* 綠色 */
    --danger-color: #FF3B30; /* 紅色 */
    --warning-color: #FF9500; /* 橙色 */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    background-color: white;
}

/* 容器樣式 */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* 標題樣式 */
h2 {
    color: var(--text-color);
    margin-bottom: 30px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

/* 表格樣式 */
.table-container {
    overflow-x: auto;
    margin: 20px 0;
    max-height: 70vh; /* 使用視窗高度的 70% 作為最大高度 */
    height: 70vh; /* 設置固定高度為視窗高度的 70% */
    position: relative;
    overflow-y: auto; /* 確保垂直滾動可用 */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: white;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0; /* 移除邊距 */
    background: white;
    overflow: visible;
}

thead.sticky-header {
    position: sticky;
    top: 0;
    z-index: 1001; /* 提高z-index確保在最上層 */
    background-color: var(--secondary-color);
    display: table-header-group; /* 確保顯示為表頭組 */
}

thead.sticky-header tr {
    position: sticky;
    top: 0;
    z-index: 1001;
    background-color: var(--secondary-color);
}

thead.sticky-header th {
    position: sticky;
    top: 0;
    background-color: var(--secondary-color);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
    z-index: 1001; /* 提高z-index確保在最上層 */
}

th {
    background-color: var(--secondary-color);
    color: var(--text-color);
    font-weight: 600;
}

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

tr:hover {
    background-color: var(--secondary-color);
}

/* 按鈕樣式 */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
    text-align: center;
    width: 100%;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: #0063CC;
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover {
    background-color: #2DA44E;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background-color: #D93025;
}

/* 表單樣式 */
.form-group {
    margin-bottom: 20px;
}

.form-control {
    width: 100%;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s ease;
}

.form-control:focus {
    border-color: var(--primary-color);
    outline: none;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23333' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

/* 語言選擇器樣式 */
.language-selector {
    padding: 10px;
    background: var(--secondary-color);
    border-radius: 8px;
}

.language-selector .form-group {
    margin-bottom: 0;
}

.language-selector label {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 操作連結樣式 */
.action-links {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.action-links a {
    color: var(--primary-color);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
    transition: background-color 0.3s;
}

.action-links a:hover {
    background-color: var(--secondary-color);
}

/* 響應式設計 */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    th, td {
        padding: 8px 10px;
    }
    
    .action-links {
        flex-direction: column;
        gap: 5px;
    }
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.main-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.action-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.action-card h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 10px;
}

.action-card h4 {
    margin-top: 0;
    margin-bottom: 15px;
    color: var(--text-color);
}

.data-section {
    margin-top: 30px;
}

.data-section h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 10px;
}

.collapsible {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 30px;
}

.collapsible .arrow {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8em;
    transition: transform 0.2s ease;
}

.collapsible-content {
    transition: all 0.3s ease;
    overflow: hidden;
}

.main-actions {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
}

.main-actions .action-card {
    flex: 1;
}

@media (max-width: 768px) {
    .main-actions {
        flex-direction: column;
    }
}

.search-box {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.search-form, .filter-form {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 400px;
}

.search-input-group, .filter-input-group {
    display: flex;
    gap: 10px;
    width: 100%;
}

.search-input, .filter-input {
    flex: 1;
    min-width: 200px;
}

.search-button, .filter-button, .clear-button {
    white-space: nowrap;
    padding: 8px 16px; /* 檢索按鈕的尺寸 */
    font-size: 14px;   /* 檢索按鈕的字體大小 */
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
}

@media (max-width: 768px) {
    .search-box {
        flex-direction: column;
    }
    
    .search-form, .filter-form {
        width: 100%;
    }
    
    .search-input, .filter-input, .search-button, .filter-button, .clear-button {
        width: 100%;
    }
}

.toggle-columns {
    cursor: pointer;
    background-color: var(--primary-color);
    color: white;
    text-align: center;
    min-width: 80px;
    position: sticky;
    top: 0;
    right: 0;
}

.collapsed-columns {
    display: none;
    min-width: 200px;
    background-color: white;
}

.collapsed-columns.show {
    display: table-cell;
}

.collapsed-columns div {
    padding: 5px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.collapsed-columns div:last-child {
    border-bottom: none;
}

/* 產品條碼樣式 */
td[data-column="product_barcode"] {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 操作按鈕樣式 */
.btn-edit {
    color: #fff;
    background-color: #ffc107;
    border: 1px solid #ffc107;
    padding: 5px 10px;
    border-radius: 4px;
    text-decoration: none;
    transition: all 0.3s ease;
}

.btn-edit:hover {
    background-color: #e0a800;
    border-color: #d39e00;
}

.btn-delete {
    color: #fff;
    background-color: #dc3545;
    border: 1px solid #dc3545;
    padding: 5px 10px;
    border-radius: 4px;
    text-decoration: none;
    transition: all 0.3s ease;
}

.btn-delete:hover {
    background-color: #c82333;
    border-color: #bd2130;
}

.collapsed-columns.show .action-links {
    border: 2px solid #dc3545;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 15px;
}

.action-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.action-buttons .btn {
    flex: 1;
    text-align: center;
    padding: 10px;
    font-size: 16px;
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-success {
    background-color: #28a745;
    border-color: #28a745;
}

.btn-success:hover {
    background-color: #218838;
    border-color: #1e7e34;
}

@media (max-width: 768px) {
    .action-buttons {
        flex-direction: column;
    }
}

/* Apple 風格 */
body.apple-style {
    background-color: #F5F5F7;
    color: #1D1D1F;
}

.apple-style .container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.apple-style h2 {
    color: #1D1D1F;
    border-bottom: 1px solid #D2D2D7;
}

.apple-style .btn {
    border-radius: 8px;
    transition: all 0.3s ease;
}

.apple-style .btn-primary {
    background-color: #007AFF;
    color: white;
}

.apple-style .btn-primary:hover {
    background-color: #0063CC;
}

.apple-style .btn-success {
    background-color: #34C759;
    color: white;
}

.apple-style .btn-success:hover {
    background-color: #2DA44E;
}

.apple-style .btn-danger {
    background-color: #FF3B30;
    color: white;
}

.apple-style .btn-danger:hover {
    background-color: #D93025;
}

.apple-style .form-control {
    border: 1px solid #D2D2D7;
    border-radius: 8px;
    transition: border-color 0.3s ease;
}

.apple-style .form-control:focus {
    border-color: #007AFF;
    outline: none;
}

.apple-style table {
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
}

.apple-style th {
    background-color: #F5F5F7;
    color: #1D1D1F;
}

.apple-style tr:hover {
    background-color: #F5F5F7;
}

/* 登錄按鈕樣式 */
.login-button .btn {
    padding: 8px 16px;
    font-size: 14px;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
}

/* 登出按鈕樣式 */
.logout-button .btn {
    padding: 8px 16px;
    font-size: 14px;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
}

/* 登錄頁面樣式 */
.login-container {
    max-width: 400px;
    margin: 50px auto;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.login-container h2 {
    text-align: center;
    margin-bottom: 20px;
}

.error-message {
    color: #dc3545;
    margin-bottom: 15px;
    text-align: center;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
}

.form-group input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.btn {
    width: 100%;
    padding: 10px;
    background-color: #007AFF;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.btn:hover {
    background-color: #0056b3;
}

/* 表單按鈕樣式 */
.form-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.form-buttons .btn {
    flex: 1;
    text-align: center;
    padding: 10px;
    font-size: 16px;
}

.btn-secondary {
    background-color: #6c757d;
    border-color: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background-color: #5a6268;
    border-color: #545b62;
}

/* 選擇顯示欄位樣式 */
.field-selector {
    background-color: var(--secondary-color);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.field-selector .collapsible-header {
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.field-selector .collapsible-content {
    margin-top: 10px;
}

.field-selector .field-checkbox {
    display: block;
    margin: 5px 0;
}

/* 清除搜索按鈕樣式 */
.clear-button {
    padding: 6.0px 32px; /* 調整高度和寬度 */
    font-size: 14px;   /* 字體大小保持不變 */
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    background-color: #6c757d; /* 灰色背景 */
    color: white; /* 白色文字 */
    border: none;
    border-radius: 8px; /* 圓角 */
    cursor: pointer;
    transition: background-color 0.3s ease;
    white-space: nowrap; /* 防止文字換行 */
    width: auto; /* 自動寬度 */
    min-width: 120px; /* 最小寬度 */
    height: 28px; /* 調整高度 */
    line-height: 1; /* 確保文字垂直居中 */
}

.clear-button:hover {
    background-color: #5a6268; /* 鼠標懸停時的背景色 */
}

/* 固定表頭樣式 */
.sticky-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 1001 !important;
    background-color: var(--secondary-color) !important;
}

.sticky-header th {
    position: sticky !important;
    top: 0 !important;
    background-color: var(--secondary-color) !important;
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1) !important;
    z-index: 1001 !important;
}

/* 表格容器在有垂直滾動條時的樣式 */
.table-container::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.table-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}