.contact-modal-overlay .promo-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-2);
}
/* ==============================================
   MODALS - Унифицированные модальные окна
   ============================================== */

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000; /* Ensure above any page dropdowns */
    animation: modalFadeIn var(--duration-300) ease-out;
}

.modal-overlay.show {
    display: flex;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        backdrop-filter: blur(0px);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(8px);
    }
}

/* Modal Container */
.modal-container {
    background: var(--background-secondary);
    border-radius: var(--radius-2xl);
    border: 1px solid var(--border-primary);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    min-width: 400px;
    max-width: 500px;
    width: 90%;
    animation: modalSlideIn var(--duration-300) ease-out;
    overflow: hidden;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Large Modal */
.templates-modal {
    width: 800px !important;
    height: 600px !important;
    background: var(--background-secondary) !important;
    border: 1px solid var(--border-primary) !important;
    border-radius: var(--radius-2xl) !important;
    box-shadow: var(--app-shadow-card), 0 0 0 1px rgba(255, 255, 255, 0.05) !important;
    backdrop-filter: blur(20px) !important;
    max-width: 90vw !important;
    max-height: 90vh !important;
    display: flex !important;
    flex-direction: column !important;
}

/* Modal Header */
.modal-header {
    padding: var(--space-5) var(--space-5) var(--space-4);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--background-tertiary);
    position: relative;
    background: linear-gradient(135deg, 
        rgba(0, 122, 255, 0.1) 0%, 
        rgba(88, 86, 214, 0.1) 50%, 
        rgba(52, 199, 89, 0.05) 100%);
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
}

.modal-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin: 0;
    background: linear-gradient(135deg, #007AFF 0%, #5856D6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-subtitle {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin: 4px 0 0 0;
}

.modal-close,
.modal-close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--background-quaternary);
    color: var(--text-muted);
    border-radius: var(--radius-xl);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-base);
    transition: all var(--duration-200) ease;
    position: absolute;
    top: 20px;
    right: 24px;
}

.modal-close:hover,
.modal-close-btn:hover {
    background: var(--app-danger);
    color: white;
    transform: scale(1.1);
}

/* Modal Body */
.modal-body {
    padding: var(--space-5);
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--border-primary);
    border-radius: 10px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Modal Footer */
.modal-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-primary);
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
    background: var(--background-tertiary);
    border-radius: 0 0 var(--radius-2xl) var(--radius-2xl);
}

/* Templates Modal Specific */
.templates-search-section {
    padding: var(--space-4) var(--space-8);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    gap: var(--space-4);
    align-items: center;
}

.templates-list-container {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.templates-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    background: linear-gradient(135deg, 
        rgba(0, 122, 255, 0.02) 0%, 
        rgba(88, 86, 214, 0.02) 100%);
    border-radius: var(--radius-lg);
    margin: var(--space-4);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid var(--app-primary);
    border-radius: 50%;
    animation: spin var(--duration-1000) linear infinite;
    margin-bottom: var(--space-5);
    backdrop-filter: blur(10px);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.templates-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}

/* Contact modal shared styles */
.contact-modal-overlay .modal-container {
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.contact-modal-overlay .modal-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.contact-modal-overlay .category-picker {
    position: relative;
}

.contact-modal-overlay .category-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.contact-modal-overlay .category-chips .chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 14px;
    background: var(--background-tertiary);
    border: 1px solid var(--border-primary);
    color: var(--text-primary);
    font-size: var(--font-size-xs);
}

.contact-modal-overlay .category-chips .chip .chip-remove {
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
}

.contact-modal-overlay .category-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--background-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-height: 260px;
    overflow-y: auto;
}

.contact-modal-overlay .category-dropdown .dropdown-item {
    padding: 8px 12px;
    cursor: pointer;
    color: var(--text-primary);
}

.contact-modal-overlay .category-dropdown .dropdown-item:hover {
    background: var(--background-tertiary);
}

.contact-modal-overlay .category-dropdown .dropdown-empty {
    padding: 10px 12px;
    color: var(--text-muted);
}

/* Promo code picker overlay - shared across app */
.promo-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.45);
    z-index: 200000; /* above any app modal */
    backdrop-filter: blur(3px);
}
.promo-overlay.show { display: flex; }
.promo-modal {
    width: min(520px, calc(100vw - 48px));
    max-height: min(520px, calc(100vh - 48px));
    background: var(--background-secondary);
    border-radius: 16px;
    border: 1px solid var(--border-primary);
    box-shadow: 0 20px 50px rgba(0,0,0,0.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: fadeInScale .18s ease;
}
.promo-header { padding: 16px 18px; display:flex; align-items:center; justify-content:space-between; border-bottom:1px solid var(--border-primary); background: var(--background-tertiary); }
.promo-title { font-weight: 700; }
.promo-available { font-size: 12px; opacity: .7; }
.promo-close-btn { background: transparent; border: 1px solid var(--border-primary); width: 30px; height: 30px; border-radius: 8px; cursor: pointer; }
.promo-body { padding: 12px 16px; display: grid; gap: 10px; }
.promo-current-info { font-size: 13px; opacity: .8; }
.promo-list { overflow: auto; max-height: 56vh; display: grid; gap: 10px; }
.promo-item { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px; border:1px solid var(--border-primary); border-radius:12px; background: var(--background-secondary); cursor:pointer; }
.promo-item:hover { background: var(--background-tertiary); border-color: color-mix(in oklab, var(--app-primary) 35%, var(--border-primary)); }
.promo-code { font-weight: 700; }
.promo-label { opacity: .75; font-size: 12px; }
.promo-empty { text-align: center; padding: 24px 12px; color: var(--text-secondary); font-size: 14px; }
.promo-footer { padding: 12px 18px 16px; display:flex; justify-content:flex-end; gap:10px; border-top:1px solid var(--border-primary); background: var(--background-tertiary); }

.empty-icon {
    font-size: 48px;
    margin-bottom: var(--space-4);
    opacity: 0.6;
}

.templates-empty h3 {
    margin: 0 0 var(--space-2) 0;
    color: var(--text-primary);
}

.templates-empty p {
    margin: 0;
    font-size: var(--font-size-sm);
}

.retry-btn {
    margin-top: var(--space-4);
    padding: var(--space-2) var(--space-4);
    background: var(--app-primary);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-size: var(--font-size-sm);
    transition: all var(--duration-200) ease;
}

.retry-btn:hover {
    background: #0056b3;
    transform: translateY(-1px);
}

.templates-grid {
    padding: var(--space-4) var(--space-8);
    overflow-y: auto;
    height: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-3);
}

.template-item {
    border: 2px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    cursor: pointer;
    transition: all var(--duration-200) var(--ease-in-out);
    background: linear-gradient(135deg, 
        rgba(255, 255, 255, 0.02) 0%, 
        rgba(255, 255, 255, 0.05) 100%);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

.template-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, 
        rgba(0, 122, 255, 0.02) 0%, 
        rgba(88, 86, 214, 0.02) 100%);
    opacity: 0;
    transition: opacity var(--duration-200) ease;
    z-index: -1;
}

.template-item:hover {
    border-color: var(--app-primary);
    background: rgba(0, 122, 255, 0.08);
    box-shadow: 0 8px 25px rgba(0, 122, 255, 0.2);
    transform: translateY(-4px);
}

.template-item:hover::before {
    opacity: 1;
}

.template-item.selected {
    border-color: var(--app-primary);
    background: linear-gradient(135deg, 
        rgba(0, 122, 255, 0.15) 0%, 
        rgba(88, 86, 214, 0.1) 100%);
    box-shadow: 0 8px 25px rgba(0, 122, 255, 0.3);
}

.template-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-2);
}

.template-name {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin: 0;
    font-size: var(--font-size-base);
}

.template-category {
    background: linear-gradient(135deg, rgba(0, 122, 255, 0.2) 0%, rgba(88, 86, 214, 0.2) 100%);
    color: rgba(0, 122, 255, 1);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: capitalize;
    border: 1px solid rgba(0, 122, 255, 0.3);
    backdrop-filter: blur(10px);
}

.template-content {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-relaxed);
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.template-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--space-3);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.template-date {
    opacity: 0.8;
}

.template-actions {
    display: flex;
    gap: var(--space-2);
}

.template-action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    transition: all var(--duration-200) ease;
}

.template-action-btn:hover {
    color: var(--app-primary);
    background: rgba(0, 122, 255, 0.1);
}

/* Prevent modal overflow blocking */
body.modal-open:has(.modal-overlay[style*="flex"]) {
    overflow: hidden;
}

/* Responsive Modals */
@media (max-width: 768px) {
    .modal-container {
        min-width: auto;
        width: 95%;
        margin: var(--space-4);
    }
    
    .templates-modal {
        width: 95% !important;
        height: 90vh !important;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: var(--space-4);
    }
    
    .modal-footer {
        flex-direction: column;
    }
    
    .btn-primary,
    .btn-secondary {
        width: 100%;
    }
    
    .templates-search-section,
    .templates-grid {
        padding: var(--space-4);
    }
} 