body { font-family: "Microsoft JhengHei", sans-serif; background-color: #f4f7f6; margin: 0; overflow-y: auto; min-height: 100vh; display: flex; flex-direction: column; }
.main-nav { background-color: #2c3e50; display: flex; padding: 0 20px; height: 50px; align-items: center; flex-shrink: 0; position: sticky; top: 0; z-index: 1000; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
.nav-brand { color: #fff; font-weight: bold; font-size: 18px; margin-right: 40px; }
.nav-tab { background: transparent; border: none; color: #bdc3c7; padding: 0 20px; height: 100%; cursor: pointer; font-size: 15px; font-weight: 500; transition: all 0.2s; border-bottom: 3px solid transparent; }
.nav-tab.active { color: #fff; border-bottom-color: #3498db; background: rgba(255,255,255,0.05); }
.tab-content { display: none; padding-bottom: 50px; }
.tab-content.active { display: block; animation: fadeIn 0.3s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Cpk Layout */
.cpk-layout { width: 100%; max-width: 1600px; margin: 0 auto; padding: 20px; }
h1 { text-align: center; color: #005a9c; border-bottom: 2px solid #ddd; padding-bottom: 10px; }
.cpk-setup-grid { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; gap: 20px; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); margin-bottom: 20px; }
.setup-area-left { grid-column: 1 / 2; display: flex; flex-direction: column; gap: 20px; }
.setup-area-right { grid-column: 2 / 3; padding-left: 20px; border-left: 1px solid #eee; }
.setup-area-bottom { grid-column: 1 / 3; border-top: 1px solid #eee; padding-top: 20px; }
.setup-block h2, .setup-area-right h2, .setup-area-bottom h2 { font-size: 16px; color: #333; margin-bottom: 10px; font-weight: bold; }
input[type="file"] { border: 1px solid #ccc; padding: 8px; width: 100%; border-radius: 4px; }
.radio-group label { display: block; margin-bottom: 8px; cursor: pointer; }
select[multiple] { width: 100%; height: 150px; border: 1px solid #ccc; border-radius: 4px; padding: 5px; }
select:not([multiple]) { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; }
.spec-row { display: flex; gap: 20px; }
.input-wrap { flex: 1; display: flex; align-items: center; gap: 10px; background: #f8f9fa; padding: 10px; border-radius: 4px; border: 1px solid #ddd; }
.input-wrap input { flex: 1; border: 1px solid #ccc; padding: 6px; border-radius: 4px; text-align: center; }
.action-btn { width: 100%; padding: 15px; background-color: #005a9c; color: white; border: none; border-radius: 8px; font-size: 18px; font-weight: bold; cursor: pointer; transition: 0.2s; margin-bottom: 20px; }
.export-btn { width: 100%; padding: 10px; background-color: #28a745; color: white; border: none; border-radius: 6px; font-weight: bold; cursor: pointer; margin-bottom: 15px; display: block; }
.export-btn:hover { background-color: #218838; }

.results-container { display: flex; flex-wrap: wrap; gap: 20px; min-height: 500px; }
.card { background: white; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); padding: 20px; }
.card-left, .card-right { flex: 1; min-width: 400px; display: flex; flex-direction: column; }
.chart-container { position: relative; height: 400px; width: 100%; flex: 1; }
#results-display { width: 100%; overflow: auto; max-height: 500px; border: 1px solid #eee; min-height: 400px; }
#results-display table { width: 100%; border-collapse: collapse; margin-top: 0; }
#results-display th, #results-display td { border: 1px solid #b3d7ff; padding: 8px 12px; text-align: left; white-space: nowrap; }
#results-display th { background-color: #e9ecef; position: sticky; top: 0; z-index: 10; }
tr.selected-row { background-color: #fff3cd !important; border-left: 5px solid #ffc107; }
.status-good { color: #28a745; font-weight: bold; } .status-ok { color: #fd7e14; font-weight: bold; } .status-bad { color: #dc3545; font-weight: bold; }

/* New Flex Layout for Cpk Setup */
.cpk-setup-flex-container {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    align-items: stretch;
}

.setup-column {
    flex: 1;
    min-width: 200px;
    border: 1px solid #eee;
    border-radius: 5px;
    padding: 15px;
    background: #fff;
    display: flex;
    flex-direction: column;
}

.setup-column h2 {
    font-size: 15px;
    font-weight: bold;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 2px solid #f0f0f0;
    color: #333;
}

.setup-column .desc-text {
    font-size: 12px;
    color: #777;
    margin-bottom: 10px;
    height: 30px; /* 固定高度讓版面整齊 */
}

.setup-column label {
    font-size: 13px;
    font-weight: bold;
    color: #555;
}

/* 響應式處理：螢幕太小時變垂直排列 */
@media (max-width: 1100px) {
    .cpk-setup-flex-container {
        flex-direction: column;
    }
    .setup-column {
        width: 100%;
    }
}

/* SPC Styles - Refined for Clarity */
.spc-top-bar { background-color: #34495e; color: white; padding: 10px 20px; display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.spc-controls { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; flex: 1; }
.source-select { display: flex; align-items: center; gap: 5px; }
.source-select select { padding: 4px; border-radius: 3px; border: none; }
.tool-group { display: flex; align-items: center; gap: 5px; }
.btn-mini { padding: 4px 8px; background: #3498db; color: white; border: none; border-radius: 3px; cursor: pointer; font-size: 12px; }
.spec-inputs { display: flex; gap: 10px; align-items: center; margin-left: auto; }
.spec-inputs span { font-size: 13px; font-weight: bold; }
.spec-inputs input { width: 70px; padding: 4px; text-align: center; border-radius: 3px; border: 1px solid #ccc; }
.actions-area { display: flex; gap: 8px; }
.btn { padding: 6px 12px; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; color: white; font-size: 13px; }
.btn.success { background: #2ecc71; } .btn.warning { background: #f39c12; } .btn.danger { background: #e74c3c; }

/* Layout & Panel */
.spc-main-container { display: grid; grid-template-columns: var(--left-width, 480px) 5px 1fr; min-height: 800px; background: #ccc; margin: 20px; border: 1px solid #999; }
.spc-left-panel { background: white; display: flex; flex-direction: column; padding: 15px; min-width: 300px; }
.panel-header { font-size: 13px; font-weight: bold; color: #7f8c8d; margin: 15px 0 10px 0; border-bottom: 2px solid #f0f0f0; padding-bottom: 5px; }

/* 修正：統計卡片樣式 (解決字黏在一起的問題) */
.stats-dashboard { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 15px; }
.stat-card { 
    background: #fff; 
    border: 1px solid #eee; 
    padding: 6px 8px; 
    text-align: center; 
    display: flex; 
    flex-direction: column; /* 強制垂直排列 */
    justify-content: center;
    border-radius: 4px;
}
.limit-ucl, .limit-lcl { border-left: 4px solid #e74c3c; }
.stat-title { font-size: 11px; color: #999; margin-bottom: 2px; display: block; } /* 增加下方間距 */
.stat-value { font-size: 15px; font-weight: bold; color: #2c3e50; display: block; }

/* Table & Chart */
.table-wrapper { flex: 1; overflow: auto; border: 1px solid #eee; max-height: 600px; position: relative; margin-top: 10px; }
.spc-left-panel table { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: auto; min-width: 400px; }
.spc-left-panel th, .spc-left-panel td { border: 1px solid #eee; padding: 4px; text-align: center; white-space: nowrap; }
.spc-left-panel th { background: #f8f9fa; position: sticky; top: 0; z-index: 10; }
.spc-left-panel td input { width: 50px; min-width: 50px; border: none; text-align: center; background: transparent; }
.spc-left-panel td input:focus { background: #e8f0fe; }
.spc-left-panel td:first-child { background: #fff; position: sticky; left: 0; font-weight: bold; z-index: 5; border-right: 2px solid #eee; }
.btn-add-row { width: 100%; padding: 8px; margin-top: 5px; background: #eef; border: 1px dashed #99c; color: #558; cursor: pointer; }
.resizer { background: #ddd; cursor: col-resize; z-index: 20; }
.spc-right-panel { background: #f8f9fa; padding: 15px; display: flex; flex-direction: column; gap: 15px; }
.chart-box { background: white; border: 1px solid #ddd; border-radius: 6px; padding: 10px; display: flex; flex-direction: column; flex: 1; min-height: 350px; }
.chart-header { display: flex; justify-content: space-between; margin-bottom: 5px; }
.canvas-container { flex: 1; position: relative; width: 100%; min-height: 250px; }
canvas { background-color: #fff; }
.violation-box { margin-top: 5px; max-height: 60px; overflow-y: auto; font-size: 11px; color: #c0392b; border-top: 1px solid #eee; }
.status-bar { background: #ecf0f1; padding: 5px 20px; font-size: 12px; color: #7f8c8d; border-top: 1px solid #ccc; }
@media (max-width: 900px) { 
    .spc-main-container { grid-template-columns: 1fr; } .resizer { display: none; } .spc-top-bar { height: auto; flex-direction: column; align-items: flex-start; } .cpk-setup-grid { grid-template-columns: 1fr; }
    .setup-area-right { border-left: none; padding-left: 0; border-top: 1px solid #eee; padding-top: 20px; }
}

/* GRR Table Styles */
.w-full { width: 100%; }
.text-sm { font-size: 0.875rem; }
.text-left { text-align: left; }
.bg-gray-100 { background-color: #f3f4f6; }
.grr-table th, .grr-table td { padding: 8px; border: 1px solid #ddd; }