/* ============================================================
   System B – Block Editor + Frontend Block Styles
   ------------------------------------------------------------
   Section 1: Frontend rendering (`.blocks` / `.block`)
   Section 2: Admin editor (`.be-*`)
   Section 3: Responsive rules
   ============================================================ */

/* ── Shared text alignment ─────────────────────────────── */
.has-text-align-left   { text-align: left; }
.has-text-align-center { text-align: center; }
.has-text-align-right  { text-align: right; }

/* ============================================================
   1. FRONTEND BLOCK RENDERING
   ============================================================ */
.blocks {
    display: block;
    max-width: 100%;
}
.blocks .block {
    margin-bottom: 1.5rem;
}
.blocks .block:last-child {
    margin-bottom: 0;
}
.blocks .block > * {
    margin-top: 0;
}

/* Paragraph */
.block-paragraph__text {
    margin-bottom: 1.1rem;
    line-height: 1.75;
}
.block-paragraph.has-drop-cap .block-paragraph__text:first-letter {
    font-size: 3.2em;
    font-weight: 700;
    float: left;
    line-height: 0.85;
    margin: 0.04em 0.12em 0 0;
}

/* Heading */
.block-heading__title {
    margin: 0 0 0.75rem;
    line-height: 1.25;
    font-weight: 700;
}

/* Image */
.block-image__figure {
    margin: 0;
    max-width: 100%;
}
.block-image__figure img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    display: block;
}
.block-image.has-text-align-center .block-image__figure,
.block-image.has-text-align-center .block-image__empty { margin: 0 auto; }
.block-image.has-text-align-right .block-image__figure,
.block-image.has-text-align-right .block-image__empty { margin-left: auto; }
.block-image__caption {
    font-size: 0.875rem;
    color: #6c757d;
    text-align: center;
    margin-top: 0.5rem;
}
.block-image__empty {
    border: 1px dashed #ced4da;
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    color: #adb5bd;
    background: #f8f9fa;
}

/* Quote */
.block-quote {
    padding: 0.25rem 0 0.25rem 1.25rem;
    border-left: 4px solid var(--bs-primary, #0d6efd);
}
.block-quote__content {
    margin: 0;
    font-style: italic;
    font-size: 1.1em;
    line-height: 1.6;
}
.block-quote__author {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: #6c757d;
}

/* List */
.block-list__items {
    padding-left: 1.5rem;
    line-height: 1.7;
}
.block-list__items li { margin-bottom: 0.35rem; }

/* Gallery */
.block-gallery__grid {
    display: grid;
    gap: 0.75rem;
}
.block-gallery__grid--1 { grid-template-columns: 1fr; }
.block-gallery__grid--2 { grid-template-columns: repeat(2, 1fr); }
.block-gallery__grid--3 { grid-template-columns: repeat(3, 1fr); }
.block-gallery__grid--4 { grid-template-columns: repeat(4, 1fr); }
.block-gallery__grid--5 { grid-template-columns: repeat(5, 1fr); }
.block-gallery__grid--6 { grid-template-columns: repeat(6, 1fr); }
.block-gallery__item { margin: 0; }
.block-gallery__item img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    border-radius: 0.4rem;
    display: block;
}
.block-gallery__item figcaption {
    font-size: 0.8rem;
    color: #6c757d;
    text-align: center;
    margin-top: 0.3rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.block-gallery__empty {
    border: 1px dashed #ced4da;
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    color: #adb5bd;
    background: #f8f9fa;
}

/* Embed */
.block-embed__wrap {
    position: relative;
    padding-top: 56.25%;
    border-radius: 0.5rem;
    overflow: hidden;
    background: #000;
}
.block-embed--square .block-embed__wrap { padding-top: 100%; }
.block-embed--tall .block-embed__wrap { padding-top: 75%; }
.block-embed__wrap iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}
.block-embed__empty {
    border: 1px dashed #ced4da;
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    color: #adb5bd;
    background: #f8f9fa;
}

/* Code */
.block-code__pre {
    background: #1e1e2e;
    color: #e4e4ef;
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
    overflow-x: auto;
    font-size: 0.875rem;
    line-height: 1.6;
}
.block-code__pre code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Table */
.block-table__scroll { overflow-x: auto; }
.block-table__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}
.block-table__table th,
.block-table__table td {
    border: 1px solid #dee2e6;
    padding: 0.5rem 0.75rem;
    text-align: left;
}
.block-table__table th { background: #f8f9fa; font-weight: 600; }
.block-table__table tr:nth-child(even) td { background: #fdfdfd; }
.block-table__empty {
    border: 1px dashed #ced4da;
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    color: #adb5bd;
}

/* Buttons */
.block-buttons__wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.block-buttons__wrap.has-text-align-center { justify-content: center; }
.block-buttons__wrap.has-text-align-right { justify-content: flex-end; }
.block-button {
    display: inline-block;
    padding: 0.55rem 1.25rem;
    border-radius: 0.4rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.15s ease;
}
.block-button--primary { background: var(--bs-primary, #0d6efd); color: #fff; }
.block-button--primary:hover { background: var(--bs-primary-darker, #0b5ed7); color: #fff; }
.block-button--secondary { background: #6c757d; color: #fff; }
.block-button--secondary:hover { background: #5c636a; color: #fff; }
.block-button--outline { background: transparent; color: var(--bs-primary, #0d6efd); border: 2px solid var(--bs-primary, #0d6efd); }
.block-button--outline:hover { background: var(--bs-primary, #0d6efd); color: #fff; }
.block-button__empty { color: #adb5bd; font-style: italic; }

/* Columns */
.block-columns__grid {
    display: grid;
    gap: 1.25rem;
}
.block-columns__grid--2 { grid-template-columns: 1fr 1fr; }
.block-columns__grid--3 { grid-template-columns: 1fr 1fr 1fr; }
.block-columns__grid--4 { grid-template-columns: repeat(4, 1fr); }
.block-columns--gap-wide .block-columns__grid { gap: 2rem; }
.block-columns--gap-narrow .block-columns__grid { gap: 0.5rem; }
.block-columns__col > *:last-child { margin-bottom: 0; }

/* Spacer / Divider */
.block-spacer { width: 100%; }
.block-divider { margin: 0; }
.block-divider__line { border: 0; border-top: 1px solid #dee2e6; margin: 0; }
.block-divider--dashed .block-divider__line { border-top-style: dashed; }
.block-divider--dotted .block-divider__line { border-top-style: dotted; }

/* ============================================================
   2. ADMIN BLOCK EDITOR
   ============================================================ */
.be-editor {
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    background: #fff;
    padding: 1rem;
    min-height: 320px;
}
.be-empty {
    border: 2px dashed #ced4da;
    border-radius: 0.5rem;
    padding: 3rem;
    text-align: center;
    color: #6c757d;
    cursor: pointer;
    transition: all 0.15s ease;
}
.be-empty:hover { border-color: var(--bs-primary, #0d6efd); color: var(--bs-primary, #0d6efd); }
.be-empty__plus {
    width: 44px;
    height: 44px;
    line-height: 40px;
    border-radius: 50%;
    border: 2px solid currentColor;
    font-size: 1.5rem;
    margin: 0 auto 0.5rem;
}
.be-empty p { margin: 0; font-size: 0.9rem; }
.be-empty code { background: #f1f3f5; padding: 0.1rem 0.35rem; border-radius: 0.25rem; }

/* Block wrapper */
.be-block {
    position: relative;
    margin-bottom: 0.75rem;
    border: 1px solid transparent;
    border-radius: 0.4rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.be-block:hover { border-color: #ced4da; }
.be-block.is-selected {
    border-color: var(--bs-primary, #0d6efd);
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.15);
    background: #fcfdff;
}
.be-block.is-dragging { opacity: 0.4; }
.be-block.is-drop-before { box-shadow: 0 -3px 0 0 var(--bs-primary, #0d6efd); }
.be-block.is-drop-after { box-shadow: 0 3px 0 0 var(--bs-primary, #0d6efd); }

/* Toolbar */
.be-block__toolbar {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.4rem;
    margin-bottom: 0.4rem;
    border-radius: 0.3rem;
    background: #f1f3f5;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.be-block:hover .be-block__toolbar,
.be-block.is-selected .be-block__toolbar { opacity: 1; }
.be-toolbar__type {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6c757d;
    padding-left: 0.25rem;
}
.be-toolbar__spacer { flex: 1; }

.be-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 0.3rem;
    padding: 0.25rem 0.45rem;
    color: #495057;
    cursor: pointer;
    line-height: 1;
    transition: background 0.12s ease;
}
.be-btn:hover { background: #e9ecef; color: #212529; }
.be-btn--sm { padding: 0.2rem 0.45rem; font-size: 0.8rem; }
.be-btn--danger:hover { background: #dc3545; color: #fff; }
.be-btn--primary { background: var(--bs-primary, #0d6efd); color: #fff; }
.be-btn--primary:hover { background: var(--bs-primary-darker, #0b5ed7); color: #fff; }

/* Body + contenteditable */
.be-block__body { padding: 0 0.25rem; }
.be-body-inner { min-height: 24px; }
.be-rte {
    outline: none;
    line-height: 1.7;
    margin: 0;
}
.be-block--paragraph .be-rte,
.be-block--quote .be-rte { min-height: 1.6em; }
.be-block--heading .be-rte { font-weight: 700; line-height: 1.3; }
.be-rte:focus { caret-color: var(--bs-primary, #0d6efd); }
.be-rte[data-placeholder]:empty::before {
    content: attr(data-placeholder);
    color: #adb5bd;
}

/* List editor */
.be-list__items { padding-left: 1.4rem; margin: 0; }
.be-list__item { outline: none; margin-bottom: 0.25rem; }

/* Inline tools row */
.be-inline-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.5rem;
    padding: 0.4rem;
    border-top: 1px dashed #e9ecef;
    background: #f8f9fa;
    border-radius: 0 0 0.3rem 0.3rem;
}
.be-inline-tools__label {
    font-size: 0.75rem;
    color: #6c757d;
    margin-right: 0.15rem;
}
.be-inline-tools__num { width: 64px !important; }
.be-inline-tools__check {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
    color: #495057;
    margin: 0;
    cursor: pointer;
}

/* Fields */
.be-field {
    display: block;
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
}
.be-field__label {
    display: block;
    font-size: 0.75rem;
    color: #6c757d;
    margin-bottom: 0.2rem;
}
.be-field--check {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    color: #495057;
}

/* Image editor */
.be-image__preview {
    min-height: 120px;
    border-radius: 0.4rem;
    overflow: hidden;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
}
.be-image__preview img { max-width: 100%; display: block; margin: 0 auto; }
.be-image__placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 120px;
    color: #adb5bd;
}
.be-image__placeholder p { margin: 0; font-size: 0.85rem; }
.be-image__tools { display: flex; gap: 0.35rem; margin-top: 0.5rem; align-items: center; }
.be-image__tools input { flex: 1; }

/* Gallery editor */
.be-gallery__grid { display: grid; gap: 0.5rem; }
.be-gallery__item {
    position: relative;
    border: 1px solid #e9ecef;
    border-radius: 0.3rem;
    overflow: hidden;
    cursor: pointer;
    aspect-ratio: 1;
    background: #f8f9fa;
}
.be-gallery__item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.be-gallery__empty {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #adb5bd;
    font-size: 1.5rem;
}

/* Embed editor */
.be-embed__preview {
    min-height: 120px;
    border-radius: 0.4rem;
    overflow: hidden;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
}
.be-embed__preview iframe { width: 100%; height: 260px; border: 0; display: block; }
.be-embed__placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 120px;
    color: #adb5bd;
}
.be-embed__placeholder p { margin: 0; font-size: 0.85rem; }

/* Code editor */
.be-code {
    background: #1e1e2e;
    border-radius: 0.4rem;
    padding: 0.75rem;
    margin: 0;
    overflow-x: auto;
}
.be-code__area {
    color: #e4e4ef;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
    outline: none;
    min-height: 60px;
}

/* Table editor */
.be-table__table { width: 100%; border-collapse: collapse; }
.be-table__table th,
.be-table__table td {
    border: 1px solid #dee2e6;
    padding: 0.4rem 0.5rem;
    min-width: 80px;
    outline: none;
}
.be-table__table th { background: #f1f3f5; font-weight: 600; }

/* Buttons editor */
.be-buttons__wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.be-buttons__item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem;
    border: 1px solid #e9ecef;
    border-radius: 0.35rem;
    background: #fff;
    flex-wrap: wrap;
}
.be-buttons__text { width: 110px !important; }
.be-buttons__url { width: 160px !important; flex: 1; }
.be-buttons__style { width: 110px !important; }
.be-buttons__check {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.78rem;
    color: #495057;
    margin: 0;
    cursor: pointer;
}

/* Columns editor */
.be-columns__grid { display: grid; gap: 0.6rem; }
.be-columns__grid--2 { grid-template-columns: 1fr 1fr; }
.be-columns__grid--3 { grid-template-columns: 1fr 1fr 1fr; }
.be-columns__grid--4 { grid-template-columns: repeat(4, 1fr); }
.be-columns__col {
    border: 1px solid #e9ecef;
    border-radius: 0.35rem;
    background: #fcfcfd;
    padding: 0.4rem;
}
.be-columns__col-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6c757d;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid #e9ecef;
}
.be-columns__col-body { padding-top: 0.4rem; }
.be-columns__empty {
    font-size: 0.78rem;
    color: #adb5bd;
    text-align: center;
    padding: 0.75rem;
    border: 1px dashed #dee2e6;
    border-radius: 0.3rem;
}

/* Mini (nested) blocks inside columns */
.be-mini-block {
    position: relative;
    border: 1px solid transparent;
    border-radius: 0.3rem;
    padding: 0.25rem;
    margin-bottom: 0.35rem;
}
.be-mini-block:hover { border-color: #ced4da; background: #fff; }
.be-mini-block__bar {
    display: flex;
    gap: 0.15rem;
    opacity: 0;
    transition: opacity 0.12s ease;
}
.be-mini-block:hover .be-mini-block__bar { opacity: 1; }
.be-mini-block .be-rte { font-size: 0.92em; }
.be-mini-heading { font-size: 1.05em !important; }
.be-mini-image { max-width: 100%; border-radius: 0.3rem; display: block; cursor: pointer; }
.be-mini-block ul { padding-left: 1.2rem; margin: 0.25rem 0; }
.be-mini-block ul li { outline: none; }

/* Spacer / Divider editor */
.be-spacer { background: repeating-linear-gradient(45deg, #f1f3f5, #f1f3f5 6px, #e9ecef 6px, #e9ecef 12px); border-radius: 0.3rem; }
.be-divider hr { border: 0; border-top: 2px solid #dee2e6; margin: 0.25rem 0; }
.be-divider--dashed hr { border-top-style: dashed; }
.be-divider--dotted hr { border-top-style: dotted; }

/* Slash command menu */
.be-slash {
    position: absolute;
    z-index: 1200;
    width: 260px;
    max-height: 320px;
    overflow: hidden;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.be-slash__search {
    border: 0 !important;
    border-bottom: 1px solid #e9ecef !important;
    border-radius: 0.5rem 0.5rem 0 0 !important;
}
.be-slash__list { max-height: 270px; overflow-y: auto; padding: 0.35rem; }
.be-slash__group {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #adb5bd;
    padding: 0.4rem 0.5rem 0.2rem;
}
.be-slash__item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    border: 0;
    background: transparent;
    padding: 0.4rem 0.5rem;
    border-radius: 0.3rem;
    text-align: left;
    cursor: pointer;
    font-size: 0.9rem;
    color: #212529;
}
.be-slash__item:hover { background: #f1f3f5; }
.be-slash__item i { color: var(--bs-primary, #0d6efd); }

/* Formatting bar */
.be-formatbar {
    position: absolute;
    z-index: 1300;
    display: flex;
    gap: 0.1rem;
    background: #212529;
    border-radius: 0.4rem;
    padding: 0.2rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.be-formatbar .be-btn { color: #fff; }
.be-formatbar .be-btn:hover { background: rgba(255, 255, 255, 0.15); color: #fff; }

/* Settings panel */
.be-settings {
    position: sticky;
    top: 90px;
}
.be-settings__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid #e9ecef;
    font-size: 0.9rem;
}
.be-settings__body { padding: 0.75rem; max-height: 60vh; overflow-y: auto; }
.be-settings__empty {
    padding: 1.5rem;
    color: #adb5bd;
    font-size: 0.85rem;
    text-align: center;
}

/* Media picker modal */
.be-media {
    position: fixed;
    inset: 0;
    z-index: 1400;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.be-media.show { display: flex; }
.be-media__dialog {
    background: #fff;
    border-radius: 0.6rem;
    width: 100%;
    max-width: 680px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.be-media__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e9ecef;
    font-weight: 600;
}
.be-media__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.75rem;
    padding: 1rem;
    overflow-y: auto;
}
.be-media__item {
    border: 1px solid #e9ecef;
    border-radius: 0.4rem;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.12s ease;
    background: #fff;
}
.be-media__item:hover { border-color: var(--bs-primary, #0d6efd); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); }
.be-media__item img { width: 100%; height: 90px; object-fit: cover; display: block; }
.be-media__item span {
    display: block;
    font-size: 0.75rem;
    padding: 0.35rem 0.5rem;
    color: #495057;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Blocks / Classic toggle */
.be-mode-toggle { display: flex; gap: 0.25rem; }
.be-mode-toggle .btn { border: 0; }

/* ============================================================
   3. RESPONSIVE
   ============================================================ */
@media (max-width: 767.98px) {
    .block-gallery__grid--3,
    .block-gallery__grid--4,
    .block-gallery__grid--5,
    .block-gallery__grid--6 {
        grid-template-columns: repeat(2, 1fr);
    }
    .block-gallery__item img { height: 110px; }

    .block-columns__grid--2,
    .block-columns__grid--3,
    .block-columns__grid--4 {
        grid-template-columns: 1fr;
    }
    .block-columns__grid--stack {
        grid-template-columns: 1fr !important;
    }

    .be-columns__grid--2,
    .be-columns__grid--3,
    .be-columns__grid--4 {
        grid-template-columns: 1fr !important;
    }
    .be-embed__preview iframe { height: 200px; }
}
