/* spc.css - Statistical Process Control (Phase 37) */

.spc-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ───────── Header ───────── */
.spc-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
}

.spc-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: #1e293b;
}

.spc-header p {
    margin: 4px 0 0;
    font-size: 13px;
    color: #64748b;
}

.spc-btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    white-space: nowrap;
}

.spc-btn-primary:hover {
    opacity: 0.88;
}

/* ───────── Empty state ───────── */
.spc-empty {
    text-align: center;
    padding: 60px 20px;
}

.spc-empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.spc-empty h3 {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 600;
    color: #374151;
}

.spc-empty p {
    margin: 0 auto 24px;
    font-size: 14px;
    color: #64748b;
    max-width: 400px;
    line-height: 1.5;
}

/* ───────── Card grid (list view) ───────── */
.spc-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.spc-chart-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.spc-chart-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: #c4b5fd;
}

.spc-chart-card-title {
    font-weight: 700;
    font-size: 15px;
    color: #1e293b;
    margin-bottom: 4px;
}

.spc-chart-card-sub {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 12px;
}

.spc-chart-card-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.spc-tag {
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
}

.spc-tag-purple {
    background: #ede9fe;
    color: #7c3aed;
}

.spc-tag-gray {
    background: #f1f5f9;
    color: #64748b;
}

/* ───────── Detail view ───────── */
.spc-back-btn {
    background: none;
    border: none;
    color: #667eea;
    cursor: pointer;
    font-size: 14px;
    margin-bottom: 16px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.spc-back-btn:hover {
    text-decoration: underline;
}

.spc-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.spc-detail-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
}

.spc-detail-header p {
    margin: 2px 0 0;
    font-size: 13px;
    color: #64748b;
}

/* ───────── Stats grid (Cp/Cpk/UCL/LCL cards) ───────── */
.spc-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.spc-stat-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px;
    text-align: center;
}

.spc-stat-card-value {
    font-size: 20px;
    font-weight: 700;
    line-height: 1.1;
}

.spc-stat-card-unit {
    font-size: 11px;
    font-weight: 400;
    color: #94a3b8;
}

.spc-stat-card-label {
    font-size: 11px;
    color: #64748b;
    margin-top: 2px;
}

.spc-stat-card-hint {
    font-size: 10px;
    font-weight: 600;
    margin-top: 2px;
}

/* Color coding for Cp/Cpk */
.spc-stat-good   { color: #38a169; }  /* Cp >= 1.33 */
.spc-stat-warn   { color: #ed8936; }  /* 1.0 <= Cp < 1.33 */
.spc-stat-bad    { color: #e53e3e; }  /* Cp < 1.0 */
.spc-stat-info   { color: #667eea; }
.spc-stat-muted  { color: #94a3b8; }

/* ───────── Chart canvas wrapper ───────── */
.spc-chart-panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}

.spc-chart-panel-title {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 12px;
}

.spc-canvas-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.spc-canvas-wrap canvas {
    display: block;
    width: 100%;
}

/* ───────── Measurements table ───────── */
.spc-table-panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 16px;
}

.spc-table-header {
    padding: 14px 16px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
}

.spc-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.spc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.spc-table thead tr {
    background: #f8fafc;
}

.spc-table th {
    padding: 10px 16px;
    text-align: left;
    color: #64748b;
    font-weight: 600;
    white-space: nowrap;
    border-bottom: 1px solid #e2e8f0;
}

.spc-table td {
    padding: 10px 16px;
    border-top: 1px solid #f1f5f9;
    vertical-align: middle;
}

.spc-table tr.spc-row-ooc {
    background: #fff5f5;
}

.spc-table .spc-td-main {
    font-weight: 600;
    color: #1e293b;
}

.spc-table .spc-td-ooc {
    font-weight: 700;
    color: #e53e3e;
}

.spc-table .spc-td-r {
    color: #ed8936;
}

.spc-table .spc-td-muted {
    color: #94a3b8;
    font-size: 12px;
}

/* ───────── Modals ───────── */
.spc-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.spc-modal {
    background: #fff;
    border-radius: 16px;
    padding: 28px;
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.spc-modal h3 {
    margin: 0 0 20px;
    font-size: 17px;
    font-weight: 700;
    color: #1e293b;
}

/* ───────── Form elements ───────── */
.spc-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.spc-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.spc-form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.spc-form-label {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.spc-form-input,
.spc-form-select {
    width: 100%;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    color: #1e293b;
    box-sizing: border-box;
    transition: border-color 0.15s;
    outline: none;
    background: #fff;
}

.spc-form-input:focus,
.spc-form-select:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
}

.spc-form-input::placeholder {
    color: #b0bac7;
}

.spc-modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: flex-end;
}

.spc-btn-cancel {
    padding: 10px 20px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    color: #374151;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.spc-btn-cancel:hover {
    background: #f8fafc;
}

/* ───────── Responsive ───────── */
@media (max-width: 480px) {
    .spc-container {
        padding: 10px;
    }

    .spc-form-row {
        grid-template-columns: 1fr;
    }

    .spc-modal {
        padding: 20px 16px;
    }

    .spc-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .spc-cards-grid {
        grid-template-columns: 1fr;
    }
}
