/* 基礎樣式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans TC', sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: #333;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* 頭部樣式 */
.header {
    background: white;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    overflow: hidden;
}

.header-content {
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.header h1 {
    font-size: 2em;
    font-weight: 600;
}

.header h1 i {
    margin-right: 10px;
    color: #ffd700;
}

.header-controls {
    display: flex;
    gap: 10px;
}

/* 按鈕樣式 */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: #333;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-primary {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: #333;
}

.btn-success {
    background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
    color: #333;
}

.btn-danger {
    background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
    color: #333;
}

.btn-warning {
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    color: #333;
}

.btn-info {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
}

.btn-secondary {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    color: #333;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

/* 狀態面板 */
.status-panel {
    margin-bottom: 20px;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
}

.status-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    border-left: 4px solid #667eea;
}

.status-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.status-card.running {
    border-left-color: #43e97b;
}

.status-card.stopped {
    border-left-color: #fa709a;
}

.status-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.status-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ccc;
}

.status-indicator.running {
    background: #43e97b;
    animation: pulse 2s infinite;
}

.status-indicator.stopped {
    background: #fa709a;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(67, 233, 123, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(67, 233, 123, 0); }
    100% { box-shadow: 0 0 0 0 rgba(67, 233, 123, 0); }
}

.status-info {
    font-size: 14px;
    color: #666;
    margin-bottom: 15px;
}

.status-actions {
    display: flex;
    gap: 8px;
}

/* 標籤頁樣式 */
.tab-nav {
    background: white;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    overflow-x: auto;
}

.tab-buttons {
    display: flex;
    padding: 0;
    min-width: max-content;
}

.tab-button {
    padding: 15px 25px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #666;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}

.tab-button:hover {
    background: #f8f9fa;
    color: #333;
}

.tab-button.active {
    color: #667eea;
    border-bottom-color: #667eea;
    background: #f8f9ff;
}

/* 標籤內容 */
.tab-content {
    background: white;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.tab-pane {
    padding: 30px;
    display: none;
}

.tab-pane.active {
    display: block;
}

/* 統計面板 */
.stats-panel {
    margin-bottom: 30px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.update-info {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 15px;
    font-size: 14px;
    color: #495057;
    font-family: monospace;
    line-height: 1.4;
}

.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.stat-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    border: 1px solid #e9ecef;
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.stat-value {
    font-size: 2em;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

.stat-card.positive .stat-value {
    color: #28a745;
}

.stat-card.negative .stat-value {
    color: #dc3545;
}

.stat-card.neutral .stat-value {
    color: #6c757d;
}

/* 機器人倉位統計 */
.robot-positions {
    margin-top: 20px;
}

/* 添加表格包裝器以支持水平滾動 */
.positions-table-wrapper {
    overflow-x: auto;
    overflow-y: visible;
    max-width: 100%;
    -webkit-overflow-scrolling: touch; /* iOS平滑滾動 */
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    position: relative; /* 為sticky定位提供定位上下文 */
    /* 確保sticky定位正常工作 */
    height: auto;
    width: 100%;
}

.positions-table {
    width: 100%;
    min-width: 800px; /* 確保表格有最小寬度以觸發水平滾動 */
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    position: relative; /* 為sticky定位提供定位上下文 */
}

.positions-table th,
.positions-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #f1f3f4;
    white-space: nowrap;
    min-width: 120px; /* 確保每欄有最小寬度 */
}

/* 商品名稱列固定 - 強化設置 */
.positions-table th:first-child,
.positions-table td:first-child {
    min-width: 140px !important; /* 商品名稱欄位寬一點 */
    position: -webkit-sticky !important; /* Safari支持 */
    position: sticky !important;
    left: 0 !important;
    background: white !important;
    z-index: 5 !important;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1) !important;
}

.positions-table th:first-child {
    background: #f8f9fa !important;
    z-index: 15 !important;
}

.positions-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #333;
    position: -webkit-sticky; /* Safari支持 */
    position: sticky;
    top: 0;
    z-index: 10;
}

.positions-table tr:hover {
    background: #f8f9ff;
}

/* 確保hover效果在固定列上也能正常顯示 */
.positions-table tr:hover td:first-child {
    background: #f8f9ff;
}

/* 數據表格 */
.data-section {
    margin-top: 20px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.section-title {
    font-size: 20px;
    font-weight: 600;
    color: #333;
}

.filter-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.filter-select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
}

.filter-select:hover {
    border-color: #667eea;
}

.filter-select:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.table-container {
    margin-top: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.table-wrapper {
    overflow-x: auto;
    overflow-y: visible;
    max-width: 100%;
    -webkit-overflow-scrolling: touch; /* iOS平滑滾動 */
}

.data-table {
    width: 100%;
    min-width: 1200px; /* 確保表格有最小寬度 */
    border-collapse: collapse;
    font-size: 14px;
    background: white;
}

.data-table th,
.data-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #f1f3f4;
    white-space: nowrap;
    min-width: 120px; /* 確保每欄有最小寬度 */
}

/* 重要欄位寬度調整 */
.data-table th:first-child,
.data-table td:first-child {
    min-width: 140px; /* 倉位差異欄位寬一點 */
    position: sticky;
    left: 0;
    background: white;
    z-index: 5;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
}

.data-table th:first-child {
    background: #f8f9fa;
    z-index: 15;
}

.data-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table th:hover {
    background: #e9ecef;
}

.data-table th.sortable::after {
    content: '\f0dc';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    margin-left: 8px;
    opacity: 0.5;
}

.data-table th.sort-asc::after {
    content: '\f0de';
    opacity: 1;
    color: #667eea;
}

.data-table th.sort-desc::after {
    content: '\f0dd';
    opacity: 1;
    color: #667eea;
}

.data-table tr:nth-child(even) {
    background: #fafbfc;
}

.data-table tr:hover {
    background: #f8f9ff;
}

.data-table td.number {
    text-align: right;
    font-family: 'Courier New', monospace;
}

.data-table td.positive {
    color: #28a745;
    font-weight: 600;
}

.data-table td.negative {
    color: #dc3545;
    font-weight: 600;
}

.data-table td.zero {
    color: #6c757d;
}

/* 載入遮罩 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    display: none;
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    text-align: center;
    color: #667eea;
}

.loading-spinner i {
    font-size: 3em;
    margin-bottom: 15px;
}

.loading-spinner p {
    font-size: 16px;
    font-weight: 500;
}

/* 通知彈窗 */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border-left: 4px solid #667eea;
    z-index: 10000;
    transform: translateX(400px);
    transition: transform 0.3s ease;
    max-width: 350px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.notification.show {
    transform: translateX(0);
}

.notification.success {
    border-left-color: #28a745;
}

.notification.error {
    border-left-color: #dc3545;
}

.notification.warning {
    border-left-color: #ffc107;
}

.notification-close {
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    font-size: 16px;
    padding: 0;
    margin-left: auto;
}

.notification-close:hover {
    color: #333;
}

/* 響應式設計 */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .header-content {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .header-controls {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .status-grid {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .tab-buttons {
        flex-wrap: wrap;
        gap: 5px;
        overflow-x: auto;
        padding: 10px 0;
    }
    
    .tab-button {
        flex: 0 0 auto;
        min-width: 120px;
        font-size: 14px;
        padding: 8px 12px;
    }
    
    /* 表格在手機上的優化 */
    .data-table {
        font-size: 12px;
        min-width: 800px; /* 手機上也保持最小寬度，依靠橫向滾動 */
    }
    
    .data-table th,
    .data-table td {
        padding: 8px 10px;
        min-width: 100px;
    }
    
    .data-table th:first-child,
    .data-table td:first-child {
        min-width: 120px;
    }
    
    /* 機器人倉位統計表格在手機上的優化 */
    .positions-table {
        font-size: 12px;
        min-width: 600px; /* 手機上也保持最小寬度，依靠橫向滾動 */
    }
    
    .positions-table th,
    .positions-table td {
        padding: 8px 10px;
        min-width: 100px;
    }
    
    .positions-table th:first-child,
    .positions-table td:first-child {
        min-width: 120px !important; /* 商品名稱欄位在手機上的最小寬度 */
        position: -webkit-sticky !important; /* Safari支持 */
        position: sticky !important;
        left: 0 !important;
        background: white !important;
        z-index: 5 !important;
    }
    
    /* 橫向滾動提示 */
    .table-wrapper::after {
        content: "👈 左右滑動查看更多欄位";
        display: block;
        text-align: center;
        padding: 10px;
        background: #f8f9fa;
        color: #666;
        font-size: 12px;
        border-top: 1px solid #e9ecef;
    }
    
    /* 機器人倉位統計表格的滾動提示 */
    .positions-table-wrapper::after {
        content: "👈 左右滑動查看更多欄位";
        display: block;
        text-align: center;
        padding: 10px;
        background: #f8f9fa;
        color: #666;
        font-size: 12px;
        border-top: 1px solid #e9ecef;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .section-header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .data-table th,
    .data-table td {
        padding: 6px 8px;
        font-size: 11px;
    }
    
    /* 機器人倉位統計表格在最小螢幕上的優化 */
    .positions-table th,
    .positions-table td {
        padding: 6px 8px;
        font-size: 11px;
    }
}

/* 自定義滾動條 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 動畫效果 */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

/* 表格排序指示器 */
.sort-indicator {
    display: inline-block;
    margin-left: 5px;
    opacity: 0.5;
}

.sort-indicator.active {
    opacity: 1;
    color: #667eea;
}

/* 執行記錄過濾器面板樣式 */
.filter-panel {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.filter-item {
    display: flex;
    flex-direction: column;
}

.filter-item label {
    font-size: 13px;
    font-weight: 500;
    color: #495057;
    margin-bottom: 6px;
}

.filter-item input[type="date"],
.filter-item input[type="text"],
.filter-item select {
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    background: white;
    font-size: 14px;
    color: #333;
    transition: all 0.2s ease;
    outline: none;
}

.filter-item input[type="date"]:focus,
.filter-item input[type="text"]:focus,
.filter-item select:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.filter-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* 響應式過濾器設計 */
@media (max-width: 768px) {
    .filter-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .filter-actions {
        justify-content: stretch;
    }

    .filter-actions .btn {
        flex: 1;
    }
} 