/* Action row under the code panel header (Convert / Share / Support / Edit with AI). */
#codemirror-floating-container .codeditor-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 8px 8px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--main-bg-color);
  min-width: 0;
  box-sizing: border-box;
  width: 100%;
}

/* Custom dropdown styling for floating code editor */
#codemirror-floating-container .custom-dropdown {
  position: relative;
  display: inline-block;
  margin: 0;
  flex: 0 0 auto;
}

#codemirror-floating-container .dropdown-button,
#codemirror-floating-container .codeditor-action-btn {
  /* Same control look as the AI assistant panel (shared --svgp-panel-* vars) */
  background: var(--svgp-panel-control-bg);
  border: 1px solid var(--svgp-panel-control-border);
  border-radius: 6px;
  color: var(--text-color);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--svgp-panel-font);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
  letter-spacing: 0.3px;
  min-width: 90px;
  justify-content: center;
}

#codemirror-floating-container .dropdown-button:hover,
#codemirror-floating-container .codeditor-action-btn:hover {
  background: rgba(99, 179, 237, 0.12);
  border-color: var(--svgp-panel-accent);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

#codemirror-floating-container .dropdown-button.active {
  background: rgba(99, 179, 237, 0.12);
  border-color: var(--svgp-panel-accent);
}

#codemirror-floating-container .dropdown-button:focus,
#codemirror-floating-container .codeditor-action-btn:focus {
  outline: none;
  border-color: var(--svgp-panel-accent);
  box-shadow: 0 0 0 2px rgba(99, 179, 237, 0.2);
}

/* Subtle accent so Edit with AI reads as the AI entry, same pill language. */
#codemirror-floating-container .edit-with-ai-btn {
  min-width: 0;
  border-color: color-mix(in srgb, var(--svgp-panel-accent) 55%, var(--svgp-panel-control-border));
  color: var(--text-color);
}

#codemirror-floating-container .edit-with-ai-btn svg {
  color: var(--svgp-panel-accent);
  flex: 0 0 auto;
}

#codemirror-floating-container .dropdown-arrow {
  transition: transform 0.2s ease;
  opacity: 0.7;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center;
}

#codemirror-floating-container .dropdown-button.active .dropdown-arrow {
  transform: rotate(180deg);
}

#codemirror-floating-container .dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: rgba(40, 44, 52, 0.95);
  backdrop-filter: blur(20px);
  border: 1px solid var(--svgp-border);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 10000;
  margin-top: 4px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px) scale(0.95);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 180px;
  overflow: visible;
}

#codemirror-floating-container .dropdown-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

#codemirror-floating-container .dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  font-size: 11px;
  color: var(--text-color);
  cursor: pointer;
  border-radius: 6px;
  margin: 4px 6px;
  transition: all 0.15s ease;
  font-family: var(--global-font-family);
  font-weight: 400;
}

#codemirror-floating-container .dropdown-item:hover {
  background: var(--svgp-hover-bg);
  transform: translateX(2px);
}

#codemirror-floating-container .dropdown-item svg {
  opacity: 0.8;
  transition: opacity 0.15s ease;
}

#codemirror-floating-container .dropdown-item:hover svg {
  opacity: 1;
}

/* Header bar, header buttons and the collapsed state come from the shared
   .svgp-panel classes in svgedit.css (same look as the AI assistant panel). */

/* Title + live preview on the left of the header (SVGPLAYG-45). */
#codemirror-floating-container .codeditor-header-start {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

/* Compact live SVG preview; only shown while the editor is maximized. */
#codemirror-floating-container .codeditor-fs-preview {
  display: none;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
  box-sizing: border-box;
  align-items: center;
  justify-content: center;
}

/* Only shown when ext-preview has mounted a thumbnail (AI on). */
#codemirror-floating-container.fullscreen .codeditor-fs-preview.is-mounted {
  display: inline-flex;
}

#codemirror-floating-container .codeditor-fs-preview .svgp-preview {
  width: 100%;
  height: 100%;
}

#codemirror-floating-container .codeditor-fs-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  background: transparent;
}

/*
 * SVG conversion / optimize / share panels (SeSvg*Dialog.js,
 * floating-panel.js): floating .svgp-panel like the code editor.
 * open() centres them in the viewport (saved left/top wins after a drag;
 * double-click the title bar re-centres). z-index must sit above the
 * Icons dock (9000) and the floating AI / code-editor surfaces (~10000),
 * otherwise a centred panel is clipped at typical desktop widths
 * (e.g. 1440x900). Docked position and size come from
 * `.svgp-panel.svgp-docked` in svgedit.css; z-index is reset then so the
 * panel stacks with the other docks.
 */
#se-svg-conversion-dialog,
#se-svg-optimize-dialog,
#se-svg-share-dialog {
  position: fixed;
  top: 60px;
  left: 20px;
  z-index: 10050;
  display: flex;
  flex-direction: column;
  width: min(880px, calc(100vw - 24px));
  height: min(600px, calc(100vh - 24px));
  min-width: min(360px, calc(100vw - 24px));
  min-height: min(240px, calc(100vh - 24px));
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  overflow: hidden;
  resize: both;
}

#se-svg-optimize-dialog {
  width: min(940px, calc(100vw - 24px));
  height: min(640px, calc(100vh - 24px));
}

/* Share panel sizes to its content and isn't resizable */
#se-svg-share-dialog {
  width: min(440px, calc(100vw - 24px));
  height: auto;
  min-height: 0;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  resize: none;
}

#se-svg-conversion-dialog.svgp-docked,
#se-svg-optimize-dialog.svgp-docked,
#se-svg-share-dialog.svgp-docked {
  z-index: auto;
}

#se-svg-conversion-dialog[hidden],
#se-svg-optimize-dialog[hidden],
#se-svg-share-dialog[hidden] {
  display: none !important;
}

/* Collapsed: shrink to the title bar; the inline (possibly user-resized) size is kept for expanding */
#se-svg-conversion-dialog.svgp-collapsed,
#se-svg-optimize-dialog.svgp-collapsed,
#se-svg-share-dialog.svgp-collapsed {
  height: auto !important;
  min-height: 0 !important;
  resize: none;
}

/* Fullscreen / maximized state (SVGPLAYG-45): fill the viewport minus
   other docked panels (AI left/right/bottom). A floating AI panel sits on
   top (its z-index is 10000). */
#codemirror-floating-container.fullscreen {
  z-index: 9999 !important;
  width: auto !important;
  height: auto !important;
  max-height: none !important;
  min-width: 0 !important;
  min-height: 0 !important;
  top: var(--svgp-fs-top, 0px) !important;
  right: var(--svgp-fs-right, 0px) !important;
  bottom: var(--svgp-fs-bottom, 0px) !important;
  left: var(--svgp-fs-left, 0px) !important;
  transform: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

/* Hide minimize button in fullscreen mode */
#codemirror-floating-container.fullscreen .minimize-button {
  display: none !important;
}

/* Set minimum height for the floating container */
#codemirror-floating-container {
  min-height: 70vh !important;
  min-width: 500px !important;
}

/*
 * Layout: the floating container is a flex column
 *   header (.svgp-panel-header) / #codeditorpanel (flex: 1) / status footer (fixed height)
 * and #codeditorpanel is a flex column
 *   toolbar (Convert / Share / Support / Edit with AI) / #codemirror (flex: 1, scrolls internally).
 * min-height: 0 lets the editor shrink to the space left instead of overflowing
 * under the footer; heights follow the panel when it is resized.
 */
#codemirror-floating-container #codeditorpanel {
  flex: 1 1 auto;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  min-width: 0 !important;
  width: 100% !important;
  display: flex;
  flex-direction: column;
  overflow: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
}

#codemirror-floating-container #codeditorpanel > :not(#codemirror),
#sidepanels #codeditorpanel > :not(#codemirror) {
  flex: 0 0 auto;
}

#codemirror-floating-container #codemirror,
#sidepanels #codemirror {
  display: flex;
  flex: 1 1 auto;
  min-height: 0 !important;
  min-width: 0 !important;
  width: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
}

#codemirror-floating-container .cm-editor,
#sidepanels #codemirror .cm-editor {
  flex: 1 1 auto;
  min-width: 0;
  height: 100% !important;
}

#codemirror-floating-container .cm-scroller {
  height: 100% !important;
}

/* Custom scrollbar styling for the floating code editor */
#codemirror-floating-container .cm-scroller::-webkit-scrollbar {
  width: 8px;
  height: 0; /* Disable horizontal scrollbar */
}

#codemirror-floating-container .cm-scroller::-webkit-scrollbar-track {
  background: var(--svgp-scrollbar-track);
  border-radius: 4px;
}

#codemirror-floating-container .cm-scroller::-webkit-scrollbar-thumb {
  background: var(--svgp-scrollbar-thumb);
  border-radius: 4px;
  transition: background 0.2s ease;
}

#codemirror-floating-container .cm-scroller::-webkit-scrollbar-thumb:hover {
  background: var(--svgp-scrollbar-thumb-hover);
}

#codemirror-floating-container .cm-scroller::-webkit-scrollbar-corner {
  background: var(--svgp-scrollbar-track);
}

/* Firefox scrollbar styling */
#codemirror-floating-container .cm-scroller {
  scrollbar-width: thin;
  scrollbar-color: var(--svgp-scrollbar-thumb) var(--svgp-scrollbar-track);
  overflow-x: hidden; /* Disable horizontal scrolling */
}

/* Disable horizontal scrolling and enable text wrapping */
#codemirror-floating-container .cm-editor {
  overflow-x: hidden !important;
}

#codemirror-floating-container .cm-content {
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
  overflow-wrap: break-word !important;
}

/* Target all CodeMirror elements to disable horizontal scrolling */
#codemirror-floating-container .cm-editor,
#codemirror-floating-container .cm-scroller,
#codemirror-floating-container .cm-content,
#codemirror-floating-container .cm-line,
#codemirror-floating-container .cm-gutter,
#codemirror-floating-container .cm-gutterElement {
  overflow-x: hidden !important;
  max-width: 100% !important;
}

/* Force text wrapping on all content */
#codemirror-floating-container .cm-line {
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
  overflow-wrap: break-word !important;
  max-width: 100% !important;
}

/* Ensure the editor container itself doesn't overflow */
#codemirror-floating-container {
  overflow-x: hidden !important;
}

#codemirror-floating-container #codeditorpanel {
  overflow-x: hidden !important;
}

#codemirror-floating-container #codemirror {
  overflow-x: hidden !important;
}

/* Additional CodeMirror specific overrides */
#codemirror-floating-container .cm-editor.cm-focused {
  outline: none !important;
}

/* Override any padding from main CSS that might crop content */
#codemirror-floating-container #codeditorpanel {
  padding-left: 0 !important;
  padding-right: 0 !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

/* Force line wrapping and prevent horizontal scroll */
/* padding-left / text-indent come from the editor's hanging-indent line decorations */
#codemirror-floating-container .cm-line {
  white-space: pre-wrap !important;
  word-break: break-all !important;
  overflow-wrap: break-word !important;
  padding-right: 20px !important;
}

/* Ensure the editor viewport doesn't allow horizontal scrolling */
#codemirror-floating-container .cm-editor .cm-scroller {
  overflow-x: hidden !important;
  overflow-y: auto !important;
}

/* Target the actual content area */
#codemirror-floating-container .cm-editor .cm-content {
  white-space: pre-wrap !important;
  word-break: break-all !important;
  overflow-wrap: break-word !important;
  max-width: 100% !important;
  width: 100% !important;
  padding-right: 15px !important;
  padding-left: 5px !important;
}

/* Global scrollbar styling for the entire SVG editor */
.svg_editor ::-webkit-scrollbar {
  width: 8px;
  height: 0; /* Disable horizontal scrollbars globally */
}

.svg_editor ::-webkit-scrollbar-track {
  background: var(--svgp-scrollbar-track);
  border-radius: 4px;
}

.svg_editor ::-webkit-scrollbar-thumb {
  background: var(--svgp-scrollbar-thumb);
  border-radius: 4px;
  transition: background 0.2s ease;
}

.svg_editor ::-webkit-scrollbar-thumb:hover {
  background: var(--svgp-scrollbar-thumb-hover);
}

.svg_editor ::-webkit-scrollbar-corner {
  background: var(--svgp-scrollbar-track);
}

/* Firefox scrollbar styling for the entire editor */
.svg_editor {
  scrollbar-width: thin;
  scrollbar-color: var(--svgp-scrollbar-thumb) var(--svgp-scrollbar-track);
}

/* Status footer styling: slim in-flow row below the editor (no overlap, no blur) */
#codemirror-status-footer {
  position: static;
  flex: 0 0 39px;
  height: 39px;
  box-sizing: border-box;
  background: var(--main-bg-color);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  font-size: 12px;
  line-height: normal;
  color: var(--text-color);
  font-family: var(--global-font-family);
}

#codemirror-status-footer span {
  opacity: 0.8;
  transition: opacity 0.2s ease;
}

#codemirror-status-footer:hover span {
  opacity: 1;
}

#codemirror-status-footer a {
  color: inherit;
  text-decoration: underline;
  transition: opacity 0.2s ease;
}

#codemirror-status-footer a:hover {
  opacity: 0.8;
}

/* Custom selection color for better visibility - ensure it takes priority over active line */
/* Using purple that complements dark theme and doesn't clash with syntax colors */
.cm-editor .cm-selectionBackground,
#codemirror-floating-container .cm-selectionBackground,
#codemirror .cm-selectionBackground {
  background-color: rgba(156, 39, 176, 0.4) !important; /* Purple with transparency */
  z-index: 10 !important;
}

.cm-editor.cm-focused .cm-selectionBackground,
#codemirror-floating-container .cm-editor.cm-focused .cm-selectionBackground,
#codemirror .cm-editor.cm-focused .cm-selectionBackground {
  background-color: rgba(156, 39, 176, 0.5) !important; /* More prominent when focused */
  z-index: 10 !important;
}

.cm-editor .cm-selectionMatch,
#codemirror-floating-container .cm-selectionMatch,
#codemirror .cm-selectionMatch {
  background-color: rgba(156, 39, 176, 0.3) !important;
  z-index: 10 !important;
}

/* Ensure selection is visible even on active lines - reduce active line background */
.cm-editor .cm-activeLine,
#codemirror-floating-container .cm-activeLine,
#codemirror .cm-activeLine {
  background-color: transparent !important;
}

.cm-editor .cm-activeLineGutter,
#codemirror-floating-container .cm-activeLineGutter,
#codemirror .cm-activeLineGutter {
  background-color: transparent !important;
}

/* Ensure selection takes priority when on active line */
.cm-editor .cm-activeLine .cm-selectionBackground,
#codemirror-floating-container .cm-activeLine .cm-selectionBackground,
#codemirror .cm-activeLine .cm-selectionBackground {
  background-color: rgba(156, 39, 176, 0.5) !important;
  z-index: 10 !important;
}

/* Sidepanel footer styling */
#codemirror-sidepanel-footer {
  height: 39px;
  box-sizing: border-box;
  background: var(--main-bg-color);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  font-size: 12px;
  line-height: normal;
  color: var(--text-color);
  font-family: var(--global-font-family);
}

#codemirror-sidepanel-footer span {
  opacity: 0.8;
  transition: opacity 0.2s ease;
}

#codemirror-sidepanel-footer:hover span {
  opacity: 1;
}

#codemirror-sidepanel-footer a {
  color: inherit;
  text-decoration: underline;
  transition: opacity 0.2s ease;
}

#codemirror-sidepanel-footer a:hover {
  opacity: 0.8;
}
