.bdm { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
.bdm__list { display: flex; flex-direction: column; max-height: calc(100vh - var(--topbar-h) - 48px); position: sticky; top: calc(var(--topbar-h) + 16px); }
.bdm__search { padding: 12px 12px 8px; margin: 0; }
.bdm__filters { margin: 0 12px 10px; }
.bdm__items { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 6px 6px; border-top: 1px solid var(--border-subtle); }

.bdm-row { position: relative; display: flex; align-items: flex-start; gap: 10px; padding: 10px 8px; border-radius: var(--radius-sm); color: var(--text-secondary); text-decoration: none; }
.bdm-row + .bdm-row { margin-top: 2px; }
.bdm-row:hover { background: var(--surface-hover); text-decoration: none; color: var(--text-secondary); }
.bdm-row.is-active { background: var(--accent-subtle); box-shadow: inset 2px 0 0 var(--accent); }
.bdm-row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.bdm-row__top { display: flex; align-items: baseline; gap: 8px; }
.bdm-row__name { flex: 1; min-width: 0; font: 600 13px/1.3 var(--font-sans); color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bdm-row__time { flex: none; font: 400 12px/1.3 var(--font-sans); color: var(--text-disabled); }
.bdm-row__snippet { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bdm-row.is-unread .bdm-row__snippet { color: var(--text-primary); font-weight: 600; }
.bdm-row__meta { display: flex; gap: 10px; font: 400 12px/1.3 var(--font-sans); color: var(--text-disabled); }
.bdm-row__meta span { display: inline-flex; align-items: center; gap: 3px; }
.bdm-row__in { color: var(--info-fg); }
.bdm-row__failed { color: var(--danger-fg); }
.bdm-row__unread { position: absolute; top: 12px; right: 8px; min-width: 18px; padding: 2px 6px; border-radius: var(--radius-pill); background: var(--danger); color: #fff; font: 600 11px/1.3 var(--font-sans); text-align: center; }
.bdm-row.is-unread .bdm-row__time { display: none; }

.bdm__thread { display: flex; flex-direction: column; min-height: 420px; }
.bdm__head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border-subtle); }
.bdm__back { display: none; }
.bdm__name { font: 600 15px/1.3 var(--font-sans); color: var(--text-primary); }
.bdm__sub { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 4px; }
.bdm__messages { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 18px; max-height: calc(100vh - var(--topbar-h) - 200px); min-height: 320px; overflow-y: auto; overscroll-behavior: contain; background: var(--surface-1); }
.bdm__foot { display: flex; align-items: center; gap: 6px; padding: 10px 18px; border-top: 1px solid var(--border-subtle); }

.bdm-day { display: flex; align-items: center; gap: 10px; font: var(--text-label); color: var(--text-muted); }
.bdm-day::before, .bdm-day::after { content: ""; flex: 1; height: 1px; background: var(--border-subtle); }

.bdm-msg { display: flex; flex-direction: column; gap: 4px; max-width: min(620px, 88%); scroll-margin-top: 16px; }
.bdm-msg--out { align-self: flex-end; align-items: flex-end; }
.bdm-msg--in { align-self: flex-start; }
.bdm-msg__who { display: inline-flex; align-items: center; gap: 5px; font: 600 11px/1.2 var(--font-sans); color: var(--text-muted); }
.bdm-msg__bubble { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-radius: var(--radius-md); border: 1px solid var(--border-subtle); background: var(--surface-2); color: var(--text-primary); font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.bdm-msg--out .bdm-msg__bubble { background: color-mix(in srgb, var(--discord) 12%, transparent); border-color: color-mix(in srgb, var(--discord) 35%, transparent); border-top-right-radius: 3px; }
.bdm-msg--in .bdm-msg__bubble { border-top-left-radius: 3px; }
.bdm-msg.is-failed .bdm-msg__bubble { border-color: color-mix(in srgb, var(--danger) 50%, transparent); background: var(--danger-subtle); }
.bdm-msg.is-skipped .bdm-msg__bubble { opacity: .7; border-style: dashed; }
.bdm-msg__text { white-space: pre-line; }
.bdm-msg__meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 4px 10px; font: 400 12px/1.4 var(--font-sans); color: var(--text-disabled); }
.bdm-msg--in .bdm-msg__meta { justify-content: flex-start; }
.bdm-msg__result { flex-basis: 100%; text-align: right; font-family: var(--font-sans); color: var(--text-muted); }
.bdm-status { --c: var(--text-muted); display: inline-flex; align-items: center; gap: 4px; color: var(--c); font-family: var(--font-sans); font-weight: 600; }
.bdm-status--success { --c: var(--success-fg); }
.bdm-status--warning { --c: var(--warning-fg); }
.bdm-status--danger { --c: var(--danger-fg); }
.bdm-status--info { --c: var(--info-fg); }

.bdm-embed { --c: var(--navy-400); display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-left: 4px solid var(--c); border-radius: 4px; background: var(--surface-1); text-align: left; }
.bdm-embed__title { font: 600 14px/1.35 var(--font-sans); color: var(--text-primary); }
.bdm-embed__title a { color: var(--info-fg); }
.bdm-embed__body { font-size: 13px; color: var(--text-secondary); white-space: pre-line; }
.bdm-embed__foot { font-size: 11px; color: var(--text-disabled); }
.bdm-mention { padding: 0 3px; border-radius: 3px; background: color-mix(in srgb, var(--discord) 20%, transparent); color: #A5B0FF; }

.bdm-files { display: flex; flex-wrap: wrap; gap: 8px; }
.bdm-files__img { display: block; width: 180px; height: 130px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border-default); background: var(--surface-3); }
.bdm-files__img img { width: 100%; height: 100%; object-fit: cover; }

[data-theme="light"] .bdm-mention { color: #3C45C9; }

@media (max-width: 900px) {
  .bdm { grid-template-columns: minmax(0, 1fr); }
  .bdm__list { position: static; max-height: none; }
  .bdm.has-selected .bdm__list { display: none; }
  .bdm:not(.has-selected) .bdm__thread { display: none; }
  .bdm__back { display: inline-flex; }
  .bdm__messages { max-height: none; padding: 12px; }
  .bdm-msg { max-width: 94%; }
}

.bdm__new { padding: 0 12px 10px; margin: 0; }
.bdm__new .select { width: 100%; }
.bdm-msg__by { margin-left: 4px; font-weight: 500; color: var(--text-disabled); }
.bdm-edit, .bdm-history { align-self: stretch; font-size: 12px; }
.bdm-msg--out .bdm-edit, .bdm-msg--out .bdm-history { text-align: right; }
.bdm-edit summary, .bdm-history summary { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; list-style: none; color: var(--text-muted); font-weight: 600; }
.bdm-edit summary::-webkit-details-marker, .bdm-history summary::-webkit-details-marker { display: none; }
.bdm-edit summary:hover, .bdm-history summary:hover { color: var(--gold-200); }
.bdm-edit form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; min-width: min(460px, 70vw); text-align: left; }
.bdm-edit__foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.bdm-history ol { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 0; padding: 0; list-style: none; text-align: left; }
.bdm-history li { display: flex; flex-direction: column; gap: 3px; padding: 8px 10px; border: 1px dashed var(--border-default); border-radius: var(--radius-sm); background: var(--surface-2); }
.bdm-history__meta { font: 400 12px/1.3 var(--font-sans); color: var(--text-muted); }
.bdm-history__old { color: var(--text-secondary); white-space: pre-line; text-decoration: line-through; text-decoration-color: var(--text-disabled); }

.bdm-reply { display: flex; flex-direction: column; gap: 8px; padding: 12px 18px 14px; border-top: 1px solid var(--border-subtle); background: var(--surface-2); scroll-margin-top: calc(var(--topbar-h) + 16px); }
.bdm-reply .textarea { min-height: 76px; }
.bdm-reply__foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.bdm-reply__foot > .muted { flex: 1 1 260px; }
.bdm-reply__count { font: 400 12px/1 var(--font-sans); color: var(--text-muted); }
.bdm-reply__count.is-near { color: var(--warning-fg); }

.bdm-embed { position: relative; }
.bdm-embed__thumb { position: absolute; top: 10px; right: 10px; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 4px; background: var(--surface-3); color: var(--text-muted); }
.bdm-embed__thumb + .bdm-embed__title, .bdm-embed__thumb ~ .bdm-embed__body { padding-right: 52px; }
.bdm-embed__fields { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.bdm-embed__field { flex: 1 1 100%; min-width: 0; }
.bdm-embed__field.is-inline { flex: 1 1 140px; }
.bdm-embed__fname { font: 600 12px/1.4 var(--font-sans); color: var(--text-primary); }
.bdm-embed__fvalue { font-size: 12px; color: var(--text-secondary); white-space: pre-line; overflow-wrap: anywhere; }
.bdm-embed__image { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--info-fg); overflow-wrap: anywhere; }
.bdm-embed__empty { font-size: 12px; color: var(--text-disabled); font-style: italic; }

.bdm-actions { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: flex-end; gap: 6px 14px; align-self: stretch; font-size: 12px; }
.bdm-actions .bdm-edit { flex: 1 1 100%; order: 2; }
.bdm-actions__btn { display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: none; color: var(--text-muted); font: 600 12px/1.4 var(--font-sans); cursor: pointer; }
.bdm-actions__btn.btn--danger:hover { color: var(--danger-fg); }
.bdm-actions__off { display: inline-flex; align-items: center; gap: 4px; color: var(--text-disabled); cursor: help; }
.bdm-actions .bdm-edit summary { order: 0; }
.bdm-edit[open] { padding: 12px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--surface-2); }
.bdm-edit form .field__label { text-align: left; }
.bdm-msg.is-deleted .bdm-msg__bubble { opacity: .55; border-style: dashed; }
.bdm-msg.is-deleted .bdm-msg__text, .bdm-msg.is-deleted .bdm-embed__body, .bdm-msg.is-deleted .bdm-embed__title { text-decoration: line-through; text-decoration-color: var(--text-disabled); }

.ebuilder { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.ebuilder__toggle { font-weight: 600; }
.ebuilder__toggle .ic { margin-right: 4px; color: var(--gold-300); }
.ebuilder__body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 300px); gap: 16px; padding: 14px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--surface-1); }
.ebuilder__form { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.ebuilder__row { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.ebuilder__colors { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ebuilder__swatch { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 2px solid var(--surface-1); box-shadow: 0 0 0 1px var(--border-strong); cursor: pointer; }
.ebuilder__swatch.is-active { box-shadow: 0 0 0 2px var(--text-primary); }
.ebuilder__swatch:focus-visible { outline: 0; box-shadow: var(--focus-ring); }
.ebuilder__picker { width: 34px; height: 28px; padding: 0 2px; border: 1px solid var(--border-default); border-radius: var(--radius-sm); background: var(--surface-2); cursor: pointer; }
.ebuilder__fields { display: flex; flex-direction: column; gap: 8px; align-self: stretch; }
.ebuilder__field { display: flex; flex-direction: column; gap: 6px; padding: 10px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); }
.ebuilder__field .textarea { min-height: 52px; }
.ebuilder__field-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ebuilder__ts { align-self: end; padding-bottom: 8px; }
.ebuilder__preview { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ebuilder__preview .bdm-embed { position: sticky; top: calc(var(--topbar-h) + 16px); }

@media (max-width: 1100px) {
  .ebuilder__body { grid-template-columns: minmax(0, 1fr); }
  .ebuilder__preview .bdm-embed { position: static; }
}
.bdm-msg:has(.bdm-edit[open]) { max-width: 100%; align-self: stretch; }
.bdm-edit .ebuilder__body { grid-template-columns: minmax(0, 1fr); }
.bdm-edit .ebuilder__preview .bdm-embed { position: static; }
