/* ==========================================================================
   BBCode: оформление редактора и отрендеренного текста.
   Подключается вместе с /js/bbcode-editor.js.
   ========================================================================== */

/* ---------- Редактор ---------- */
.bb-editor {
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: .375rem;
    background: var(--bs-body-bg, #fff);
    overflow: hidden;
}

.bb-editor:focus-within {
    border-color: #86b7fe;
    box-shadow: 0 0 0 .25rem rgba(13, 110, 253, .15);
}

.bb-editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .15rem;
    padding: .3rem .4rem;
    background: var(--bs-tertiary-bg, #f8f9fa);
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}

.bb-editor-toolbar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    font-size: .9rem;
    color: var(--bs-body-color, #212529);
    background: transparent;
    border: 0;
    border-radius: .25rem;
    cursor: pointer;
    transition: background-color .12s ease, color .12s ease;
}

.bb-editor-toolbar button:hover {
    background: rgba(13, 110, 253, .12);
    color: var(--bs-primary, #0d6efd);
}

.bb-editor-toolbar .bb-sep {
    width: 1px;
    height: 1.2rem;
    margin: 0 .3rem;
    background: var(--bs-border-color, #dee2e6);
}

.bb-editor-toolbar .bb-spacer {
    flex: 1 1 auto;
}

.bb-editor-tabs {
    display: flex;
    gap: .25rem;
    padding: .3rem .4rem 0;
}

.bb-editor-tabs button {
    padding: .2rem .7rem;
    font-size: .8rem;
    color: var(--bs-secondary-color, #6c757d);
    background: transparent;
    border: 1px solid transparent;
    border-bottom: 0;
    border-radius: .25rem .25rem 0 0;
    cursor: pointer;
}

.bb-editor-tabs button:hover {
    color: var(--bs-body-color, #212529);
}

.bb-editor-tabs button.active {
    color: var(--bs-primary, #0d6efd);
    background: var(--bs-body-bg, #fff);
    border-color: var(--bs-border-color, #dee2e6);
}

/* Само поле ввода не имеет собственной рамки — её даёт обёртка. */
.bb-editor > textarea.bb-editor-input {
    display: block;
    width: 100%;
    padding: .6rem .75rem;
    font-family: var(--bs-body-font-family);
    font-size: .95rem;
    line-height: 1.5;
    color: var(--bs-body-color, #212529);
    background: transparent;
    border: 0;
    border-radius: 0;
    resize: vertical;
}

.bb-editor > textarea.bb-editor-input:focus {
    outline: none;
    box-shadow: none;
}

.bb-editor.is-preview > textarea.bb-editor-input {
    display: none;
}

.bb-editor-preview {
    display: none;
    min-height: 8rem;
    max-height: 34rem;
    overflow-y: auto;
    padding: .75rem;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
}

.bb-editor.is-preview .bb-editor-preview {
    display: block;
}

.bb-editor-preview .bb-empty {
    color: var(--bs-secondary-color, #6c757d);
    font-style: italic;
}

/* ---------- Отрендеренный текст ---------- */
.bb-text {
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.bb-text > *:first-child {
    margin-top: 0;
}

.bb-text > *:last-child {
    margin-bottom: 0;
}

.bb-text p {
    margin: 0 0 .65rem;
}

.bb-text a {
    color: var(--bs-link-color, #0d6efd);
    text-decoration: underline;
}

.bb-text a:hover {
    color: var(--bs-link-hover-color, #0a58ca);
}

.bb-text .bb-img {
    max-width: 100%;
    height: auto;
    border-radius: .25rem;
}

.bb-text .bb-video {
    position: relative;
    max-width: 100%;
    aspect-ratio: 16 / 9;
    margin: .5rem 0;
    border: 0;
    border-radius: .25rem;
    overflow: hidden;
}

.bb-text .bb-video iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.bb-text .bb-quote {
    margin: .65rem 0;
    padding: .5rem .85rem;
    background: var(--bs-tertiary-bg, #f8f9fa);
    border-left: 3px solid var(--bs-primary, #0d6efd);
    border-radius: 0 .25rem .25rem 0;
}

.bb-text .bb-quote-author {
    display: block;
    margin-bottom: .25rem;
    font-size: .85rem;
    font-weight: 600;
    color: var(--bs-secondary-color, #6c757d);
}

.bb-text .bb-quote-author::before {
    content: '“';
}

.bb-text .bb-quote-author::after {
    content: '”';
}

.bb-text .bb-code {
    display: block;
    margin: .65rem 0;
    padding: .6rem .8rem;
    font-family: var(--bs-font-monospace, SFMono-Regular, Menlo, Consolas, monospace);
    font-size: .85rem;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-x: auto;
    background: #f6f8fa;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: .25rem;
}

.bb-text .bb-spoiler {
    margin: .65rem 0;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: .25rem;
    background: var(--bs-tertiary-bg, #f8f9fa);
}

.bb-text .bb-spoiler > summary {
    padding: .4rem .7rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    list-style: none;
}

.bb-text .bb-spoiler > summary::-webkit-details-marker {
    display: none;
}

.bb-text .bb-spoiler > summary::before {
    content: '▸ ';
    display: inline-block;
    transition: transform .12s ease;
}

.bb-text .bb-spoiler[open] > summary::before {
    content: '▾ ';
}

.bb-text .bb-spoiler-body {
    padding: .1rem .7rem .6rem;
    border-top: 1px dashed var(--bs-border-color, #dee2e6);
}

.bb-text .bb-table-wrap {
    margin: .65rem 0;
    overflow-x: auto;
}

.bb-text .bb-table {
    width: 100%;
    margin: 0;
    font-size: .9rem;
    border-collapse: collapse;
}

.bb-text .bb-table th,
.bb-text .bb-table td {
    padding: .35rem .6rem;
    border: 1px solid var(--bs-border-color, #dee2e6);
    vertical-align: top;
}

.bb-text .bb-table th {
    background: var(--bs-tertiary-bg, #f8f9fa);
    font-weight: 600;
}

.bb-text .bb-hr {
    margin: 1rem 0;
    border: 0;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
}

.bb-text .bb-center {
    text-align: center;
}

.bb-text .bb-list {
    margin: .5rem 0 .65rem;
    padding-left: 1.5rem;
}

.bb-text .bb-list > li {
    margin-bottom: .2rem;
}

.bb-text .bb-error {
    padding: .3rem .5rem;
    font-size: .85rem;
    color: var(--bs-danger-text-emphasis, #58151c);
    background: var(--bs-danger-bg-subtle, #f8d7da);
    border-left: 3px solid var(--bs-danger, #dc3545);
    border-radius: 0 .25rem .25rem 0;
}
/* ---------- Палитра выбора цвета ---------- */
.bb-palette {
    position: fixed;
    z-index: 1080;
    width: 220px;
    padding: .5rem;
    background: linear-gradient(180deg, rgba(17, 25, 34, 0.98), rgba(11, 16, 23, 0.96));
    border: 1px solid rgba(126, 180, 255, 0.18);
    border-radius: .4rem;
    box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .35);
    color: #edf3ff;
}

.bb-palette-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: .25rem;
}

.bb-swatch {
    width: 100%;
    aspect-ratio: 1 / 1;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, .15);
    border-radius: .2rem;
    cursor: pointer;
}

.bb-swatch:hover {
    outline: 2px solid var(--bs-primary, #0d6efd);
    outline-offset: 1px;
}

.bb-palette-custom {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    width: 100%;
    margin-top: .5rem;
    padding: .3rem .5rem;
    font-size: .82rem;
    color: #edf3ff;
    background: rgba(8, 12, 17, 0.9);
    border: 1px solid rgba(126, 180, 255, 0.18);
    border-radius: .3rem;
    cursor: pointer;
}

.bb-palette-custom:hover {
    color: var(--bs-primary, #0d6efd);
    border-color: var(--bs-primary, #0d6efd);
}

.bb-palette-picker {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ==========================================================================
   СТИКЕРЫ
   ========================================================================== */

/* Рендер стикера в тексте */
.bb-text .bb-sticker {
    width: 120px;
    height: 120px;
    object-fit: contain;
    display: inline-block;
    vertical-align: bottom;
    margin: .25rem .15rem;
    border-radius: .25rem;
    pointer-events: none;
}

/* Кнопка стикеров в тулбаре */
.bb-editor-toolbar .bb-sticker-btn {
    position: relative;
}

/* Панель стикеров */
.bb-sticker-panel {
    position: fixed;
    z-index: 1075;
    width: 320px;
    max-height: 420px;
    background: linear-gradient(180deg, rgba(17, 25, 34, 0.98), rgba(11, 16, 23, 0.96));
    border: 1px solid rgba(126, 180, 255, 0.18);
    border-radius: .5rem;
    box-shadow: 0 .5rem 1.5rem rgba(0, 0, 0, .35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #edf3ff;
}

.bb-sticker-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .5rem .75rem;
    border-bottom: 1px solid rgba(126, 180, 255, 0.15);
    background: rgba(12, 18, 25, 0.95);
}

.bb-sticker-panel-header h6 {
    margin: 0;
    font-size: .85rem;
    font-weight: 600;
    color: #edf3ff;
}

.bb-sticker-panel-close {
    background: none;
    border: none;
    padding: .15rem .3rem;
    font-size: 1rem;
    color: rgba(237, 243, 255, 0.8);
    cursor: pointer;
    border-radius: .2rem;
    line-height: 1;
}

.bb-sticker-panel-close:hover {
    color: var(--bs-body-color, #212529);
    background: rgba(0, 0, 0, .05);
}

/* Контейнер категорий и контента */
.bb-sticker-panel-body {
    display: flex;
    flex: 1 1 auto;
    overflow: hidden;
}

/* Табы категорий (вертикальные слева) */
.bb-sticker-categories {
    width: 56px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-right: 1px solid rgba(126, 180, 255, 0.15);
    background: rgba(12, 18, 25, 0.95);
}

.bb-sticker-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .15rem;
    padding: .4rem .2rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: .65rem;
    color: rgba(237, 243, 255, 0.7);
    transition: background-color .12s ease, color .12s ease;
    border-right: 2px solid transparent;
    min-height: 52px;
}

.bb-sticker-tab:hover {
    background: rgba(94, 200, 255, .08);
    color: #edf3ff;
}

.bb-sticker-tab.active {
    background: rgba(8, 12, 17, 0.9);
    color: var(--bs-primary, #5ec8ff);
    border-right-color: var(--bs-primary, #5ec8ff);
    font-weight: 600;
}

.bb-sticker-tab i {
    font-size: 1.1rem;
}

/* Сетка стикеров */
.bb-sticker-grid {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .25rem;
    padding: .5rem;
    overflow-y: auto;
    align-content: start;
}

.bb-sticker-item {
    width: 100%;
    aspect-ratio: 1 / 1;
    padding: 0;
    border: 1px solid transparent;
    border-radius: .35rem;
    background: transparent;
    cursor: pointer;
    transition: border-color .12s ease, background-color .12s ease, transform .1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bb-sticker-item:hover {
    border-color: var(--bs-primary, #0d6efd);
    background: rgba(13, 110, 253, .06);
    transform: scale(1.05);
}

.bb-sticker-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    border-radius: .2rem;
}

/* Адаптив для мобильных */
@media (max-width: 575.98px) {
    .bb-sticker-panel {
        width: calc(100vw - 1.5rem);
        max-height: 60vh;
    }

    .bb-sticker-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .bb-text .bb-sticker {
        width: 90px;
        height: 90px;
    }
}
