/* -------------------------------------------------------------------------- */
/*                              App Layout (Modern)                          */
/* -------------------------------------------------------------------------- */

.bn-ms-app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-width: 0; /* contain children in viewport width */
  background: var(--bn-ms-color-surface);
  color: var(--bn-ms-color-text);
  font-family: var(--bn-ms-font-sans);
  overflow: hidden;
  position: relative;
}

.bn-ms-app::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(140deg, var(--bn-ms-color-primary-soft), transparent 55%);
  pointer-events: none;
  opacity: 0.5;
  z-index: 0;
}

/* --- Sidebar (Mobile: Full screen, Desktop: Left panel) --- */
.bn-ms-sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bn-ms-color-surface-alt);
  height: 100%;
  width: 100%;
  min-width: 0;
  position: relative;
  z-index: 1;
  box-shadow: inset -1px 0 0 var(--bn-ms-color-border);
}

.bn-ms-sidebar__panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.bn-ms-sidebar__header {
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--bn-ms-color-border);
  background: var(--bn-ms-color-surface);
  flex-shrink: 0;
  min-height: 52px;
  box-shadow: 0 1px 0 var(--bn-ms-color-border-strong);
}

.bn-ms-sidebar__title {
  font-size: 1.1rem;
  font-weight: var(--bn-ms-font-weight-bold);
  color: var(--bn-ms-color-text);
}

.bn-ms-sidebar__actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Scrollable content area in sidebar */
.bn-ms-sidebar__content {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
  /* keep space for sticky footer so last items aren't hidden */
  padding-bottom: calc(60px + var(--bn-ms-safe-bottom, 0px));
}

/* Footer in sidebar */
.bn-ms-sidebar__footer {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 8px 10px;
  border-top: 1px solid var(--bn-ms-color-border);
  background: var(--bn-ms-color-surface);
  /* never scroll out; if parent scrolls, keep visible */
  position: sticky;
  bottom: 0;
  z-index: 5;
}

.bn-ms-sidebar__footer-btn {
  flex: 1;
  appearance: none;
  border: 1px solid var(--bn-ms-color-border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--bn-ms-color-surface);
  color: var(--bn-ms-color-text);
  cursor: pointer;
  transition: transform var(--bn-ms-transition-base), box-shadow var(--bn-ms-transition-base), color var(--bn-ms-transition-base), border-color var(--bn-ms-transition-base);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.bn-ms-sidebar__footer-btn:hover {
  border-color: var(--bn-ms-color-primary);
  color: var(--bn-ms-color-primary);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.bn-ms-sidebar__footer-btn:active {
  transform: scale(0.98);
}

.bn-ms-sidebar__footer-btn:focus-visible {
  outline: none;
  border-color: var(--bn-ms-color-primary);
  box-shadow: 0 0 0 3px var(--bn-ms-color-primary-soft);
}

/* --- Main content (Thread view) --- */
.bn-ms-main {
  display: none;
  flex-direction: column;
  height: 100%;
  min-width: 0; /* prevent horizontal overflow in split view */
  background: var(--bn-ms-color-surface);
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  transform: translateX(100%);
  transition: transform var(--bn-ms-transition-base);
  overflow: hidden;
}

/* Header, body and footer inside main */
.bn-ms-main__header {
  flex-shrink: 0;
  flex-grow: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  min-height: 60px;
  max-height: 60px;
  border-bottom: 1px solid var(--bn-ms-color-border);
  background: var(--bn-ms-color-surface);
  box-shadow: 0 1px 0 var(--bn-ms-color-border-strong);
  z-index: 2;
  position: relative;
}

.bn-ms-main__body {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0; /* allow children to shrink properly */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bn-ms-color-bg);
  position: relative;
}

.bn-ms-main__body > * {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.bn-ms-main__footer {
  flex-shrink: 0;
  flex-grow: 0;
  background: var(--bn-ms-color-surface);
  border-top: 1px solid var(--bn-ms-color-border);
  padding: 0;
  position: relative;
  z-index: 3;
  min-height: 60px;
}

/* Panel containers inside main */
.bn-ms-main__panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

/* When conversation is open on mobile */
.bn-ms-app[data-sidebar-hidden="true"] .bn-ms-main {
  display: flex;
  transform: translateX(0);
}

/* --- Close/Back buttons --- */
.bn-ms-close {
  appearance: none;
  background: none;
  border: none;
  color: var(--bn-ms-color-text-muted);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  padding: var(--bn-ms-spacing-2xs);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--bn-ms-transition-base), color var(--bn-ms-transition-base), transform var(--bn-ms-transition-base);
  border-radius: 50%;
  width: 40px;
  height: 40px;
}

.bn-ms-close:hover {
  background: var(--bn-ms-color-primary-soft);
  color: var(--bn-ms-color-text);
}

.bn-ms-close:active {
  transform: scale(0.95);
}

.bn-ms-close:focus-visible {
  outline: none;
  background: var(--bn-ms-color-primary-soft);
  color: var(--bn-ms-color-text);
}

/* --- Desktop Layout (Side-by-side split view) --- */
@media (min-width: 768px) {
  .bn-ms-app {
    flex-direction: row;
  }

  .bn-ms-sidebar {
    width: 320px;
    flex: 0 0 320px;
    border-right: 1px solid var(--bn-ms-color-border);
    position: relative;
    transform: none;
  }

  .bn-ms-main {
    display: flex;
    position: relative;
    flex: 1;
    transform: none;
    z-index: 1;
  }

  /* Always show both panels on desktop */
  .bn-ms-app[data-sidebar-hidden="true"] .bn-ms-sidebar {
    display: flex;
  }

  .bn-ms-app[data-sidebar-hidden="true"] .bn-ms-main {
    display: flex;
  }
  
  /* Hide toggle button on desktop */
  .bn-ms-sidebar__actions [data-action="toggle-sidebar"] {
    display: none;
  }
}

@media (max-width: 767px) {
  .bn-ms-app[data-sidebar-hidden="true"] .bn-ms-sidebar {
    display: none;
  }

  .bn-ms-sidebar__footer {
    padding-bottom: calc(0.5rem + var(--bn-ms-safe-bottom, 0px));
  }
}

