/*
    See the JupyterLab Developer Guide for useful CSS Patterns:

    https://jupyterlab.readthedocs.io/en/stable/developer/css.html
*/

:root {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-smooth: never;

  --jp-ui-font-size0: 0.75em !important;
  --jp-ui-font-size1: 11.7px !important;
  --jp-ui-font-size2: 1.08em !important;
  --jp-ui-font-size3: 1.296em !important;
  --jp-code-font-size: 11.7px !important;
}

/* Dark mode override for jp-layout-color2 */
[data-jp-theme-light='false'] {
  --jp-layout-color2: #232323 !important;
  --jp-border-color3: #383838 !important;
}

/* Chat box widget styling */
.sage-ai-chatbox {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background-color: var(--jp-layout-color0);
  color: var(--jp-ui-font-color1);
  font-family: var(--jp-ui-font-family);
  border-radius: 12px;
  border: 0.5px solid var(--jp-border-color2);
  box-shadow: 0 0 20px 8px rgb(0 0 0 / 10%);
}

[data-jp-theme-light='false'] .sage-ai-chatbox {
  background-color: #1a1a1a;
}

[data-jp-theme-light='true'] .sage-ai-chatbox {
  background-color: #fff;
}

[data-jp-theme-light='false'] .sage-ai-chatbox {
  background-color: #1a1a1a;
}

[data-jp-theme-light='true'] .sage-ai-chatbox {
  background-color: #fff;
}

.sage-ai-chat-container {
  width: 100%;
  padding: 6px;
}

.sage-ai-toolbar {
  display: flex;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid var(--jp-border-color2);
  height: 53px;
}

.sage-ai-more-options-button {
  margin-left: 8px;
}

/* Autorun checkbox container styling */
.sage-ai-checkbox-container {
  display: flex;
  align-items: center;
  margin-right: 4px;
  padding: 0 2px;
  font-size: var(--jp-ui-font-size0);
}

.sage-ai-checkbox {
  margin-right: 5px;
  cursor: pointer;
  width: 16px;
  height: 16px;
}

.sage-ai-checkbox-label {
  color: var(--jp-ui-font-color1);
  cursor: pointer;
  user-select: none;
  font-size: 14px;
  line-height: 4px;
}

.sage-ai-checkbox-container:hover .sage-ai-checkbox-label {
  color: var(--jp-ui-font-color0);
}

/* Common styles for buttons and controls */
.sage-ai-control-base {
  border: 0.5px solid #e7e7e7;
  border-radius: 6px !important;
  background: transparent;
  transition: all 0.2s ease;
}

[data-jp-theme-light='false'] .sage-ai-control-base {
  border-color: #383838;
}

.sage-ai-control-base:hover:not(:disabled) {
  border-color: #666;
}

/* Auto Run Toggle Switch Styles */
.sage-ai-autorun-toggle {
  padding: 0 10px;
  margin-right: 8px;
  height: 30px;
  min-width: 89px;
}

.sage-ai-autorun-toggle .sage-ai-toggle-input {
  display: none; /* Hide the actual checkbox */
}

.sage-ai-toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  margin: 0;
  font-size: 13px;
  color: var(--jp-ui-font-color1);
  user-select: none;
}

.sage-ai-toggle-switch {
  position: relative;
  width: 28px;
  height: 16px;
  background: #494949;
  border-radius: 8px;
  transition: background-color 0.3s ease;
  flex-shrink: 0;
}

.sage-ai-toggle-switch::before {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s ease;
}

/* Active state styles */
.sage-ai-toggle-input:checked + .sage-ai-toggle-label .sage-ai-toggle-switch {
  background: #4caf50;
}

.sage-ai-toggle-input:checked
  + .sage-ai-toggle-label
  .sage-ai-toggle-switch::before {
  transform: translateX(12px);
}

/* Hover effects */
.sage-ai-autorun-toggle:hover .sage-ai-toggle-label {
  color: var(--jp-ui-font-color0);
}

.sage-ai-reset-button {
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  padding: 8px;
  gap: 6px;
  width: 32px;
  height: 32px;
  flex: none;
  flex-grow: 0;
  cursor: pointer;
}

.sage-ai-history-container {
  flex: 1;
  overflow: hidden;
  padding-bottom: 20px; /* Reverted to default, now handled dynamically */
  display: flex;
}

.sage-ai-history-container.floating-box-visible {
  padding-top: 0 !important;
}

.sage-ai-scroll-down-button {
  position: absolute;
  width: 100%;
  align-items: center;
  -webkit-animation: sage-ai-vert-move 1s infinite alternate;
  animation: sage-ai-vert-move 1s infinite alternate;
  padding: 0;
  margin: 0;
  outline: none;
  border: none;
  background: none;
  cursor: pointer;
}

.sage-ai-scroll-down-button.hidden {
  display: none;
}

@keyframes sage-ai-vert-move {
  0% {
    transform: translateY(0);
  }

  100% {
    transform: translateY(5px);
  }
}

@keyframes sage-ai-vert-move {
  0% {
    transform: translateY(0);
  }

  100% {
    transform: translateY(5px);
  }
}

.sage-ai-scroll-down-button svg {
  border-radius: 50%;
  padding: 2px;
  align-items: center;
  backdrop-filter: blur(10px);
}

.sage-ai-chat-history {
  flex: 1;
  height: 100%;
  overflow-y: auto;

  /* Ensure scrolling works properly with the increased bottom padding */
  scroll-behavior: smooth;
  padding: 0 12px;
}

.jp-Cell {
  margin-top: 28px !important;
}

.sage-ai-rich-chat-input {
  margin-bottom: 42px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sage-ai-rich-chat-input::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.sage-ai-in-context-cell .jp-Editor {
  border: 1px solid #16bd16 !important;
  border-radius: 2px;
  box-shadow: 0 0 3px rgb(22 189 22 / 20%);
}

/* New chatbox wrapper for structured input layout */
.sage-ai-chatbox-wrapper {
  flex: 1;
  border-radius: 8px;
  padding: 1px; /* This creates the border width */
  background: var(--jp-border-color1); /* Default border color */
  display: flex;
  flex-direction: column;
}

.sage-ai-chatbox-wrapper:focus-within {
  background: conic-gradient(
    from 24deg,
    #a7d8f0,
    #ff9270 14%,
    #fdf0b2 28%,
    #a5ddf4 42%,
    #8521ca 56%,
    #fbf4c8 70%,
    #b169e8 85%,
    #a7d8f0 100%
  );
}

.sage-ai-input-container {
  z-index: 2;
  display: flex;
  padding: 10px;

  /* background-color: var(--jp-layout-color1); */
  background: transparent;
  position: relative;
}

/* Context row (first row) */
.sage-ai-context-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 4px;
  background-color: var(--jp-layout-color0);
  border-radius: 7px 7px 0 0;
  min-height: 24px;
  flex-wrap: wrap;

  /* border-bottom: 1px solid var(--jp-border-color2); */
}

/* Hide context row when no contexts and hide border */
.sage-ai-context-row:has(.sage-ai-context-display-inline.hidden) {
  display: none;
}

.sage-ai-context-row:has(.sage-ai-context-display-inline.hidden)
  + .sage-ai-input-row {
  border-radius: 7px;
}

.sage-ai-context-row:has(.sage-ai-context-display-inline.hidden)
  + .sage-ai-input-row
  .sage-ai-rich-chat-input-wrapper {
  border-radius: 7px;
}

.sage-ai-context-row:has(.sage-ai-context-display-inline.hidden)
  + .sage-ai-input-row
  .sage-ai-rich-chat-input {
  border-radius: 7px;
}

/* Alternative fallback for browsers that don't support :has() */
.sage-ai-context-row.context-row-hidden {
  display: none;
}

.sage-ai-context-row.context-row-hidden + .sage-ai-input-row {
  border-radius: 7px;
}

.sage-ai-context-row.context-row-hidden
  + .sage-ai-input-row
  .sage-ai-rich-chat-input-wrapper {
  border-radius: 7px;
}

.sage-ai-context-row.context-row-hidden
  + .sage-ai-input-row
  .sage-ai-rich-chat-input {
  border-radius: 7px;
}

.sage-ai-context-text {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  line-height: 160%;
}

.sage-ai-at-icon {
  height: 13px;
  margin-right: 5px;
  transform: translateY(-3px);
}

/* Add Context button */
.sage-ai-add-context-button {
  border: 1px solid var(--jp-border-color2);
  border-radius: 6px !important;
  color: var(--jp-ui-font-color2);
  cursor: pointer;
  padding: 3px 8px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  background: var(--jp-layout-color0);
}

.sage-ai-add-context-button:hover {
  border-color: var(--jp-ui-font-color1);
  color: var(--jp-ui-font-color1);

  /* background-color: var(--jp-brand-color3); */
}

.sage-ai-add-context-button:hover .sage-ai-at-icon svg path {
  stroke: var(--jp-ui-font-color1);
}

/* Inline context display */
.sage-ai-context-display-inline {
  flex: 1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 24px;
}

.sage-ai-context-display-inline.hidden {
  display: none;
}

.sage-ai-context-items-inline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  width: 100%;
}

/* Inline context cell boxes */
.sage-ai-context-cell-box-inline {
  background: #e6f7ff;
  color: #1976d2;
  border: 1px solid #1976d2;
  border-radius: 4px;
  font-size: 11px;
  padding: 2px 6px;
  display: inline-flex;
  align-items: center;
  position: relative;
  gap: 4px;
  transition: all 0.2s;
  font-weight: 500;
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sage-ai-context-cell-box-inline:hover {
  box-shadow: 0 1px 4px rgb(25 118 210 / 20%);
}

/* Input row (second row) */
.sage-ai-input-row {
  display: flex;
  align-items: flex-end;
  position: relative;
  background-color: var(--jp-layout-color0);
  border-radius: 0 0 7px 7px;
}

/* Rich text input wrapper for gradient border - updated for new structure */
.sage-ai-rich-chat-input-wrapper {
  flex: 1;
  border: none; /* Remove border since chatbox-wrapper provides it */
  border-radius: 0 0 7px 7px;
  padding: 0; /* Remove padding since wrapper handles it */
  background: transparent; /* Transparent since chatbox-wrapper handles background */
}

.sage-ai-rich-chat-input-wrapper:focus-within {
  background: transparent; /* Let the parent handle the gradient */
}

/* Rich text input styling - updated for new structure */
.sage-ai-rich-chat-input {
  border: none; /* Remove border since wrapper provides it */
  border-radius: 0 0 7px 7px; /* Match the wrapper radius */
  padding: 12px;
  background-color: var(--jp-layout-color0);
  color: var(--jp-ui-font-color1);
  font-size: var(--jp-ui-font-size1);
  font-family: var(--jp-ui-font-family);
  resize: none;
  overflow-y: hidden;
  min-height: 42px;
  max-height: 240px;
  line-height: 1.5;
  transition: height 0.1s ease;
  white-space: pre-wrap;
  word-wrap: break-word;
  word-break: break-word;
}

[data-jp-theme-light='true'] .sage-ai-rich-chat-input {
  background-color: #fcfcfc;
}

.sage-ai-rich-chat-input:focus {
  outline: none;

  /* Remove the old focus styles since wrapper handles the border */
}

.sage-ai-new-prompt-cta {
  display: flex;
  flex-flow: row wrap;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--jp-ui-font-color2);
}

.sage-ai-new-prompt-cta p {
  text-wrap: nowrap !important;
  margin: 0 !important;
}

.sage-ai-new-prompt-cta a {
  color: var(--jp-ui-font-color0);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  text-wrap: nowrap !important;
}

/* Placeholder styling for rich text input */
.sage-ai-rich-chat-input.empty::before {
  content: attr(data-placeholder);
  color: var(--jp-ui-font-color2);
  pointer-events: none;
  position: absolute;
  transform: translateY(0);
}

/* Mention styling with different colors for different types */
.sage-ai-mention {
  font-weight: 600;
  border-radius: 3px;
  padding: 1px 3px;
  margin: 0 1px;
  white-space: nowrap;
}

.sage-ai-mention-template {
  background-color: rgb(156 39 176 / 10%);
  color: #9c27b0;
  border: 1px solid rgb(156 39 176 / 30%);
}

.sage-ai-mention-data {
  background-color: rgb(33 150 243 / 10%);
  color: #2196f3;
  border: 1px solid rgb(33 150 243 / 30%);
}

.sage-ai-mention-variable {
  background-color: rgb(76 175 80 / 10%);
  color: #4caf50;
  border: 1px solid rgb(76 175 80 / 30%);
}

.sage-ai-mention-cell {
  background-color: rgb(255 152 0 / 10%);
  color: #ff9800;
  border: 1px solid rgb(255 152 0 / 30%);
}

.sage-ai-mention-default {
  background-color: rgb(96 125 139 / 10%);
  color: #607d8b;
  border: 1px solid rgb(96 125 139 / 30%);
}

.sage-ai-mention-broken {
  background-color: rgb(244 67 54 / 10%);
  color: #f44336;
  border: 1px solid rgb(244 67 54 / 30%);
  text-decoration: line-through;
}

/* Dark theme adjustments for mentions */
[data-jp-theme-name='JupyterLab Dark'] .sage-ai-mention-template {
  background-color: rgb(156 39 176 / 20%);
  color: #ce93d8;
}

[data-jp-theme-name='JupyterLab Dark'] .sage-ai-mention-data {
  background-color: rgb(33 150 243 / 20%);
  color: #90caf9;
}

[data-jp-theme-name='JupyterLab Dark'] .sage-ai-mention-variable {
  background-color: rgb(76 175 80 / 20%);
  color: #a5d6a7;
}

[data-jp-theme-name='JupyterLab Dark'] .sage-ai-mention-cell {
  background-color: rgb(255 152 0 / 20%);
  color: #ffcc02;
}

[data-jp-theme-name='JupyterLab Dark'] .sage-ai-mention-default {
  background-color: rgb(96 125 139 / 20%);
  color: #b0bec5;
}

[data-jp-theme-name='JupyterLab Dark'] .sage-ai-mention-broken {
  background-color: rgb(244 67 54 / 20%);
  color: #ef5350;
}

.sage-ai-send-button,
.sage-ai-cancel-button {
  background: var(--jp-inverse-layout-color1);
  color: var(--jp-ui-font-color1);
  border: none;
  padding: 6px;
  cursor: pointer;
  font-size: var(--jp-ui-font-size0);
  transition: background-color 0.2s;
  width: 28px;
  height: 28px;
  border-radius: 50% !important;
}

.sage-ai-cancel-button {
  background: var(--jp-inverse-layout-color0) !important;
}

.sage-ai-cancel-button svg rect {
  fill: var(--jp-ui-inverse-font-color1) !important;
}

.sage-ai-send-button.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sage-ai-send-button.enabled {
  background-color: var(--jp-inverse-layout-color0);
  cursor: pointer;
}

.sage-ai-send-button svg {
  width: 16px;
  height: 16px;
}

.sage-ai-send-button.enabled svg path {
  stroke: var(--jp-ui-inverse-font-color0) !important;
}

.sage-ai-message {
  padding: 8px;
  border-radius: 14px;
  max-width: 100%;
  word-wrap: break-word;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-history-item-opaque {
  opacity: 0.3;
}

.sage-ai-user-message {
  position: relative;
  margin: 8px 0;
  padding: 10px;
  justify-self: end;
  width: 100%;
  border: 1px solid var(--jp-border-color2);
}

.sage-ai-user-message:has(.sage-ai-user-message-content.collapsible) {
  transition: background-color 0.3s ease;
  cursor: pointer;
}

.sage-ai-user-message:has(.sage-ai-user-message-content.collapsible):hover {
  background-color: var(--jp-layout-color2);
}

.sage-ai-user-message-content.collapsed {
  max-height: 65px;
  mask-image: -webkit-gradient(linear, left 70%, left bottom, from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
  -webkit-mask-image: -webkit-gradient(linear, left 70%, left bottom, from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
}

.sage-ai-user-message-content {
  max-height: fit-content;
}

.sage-ai-system-message {
  color: var(--jp-ui-font-color2);
  font-style: italic;
  justify-content: center;
  align-items: center;
  padding: 4px;
}

.sage-ai-error-message {
  color: var(--jp-error-color1);
  font-style: italic;
  justify-content: center;
  padding: 4px;
  background-color: var(--jp-error-color3);
  border-left: 3px solid var(--jp-error-color1);
}

/* Revert and Send button style */
.sage-ai-revert-send-button {
  background-color: var(--jp-warn-color1);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: var(--jp-ui-font-size0);
  transition: background-color 0.2s;
  opacity: 1;
}

.sage-ai-revert-send-button:hover {
  background-color: var(--jp-warn-color0);
}

.sage-ai-revert-send-button:disabled {
  background-color: var(--jp-warn-color3);
  cursor: not-allowed;
  opacity: 0.6;
}

.sage-ai-revert-send-button.hidden {
  display: none;
}

.sage-ai-loading {
  color: var(--jp-ui-font-color3);
  font-style: italic;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: row;
  gap: 10px;
}

.sage-ai-loading-dots {
  display: inline-block;
  position: relative;
  width: 40px;
  height: 12px;
}

.sage-ai-loading-dots span {
  position: absolute;
  top: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--jp-info-color0);
  animation-timing-function: cubic-bezier(0, 1, 1, 0);
}

.sage-ai-loading-dots span:nth-child(1) {
  left: 0;
  animation: sage-ai-loading-dots1 0.6s infinite;
}

.sage-ai-loading-dots span:nth-child(2) {
  left: 10px;
  animation: sage-ai-loading-dots2 0.6s infinite;
}

.sage-ai-loading-dots span:nth-child(3) {
  left: 20px;
  animation: sage-ai-loading-dots2 0.6s infinite;
}

.sage-ai-loading-dots span:nth-child(4) {
  left: 30px;
  animation: sage-ai-loading-dots3 0.6s infinite;
}

@keyframes sage-ai-loading-dots1 {
  0% {
    transform: scale(0);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes sage-ai-loading-dots2 {
  0% {
    transform: translate(0, 0);
  }

  100% {
    transform: translate(10px, 0);
  }
}

@keyframes sage-ai-loading-dots3 {
  0% {
    transform: scale(1);
  }

  100% {
    transform: scale(0);
  }
}

.sage-ai-blob-loader {
  position: relative;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0057c8, #207fd7, #42d9ff);
  background-size: 300% 300%;
  animation:
    ellipseAnimation 2s linear infinite,
    gradientShift 2s ease-in-out infinite;
}

/* Blob morphing and rotating animation */
@keyframes ellipseAnimation {
  0% {
    border-radius: 50%;
  }

  12.5% {
    border-radius: 25% 50% 50%;
    transform: rotate(45deg);
  }

  25% {
    border-radius: 25% 25% 50% 50%;
    transform: rotate(90deg);
  }

  37.5% {
    border-radius: 25% 25% 25% 50%;
    transform: rotate(135deg);
  }

  50% {
    border-radius: 25%;
    transform: rotate(180deg);
  }

  62.5% {
    border-radius: 50% 25% 25%;
    transform: rotate(225deg);
  }

  75% {
    border-radius: 50% 50% 25% 25%;
    transform: rotate(270deg);
  }

  87.5% {
    border-radius: 50% 50% 50% 25%;
    transform: rotate(315deg);
  }

  100% {
    border-radius: 50%;
    transform: rotate(360deg);
  }
}

/* Smooth shifting gradient animation */
@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

.sage-ai-tool-calls {
  margin: 8px 0;
  padding: 8px;
  border-left: 3px solid var(--jp-brand-color1);
  background-color: var(--jp-layout-color2);
  border-radius: 4px;
}

.sage-ai-tool-calls-header {
  margin-bottom: 8px;
  font-weight: bold;
  color: var(--jp-ui-font-color1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sage-ai-tool-calls-header::after {
  content: '▼';
  font-size: 12px;
  transition: transform 0.2s ease;
}

.sage-ai-tool-calls-header.collapsed::after {
  transform: rotate(-90deg);
}

.sage-ai-tool-calls-content {
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.sage-ai-tool-calls-content.collapsed {
  max-height: 0;
}

.sage-ai-tool-call {
  margin-bottom: 8px;
  padding: 4px 0;
}

.sage-ai-tool-call-badge {
  display: inline-block;

  /* color: white; */
  margin-right: 8px;
  font-size: 12px;
}

.sage-ai-tool-call-content {
  background-color: var(--jp-layout-color1);
  border-radius: 4px;
  padding: 8px;
  margin-top: 4px;
  font-family: monospace;
  font-size: 12px;
  overflow-x: auto;
}

.sage-ai-tool-result {
  margin: 8px 0;
  padding: 8px;
  border-left: 3px solid var(--jp-success-color0);
  background-color: var(--jp-layout-color2);
  border-radius: 4px;
}

.sage-ai-tool-result-header {
  margin-bottom: 8px;
  font-weight: bold;
  color: var(--jp-ui-font-color1);
}

.sage-ai-tool-result-content {
  background-color: var(--jp-layout-color1);
  border-radius: 4px;
  padding: 8px;
  margin-top: 4px;
  font-family: monospace;
  font-size: 12px;
  overflow-x: auto;
}

.sage-ai-streaming-cursor {
  display: inline-block;
  height: 12px;
  width: 12px;
  border-radius: 50%;
  margin-left: 4px;
  vertical-align: middle;
  margin-bottom: 4px;
  background-color: var(--jp-ui-font-color1);
  animation: blink 1s infinite;
}

@keyframes blink {
  0%,
  50% {
    opacity: 1;
  }

  51%,
  100% {
    opacity: 0;
  }
}

.sage-ai-streaming-tool-call {
  opacity: 0.9;
  transition: opacity 0.3s ease;
}

.sage-ai-streaming-tool-call-container {
  background-color: var(--jp-layout-color2);
  border-radius: 4px;
  padding: 8px;
  margin: 4px 0;
  border-left: 3px solid var(--jp-brand-color1);
}

.sage-ai-streaming-tool-call-placeholder {
  color: var(--jp-ui-font-color2);
  font-style: italic;
  padding: 8px;
  text-align: center;
  background-color: var(--jp-layout-color1);
  border-radius: 4px;
  border: 1px dashed var(--jp-border-color1);
}

.sage-ai-streaming-tool-call-container .sage-ai-tool-call-v1 {
  margin-bottom: 8px;
  animation: fadeInUp 0.3s ease;
}

.sage-ai-streaming-tool-call-container .sage-ai-tool-call-v1:last-child {
  margin-bottom: 0;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.sage-ai-streaming-content {
  font-family: var(--jp-ui-font-family);
  line-height: 1.5;
}

/* Improve code block rendering during streaming */
.sage-ai-streaming-content code {
  font-family: var(--jp-code-font-family);
  background-color: var(--jp-layout-color2);
  padding: 2px 4px;
  border-radius: 3px;
}

/* Ensure the streaming content expands properly */
.sage-ai-message-content {
  width: 100%;
  margin-left: 0;
}

.sage-ai-tool-group {
  margin: 8px 0;
  padding: 8px;

  /* border-left: 3px solid var(--jp-brand-color1); */
  background-color: var(--jp-layout-color2);
  border-radius: 4px;
}

.sage-ai-tool-group-header {
  margin-bottom: 8px;
  font-weight: bold;
  color: var(--jp-ui-font-color1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sage-ai-tool-group-header::after {
  content: '▼';
  font-size: 12px;
  transition: transform 0.2s ease;
}

.sage-ai-tool-group-header.collapsed::after {
  transform: rotate(-90deg);
}

.sage-ai-tool-group-content {
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.sage-ai-tool-group-content.collapsed {
  max-height: 0;
}

.sage-ai-tool-item {
  margin-bottom: 12px;
  border-bottom: 1px solid var(--jp-border-color1);
  padding-bottom: 12px;
}

.sage-ai-tool-item:last-child {
  margin-bottom: 0;
  border-bottom: none;
  padding-bottom: 0;
}

.sage-ai-tool-item-header {
  display: flex;
  align-items: center;
  margin-bottom: 4px;
  padding: 0;
  font-weight: bold;
  flex-flow: row wrap;
  place-content: center space-between;
  width: 100%;
}

.sage-ai-tool-timestamp {
  margin-left: 10px;
  font-size: 11px;
  color: var(--jp-ui-font-color2);
  font-style: italic;
  font-weight: normal;
}

.sage-ai-tool-call .sage-ai-tool-call-content,
.sage-ai-tool-result .sage-ai-tool-result-content {
  background-color: var(--jp-layout-color1);
  border-radius: 4px;
  padding: 8px;
  margin-top: 4px;
  font-family: monospace;
  font-size: 12px;
  overflow-x: auto;
}

/* Add this to your existing CSS */

.sage-ai-dropdown-indicator {
  margin-left: auto;
  font-size: 12px;
  transition: transform 0.2s ease;
}

.sage-ai-tool-item-header {
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  border-radius: 4px;
}

.sage-ai-tool-item-header:hover {
  background-color: var(--jp-layout-color2);
}

.sage-ai-tool-item-header.collapsed .sage-ai-dropdown-indicator {
  transform: rotate(-90deg);
}

.sage-ai-tool-call-content,
.sage-ai-tool-result-content {
  max-height: 500px;
  overflow: auto;
  transition:
    max-height 0.3s ease,
    opacity 0.3s ease;
  opacity: 1;
}

.sage-ai-tool-call-content.collapsed,
.sage-ai-tool-result-content.collapsed {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  margin: 0;
  padding: 0;
}

/* Tool group styling */
.sage-ai-tool-group-title {
  font-weight: bold;
  color: var(--jp-ui-font-color0);
  margin-bottom: 8px;
  padding: 4px 8px;
  background-color: var(--jp-layout-color2);
  border-radius: 4px 4px 0 0;
  border-bottom: 1px solid var(--jp-border-color1);
}

/* Make sure there's no lingering collapse functionality */
.sage-ai-tool-group-content {
  display: block;
  overflow: visible;
  max-height: none;
}

.sage-ai-undo-button {
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  padding: 8px;
  gap: 6px;
  width: 32px;
  height: 32px;
  flex: none;
  flex-grow: 0;
  cursor: pointer;
  margin-right: 8px;
}

.sage-ai-undo-button:disabled {
  opacity: 0.4;
  background-color: rgb(0 0 0 / 10%);
  cursor: not-allowed;
}

.sage-ai-icon-close {
  font-size: 16px;
}

.sage-ai-icon-button-sm,
.sage-ai-icon-button-md {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  color: #949494;
  line-height: 0;
  border: none;
  cursor: pointer;
  padding: 0;
  border-radius: 50% !important;
  width: 24px;
  height: 24px;
  transition: background-color 0.2s ease;
}

.sage-ai-icon-button-sm {
  width: 20px;
  height: 20px;
}

.sage-ai-icon-button-md {
  width: 36px;
  height: 36px;
}

.sage-ai-icon-button-sm:hover,
.sage-ai-icon-button-md:hover {
  background-color: var(--jp-layout-color2);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: var(--jp-ui-font-size0);
  transition: background-color 0.2s;
}

.sage-ai-undo-button:disabled {
  background-color: var(--jp-layout-color3);
  cursor: not-allowed;
  opacity: 0.6;
}

.sage-ai-undo-button:hover:not(:disabled) {
  background-color: var(--jp-brand-color1);
}

/* Thread selector styling */
.sage-ai-thread-selector {
  background-color: transparent;
  border: none;
  color: var(--jp-ui-font-color1);
  cursor: pointer;
  padding: 4px;
  font-size: 14px;
  display: flex;
  align-items: center;
  border-radius: 4px;
  margin-right: 8px;
}

.sage-ai-thread-selector:hover {
  background-color: var(--jp-layout-color3);
}

.sage-ai-thread-selector svg {
  width: 24px;
  height: 24px;
}

.sage-ai-thread-selector-button {
  margin-right: 4px;
}

.sage-ai-thread-name {
  flex: 1;
  align-content: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: var(--jp-ui-font-size1);
}

.d2h-file-header {
  display: none !important;
}

.d2h-file-wrapper {
  margin-bottom: 0 !important;
}

.d2h-info {
  display: none !important;
}

.jp-Notebook-footer {
  display: none !important;
}

/* Markdown Content Styling */
.sage-ai-markdown-content {
  line-height: 1.6;
  margin-left: 0 !important;
  margin-top: 4px;
}

.sage-ai-markdown-content h1,
.sage-ai-markdown-content h2,
.sage-ai-markdown-content h3,
.sage-ai-markdown-content h4,
.sage-ai-markdown-content h5,
.sage-ai-markdown-content h6 {
  margin-top: 1em;
  margin-bottom: 0.5em;
  font-weight: 600;
  color: var(--jp-ui-font-color0);
}

.sage-ai-markdown-content h1 {
  font-size: 1.8em;
}

.sage-ai-markdown-content h2 {
  font-size: 1.6em;
}

.sage-ai-markdown-content h3 {
  font-size: 1.4em;
}

.sage-ai-markdown-content h4 {
  font-size: 1.2em;
}

.sage-ai-markdown-content h5 {
  font-size: 1.1em;
}

.sage-ai-markdown-content h6 {
  font-size: 1em;
}

.sage-ai-markdown-content p {
  margin: 0;
}

.sage-ai-markdown-content ul,
.sage-ai-markdown-content ol {
  padding-left: 2em;
  margin: 4px;
}

.sage-ai-markdown-content ul {
  list-style-type: disc;
}

.sage-ai-markdown-content ol {
  list-style-type: decimal;
}

.sage-ai-markdown-content li {
  margin: 0.3em 0;
}

.sage-ai-markdown-content a {
  color: var(--jp-brand-color1);
  text-decoration: none;
}

.sage-ai-markdown-content a:hover {
  text-decoration: underline;
}

.sage-ai-markdown-content blockquote {
  border-left: 4px solid var(--jp-border-color2);
  padding-left: 1em;
  margin: 1em 0;
  color: var(--jp-ui-font-color2);
}

.sage-ai-markdown-content code {
  font-family: var(--jp-code-font-family);
  background-color: var(--jp-layout-color2);
  padding: 2px 4px;
  border-radius: 3px;
}

.sage-ai-markdown-content pre {
  background-color: var(--jp-layout-color2);
  border-radius: 8px;
  padding: 1em;
  overflow-x: auto;
  margin: 1em 0;
  position: relative;
}

.sage-ai-markdown-content pre code {
  background-color: transparent;
  padding: 0;
  font-size: 0.9em;
  white-space: pre;
}

.sage-ai-markdown-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
}

.sage-ai-markdown-content th,
.sage-ai-markdown-content td {
  border: 1px solid var(--jp-border-color2);
  padding: 8px;
  text-align: left;
}

.sage-ai-markdown-content th {
  background-color: var(--jp-layout-color2);
  font-weight: bold;
}

.sage-ai-markdown-content img {
  max-width: 100%;
  height: auto;
}

/* Code Block Container */
.sage-ai-code-block-container {
  position: relative;
  margin: 1em 0;
}

/* Copy Code Button */
.sage-ai-copy-code-button {
  position: absolute;
  top: 5px;
  right: 5px;
  background-color: transparent;
  color: var(--jp-ui-font-color1);
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.sage-ai-copy-code-button:hover {
  opacity: 1;
}

/* Message structure */
.sage-ai-message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.sage-ai-message-header-image {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(
    135deg,
    rgb(254 193 99 / 12%) 0%,
    rgb(222 67 19 / 12%) 100%
  );
  height: 27px;
  width: 27px;
  flex-shrink: 0;
  border-radius: 50%;
}

.sage-ai-message-header-title {
  color: var(--jp-ui-font-color2);
  font-size: var(--jp-ui-font-size1);
  font-weight: 500;
}

/* Context cells indicator */
.context-cells-indicator {
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  margin: 8px;
  margin-bottom: 0;
  border-radius: 4px;
  color: #666;
  width: calc(100% - 32px);
  display: none !important;
}

/* Hide indicator when no cells are in context */
.context-cells-indicator.hidden {
  display: none;
}

/* Context cell box (like .sage-ai-cell-id-label) */
.sage-ai-context-cell-box {
  background: #e6f7ff;
  color: #1976d2;
  border: 2px solid #1976d2;
  border-radius: 4px;
  font-size: 12px;
  padding: 4px;
  z-index: 101;
  display: inline-flex;
  align-items: center;
  position: relative;
  gap: 4px;
  transition:
    box-shadow 0.2s,
    border 0.2s;
  margin-bottom: 2px;
  box-shadow: 0 2px 8px rgb(25 118 210 / 12%);
  font-weight: 500;
  flex-direction: row;
}

.sage-ai-context-cell-box:hover {
  box-shadow: 0 4px 16px rgb(25 118 210 / 18%);
  border-color: #1251a3;
}

.sage-ai-context-cell-delete {
  color: #e53935;
  font-size: 14px;
  cursor: pointer;
  line-height: 0;
}

.sage-ai-tool-call-v1 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  margin-bottom: 4px;
  padding: 0 8px;
  font-family: var(--jp-ui-font-family);
  font-size: var(--jp-ui-font-size1);
  color: var(--jp-ui-font-color2);
}

.sage-ai-tool-call-v1.clickable {
  cursor: pointer;
}

.sage-ai-tool-call-v1.error-state svg {
  fill: var(--error-fill-active) !important;
}

.sage-ai-tool-call-v1.error-state span {
  color: var(--error-fill-active) !important;
}

.sage-ai-loading-text {
  background: linear-gradient(
    135deg,
    transparent,
    var(--jp-ui-font-color1),
    transparent
  );
  background-clip: text;
  color: transparent !important;
  background-size: 200% 100%;
  animation: shimmer 2.5s linear infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

.sage-ai-tool-call-cell {
  border-radius: 5px;
  background: rgb(59 130 246 / 13%);
  color: #60a5fa;
  padding: 1px 6px;
  font-family: var(--jp-code-font-family), serif;
  font-size: 12px;
  font-style: normal;
  font-weight: 500;
  line-height: 160%; /* 19.2px */
  border: none;
}

.sage-ai-tool-call-cell:hover {
  background: rgb(59 130 246 / 20%);
  color: #2563eb;
  cursor: pointer;
}

.sage-ai-tool-call-code {
  background: var(--d2h-dark-selected-color);
  color: var(--jp-ui-font-color1);
  border-radius: 4px;
  font-size: var(--jp-ui-font-size0);
  padding: 2px 4px;
}

/* Mode selector styles are now in mode-selector-dropdown.css */

/* Floating current/next step box */
.sage-ai-step-floating-box {
  position: fixed;
  justify-self: anchor-center;
  backdrop-filter: blur(10px);
  border: 0 solid var(--jp-border-color2);
  border-bottom-width: 1px;
  width: calc(100% - 25px);
  padding: 8px 12px;
  box-shadow: 0 2px 8px rgb(0 0 0 / 10%);
  z-index: 100;
  display: none;
  font-size: var(--jp-ui-font-size0);
  line-height: 1.4;
}

.sage-ai-step-floating-box.visible {
  display: flex;
  gap: 8px;
  max-height: 80px;
}

.sage-ai-chat-history.floating-box-visible > :first-child {
  margin-top: 84px !important;
}

.sage-ai-step-floating-box .content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sage-ai-step-floating-box .current-task-text {
  color: var(--jp-ui-font-color0);
  font-size: 11px;
  margin: 0;
  margin-top: 3px;
}

.sage-ai-step-floating-box .next-task-text {
  color: var(--jp-ui-font-color2);
  font-size: var(--jp-ui-font-size0);
  margin: 0;
}

.sage-ai-step-floating-box .close-button {
  background: none;
  border: none;
  color: var(--jp-ui-font-color2);
  cursor: pointer;
  padding: 2px;
  font-size: 14px;
  line-height: 1;
  border-radius: 2px;
  transition: background-color 0.2s;
}

.sage-ai-step-floating-box .close-button:hover {
  background-color: var(--jp-layout-color3);
  color: var(--jp-ui-font-color1);
}

.sage-ai-step-floating-box .loader {
  width: 20px;
  height: 20px;
  display: inline-block;
  position: relative;
}

.sage-ai-step-floating-box .loader::after,
.sage-ai-step-floating-box .loader::before {
  content: '';
  box-sizing: border-box;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--jp-ui-font-color1);
  position: absolute;
  left: 0;
  top: 0;
  animation: sage-ai-step-floating-box-animloader 2s linear infinite;
}

.sage-ai-step-floating-box .loader::after {
  animation-delay: 1s;
}

@keyframes sage-ai-step-floating-box-animloader {
  0% {
    transform: scale(0);
    opacity: 1;
  }

  100% {
    transform: scale(1);
    opacity: 0;
  }
}

.sage-ai-step-floating-box .source-toggle {
  align-self: center;
  background: none;
  border: none;
  color: var(--jp-ui-font-color2);
  cursor: pointer;
  font-size: var(--jp-ui-font-size0);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 4px;
  transition:
    background-color 0.2s,
    color 0.2s;
  width: 24px;
  height: 24px;
}

.sage-ai-step-floating-box .source-toggle:hover {
  background-color: var(--jp-layout-color2);
  color: var(--jp-ui-font-color1);
}

.sage-ai-step-floating-box .toggle-icon {
  font-size: 12px;
  transition: transform 0.2s ease;
  line-height: 1;
}

.sage-ai-step-floating-box .source-content {
  padding: 8px;
  background-color: var(--jp-layout-color2);
  border-radius: 4px;
  border: 1px solid var(--jp-border-color2);
  overflow-y: auto;
  resize: vertical;
  min-height: 100px;
  max-height: 60vh;
}

.sage-ai-step-floating-box .source-markdown {
  font-family: var(--jp-code-font-family);
  font-size: 11px;
  line-height: 1.4;
  color: var(--jp-ui-font-color1);
}

.sage-ai-step-floating-box .source-markdown h1,
.sage-ai-step-floating-box .source-markdown h2,
.sage-ai-step-floating-box .source-markdown h3,
.sage-ai-step-floating-box .source-markdown h4,
.sage-ai-step-floating-box .source-markdown h5,
.sage-ai-step-floating-box .source-markdown h6 {
  margin: 8px 0 4px;
  font-weight: 600;
  color: var(--jp-ui-font-color0);
}

.sage-ai-step-floating-box .source-markdown h1 {
  font-size: 14px;
}

.sage-ai-step-floating-box .source-markdown h2 {
  font-size: 13px;
}

.sage-ai-step-floating-box .source-markdown h3 {
  font-size: 12px;
}

.sage-ai-step-floating-box .source-markdown h4,
.sage-ai-step-floating-box .source-markdown h5,
.sage-ai-step-floating-box .source-markdown h6 {
  font-size: 11px;
}

.sage-ai-step-floating-box .source-markdown p {
  margin: 4px 0;
}

.sage-ai-step-floating-box .source-markdown ul,
.sage-ai-step-floating-box .source-markdown ol {
  padding-left: 16px;
  margin: 4px 0;
}

.sage-ai-step-floating-box .source-markdown li {
  margin: 2px 0;
}

.sage-ai-step-floating-box .source-markdown code {
  background-color: var(--jp-layout-color1);
  padding: 1px 3px;
  border-radius: 2px;
  font-size: 10px;
}

.sage-ai-step-floating-box .source-markdown pre {
  background-color: var(--jp-layout-color1);
  border-radius: 4px;
  padding: 6px;
  margin: 4px 0;
  overflow-x: auto;
}

.sage-ai-step-floating-box .source-markdown pre code {
  background-color: transparent;
  padding: 0;
  font-size: 10px;
}

.sage-ai-step-floating-box .source-markdown blockquote {
  border-left: 3px solid var(--jp-border-color2);
  padding-left: 8px;
  margin: 4px 0;
  color: var(--jp-ui-font-color2);
  font-style: italic;
}

/* Adjust floating box height when source is expanded */
.sage-ai-step-floating-box.visible {
  display: flex;
  gap: 8px;
  max-height: none;
  flex-wrap: wrap;
}

.sage-ai-step-floating-box.visible .content {
  flex: 1;
  min-width: 200px;
}

.sage-ai-step-floating-box.visible .source-section {
  flex-basis: 100%;
}

/* Diff2Html overrides */
.d2h-code-line {
  padding: 0 5em !important;
}

.d2h-code-linenumber {
  width: 4.5em !important;
  backdrop-filter: blur(8px);
}

.line-num1,
.line-num2 {
  width: 50% !important;
  text-align: center !important;
  padding: 0 !important;
}

.hljs-regexp,
.hljs-string,
.hljs-meta .hljs-string {
  color: var(--jp-brand-color0) !important;
}

.hljs {
  color: var(--jp-ui-font-color2) !important;
}

.sage-ai-waiting-reply-container {
  display: none;
  bottom: 0;
  margin: 8px 0 0;
  font-size: 12px;
  padding: 12px;
  /*color: rgb(238 196 70 / 100%);*/
  border-radius: 12px;
  /*border: 1px solid rgb(238 196 70 / 50%);*/
  text-align: center;
  /*box-shadow: 0 2px 8px rgb(0 0 0 / 10%);*/
  /*backdrop-filter: blur(8px);*/
  background: transparent;
}

[data-jp-theme-light='false'] .sage-ai-waiting-reply-container {
  /*background: var(--BG-main, #111);*/
  color: var(--jp-ui-font-color0);
}

.sage-ai-waiting-reply-container.visible {
  display: block;
}

.sage-ai-waiting-reply-text {
  margin-bottom: 2px;
  font-weight: 500;
}

.sage-ai-continue-button {
  background-color: transparent;
  color: white;
  padding: 6px;
  border-radius: 4px !important;
  border: 1px solid #383838 !important;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 6px;
  transition: all 0.2s ease;
}

.sage-ai-continue-button.hidden {
  display: none;
}

.sage-ai-continue-button:hover {
  background-color: transparent;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgb(0 0 0 / 15%);
}

.sage-ai-continue-button:active {
  transform: translateY(1px);
}

.sage-ai-prompt-buttons-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

[data-jp-theme-light='false'] .sage-ai-prompt-button {
  color: white !important;
}

.sage-ai-prompt-button {
  background-color: transparent;
  padding: 8px 12px;
  border-radius: 6px !important;
  border: 1px solid #383838 !important;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  min-height: 32px;
  white-space: normal;
  word-wrap: break-word;
}

.sage-ai-prompt-button:hover {
  background-color: transparent;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgb(0 0 0 / 15%);
}

.sage-ai-prompt-button:active {
  transform: translateY(1px);
}

.cm-editor:has(+ .jp-DiffOverlay) {
  display: none !important;
}

.jp-InputArea:has(.jp-DiffOverlay.sage-ai-quick-gen-diff-overlay) {
  display: block !important;
}

.hljs-subst {
  color: #9bb8d4 !important;
}

.sage-ai-restore-redo-element {
  animation: fadeIn 0.2s ease;
  display: none;
  backdrop-filter: blur(2px);
  border-radius: 50%;
  padding: 0;
  position: absolute;
  bottom: -7px;
  right: 25px;
  cursor: pointer;
  z-index: 0;
}

.sage-ai-restore-redo-element {
  color: var(--jp-ui-font-color2);
}

.sage-ai-restore-redo-element:hover {
  color: var(--jp-ui-font-color3);
}

/* Rollback element styles */
.sage-ai-rollback-element {
  animation: fadeIn 0.2s ease;
  display: inline-flex;
  backdrop-filter: blur(2px);
  border-radius: 50%;
  padding: 2px;
  position: absolute;
  bottom: -6px;
  right: 0;
  align-items: center;
  cursor: pointer;
  z-index: 5;
}

.sage-ai-rollback-icon {
  transition: transform 0.2s cubic-bezier(.4,2,.6,1), filter 0.2s;
  display: inline-flex;
}

.sage-ai-rollback-tooltip {
  position: absolute;
  left: -140px;
  top: 50%;
  transform: translateY(-50%) translateX(-10px);
  background: var(--jp-layout-color2, #f5f5f5);
  color: var(--jp-ui-font-color1, #222);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: opacity 0.2s cubic-bezier(.4,2,.6,1), transform 0.2s cubic-bezier(.4,2,.6,1);
  z-index: 10;
  opacity: 0;
  pointer-events: none;
}

.sage-ai-rollback-element:hover .sage-ai-rollback-tooltip {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.sage-ai-rollback-element:hover .sage-ai-rollback-icon {
  transform: scale(1.25);
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.10));
}
