/* ============================================
   MODAL OVERLAY
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

    .modal-overlay.active {
        display: flex;
    }

/* ============================================
   MODAL CONTENT
   ============================================ */
.modal-content {
    background: white;
    border-radius: var(--radius-lg);
    max-width: 700px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.25s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

    .modal-header h2 {
        font-size: var(--font-size-large);
        font-weight: 600;
        color: var(--text-primary);
        margin: 0;
    }

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-light);
    cursor: pointer;
    transition: var(--transition);
    padding: 0 8px;
    line-height: 1;
}

    .modal-close:hover {
        color: var(--text-primary);
        transform: rotate(90deg);
    }

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

    .modal-body p,
    .modal-body div {
        font-size: var(--font-size-base);
    }

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

/* ============================================
   MODAL FORM
   ============================================ */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

    .form-group label {
        font-size: var(--font-size-small);
        font-weight: 500;
        color: var(--text-secondary);
    }

        .form-group label .required {
            color: #EF4444;
        }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 8px 12px;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        font-size: var(--font-size-base);
        transition: var(--transition);
        font-family: inherit;
        background: white;
        color: var(--text-primary);
        width: 100%;
    }

        .form-group input:focus,
        .form-group select:focus,
        .form-group textarea:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
        }

    .form-group textarea {
        resize: vertical;
        min-height: 60px;
        font-size: var(--font-size-base);
    }

    .form-group .form-error {
        color: #EF4444;
        font-size: 12px;
        margin-top: 4px;
    }

/* ============================================
   MODAL RESPONSIVE
   ============================================ */
@media (max-width: 600px) {
    .modal-content {
        max-width: 100%;
        margin: 10px;
        max-height: 95vh;
        border-radius: var(--radius-md);
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-group[style*="grid-column: span 2;"] {
        grid-column: span 1 !important;
    }

    .modal-header {
        padding: 16px;
    }

        .modal-header h2 {
            font-size: var(--font-size-base);
        }

    .modal-body {
        padding: 16px;
    }

    .modal-footer {
        padding: 12px 16px;
    }

        .modal-footer .btn-primary,
        .modal-footer .btn-secondary,
        .modal-footer .btn-danger {
            flex: 1;
            justify-content: center;
            font-size: var(--font-size-small);
            height: 36px;
            padding: 6px 16px;
        }

    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: var(--font-size-small);
        padding: 6px 10px;
    }

    .form-group label {
        font-size: 12px;
    }
}
/* ============================================
   AUTO-FILL INFO
   ============================================ */
.auto-fill-info {
    grid-column: span 2;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
    margin-top: -8px;
    white-space: pre-line;
    display: none;
}

    .auto-fill-info.success {
        background: #e8f5e9;
        border-left: 3px solid #4caf50;
        color: #1b5e20;
    }

    .auto-fill-info.warning {
        background: #fff3e0;
        border-left: 3px solid #ff9800;
        color: #e65100;
    }

    .auto-fill-info.error {
        background: #ffebee;
        border-left: 3px solid #f44336;
        color: #c62828;
    }

    .auto-fill-info.loading {
        background: #e3f2fd;
        border-left: 3px solid #2196f3;
        color: #0d47a1;
    }

.numcb-preview {
    grid-column: span 2;
    padding: 6px 12px;
    background: #e3f2fd;
    border-radius: 4px;
    color: #0d47a1;
    font-size: 13px;
    border-left: 3px solid #2196f3;
    margin-top: -8px;
}
/* ============================================
   ПРЕДУПРЕЖДЕНИЕ О ДУБЛИКАТЕ
   ============================================ */
.auto-fill-info.warning-duplicate {
    background: #fff3e0 !important;
    border-left: 4px solid #ff6b00 !important;
    color: #bf360c !important;
    font-weight: 500 !important;
    box-shadow: 0 2px 10px rgba(255, 107, 0, 0.2) !important;
}

.auto-fill-info .duplicate-highlight {
    color: #d32f2f;
    font-weight: 700;
    font-size: 15px;
}

.auto-fill-info .duplicate-details {
    background: #fff8e1;
    padding: 8px 12px;
    border-radius: 4px;
    margin-top: 6px;
    font-family: monospace;
    font-size: 12px;
    border: 1px solid #ffcc80;
}
/* ============================================
   МЕДОРГАНИЗАЦИИ - КОНТЕКСТНЫЙ ПОИСК
   ============================================ */

.medorg-search-wrapper {
    position: relative;
    width: 100%;
}

.medorg-search-input {
    width: 100% !important;
    padding-right: 36px !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}

    .medorg-search-input:focus {
        border-color: #594AE2 !important;
        box-shadow: 0 0 0 3px rgba(89, 74, 226, 0.1) !important;
    }

        .medorg-search-input:focus + .medorg-search-results {
            display: block !important;
        }

.medorg-search-results {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 0 0 6px 6px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    margin-top: 2px;
}

    .medorg-search-results:not(:empty) {
        display: block;
    }

.medorg-search-item {
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.15s;
    font-size: 14px;
}

    .medorg-search-item:hover,
    .medorg-search-item.active {
        background: #f3f4f6;
    }

    .medorg-search-item:last-child {
        border-bottom: none;
    }

    .medorg-search-item .highlight {
        background: #fef3c7;
        font-weight: 600;
    }

.medorg-search-empty {
    padding: 12px 16px;
    color: #6b7280;
    text-align: center;
    font-size: 14px;
}

/* Адаптив для мобильных */
@media (max-width: 600px) {
    .medorg-search-results {
        max-height: 200px;
    }

    .medorg-search-item {
        padding: 8px 12px;
        font-size: 13px;
    }
}