/**
 * =====================================================
 * СТИЛИ МОДАЛЬНЫХ ОКОН СОГЛАСИЯ НА РАСПРОСТРАНЕНИЕ ПД
 * Kuvalda+ Distribution Consent Modal v2.0
 * =====================================================
 * 
 * Цветовая схема: Telegram Blue (#2481cc)
 * Поддержка: светлая и тёмная тема
 * 
 * Структура:
 * 1. CSS переменные
 * 2. Overlay и базовые стили модального окна
 * 3. Модальное окно согласия (копия стилей consent.css)
 * 4. Модальное окно документа
 * 5. Адаптивность
 * 
 * =====================================================
 */

/* =====================================================
   CSS ПЕРЕМЕННЫЕ
   ===================================================== */

:root {
    /* Основные цвета */
    --dc-primary: #f97316;
    --dc-primary-hover: #ea580c;
    --dc-primary-light: rgba(36, 129, 204, 0.1);
    
    /* Текст */
    --dc-text: #1a1a1a;
    --dc-text-secondary: #6b7280;
    --dc-text-muted: #9ca3af;
    
    /* Фон */
    --dc-bg: #ffffff;
    --dc-bg-secondary: #f8f9fa;
    --dc-overlay: rgba(0, 0, 0, 0.5);
    
    /* Границы */
    --dc-border: #e5e7eb;
    --dc-border-hover: #d1d5db;
    
    /* Ошибки */
    --dc-error: #ef4444;
    --dc-error-bg: #fef2f2;
    
    /* Тени */
    --dc-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    --dc-shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.2);
    
    /* Скругления */
    --dc-radius: 16px;
    --dc-radius-sm: 8px;
    
    /* Анимации */
    --dc-transition: 0.2s ease;
}

/* Тёмная тема */
@media (prefers-color-scheme: dark) {
    :root {
        --dc-primary: #e0894f;
        --dc-primary-hover: #eaa46b;
        --dc-primary-light: rgba(79, 163, 224, 0.15);
        
        --dc-text: #ffffff;
        --dc-text-secondary: #a1a1aa;
        --dc-text-muted: #71717a;
        
        --dc-bg: #1c1c1e;
        --dc-bg-secondary: #2c2c2e;
        --dc-overlay: rgba(0, 0, 0, 0.7);
        
        --dc-border: #3c3c3e;
        --dc-border-hover: #4c4c4e;
        
        --dc-error-bg: rgba(239, 68, 68, 0.1);
        
        --dc-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
        --dc-shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
    }
}

/* =====================================================
   OVERLAY (ЗАТЕМНЁННЫЙ ФОН)
   ===================================================== */

.dc-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: var(--dc-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 10000;
    animation: dcFadeIn 0.2s ease;
    -webkit-overflow-scrolling: touch;
}

@keyframes dcFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* =====================================================
   МОДАЛЬНОЕ ОКНО (БАЗОВОЕ)
   ===================================================== */

.dc-modal {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    background: var(--dc-bg);
    border-radius: var(--dc-radius);
    box-shadow: var(--dc-shadow-lg);
    overflow: hidden;
    animation: dcSlideUp 0.25s ease;
    display: flex;
    flex-direction: column;
}

@keyframes dcSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =====================================================
   МОДАЛЬНОЕ ОКНО СОГЛАСИЯ
   ===================================================== */

/* Шапка с логотипом */
.dc-modal-header {
    text-align: center;
    padding: 24px 24px 0;
}

.dc-logo {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.dc-logo-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.dc-logo-text {
    font-size: 24px;
    font-weight: 700;
    color: var(--dc-text);
    letter-spacing: -0.5px;
}

.dc-logo-plus {
    color: var(--dc-primary);
}

/* Заголовок */
.dc-modal-title {
    text-align: center;
    padding: 20px 24px;
}

.dc-modal-title h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--dc-text);
    margin: 0 0 8px;
}

.dc-modal-title p {
    font-size: 14px;
    color: var(--dc-text-secondary);
    margin: 0;
    line-height: 1.5;
}

/* Форма */
.dc-modal-form {
    padding: 0 24px;
}

/* Чекбокс */
.dc-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: var(--dc-bg-secondary);
    border: 1px solid var(--dc-border);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--dc-transition);
    -webkit-tap-highlight-color: transparent;
}

.dc-checkbox:hover {
    border-color: var(--dc-border-hover);
    background: var(--dc-bg);
}

.dc-checkbox:has(input:checked) {
    border-color: var(--dc-primary);
    background: var(--dc-primary-light);
}

/* Скрываем стандартный чекбокс */
.dc-checkbox input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

/* Кастомная галочка */
.dc-checkbox-mark {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: 2px solid var(--dc-border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--dc-transition);
    background: var(--dc-bg);
}

.dc-checkbox-mark svg {
    width: 14px;
    height: 14px;
    color: white;
    opacity: 0;
    transform: scale(0.5);
    transition: var(--dc-transition);
}

/* Состояние checked */
.dc-checkbox input:checked + .dc-checkbox-mark {
    background: var(--dc-primary);
    border-color: var(--dc-primary);
}

.dc-checkbox input:checked + .dc-checkbox-mark svg {
    opacity: 1;
    transform: scale(1);
}

/* Текст чекбокса */
.dc-checkbox-text {
    flex: 1;
    font-size: 14px;
    line-height: 1.5;
    color: var(--dc-text);
    padding-top: 2px;
}

/* Ссылка */
.dc-link {
    color: var(--dc-primary);
    text-decoration: none;
    font-weight: 500;
    transition: var(--dc-transition);
}

.dc-link:hover {
    text-decoration: underline;
}

.dc-link:active {
    opacity: 0.8;
}

/* Ошибка */
.dc-error {
    display: none;
    padding: 12px 16px;
    margin-top: 12px;
    background: var(--dc-error-bg);
    border-radius: var(--dc-radius-sm);
    font-size: 14px;
    color: var(--dc-error);
    text-align: center;
}

.dc-error.visible {
    display: block;
    animation: dcShake 0.4s ease;
}

@keyframes dcShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

/* Подвал модального окна */
.dc-modal-footer {
    padding: 20px 24px 24px;
}

.dc-footer-text {
    font-size: 12px;
    color: var(--dc-text-muted);
    text-align: center;
    margin: 0 0 16px;
    line-height: 1.5;
}

/* Кнопки */
.dc-buttons {
    display: flex;
    gap: 12px;
}

.dc-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--dc-transition);
    -webkit-tap-highlight-color: transparent;
    font-family: inherit;
}

/* Кнопка "Отмена" */
.dc-btn-secondary {
    background: var(--dc-bg-secondary);
    color: var(--dc-text);
    border: 1px solid var(--dc-border);
}

.dc-btn-secondary:hover {
    background: var(--dc-bg);
    border-color: var(--dc-border-hover);
}

.dc-btn-secondary:active {
    transform: scale(0.98);
}

/* Кнопка "Продолжить" */
.dc-btn-primary {
    background: var(--dc-primary);
    color: white;
}

.dc-btn-primary:hover:not(:disabled) {
    background: var(--dc-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(36, 129, 204, 0.3);
}

.dc-btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.dc-btn-primary:disabled {
    background: var(--dc-border);
    color: var(--dc-text-muted);
    cursor: not-allowed;
}

/* Кнопка на всю ширину */
.dc-btn-full {
    width: 100%;
}

/* Лоадер на кнопке */
.dc-btn-loader {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: dcSpin 0.8s linear infinite;
}

.dc-btn.loading .dc-btn-loader {
    display: block;
}

.dc-btn.loading .dc-btn-text {
    opacity: 0.7;
}

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

/* =====================================================
   МОДАЛЬНОЕ ОКНО ДОКУМЕНТА
   ===================================================== */

.dc-modal-document {
    max-width: 600px;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
}

/* Крестик закрытия */
.dc-close-x {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--dc-bg-secondary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--dc-transition);
    z-index: 10;
    -webkit-tap-highlight-color: transparent;
}

.dc-close-x svg {
    width: 20px;
    height: 20px;
    color: var(--dc-text-secondary);
}

.dc-close-x:hover {
    background: var(--dc-border);
}

.dc-close-x:hover svg {
    color: var(--dc-text);
}

.dc-close-x:active {
    transform: scale(0.95);
}

/* Контент документа (скроллится) */
.dc-document-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    padding-top: 56px; /* Место для крестика */
    -webkit-overflow-scrolling: touch;
}

/* Стили текста документа */
.dc-doc-header {
    text-align: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--dc-border);
}

.dc-doc-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--dc-text);
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dc-doc-header p {
    font-size: 14px;
    color: var(--dc-text-secondary);
    margin: 0;
    line-height: 1.4;
}

.dc-doc-service {
    font-weight: 600;
    color: var(--dc-primary) !important;
    margin-top: 8px !important;
}

.dc-doc-intro {
    margin-bottom: 20px;
}

.dc-doc-intro p {
    font-size: 13px;
    color: var(--dc-text-secondary);
    line-height: 1.6;
}

.dc-doc-section {
    margin-bottom: 20px;
}

.dc-doc-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--dc-text);
    margin: 0 0 8px;
}

.dc-doc-section p {
    font-size: 13px;
    color: var(--dc-text-secondary);
    line-height: 1.5;
    margin: 0 0 8px;
}

.dc-doc-section p:last-child {
    margin-bottom: 0;
}

.dc-doc-section ul {
    margin: 0;
    padding-left: 20px;
}

.dc-doc-section li {
    font-size: 13px;
    color: var(--dc-text-secondary);
    line-height: 1.5;
    margin-bottom: 4px;
}

.dc-doc-section li:last-child {
    margin-bottom: 0;
}

/* Таблица в документе */
.dc-doc-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 12px;
}

.dc-doc-table th,
.dc-doc-table td {
    padding: 8px 10px;
    text-align: left;
    border: 1px solid var(--dc-border);
}

.dc-doc-table th {
    background: var(--dc-bg-secondary);
    font-weight: 600;
    color: var(--dc-text);
}

.dc-doc-table td {
    color: var(--dc-text-secondary);
}

/* Подвал документа */
.dc-doc-footer {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--dc-border);
}

.dc-doc-footer p {
    font-size: 12px;
    color: var(--dc-text-muted);
    margin: 0 0 4px;
}

/* Кнопка закрытия документа */
.dc-document-footer {
    padding: 16px 24px 24px;
    border-top: 1px solid var(--dc-border);
    background: var(--dc-bg);
}

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

/* Маленькие экраны */
@media (max-width: 480px) {
    .dc-modal-overlay {
        padding: 12px;
        align-items: flex-end;
    }
    
    .dc-modal {
        max-width: 100%;
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        border-radius: 16px 16px 0 0;
    }
    
    .dc-modal-header {
        padding: 20px 20px 0;
    }
    
    .dc-modal-title {
        padding: 16px 20px;
    }
    
    .dc-modal-title h1 {
        font-size: 20px;
    }
    
    .dc-modal-title p {
        font-size: 13px;
    }
    
    .dc-modal-form {
        padding: 0 20px;
    }
    
    .dc-checkbox {
        padding: 14px;
    }
    
    .dc-checkbox-text {
        font-size: 13px;
    }
    
    .dc-modal-footer {
        padding: 16px 20px 20px;
    }
    
    .dc-btn {
        padding: 12px 16px;
        font-size: 14px;
    }
    
    /* Документ */
    .dc-modal-document {
        max-width: 100%;
    }
    
    .dc-document-content {
        padding: 20px;
        padding-top: 50px;
    }
    
    .dc-document-footer {
        padding: 12px 20px 20px;
    }
}

/* Очень маленькие экраны */
@media (max-width: 360px) {
    .dc-modal-overlay {
        padding: 8px;
    }
    
    .dc-logo-icon {
        width: 32px;
        height: 32px;
    }
    
    .dc-logo-text {
        font-size: 20px;
    }
    
    .dc-modal-title h1 {
        font-size: 18px;
    }
    
    .dc-checkbox {
        padding: 12px;
        gap: 10px;
    }
    
    .dc-checkbox-mark {
        width: 22px;
        height: 22px;
    }
    
    .dc-checkbox-text {
        font-size: 12px;
    }
    
    .dc-buttons {
        flex-direction: column;
        gap: 10px;
    }
    
    .dc-doc-header h2 {
        font-size: 16px;
    }
    
    .dc-doc-section h3 {
        font-size: 13px;
    }
    
    .dc-doc-section p,
    .dc-doc-section li {
        font-size: 12px;
    }
}

/* Ландшафтная ориентация на мобильных */
@media (max-height: 500px) and (orientation: landscape) {
    .dc-modal-overlay {
        align-items: flex-start;
        padding: 8px;
    }
    
    .dc-modal {
        max-height: calc(100vh - 16px);
    }
    
    .dc-modal-header {
        padding: 12px 20px 0;
    }
    
    .dc-modal-title {
        padding: 12px 20px;
    }
    
    .dc-modal-title h1 {
        font-size: 18px;
        margin-bottom: 4px;
    }
    
    .dc-modal-title p {
        font-size: 12px;
    }
    
    .dc-modal-footer {
        padding: 12px 20px 16px;
    }
    
    .dc-footer-text {
        margin-bottom: 10px;
    }
}

/* =====================================================
   ПОДДЕРЖКА TELEGRAM ТЕМЫ
   ===================================================== */

/* Если Telegram передаёт цвет фона */
.dc-modal {
    background: var(--tg-theme-bg-color, var(--dc-bg));
}

.dc-checkbox {
    background: var(--tg-theme-secondary-bg-color, var(--dc-bg-secondary));
}

.dc-document-footer {
    background: var(--tg-theme-bg-color, var(--dc-bg));
}
