/* Editor CSS - Editor layout, toolbar, title, and editor styling */

/* Note Editor */
.note-editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* Prevents overflow */
    gap: 0; /* Remove gap, handle spacing individually */
}

/* Button Container */
.editor-buttons {
    display: none !important;
}

/* Horizontal Toolbar Styling */
.editor-toolbar {
    display: flex;
    flex-direction: row;
    gap: 12px; /* Increase gap for better spacing */
    padding: 8px 20px; /* Increase horizontal padding */
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    backdrop-filter: blur(5px);
    width: 100%; /* Take full width of container */
    max-width: 100%; /* Ensure it doesn't exceed container */
    overflow: visible; /* Remove overflow scrolling */
    box-sizing: border-box;
}

.editor-toolbar button {
    flex-shrink: 0;
    width: 40px; /* Make buttons slightly larger */
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    background-color: transparent;
    color: var(--text-color);
    box-sizing: border-box;
}

.editor-toolbar button:hover {
    background-color: var(--border-color);
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.editor-toolbar button:active {
    transform: scale(0.95);
}

/* Specific button hover colors for better UX */
#saveButton:hover {
    background-color: rgba(76, 175, 80, 0.15);
    color: #4caf50;
}

#deleteButton:hover {
    background-color: rgba(244, 67, 54, 0.15);
    color: #f44336;
}

#clearButton:hover {
    background-color: rgba(255, 152, 0, 0.15);
    color: #ff9800;
}

#txtButton:hover, #mdButton:hover {
    background-color: rgba(33, 150, 243, 0.15);
    color: #2196f3;
}

#openFileButton:hover {
    background-color: rgba(156, 39, 176, 0.15);
    color: #9c27b0;
}

/* Tooltip styling for toolbar buttons */
.editor-toolbar button::after {
    content: attr(data-tooltip);
    position: absolute;
    top: -38px; /* Show above the button */
    left: 50%;
    transform: translateX(-50%);
    background-color: #333;
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 100;
}

.editor-toolbar button:hover::after {
    opacity: 1;
}

/* Title row as a single bar with inline toggle button */
.title-row {
    display: flex;
    align-items: stretch; /* Make children the same height */
    width: 100%;
    margin-bottom: 16px;
    gap: 0; /* Remove gap so input and button are flush */
    position: relative;
}

/* Note title input fills available space, no margin, rounded only on left */
#noteTitle {
    flex: 1;
    width: 100%;
    padding: 16px 20px;
    font-size: 20px;
    font-weight: 600;
    border-radius: 12px 0 0 12px; /* Only left corners rounded */
    border: 2px solid var(--border-color);
    background-color: var(--card-background);
    color: var(--text-color);
    box-sizing: border-box;
    transition: all 0.3s ease;
    line-height: 1.4;
    margin: 0; /* Remove margin */
    border-right: none; /* Remove right border to merge with button */
    height: 44px; /* Match button height */
}

#noteTitle:focus {
    outline: none;
    border-color: var(--button-background);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
    transform: translateY(-1px);
}

/* Preview/Edit toggle button flush with input, rounded only on right */
.mode-toggle-button {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    border: 2px solid var(--border-color);
    border-left: none; /* Remove left border to merge with input */
    border-radius: 0 12px 12px 0; /* Only right corners rounded */
    background-color: var(--button-background);
    color: white;
    box-shadow: none;
    transition: all 0.3s ease;
    position: relative;
}

.mode-toggle-button:hover {
    background-color: var(--button-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.mode-toggle-button:active {
    transform: translateY(0);
}

/* Tooltip for the toggle button - show above the button */
.mode-toggle-button::after {
    content: attr(data-tooltip);
    position: absolute;
    top: -38px; /* Place above the button */
    left: 50%;
    transform: translateX(-50%);
    background-color: #333;
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 100;
}

.mode-toggle-button:hover::after {
    opacity: 1;
}

/* Markdown Editor Styles - Fixed height with scrolling */
.markdown-editor-container {
    width: 100%;
    height: 490px; /* Changed from 480px to 490px */
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--card-background);
    margin-bottom: 16px;
    overflow: hidden; /* Hide overflow to let internal scrolling handle it */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    position: relative; /* For proper positioning */
}

.markdown-editor-container:focus-within {
    border-color: var(--button-background);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1), 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

/* CodeMirror editor fixes - constrained height with scrolling */
.cm-editor {
    height: 100% !important; /* Take full container height */
    max-height: 490px !important; /* Changed from 480px to 490px */
    font-size: 16px;
    border-radius: 6px;
    font-family: 'Roboto', sans-serif;
    overflow: auto; /* Enable scrolling */
}

.cm-editor.cm-focused {
    outline: none;
}

.cm-content {
    padding: 20px;
    font-family: 'Roboto', sans-serif;
    line-height: 1.6;
    font-size: 16px;
    min-height: calc(490px - 40px); /* Changed from 480px to 490px */
    max-height: none; /* Remove max-height constraint */
}

.cm-editor .cm-scroller {
    font-family: 'Roboto', sans-serif;
    overflow: auto !important; /* Ensure scrolling is enabled */
    max-height: 490px; /* Changed from 480px to 490px */
}

/* Simple editor (textarea) fixes for consistent scrolling */
#simpleEditor {
    width: 100% !important;
    height: 490px !important; /* Changed from 480px to 490px */
    max-height: 490px !important; /* Changed from 480px to 490px */
    font-family: 'Roboto', monospace !important;
    font-size: 16px !important;
    border: none !important;
    outline: none !important;
    padding: 20px !important;
    resize: none !important;
    background-color: var(--card-background) !important;
    color: var(--text-color) !important;
    box-sizing: border-box !important;
    overflow-y: auto !important; /* Enable vertical scrolling */
    overflow-x: auto !important; /* Enable horizontal scrolling if needed */
    line-height: 1.6 !important;
}

/* Dark mode editor styling */
body.dark-mode .cm-editor {
    background-color: var(--dark-card-background);
    color: var(--dark-text);
}

body.dark-mode .cm-content {
    background-color: var(--dark-card-background);
    color: var(--dark-text);
}

body.dark-mode .cm-focused {
    background-color: var(--dark-card-background);
}

body.dark-mode #simpleEditor {
    background-color: var(--dark-card-background) !important;
    color: var(--dark-text) !important;
}

/* Dark mode styles for toggle button */
body.dark-mode .mode-toggle-button {
    background-color: var(--dark-button-background);
}

body.dark-mode .mode-toggle-button:hover {
    background-color: var(--dark-button-hover);
}

body.dark-mode .mode-toggle-button::after {
    background-color: #555;
    color: #e0e0e0;
}

/* Custom scrollbar styling for better appearance */
.cm-scroller::-webkit-scrollbar,
#simpleEditor::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.cm-scroller::-webkit-scrollbar-track,
#simpleEditor::-webkit-scrollbar-track {
    background: var(--border-color);
    border-radius: 4px;
}

.cm-scroller::-webkit-scrollbar-thumb,
#simpleEditor::-webkit-scrollbar-thumb {
    background: var(--button-background);
    border-radius: 4px;
}

.cm-scroller::-webkit-scrollbar-thumb:hover,
#simpleEditor::-webkit-scrollbar-thumb:hover {
    background: var(--button-hover);
}

/* Dark mode scrollbar */
body.dark-mode .cm-scroller::-webkit-scrollbar-track,
body.dark-mode #simpleEditor::-webkit-scrollbar-track {
    background: var(--dark-border-color);
}

body.dark-mode .cm-scroller::-webkit-scrollbar-thumb,
body.dark-mode #simpleEditor::-webkit-scrollbar-thumb {
    background: var(--dark-button-background);
}

body.dark-mode .cm-scroller::-webkit-scrollbar-thumb:hover,
body.dark-mode #simpleEditor::-webkit-scrollbar-thumb:hover {
    background: var(--dark-button-hover);
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .editor-toolbar {
        gap: 10px;
        padding: 6px 15px;
    }
    
    .editor-toolbar button {
        width: 36px;
        height: 36px;
        font-size: 15px;
    }
}

@media (max-width: 768px) {
    .editor-toolbar {
        gap: 8px;
        padding: 6px 12px;
        width: auto; /* Let it size naturally on mobile */
        min-width: 300px; /* Ensure minimum usable width */
    }
    
    .editor-toolbar button {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    
    .title-row {
        gap: 8px;
    }
    
    .mode-toggle-button {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }
    
    #noteTitle {
        font-size: 18px;
        padding: 14px 16px;
        border-radius: 10px;
    }
    
    .markdown-editor-container {
        height: 300px; /* Smaller height on mobile */
    }
    
    .cm-editor {
        max-height: 300px !important;
    }
    
    .cm-scroller {
        max-height: 300px !important;
    }
    
    #simpleEditor {
        height: 300px !important;
        max-height: 300px !important;
    }
    
    .cm-content {
        min-height: calc(300px - 40px);
    }
}

@media (max-width: 480px) {
    .editor-toolbar {
        gap: 6px;
        padding: 5px 10px;
        min-width: 280px; /* Smaller minimum on very small screens */
    }
    
    .editor-toolbar button {
        width: 30px;
        height: 30px;
        font-size: 13px;
    }
    
    .title-row {
        gap: 6px;
    }
    
    .mode-toggle-button {
        width: 36px;
        height: 36px;
        font-size: 13px;
    }
    
    #noteTitle {
        font-size: 16px;
        padding: 12px 14px;
    }
    
    .markdown-editor-container {
        height: 250px; /* Even smaller on very small screens */
    }
    
    .cm-editor {
        max-height: 250px !important;
    }
    
    .cm-scroller {
        max-height: 250px !important;
    }
    
    #simpleEditor {
        height: 250px !important;
        max-height: 250px !important;
        font-size: 14px !important;
    }
    
    .cm-content {
        min-height: calc(250px - 40px);
        font-size: 14px;
    }
}