/* ==================== CSS 變數定義 - 主題系統 ==================== */
:root {
    /* 主色調 */
    --color-primary: #667eea;
    --color-primary-light: #5dade2;
    --color-primary-dark: #5568d3;
    --color-secondary: #76d7c4;
    --color-accent: #ff9800;
    
    /* 背景色 */
    --color-body-bg: linear-gradient(135deg, #a8d8ea 0%, #d4f1f4 100%);
    --color-container-bg: #ffffff;
    --color-section-bg: #f9f9f9;
    --color-header-bg: linear-gradient(135deg, #5dade2 0%, #76d7c4 100%);
    --color-footer-bg: #f5f5f5;
    
    /* 文字顏色 */
    --color-text-primary: #333333;
    --color-text-secondary: #555555;
    --color-text-muted: #888888;
    --color-text-light: #ffffff;
    
    /* 邊框顏色 */
    --color-border-light: #ddd;
    --color-border-medium: #ccc;
    
    /* 區域顏色 */
    --color-region-hk: #667eea;
    --color-region-mo: #e91e63;
    
    /* 類別顏色 */
    --color-category-a: #4caf50;
    --color-category-b: #2196f3;
    --color-category-c: #ff9800;
    --color-category-d: #f44336;
    
    /* 狀態顏色 */
    --color-success: #4caf50;
    --color-warning: #ff9800;
    --color-danger: #f44336;
    --color-info: #2196f3;
    --color-highlight: #ffeb3b;
    
    /* 表格顏色 */
    --color-table-header-bg: #667eea;
    --color-table-header-text: #ffffff;
    --color-table-row-even: #f9f9f9;
    --color-table-row-hover: #f0f4ff;
    --color-table-total-bg: #e8f5e9;
    --color-table-carry-bg: #fff3e0;
    
    /* 按鈕顏色 */
    --color-btn-primary-bg: #667eea;
    --color-btn-primary-hover: #5568d3;
    --color-btn-secondary-bg: #e0e0e0;
    --color-btn-success-bg: #4caf50;
    --color-btn-warning-bg: #ff9800;
    --color-btn-danger-bg: #f44336;
    --color-btn-info-bg: #2196f3;
    
    /* 滾動條 */
    --color-scrollbar-track: #f1f1f1;
    --color-scrollbar-thumb: #c1c1c1;
    --color-scrollbar-thumb-hover: #a8a8a8;
    
    /* 陰影 */
    --shadow-container: 0 20px 60px rgba(0, 0, 0, 0.3);
    --shadow-card: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-button: 0 5px 15px rgba(102, 126, 234, 0.4);
}

/* ==================== 全局樣式 ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--color-body-bg);
    color: var(--color-text-primary);
    line-height: 1.6;
    min-height: 100vh;
    padding: 20px;
    transition: background 0.3s ease, color 0.3s ease;
}

/* ==================== 容器和佈局 ==================== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    background: var(--color-container-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-container);
    overflow: hidden;
    transition: background 0.3s ease;
}

header {
    background: var(--color-header-bg);
    color: var(--color-text-light);
    padding: 30px;
    text-align: center;
    transition: background 0.3s ease;
}

header h1 {
    font-size: 2.2em;
    margin-bottom: 8px;
    font-weight: bold;
}

.subtitle {
    font-size: 1em;
    opacity: 0.9;
}

main {
    padding: 30px;
}

footer {
    background: var(--color-footer-bg);
    color: var(--color-text-secondary);
    text-align: center;
    padding: 15px;
    font-size: 0.85em;
    border-top: 1px solid var(--color-border-light);
    transition: background 0.3s ease, color 0.3s ease;
}

/* ==================== 區域樣式 ==================== */
.section {
    margin-bottom: 30px;
    padding: 20px;
    background: var(--color-section-bg);
    border-radius: 8px;
    border-left: 5px solid var(--color-primary);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.section h2 {
    font-size: 1.4em;
    margin-bottom: 15px;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color 0.3s ease;
}

.section h3 {
    font-size: 1.1em;
    margin: 20px 0 10px 0;
    color: var(--color-text-secondary);
    transition: color 0.3s ease;
}

.hint {
    color: var(--color-text-muted);
    font-size: 0.9em;
    margin: 5px 0 15px 0;
    transition: color 0.3s ease;
}

/* ==================== 按鈕樣式 ==================== */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-block;
}

.btn-large {
    padding: 12px 24px;
    font-size: 1em;
}

.btn-primary {
    background: var(--color-btn-primary-bg);
    color: var(--color-text-light);
}

.btn-primary:hover {
    background: var(--color-btn-primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-button);
}

.btn-secondary {
    background: var(--color-btn-secondary-bg);
    color: var(--color-text-primary);
}

.btn-secondary:hover {
    background: var(--color-border-medium);
}

.btn-success {
    background: var(--color-btn-success-bg);
    color: var(--color-text-light);
}

.btn-success:hover {
    background: var(--color-success);
    filter: brightness(0.9);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(76, 175, 80, 0.4);
}

.btn-info {
    background: var(--color-btn-info-bg);
    color: var(--color-text-light);
}

.btn-info:hover {
    background: var(--color-info);
    filter: brightness(0.9);
}

.btn-warning {
    background: var(--color-btn-warning-bg);
    color: var(--color-text-light);
}

.btn-warning:hover {
    background: var(--color-warning);
    filter: brightness(0.9);
}

.btn-danger {
    background: var(--color-btn-danger-bg);
    color: var(--color-text-light);
}

.btn-danger:hover {
    background: var(--color-danger);
    filter: brightness(0.9);
}

.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 15px;
}

/* ==================== Safety Stock Matrix 樣式 ==================== */
.matrix-section {
    border-left-color: var(--color-success);
}

/* ==================== 權重快速設定面板樣式 ==================== */
.weight-settings-panel {
    background: var(--color-container-bg);
    border-radius: 8px;
    margin-bottom: 20px;
    border: 2px solid var(--color-primary);
    overflow: hidden;
}

.weight-toggle-btn {
    width: 100%;
    padding: 12px;
    background: var(--color-primary);
    color: var(--color-text-light);
    border: none;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.weight-toggle-btn:hover {
    filter: brightness(0.9);
}

.weight-toggle-btn.active {
    background: var(--color-primary-dark);
}

.weight-content {
    padding: 20px;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 2000px;
    }
}

.weight-group {
    margin-bottom: 20px;
    padding: 15px;
    background: var(--color-section-bg);
    border-radius: 6px;
}

.weight-group h4 {
    margin-bottom: 12px;
    color: var(--color-text-primary);
    font-size: 0.95em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.weight-hint {
    margin-top: 10px;
    margin-bottom: 0;
    font-size: 0.85em;
    color: var(--color-text-muted);
}

.weight-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 10px;
}

.weight-inputs label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85em;
    color: var(--color-text-secondary);
    text-align: center;
}

.weight-label-text {
    font-weight: 600;
}

.weight-label-a .weight-label-text { color: var(--color-category-a); }
.weight-label-b .weight-label-text { color: var(--color-category-b); }
.weight-label-c .weight-label-text { color: var(--color-category-c); }
.weight-label-d .weight-label-text { color: var(--color-category-d); }

.weight-input {
    padding: 8px;
    border: 1px solid var(--color-border-light);
    border-radius: 4px;
    text-align: center;
    font-size: 1em;
    font-weight: 600;
    background: var(--color-container-bg);
    color: var(--color-text-primary);
    transition: all 0.2s ease;
}

.weight-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.template-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.template-btn {
    font-size: 0.85em;
    padding: 6px 12px;
}

.weight-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: flex-end;
}

.weight-preview {
    margin-top: 20px;
    padding: 15px;
    background: var(--color-container-bg);
    border-radius: 6px;
    border: 1px solid var(--color-border-light);
}

.weight-preview h4 {
    margin-bottom: 15px;
    color: var(--color-text-primary);
    font-size: 1em;
}

.weight-preview-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.weight-preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
}

.weight-preview-table th,
.weight-preview-table td {
    border: 1px solid var(--color-border-light);
    padding: 6px 8px;
    text-align: center;
}

.weight-preview-table th {
    background: var(--color-footer-bg);
    font-weight: 600;
    color: var(--color-text-primary);
}

.weight-preview-table .region-header {
    font-weight: bold;
    background: var(--color-table-row-even);
}

.weight-preview-table .value-cell {
    font-weight: 600;
}

.weight-preview-summary {
    padding: 12px;
    background: var(--color-section-bg);
    border-radius: 4px;
    font-size: 0.9em;
    line-height: 1.8;
}

/* ==================== 算式簡介樣式 (摺疊式) ==================== */
.weight-formula-intro {
    background: linear-gradient(135deg, #f0f4ff 0%, #e8f5e9 100%);
    border-radius: 12px;
    margin-bottom: 20px;
    border: 2px solid var(--color-primary-light);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.1);
    overflow: hidden;
}

.formula-toggle-btn {
    width: 100%;
    padding: 15px 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 1.1em;
    font-weight: 600;
    color: var(--color-primary);
    transition: all 0.3s ease;
}

.formula-toggle-btn:hover {
    background: rgba(102, 126, 234, 0.05);
}

.formula-toggle-btn .toggle-icon {
    font-size: 0.8em;
    transition: transform 0.3s ease;
}

.formula-toggle-btn.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.formula-content {
    padding: 0 20px 20px 20px;
    animation: slideDown 0.3s ease;
}

.formula-content.collapsed {
    display: none;
}

.formula-box {
    background: var(--color-container-bg);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    border-left: 4px solid var(--color-primary);
}

.formula-title {
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 8px;
    font-size: 0.9em;
}

.formula-code {
    display: block;
    background: #f8f9fa;
    padding: 12px 15px;
    border-radius: 6px;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.95em;
    color: var(--color-primary-dark);
    font-weight: 600;
    word-wrap: break-word;
    line-height: 1.5;
}

.formula-params {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.param-item {
    background: var(--color-container-bg);
    padding: 10px 12px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.param-name {
    font-weight: 700;
    color: var(--color-text-primary);
    font-size: 0.9em;
}

.param-desc {
    font-size: 0.85em;
    color: var(--color-text-secondary);
    line-height: 1.4;
}

.formula-example {
    background: linear-gradient(135deg, #fff8e1 0%, #ffecb3 100%);
    border-radius: 8px;
    padding: 15px;
    border-left: 4px solid var(--color-warning);
}

.example-title {
    font-weight: 700;
    color: var(--color-warning);
    margin-bottom: 10px;
    font-size: 0.95em;
}

.example-content {
    font-size: 0.9em;
    color: var(--color-text-primary);
    line-height: 1.6;
}

.example-content p {
    margin: 5px 0;
}

.example-content strong {
    color: var(--color-primary);
}

.example-note {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--color-border-light);
    color: var(--color-text-muted);
    font-size: 0.85em;
}

@media (max-width: 768px) {
    .weight-inputs {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .weight-preview-content {
        grid-template-columns: 1fr;
    }
    
    .weight-actions {
        flex-direction: column;
    }
}

/* ==================== Matrix Controls ==================== */
.matrix-controls {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
}

.matrix-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

.matrix-region {
    background: var(--color-container-bg);
    padding: 15px;
    border-radius: 8px;
    box-shadow: var(--shadow-card);
    transition: background 0.3s ease;
}

.region-title {
    font-size: 1.1em;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 10px;
    color: var(--color-text-light);
}

.region-title.region-hk {
    background: var(--color-region-hk);
}

.region-title.region-mo {
    background: var(--color-region-mo);
}

.matrix-table {
    width: 100%;
    border-collapse: collapse;
}

.matrix-table th,
.matrix-table td {
    border: 1px solid var(--color-border-light);
    padding: 8px 10px;
    text-align: center;
    transition: border-color 0.3s ease;
}

.matrix-table th {
    background: var(--color-footer-bg);
    font-weight: 600;
    color: var(--color-text-primary);
    transition: background 0.3s ease, color 0.3s ease;
}

.category-cell {
    font-weight: 600;
    text-align: left !important;
}

.category-cell.category-a { background: rgba(76, 175, 80, 0.15); color: var(--color-category-a); }
.category-cell.category-b { background: rgba(33, 150, 243, 0.15); color: var(--color-category-b); }
.category-cell.category-c { background: rgba(255, 152, 0, 0.15); color: var(--color-category-c); }
.category-cell.category-d { background: rgba(244, 67, 54, 0.15); color: var(--color-category-d); }

.matrix-cell {
    cursor: pointer;
    transition: background 0.2s;
}

.matrix-cell:hover {
    background: var(--color-table-row-hover);
}

.matrix-cell.editing {
    background: var(--color-highlight);
}

.matrix-cell .display-value {
    font-weight: 600;
    font-size: 1.1em;
}

.matrix-cell .edit-value {
    width: 60px;
    padding: 4px;
    border: 2px solid var(--color-primary);
    border-radius: 4px;
    text-align: center;
    font-size: 1em;
    background: var(--color-container-bg);
    color: var(--color-text-primary);
}

/* ==================== 店鋪選擇樣式 ==================== */
.stores-section {
    border-left-color: var(--color-primary);
}

/* 控制欄樣式 - 更現代的設計 */
.filter-controls {
    margin-bottom: 20px;
}

.filter-controls .button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(135deg, var(--color-section-bg) 0%, var(--color-container-bg) 100%);
    border-radius: 12px;
    border: 1px solid var(--color-border-light);
}

.store-count {
    font-size: 0.95em;
    color: var(--color-text-secondary);
    padding: 10px 16px;
    background: var(--color-container-bg);
    border-radius: 20px;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    transition: all 0.3s ease;
}

/* ==================== 左右兩欄佈局 ==================== */
.stores-selector-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
    margin-bottom: 25px;
    align-items: stretch;
}

@media (max-width: 1100px) {
    .stores-selector-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

/* 左側篩選面板 */
.selector-left-panel {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

/* 右側店鋪清單面板 - 高度與左側對齊 */
.selector-right-panel {
    background: var(--color-container-bg);
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* 篩選區域 - 卡片化設計 */
.category-filters {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
    background: var(--color-container-bg);
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
    border: 1px solid #f1f5f9;
    transition: all 0.3s ease;
}

.filter-group:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.06);
    border-color: #e2e8f0;
}

.filter-label {
    font-weight: 700;
    color: var(--color-text-primary);
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-label::before {
    content: '';
    width: 4px;
    height: 16px;
    background: var(--color-primary);
    border-radius: 2px;
}

.filter-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 8px 16px;
    border: 2px solid #e2e8f0;
    background: white;
    color: var(--color-text-secondary);
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.25s ease;
    font-size: 0.85em;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.filter-btn:hover {
    border-color: var(--color-primary);
    background: var(--color-table-row-hover);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(102, 126, 234, 0.15);
}

.filter-btn.active {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: var(--color-text-light);
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.35);
}

/* 店鋪組別按鈕樣式 */
.store-group-buttons {
    gap: 10px;
}

.store-group-btn {
    min-width: 50px;
    padding: 10px 20px;
    font-weight: 700;
    font-size: 0.9em;
    border-radius: 10px;
}

.store-group-btn.active {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.35);
}

/* OM 群組樣式 */
.om-group {
    background: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%);
    border: 1px solid #e9d5ff;
}

.om-group .filter-label::before {
    background: linear-gradient(135deg, #9333ea 0%, #7c3aed 100%);
}

/* 右側 OM 面板樣式 - 可捲動 */
.selector-right-panel .om-stores-panel {
    margin-top: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    border: none;
    box-shadow: none;
    border-radius: 0;
}

.selector-right-panel .om-stores-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* 空狀態提示 */
.om-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.om-empty-icon {
    font-size: 4em;
    margin-bottom: 20px;
    opacity: 0.5;
}

.om-empty-state p {
    font-size: 1.1em;
    color: var(--color-text-secondary);
    margin-bottom: 8px;
}

.om-empty-hint {
    font-size: 0.95em;
    color: var(--color-text-muted);
}

/* 店鋪佈局 */
.stores-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 25px;
}

@media (max-width: 1000px) {
    .stores-layout {
        grid-template-columns: 1fr;
    }
}

/* 店鋪容器 */
.stores-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
    background: var(--color-container-bg);
    padding: 20px;
    border-radius: 12px;
    max-height: 550px;
    overflow-y: auto;
    transition: all 0.3s ease;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

.store-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 10px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.25s ease;
    font-size: 0.95em;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.store-item:hover {
    background: white;
    border-color: var(--color-primary);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.15);
}

.store-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--color-primary);
    border-radius: 4px;
}

.store-item .store-name {
    flex: 1;
    cursor: pointer;
    font-weight: 600;
    min-width: 80px;
    color: var(--color-text-primary);
    font-size: 0.95em;
}

.store-item .store-code {
    font-size: 0.8em;
    color: var(--color-text-muted);
    font-family: 'SF Mono', monospace;
    background: #e2e8f0;
    padding: 3px 8px;
    border-radius: 6px;
    font-weight: 600;
}

.store-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.75em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.store-badge.region-hk {
    background: linear-gradient(135deg, var(--color-region-hk) 0%, #5a67d8 100%);
    color: var(--color-text-light);
}

.store-badge.region-mo {
    background: linear-gradient(135deg, var(--color-region-mo) 0%, #c2185b 100%);
    color: var(--color-text-light);
}

.store-badge.category-a { background: linear-gradient(135deg, var(--color-category-a) 0%, #388e3c 100%); color: var(--color-text-light); }
.store-badge.category-b { background: linear-gradient(135deg, var(--color-category-b) 0%, #1976d2 100%); color: var(--color-text-light); }
.store-badge.category-c { background: linear-gradient(135deg, var(--color-category-c) 0%, #f57c00 100%); color: var(--color-text-light); }
.store-badge.category-d { background: linear-gradient(135deg, var(--color-category-d) 0%, #d32f2f 100%); color: var(--color-text-light); }

.store-badge.size-badge {
    background: linear-gradient(135deg, #64748b 0%, #475569 100%);
    color: var(--color-text-light);
}

.store-safety-stock {
    font-weight: 700;
    color: var(--color-success);
    min-width: 30px;
    text-align: center;
    font-size: 1em;
    background: rgba(76, 175, 80, 0.1);
    padding: 4px 8px;
    border-radius: 6px;
}

/* 可編輯店鋪 Safety Stock */
.editable-store-stock {
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.editable-store-stock:hover {
    background: var(--color-highlight);
    box-shadow: 0 0 0 2px var(--color-warning);
}

.editable-store-stock.editing {
    background: var(--color-highlight);
    box-shadow: 0 0 0 2px var(--color-accent);
}

.store-stock-input {
    width: 50px;
    padding: 5px;
    border: 2px solid var(--color-primary);
    border-radius: 6px;
    text-align: center;
    font-size: 0.95em;
    font-weight: 700;
    color: var(--color-success);
    background: var(--color-container-bg);
}

.store-stock-input:focus {
    outline: none;
    border-color: var(--color-primary-dark);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

/* 店鋪預覽 */
.stores-preview {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    padding: 20px;
    border-radius: 12px;
    max-height: 550px;
    overflow-y: auto;
    transition: all 0.3s ease;
    border: 1px solid #e2e8f0;
}

.no-selection {
    text-align: center;
    color: var(--color-text-muted);
    padding: 40px 30px;
}

.no-selection p:first-child {
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--color-text-secondary);
}

.preview-summary {
    padding: 14px 16px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 215, 196, 0.1) 100%);
    border-radius: 10px;
    margin-bottom: 18px;
    font-weight: 600;
    color: var(--color-text-primary);
    border: 1px solid rgba(102, 126, 234, 0.15);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preview-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.9em;
    border-radius: 10px;
    overflow: hidden;
}

.preview-table th,
.preview-table td {
    border: none;
    border-bottom: 1px solid #e2e8f0;
    padding: 10px 12px;
    text-align: left;
    transition: all 0.2s ease;
}

.preview-table th {
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    font-weight: 700;
    color: var(--color-text-primary);
    text-transform: uppercase;
    font-size: 0.8em;
    letter-spacing: 0.5px;
}

.preview-table tbody tr:hover {
    background: rgba(102, 126, 234, 0.03);
}

.preview-table tfoot .total-row {
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    font-weight: 700;
}

.preview-table tfoot .total-row td {
    border-bottom: none;
    font-size: 1.05em;
}

/* ==================== 結果區域樣式 ==================== */
.results-section {
    border-left-color: var(--color-success);
}

.results-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.stat-item {
    background: var(--color-container-bg);
    padding: 15px;
    border-radius: 8px;
    box-shadow: var(--shadow-card);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.3s ease;
}

.stat-item label {
    font-weight: 600;
    color: var(--color-text-secondary);
}

.stat-value {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--color-text-primary);
}

.stat-highlight {
    background: var(--color-highlight);
}

.stat-highlight .stat-value {
    color: var(--color-text-primary);
}

/* 結果表格 */
.results-container,
.detail-container {
    background: var(--color-container-bg);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    overflow-x: auto;
    transition: background 0.3s ease;
}

.results-table,
.detail-table {
    width: 100%;
    border-collapse: collapse;
}

.results-table th,
.results-table td,
.detail-table th,
.detail-table td {
    border: 1px solid var(--color-border-light);
    padding: 10px;
    text-align: left;
    transition: border-color 0.3s ease;
}

.results-table th,
.detail-table th {
    background: var(--color-table-header-bg);
    color: var(--color-table-header-text);
    font-weight: 600;
}

.results-table tbody tr:nth-child(even),
.detail-table tbody tr:nth-child(even) {
    background: var(--color-table-row-even);
}

.results-table tbody tr:hover,
.detail-table tbody tr:hover {
    background: var(--color-table-row-hover);
}

.group-header td {
    background: rgba(59, 130, 246, 0.15);
    font-weight: bold;
    font-size: 1.1em;
    text-align: center;
    color: var(--color-text-primary);
}

.region-header-hk {
    background: var(--color-region-hk) !important;
    color: var(--color-text-light) !important;
}

.region-header-mo {
    background: var(--color-region-mo) !important;
    color: var(--color-text-light) !important;
}

.total-row td {
    background: var(--color-table-total-bg) !important;
    font-weight: bold;
    border-top: 2px solid var(--color-success);
}

.carry-row td {
    background: var(--color-table-carry-bg) !important;
    font-weight: bold;
}

.empty-message {
    text-align: center;
    color: var(--color-text-muted);
    padding: 30px !important;
}

/* Badge 樣式 */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: 600;
}

.badge.category-a { background: rgba(76, 175, 80, 0.15); color: var(--color-category-a); }
.badge.category-b { background: rgba(33, 150, 243, 0.15); color: var(--color-category-b); }
.badge.category-c { background: rgba(255, 152, 0, 0.15); color: var(--color-category-c); }
.badge.category-d { background: rgba(244, 67, 54, 0.15); color: var(--color-category-d); }

/* Carry 狀態 */
.carry-status {
    font-weight: bold;
    text-align: center;
}

.carry-yes {
    color: var(--color-success);
}

.carry-no {
    color: var(--color-danger);
}

/* 可編輯單元格 */
.editable-cell {
    cursor: pointer;
    transition: background 0.2s;
}

.editable-cell:hover {
    background: var(--color-highlight) !important;
}

.editable-cell.editing {
    background: var(--color-highlight) !important;
}

.editable-cell .display-value {
    font-weight: 600;
}

.editable-cell .edit-value {
    width: 70px;
    padding: 4px;
    border: 2px solid var(--color-primary);
    border-radius: 4px;
    text-align: center;
    font-size: 1em;
    background: var(--color-container-bg);
    color: var(--color-text-primary);
}

/* ==================== 店鋪管理樣式 ==================== */
.stores-management-section {
    border-left-color: var(--color-warning);
}

.management-controls {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
}

.stores-editor {
    width: 100%;
    height: 400px;
    padding: 15px;
    border: 2px solid var(--color-border-light);
    border-radius: 6px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
    resize: vertical;
    background: var(--color-container-bg);
    color: var(--color-text-primary);
    transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.stores-format-hint {
    background: var(--color-container-bg);
    padding: 15px;
    border-radius: 6px;
    margin-top: 15px;
    transition: background 0.3s ease;
}

.stores-format-hint h4 {
    margin-bottom: 10px;
    color: var(--color-text-secondary);
}

.stores-format-hint pre {
    background: var(--color-section-bg);
    padding: 15px;
    border-radius: 4px;
    font-size: 0.85em;
    overflow-x: auto;
    color: var(--color-text-primary);
    transition: background 0.3s ease, color 0.3s ease;
}

/* ==================== 主題選擇器樣式 ==================== */
.theme-selector {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

.theme-selector-btn {
    background: var(--color-container-bg);
    border: 2px solid var(--color-primary);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    box-shadow: var(--shadow-card);
    transition: all 0.3s ease;
}

.theme-selector-btn:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-container);
}

.theme-panel {
    position: absolute;
    top: 55px;
    right: 0;
    background: var(--color-container-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-container);
    padding: 15px;
    min-width: 280px;
    display: none;
    border: 1px solid var(--color-border-light);
}

.theme-panel.active {
    display: block;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes slideDown {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
}

.theme-panel h3 {
    margin: 0 0 15px 0;
    font-size: 1em;
    color: var(--color-text-primary);
    border-bottom: 2px solid var(--color-primary);
    padding-bottom: 8px;
}

.theme-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.theme-option:hover {
    background: var(--color-section-bg);
    border-color: var(--color-primary);
}

.theme-option.active {
    background: var(--color-table-row-hover);
    border-color: var(--color-primary);
}

.theme-preview {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1em;
}

.theme-info {
    flex: 1;
}

.theme-name {
    font-weight: 600;
    font-size: 0.95em;
    color: var(--color-text-primary);
}

.theme-desc {
    font-size: 0.8em;
    color: var(--color-text-muted);
}

.theme-sasa { background: linear-gradient(135deg, #E6007E 0%, #FF1493 100%); color: #fff; }
.theme-corporate { background: linear-gradient(135deg, #5dade2 0%, #76d7c4 100%); }
.theme-dark { background: linear-gradient(135deg, #1a1b26 0%, #2a2e3f 100%); color: #fff; }
.theme-warm { background: linear-gradient(135deg, #f4a261 0%, #e9c46a 100%); }
.theme-highcontrast { background: #000080; color: #fff; }
.theme-elegant { background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%); color: #fff; }
.theme-minimal { background: #374151; color: #fff; }

/* ==================== 響應式設計 ==================== */
@media (max-width: 1200px) {
    .filter-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 1100px) {
    .stores-selector-layout {
        grid-template-columns: 1fr;
    }
    
    .selector-right-panel {
        position: relative;
        top: 0;
        order: -1;
    }
    
    .selector-right-panel .om-stores-panel {
        min-height: 300px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    header h1 {
        font-size: 1.5em;
    }
    
    main {
        padding: 15px;
    }
    
    .section {
        padding: 15px;
    }
    
    /* 雙欄佈局響應式 */
    .selector-left-panel {
        padding: 15px;
    }
    
    .selector-right-panel .om-stores-panel {
        min-height: 250px;
    }
    
    /* 篩選區域響應式 */
    .category-filters {
        gap: 12px;
    }
    
    .filter-group {
        padding: 12px;
    }
    
    .filter-buttons {
        gap: 6px;
    }
    
    .filter-btn {
        padding: 6px 12px;
        font-size: 0.8em;
    }
    
    /* 店鋪組別響應式 */
    .store-group-btn {
        padding: 8px 16px;
        min-width: 45px;
    }
    
    /* OM 按鈕響應式 */
    .om-filter-buttons {
        gap: 8px;
    }
    
    .om-filter-btn {
        padding: 10px 14px;
        min-width: 75px;
    }
    
    .om-filter-btn .om-name {
        font-size: 0.9em;
    }
    
    .om-filter-btn .om-count {
        font-size: 0.75em;
    }
    
    /* OM 面板響應式 */
    .om-stores-grid {
        grid-template-columns: 1fr;
    }
    
    .om-stores-summary {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    /* 店鋪列表響應式 */
    .stores-container {
        grid-template-columns: 1fr;
        padding: 15px;
    }
    
    .store-item {
        padding: 10px 12px;
    }
    
    .stores-layout {
        grid-template-columns: 1fr;
    }
    
    .matrix-container {
        grid-template-columns: 1fr;
    }
    
    .results-controls {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        text-align: center;
    }
    
    .theme-selector {
        top: 10px;
        right: 10px;
    }
    
    .theme-panel {
        right: -10px;
        min-width: 260px;
    }
    
    /* 控制欄響應式 */
    .filter-controls .button-group {
        padding: 12px 15px;
    }
    
    .store-count {
        font-size: 0.85em;
        padding: 8px 12px;
    }
}

/* ==================== 滾動條美化 ==================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-scrollbar-track);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--color-scrollbar-thumb);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-scrollbar-thumb-hover);
}

/* ==================== 打印樣式 ==================== */
@media print {
    body {
        background: white;
        padding: 0;
    }
    
    .container {
        box-shadow: none;
    }
    
    .btn,
    .filter-controls,
    .matrix-controls,
    .management-controls,
    .stores-management-section,
    .theme-selector {
        display: none !important;
    }
    
    .section {
        break-inside: avoid;
    }
}

/* ==================== OM 營運經理篩選樣式 ==================== */
.om-filter-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    padding: 5px;
}

.om-filter-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px 20px;
    min-width: 90px;
    border: 2px solid #e2e8f0;
    background: white;
    color: var(--color-text-primary);
    border-radius: 14px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    line-height: 1.4;
    box-shadow: 0 2px 4px rgba(0,0,0,0.04);
    position: relative;
    overflow: hidden;
}

.om-filter-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-secondary));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.om-filter-btn:hover {
    border-color: var(--color-primary);
    background: white;
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.25);
}

.om-filter-btn:hover::before {
    opacity: 1;
}

.om-filter-btn.active {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: var(--color-text-light);
    border-color: transparent;
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
    transform: translateY(-2px);
}

.om-filter-btn.active::before {
    opacity: 0;
}

.om-filter-btn .om-name {
    font-size: 1em;
    font-weight: 700;
}

.om-filter-btn .om-count {
    font-size: 0.8em;
    opacity: 0.7;
    margin-top: 4px;
    font-weight: 500;
    padding: 2px 8px;
    background: rgba(0,0,0,0.05);
    border-radius: 10px;
}

.om-filter-btn.active .om-count {
    opacity: 0.95;
    background: rgba(255,255,255,0.2);
}

/* OM 店鋪清單面板 */
.om-stores-panel {
    margin-top: 20px;
    background: var(--color-container-bg);
    border: none;
    border-radius: 16px;
    overflow: hidden;
    animation: slideDown 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 20px 40px rgba(0,0,0,0.12);
}

.om-stores-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: var(--color-text-light);
}

.om-stores-header h4 {
    margin: 0;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.close-om-panel {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: var(--color-text-light);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.3em;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.close-om-panel:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1) rotate(90deg);
}

.om-stores-content {
    padding: 20px;
    max-height: 450px;
    overflow-y: auto;
}

.om-stores-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
}

.om-store-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    transition: all 0.25s ease;
}

.om-store-item:hover {
    background: white;
    border-color: var(--color-primary);
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.om-store-code {
    font-family: 'SF Mono', monospace;
    font-size: 0.8em;
    font-weight: 600;
    color: white;
    background: var(--color-text-secondary);
    padding: 4px 8px;
    border-radius: 6px;
    min-width: 50px;
    text-align: center;
}

.om-store-name {
    flex: 1;
    font-size: 0.95em;
    color: var(--color-text-primary);
    font-weight: 500;
}

.om-store-badges {
    display: flex;
    gap: 5px;
}

.om-store-badge {
    font-size: 0.7em;
    padding: 3px 6px;
    border-radius: 4px;
    font-weight: 700;
}

.om-empty-message {
    text-align: center;
    color: var(--color-text-muted);
    padding: 40px;
    font-style: italic;
    font-size: 1.05em;
}

.om-stores-summary {
    margin-top: 20px;
    padding: 16px 20px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95em;
    border: 1px solid #e2e8f0;
}

.om-stores-summary .total-count {
    font-weight: 700;
    color: var(--color-primary);
    font-size: 1.1em;
}

/* ==================== OM 彙總表格樣式 ==================== */
.om-summary-container {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid var(--color-border-medium);
}

.om-summary-container h3 {
    color: var(--color-primary);
    margin-bottom: 10px;
}

.percentage-bar {
    position: relative;
    height: 22px;
    background: var(--color-border-light);
    border-radius: 11px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.percentage-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-secondary));
    border-radius: 11px;
    transition: width 0.5s ease;
    box-shadow: 0 0 8px rgba(102, 126, 234, 0.4);
}

.percentage-bar span {
    position: relative;
    z-index: 1;
    font-size: 12px;
    font-weight: bold;
    color: var(--color-text-primary);
    text-shadow: 0 1px 2px rgba(255,255,255,0.8);
}

.category-detail-row {
    background: var(--color-section-bg) !important;
}

.category-detail-row:hover {
    background: var(--color-section-bg) !important;
}

.category-tags {
    padding: 10px 15px;
    text-align: center;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.om-badge {
    display: inline-block;
    margin: 2px;
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.om-badge-a {
    background: rgba(76, 175, 80, 0.2);
    color: var(--color-category-a);
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.om-badge-b {
    background: rgba(33, 150, 243, 0.2);
    color: var(--color-category-b);
    border: 1px solid rgba(33, 150, 243, 0.3);
}

.om-badge-c {
    background: rgba(255, 152, 0, 0.2);
    color: var(--color-category-c);
    border: 1px solid rgba(255, 152, 0, 0.3);
}

.om-badge-d {
    background: rgba(244, 67, 54, 0.2);
    color: var(--color-category-d);
    border: 1px solid rgba(244, 67, 54, 0.3);
}
