/* ============================================================================
   Модальные окна и форматы
   ============================================================================ */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.4);
    padding-left: 1rem;
    padding-right: 1rem;
    padding-top: 2rem;
    backdrop-filter: blur(4px);
    overflow-y: auto;
}

.modal-backdrop.hidden { 
    display: none !important; 
    visibility: hidden !important;
    opacity: 0 !important;
}

/* ============================================================================
   МОДАЛЬНОЕ ОКНО .modal-overlay (для dashboard, accountant и других страниц)
   ============================================================================ */

.modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.7) !important;
    display: flex;
    justify-content: center !important;
    align-items: center !important;
    z-index: 10000 !important;
    backdrop-filter: blur(4px);
    padding: 0 !important;
    margin: 0 !important;
}

/* Скрытие модального окна - inline стили и класс hidden имеют приоритет */
.modal-overlay[style*="display: none"],
.modal-overlay.hidden {
    display: none !important;
}

.modal-content {
    background: #ffffff !important;
    border: 1px solid rgba(139, 92, 246, 0.3) !important;
    border-radius: 8px !important;
    padding: 0 !important;
    max-width: 500px !important;
    width: 90% !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15) !important;
    position: relative !important;
    z-index: 10001 !important;
}

.modal-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 1.25rem 1.5rem !important;
    border-bottom: 1px solid rgba(139, 92, 246, 0.2) !important;
}

.modal-header .modal-close {
    position: static !important;
    background: transparent !important;
    border: none !important;
    color: #6b7280 !important;
    font-size: 1.5rem !important;
    cursor: pointer !important;
    padding: 0 !important;
    width: 30px !important;
    height: 30px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 4px !important;
    transition: all 0.2s !important;
    margin: 0 !important;
    top: auto !important;
    right: auto !important;
}

.modal-header .modal-close:hover {
    background: rgba(220, 38, 38, 0.1) !important;
    color: #ef4444 !important;
}

.modal-body {
    padding: 1.5rem !important;
}

.document-modal {
    position: relative;
    width: 100%;
    max-width: 48rem;
    border-radius: 24px;
    padding: 2rem;
    box-shadow: 0 10px 35px rgba(31, 41, 51, 0.15);
    background: #ffffff !important;
    border: 2px solid rgba(16, 100, 209, 0.3) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    color: var(--brand-text) !important;
    margin-top: 2rem;
    margin-bottom: 2rem;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 2rem;
    transition-property: color, background-color, border-color, text-decoration-color, fill, stroke;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 0.15s;
    color: #6b7280;
    background: #f3f4f6;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e5e7eb;
}

.modal-close:hover {
    color: #ef4444;
    background: #fee2e2;
    border-color: #ef4444;
    transform: scale(1.1);
}

.modal-title {
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
    line-height: 2rem;
    font-weight: 700;
    color: #1064d1;
    background: linear-gradient(120deg, #1064d1, #6366f1, #8b5cf6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.modal-subtitle {
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: #6b7280;
    margin-bottom: 1.5rem;
}

.modal-section { margin-bottom: 1.5rem; }

.modal-step-title {
    margin-bottom: 0.75rem;
    font-size: 0.75rem;
    line-height: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #6b7280;
}

.modal-options {
    display: grid;
    gap: 1rem;
}

@media (min-width: 768px) {
    .modal-options { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.document-option {
    display: flex;
    cursor: pointer;
    flex-direction: column;
    gap: 0.25rem;
    border-radius: 16px;
    border-width: 2px;
    padding: 1rem;
    text-align: left;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
    background: #ffffff;
    border-color: rgba(16, 100, 209, 0.3);
    color: var(--brand-text);
}

.document-option-title {
    font-weight: 600;
    color: var(--brand-text);
}

.document-option-text {
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: #6b7280;
}

.document-option:hover {
    border-color: rgba(16, 100, 209, 0.5);
    background: #f9fafb;
    box-shadow: 0 2px 8px rgba(16, 100, 209, 0.15);
}

.document-option.active {
    border-color: #1064d1;
    background: rgba(239, 246, 255, 0.8);
    box-shadow: 0 4px 12px rgba(16, 100, 209, 0.2);
    color: var(--brand-text);
}

.document-option.active .document-option-title {
    color: #1064d1;
}

.modal-grid { display: grid; gap: 1rem; }
@media (min-width: 768px) { .modal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.modal-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

@media (min-width: 768px) {
    .modal-field-wide { grid-column: span 2 / span 2; }
}

.modal-input {
    border-radius: 12px;
    border-width: 2px;
    padding: 0.5rem 0.75rem;
    outline: 2px solid transparent;
    outline-offset: 2px;
    background: #ffffff;
    border-color: rgba(16, 100, 209, 0.3);
    color: var(--brand-text);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-input:focus {
    border-color: #1064d1;
    box-shadow: 0 0 0 3px rgba(16, 100, 209, 0.1);
}

.modal-hint {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    line-height: 1rem;
    color: #6b7280;
}

.modal-checkbox-section {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e5e7eb;
}

.modal-checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--brand-text);
    user-select: none;
}

.modal-checkbox {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
    accent-color: #1064d1;
}

.format-option {
    cursor: pointer;
    border-radius: 16px;
    border-width: 2px;
    padding: 0.75rem 1rem;
    text-align: center;
    font-weight: 600;
    transition: all 0.2s ease;
    background: #ffffff;
    border-color: rgba(16, 100, 209, 0.3);
    color: var(--brand-text);
}

.format-option:hover {
    border-color: #1064d1 !important;
    background: #f9fafb !important;
    color: #1064d1 !important;
    box-shadow: 0 2px 8px rgba(16, 100, 209, 0.15) !important;
}

/* ============================================================================
   АДАПТИВНОСТЬ МОДАЛЬНЫХ ОКОН
   ============================================================================ */

@media (max-width: 768px) {
    .modal-backdrop {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    .document-modal {
        padding: 1.5rem;
        border-radius: 16px;
        max-width: 100%;
    }
    
    .modal-title {
        font-size: 1.25rem;
        line-height: 1.75rem;
    }
    
    .modal-options {
        grid-template-columns: 1fr !important;
    }
    
    .modal-grid {
        grid-template-columns: 1fr !important;
    }
    
    .modal-field-wide {
        grid-column: span 1 !important;
    }
}

@media (max-width: 480px) {
    .document-modal {
        padding: 1rem;
        border-radius: 12px;
    }
    
    .modal-title {
        font-size: 1.1rem;
        line-height: 1.5rem;
    }
    
    .modal-close {
        width: 28px;
        height: 28px;
        top: 0.75rem;
        right: 0.75rem;
        font-size: 1.25rem;
    }
}

/* ============================================================================
   МОДАЛЬНОЕ ОКНО С ИНФОРМАЦИЕЙ О ПОСЛЕДНЕМ ПЛАТЕЖЕ
   ============================================================================ */

.last-payment-container {
    position: fixed !important;
    z-index: 30 !important; /* Ниже модального окна с кнопками импорта (z-index: 40), но ниже основного контента */
    pointer-events: auto; /* Разрешаем взаимодействие с блоком */
    width: 220px !important; /* Та же ширина, что и у action-panel */
    min-width: 220px !important;
    max-width: 220px !important;
    box-sizing: border-box !important;
    right: 1.5rem !important; /* Та же позиция справа, что и у action-panel */
    overflow: visible !important; /* Убираем прокрутку */
    padding-bottom: 0 !important;
}

.last-payment-modal {
    position: relative;
    z-index: 30;
    width: 100% !important; /* Занимает всю ширину контейнера */
    max-width: 100% !important;
    box-sizing: border-box !important;
    pointer-events: auto; /* Разрешаем взаимодействие с содержимым */
    overflow: visible !important; /* Убираем прокрутку */
}

.last-payment-container .modal-section {
    overflow: visible !important; /* Убираем прокрутку */
    max-height: none !important;
}

/* Адаптивность для блока информации о последнем платеже */
@media (max-width: 1024px) {
    .last-payment-container {
        /* На маленьких экранах блок может перекрывать контент, поэтому скрываем его */
        display: none !important;
    }
}
