/**
 * TriEditor v1.0 — Стили визуального WYSIWYG-редактора
 * (c) TriCMS Team
 */

/* ================================
   Обёртка
   ================================ */
.trieditor-wrap {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
    transition: border-color .2s, box-shadow .2s;
    position: relative;
}

.trieditor-wrap:focus-within {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .12);
}

/* ================================
   Тулбар
   ================================ */
.trieditor-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    background: #f8f9fb;
    border-bottom: 1px solid #e5e7eb;
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 10;
}

.trieditor-btn-group {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    margin-right: 4px;
    padding-right: 6px;
    border-right: 1px solid #e5e7eb;
}

.trieditor-btn-group:last-child {
    border-right: none;
    margin-right: 0;
    padding-right: 0;
}

.trieditor-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #374151;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all .15s;
    position: relative;
}

.trieditor-btn:hover {
    background: #e5e7eb;
    color: #111827;
}

.trieditor-btn.active {
    background: #6366f1;
    color: #fff;
}

.trieditor-btn.active:hover {
    background: #4f46e5;
}

.trieditor-btn i {
    font-size: 13px;
    line-height: 1;
}

.trieditor-btn--label {
    width: auto;
    min-width: 32px;
    padding: 0 7px;
    font-weight: 700;
}

.trieditor-btn-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
}

/* ================================
   Dropdown формата
   ================================ */
.trieditor-dropdown {
    position: relative;
}

.trieditor-dropdown-toggle {
    width: auto;
    padding: 0 8px;
    gap: 4px;
    font-size: 12px;
    font-weight: 500;
    min-width: 100px;
    justify-content: space-between;
}

.trieditor-dropdown-toggle .fa-caret-down {
    font-size: 10px;
    opacity: .6;
    margin-left: 4px;
}

.trieditor-format-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.trieditor-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 160px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
    z-index: 100;
    padding: 4px;
    margin-top: 2px;
}

.trieditor-dropdown-menu.open {
    display: block;
}

.trieditor-dropdown-item {
    display: block;
    width: 100%;
    padding: 6px 10px;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
    color: #374151;
    margin: 0;
    font-weight: normal;
    transition: background .1s;
}

.trieditor-dropdown-item:hover {
    background: #f3f4f6;
}

h2.trieditor-dropdown-item {
    font-size: 1.3em;
    font-weight: 700;
}

h3.trieditor-dropdown-item {
    font-size: 1.15em;
    font-weight: 600;
}

h4.trieditor-dropdown-item {
    font-size: 1em;
    font-weight: 600;
}

/* Font size dropdown */
.trieditor-fontsize-toggle {
    min-width: 70px;
    gap: 3px;
    font-size: 12px;
}

.trieditor-fontsize-toggle i:first-child {
    font-size: 11px;
    opacity: .7;
}

.trieditor-fontsize-label {
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

.trieditor-fontsize-menu {
    max-height: 250px;
    overflow-y: auto;
    min-width: 90px;
}

.trieditor-fontsize-item {
    padding: 4px 10px;
    line-height: 1.4;
}

.trieditor-fontsize-item span {
    display: block;
    white-space: nowrap;
}

/* ================================
   Цвета — Палитра (DLE-style)
   ================================ */
.trieditor-palette-group {
    border-right: 1px solid #e5e7eb;
    margin-right: 4px;
    padding-right: 6px;
}

.trieditor-palette-wrap {
    position: relative;
}

.trieditor-color-btn {
    position: relative;
    width: auto;
    padding: 0 4px;
    gap: 2px;
}

.trieditor-color-bar {
    position: absolute;
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
    width: 18px;
    height: 3px;
    border-radius: 2px;
}

.trieditor-palette-panel {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
    z-index: 100;
    padding: 8px;
    margin-top: 2px;
    width: 174px;
}

.trieditor-palette-panel.open {
    display: block;
}

.trieditor-palette-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 3px;
    margin-bottom: 6px;
}

.trieditor-swatch {
    width: 30px;
    height: 26px;
    border: 1px solid rgba(0, 0, 0, .08);
    border-radius: 4px;
    cursor: pointer;
    transition: transform .1s, box-shadow .1s;
    padding: 0;
}

.trieditor-swatch:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
    z-index: 2;
    position: relative;
}

.trieditor-swatch-border {
    border: 1px solid #ccc;
}

.trieditor-palette-bottom {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-top: 6px;
    border-top: 1px solid #e5e7eb;
}

.trieditor-palette-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 26px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    background: #f9fafb;
    cursor: pointer;
    color: #555;
    font-size: 13px;
    transition: all .15s;
    padding: 0;
}

.trieditor-palette-action:hover {
    background: #e5e7eb;
    color: #111;
}

.trieditor-palette-custom-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
}

/* ================================
   Область редактирования
   ================================ */
.trieditor-content {
    padding: 16px 20px;
    outline: none;
    font-size: 15px;
    line-height: 1.65;
    color: #1f2937;
    overflow-y: auto;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.trieditor-content:empty::before {
    content: attr(data-placeholder);
    color: #9ca3af;
    pointer-events: none;
    font-style: italic;
}

/* Стили контента внутри редактора */
.trieditor-content p {
    margin: 0 0 0.8em;
}

.trieditor-content h2 {
    font-size: 1.5em;
    font-weight: 700;
    margin: 1em 0 0.5em;
    color: #111827;
}

.trieditor-content h3 {
    font-size: 1.25em;
    font-weight: 600;
    margin: 0.8em 0 0.4em;
    color: #1f2937;
}

.trieditor-content h4 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 0.6em 0 0.3em;
    color: #374151;
}

.trieditor-content blockquote {
    margin: 1em 0;
    padding: 12px 16px;
    border-left: 4px solid #6366f1;
    background: #f5f3ff;
    color: #4b5563;
    border-radius: 0 6px 6px 0;
    font-style: italic;
}

.trieditor-content ul,
.trieditor-content ol {
    margin: 0.5em 0;
    padding-left: 2em;
}

.trieditor-content li {
    margin-bottom: 0.25em;
}

.trieditor-content a {
    color: #6366f1;
    text-decoration: underline;
}

.trieditor-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin: 8px 0;
}

.trieditor-content table,
.trieditor-content .trieditor-table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

.trieditor-content table td,
.trieditor-content table th,
.trieditor-content .trieditor-table td,
.trieditor-content .trieditor-table th {
    border: 1px solid #d1d5db;
    padding: 8px 12px;
    text-align: left;
}

.trieditor-content table th,
.trieditor-content .trieditor-table th {
    background: #f3f4f6;
    font-weight: 600;
}

.trieditor-content hr {
    border: none;
    border-top: 2px solid #e5e7eb;
    margin: 1.5em 0;
}

.trieditor-content pre,
.trieditor-content code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    background: #f3f4f6;
    border-radius: 4px;
}

.trieditor-content code {
    padding: 2px 5px;
    font-size: 0.9em;
    color: #e11d48;
}

.trieditor-content pre {
    padding: 12px 16px;
    overflow-x: auto;
    margin: 1em 0;
}

/* ================================
   Режим исходного кода
   ================================ */
.trieditor-source {
    display: none;
    width: 100%;
    border: none;
    outline: none;
    padding: 16px 20px;
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #1f2937;
    background: #fefce8;
    resize: vertical;
    box-sizing: border-box;
}

/* ================================
   Нижняя панель
   ================================ */
.trieditor-statusbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 12px;
    background: #f8f9fb;
    border-top: 1px solid #e5e7eb;
    font-size: 11px;
    color: #9ca3af;
}

.trieditor-brand {
    font-weight: 600;
    color: #6366f1;
    letter-spacing: .3px;
}

.trieditor-counter {
    color: #6b7280;
    font-size: 11px;
    font-weight: 500;
}

.trieditor-path {
    font-family: monospace;
    font-size: 10px;
    color: #9ca3af;
}

/* ================================
   Полноэкранный режим
   ================================ */
.trieditor-fullscreen {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99999;
    border-radius: 0;
    border: none;
    display: flex;
    flex-direction: column;
}

.trieditor-fullscreen .trieditor-toolbar {
    position: sticky;
    top: 0;
    flex-shrink: 0;
}

.trieditor-fullscreen .trieditor-content {
    flex: 1;
    overflow-y: auto;
    min-height: auto !important;
}

.trieditor-fullscreen .trieditor-source {
    flex: 1;
    min-height: auto !important;
}

.trieditor-fullscreen .trieditor-statusbar {
    flex-shrink: 0;
}

/* ================================
   Модальные окна
   ================================ */
.trieditor-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: trieditor-fade-in .15s ease;
}

@keyframes trieditor-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.trieditor-modal {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .2);
    width: 420px;
    max-width: 90vw;
    animation: trieditor-slide-up .2s ease;
}

@keyframes trieditor-slide-up {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.trieditor-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 15px;
    color: #111827;
}

.trieditor-modal-close {
    border: none;
    background: transparent;
    font-size: 22px;
    cursor: pointer;
    color: #9ca3af;
    padding: 0;
    line-height: 1;
    transition: color .15s;
}

.trieditor-modal-close:hover {
    color: #ef4444;
}

.trieditor-modal-body {
    padding: 16px 20px;
}

.trieditor-modal-row {
    margin-bottom: 14px;
}

.trieditor-modal-row:last-child {
    margin-bottom: 0;
}

.trieditor-modal-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 4px;
}

.trieditor-modal-input {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    color: #1f2937;
    transition: border-color .15s, box-shadow .15s;
    box-sizing: border-box;
}

.trieditor-modal-input:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .12);
}

.trieditor-modal-check {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
}

.trieditor-modal-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #6366f1;
}

.trieditor-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    border-radius: 0 0 12px 12px;
}

.trieditor-modal-btn {
    padding: 8px 18px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    background: #fff;
    color: #374151;
    transition: all .15s;
}

.trieditor-modal-btn:hover {
    background: #f3f4f6;
}

.trieditor-modal-btn.primary {
    background: #6366f1;
    color: #fff;
    border-color: #6366f1;
}

.trieditor-modal-btn.primary:hover {
    background: #4f46e5;
}

/* ================================
   Загрузка файлов
   ================================ */
.trieditor-upload-modal {
    width: 620px;
    max-width: 95vw;
}

.trieditor-upload-drop {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 32px 20px;
    text-align: center;
    background: #f9fafb;
    transition: all .2s;
    margin-bottom: 12px;
}

.trieditor-upload-drop.dragover {
    border-color: #6366f1;
    background: #eef2ff;
}

.trieditor-upload-drop-icon {
    font-size: 40px;
    color: #9ca3af;
    margin-bottom: 8px;
}

.trieditor-upload-drop.dragover .trieditor-upload-drop-icon {
    color: #6366f1;
}

.trieditor-upload-drop p {
    margin: 0;
    color: #6b7280;
    font-size: 14px;
}

.trieditor-upload-browse {
    color: #6366f1;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
}

.trieditor-upload-browse:hover {
    color: #4f46e5;
}

.trieditor-upload-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
}

.trieditor-upload-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 0 4px;
}

.trieditor-upload-progress-bar {
    flex: 1;
    height: 8px;
    background: #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
}

.trieditor-upload-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #818cf8);
    border-radius: 8px;
    transition: width .3s;
    width: 0;
}

.trieditor-upload-progress-text {
    font-size: 12px;
    font-weight: 600;
    color: #6366f1;
    min-width: 36px;
    text-align: right;
}

.trieditor-upload-files {
    max-height: 260px;
    overflow-y: auto;
}

.trieditor-upload-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin-bottom: 6px;
    background: #fff;
    transition: background .2s;
}

.trieditor-upload-file.inserted {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.trieditor-upload-file-error {
    background: #fef2f2;
    border-color: #fecaca;
}

.trieditor-upload-thumb {
    width: 56px;
    height: 48px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
}

.trieditor-upload-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.trieditor-upload-thumb-file {
    font-size: 20px;
    color: #9ca3af;
}

.trieditor-upload-file-error .trieditor-upload-thumb-file {
    color: #e74c3c;
}

.trieditor-upload-info {
    flex: 1;
    min-width: 0;
}

.trieditor-upload-name {
    font-size: 13px;
    font-weight: 500;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.trieditor-upload-size {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 2px;
}

.trieditor-upload-insert-btn {
    flex-shrink: 0;
    padding: 5px 14px;
    border: 1px solid #6366f1;
    background: #6366f1;
    color: #fff;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.trieditor-upload-insert-btn:hover {
    background: #4f46e5;
    border-color: #4f46e5;
}

.trieditor-upload-insert-btn:disabled {
    background: #22c55e;
    border-color: #22c55e;
    cursor: default;
}

/* Модалка вставки изображения с выбором размера и выравнивания */
.trieditor-insert-image-modal {
    width: 420px;
}

.trieditor-insert-size-opt {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    margin-top: 4px;
}

.trieditor-radio {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 400;
}

.trieditor-radio input {
    margin: 0;
}

.trieditor-insert-align {
    margin-top: 4px;
    max-width: 180px;
}

/* ================================
   Адаптивность
   ================================ */
@media (max-width: 768px) {
    .trieditor-toolbar {
        padding: 4px 4px;
        gap: 1px;
    }

    .trieditor-btn {
        width: 28px;
        height: 28px;
        font-size: 11px;
    }

    .trieditor-btn-group {
        margin-right: 2px;
        padding-right: 3px;
    }

    .trieditor-dropdown-toggle {
        min-width: 80px;
        font-size: 11px;
    }

    .trieditor-content {
        padding: 12px 14px;
        font-size: 14px;
    }

    .trieditor-modal {
        width: 340px;
    }

    .trieditor-upload-modal {
        width: 95vw;
    }

    .trieditor-palette-panel {
        left: auto;
        right: 0;
    }
}

@media (max-width: 480px) {
    .trieditor-btn-group {
        border-right: none;
    }

    .trieditor-upload-file {
        flex-wrap: wrap;
    }

    .trieditor-upload-insert-btn {
        width: 100%;
        justify-content: center;
    }
}