/* Right AI rail — squeezes main content (like left sidebar), Cursor-style chat */

:root {
  --wd-ai-rail-w: 380px;
}

body.mi-page .bdu-ai-dock,
body.bd-oi-page .bdu-ai-dock {
  display: none !important;
}

body.mi-page .bd-wrap,
body.bd-oi-page .bd-wrap,
body.bd-oi-page.bd-command-locked .bd-wrap {
  padding-bottom: 0 !important;
}

/* —— Main content squeeze when AI rail open —— */
@media (min-width: 901px) {
  body.wd-ai-panel-open.bd-oi-page .oi-main {
    margin-right: var(--wd-ai-rail-w);
    width: calc(100% - 212px - var(--wd-ai-rail-w));
    transition: margin-right 0.26s cubic-bezier(0.4, 0, 0.2, 1), width 0.26s cubic-bezier(0.4, 0, 0.2, 1);
  }
  body.wd-ai-panel-open.bd-oi-page.oi-sidebar-collapsed .oi-main {
    width: calc(100% - 56px - var(--wd-ai-rail-w));
  }
  body.mi-page .bd-wrap-inner {
    transition: margin-right 0.26s cubic-bezier(0.4, 0, 0.2, 1);
  }
  body.wd-ai-panel-open.mi-page .bd-wrap-inner {
    margin-right: var(--wd-ai-rail-w);
  }
}

/* —— Fixed right rail (not overlay) —— */
.wd-ai-side-panel {
  --wd-ai-rail-w: 380px;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--wd-ai-rail-w);
  z-index: 200;
  pointer-events: none;
  visibility: hidden;
}

body.wd-ai-panel-open .wd-ai-side-panel {
  visibility: visible;
  pointer-events: auto;
}

.wd-ai-side-panel-drawer {
  width: 100%;
  height: 100%;
  transform: translateX(100%);
  transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
}

body.wd-ai-panel-open .wd-ai-side-panel-drawer {
  transform: translateX(0);
}

.wd-ai-side-panel-backdrop {
  display: none !important;
}

.wd-ai-side-panel-drawer {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: #fff;
  border-left: 1px solid #e2e8f0;
  box-shadow: -4px 0 24px rgba(15, 23, 42, 0.06);
}

/* Right-edge tab — hidden when header AI control is present (cockpit / MI) */
body.bd-oi-page .wd-ai-side-tab,
body.mi-page .wd-ai-side-tab {
  display: none !important;
}

/* Collapsed tab on right edge (pages without header AI) */
.wd-ai-side-tab {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 210;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  padding: 8px 5px;
  border: none;
  border-radius: 6px 0 0 6px;
  background: linear-gradient(180deg, #7c3aed 0%, #5b21b6 100%);
  color: #fff;
  font-weight: 700;
  font-size: 0.62rem;
  font-family: inherit;
  letter-spacing: 0.04em;
  line-height: 1.1;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: -2px 0 10px rgba(91, 33, 182, 0.28);
  transition: opacity 0.2s ease, transform 0.2s ease, padding 0.15s ease, right 0.26s ease;
}
.wd-ai-side-tab:hover {
  filter: brightness(1.08);
  padding-right: 6px;
}
body.wd-ai-panel-open .wd-ai-side-tab {
  right: var(--wd-ai-rail-w, 380px);
  opacity: 0.92;
}

/* —— Header —— */
.wd-ai-side-panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  background: #fafaff;
}
.wd-ai-side-panel-head h2 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 800;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 8px;
}
.wd-ai-side-panel-head .bdu-ai-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.35);
}
.wd-ai-side-panel-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wd-ai-side-panel-head .bdu-chatgpt-clear {
  font-size: 0.72rem;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #64748b;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
}
.wd-ai-side-panel-close {
  width: 32px;
  height: 32px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  color: #64748b;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
}
.wd-ai-side-panel-close:hover {
  background: #f1f5f9;
  color: #0f172a;
}

/* —— Messages (only scroll region) —— */
.wd-ai-side-panel-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 14px 14px 8px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

/* Kill legacy dock message caps inside rail */
.wd-ai-side-panel .bdu-chatgpt-messages,
.wd-ai-side-panel-messages.bdu-chatgpt-messages {
  max-height: none !important;
  flex: 1 1 0 !important;
  min-height: 0 !important;
}

.wd-ai-side-panel-messages:empty::before {
  content: 'Ask about metrics, trends, forecasts, and what to fix first.';
  display: block;
  margin: auto;
  padding: 24px 12px;
  font-size: 0.82rem;
  color: #94a3b8;
  text-align: center;
  line-height: 1.45;
  max-width: 280px;
}

/* —— Footer: chips + input pinned to bottom —— */
.wd-ai-side-panel-foot {
  flex: 0 0 auto;
  margin-top: auto;
  padding: 10px 12px 12px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
}

.wd-ai-side-panel .wd-ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  max-height: 72px;
  overflow-y: auto;
}

.wd-ai-side-panel .wd-ai-chip {
  padding: 5px 10px;
  font-size: 0.68rem;
  border-radius: 999px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
}
.wd-ai-side-panel .wd-ai-chip:hover {
  border-color: #7c3aed;
  color: #5b21b6;
  background: #f5f3ff;
}

.wd-ai-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
}

.wd-ai-input-bar textarea {
  flex: 1;
  min-width: 0;
  border: none !important;
  background: transparent !important;
  resize: none;
  overflow: hidden;
  min-height: 22px;
  max-height: 100px;
  font-size: 0.88rem;
  line-height: 1.4;
  font-family: inherit;
  padding: 2px 0;
  color: #0f172a !important;
  box-shadow: none !important;
}
.wd-ai-input-bar textarea:focus {
  outline: none;
}

.wd-ai-input-bar .bdu-chatgpt-send {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, #7c3aed 0%, #5b21b6 100%);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.wd-ai-input-bar .bdu-chatgpt-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.wd-ai-disclaimer {
  margin: 8px 2px 0;
  font-size: 0.62rem;
  color: #94a3b8;
  text-align: center;
  line-height: 1.3;
}

/* Hide nested legacy composer wrappers if present */
.wd-ai-side-panel .bdu-chatgpt-composer,
.wd-ai-side-panel-composer {
  display: contents;
}

.bdu-chatgpt-msg {
  display: flex;
  width: 100%;
  flex-shrink: 0;
}
.bdu-chatgpt-msg--user {
  justify-content: flex-end;
}
.bdu-chatgpt-msg--assistant {
  justify-content: flex-start;
}
.bdu-chatgpt-bubble {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 0.84rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.bdu-chatgpt-msg--user .bdu-chatgpt-bubble {
  background: #eef2ff;
  color: #1e1b4b;
  border: 1px solid #c7d2fe;
}
.bdu-chatgpt-msg--assistant .bdu-chatgpt-bubble {
  background: #fff;
  color: #334155;
  border: 1px solid #e2e8f0;
}
.bdu-chatgpt-msg--loading .bdu-chatgpt-bubble {
  color: #94a3b8;
  font-style: italic;
}

.mi-ai-panel-btn {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid #c4b5fd;
  background: #f5f3ff;
  color: #5b21b6;
  font-size: 0.65rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  line-height: 1.2;
}
.mi-ai-panel-btn:hover {
  background: #ede9fe;
  border-color: #7c3aed;
}

@media (max-width: 900px) {
  body.wd-ai-panel-open.bd-oi-page .oi-main,
  body.wd-ai-panel-open.mi-page .bd-wrap-inner {
    margin-right: 0;
    width: auto;
  }
  .wd-ai-side-panel {
    width: min(100%, 420px);
  }
}
