/* Base styles */
* {
    box-sizing: border-box;
}

/* ── Custom Tooltips ─────────────────────────────────────────── */
/* Usage: data-tooltip="Label" on any element                    */
/* Default: tip appears ABOVE. Add .tooltip-down for below.     */
[data-tooltip] {
    position: relative;
}

/* The tooltip bubble */
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 7px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(18, 10, 16, 0.82);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #c4a4b4;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 9.5px;
    font-weight: 500;
    letter-spacing: 0.3px;
    white-space: nowrap;
    padding: 4px 8px;
    border-radius: 2px;
    border: 1px solid rgba(58, 38, 58, 0.7);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    /* instant – no transition */
    transition: none;
    z-index: 9999;
}

/* The tiny upward-pointing arrow */
[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: rgba(58, 38, 58, 0.7);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: none;
    z-index: 9999;
}

/* Show on hover */
[data-tooltip]:hover::after,
[data-tooltip]:hover::before {
    opacity: 1;
    visibility: visible;
}

/* ── .tooltip-down variant (tip appears below the element) ── */
.tooltip-down[data-tooltip]::after {
    bottom: auto;
    top: calc(100% + 7px);
}

.tooltip-down[data-tooltip]::before {
    bottom: auto;
    top: calc(100% + 2px);
    border-top-color: transparent;
    border-bottom-color: rgba(58, 38, 58, 0.7);
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    background-color: #0d080c;
}

/* Page Header */
.page-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    z-index: 1000;
    transition: box-shadow 0.2s ease;
}

.page-header.scrolled {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.page-header.scrolled::after {
    content: '';
    position: absolute;
    bottom: -20px;
    left: 0;
    right: 0;
    height: 20px;
    background: linear-gradient(to bottom, rgba(13, 8, 12, 0.6), rgba(13, 8, 12, 0));
    pointer-events: none;
}

.header-background {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    background-color: #140d11;
    overflow: hidden;
    border-bottom: 1px solid #2a182a;
}

.diagonal-lines {
    position: absolute;
    top: 0;
    left: -30px;
    right: 0;
    height: 100%;
    background-image: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 7px,
        #1a101a 7px,
        #1a101a 8px
    );
}

.header-content {
    position: relative;
    height: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding-right: 15px;
}

.header-tab {
    position: relative;
    height: 38px;
    background-color: #140d11;
    border: 1px solid #2a182a;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    padding: 0 20px;
    display: flex;
    align-items: center;
    margin-left: 15px;
    margin-top: 18px;
    min-width: 150px;
    z-index: 2;
    gap: 8px;
}

.header-tab .svg-inline--fa {
    color: #d4b4c4;
    font-size: 12px;
}

.header-tab::before {
    content: '';
    position: absolute;
    bottom: -1px;
    left: -1px;
    right: -1px;
    height: 9px;
    background-color: #140d11;
    z-index: 3;
    /* border-left: 1px solid #2a182a;
    border-right: 1px solid #2a182a; */
}

.header-tab i {
    color: #d4b4c4;
    font-size: 10px;
    margin-right: 6px;
}

.tab-text {
    color: #d4b4c4;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    height: 36px;
    overflow: visible;
}

.main-container {
    margin-top: 48px;
    height: calc(100vh - 48px);
    display: flex;
    overflow: hidden;
    gap: 0;
}

.editor-panel {
    flex: 0 1 50%;
    min-width: 300px;
    max-width: 80%;
    height: 100%;
    min-height: 0;
    background-color: #140d11;
    border-right: 1px solid #2a182a;
    display: flex;
    flex-direction: column;
    position: relative;
}

#codeEditor {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    position: relative;
    margin-top: 12px;

    scrollbar-width: none;
    -ms-overflow-style: none;
}

#codeEditor::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    pointer-events: none;
    background: linear-gradient(to bottom, rgba(20, 13, 17, 0.95), rgba(20, 13, 17, 0) 70%, rgba(20, 13, 17, 0));
    z-index: 2;
    opacity: 0;
    transition: opacity 0.2s ease;
}

#codeEditor.has-scroll-shadow::before {
    opacity: 1;
}

.preview-panel {
    flex: 1;
    min-width: 200px;
    height: 100%;
    background-color: #0d080c;
    position: relative;
}

#canvasContainer {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #0d080c;
}

#canvasContainer canvas {
    max-width: 100%;
    max-height: 100%;
}

.CodeMirror {
    height: 100% !important;
    font-size: 13px;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace !important;
    background-color: #140d11 !important;
}

.CodeMirror-scroll {
    min-height: 100%;
    overflow-y: auto !important;
    overflow-x: auto !important;
}

.CodeMirror-gutters {
    background-color: #140d11 !important;
    border-right: 1px solid #1a101a !important;
}

.CodeMirror-linenumber {
    color: #5a3a4a !important;
}

/* CodeMirror Autocomplete/Hint Styling */
.CodeMirror-hints {
    background-color: #1a101a !important;
    border: 1px solid #3a283a !important;
    border-radius: 2px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 12px;
}

.CodeMirror-hint {
    color: #d4b4c4 !important;
    padding: 4px 8px;
    border-radius: 2px;
}

.CodeMirror-hint-active {
    background-color: #2a182a !important;
    color: #ef79a2 !important;
}

/* Console styles */
.console-wrapper {
    width: 100%;
    background-color: #0a050a;
    border-top: 1px solid #2a182a;
    transition: height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    height: 36px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.console-wrapper.expanded {
    height: 360px;
}

.console-header {
    height: 36px;
    min-height: 36px;
    flex-shrink: 0;
    padding: 0 16px;
    background-color: #0a050a;
    border-bottom: 1px solid #2a182a;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.console-label-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.console-label-group .svg-inline--fa {
    color: #7a5a6a;
    font-size: 12px;
}

.console-header:hover {
    background-color: #140d11;
}

.console-title {
    font-size: 10px;
    font-weight: 500;
    color: #7a5a6a;
    margin: 0;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#errorConsole {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    background-color: #0a050a;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 11px;
    padding: 6px 8px;
    color: #d4b4c4;
}

.error-message {
    color: #ff5a7a;
    margin-bottom: 4px;
    white-space: pre-wrap;
    word-break: break-word;
}

.error-details {
    color: #ef79a2;
    margin-left: 12px;
    font-size: 10px;
    margin-bottom: 2px;
}

.console-message {
    color: #d4b4c4;
    margin-bottom: 2px;
}

/* Toast styling */
.toast-container {
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
}

.toast {
    background-color: #1a101a;
    color: #d4b4c4;
    padding: 8px 16px;
    border-radius: 2px;
    margin-bottom: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    animation: slideIn 0.2s ease-out;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 11px;
    border: 1px solid #2a182a;
    opacity: 1 !important;
    position: relative;
    z-index: 2000;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Editor toolbar styling */
.editor-toolbar {
    display: none;
}

.editor-floating-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Floating copy button */
#copyBtn {
    backdrop-filter: blur(8px);
    background-color: rgba(26, 16, 26, 0.9) !important;
    border: 1px solid rgba(58, 38, 58, 0.8) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateZ(0);
    color: #9a7a8a !important;
}

/* Fresh Sketch button */
#freshSketchBtn {
    backdrop-filter: blur(8px);
    background-color: rgba(26, 16, 26, 0.9) !important;
    border: 1px solid rgba(58, 38, 58, 0.8) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateZ(0);
    color: #9a7a8a !important;
}

#freshSketchBtn:hover {
    transform: translateY(-1px) translateZ(0);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    background-color: rgba(42, 24, 42, 0.95) !important;
    border-color: rgba(78, 58, 78, 0.9) !important;
    color: #d4b4c4 !important;
}

#freshSketchBtn:active {
    transform: translateY(0) translateZ(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* AI Loading indicator */
.ai-loader {
    display: none;
    height: 24px;
    padding: 0 8px;
    font-size: 16px;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    color: #c2508c;
    background-color: transparent;
    border: none;
    align-items: center;
    justify-content: center;
}

/* Version Control Button */
#versionControlBtn {
    backdrop-filter: blur(8px);
    background-color: rgba(26, 16, 26, 0.9) !important;
    border: 1px solid rgba(58, 38, 58, 0.8) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateZ(0);
    color: #9a7a8a !important;
}

#versionControlBtn:hover {
    transform: translateY(-1px) translateZ(0);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    background-color: rgba(42, 24, 42, 0.95) !important;
    border-color: rgba(78, 58, 78, 0.9) !important;
    color: #d4b4c4 !important;
}

#versionControlBtn:active {
    transform: translateY(0) translateZ(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* Version Control Popover */
.version-popover {
    position: absolute;
    top: 40px;
    right: -130px;
    width: 320px;
    max-height: 400px;
    background-color: #140d11;
    border: 1px solid #3a283a;
    border-radius: 2px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    z-index: 100;
    backdrop-filter: blur(12px);
}

.version-popover-header {
    padding: 12px 16px;
    border-bottom: 1px solid #2a182a;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.version-popover-title {
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 11px;
    font-weight: 500;
    color: #d4b4c4;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.version-popover-close {
    background: none;
    border: none;
    color: #7a5a6a;
    font-size: 10px;
    cursor: pointer;
    padding: 2px 4px;
    transition: color 0.15s;
}

.version-popover-close:hover {
    color: #d4b4c4;
}

.version-popover-body {
    padding: 12px;
    max-height: 360px;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.version-popover-body::-webkit-scrollbar {
    display: none;
    width: 0;
    background: transparent;
}

/* Version Timeline */
.version-timeline {
    position: relative;
}

.version-timeline-empty {
    text-align: center;
    padding: 24px;
    color: #7a5a6a;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 10px;
}

.version-timeline-item {
    position: relative;
    padding-left: 32px;
    padding-bottom: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.version-timeline-item:hover .version-timeline-prompt {
    color: #ef79a2;
}

.version-timeline-item:last-child {
    padding-bottom: 0;
}

.version-timeline-item:last-child::before {
    display: none;
}

.version-timeline-item::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 20px;
    bottom: -8px;
    width: 1px;
    border-left: 1px dotted #3a283a;
}

.version-timeline-node {
    position: absolute;
    left: 2px;
    top: 4px;
    width: 10px;
    height: 10px;
    border: 1px solid rgba(194, 80, 140, 0.5);
    background-color: #140d11;
    border-radius: 2px;
    transition: all 0.2s;
}

.version-timeline-item:hover .version-timeline-node {
    background-color: #c2508c;
    border-color: #c2508c;
}

.version-timeline-content {
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
}

.version-timeline-prompt {
    font-size: 11px;
    color: #d4b4c4;
    margin-bottom: 4px;
    line-height: 1.4;
}

.version-timeline-time {
    font-size: 9px;
    color: #7a5a6a;
}

#copyBtn:hover {
    transform: translateY(-1px) translateZ(0);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    background-color: rgba(42, 24, 42, 0.95) !important;
    border-color: rgba(78, 58, 78, 0.9) !important;
    color: #d4b4c4 !important;
}

#copyBtn:active {
    transform: translateY(0) translateZ(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* Resize handlers */
.resize-handle {
    position: absolute;
    background-color: #1a101a;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.15s;
}

.resize-handle:hover {
    opacity: 1;
    background-color: #2a182a;
}

.resize-handle-horizontal {
    cursor: col-resize;
    width: 2px;
    height: 100%;
    top: 0;
    right: 0;
}

.resize-handle-vertical {
    cursor: row-resize;
    height: 2px;
    width: 100%;
    bottom: 0;
    left: 0;
}

/* Button overrides */
.btn {
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 11px;
    padding: 4px 12px;
    border-radius: 2px;
    font-weight: 500;
    border: none;
    transition: all 0.15s;
}

.btn-success {
    background-color: #c2508c !important;
    color: #fff !important;
}

.btn-success:hover {
    background-color: #d65aa0 !important;
}

.btn-secondary {
    background-color: #1a101a !important;
    color: #9a7a8a !important;
    border: 1px solid #3a283a !important;
}

.btn-secondary:hover {
    background-color: #2a182a !important;
    color: #d4b4c4 !important;
}

.btn-sm {
    padding: 3px 10px;
    font-size: 10px;
}

.btn-primary {
    background-color: #c2508c !important;
    border: 1px solid #d65aa0 !important;
    color: #fff !important;
}

.btn-primary:hover {
    background-color: #d65aa0 !important;
    border-color: #ef79a2 !important;
}

.btn-primary:focus {
    box-shadow: 0 0 0 2px rgba(194, 80, 140, 0.3) !important;
}

.console-toggle {
    background: none;
    border: none;
    color: #7a5a6a;
    padding: 2px 4px;
    cursor: pointer;
    font-size: 10px;
    transition: transform 0.2s ease;
}

.console-toggle:hover {
    color: #9a7a8a;
}

.console-wrapper.expanded .console-toggle {
    transform: rotate(180deg);
}

/* Modal overrides */
.modal-content {
    background-color: #140d11 !important;
    border: 1px solid #3a283a !important;
    border-radius: 2px;
}

.modal-header {
    border-bottom: 1px solid #2a182a !important;
    padding: 12px 16px;
}

.modal-title {
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 13px;
    font-weight: 500;
    color: #d4b4c4;
}

.modal-body {
    padding: 16px;
}

.modal-footer {
    border-top: 1px solid #2a182a !important;
    padding: 12px 16px;
}

.form-label {
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 11px;
    color: #9a7a8a;
    font-weight: 500;
}

.form-control {
    background-color: #140d11 !important;
    border: 1px solid #3a283a !important;
    color: #d4b4c4 !important;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 11px;
    padding: 6px 10px;
    border-radius: 2px;
}

.form-control:focus {
    background-color: #1a101a !important;
    border-color: #d65aa0 !important;
    box-shadow: 0 0 0 2px rgba(214, 90, 160, 0.3) !important;
}

.form-text {
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 10px;
    color: #7a5a6a;
}

.form-check-label {
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 11px;
    color: #d4b4c4;
}

.form-check-input {
    width: 40px;
    height: 20px;
    background-color: #2a182a !important;
    border: 1px solid #3a283a !important;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%239a7a8a'/%3e%3c/svg%3e") !important;
}

.form-check-input:checked {
    background-color: #c2508c !important;
    border-color: #d65aa0 !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='white'/%3e%3c/svg%3e") !important;
}

.form-check-input:focus {
    box-shadow: 0 0 0 2px rgba(194, 80, 140, 0.3) !important;
    border-color: #d65aa0 !important;
}

.btn-close {
    filter: invert(0.6) sepia(1) saturate(0.3) hue-rotate(280deg) brightness(0.7);
    opacity: 1;
    width: 11px;
    height: 11px;
    background-size: 11px;
    outline: none !important;
    box-shadow: none !important;
}

.btn-close:hover,
.btn-close:focus,
.btn-close:focus-visible,
.btn-close:active {
    filter: invert(0.9) sepia(0.2) saturate(0.3) hue-rotate(280deg) brightness(1);
    opacity: 1;
    outline: none !important;
    box-shadow: none !important;
}

.modal-backdrop {
    backdrop-filter: blur(4px);
    background-color: rgba(13, 8, 12, 0.7) !important;
}

/* Hide scrollbars but preserve scroll behavior */
body,
.main-container,
.editor-panel,
#codeEditor,
.CodeMirror-scroll,
#errorConsole,
.preview-panel {
    scrollbar-width: none;
}

body::-webkit-scrollbar,
.main-container::-webkit-scrollbar,
.editor-panel::-webkit-scrollbar,
#codeEditor::-webkit-scrollbar,
.CodeMirror-scroll::-webkit-scrollbar,
#errorConsole::-webkit-scrollbar,
.preview-panel::-webkit-scrollbar {
    display: none;
}