/* Chat-first shell — primary = conversation; everything else in Brain drawer */

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

body.btb-chat-first {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg, #0a0812);
  color: var(--text, #e8e4f0);
}

.btb-app {
  flex: 1;
  display: flex;
  min-height: 0;
  width: 100%;
}

/* —— Left sidebar —— */
.btb-sidebar {
  width: min(280px, 88vw);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border, #2a2238);
  background: #0c0810;
  min-height: 0;
}

.btb-new-chat {
  margin: 0.75rem 0.75rem 0.5rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #1a1424;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}
.btb-new-chat:hover {
  background: #221a32;
}

.btb-search {
  margin: 0 0.75rem 0.65rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: #120b18;
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
}

.btb-side-h {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0.35rem 0.75rem 0.35rem;
}

.btb-chat-list {
  flex: 1;
  min-height: 2rem;
  overflow-y: auto;
  padding: 0 0.45rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.btb-sess {
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}
.btb-sess:hover {
  background: rgba(255, 255, 255, 0.04);
}
.btb-sess.is-active {
  background: rgba(167, 139, 250, 0.12);
  border-color: rgba(167, 139, 250, 0.25);
}

.btb-projects {
  padding: 0 0.75rem 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.btb-projects-empty {
  margin: 0.25rem 0 0;
}

/* —— Main column —— */
.btb-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #0a0812;
}

.btb-topbar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: #0d0812;
  /* Keep live status readable: title may shrink; badge + Brain never squash */
}

.btb-chat-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.95rem;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btb-topbar > .btb-brain-pill {
  flex: 0 0 auto;
  max-width: 45%;
}

.btb-brain-pill {
  font-size: 0.72rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  white-space: nowrap;
  flex-shrink: 0;
}
.btb-brain-pill.pill.ok {
  color: #a7f3d0;
  border-color: rgba(34, 197, 94, 0.45);
  background: rgba(34, 197, 94, 0.12);
}
.btb-brain-pill.pill.bad {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.5);
  background: rgba(248, 113, 113, 0.1);
}

/* Subtle “always aware” indicator — not a button, low visual weight */
.btb-presence-indicator {
  flex: 0 0 auto;
  font-size: 0.66rem;
  color: var(--muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
  user-select: none;
  opacity: 0.88;
}
.btb-presence-dot {
  font-size: 0.55rem;
  vertical-align: 0.08em;
  opacity: 0.95;
}
.btb-presence-txt {
  font-weight: 500;
}

.btb-open-brain {
  flex: 0 0 auto;
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(167, 139, 250, 0.35);
  background: #2d1f4a;
  color: #f5f3ff;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}
.btb-open-brain:hover {
  filter: brightness(1.08);
}

.btb-failsafe {
  margin: 0 0.75rem;
}

.failsafe-banner {
  margin: 0.5rem 0.75rem 0;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: #3f1a1a;
  border: 1px solid #7f1d1d;
  font-size: 0.85rem;
  line-height: 1.4;
}

.btb-chat-col {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.btb-welcome {
  flex: 0 0 auto;
  text-align: center;
  padding: 2.5rem 1.25rem 1rem;
  max-width: 22rem;
  margin: 0 auto;
  width: 100%;
}
.btb-welcome[hidden] {
  display: none !important;
}
.btb-welcome-line1 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
  font-weight: 500;
  color: var(--text);
}
.btb-welcome-line2 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 400;
}

.btb-main .chat-log {
  flex: 1;
  min-height: 0;
  max-height: none;
  width: 100%;
  max-width: min(42rem, 92vw);
  margin: 0 auto;
  padding: 0.75rem 1rem 1rem;
  scroll-behavior: smooth;
}

.btb-input-area {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: #0d0a14;
  padding: 0.5rem 0.75rem 0.35rem;
}

.btb-input-inner {
  max-width: min(42rem, 92vw);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.btb-input-inner textarea#m {
  width: 100%;
  min-height: 48px;
  max-height: 200px;
  margin: 0;
}

.btb-input-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
}

.btb-mic-btn {
  padding: 0.45rem 0.6rem;
  font-size: 1rem;
  line-height: 1;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1e1630;
  color: var(--text);
  cursor: pointer;
}
.btb-mic-btn:hover {
  background: #281d3d;
}
.btb-mic-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#send {
  min-width: 4.5rem;
}

.btb-status-line.foot {
  max-width: min(42rem, 92vw);
  margin: 0.25rem auto 0.35rem;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
  font-size: 0.75rem;
  opacity: 0.9;
}

.btb-thinking-dots {
  display: inline-flex;
  gap: 3px;
  margin-left: 3px;
  vertical-align: text-bottom;
  opacity: 0.65;
  font-family: inherit;
}

.btb-thinking-dots span {
  display: inline-block;
  animation: btbDotFade 1.1s ease-in-out infinite;
}

.btb-thinking-dots span:nth-child(2) {
  animation-delay: 0.15s;
}
.btb-thinking-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes btbDotFade {
  0%,
  100% {
    opacity: 0.2;
  }
  50% {
    opacity: 1;
  }
}

/* —— Right Brain drawer —— */
.btb-brain-scrim {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  cursor: default;
}

.btb-brain-scrim[hidden] {
  display: none !important;
}

.btb-brain-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1001;
  width: min(100vw, 420px);
  height: 100%;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #0e0a16;
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  min-height: 0;
}

.btb-brain-drawer[hidden] {
  display: none !important;
}

.btb-brain-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: #120b1a;
  flex: none;
}
.btb-brain-hd h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.btb-brain-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
}
.btb-brain-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.btb-brain-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  background: #0a0810;
  flex: none;
}

.btb-ttab {
  padding: 0.35rem 0.5rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  font: inherit;
}
.btb-ttab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}
.btb-ttab.is-on {
  color: #ddd6fe;
  border-color: rgba(167, 139, 250, 0.35);
  background: rgba(124, 58, 237, 0.15);
}

.btb-brain-panels {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.btb-tab-panel {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem 0.65rem 1rem;
}
.btb-tab-panel[hidden] {
  display: none !important;
}

/* Panels inside drawer: restore readable spacing */
.btb-tab-panel .mission-strip,
.btb-tab-panel .continuity-strip {
  border-radius: 0;
  margin: -0.5rem -0.65rem 0.5rem;
  width: auto;
}
.btb-tab-panel .ollama-bar,
.btb-tab-panel .brain-deck,
.btb-tab-panel .lab-bar {
  margin: 0 -0.65rem 0.5rem;
  width: auto;
}
.btb-tab-panel header {
  margin: 0 -0.65rem 0.5rem;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.btb-tab-panel .media-bar,
.btb-tab-panel .voice-bar {
  margin: 0 -0.65rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.btb-sheader {
  padding: 0.5rem 0.75rem;
}

.btb-drawer-card.panel {
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}
.btb-drawer-card.panel h2 {
  font-size: 0.7rem;
}

.btb-sys-block {
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}
.btb-sys-block h3 {
  margin: 0 0 0.45rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.btb-sys-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 0.5rem;
}

/* Mobile: hide sidebar to bar — optional: stack */
@media (max-width: 720px) {
  .btb-app {
    flex-direction: column;
  }
  .btb-sidebar {
    width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

body.btb-brain-open {
  overflow: hidden;
}
