/** 
* AI File Actions Styles 
* Styling for the AI file actions component, including the split button and dropdown menu.
*/

/* --- Container for the split button --- */
.ai-file-actions-container {
  display: inline-flex;
  margin-left: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  overflow: visible;
  position: relative;
  white-space: nowrap;
}

/* --- Common Button Styles --- */
.ai-file-actions-btn {
  padding: 0.6em 0.9em;
  background-color: var(--secondary-bg-color);
  color: var(--md-default-fg-color);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-size: 16px;
}

/* --- Hover effects on buttons --- */
.ai-file-actions-btn:hover {
  background-color: var(--warm-brown);
  color: var(--cream);
}

/* --- Left Button (Copy) --- */
.ai-file-actions-copy {
  border-right: 1px solid var(--border-color);
  gap: 0.5em;
  border-top-left-radius: var(--border-radius);
  border-bottom-left-radius: var(--border-radius);
}

/* Keep separator stable on hover */
.ai-file-actions-container:hover .ai-file-actions-copy {
  border-right-color: var(--border-color);
}

/* --- Right Button (Trigger) --- */
.ai-file-actions-trigger {
  border-top-right-radius: var(--border-radius);
  border-bottom-right-radius: var(--border-radius);
  padding: 0.6em 0.7em;
}

.ai-file-actions-trigger.active {
  background-color: var(--warm-brown);
  color: var(--cream);
}

/* --- Icons --- */
.ai-file-actions-icon {
  width: 1.1em;
  height: 1.1em;
  min-width: 1.1em;
  fill: currentColor;
  display: block;
}

/* Specific adjustment for spinner placement */
.ai-file-actions-icon.loading-spinner {
  margin: 0;
}

/* Size and color for the chevron icon */
.ai-file-actions-chevron {
  background-size: 1em 1em;
  transition: transform 0.2s;
  fill: currentColor;
}

/* Rotate chevron when active */
.ai-file-actions-trigger.active .ai-file-actions-chevron {
  transform: rotate(180deg);
}

/* --- Dropdown Menu --- */
.ai-file-actions-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background-color: var(--secondary-bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  z-index: 3;
  min-width: 140px;
  overflow: hidden;
  flex-direction: column;
  padding: 5px;
}

[data-md-color-scheme] .ai-file-actions-menu {
  border-color: var(--border-color);
}

/* Reset specific overrides if they exist for the active custom schemes */
[data-md-color-scheme='custom-light'] .ai-file-actions-container,
[data-md-color-scheme='custom-dark'] .ai-file-actions-container {
  border-color: var(--border-color);
}

.ai-file-actions-menu.show {
  display: flex;
}

/* --- Dropdown Items --- */
.md-typeset a.ai-file-actions-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.475rem 0.625rem;
  border: none;
  background: none;
  color: var(--md-default-fg-color);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.1s;
  font-size: 16px;
  line-height: 1.2;
}

.ai-file-actions-item .ai-file-actions-external {
  margin-left: auto;
}

.md-typeset a.ai-file-actions-item:hover {
  background-color: var(--warm-brown);
  color: var(--cream);
}

/* --- Table-scoped overrides --- */
.md-typeset table .ai-file-actions-btn,
.md-typeset table .ai-file-actions-item {
  font-size: 0.64rem;
}

/* Remove the scroll wrapper's overflow constraint on any table that contains
   the file actions widget, so the absolutely-positioned dropdown can extend
   beyond the table bounds without being clipped. */
.md-typeset__scrollwrap:has(.ai-file-actions-container) {
  overflow: visible;
}

/* Switching to inline-table prevents the table row from expanding to
   accommodate the absolutely-positioned dropdown. As a block-level element,
   display:table can stretch its rows to contain overflowing children;
   inline-table does not exhibit this behaviour. */
.md-typeset table:not([class]):has(.ai-file-actions-container) {
  display: inline-table;
}

/* --- H1 + per-page AI actions wrapper --- */
.h1-ai-actions-wrapper {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.h1-ai-actions-wrapper h1 {
  flex: 1;
  margin: 0;
}

/* Mobile responsive */
@media screen and (max-width: 768px) {
  .h1-ai-actions-wrapper {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .h1-ai-actions-wrapper h1 {
    width: 100%;
  }

  .h1-ai-actions-wrapper .ai-file-actions-container {
    margin-left: 0;
    margin-top: 0.5rem;
  }

  .h1-ai-actions-wrapper .ai-file-actions-menu {
    left: 0;
    right: auto;
    min-width: 200px;
  }
}

/* --- Loading Spinner --- */
.ai-file-actions-container .loading-spinner {
  animation: spinner-rotate 2s linear infinite;
}

.ai-file-actions-container .loading-spinner circle {
  animation: spinner-dash 1.5s ease-in-out infinite;
}

@keyframes spinner-rotate {
  100% {
    transform: rotate(360deg);
  }
}

@keyframes spinner-dash {
  0% {
    stroke-dasharray: 1, 150;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -35;
  }
  100% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -124;
  }
}
