/* BC Account manual RAG chat — split-screen + citation reader (no secrets) */

:root {
  --bc-chat-panel-w: min(40vw, 440px);
}

html.bc-chat-split-open,
html.bc-chat-split-open body {
  overflow-x: hidden;
}

@media (min-width: 769px) {
  html.bc-chat-split-open body {
    margin-right: var(--bc-chat-panel-w);
    transition: margin-right 0.25s ease;
  }
}

#bc-manual-chat-root {
  --bc-chat-bg: #ffffff;
  --bc-chat-fg: #111827;
  --bc-chat-muted: #6b7280;
  --bc-chat-border: #e5e7eb;
  --bc-chat-panel: #f8fafc;
  --bc-chat-user: #2563eb;
  --bc-chat-user-fg: #ffffff;
  --bc-chat-bot: #f1f5f9;
  --bc-chat-accent: #2563eb;
  --bc-chat-shadow: -8px 0 32px rgba(15, 23, 42, 0.12);
  font-family: "Anuphan", "IBM Plex Sans Thai", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--bc-chat-fg);
}

html[data-theme="dark"] #bc-manual-chat-root {
  --bc-chat-bg: #0f172a;
  --bc-chat-fg: #e5e7eb;
  --bc-chat-muted: #94a3b8;
  --bc-chat-border: #334155;
  --bc-chat-panel: #1e293b;
  --bc-chat-user: #3b82f6;
  --bc-chat-user-fg: #ffffff;
  --bc-chat-bot: #1e293b;
  --bc-chat-accent: #60a5fa;
  --bc-chat-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
}

#bc-manual-chat-root *,
#bc-manual-chat-root *::before,
#bc-manual-chat-root *::after {
  box-sizing: border-box;
}

/* —— Citation reader (left / main pane) —— */
.bc-chat-reader {
  position: fixed;
  z-index: 9995;
  top: 0;
  left: 0;
  right: var(--bc-chat-panel-w);
  bottom: 0;
  display: none;
  flex-direction: column;
  background: var(--bc-chat-bg, #fff);
  border-right: 1px solid var(--bc-chat-border, #e5e7eb);
}

html.bc-chat-reader-open .bc-chat-reader {
  display: flex;
}

html[data-theme="dark"] .bc-chat-reader {
  background: #0f172a;
  border-right-color: #334155;
}

.bc-chat-reader-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
  padding: 0.55rem 0.85rem;
  background: #f8fafc;
  border-bottom: 1px solid #e5e7eb;
  font-size: 0.9rem;
}

html[data-theme="dark"] .bc-chat-reader-bar {
  background: #1e293b;
  border-bottom-color: #334155;
  color: #e5e7eb;
}

.bc-chat-reader-bar strong {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.bc-chat-reader-back,
.bc-chat-reader-newtab {
  flex-shrink: 0;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #111827;
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

html[data-theme="dark"] .bc-chat-reader-back,
html[data-theme="dark"] .bc-chat-reader-newtab {
  background: #0f172a;
  border-color: #475569;
  color: #e5e7eb;
}

.bc-chat-reader-back:hover,
.bc-chat-reader-newtab:hover,
.bc-chat-reader-back:focus-visible,
.bc-chat-reader-newtab:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

.bc-chat-reader iframe {
  flex: 1;
  width: 100%;
  border: 0;
  background: #fff;
  min-height: 0;
}

/* —— Right chat panel —— */
.bc-chat-panel {
  position: fixed;
  z-index: 10000;
  top: 0;
  right: 0;
  width: var(--bc-chat-panel-w);
  max-width: 100vw;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bc-chat-bg);
  border-left: 1px solid var(--bc-chat-border);
  box-shadow: var(--bc-chat-shadow);
  transform: translateX(105%);
  transition: transform 0.25s ease;
  visibility: hidden;
  pointer-events: none;
}

.bc-chat-panel.is-open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}

/* Desktop-only drag target on the panel's left edge. */
.bc-chat-resizer {
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  left: -5px;
  width: 10px;
  cursor: col-resize;
  touch-action: none;
}

.bc-chat-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4px;
  width: 2px;
  background: var(--bc-chat-accent);
  opacity: 0.35;
  transition: opacity 0.15s ease;
}

.bc-chat-resizer:hover::after,
.bc-chat-resizer:focus-visible::after,
html.bc-chat-resizing .bc-chat-resizer::after {
  opacity: 0.9;
}

html.bc-chat-resizing,
html.bc-chat-resizing body {
  cursor: col-resize !important;
  user-select: none !important;
}

html.bc-chat-resizing body {
  transition: none !important;
}

.bc-chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  background: var(--bc-chat-panel);
  border-bottom: 1px solid var(--bc-chat-border);
  flex-shrink: 0;
}

.bc-chat-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.bc-chat-header p {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: var(--bc-chat-muted);
}

/* Dedicated close control on chat pane */
.bc-chat-close {
  border: 1px solid var(--bc-chat-border);
  background: transparent;
  color: var(--bc-chat-fg);
  border-radius: 8px;
  min-width: 2.5rem;
  height: 2.5rem;
  padding: 0 0.55rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

.bc-chat-close:hover,
.bc-chat-close:focus-visible {
  outline: 2px solid var(--bc-chat-accent);
  outline-offset: 1px;
}

.bc-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--bc-chat-bg);
  min-height: 0;
}

.bc-chat-msg {
  max-width: 95%;
  padding: 0.65rem 0.8rem;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.bc-chat-msg.user {
  align-self: flex-end;
  background: var(--bc-chat-user);
  color: var(--bc-chat-user-fg);
}

.bc-chat-msg.bot {
  align-self: flex-start;
  background: var(--bc-chat-bot);
  border: 1px solid var(--bc-chat-border);
  color: var(--bc-chat-fg);
}

.bc-chat-msg.error {
  align-self: stretch;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

html[data-theme="dark"] .bc-chat-msg.error {
  background: #450a0a;
  color: #fecaca;
  border-color: #7f1d1d;
}

.bc-chat-sources {
  margin: 0.55rem 0 0;
  padding: 0.45rem 0 0;
  border-top: 1px dashed var(--bc-chat-border);
  list-style: none;
  font-size: 0.8rem;
}

.bc-chat-sources-label {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--bc-chat-muted);
  font-weight: 600;
}

.bc-chat-sources li {
  margin: 0.25rem 0;
}

.bc-chat-sources a,
.bc-chat-source-link {
  color: var(--bc-chat-accent);
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  text-align: left;
}

.bc-chat-sources a:hover,
.bc-chat-source-link:hover {
  filter: brightness(1.1);
}

.bc-chat-status {
  padding: 0 1rem 0.4rem;
  font-size: 0.75rem;
  color: var(--bc-chat-muted);
  flex-shrink: 0;
  min-height: 1.1em;
}

.bc-chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.85rem 1rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--bc-chat-border);
  background: var(--bc-chat-panel);
  flex-shrink: 0;
}

.bc-chat-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--bc-chat-border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  background: var(--bc-chat-bg);
  color: var(--bc-chat-fg);
}

.bc-chat-input:focus {
  outline: 2px solid var(--bc-chat-accent);
  outline-offset: 1px;
}

.bc-chat-send {
  border: none;
  border-radius: 10px;
  padding: 0.65rem 0.95rem;
  background: var(--bc-chat-accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.bc-chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.bc-chat-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(15, 23, 42, 0.45);
  border: 0;
  padding: 0;
  cursor: pointer;
}

html.bc-chat-split-open .bc-chat-scrim {
  display: block;
}

@media (min-width: 769px) {
  html.bc-chat-split-open .bc-chat-scrim {
    display: none;
  }
}

@media (max-width: 768px) {
  :root {
    --bc-chat-panel-w: 100vw;
  }

  .bc-chat-panel {
    width: 100%;
  }

  .bc-chat-resizer {
    display: none;
  }

  /* On mobile, reader sits under chat when both open — stack: reader full then chat overlays.
     Prefer: when reading a source on mobile, chat can stay as bottom sheet height ~45% */
  .bc-chat-reader {
    right: 0;
    bottom: 48%;
  }

  html.bc-chat-reader-open .bc-chat-panel.is-open {
    top: auto;
    height: 48%;
    height: 48dvh;
    border-left: 0;
    border-top: 1px solid var(--bc-chat-border);
  }
}

/* —— Dedicated OPEN controls (nav / hero) —— */
.bc-chat-nav-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--brand, #2563eb);
  background: transparent;
  color: var(--brand, #2563eb);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.bc-chat-nav-btn:hover,
.bc-chat-nav-btn:focus-visible {
  filter: brightness(1.05);
  outline: 2px solid var(--brand, #2563eb);
  outline-offset: 2px;
}

html[data-theme="dark"] .bc-chat-nav-btn {
  border-color: #60a5fa;
  color: #60a5fa;
}

.bc-chat-hero-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  max-width: 100%;
  padding: 10px 24px;
  border: 1px solid #2563eb;
  border-radius: 999px;
  background: #2563eb;
  color: #fff !important;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.5;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(37, 99, 235, 0.28);
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.bc-chat-hero-btn:hover,
.bc-chat-hero-btn:focus-visible {
  filter: brightness(1.06);
  transform: translateY(-2px);
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

html[data-theme="dark"] .bc-chat-hero-btn {
  background: #3b82f6;
  border-color: #3b82f6;
}

/* Secondary floating open (hidden while chat open) */
.bc-chat-fab {
  position: fixed;
  z-index: 9997;
  right: 1rem;
  bottom: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1.05rem;
  background: #2563eb;
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
}

html.bc-chat-split-open .bc-chat-fab {
  display: none;
}

.bc-chat-fab:hover,
.bc-chat-fab:focus-visible {
  filter: brightness(1.08);
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}
