/* Note Editor Styles */
.note-editor {
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--bg-primary);
}

/* Editor Header */
.editor-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    background-color: var(--bg-secondary);
}

.note-title {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 600;
    padding: var(--space-2);
    border-radius: var(--radius-md);
    transition: background-color 0.2s;
}

.note-title:focus {
    outline: none;
    background-color: var(--bg-tertiary);
}

.note-title::placeholder {
    color: var(--text-muted);
}

.editor-actions {
    display: flex;
    gap: var(--space-2);
}

/* Editor Toolbar */
.editor-toolbar {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-default);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-secondary);
    flex-wrap: wrap;
    gap: var(--space-2);
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 1;
}

.toolbar-center {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.toolbar-right {
    display: flex;
    gap: var(--space-4);
    align-items: center;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background-color: var(--border-default);
    margin: 0 var(--space-1);
}

.toolbar-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    min-width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.toolbar-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.toolbar-btn.active {
    background-color: var(--accent-secondary);
    color: white;
}

.toolbar-btn svg {
    pointer-events: none;
}

/* Preview Toggle */
.preview-toggle {
    background-color: var(--accent-secondary) !important;
    color: white !important;
}

.preview-toggle.active {
    background-color: var(--accent-primary) !important;
}

/* Dropdown Styles */
.toolbar-dropdown {
    position: relative;
}

.dropdown-toggle {
    gap: var(--space-1);
}

.dropdown-arrow {
    margin-left: var(--space-1);
    transition: transform 0.2s;
}

.dropdown-toggle.active .dropdown-arrow {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    min-width: 120px;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s;
}

.dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-menu button {
    width: 100%;
    background: none;
    border: none;
    color: var(--text-primary);
    padding: var(--space-2) var(--space-3);
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 14px;
}

.dropdown-menu button:hover {
    background-color: var(--bg-hover);
}

.dropdown-menu button:first-child {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.dropdown-menu button:last-child {
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.word-count {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.save-status {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.save-status.saving {
    color: var(--accent-secondary);
}

.save-status.saved {
    color: var(--accent-primary);
}

.save-status.error {
    color: var(--accent-danger);
}

/* Editor Container */
.editor-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.editor-panes {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.editor-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 300px;
    position: relative;
}

.preview-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-left: 1px solid var(--border-default);
    background-color: var(--bg-primary);
    min-width: 300px;
}

.editor-panes.split-view .editor-pane {
    flex: 0 0 50%;
}

.editor-panes.split-view .preview-pane {
    flex: 0 0 50%;
}

.preview-content {
    flex: 1;
    padding: var(--space-4);
    overflow-y: auto;
    font-family: var(--font-markdown);
    line-height: 1.6;
    font-size: 16px;
    color: var(--text-primary);
}

.preview-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
}

.preview-placeholder p {
    margin-top: var(--space-2);
    font-size: 14px;
}

/* Resize Handle */
.resize-handle {
    width: 4px;
    background-color: var(--border-default);
    cursor: col-resize;
    position: relative;
    transition: background-color 0.2s;
}

.resize-handle:hover {
    background-color: var(--accent-secondary);
}

.resize-handle::before {
    content: '';
    position: absolute;
    top: 0;
    left: -2px;
    right: -2px;
    bottom: 0;
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .editor-header {
        padding: var(--space-3);
        flex-wrap: wrap;
        gap: var(--space-2);
    }

    .note-title {
        font-size: 16px;
        padding: var(--space-2);
    }

    .editor-actions {
        flex-shrink: 0;
    }

    .editor-toolbar {
        padding: var(--space-2) var(--space-3);
        flex-wrap: wrap;
        gap: var(--space-1);
    }

    .toolbar-left {
        flex: 1;
        min-width: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .toolbar-left::-webkit-scrollbar {
        display: none;
    }

    .toolbar-group {
        gap: var(--space-1);
        flex-shrink: 0;
    }

    .toolbar-btn {
        min-width: 36px;
        height: 36px;
        padding: var(--space-2);
    }

    .toolbar-divider {
        height: 24px;
        margin: 0 var(--space-1);
    }

    .toolbar-center {
        order: 3;
        width: 100%;
        justify-content: center;
        margin-top: var(--space-2);
        padding-top: var(--space-2);
        border-top: 1px solid var(--border-default);
    }

    .toolbar-right {
        gap: var(--space-2);
        font-size: 11px;
    }

    /* Mobile preview handling */
    .preview-pane {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
        background: var(--bg-primary);
        min-width: auto;
    }

    .editor-panes.split-view .editor-pane {
        display: none;
    }

    .editor-panes.split-view .preview-pane {
        flex: 1;
        border-left: none;
    }

    .preview-content {
        padding: var(--space-3);
        padding-top: 60px; /* Space for mobile header */
    }

    /* Mobile preview header */
    .preview-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-default);
        padding: var(--space-3);
        z-index: 1001;
        display: flex !important;
        align-items: center;
        justify-content: space-between;
    }

    .preview-title {
        font-size: 16px;
        font-weight: 600;
        color: var(--text-primary);
    }

    .preview-close-btn {
        background: none;
        border: none;
        color: var(--text-primary);
        font-size: 20px;
        cursor: pointer;
        padding: var(--space-1);
        border-radius: var(--radius-sm);
        display: flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
    }

    .preview-close-btn:hover {
        background: var(--bg-hover);
    }

    /* Dropdown adjustments for mobile */
    .dropdown-menu {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        min-width: 200px;
        max-height: 60vh;
        overflow-y: auto;
    }

    .dropdown-menu button {
        padding: var(--space-3);
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .editor-header {
        padding: var(--space-2);
    }

    .note-title {
        font-size: 14px;
    }

    .editor-toolbar {
        padding: var(--space-2);
    }

    .toolbar-btn {
        min-width: 32px;
        height: 32px;
    }

    .toolbar-right {
        font-size: 10px;
        gap: var(--space-1);
    }

    .word-count,
    .save-status {
        display: none; /* Hide on very small screens */
    }

    .preview-content {
        padding: var(--space-2);
        padding-top: 56px;
    }

    .preview-header {
        padding: var(--space-2);
    }

    .preview-title {
        font-size: 14px;
    }

    .dropdown-menu {
        min-width: 160px;
    }

    .dropdown-menu button {
        padding: var(--space-2);
        font-size: 14px;
    }
}

/* Touch improvements */
@media (pointer: coarse) {
    .toolbar-btn {
        min-width: 44px;
        height: 44px;
    }

    .resize-handle {
        width: 8px;
    }

    .resize-handle::before {
        left: -4px;
        right: -4px;
    }
}

/* GitHub-style Markdown Preview */
.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
    color: var(--text-primary);
    font-weight: 600;
    line-height: 1.25;
    margin-top: 24px;
    margin-bottom: 16px;
    font-family: var(--font-markdown);
}

.preview-content h1 {
    font-size: 2em;
    border-bottom: 1px solid var(--border-default);
    padding-bottom: 0.3em;
}

.preview-content h2 {
    font-size: 1.5em;
    border-bottom: 1px solid var(--border-default);
    padding-bottom: 0.3em;
}

.preview-content h3 {
    font-size: 1.25em;
}

.preview-content h4 {
    font-size: 1em;
}

.preview-content h5 {
    font-size: 0.875em;
}

.preview-content h6 {
    font-size: 0.85em;
    color: var(--text-secondary);
}

.preview-content p {
    margin-bottom: 16px;
    color: var(--text-primary);
}

.preview-content strong {
    font-weight: 600;
}

.preview-content em {
    font-style: italic;
}

.preview-content code {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 85%;
}

.preview-content pre {
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 16px;
    overflow-x: auto;
    margin-bottom: 16px;
}

.preview-content pre code {
    background: none;
    padding: 0;
    font-size: 85%;
    color: var(--text-primary);
}

.preview-content blockquote {
    border-left: 4px solid var(--border-default);
    padding-left: 16px;
    margin: 16px 0;
    color: var(--text-secondary);
}

.preview-content ul,
.preview-content ol {
    padding-left: 32px;
    margin-bottom: 16px;
}

.preview-content li {
    margin-bottom: 4px;
    color: var(--text-primary);
}

.preview-content table {
    border-collapse: collapse;
    border-spacing: 0;
    width: 100%;
    margin-bottom: 16px;
}

.preview-content table th,
.preview-content table td {
    border: 1px solid var(--border-default);
    padding: 6px 13px;
    text-align: left;
}

.preview-content table th {
    background-color: var(--bg-tertiary);
    font-weight: 600;
}

.preview-content table tr:nth-child(2n) {
    background-color: var(--bg-secondary);
}

.preview-content hr {
    border: none;
    border-top: 1px solid var(--border-default);
    margin: 24px 0;
}

.preview-content a {
    color: var(--accent-secondary);
    text-decoration: none;
}

.preview-content a:hover {
    text-decoration: underline;
}

.preview-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin: 8px 0;
}

.preview-content del {
    text-decoration: line-through;
    color: var(--text-muted);
}

#codeEditor {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.6;
    padding: var(--space-4);
    resize: none;
    outline: none;
}

#codeEditor::placeholder {
    color: var(--text-muted);
    line-height: 1.6;
}

/* CodeMirror Overrides */
.CodeMirror {
    height: 100% !important;
    font-family: var(--font-editor) !important;
    font-size: 14px !important;
    line-height: 1.45 !important;
    font-weight: 400 !important;
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    letter-spacing: 0.025em !important;
}

.CodeMirror-focused .CodeMirror-cursor {
    border-left: 2px solid var(--accent-secondary) !important;
}

.CodeMirror-selected {
    background-color: var(--bg-hover) !important;
}

.CodeMirror-line::selection,
.CodeMirror-line > span::selection,
.CodeMirror-line > span > span::selection {
    background-color: var(--bg-hover) !important;
}

.CodeMirror-gutters {
    background-color: var(--bg-secondary) !important;
    border-right: 1px solid var(--border-default) !important;
}

.CodeMirror-linenumber {
    color: var(--text-muted) !important;
    font-family: var(--font-mono) !important;
}

.CodeMirror-activeline-background {
    background-color: rgba(255, 255, 255, 0.04) !important;
}

/* Markdown Syntax Highlighting */
.cm-header {
    color: #79c0ff !important;
    font-weight: 600 !important;
}

.cm-quote {
    color: var(--text-secondary) !important;
    font-style: italic !important;
}

.cm-link {
    color: #58a6ff !important;
    text-decoration: underline !important;
}

.cm-url {
    color: #a5a5a5 !important;
}

.cm-strong {
    color: var(--text-primary) !important;
    font-weight: 600 !important;
}

.cm-em {
    color: var(--text-primary) !important;
    font-style: italic !important;
}

.cm-comment {
    color: #8b949e !important;
    background-color: var(--bg-tertiary) !important;
    padding: 2px 4px !important;
    border-radius: var(--radius-sm) !important;
    font-family: var(--font-mono) !important;
}

.cm-string {
    color: #a5c261 !important;
}

.cm-number {
    color: #d19a66 !important;
}

.cm-keyword {
    color: #c678dd !important;
}

.cm-def {
    color: #61dafb !important;
}

.cm-variable {
    color: #e06c75 !important;
}

.cm-tag {
    color: #e06c75 !important;
}

.cm-attribute {
    color: #d19a66 !important;
}

/* Code Block Styling */
.cm-meta {
    color: var(--text-muted) !important;
}

/* List styling */
.cm-formatting-list {
    color: #79c0ff !important;
    font-weight: 600 !important;
}

/* Task list styling */
.cm-formatting-task {
    color: #79c0ff !important;
}

/* Horizontal rule */
.cm-hr {
    color: var(--border-default) !important;
}

/* Focus mode - dimmed lines */
.CodeMirror-unfocused-line {
    opacity: 0.6 !important;
    transition: opacity 0.2s !important;
}

/* Editor loading state */
.editor-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-muted);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .editor-header {
        padding: var(--space-3);
        flex-wrap: wrap;
        gap: var(--space-2);
    }
    
    .note-title {
        font-size: 16px;
    }
    
    .editor-toolbar {
        padding: var(--space-2) var(--space-3);
        flex-wrap: wrap;
    }
    
    .toolbar-left {
        order: 2;
    }
    
    .toolbar-right {
        order: 1;
        width: 100%;
        justify-content: space-between;
    }
    
    #codeEditor,
    .CodeMirror {
        padding: var(--space-3) !important;
        font-size: 13px !important;
    }
}

/* Print styles */
@media print {
    .editor-header,
    .editor-toolbar,
    .sidebar {
        display: none !important;
    }
    
    .note-editor {
        background: white !important;
        color: black !important;
    }
    
    .CodeMirror {
        background: white !important;
        color: black !important;
    }
}

/* Note Type Indicators */
.note-type-indicator {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    padding: var(--space-1) var(--space-2);
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-muted);
}

/* Template-specific toolbar styling */
.plan-toolbar {
    border-left: 3px solid #4ade80;
}

.code-toolbar {
    border-left: 3px solid #60a5fa;
}

.credentials-toolbar {
    border-left: 3px solid #f59e0b;
}

.standard-toolbar {
    border-left: 3px solid #a855f7;
}

/* Security status indicator */
.security-status {
    animation: pulse 2s infinite;
}

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

/* Language dropdown specific styles */
.toolbar-dropdown .dropdown-menu[data-menu="languages"] {
    max-height: 300px;
    overflow-y: auto;
    min-width: 140px;
}

.toolbar-dropdown .dropdown-menu[data-menu="languages"] button {
    text-align: left;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: 13px;
}

/* Notification styles */
.notification {
    animation: slideInRight 0.3s ease;
}

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

/* Credential Form Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}

.credential-form-modal {
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    max-width: 600px;
    width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-5);
    flex: 1;
    overflow-y: auto;
}

.form-group {
    margin-bottom: var(--space-4);
}

.form-group label {
    display: block;
    margin-bottom: var(--space-2);
    font-weight: 500;
    color: var(--text-primary);
    font-size: 14px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font-ui);
    font-weight: 400;
    line-height: 1.5;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
}

.form-group select {
    font-family: var(--font-ui);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.password-input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-group input {
    padding-right: 80px;
}

.password-toggle,
.generate-btn {
    position: absolute;
    right: var(--space-1);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    font-size: 16px;
}

.password-toggle {
    right: 40px;
}

.generate-btn {
    right: var(--space-1);
}

.password-toggle:hover,
.generate-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-default);
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
    background: var(--bg-secondary);
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
}

.btn-primary:hover {
    background: var(--accent-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(88, 166, 255, 0.3);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
}

.btn-secondary:hover {
    background: var(--bg-primary);
    border-color: var(--border-hover);
}

/* Mobile responsive modal */
@media (max-width: 768px) {
    .credential-form-modal {
        width: 95vw;
        max-height: 95vh;
        margin: var(--space-2);
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: var(--space-3);
    }
    
    .modal-footer {
        flex-direction: column-reverse;
    }
    
    .btn-primary,
    .btn-secondary {
        width: 100%;
        padding: var(--space-4);
    }
}
