/* ============================================================
   NCR — Non-Conformance Reports (Phase 36)
   Замена SAP QM Non-Conformance
   Design: purple gradient #667eea → #764ba2
   ============================================================ */

/* ===== Container ===== */

.ncr-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 16px;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ===== Header ===== */

.ncr-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
    padding: 20px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 14px;
    color: white;
}

.ncr-header h2 {
    font-size: 20px;
    font-weight: 700;
    color: white;
    margin: 0;
}

.ncr-header p {
    margin: 4px 0 0;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.75);
}

.ncr-header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

/* ===== Buttons ===== */

.ncr-btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    font-family: inherit;
    white-space: nowrap;
}

.ncr-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ncr-btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.ncr-btn-primary:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
}

.ncr-btn-secondary {
    background: #f8fafc;
    color: #64748b;
    border: 1px solid #e2e8f0;
}

.ncr-btn-secondary:hover:not(:disabled) {
    background: #f1f5f9;
    color: #374151;
}

.ncr-btn-ghost {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.35);
}

.ncr-btn-ghost:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.3);
}

.ncr-btn-outline {
    background: white;
    color: #667eea;
    border: 1px solid #667eea;
}

.ncr-btn-outline:hover:not(:disabled) {
    background: #f5f3ff;
}

.ncr-btn-danger {
    background: #fee2e2;
    color: #dc2626;
}

.ncr-btn-danger:hover:not(:disabled) {
    background: #fca5a5;
}

.ncr-btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

/* ===== Filters ===== */

.ncr-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    align-items: center;
}

.ncr-filter-select {
    padding: 7px 32px 7px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    color: #374151;
    background: white;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236e6e73' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ncr-filter-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

/* ===== Stats Row ===== */

.ncr-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

@media (max-width: 700px) {
    .ncr-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 400px) {
    .ncr-stats {
        grid-template-columns: 1fr 1fr;
    }
}

.ncr-stat-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 14px 16px;
    text-align: center;
}

.ncr-stat-value {
    font-size: 26px;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.1;
    margin-bottom: 4px;
}

.ncr-stat-label {
    font-size: 11px;
    color: #94a3b8;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ncr-stat-card.critical .ncr-stat-value { color: #e53e3e; }
.ncr-stat-card.major   .ncr-stat-value { color: #ed8936; }
.ncr-stat-card.open    .ncr-stat-value { color: #e53e3e; }

/* ===== NCR Table / List ===== */

.ncr-table {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ===== NCR Card ===== */

.ncr-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 16px;
    cursor: pointer;
    transition: box-shadow 0.2s, border-color 0.2s;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    position: relative;
}

.ncr-card:hover {
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.12);
    border-color: #c4b5fd;
}

/* Severity left border */
.ncr-card.severity-critical { border-left: 4px solid #e53e3e; }
.ncr-card.severity-major    { border-left: 4px solid #ed8936; }
.ncr-card.severity-minor    { border-left: 4px solid #38a169; }

.ncr-card-number {
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
    min-width: 52px;
    text-align: center;
    background: #f8fafc;
    border-radius: 6px;
    padding: 4px 6px;
    white-space: nowrap;
    flex-shrink: 0;
    align-self: center;
}

.ncr-card-body {
    flex: 1;
    min-width: 0;
}

.ncr-card-top {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.ncr-card-title {
    font-size: 14px;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ncr-card-desc {
    font-size: 12px;
    color: #64748b;
    line-height: 1.4;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.ncr-card-side {
    text-align: right;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.ncr-card-date {
    font-size: 11px;
    color: #94a3b8;
}

/* ===== Badges ===== */

.ncr-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

/* Severity badges */
.ncr-badge-severity-critical {
    background: #fff5f5;
    color: #e53e3e;
}

.ncr-badge-severity-major {
    background: #fffaf0;
    color: #dd6b20;
}

.ncr-badge-severity-minor {
    background: #f0fff4;
    color: #38a169;
}

/* Type badge */
.ncr-badge-type {
    background: #f1f5f9;
    color: #64748b;
}

/* Status badges */
.ncr-badge-status-open {
    background: rgba(229, 62, 62, 0.12);
    color: #e53e3e;
}

.ncr-badge-status-investigating {
    background: rgba(237, 137, 54, 0.12);
    color: #ed8936;
}

.ncr-badge-status-corrective_action {
    background: rgba(49, 130, 206, 0.12);
    color: #3182ce;
}

.ncr-badge-status-verification {
    background: rgba(128, 90, 213, 0.12);
    color: #805ad5;
}

.ncr-badge-status-closed {
    background: rgba(56, 161, 105, 0.12);
    color: #38a169;
}

/* ===== Detail View ===== */

.ncr-detail {
    background: white;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    overflow: hidden;
}

.ncr-detail-head {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}

.ncr-detail-number {
    font-size: 12px;
    opacity: 0.7;
    margin-bottom: 4px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.ncr-detail-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
}

.ncr-detail-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.ncr-detail-badge {
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.ncr-detail-body {
    padding: 20px 24px;
}

.ncr-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

@media (max-width: 560px) {
    .ncr-detail-grid {
        grid-template-columns: 1fr;
    }
}

.ncr-detail-field-label {
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.ncr-detail-field-value {
    font-size: 14px;
    color: #374151;
}

.ncr-detail-section {
    margin-bottom: 16px;
}

.ncr-detail-section-label {
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.ncr-detail-section-content {
    font-size: 14px;
    color: #374151;
    background: #f8fafc;
    border-radius: 8px;
    padding: 12px 14px;
    line-height: 1.6;
    border: 1px solid #e2e8f0;
}

.ncr-detail-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 16px;
    border-top: 1px solid #e2e8f0;
    margin-top: 4px;
}

/* ===== Form / Modal ===== */

.ncr-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;
    box-sizing: border-box;
}

.ncr-form {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.ncr-form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 0;
    flex-shrink: 0;
}

.ncr-form-title {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
}

.ncr-form-close {
    background: none;
    border: none;
    font-size: 20px;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
    line-height: 1;
}

.ncr-form-close:hover {
    background: #f1f5f9;
    color: #374151;
}

.ncr-form-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.ncr-form-footer {
    padding: 0 24px 20px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-shrink: 0;
    border-top: 1px solid #f1f5f9;
    padding-top: 16px;
}

/* Form fields */
.ncr-form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ncr-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (max-width: 480px) {
    .ncr-form-row {
        grid-template-columns: 1fr;
    }
}

.ncr-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ncr-required {
    color: #e53e3e;
    margin-left: 2px;
}

.ncr-input,
.ncr-select,
.ncr-textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: #1e293b;
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.ncr-input:focus,
.ncr-select:focus,
.ncr-textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.ncr-input::placeholder,
.ncr-textarea::placeholder {
    color: #c0cdd9;
}

.ncr-select {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236e6e73' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.ncr-textarea {
    resize: vertical;
    min-height: 80px;
    line-height: 1.5;
}

/* ===== Empty State ===== */

.ncr-empty {
    text-align: center;
    padding: 60px 20px;
    color: #94a3b8;
}

.ncr-empty-icon {
    font-size: 52px;
    margin-bottom: 16px;
    line-height: 1;
}

.ncr-empty-title {
    font-size: 18px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
}

.ncr-empty-desc {
    font-size: 14px;
    color: #64748b;
    line-height: 1.6;
    max-width: 420px;
    margin: 0 auto 24px;
}

/* ===== Toast Notification ===== */

.ncr-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    font-family: system-ui, -apple-system, sans-serif;
    color: white;
    background: #1e293b;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s, transform 0.25s;
    max-width: 320px;
    pointer-events: none;
}

.ncr-toast-visible {
    opacity: 1;
    transform: translateY(0);
}

.ncr-toast-success {
    background: #166534;
}

.ncr-toast-error {
    background: #991b1b;
}

/* ===== Back Button ===== */

.ncr-back-btn {
    background: none;
    border: none;
    color: #667eea;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    padding: 0;
    margin-bottom: 16px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color 0.2s;
}

.ncr-back-btn:hover {
    color: #764ba2;
}

/* ===== Severity color-coded utility classes ===== */

/* critical = #e53e3e */
.ncr-severity-critical   { border-left-color: #e53e3e !important; }
.ncr-text-critical        { color: #e53e3e; }
.ncr-bg-critical          { background: #fff5f5; color: #e53e3e; }

/* major = #ed8936 */
.ncr-severity-major      { border-left-color: #ed8936 !important; }
.ncr-text-major           { color: #dd6b20; }
.ncr-bg-major             { background: #fffaf0; color: #dd6b20; }

/* minor = #38a169 */
.ncr-severity-minor      { border-left-color: #38a169 !important; }
.ncr-text-minor           { color: #38a169; }
.ncr-bg-minor             { background: #f0fff4; color: #38a169; }

/* ===== Status color utility classes ===== */

/* open = #e53e3e */
.ncr-status-open            { background: rgba(229,62,62,0.12);   color: #e53e3e; }

/* investigating = #ed8936 */
.ncr-status-investigating   { background: rgba(237,137,54,0.12);  color: #ed8936; }

/* corrective_action = #3182ce */
.ncr-status-corrective_action { background: rgba(49,130,206,0.12); color: #3182ce; }

/* verification = #805ad5 */
.ncr-status-verification    { background: rgba(128,90,213,0.12);  color: #805ad5; }

/* closed = #38a169 */
.ncr-status-closed          { background: rgba(56,161,105,0.12);  color: #38a169; }

/* ===== Divider ===== */

.ncr-divider {
    height: 1px;
    background: #e2e8f0;
    margin: 14px 0;
}

/* ===== Responsive tweaks ===== */

@media (max-width: 640px) {
    .ncr-header {
        padding: 16px;
    }

    .ncr-header h2 {
        font-size: 17px;
    }

    .ncr-detail-head {
        padding: 16px;
    }

    .ncr-detail-title {
        font-size: 17px;
    }

    .ncr-detail-body {
        padding: 16px;
    }

    .ncr-card {
        flex-direction: column;
        gap: 10px;
    }

    .ncr-card-side {
        align-items: flex-start;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
    }
}
