/* editor.css — Editor container, tools, CodeMirror integration */

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

.editor-header {
    background: var(--bg-elevated);
    padding: 4px 12px;
    border-bottom: 1px solid var(--border-default);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.editor-tools {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tool-btn {
    background: transparent;
    color: var(--text-primary);
    border: none;
    border-radius: var(--radius-sm);
    padding: 4px 6px;
    font-size: var(--font-size-lg);
    cursor: pointer;
    transition: background 0.1s;
}

.tool-btn:hover {
    background: var(--overlay-medium);
    color: var(--text-bright);
}

.tool-btn.active {
    background: var(--accent-primary);
    color: var(--on-accent);
}

.toolbar-overflow-btn { display: none; }

.toolbar-overflow-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 4px 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    min-width: 200px;
}

.toolbar-overflow-item {
    padding: 8px 16px;
    cursor: pointer;
    font-size: var(--font-size-base);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    font-family: var(--font-ui);
}
.toolbar-overflow-item:hover { background: var(--bg-active); }
.toolbar-overflow-item.active { color: var(--text-link); }
.toolbar-overflow-item:disabled { opacity: 0.4; cursor: default; }
.toolbar-overflow-item:disabled:hover { background: none; }
.toolbar-overflow-separator {
    height: 1px;
    background: var(--border-default);
    margin: 4px 0;
}

.file-info {
    font-size: var(--font-size-base);
    color: var(--text-primary);
}

/* Editor core */
.editor {
    flex: 1;
    background: var(--bg-base);
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font-mono);
    font-size: var(--font-size-lg);
    line-height: 1.5;
    color: var(--text-code);
    padding: 16px;
    padding-bottom: calc(100vh - 250px);
}

/* 不可視文字表示用のオーバーレイ */
.whitespace-overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: 20px;
    pointer-events: none;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    color: transparent !important;
    font-weight: normal !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    text-shadow: none !important;
    user-select: none;
    transform-origin: top left;
    white-space: pre-wrap !important;
    overflow: hidden;
    z-index: 10 !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    padding: 0;
    padding-bottom: calc(100vh - 250px);
    box-sizing: border-box;
    font-variant-ligatures: none;
}

.whitespace-char {
    color: rgba(100, 180, 255, 0.8) !important;
    font-weight: bold !important;
}

/* 行番号表示用のオーバーレイ */
.line-numbers-overlay {
    position: absolute;
    top: 20px;
    left: 0;
    bottom: 20px;
    width: 50px;
    pointer-events: none;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-muted);
    background: rgba(37, 37, 38, 0.95);
    border-right: 1px solid var(--border-default);
    user-select: none;
    z-index: 5;
    padding: 0 8px 0 5px;
    text-align: right;
    white-space: pre;
    overflow: hidden;
    box-sizing: border-box;
    padding-bottom: calc(100vh - 250px);
}

.line-numbers-overlay .line-number {
    height: 21px;
    line-height: 21px;
}

.editor-wrapper.with-line-numbers .editor {
    padding-left: 70px;
}

.editor-wrapper.with-line-numbers .whitespace-overlay {
    left: 70px;
}

.editor-wrapper.with-line-numbers .search-overlay {
    left: 70px;
}

/* エディタ内検索ハイライト */
.search-overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: 20px;
    z-index: 15;
    pointer-events: none;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    padding: 0;
    padding-bottom: calc(100vh - 250px);
    overflow: hidden;
    color: transparent;
}

.search-highlight {
    background: #ffff00 !important;
    color: #000000 !important;
    font-weight: bold !important;
    padding: 0 1px !important;
    border-radius: 2px !important;
}

.search-overlay.hidden {
    display: none !important;
    visibility: hidden !important;
}

.editor-container {
    position: relative;
}

.editor-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor.show-whitespace {
    position: relative;
    z-index: 2;
    background: rgba(30, 30, 30, 0.95);
}

.whitespace-overlay.hidden {
    display: none !important;
    visibility: hidden !important;
}

/* 矩形選択オーバーレイ */
.rectangle-selection-overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: 20px;
    pointer-events: none;
    z-index: 15;
}

.rectangle-selection {
    position: absolute;
    background: rgba(14, 99, 156, 0.3);
    border: 1px solid #0e639c;
    pointer-events: none;
}

.rectangle-cursor {
    position: absolute;
    width: 2px;
    background: var(--text-bright);
    animation: blink 1s infinite;
    pointer-events: none;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.rectangle-selection-overlay.hidden {
    display: none !important;
}

/* CodeMirror integration */
#editorMount {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#editorMount .cm-editor {
    height: 100%;
    flex: 1;
}

#editorMount .cm-scroller {
    overflow: auto;
    scrollbar-gutter: stable;
}

#editorMount .cm-scroller::-webkit-scrollbar,
.md-preview-panel::-webkit-scrollbar {
    width: 8px;
}
#editorMount .cm-scroller::-webkit-scrollbar-track,
.md-preview-panel::-webkit-scrollbar-track {
    background: transparent;
}
#editorMount .cm-scroller::-webkit-scrollbar-thumb,
.md-preview-panel::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 4px;
    transition: background 0.2s;
}
#editorMount .cm-scroller:hover::-webkit-scrollbar-thumb,
.md-preview-panel:hover::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb-hover);
}
#editorMount .cm-scroller::-webkit-scrollbar-thumb:hover,
.md-preview-panel::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-active);
}

/* Firefox: thin scrollbar */
#editorMount .cm-scroller,
.md-preview-panel,
.sidebar {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

/* Fast Scroll handle (mobile polyfill for scrollbar drag) */
.fast-scroll-handle {
    display: none;
}

/* CodeMirror search panel */
.cm-editor .cm-panels {
    background-color: var(--editor-panel-bg);
    color: var(--editor-text);
    border-top: 1px solid var(--editor-panel-input-border);
}
.cm-editor .cm-textfield {
    background-color: var(--editor-panel-input-bg);
    color: var(--editor-text);
    border: 1px solid var(--editor-panel-input-border);
    border-radius: var(--radius-sm);
    padding: 3px 6px;
    font-size: var(--font-size-base);
    outline: none;
}
.cm-editor .cm-textfield:focus {
    border-color: var(--accent-primary);
}
.cm-editor .cm-panel input[type="checkbox"] {
    accent-color: var(--accent-primary);
}
.cm-editor .cm-panel button {
    background-image: none !important;
    background-color: var(--accent-primary) !important;
    color: var(--on-accent) !important;
    border: none !important;
    border-radius: var(--radius-sm);
    padding: 4px 10px;
    cursor: pointer;
    font-size: var(--font-size-base);
}
.cm-editor .cm-panel button:hover {
    background-image: none !important;
    background-color: var(--accent-hover) !important;
}
.cm-editor .cm-panel label {
    color: var(--editor-text);
    font-size: var(--font-size-sm);
}

@media (max-width: 768px) {
    .editor-container {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        height: calc(100% - 40px);
        position: relative;
    }

    .cm-foldGutter {
        display: none !important;
    }

    .cm-gutters {
        border-right: none !important;
        background: transparent !important;
    }

    .editor {
        flex: 1;
        font-size: 16px;
        padding: 15px;
        padding-bottom: calc(100vh - 200px);
        line-height: 1.4;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        resize: none;
        margin-bottom: 5px;
    }

    .whitespace-overlay {
        top: 15px;
        left: 15px;
        right: 15px;
        bottom: 15px;
        padding: 0;
        padding-bottom: calc(100vh - 200px);
        max-height: calc(100% - 30px);
        font-size: 16px !important;
        line-height: 1.4 !important;
    }

    .line-numbers-overlay {
        top: 15px;
        bottom: 15px;
        width: 40px;
        font-size: 16px;
        line-height: 1.4;
        padding: 0 6px 0 3px;
        padding-bottom: calc(100vh - 200px);
    }

    .editor-wrapper.with-line-numbers .editor {
        padding-left: 55px;
    }

    .editor-wrapper.with-line-numbers .whitespace-overlay {
        left: 55px;
    }

    .editor-wrapper.with-line-numbers .search-overlay {
        left: 55px;
    }

    .editor-wrapper {
        flex: 1;
    }

    .fast-scroll-handle {
        display: block;
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 28px;
        z-index: 50;
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s;
    }

    .fast-scroll-handle.visible {
        opacity: 1;
        pointer-events: auto;
    }

    .fast-scroll-thumb {
        position: absolute;
        right: 4px;
        width: 4px;
        height: 40px;
        border-radius: 2px;
        background: var(--scrollbar-thumb);
        transition: width 0.15s, background 0.15s, right 0.15s;
    }

    .fast-scroll-handle.dragging .fast-scroll-thumb {
        width: 8px;
        right: 2px;
        background: var(--scrollbar-thumb-active);
    }
}

@media (max-width: 400px) {
    .editor {
        font-size: 14px;
        padding: 10px;
        padding-bottom: calc(100vh - 150px);
    }

    .whitespace-overlay {
        top: 10px;
        left: 10px;
        right: 10px;
        bottom: 10px;
        font-size: 14px;
        padding-bottom: calc(100vh - 150px);
    }

    .search-overlay {
        top: 10px;
        left: 10px;
        right: 10px;
        bottom: 10px;
        font-size: 14px;
        padding-bottom: calc(100vh - 150px);
    }

    .toolbar-secondary { display: none !important; }
    .toolbar-overflow-btn { display: inline-flex !important; }
}
