/* ============================================================
   Базовые переменные
   ============================================================ */
.iht-pdf-wrap {
    --pdf-bg:      #0d0d12;
    --pdf-card:    #16161f;
    --pdf-input:   #1e1e2a;
    --pdf-border:  #2a2a38;
    --pdf-text:    #f0f0f5;
    --pdf-muted:   #8888a0;
    --pdf-accent:  #ef4444;
    --pdf-radius:  24px;
    --pdf-yellow:  #f59e0b;
    --pdf-green:   #10b981;
    --pdf-edit:    #6366f1;
}

/* ============================================================
   Обёртка модуля
   ============================================================ */
.iht-pdf-wrap {
    background: var(--pdf-bg); border-radius: var(--pdf-radius); max-width: 800px; margin: 32px auto;
    color: var(--pdf-text); box-shadow: 0 0 0 1px var(--pdf-border), 0 32px 80px rgba(0,0,0,0.6);
    overflow: hidden; font-family: 'Inter', sans-serif; position: relative;
}

/* ============================================================
   Шапка
   ============================================================ */
.iht-pdf-header {
    display: flex; align-items: center; gap: 16px; padding: 20px 24px;
    border-bottom: 1px solid var(--pdf-border); background: var(--pdf-card);
}
.iht-pdf-icon {
    width: 46px; height: 46px; border-radius: 14px;
    background: linear-gradient(135deg, var(--pdf-accent), #b91c1c);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; color: #fff; flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(239,68,68,0.4);
}
.iht-pdf-title    { font-size: 16px; font-weight: 700; margin: 0; }
.iht-pdf-subtitle { font-size: 12px; color: var(--pdf-muted); margin-top: 4px; }

/* ============================================================
   Тело
   ============================================================ */
.iht-pdf-body { padding: 24px; }

.iht-pdf-dropzone {
    border: 2px dashed var(--pdf-border); border-radius: 16px; padding: 50px 20px;
    text-align: center; cursor: pointer; transition: 0.3s; background: var(--pdf-card);
    display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.iht-pdf-dropzone:hover { border-color: var(--pdf-accent); background: rgba(239,68,68,0.05); }
.iht-pdf-dropzone i     { font-size: 36px; color: var(--pdf-muted); }
.iht-pdf-link           { color: var(--pdf-accent); font-weight: 600; text-decoration: underline; }

/* ============================================================
   Сетка превью
   ============================================================ */
.iht-pdf-preview-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 16px; margin: 24px 0;
}
.iht-pdf-preview-item {
    background: var(--pdf-input); border: 1px solid var(--pdf-border); border-radius: 12px;
    padding: 6px; position: relative; cursor: grab; transition: transform 0.2s;
}
.iht-pdf-preview-item:hover { transform: scale(1.02); }
.iht-pdf-preview-item img {
    width: 100%; height: 110px; object-fit: cover; border-radius: 8px;
}

/* Кнопка удаления (крест) */
.iht-pdf-remove-item {
    position: absolute; top: -8px; right: -8px;
    width: 26px; height: 26px; background: #ef4444; color: #fff;
    border-radius: 50%; font-size: 12px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; border: 2px solid var(--pdf-bg); z-index: 5;
    transition: transform .15s;
}
.iht-pdf-remove-item:hover { transform: scale(1.15); background: #dc2626; }

/* Кнопка редактирования (карандаш) */
.iht-pdf-edit-item {
    position: absolute; top: -8px; left: -8px;
    width: 26px; height: 26px; background: var(--pdf-edit); color: #fff;
    border-radius: 50%; font-size: 11px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; border: 2px solid var(--pdf-bg); z-index: 5;
    transition: transform .15s;
}
.iht-pdf-edit-item:hover { transform: scale(1.15); background: #4f46e5; }

/* ============================================================
   Опции формата / ориентации
   ============================================================ */
.iht-pdf-options { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.iht-pdf-option  { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 130px; }
.iht-pdf-option label {
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .5px; color: #888;
    display: flex; align-items: center; gap: 6px;
}
.iht-pdf-option select {
    background: #1e1e2a; border: 1.5px solid #2a2a38; border-radius: 10px;
    padding: 9px 12px; color: #f0f0f5; font-size: 13px; outline: none;
    cursor: pointer; transition: border-color .2s; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px;
}
.iht-pdf-option select:focus { border-color: #ef4444; }

/* ============================================================
   Футер: кнопки
   ============================================================ */
.iht-pdf-footer { display: flex; gap: 12px; }

.iht-pdf-btn-primary {
    flex: 2; background: linear-gradient(135deg, var(--pdf-accent), #b91c1c);
    border: none; border-radius: 12px; color: #fff; font-size: 14px; font-weight: 700;
    padding: 14px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: 0.3s; box-shadow: 0 4px 12px rgba(239,68,68,0.2);
}
.iht-pdf-btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.iht-pdf-btn-primary:disabled { cursor: wait; opacity: 0.5; box-shadow: none; transform: none; }

.iht-pdf-btn-secondary {
    flex: 1; background: var(--pdf-input); border: 1px solid var(--pdf-border);
    border-radius: 12px; color: var(--pdf-muted); font-size: 14px; font-weight: 600;
    padding: 14px; cursor: pointer; transition: 0.2s;
}
.iht-pdf-btn-secondary:hover:not(:disabled) { border-color: #555; color: #fff; }
.iht-pdf-btn-secondary:disabled             { cursor: not-allowed; opacity: .45; }

/* ── Анимации PDF-генерации ── */
@keyframes pdf-bounce {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-5px); }
}
.iht-pdf-btn-primary.is-preparing:disabled {
    background: var(--pdf-yellow) !important; opacity: 1 !important;
    box-shadow: 0 4px 15px rgba(245,158,11,0.4);
}
.iht-pdf-btn-primary.is-processing:disabled {
    background: var(--pdf-green) !important; opacity: 1 !important;
    box-shadow: 0 4px 15px rgba(16,185,129,0.4);
}
.iht-pdf-btn-primary.is-processing i { animation: pdf-bounce 0.5s infinite; }

.pdf-ghost { opacity: 0.4; background: var(--pdf-accent) !important; }

/* ============================================================
   РЕДАКТОР — оверлей и модальное окно
   ============================================================ */
.iht-pdf-editor-overlay {
    position: fixed; inset: 0; z-index: 99999;
    background: rgba(5,5,10,0.85); backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center;
    padding: 16px; opacity: 0; pointer-events: none; transition: opacity .22s ease;
}
.iht-pdf-editor-overlay.is-visible { opacity: 1; pointer-events: auto; }

.iht-pdf-editor-modal {
    background: #13131c; border: 1px solid #2a2a3a; border-radius: 20px;
    width: 100%; max-width: 860px; box-shadow: 0 40px 100px rgba(0,0,0,0.7);
    display: flex; flex-direction: column; overflow: hidden;
    transform: translateY(12px) scale(.98); transition: transform .22s ease;
}
.iht-pdf-editor-overlay.is-visible .iht-pdf-editor-modal { transform: translateY(0) scale(1); }

/* Шапка */
.iht-pdf-editor-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 24px; border-bottom: 1px solid #232330; background: #0f0f18;
}
.iht-pdf-editor-title { font-size: 15px; font-weight: 700; color: #e0e0f0; display: flex; align-items: center; gap: 10px; }
.iht-pdf-editor-title i { color: var(--pdf-edit); }
.iht-pdf-editor-close {
    width: 32px; height: 32px; background: #1e1e2a; border: 1px solid #2a2a38; border-radius: 10px;
    color: var(--pdf-muted); font-size: 14px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.2s;
}
.iht-pdf-editor-close:hover { background: #2a2a3a; color: #ef4444; border-color: #ef4444; }

/* ── Лента форматов (ЦЕНТРИРОВАНИЕ) ── */
.iht-pdf-editor-ratios-wrap {
    background: #16161f; border-bottom: 1px solid #232330; padding: 16px 24px;
    display: flex; justify-content: center; /* Центрируем всю ленту */
}
.iht-pdf-editor-ratios {
    display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px;
    scrollbar-width: none; /* Firefox */
    position: relative; /* Для позиционирования ползунка */
    max-width: 100%;
}
.iht-pdf-editor-ratios::-webkit-scrollbar { display: none; } /* Chrome */

/* ── АНИМИРОВАННЫЙ ПОЛЗУНОК (Градиент как в ИИ чате) ── */
.iht-ratio-slider {
    position: absolute;
    top: 0; left: 0;
    height: 64px; /* Высота кнопки */
    background: linear-gradient(135deg, #a855f7, #ec4899); /* Тот самый градиент */
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4); /* Эффект свечения */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 0; /* Под кнопками */
    pointer-events: none; /* Чтобы клики проходили сквозь него */
}

/* Сами кнопки-форматы */
.iht-pdf-ratio-btn {
    position: relative; z-index: 1; /* Текст и иконка над ползунком */
    display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 8px;
    min-width: 68px; height: 64px; background: transparent; border: none; color: #8888a0;
    cursor: pointer; transition: color 0.2s; padding: 4px; border-radius: 12px;
}
.iht-pdf-ratio-btn:hover { color: #f0f0f5; }
.iht-pdf-ratio-btn.active { color: #fff; } /* Фон делает slider, здесь только белый цвет текста */
.iht-pdf-ratio-btn span { font-size: 11px; font-weight: 600; white-space: nowrap; }

.ratio-icon {
    border: 1.5px solid currentColor; border-radius: 4px;
    transition: 0.2s; margin-bottom: 2px;
}

/* ── Центральный тулбар (Ползунок и вращение) ── */
.iht-pdf-editor-toolbar {
    display: flex; gap: 24px; flex-wrap: wrap; padding: 16px 24px;
    border-bottom: 1px solid #1e1e2a; background: #11111a; align-items: center; justify-content: space-between;
}
.iht-pdf-slider-group { display: flex; align-items: center; gap: 16px; flex: 1; max-width: 400px; }
.iht-pdf-editor-label { font-size: 13px; font-weight: 700; color: #e0e0f0; }

/* Кастомный ползунок градусов */
.iht-range-slider { -webkit-appearance: none; width: 100%; background: transparent; margin: 0; }
.iht-range-slider::-webkit-slider-thumb {
    -webkit-appearance: none; height: 18px; width: 18px; border-radius: 50%;
    background: #fff; cursor: pointer; margin-top: -7px; box-shadow: 0 0 10px rgba(0,0,0,0.5); border: 2px solid var(--pdf-edit);
}
.iht-range-slider::-webkit-slider-runnable-track { width: 100%; height: 4px; cursor: pointer; background: #2a2a38; border-radius: 2px; }
.iht-range-slider::-moz-range-thumb { height: 18px; width: 18px; border-radius: 50%; background: #fff; cursor: pointer; border: 2px solid var(--pdf-edit); }
.iht-range-slider::-moz-range-track { width: 100%; height: 4px; cursor: pointer; background: #2a2a38; border-radius: 2px; }

.iht-pdf-editor-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.iht-pdf-editor-tool {
    background: #1a1a26; border: 1.5px solid #272735; border-radius: 8px; color: #aaa;
    font-size: 14px; padding: 8px 14px; cursor: pointer; transition: 0.18s; display: flex; align-items: center; justify-content: center;
}
.iht-pdf-editor-tool:hover  { border-color: #4a4a7a; color: #e0e0f0; background: #20202e; }
.iht-pdf-editor-tool.active { background: var(--pdf-edit); border-color: var(--pdf-edit); color: #fff; }

/* ── Canvas-обёртка ── */
.iht-pdf-editor-canvas-wrap {
    flex: 1; overflow: hidden; background: #08080c; display: flex; align-items: center; justify-content: center; min-height: 350px;
}
#iht-editor-canvas { display: block; max-width: 100%; user-select: none; -webkit-user-select: none; touch-action: none; }

/* ── Футер редактора ── */
.iht-pdf-editor-footer { display: flex; gap: 12px; padding: 16px 24px; border-top: 1px solid #1e1e2a; background: #0f0f18; }
.iht-pdf-editor-cancel-btn {
    flex: 1; padding: 14px; font-size: 14px; background: #1a1a26; border: 1px solid #272735; border-radius: 12px; color: var(--pdf-muted); cursor: pointer; transition: 0.18s;
}
.iht-pdf-editor-cancel-btn:hover { border-color: var(--pdf-muted); color: var(--pdf-text); }
.iht-editor-save-btn { flex: 2; padding: 14px; font-size: 14px; border-radius: 12px; }

@media (max-width: 600px) {
    .iht-pdf-editor-toolbar { flex-direction: column; align-items: stretch; gap: 16px; }
    .iht-pdf-slider-group { max-width: 100%; }
    .iht-pdf-editor-btns { justify-content: space-between; }
    .iht-pdf-editor-tool { flex: 1; }
}