/* Custom styles for DiaVinci - Tailwind CSS Compatible */

/* Dragging state for components */
.dragging {
    opacity: 0.6;
    transform: scale(0.95);
}

/* Canvas specific styles */
.canvas-container {
    position: relative;
}

#drawCanvas {
    border: 2px solid #e5e7eb;
    border-radius: 0.5rem;
    background: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
}

/* Transition drawing mode styles */
.transition-drawing-mode {
    border: 2px dashed #ff6b6b !important;
    background-color: rgba(255, 107, 107, 0.02) !important;
    box-shadow: 0 0 0 4px rgba(255, 107, 107, 0.1), 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
}

/* Custom scrollbar for project list */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Hover effects for interactive elements */
.option:hover {
    transform: translateY(-2px);
}

.project-item:hover {
    transform: translateY(-1px);
}

/* Component icons with SVG shapes */
.component-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.component-icon svg {
    width: 32px;
    height: 32px;
    transition: transform 0.2s ease;
}

.option:hover .component-icon svg {
    transform: scale(1.1);
}

/* Ensure dialogs and modals appear above everything */
.dialog-overlay {
    z-index: 9999;
}

/* Floating action buttons */
button[id$="-btn"] {
    position: relative;
    z-index: 10;
}

/* Canvas floating buttons */
button[style*="position: absolute"] {
    z-index: 100;
    transition: all 0.2s ease;
}

button[style*="position: absolute"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Input field styling for compatibility */
input[type="text"]:focus {
    outline: none;
}

/* Mobile specific adjustments */
@media (max-width: 768px) {
    .components-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .option {
        min-height: 80px;
    }
}

@media (max-width: 640px) {
    .components-grid {
        grid-template-columns: 1fr;
    }
    
    .canvas-container {
        margin: 0;
        padding: 8px;
    }
    
    #drawCanvas {
        min-height: 400px;
    }
}

/* Bottom navigation styles */
.bottom-nav {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-top: 1px solid #334155;
    position: sticky;
    bottom: 0;
    z-index: 50;
}

.bottom-nav-button {
    transition: all 0.2s ease;
}

.bottom-nav-button:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.bottom-nav-button:active {
    transform: translateY(0);
}

/* Remove button specific styles */
#remove-btn {
    white-space: nowrap !important;
    overflow: hidden !important;
}

#remove-btn.show {
    display: inline-flex !important;
}

#remove-btn.hide {
    display: none !important;
}

#remove-btn span {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* Project item delete button fix */
.project-item {
    position: relative;
}

.project-item:hover .delete-btn {
    opacity: 1;
}

.delete-btn {
    opacity: 0;
    transition: opacity 0.2s ease;
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fee2e2;
    color: #dc2626;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    z-index: 10;
}

.delete-btn:hover {
    background: #fecaca;
    color: #b91c1c;
}

/* Grid toggle button states */
.grid-off {
    color: #6b7280;
}

.grid-on {
    color: #2563eb;
    background-color: #dbeafe;
}

/* Rulers toggle button states */
.rulers-off {
    color: #6b7280;
}

.rulers-on {
    color: #059669;
    background-color: #d1fae5;
}

/* Grid overlay styles */
.grid-overlay {
    position: absolute;
    top: 12px;  /* Account for container padding (p-3 = 12px) */
    left: 12px; /* Account for container padding (p-3 = 12px) */
    pointer-events: none;
    z-index: 1;
}

/* Rulers overlay styles */
.rulers-overlay {
    position: absolute;
    pointer-events: none;
    z-index: 2;
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
}

.rulers-overlay.horizontal {
    top: 12px;  /* Account for container padding (p-3 = 12px) */
    left: 12px; /* Account for container padding (p-3 = 12px) */
    width: calc(100% - 24px); /* Subtract padding from both sides */
    height: 25px;
    border-bottom: 2px solid #374151;
}

.rulers-overlay.vertical {
    top: 12px;  /* Account for container padding (p-3 = 12px) */
    left: 12px; /* Account for container padding (p-3 = 12px) */
    width: 25px;
    height: calc(100% - 24px); /* Subtract padding from both sides */
    border-right: 2px solid #374151;
}

/* Smart guide lines */
.smart-guide {
    position: absolute;
    background-color: #3b82f6;
    pointer-events: none;
    z-index: 10;
}

.smart-guide.horizontal {
    height: 1px;
    width: 100%;
}

.smart-guide.vertical {
    width: 1px;
    height: 100%;
}

/* Snap indicator */
.snap-indicator {
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: #10b981;
    border-radius: 50%;
    pointer-events: none;
    z-index: 15;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 2px white;
}

/* Terminal Panel Styles */
.terminal-panel {
    height: 30vh;
    min-height: 200px;
    max-height: 90vh; /* Restore to 90vh for maximum space */
    transition: all 0.3s ease-in-out;
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    resize: vertical;
    overflow: hidden;
    box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column; /* Stack header, content, command line vertically */
    /* Use fixed positioning above bottom navigation */
    position: fixed;
    bottom: 60px; /* Leave space for bottom navigation (approximately 60px height) */
    left: 0;
    right: 0;
    z-index: 60; /* Higher than bottom-nav z-index: 50 */
}

.terminal-panel.hidden {
    height: 0 !important;
    min-height: 0 !important;
    opacity: 0;
    pointer-events: none;
    transform: translateY(100%); /* Slide down when hidden */
}

/* Resize handle styles */
.terminal-resize-handle {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.terminal-resize-handle:hover {
    height: 3px !important;
}

.terminal-resize-handle:active,
.terminal-panel.resizing .terminal-resize-handle {
    height: 3px !important;
    background-color: #3b82f6 !important;
}

.terminal-header {
    user-select: none;
    cursor: default;
    background-color: #e2e8f0;
    border-bottom: 1px solid #cbd5e1;
    flex-shrink: 0; /* Header has fixed height */
}

.terminal-content {
    background-color: #f8fafc;
    color: #1f2937;
    padding: 16px;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth; /* Smooth scrolling for better UX */
    flex: 1; /* Take remaining space between header and command line */
    min-height: 0; /* Allow shrinking */
}

#terminal-output {
    padding-bottom: 8px; /* Small padding at bottom of logs */
}

/* Terminal command line input styling */
.terminal-command-line {
    background: rgba(59, 130, 246, 0.08);
    border-top: 1px solid rgba(59, 130, 246, 0.2);
    flex-shrink: 0; /* Prevent shrinking */
    min-height: 40px; /* Further reduced from 48px for minimal height */
    padding: 6px 16px 8px 16px; /* Minimal padding for very compact design */
    box-sizing: border-box; /* Include padding in height calculation */
}

.terminal-command-line input {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
    color: #1f2937;
    width: 100%;
}

.terminal-command-line input:focus {
    outline: none;
    background: rgba(59, 130, 246, 0.15); /* Slightly more visible when focused */
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.3); /* Add subtle focus ring */
}

/* Make the command line more prominent when focused */
.terminal-command-line:focus-within {
    background: rgba(59, 130, 246, 0.12);
    border-top-color: rgba(59, 130, 246, 0.4);
}

.terminal-command-line input::placeholder {
    color: #6b7280;
}

/* Ensure command line is always visible and accessible */
.terminal-command-line {
    position: relative;
    z-index: 10; /* Higher than content */
    background: rgba(59, 130, 246, 0.08) !important; /* Force background */
}

/* Add visual separator to make command line more prominent */
.terminal-command-line::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.3), rgba(59, 130, 246, 0.6), rgba(59, 130, 246, 0.3));
}

.terminal-line {
    margin-bottom: 6px;
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.5;
    font-size: 13px;
}

.terminal-line.info {
    color: #1f2937;
}

.terminal-line.warning {
    color: #f59e0b;
    font-weight: 500;
}

.terminal-line.error {
    color: #dc2626;
    font-weight: 500;
}

.terminal-line.debug {
    color: #6b7280;
    font-style: italic;
}

.terminal-line.success {
    color: #059669;
    font-weight: 500;
}

.terminal-line.function {
    color: #7c3aed;
    font-weight: 500;
}

.terminal-line.canvas-drop {
    color: #059669;
    font-weight: 600;
    background-color: #f0fdf4;
    padding: 4px 8px;
    border-radius: 4px;
    border-left: 3px solid #10b981;
}

.terminal-line.text-control {
    color: #1d4ed8;
    font-weight: 600;
    background-color: #eff6ff;
    padding: 4px 8px;
    border-radius: 4px;
    border-left: 3px solid #3b82f6;
}

.terminal-line.element-move {
    color: #d97706;
    font-weight: 600;
    background-color: #fffbeb;
    padding: 4px 8px;
    border-radius: 4px;
    border-left: 3px solid #f59e0b;
}

.terminal-line.element-modify {
    color: #7c3aed;
    font-weight: 600;
    background-color: #faf5ff;
    padding: 4px 8px;
    border-radius: 4px;
    border-left: 3px solid #8b5cf6;
}

.terminal-timestamp {
    color: #9ca3af;
    font-size: 11px;
}

/* Remove focus outline from terminal toggle button */
#terminal-toggle-btn:focus {
    outline: none !important;
    box-shadow: none !important;
    border: none !important;
}

/* Bottom navigation layout fixes */
.bottom-nav {
    position: relative;
}

.bottom-nav > div {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
}

/* Ensure terminal button stays on the left */
#terminal-toggle-btn {
    margin-right: auto;
    flex-shrink: 0;
}

/* Ensure button group stays on the right */
.bottom-nav .flex-nowrap {
    margin-left: auto;
    flex-shrink: 0;
}

/* Terminal scrollbar */
.terminal-content::-webkit-scrollbar {
    width: 8px;
}

.terminal-content::-webkit-scrollbar-track {
    background: #333;
    border-radius: 4px;
}

.terminal-content::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

.terminal-content::-webkit-scrollbar-thumb:hover {
    background: #777;
}

/* Adjust main container when terminal is open */
.main-content.terminal-open {
    padding-bottom: 20vh;
    transition: padding-bottom 0.3s ease-in-out;
}

/* Animation for terminal toggle button */
#terminal-toggle-btn.active {
    background-color: #4b5563 !important;
    transform: scale(0.95);
}

/* Context menu styling for element information */
.context-menu-info {
    color: #6b7280 !important;
    font-weight: 500 !important;
    cursor: default !important;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace !important;
    font-size: 12px !important;
}

.context-menu-info:hover {
    background-color: #f3f4f6 !important;
}

.context-menu-separator {
    color: #d1d5db !important;
    cursor: default !important;
    text-align: center !important;
    font-size: 8px !important;
    padding: 2px 0 !important;
}

.context-menu-separator:hover {
    background-color: transparent !important;
}

/* Mobile responsive terminal adjustments */
@media (max-width: 768px) {
    .terminal-panel {
        /* Keep terminal above bottom navigation on mobile too */
        bottom: 70px; /* Slightly more space on mobile for larger bottom nav */
        max-height: 80vh; /* Restore to 80vh for mobile */
    }
    
    .terminal-command-line {
        min-height: 44px; /* Slightly bigger on mobile but still compact */
        padding: 8px 16px 10px 16px; /* Minimal padding on mobile too */
    }
}

/* iOS Safari specific adjustments for bottom safe area */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .terminal-panel {
        padding-bottom: env(safe-area-inset-bottom);
        /* Removed margin-bottom to prevent conflicts with fixed positioning */
    }
}

/* Language Switcher Dropdown Styles */
.language-switcher-dropdown {
    position: relative;
}

.language-dropdown-trigger {
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.language-dropdown-trigger:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.language-dropdown-trigger:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.language-dropdown-menu {
    position: absolute;
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    border: 1px solid #e5e7eb;
    overflow: hidden;
    z-index: 1000;
    animation: dropdownFadeIn 0.15s ease-out;
}

.language-dropdown-menu.hidden {
    display: none;
}

.language-option {
    border: none;
    background: none;
    cursor: pointer;
    user-select: none;
    text-align: left;
    transition: background-color 0.15s ease;
}

.language-option:hover {
    background-color: #f9fafb;
}

.language-option:active {
    background-color: #f3f4f6;
}

/* Language button text styles */
.language-dropdown-trigger #current-lang {
    color: white;
    font-weight: bold;
    font-size: 0.875rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Main button flag styles */
.language-dropdown-trigger #current-flag {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.flag-icon {
    display: inline-block;
    vertical-align: middle;
}

/* Square flags for dropdown items */
.square-flag {
    width: 24px;
    height: 18px;
    border-radius: 3px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Hide/show emoji or SVG flags based on support */
.no-emoji-flags .emoji-flag {
    display: none;
}

.no-emoji-flags .svg-flag {
    display: inline-flex !important;
}

.emoji-flag {
    display: inline-flex;
}

.svg-flag {
    display: none;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive adjustments for language switcher */
@media (max-width: 640px) {
    .language-dropdown-trigger {
        width: 40px;
        height: 40px;
    }
    
    .flag-icon {
        font-size: 16px;
    }
    
    .language-dropdown-menu {
        min-width: 140px;
    }
}

/* Editor and Modal Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes modalIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Code Editor Specific Styles */
.code-editor-container {
    position: relative;
    font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
}

.code-editor-container .syntax-highlight {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 1;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow: hidden;
}

.code-editor-container textarea {
    background: transparent;
    color: rgba(30, 41, 59, 0.8);
    caret-color: #3b82f6;
    z-index: 2;
    outline: none;
    border: none;
    resize: none;
    font-family: inherit;
    tab-size: 4;
}

.code-editor-container .line-numbers {
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
    color: #64748b;
    font-family: inherit;
    user-select: none;
    text-align: right;
    padding-right: 8px;
}

/* IntelliSense popup styling */
.intellisense-popup {
    position: absolute;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    font-family: 'Fira Code', 'Consolas', monospace;
    max-height: 200px;
    overflow-y: auto;
    animation: fadeIn 0.2s ease-out;
}

.intellisense-popup .item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.1s;
}

.intellisense-popup .item:hover,
.intellisense-popup .item.selected {
    background: #f8fafc;
}

.intellisense-popup .item:last-child {
    border-bottom: none;
}

.intellisense-popup .type-icon {
    font-size: 12px;
    width: 16px;
    text-align: center;
}

.intellisense-popup .suggestion-text {
    font-weight: 600;
    color: #1e293b;
    flex: 1;
}

.intellisense-popup .type-badge {
    background: #e2e8f0;
    color: #64748b;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
