/* When LLM state display is hidden, move plan state display up */
.sage-ai-chatbox:has(.sage-ai-llm-state-widget.hidden)
  .sage-ai-plan-state-widget {
  margin-bottom: 0 !important;
}

/* Wrapper for fixed positioning with flexbox */
.sage-ai-state-display-container {
  position: fixed !important;
  bottom: 0;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* Apply styles directly to widget nodes */
.sage-ai-plan-state-widget {
  order: 1;
  pointer-events: auto;
  margin: 0 17px 4px;
  margin-bottom: -10px;
}

.sage-ai-plan-state-widget.hidden {
  display: none;
}

.sage-ai-llm-state-widget {
  order: 2;
  pointer-events: auto;
  margin: 0 17px;
}

.sage-ai-input-spacer {
  order: 3;
  flex-shrink: 0;
}

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

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

/* Plan State Display - positioned above the LLM state display */
.sage-ai-plan-state-display {
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  padding-bottom: 14px;
  border-radius: 8px 8px 0 0;
  font-size: 13px;
  color: var(--jp-ui-font-color1);
  box-shadow: 0 2px 4px rgb(0 0 0 / 5%);
  transition: all 0.2s ease-in-out;
  border: 1px solid var(--jp-border-color2);
}

.sage-ai-plan-state-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sage-ai-plan-state-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.sage-ai-plan-current-step {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sage-ai-plan-current-text {
  color: var(--jp-ui-font-color1);
  font-size: 12px;
  font-weight: 400;
}

.sage-ai-plan-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.sage-ai-plan-next-text {
  color: var(--jp-ui-font-color2);
  font-weight: 300;
  font-size: 10px;
  flex: 1; /* Take up available space */
}

.sage-ai-plan-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-plan-source-toggle:hover {
  background-color: var(--jp-layout-color2);
  color: var(--jp-ui-font-color1);
}

.sage-ai-plan-source-content {
  margin-top: 8px;
  margin-bottom: 4px;
  padding: 12px;
  background-color: var(--jp-layout-color2);
  border-radius: 6px;
  overflow-y: auto;
  min-height: 100px;
  max-height: 25vh;
  transition: all 0.3s ease-in-out;
  transform-origin: bottom; /* Changed from top to bottom to expand upward */
}

.sage-ai-plan-source-content.collapsed {
  max-height: 0;
  min-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-top: 0;
  border: none;
  opacity: 0;
  transform: scaleY(0);
}

.sage-ai-plan-source-content.expanded {
  opacity: 1;
  transform: scaleY(1);
}

.sage-ai-plan-tasks-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-family: var(--jp-ui-font-family);
  font-size: 12px;
  line-height: 1.4;
  color: var(--jp-ui-font-color1);
}

.sage-ai-plan-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--jp-ui-font-color0);
}

.sage-ai-plan-task-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sage-ai-plan-subtask-item {
  margin-left: 16px;
}

.sage-ai-task-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sage-ai-plan-subtopics {
  margin-top: 4px;
  margin-bottom: 0;
}

.sage-ai-plan-subtopic {
  margin: 0;
  padding: 0;
}

.sage-ai-subtopic-bullet {
  color: var(--jp-ui-font-color2);
  font-size: 12px;
  font-weight: bold;
}

.sage-ai-subtopic-text {
  color: var(--jp-ui-font-color1);
  font-size: var(--jp-ui-font-size1);
  font-weight: 400;
}

.sage-ai-task-executing {
  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;
  }
}

/* Keep the old markdown styles for backward compatibility */
.sage-ai-plan-source-markdown {
  font-family: var(--jp-code-font-family);
  font-size: 11px;
  line-height: 1.4;
  color: var(--jp-ui-font-color1);
}

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

.sage-ai-plan-source-markdown h1 {
  font-size: 14px;
}

.sage-ai-plan-source-markdown h2 {
  font-size: 13px;
}

.sage-ai-plan-source-markdown h3 {
  font-size: 12px;
}

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

.sage-ai-plan-source-markdown p {
  margin: 4px 0;
}

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

.sage-ai-plan-source-markdown li {
  margin: 2px 0;
}

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

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

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

.sage-ai-plan-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;
}

/* Ensure the blob loader works in this context */
.sage-ai-plan-state-display .sage-ai-blob-loader {
  flex-shrink: 0;
}

/* Toggle icon animation */
.sage-ai-plan-toggle-icon {
  font-size: 12px;
  transition: transform 0.2s ease;
  line-height: 1;
}

.sage-ai-plan-source-toggle[aria-expanded='false'] > svg {
  transform: rotate(180deg);
}

.sage-ai-plan-state-loader {
  width: 26px;
  height: 26px;
  display: inline-block;
  position: relative;
}

.sage-ai-plan-state-loader::after,
.sage-ai-plan-state-loader::before {
  content: '';
  box-sizing: border-box;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(59, 130, 246, 1);
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  animation: sage-ai-plan-state-display-animloader 2s linear infinite;
}

.sage-ai-plan-state-loader::after {
  animation-delay: 1s;
}

@keyframes sage-ai-plan-state-display-animloader {
  0% {
    transform: scale(0);
    opacity: 1;
  }

  100% {
    border-color: #ccdffe;
    transform: scale(1);
    opacity: 0;
  }
}
