* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f7fa;
    padding: 24px;
    color: #1e293b;
}

.container {
    max-width: 1400px;  /* Было 900px */
    margin: 0 auto;
}

.card {
    background: white;
    border-radius: 16px;
    padding: 32px;  /* Было 24px */
    margin-bottom: 24px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

h1 { 
    font-size: 28px;  /* Было 24px */
    margin-bottom: 20px; 
    color: #1e293b;
}

h2 { 
    font-size: 20px;  /* Было 18px */
    margin-bottom: 20px; 
    color: #334155; 
}

h3 { 
    font-size: 18px;  /* Было 16px */
    margin: 24px 0 16px; 
    color: #475569; 
}

h4 { 
    font-size: 15px;  /* Было 14px */
    margin: 20px 0 12px; 
    color: #64748b; 
}

.status-badge {
    display: inline-block;
    padding: 8px 16px;  /* Было 6px 12px */
    border-radius: 24px;
    font-size: 15px;  /* Было 14px */
    font-weight: 500;
}

.status-ok { 
    background: #dcfce7; 
    color: #166534; 
}

.status-error { 
    background: #fee2e2; 
    color: #991b1b; 
}

select, 
input[type="text"] {
    width: 100%;
    padding: 12px 16px;  /* Было 10px 12px */
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font-size: 15px;  /* Было 14px */
    background: white;
}

select:focus,
input[type="text"]:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group {
    margin-bottom: 20px;  /* Было 16px */
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 8px;
    color: #475569;
    font-size: 15px;
}

.btn {
    padding: 12px 24px;  /* Было 10px 20px */
    border-radius: 10px;
    font-size: 15px;  /* Было 14px */
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    margin-right: 12px;
    display: inline-block;
    text-decoration: none;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover { 
    background: #2563eb; 
}

.btn-secondary {
    background: #e2e8f0;
    color: #1e293b;
}

.btn-secondary:hover { 
    background: #cbd5e1; 
}

.btn-icon {
    background: none;
    border: none;
    color: #ef4444;
    font-size: 20px;  /* Было 18px */
    cursor: pointer;
    padding: 10px;
    width: 40px;  /* Было 32px */
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.btn-icon:hover { 
    background: #fee2e2; 
}

.mapping-row {
    display: grid;
    grid-template-columns: 2fr 1fr 2fr 1.5fr 50px;  /* Расширили колонки */
    gap: 12px;  /* Было 8px */
    margin-bottom: 16px;
    align-items: center;
}

.source-type,
.list-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    background: white;
}

.variable-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
}

.webhook-url {
    background: #f1f5f9;
    padding: 16px;
    border-radius: 10px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', monospace;
    word-break: break-all;
    margin: 16px 0;
    font-size: 14px;
    border: 1px solid #e2e8f0;
}

.webhook-url-small {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', monospace;
    font-size: 12px;
    color: #64748b;
    margin-top: 6px;
    word-break: break-all;
}

.info-text {
    color: #64748b;
    font-size: 14px;
    margin-top: 6px;
}

.integration-item {
    background: #f8fafc;
    padding: 20px;  /* Было 16px */
    border-radius: 12px;
    margin-bottom: 16px;
    border-left: 4px solid #3b82f6;
}

.integration-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.badge {
    padding: 4px 10px;  /* Было 2px 8px */
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    background: #e2e8f0;
    color: #475569;
}

.badge.active {
    background: #dcfce7;
    color: #166534;
}

.badge.inactive {
    background: #fee2e2;
    color: #991b1b;
}

.integration-mappings {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.mapping-badge {
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 12px;
    background: #f1f5f9;
    color: #64748b;
    font-family: 'SF Mono', Monaco, monospace;
}

.form-actions {
    margin-top: 32px;
    display: flex;
    gap: 12px;
}

#portal-info {
    margin-top: 12px;
    color: #64748b;
    font-size: 15px;
}

#fields-mapping-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
}

#webhook-info-section {
    margin-top: 24px;
    padding: 20px;
    background: #f8fafc;
    border-radius: 12px;
}

#integrations-list {
    margin-top: 24px;
}

hr {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 24px 0;
}

/* ========== КАСТОМНЫЙ SELECT С ПОИСКОМ ========== */

.searchable-select {
    position: relative;
    width: 100%;
    user-select: none;
}

.searchable-select-display {
    padding: 12px 16px;  /* Увеличен */
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: white;
    cursor: pointer;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: border-color 0.2s;
}

.searchable-select-display:hover {
    border-color: #3b82f6;
}

.searchable-select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    max-height: 400px;  /* Увеличен */
    display: flex;
    flex-direction: column;
}

.searchable-select-search {
    padding: 14px 16px;  /* Увеличен */
    border: none;
    border-bottom: 1px solid #e2e8f0;
    font-size: 15px;
    outline: none;
    border-radius: 10px 10px 0 0;
}

.searchable-select-search:focus {
    background: #f8fafc;
}

.searchable-select-options {
    overflow-y: auto;
    max-height: 320px;  /* Увеличен */
    padding: 6px 0;
}

.searchable-select-option {
    padding: 10px 16px;  /* Увеличен */
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s;
    border-bottom: 1px solid #f1f5f9;
}

.searchable-select-option:last-child {
    border-bottom: none;
}

.searchable-select-option:hover {
    background: #f1f5f9;
}

.searchable-select-option.selected {
    background: #dbeafe;
    color: #1e40af;
}

.searchable-select-option mark {
    background: #fef08a;
    padding: 2px 3px;
    border-radius: 3px;
    color: #854d0e;
}

.searchable-select-empty {
    padding: 20px;
    text-align: center;
    color: #94a3b8;
    font-size: 14px;
}

/* ========== АДАПТИВНОСТЬ ========== */

@media (max-width: 1024px) {
    .container {
        max-width: 100%;
    }
    
    .mapping-row {
        grid-template-columns: 1.5fr 1fr 1.5fr 1fr 40px;
        gap: 8px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 16px;
    }
    
    .card {
        padding: 20px;
    }
    
    .mapping-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .btn {
        width: 100%;
        margin-right: 0;
        margin-bottom: 10px;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .integration-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
}

/* ========== АНИМАЦИИ ========== */

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ========== КОНТЕЙНЕР ДЛЯ SELECT СП ========== */

#sp-select-container {
    margin-bottom: 20px;
}

#sp-select-container .searchable-select {
    max-width: 100%;
}

.searchable-select-display[style*="opacity: 0.6"] {
    cursor: not-allowed;
    border-color: #e2e8f0;
}