/**
 * yaml-editor.css - Styles for Editor Dialog with Monaco YAML Editor
 * Version: 4.8.0
 *
 * Editor-first design with locations popup overlay
 * Hoverable tooltips with clickable links
 * Save popup with labeled locations explaining when to use each
 * Clickable module paths in include lists
 */

/* ==========================================================================
   Editor Dialog Base Styles
   ========================================================================== */

html dialog.md-dialog.md-dialog--editor {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90vw;
    max-width: 900px;
    min-width: 500px;
    height: 75vh;
    max-height: 85vh;
    margin: 0;
    border: none;
    border-radius: 0.5rem;
    background: var(--md-default-bg-color, #1e1e2e) !important;
    color: var(--md-default-fg-color, #cdd6f4) !important;
    padding: 0;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

html dialog.md-dialog.md-dialog--editor[open] {
    display: flex;
    flex-direction: column;
}

/* Fullscreen mode */
html dialog.md-dialog.md-dialog--editor.fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
}

html dialog.md-dialog.md-dialog--editor::backdrop {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

/* ==========================================================================
   Dialog Wrapper & Layout
   ========================================================================== */

.editor-dialog-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

/* ==========================================================================
   Dialog Header - VS Code style toolbar
   ========================================================================== */

.editor-dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0.5rem;
    background: var(--md-code-bg-color, #313244);
    border-bottom: 1px solid var(--md-default-fg-color--lightest, #45475a);
    flex-shrink: 0;
    gap: 0.5rem;
    height: 32px;
}

.editor-dialog-title {
    font-size: 12px;
    font-weight: 400;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #8a8a8a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
    min-width: 0;
    line-height: 32px;
}

.editor-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    height: 32px;
}

/* Toolbar buttons - VS Code style - force override all MkDocs styles */
.editor-header-actions button,
.editor-header-actions .md-button,
.editor-header-actions .editor-toolbar-btn,
.editor-header-actions [class*="yaml-editor-"] {
    all: unset !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 26px !important;
    height: 26px !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    border: none !important;
    border-radius: 3px !important;
    cursor: pointer !important;
    color: #a0a0a0 !important;
    transition: background 0.1s, color 0.1s !important;
    box-sizing: border-box !important;
    font-size: 0 !important;
    line-height: 1 !important;
}

.editor-header-actions button:hover,
.editor-header-actions .md-button:hover,
.editor-header-actions .editor-toolbar-btn:hover,
.editor-header-actions [class*="yaml-editor-"]:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    color: #ccc !important;
}

.editor-header-actions button svg,
.editor-header-actions .md-button svg,
.editor-header-actions .editor-toolbar-btn svg,
.editor-header-actions [class*="yaml-editor-"] svg {
    width: 16px !important;
    height: 16px !important;
    fill: currentColor !important;
    flex-shrink: 0 !important;
}

.header-divider {
    width: 1px !important;
    height: 14px !important;
    background: rgba(255, 255, 255, 0.15) !important;
    margin: 0 4px !important;
    flex-shrink: 0 !important;
}

/* Close button - red hover like VS Code */
.editor-header-actions .editor-dialog-close:hover,
.editor-header-actions button:last-child:hover {
    background: rgba(232, 17, 35, 0.9) !important;
    color: #fff !important;
}

/* Copy button success state */
.editor-header-actions .yaml-editor-copy.copied {
    color: #a6e3a1 !important;
    background: rgba(166, 227, 161, 0.15) !important;
}

/* JS-based tooltip styling - tooltips are created dynamically */
.editor-tooltip {
    position: absolute;
    background: #0a0a12;
    color: #f0f0f0;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 400;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    white-space: normal;
    max-width: 320px;
    line-height: 1.5;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.15);
    z-index: 10000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

/* Monospace tooltip for file paths (short single-line) */
.editor-tooltip.tooltip-path {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
    white-space: nowrap;
    max-width: 90vw;
}

.editor-tooltip.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Link styling inside tooltip */
.editor-tooltip a {
    color: #89b4fa;
    text-decoration: underline;
    cursor: pointer;
}

.editor-tooltip a:hover {
    color: #b4befe;
}

/* Arrow pointing up (tooltip below element) */
.editor-tooltip::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-bottom-color: #0a0a12;
    border-top: none;
}

/* Arrow pointing down (tooltip above element) */
.editor-tooltip.arrow-bottom::before {
    top: auto;
    bottom: -6px;
    border-bottom: none;
    border-top: 6px solid #0a0a12;
}

/* ==========================================================================
   Editor Content Area
   ========================================================================== */

.editor-dialog-content {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.yaml-editor-container {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: #1e1e2e;
    position: relative;
}

/* Iframe-based Monaco editor */
.yaml-editor-container > iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #1e1e2e;
    display: block;
}

/* ==========================================================================
   Status Bar (minimal)
   ========================================================================== */

.yaml-editor-statusbar {
    display: flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

.yaml-editor-status {
    font-size: 0.65rem;
    font-weight: 500;
    color: #a6e3a1;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.yaml-editor-status::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
}

.yaml-editor-status.modified {
    color: #f9e2af;
}

.yaml-editor-status.error {
    color: #f38ba8;
}

.yaml-editor-status.loading {
    color: #89b4fa;
}

.yaml-editor-status.loading::before {
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Schema loaded status - clickable */
.yaml-editor-status.schema-loaded {
    color: #a6e3a1;
    cursor: pointer;
}

.yaml-editor-status.schema-loaded:hover {
    color: #89b4fa;
    text-decoration: underline;
}

/* Download hint in status bar */
.yaml-editor-status .download-hint {
    color: #89b4fa;
    opacity: 0.7;
    transition: opacity 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: 0.25rem;
}

.yaml-editor-status .download-hint:hover {
    opacity: 1;
    text-decoration: underline;
}

.yaml-editor-status .download-hint svg {
    vertical-align: middle;
}

.yaml-editor-status .schema-link {
    display: inline;
}

.yaml-editor-status .schema-link:hover {
    text-decoration: underline;
}

/* Highlighted download button (when hovering download hint) */
.editor-header-actions .yaml-editor-locations.highlighted,
.yaml-editor-locations.highlighted {
    background: rgba(137, 180, 250, 0.3) !important;
    color: #89b4fa !important;
    box-shadow: 0 0 0 2px rgba(137, 180, 250, 0.4);
    border-radius: 4px;
}

/* ==========================================================================
   Locations Popup Overlay
   ========================================================================== */

.locations-popup {
    position: absolute;
    top: 2.5rem;
    right: 1rem;
    z-index: 100;
    animation: popupSlideDown 0.15s ease-out;
}

@keyframes popupSlideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.locations-popup-content {
    background: var(--md-code-bg-color, #313244);
    border: 1px solid var(--md-default-fg-color--lightest, #45475a);
    border-radius: 0.4rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    min-width: 300px;
    max-width: 90vw;
}

.locations-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--md-default-fg-color--light, #a6adc8);
}

.locations-header-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.locations-header-label .help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: help;
    color: var(--md-default-fg-color--light, #6c7086);
    transition: color 0.15s ease;
}

.locations-header-label .help-icon:hover {
    color: var(--md-accent-fg-color, #89b4fa);
}

.locations-header-label .help-icon svg {
    width: 14px;
    height: 14px;
}

.locations-popup-close {
    background: transparent;
    border: none;
    color: var(--md-default-fg-color--light, #6c7086);
    cursor: pointer;
    padding: 0.15rem;
    border-radius: 0.15rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.locations-popup-close:hover {
    background: rgba(243, 139, 168, 0.2);
    color: #f38ba8;
}

.locations-popup-close svg {
    width: 14px;
    height: 14px;
}

/* ==========================================================================
   Locations List (inside popup) - Ultra-specific selectors to override MkDocs
   ========================================================================== */

dialog.md-dialog--editor .locations-popup .locations-list,
.md-dialog--editor .locations-popup .locations-list,
.locations-popup .locations-list,
.locations-list {
    all: unset !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
    list-style: none !important;
    padding: 0.5rem 0.75rem !important;
    margin: 0 !important;
}

dialog.md-dialog--editor .locations-popup .locations-list li,
.md-dialog--editor .locations-popup .locations-list li,
.locations-popup .locations-list li,
.locations-list li {
    all: unset !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 0.25rem !important;
    padding: 0.5rem !important;
    background: rgba(0, 0, 0, 0.15) !important;
    border-radius: 0.25rem !important;
    border: none !important;
    box-sizing: border-box !important;
}

dialog.md-dialog--editor .locations-popup .locations-list li:hover,
.locations-list li:hover {
    background: rgba(0, 0, 0, 0.25) !important;
}

dialog.md-dialog--editor .locations-popup .locations-list li .location-label,
.md-dialog--editor .locations-popup .locations-list li .location-label,
.locations-popup .locations-list .location-label,
.locations-list .location-label,
.locations-list li span.location-label {
    all: unset !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.35rem !important;
    font-size: 0.72rem !important;
    font-weight: 600 !important;
    color: #89b4fa !important;
    margin-bottom: 0.2rem !important;
    line-height: 1.4 !important;
}

/* Help icon inside location labels */
dialog.md-dialog--editor .locations-popup .locations-list .location-label .help-icon,
.locations-list .location-label .help-icon,
.location-label .help-icon {
    all: unset !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: help !important;
    color: #6c7086 !important;
    transition: color 0.15s ease !important;
    flex-shrink: 0 !important;
}

dialog.md-dialog--editor .locations-popup .locations-list .location-label .help-icon:hover,
.locations-list .location-label .help-icon:hover,
.location-label .help-icon:hover {
    color: #89b4fa !important;
}

dialog.md-dialog--editor .locations-popup .locations-list .location-label .help-icon svg,
.locations-list .location-label .help-icon svg,
.location-label .help-icon svg {
    width: 12px !important;
    height: 12px !important;
    fill: currentColor !important;
}

dialog.md-dialog--editor .locations-popup .locations-list li .location-path-row,
.md-dialog--editor .locations-popup .locations-list li .location-path-row,
.locations-popup .locations-list .location-path-row,
.locations-list .location-path-row {
    all: unset !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 0.5rem !important;
    box-sizing: border-box !important;
}

dialog.md-dialog--editor .locations-popup .locations-list .location-path,
.md-dialog--editor .locations-popup .locations-list .location-path,
.locations-popup .locations-list .location-path,
.locations-list .location-path,
.locations-list li code.location-path {
    all: unset !important;
    flex: 1 !important;
    background: transparent !important;
    color: var(--md-code-fg-color, #cdd6f4) !important;
    padding: 0 !important;
    font-size: 0.72rem !important;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace !important;
    white-space: nowrap !important;
    border: none !important;
    display: inline !important;
}

dialog.md-dialog--editor .locations-popup .locations-list .copy-btn,
.md-dialog--editor .locations-popup .locations-list .copy-btn,
.locations-popup .locations-list .copy-btn,
.locations-list .copy-btn,
.locations-list li button.copy-btn {
    all: unset !important;
    padding: 0.25rem !important;
    background: transparent !important;
    color: var(--md-default-fg-color--light, #6c7086) !important;
    border: none !important;
    border-radius: 0.2rem !important;
    cursor: pointer !important;
    transition: all 0.15s ease !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    opacity: 0.6 !important;
    box-sizing: border-box !important;
}

dialog.md-dialog--editor .locations-popup .locations-list .copy-btn:hover,
.locations-list .copy-btn:hover {
    background: rgba(137, 180, 250, 0.2) !important;
    color: var(--md-accent-fg-color, #89b4fa) !important;
    opacity: 1 !important;
}

dialog.md-dialog--editor .locations-popup .locations-list .copy-btn svg,
.locations-list .copy-btn svg {
    width: 14px !important;
    height: 14px !important;
    fill: currentColor !important;
}

/* Locations popup footer with download button */
.locations-popup-footer {
    padding: 0.5rem 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.locations-download-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: rgba(137, 180, 250, 0.15) !important;
    color: var(--md-accent-fg-color, #89b4fa) !important;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.15s ease;
}

.locations-download-btn:hover {
    background: rgba(137, 180, 250, 0.25) !important;
}

.locations-download-btn svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* ==========================================================================
   Monaco Editor Overrides
   ========================================================================== */

.yaml-editor-container .monaco-editor {
    border-radius: 0;
}

/* Force proper Monaco rendering after instant navigation */
.yaml-editor-container .monaco-editor .overflow-guard {
    position: relative !important;
}

.yaml-editor-container .monaco-editor .margin {
    background: #1e1e2e !important;
    visibility: visible !important;
    display: block !important;
    opacity: 1 !important;
    position: absolute !important;
    left: 0 !important;
}

/* Force line numbers to render correctly */
.yaml-editor-container .monaco-editor .margin-view-overlays {
    visibility: visible !important;
    opacity: 1 !important;
    position: absolute !important;
    width: auto !important;
    min-width: 40px !important;
    transform: none !important;
    clip-path: none !important;
    overflow: visible !important;
}

.yaml-editor-container .monaco-editor .line-numbers {
    visibility: visible !important;
    display: block !important;
    opacity: 1 !important;
    color: #6c7086 !important;
    min-width: 30px !important;
    transform: none !important;
    position: relative !important;
}

/* Force the margin to not clip content */
.yaml-editor-container .monaco-editor .margin {
    overflow: visible !important;
    clip-path: none !important;
}

/* Ensure the editor content area doesn't clip line numbers */
.yaml-editor-container .monaco-editor .lines-content {
    position: relative !important;
}

.yaml-editor-container .monaco-editor .view-overlays {
    position: absolute !important;
}

.yaml-editor-container .monaco-editor .monaco-scrollable-element > .scrollbar > .slider {
    background: rgba(255, 255, 255, 0.2) !important;
    border-radius: 4px;
}

.yaml-editor-container .monaco-editor .monaco-scrollable-element > .scrollbar > .slider:hover {
    background: rgba(255, 255, 255, 0.3) !important;
}

/* Loading state for editor */
.yaml-editor-container:empty::before {
    content: 'Loading editor...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--md-default-fg-color--light, #6c7086);
    font-size: 0.85rem;
}

.yaml-editor-container:empty {
    position: relative;
}

/* ==========================================================================
   Responsive Styles
   ========================================================================== */

@media (max-width: 768px) {
    html dialog.md-dialog.md-dialog--editor {
        width: 100vw;
        min-width: unset;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .editor-dialog-header {
        height: 32px;
        padding: 0 8px;
    }

    .editor-dialog-title {
        font-size: 11px;
    }

    .locations-popup {
        left: 4px;
        right: 4px;
        top: 36px;
    }

    .locations-popup-content {
        min-width: unset;
        max-width: unset;
    }

    .locations-list .location-path {
        font-size: 0.65rem;
    }
}

/* ==========================================================================
   Legacy Support - Hide old elements
   ========================================================================== */

.md-content .md-typeset .tenx-browser-edit-button,
.md-typeset .tenx-browser-edit-button,
.tenx-browser-edit-button {
    display: none !important;
}
