/* =================================================================
   Blog module — categories, post list, single post view.
   Built on shared design tokens (see themes/*/default/style.css).
   ================================================================= */

.bg-head-bar {
    display: flex !important; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; flex-wrap: nowrap;
    padding: .3rem .7rem !important; background: var(--surface) !important; border: 1px solid var(--border) !important; border-radius: var(--radius, 5px);
}
.bg-head-bar h1 { margin: 0; font-size: .95rem; }

/* Icon-only add button, right-aligned with the page title */
.page-add-btn {
    display: flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
    background: var(--indigo); text-decoration: none; font-size: .82rem;
    box-shadow: 0 3px 10px -3px rgba(0,0,0,.3);
    transition: background .12s ease, transform .1s ease;
}
.page-add-btn:hover { background: var(--indigo-deep); }
.page-add-btn:active { transform: scale(.94); }

/* ---------- Category grid ----------------------------------------- */
.bg-categories-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: .5rem; margin-bottom: 1.5rem; }
.bg-category-card {
    display: flex; flex-direction: column; align-items: center; text-align: center; gap: .15rem;
    text-decoration: none; color: inherit; padding: .65rem .4rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    transition: transform .1s ease, box-shadow .15s ease;
}
.bg-category-card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px -6px rgba(0,0,0,.15); }
.bg-category-icon { font-size: 1.25rem; }
.bg-category-name { font-weight: 700; font-size: .76rem; color: var(--ink); }
.bg-category-count { font-size: .64rem; color: var(--ink-soft); }

/* ---------- Sub-nav (All / New / Top / My) — matches the Members module ---------- */
.bg-subnav {
    display: flex; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius, 5px); margin-bottom: 1.25rem; overflow: hidden;
}
.bg-subnav a {
    flex: 1; text-align: center; padding: .4rem .3rem; text-decoration: none;
    color: var(--ink-soft); font-weight: 600; font-size: .72rem; position: relative;
    border-bottom: 2px solid transparent; white-space: nowrap;
}
.bg-subnav a.is-active { color: var(--indigo); border-bottom-color: var(--indigo); background: var(--indigo-soft, var(--paper)); }
.bg-subnav-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 16px; height: 16px; padding: 0 .28rem; margin-left: .2rem;
    background: var(--success); color: #fff; border-radius: 999px; font-size: .64rem; font-weight: 700;
}
.bg-subnav-badge-neutral { background: var(--indigo); }

.bg-panel { margin-bottom: 1.5rem; }
.bg-section-head {
    font-family: var(--font-display); font-weight: 800; font-size: .95rem; margin: 0;
    padding: .3rem .7rem; background: var(--surface); border: 1px solid var(--border); border-bottom: none;
    border-radius: var(--radius, 5px) var(--radius, 5px) 0 0;
}

/* ---------- Post list ----------------------------------------------- */
.bg-post-list {
    display: flex; flex-direction: column; gap: 0;
    background: var(--paper); border: 1px solid var(--border); border-top: none;
    border-radius: 0 0 var(--radius, 5px) var(--radius, 5px); padding: 0;
}
.bg-post-row {
    display: flex; gap: .9rem; align-items: flex-start;
    background: var(--surface); border: 1px solid var(--border); border-bottom: none; border-radius: 0;
    padding: .8rem .9rem; text-decoration: none; color: inherit;
    transition: box-shadow .15s ease, transform .1s ease;
}
.bg-post-list .bg-post-row:first-child { border-radius: var(--radius, 5px) var(--radius, 5px) 0 0; }
.bg-post-list .bg-post-row:last-child { border-bottom: 1px solid var(--border); border-radius: 0 0 var(--radius, 5px) var(--radius, 5px); }
.bg-post-row:hover { box-shadow: 0 4px 14px -8px rgba(0,0,0,.18); transform: translateY(-1px); }
.bg-post-row-thumb {
    flex-shrink: 0; width: 84px; height: 84px; border-radius: 8px; overflow: hidden;
    background: var(--paper); display: flex; align-items: center; justify-content: center; font-size: 1.8rem;
}
.bg-post-row-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bg-post-row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .2rem; }
.bg-category-badge {
    align-self: flex-start; font-size: .7rem; font-weight: 700; padding: .1rem .5rem; border-radius: 999px;
    background: var(--indigo-soft, var(--paper)); color: var(--indigo);
}
.bg-post-row-title { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bg-post-row-excerpt { margin: 0; font-size: .84rem; color: var(--ink-soft); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.bg-post-row-meta { display: flex; gap: .7rem; flex-wrap: wrap; font-size: .76rem; color: var(--ink-soft); }

/* ---------- Breadcrumb ------------------------------------------------ */
.bg-breadcrumb { font-size: .72rem; line-height: 1.2; color: var(--ink-soft); margin-bottom: .4rem; }
.bg-breadcrumb a { color: var(--ink-soft); text-decoration: none; }
.bg-breadcrumb a:hover { color: var(--indigo); }
.bg-breadcrumb span { color: var(--ink); font-weight: 600; }

/* ---------- Single post ------------------------------------------------ */
.bg-post {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem 1.1rem; box-shadow: var(--shadow);
}
.bg-post-title-row { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .35rem; }
.bg-post-title-row .bg-post-title { flex: 1; min-width: 0; margin-bottom: 0; font-size: 1.2rem; }
.bg-post-byline { font-size: .85rem; margin-bottom: 1rem; }
.bg-post-byline a { font-weight: 600; }

/* ---------- Post kebab menu (Edit / Delete) ------------------------- */
.bg-menu { position: relative; flex-shrink: 0; }
.bg-menu-btn {
    display: flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 50%; border: none; background: none;
    color: var(--ink-soft); font-size: 1.1rem; font-weight: 800; line-height: 1;
    cursor: pointer; transition: background .12s ease, color .12s ease;
}
.bg-menu-btn:hover, .bg-menu.is-open .bg-menu-btn { background: var(--paper); color: var(--ink); }
.bg-menu-dropdown {
    position: absolute; top: calc(100% + 4px); right: 0; z-index: 40;
    min-width: 170px; padding: .35rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: 5px;
    box-shadow: var(--shadow, 0 10px 28px -12px rgba(0,0,0,.25));
}
.bg-menu-dropdown a, .bg-menu-dropdown button, .bg-menu-dropdown form > button { display: flex; align-items: center; gap: .5rem; width: 100%; margin: 0; box-sizing: border-box; }
.bg-menu-dropdown a, .bg-menu-dropdown button {
    padding: .55rem .6rem; border-radius: 5px; border: none; background: none;
    font-family: inherit; font-size: .86rem; font-weight: 600; text-align: left;
    color: var(--ink); text-decoration: none; cursor: pointer;
}
.bg-menu-dropdown a:hover, .bg-menu-dropdown button:hover { background: var(--paper); }
.bg-menu-danger { color: var(--danger) !important; }
.bg-menu-danger:hover { background: rgba(214,69,90,.1) !important; }

.bg-post-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .5rem; margin-bottom: 1.2rem; }
.bg-post-gallery[data-count="1"] { grid-template-columns: 1fr; align-items: center; }
.bg-post-gallery-item { display: block; border-radius: 10px; overflow: hidden; aspect-ratio: 4/3; background: var(--paper); }
.bg-post-gallery-item img { width: 100%; height: 100%; object-fit: contain; display: block; transition: transform .2s ease; }
/* A single cover photo shows at its own natural size instead of being forced
   into a fixed box — width/height stay auto, only capped by max-width/
   max-height, so the image scales down proportionally with no leftover
   blank space (unlike combining a fixed width with a capped height, which
   mismatches the box against the image and letterboxes it). */
.bg-post-gallery[data-count="1"] .bg-post-gallery-item {
    aspect-ratio: auto; background: none; display: flex; justify-content: center; align-items: center;
}
.bg-post-gallery[data-count="1"] .bg-post-gallery-item img {
    width: auto; height: auto; max-width: 100%; max-height: 70vh;
}
.bg-post-gallery-item:hover img { transform: scale(1.04); }

.bg-post-body { font-size: 1rem; line-height: 1.7; white-space: pre-wrap; margin-bottom: 1.25rem; }

/* ---------- BBCode elements (shared visual language with forum-v2.css) --- */
.bbcode-quote {
    border-left: 3px solid var(--indigo); background: var(--paper);
    padding: .6rem .9rem; margin: .75rem 0; border-radius: 0 6px 6px 0;
    font-style: italic; color: var(--ink-soft); white-space: normal;
}
.bbcode-quote cite {
    display: block; font-style: normal; font-weight: 700; font-size: .8rem;
    color: var(--indigo); margin-bottom: .3rem;
}
.bbcode-list { margin: .5rem 0; padding-left: 1.4rem; white-space: normal; }
.bbcode-list li { margin-bottom: .3rem; }
.bbcode-img { max-width: 100%; border-radius: 8px; margin: .5rem 0; display: block; }
.bbcode-table-wrap { overflow-x: auto; margin: .75rem 0; border: 1px solid var(--border); border-radius: 8px; }
.bbcode-table { width: 100%; border-collapse: collapse; font-size: .88rem; white-space: normal; }
.bbcode-table td { padding: .5rem .75rem; border: 1px solid var(--border); }
.bbcode-table tr:first-child td { background: var(--paper); font-weight: 700; }
.bbcode-code {
    margin: .75rem 0; padding: 1rem; border-radius: 8px; white-space: pre;
    background: #1e1e2e !important; overflow-x: auto; font-size: .85rem; line-height: 1.6;
}
.bbcode-code code {
    font-family: ui-monospace, 'Cascadia Code', 'Fira Code', monospace !important;
    background: none !important; white-space: pre !important;
}

.bg-post-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; padding-top: 1rem; border-top: 1px solid var(--border); }
.bg-post-actions .bookmark-toggle-btn { margin-left: auto; }
.bg-react-btn {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .45rem .9rem; border-radius: 5px; border: 1px solid var(--border);
    background: var(--paper); font-size: .85rem; font-weight: 700; cursor: pointer;
    transition: background .12s ease, border-color .12s ease;
}
.bg-react-btn:hover { background: var(--border); }
.bg-react-btn.is-active-like { background: rgba(42,157,111,.12); border-color: var(--success); color: var(--success); }
.bg-react-btn.is-active-dislike { background: rgba(214,69,90,.1); border-color: var(--danger); color: var(--danger); }

.bg-login-note { font-size: .8rem; color: var(--ink-soft); margin-top: .6rem; }
.bg-login-note a { font-weight: 600; color: var(--indigo); }

/* ---------- Forms (create / edit) --------------------------------------- */
.bg-form { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; padding: 1.1rem; }
.bg-form h3 { margin-bottom: .35rem; }
.bg-form label { font-size: .82rem; font-weight: 600; margin-top: .55rem; }
.bg-form input[type=text], .bg-form input[type=file], .bg-form textarea, .bg-form select {
    padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 5px;
    background: var(--paper); font-family: inherit; font-size: .9rem; resize: vertical;
}
.bg-form textarea { line-height: 1.6; }
.bg-form-hint { font-size: .76rem; color: var(--ink-soft); margin: .2rem 0 0; }

.bg-edit-photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: .6rem; }
.bg-edit-photo { position: relative; border-radius: 8px; overflow: hidden; aspect-ratio: 1/1; background: var(--paper); }
.bg-edit-photo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.bg-edit-photo form { position: absolute; top: .3rem; right: .3rem; margin: 0; }
.bg-edit-photo button {
    width: 24px; height: 24px; border-radius: 50%; border: none; cursor: pointer;
    background: rgba(0,0,0,.6); color: #fff; font-size: .75rem; line-height: 1;
}
.bg-edit-photo button:hover { background: var(--danger); }

/* ---------- Responsive -------------------------------------------------- */
@media (max-width: 640px) {
    .bg-post { padding: 1.1rem 1.2rem; }
    .bg-post-row-thumb { width: 64px; height: 64px; }
    .bg-categories-grid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: .4rem; }
}

/* ---------- Pagination (same modern style as feed.css) ------------------ */


@media (max-width: 480px) {
    .pagination a, .pagination span { min-width: 34px; height: 34px; font-size: .82rem; }
}

/* ---------- Shared BBCode help disclosure (public/_bbcode_help.php) ---- */
.bbcode-help { margin: .5rem 0 1rem; border: 1px solid var(--border); border-radius: 6px; padding: .5rem .75rem; }
.bbcode-help summary { cursor: pointer; font-size: .82rem; font-weight: 700; color: var(--ink-soft); list-style: none; }
.bbcode-help summary::-webkit-details-marker { display: none; }
.bbcode-help[open] summary { margin-bottom: .5rem; }
.bbcode-help-grid { display: grid; gap: .35rem; font-size: .78rem; color: var(--ink-soft); }
.bbcode-help-grid code { background: var(--paper); padding: .1rem .35rem; border-radius: 4px; font-size: .76rem; }

/* ---------- Shared BBCode toolbar (public/_bbcode_toolbar.php) --------- */
.bbcode-toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: .15rem;
    padding: .25rem; border: 1px solid var(--border); border-bottom: none;
    border-radius: 6px 6px 0 0; background: var(--paper);
}
.bbcode-toolbar button {
    width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
    border: none; background: none; border-radius: 4px; color: var(--ink-soft);
    cursor: pointer; font-size: .74rem; transition: background .12s ease, color .12s ease;
}
.bbcode-toolbar button:hover { background: var(--surface); color: var(--indigo); }
.bbcode-toolbar-sep { width: 1px; height: 15px; background: var(--border); margin: 0 .1rem; }
.bbcode-toolbar-code { display: flex; align-items: center; gap: .15rem; }
.bbcode-lang-select {
    font-size: .68rem; padding: .15rem .25rem; border-radius: 4px; height: 24px;
    border: 1px solid var(--border); background: var(--surface); color: var(--ink-soft);
}

/* The rich editing surface (public/assets/bbcode-toolbar.js) — a
   contenteditable div that replaces the textarea as what's actually typed
   into, so a pasted table/list/image shows as the real thing immediately
   instead of bracket text. Reuses the exact same .bbcode-* classes the
   published post display uses (quote/list/table/img/code below), since
   BBCode::render() output is literally what gets loaded into it on the
   edit page — what's shown here already matches what publishing produces. */
.bbcode-rich-editor {
    min-height: 220px; max-height: 480px; overflow-y: auto;
    padding: .75rem .9rem; border: 1px solid var(--border); border-radius: 0 0 6px 6px;
    background: var(--surface); font-size: .92rem; line-height: 1.6;
}
.bbcode-rich-editor:focus { outline: 2px solid var(--indigo); outline-offset: -1px; }
.bbcode-rich-editor img { max-width: 100%; border-radius: 8px; margin: .35rem 0; display: block; }
.bbcode-upload-placeholder { color: var(--ink-soft); font-style: italic; }
editor-youtube-embed {
    display: block; padding: .5rem .75rem; margin: .5rem 0; border-radius: 6px;
    background: var(--paper); border: 1px dashed var(--border); color: var(--ink-soft); font-size: .85rem;
    user-select: none;
}

.bbcode-youtube {
    position: relative; width: 100%; max-width: 560px; aspect-ratio: 16/9;
    margin: .75rem 0; border-radius: 8px; overflow: hidden; background: #000;
}
.bbcode-youtube iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; }

/* ---------- Post tags ------------------------------------------- */
.bg-post-tags { display: flex; flex-wrap: wrap; gap: .4rem; margin: -.5rem 0 1rem; }
.bg-tag-pill {
    display: inline-block; padding: .2rem .65rem; border-radius: 999px;
    background: var(--indigo-soft, var(--paper)); color: var(--indigo);
    font-size: .78rem; font-weight: 700; text-decoration: none; transition: background .12s ease;
}
.bg-tag-pill:hover { background: var(--indigo); color: #fff; }

/* ---------- Related posts ---------------------------------------- */
.bg-related-posts { margin-top: 1.25rem; }
.bg-related-posts h3 { font-size: .95rem; margin-bottom: .6rem; }
.bg-related-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem; }
.bg-related-item {
    display: flex; flex-direction: column; gap: .2rem; padding: .75rem .9rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    text-decoration: none; color: inherit; transition: box-shadow .12s ease, transform .12s ease;
}
.bg-related-item:hover { box-shadow: 0 4px 14px -8px rgba(0,0,0,.18); transform: translateY(-1px); }
.bg-related-title { font-weight: 700; font-size: .9rem; color: var(--ink); }

/* Touch theme: scroll the toolbar horizontally instead of wrapping to a
   second row — keeps it to one tidy strip you can swipe through, since a
   phone-width screen can't fit every icon side by side otherwise. */
body.touch-theme .bbcode-toolbar {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
body.touch-theme .bbcode-toolbar::-webkit-scrollbar { display: none; }
body.touch-theme .bbcode-toolbar button,
body.touch-theme .bbcode-toolbar-sep,
body.touch-theme .bbcode-toolbar-code { flex-shrink: 0; }

/* ---------- Tags chip input (public/assets/tags-input.js) -------------- */
.tags-input-container {
    display: flex; flex-wrap: wrap; align-items: center; gap: .35rem;
    padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); min-height: 42px; cursor: text;
}
.tags-input-container:focus-within { border-color: var(--indigo); box-shadow: 0 0 0 3px color-mix(in srgb, var(--indigo) 16%, transparent); }
.tag-chip {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .2rem .3rem .2rem .55rem; border-radius: 999px;
    background: var(--indigo-soft, var(--paper)); color: var(--indigo);
    font-size: .8rem; font-weight: 700; white-space: nowrap;
}
.tag-chip-remove {
    display: flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border: none; border-radius: 50%; background: none;
    color: inherit; cursor: pointer; font-size: .85rem; line-height: 1; padding: 0; opacity: .6;
}
.tag-chip-remove:hover { opacity: 1; background: rgba(0,0,0,.08); }
.tags-input-container input.tags-input-field {
    flex: 1; min-width: 140px; border: none !important; outline: none; background: none !important;
    font-size: .9rem; padding: .2rem 0 !important; font-family: inherit; color: var(--ink);
}
