
/* Кнопка запуска в .material-sidebar */
 .open-editor-btn {
 display: inline-flex;
 align-items: center;
 gap: 6px;
 background: #007acc;
 color: #fff;
 border: none;
 padding: 10px 18px;
 border-radius: 6px;
 cursor: pointer;
 font-size: 14px;
 font-family: system-ui, sans-serif;
 font-weight: 600;
 margin: 10px 0;
 transition: background 0.2s, transform 0.1s;
 }
 .open-editor-btn:hover { background: #0062a3; }
 .open-editor-btn:active { transform: scale(0.97); }

 /* ---------- Модальное окно редактора ---------- */
 .code-editor-modal {
 --ce-bg: #1e1e1e;
 --ce-bg-2: #252526;
 --ce-bg-3: #2d2d2d;
 --ce-border: #333;
 --ce-text: #d4d4d4;
 --ce-text-dim: #a9a9a9;
 --ce-accent: #007acc;
 --ce-header-bg: #1e1e1e;
 --ce-header-fg: #ffffff;
 --ce-btn-bg: #3c3c3c;
 --ce-btn-bg-hover: #4a4a4a;
 --ce-btn-fg: #ffffff;
 --ce-gutter-fg: #6e7681;

 display: none;
 position: fixed;
 inset: 0;
 background: rgba(0,0,0,0.75);
 z-index: 99999;
 font-family: 'Consolas','Monaco',monospace;
 overscroll-behavior: contain;
 }

 .code-editor-modal[data-theme="light"] {
 --ce-bg: #ffffff;
 --ce-bg-2: #f3f3f3;
 --ce-bg-3: #e8e8e8;
 --ce-border: #d2d2d2;
 --ce-text: #1f1f1f;
 --ce-text-dim: #5a5a5a;
 --ce-accent: #0066cc;
 --ce-header-bg: #f3f3f3;
 --ce-header-fg: #222222;
 --ce-btn-bg: #e3e3e3;
 --ce-btn-bg-hover: #d5d5d5;
 --ce-btn-fg: #222222;
 --ce-gutter-fg: #a6a6a6;
 }

 .code-editor-modal.active { display: flex; flex-direction: column; }

 .modal-header {
 position: relative;
 display: flex;
 justify-content: space-between;
 align-items: center;
 padding: 10px 16px;
 background: var(--ce-header-bg);
 color: var(--ce-header-fg);
 border-bottom: 1px solid var(--ce-border);
 user-select: none;
 }
 .modal-header h3 { margin: 0; font-size: 15px; font-weight: 500; }

 .header-actions { display: flex; gap: 8px; align-items: center; }

 .modal-btn {
 border: none;
 padding: 6px 14px;
 border-radius: 4px;
 cursor: pointer;
 font-size: 13px;
 font-family: inherit;
 transition: background 0.2s;
 }
 .btn-minimize { background: var(--ce-btn-bg); color: var(--ce-btn-fg); }
 .btn-minimize:hover { background: var(--ce-btn-bg-hover); }
 .btn-theme { background: var(--ce-btn-bg); color: var(--ce-btn-fg); padding: 6px 10px; font-size: 14px; line-height: 1; }
 .btn-theme:hover { background: var(--ce-btn-bg-hover); }
 .btn-close { background: #dc3545; color: #fff; }
 .btn-close:hover { background: #c82333; }
 .btn-run { background: #28a745; color: #fff; }
 .btn-run:hover { background: #218838; }
 .btn-clear { background: var(--ce-btn-bg); color: var(--ce-btn-fg); }
 .btn-clear:hover { background: var(--ce-btn-bg-hover); }
 .btn-download { background: #5c6bc0; color: #fff; }
 .btn-download:hover { background: #4e5aab; }

 .modal-body {
 display: flex;
 flex: 1;
 overflow: hidden;
 }

 /* ============ Превью ============ */
 .modal-preview {
 flex: 1 1 0;
 min-width: 0;
 min-height: 0;
 background: #fff;
 position: relative;
 display: flex;
 flex-direction: column;
 overflow: hidden;
 }

 .preview-toolbar {
 flex: 0 0 auto;
 display: flex;
 align-items: center;
 gap: 6px;
 padding: 6px 10px;
 background: var(--ce-bg-2);
 border-bottom: 1px solid var(--ce-border);
 /* overflow-x: auto; */
 -webkit-overflow-scrolling: touch;
 position: relative;
 }

 .preview-device-select {
 border: 1px solid var(--ce-border);
 background: var(--ce-btn-bg);
 color: var(--ce-btn-fg);
 border-radius: 4px;
 padding: 4px 8px;
 font-size: 12px;
 font-family: inherit;
 cursor: pointer;
 max-width: 260px;
 }
 .preview-btn {
 border: 1px solid var(--ce-border);
 background: var(--ce-btn-bg);
 color: var(--ce-btn-fg);
 border-radius: 4px;
 padding: 4px 10px;
 font-size: 14px;
 cursor: pointer;
 line-height: 1;
 font-family: inherit;
 transition: background .15s, color .15s, border-color .15s;
 }
 .preview-btn:hover { background: var(--ce-btn-bg-hover); }
 .preview-btn.active {
 background: var(--ce-accent);
 border-color: var(--ce-accent);
 color: #fff;
 }

 .preview-size {
 margin-left: auto;
 padding-left: 10px;
 font-size: 11px;
 color: var(--ce-text-dim);
 white-space: nowrap;
 font-family: 'Consolas','Monaco',monospace;
 /* height: 400px; */
 /* position: absolute; */
 top: 100px;
 }

 .preview-stage {
 flex: 1 1 auto;
 min-height: 0;
 overflow: auto;
 background: var(--ce-bg);
 padding: 0;
 box-sizing: border-box;
 overscroll-behavior: contain;
 }
 .preview-stage.fixed-width,
 .preview-stage.fixed-height {
 padding: 12px;
 }
 .preview-stage iframe {
 display: block;
 width: 100%;
 height: 100%;
 border: none;
 background: var(--ce-bg);
 margin: 0 auto;
 box-shadow: 0 0 0 1px rgba(0,0,0,.08);
 transition: width .2s, height .2s;
 }
 .preview-stage.fixed-width iframe,
 .preview-stage.fixed-height iframe {
 box-shadow: 0 4px 20px rgba(0,0,0,.15), 0 0 0 1px rgba(0,0,0,.1);
 }

 /* Fullscreen превью */
 .code-editor-modal.preview-fs .modal-editors,
 .code-editor-modal.preview-fs .modal-resizer { display: none !important; }
 .code-editor-modal.preview-fs .modal-preview {
 flex: 1 1 auto !important;
 height: auto !important;
 }

 /* ---------- Панель внешних библиотек ---------- */
 .resources-panel {
 position: absolute;
 top: 100%;
 right: 8px;
 margin-top: 4px;
 background: var(--ce-bg-2);
 border: 1px solid var(--ce-border);
 border-radius: 8px;
 padding: 10px;
 min-width: 260px;
 box-shadow: 0 12px 32px rgba(0,0,0,.4);
 z-index: 200;
 font-family: system-ui, -apple-system, sans-serif;
 }
 .resources-panel[hidden] { display: none; }
 .resources-panel-title {
 font-size: 11px;
 text-transform: uppercase;
 letter-spacing: .5px;
 color: var(--ce-text-dim);
 margin-bottom: 6px;
 padding: 0 4px;
 }
 .resources-item {
 display: flex;
 align-items: flex-start;
 gap: 10px;
 padding: 8px 6px;
 border-radius: 5px;
 cursor: pointer;
 transition: background .15s;
 }
 .resources-item:hover { background: var(--ce-bg-3); }
 .resources-item input {
 margin: 3px 0 0 0;
 cursor: pointer;
 flex: 0 0 auto;
 }
 .resources-item span {
 display: flex;
 flex-direction: column;
 gap: 2px;
 min-width: 0;
 }
 .resources-item strong {
 font-size: 13px;
 color: var(--ce-text);
 font-weight: 500;
 }
 .resources-item small {
 font-size: 11px;
 color: var(--ce-text-dim);
 font-family: 'Consolas','Monaco',monospace;
 word-break: break-word;
 }
 .resources-panel-hint {
 margin-top: 8px;
 padding: 8px 6px 0;
 border-top: 1px solid var(--ce-border);
 font-size: 11px;
 color: var(--ce-text-dim);
 line-height: 1.4;
 }

 /* ============ Перегородка ============ */
 .modal-resizer {
 flex: 0 0 8px;
 position: relative;
 background: var(--ce-bg-2);
 border-left: 1px solid var(--ce-border);
 border-right: 1px solid var(--ce-border);
 cursor: col-resize;
 touch-action: none;
 transition: background .15s;
 z-index: 3;
 }
 .modal-resizer::before {
 content: '';
 position: absolute;
 top: 50%;
 left: 50%;
 transform: translate(-50%, -50%);
 width: 2px;
 height: 36px;
 border-radius: 2px;
 background: var(--ce-text-dim);
 opacity: .35;
 transition: opacity .15s, background .15s;
 }
 .modal-resizer:hover,
 .modal-resizer.dragging { background: var(--ce-accent); }
 .modal-resizer:hover::before,
 .modal-resizer.dragging::before { background: #fff; opacity: 1; }

 body.ce-resizing { user-select: none; }
 body.ce-resizing iframe { pointer-events: none; }

 /* ============ Редакторы ============ */
 .modal-editors {
 flex: 0 0 45%;
 min-width: 0;
 /* max-width: 85%; */
 display: flex;
 flex-direction: column;
 background: var(--ce-bg);
 }

 .editor-tabs {
 display: flex;
 background: var(--ce-bg-2);
 border-bottom: 1px solid var(--ce-border);
 align-items: stretch;
 }
 .editor-tab {
 padding: 10px 22px;
 color: var(--ce-text-dim);
 cursor: pointer;
 border: none;
 background: transparent;
 font-family: inherit;
 font-size: 13px;
 border-bottom: 2px solid transparent;
 }
 .editor-tab:hover { background: var(--ce-bg-3); }
 .editor-tab.active {
 color: var(--ce-text);
 border-bottom-color: var(--ce-accent);
 background: var(--ce-bg);
 }

 .editor-split-btn {
 margin-left: auto;
 padding: 0 14px;
 border: none;
 background: transparent;
 color: var(--ce-text-dim);
 cursor: pointer;
 font-size: 16px;
 border-bottom: 2px solid transparent;
 font-family: inherit;
 }
 .editor-split-btn:hover { background: var(--ce-bg-3); color: var(--ce-text); }
 .editor-split-btn.active {
 color: var(--ce-accent);
 border-bottom-color: var(--ce-accent);
 background: var(--ce-bg);
 }

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

 /* Split view */
 .code-editor-modal.split-view .editor-pane {
 display: flex !important;
 flex: 1 1 0;
 min-height: 0;
 border-bottom: 1px solid var(--ce-border);
 }
 .code-editor-modal.split-view .editor-pane:last-child { border-bottom: none; }

 .code-textarea {
 flex: 1;
 background: var(--ce-bg);
 color: var(--ce-text);
 border: none;
 padding: 12px;
 font-family: 'Consolas','Monaco',monospace;
 font-size: 13px;
 line-height: 1.6;
 resize: none;
 outline: none;
 tab-size: 4;
 white-space: pre;
 overflow: auto;
 }

 /* CodeMirror под тему */
 .code-editor-modal .editor-pane .CodeMirror {
 flex: 1 1 0;
 min-height: 0;
 height: auto;
 background: var(--ce-bg);
 color: var(--ce-text);
 font-family: 'Consolas','Monaco',monospace;
 font-size: 13px;
 line-height: 1.6;
 }
 .code-editor-modal .editor-pane .CodeMirror-gutters {
 background: var(--ce-bg);
 border-right: 1px solid var(--ce-border);
 }
 .code-editor-modal .editor-pane .CodeMirror-linenumber { color: var(--ce-gutter-fg); }

 /* ============ Список подсказок ============ */
 body .CodeMirror-hints {
 z-index: 2147483000 !important;
 margin: 0;
 padding: 5px;
 list-style: none;
 border-radius: 8px;
 border: 1px solid transparent;
 font-family: 'Consolas','Monaco',monospace;
 font-size: 13px;
 line-height: 1.5;
 min-width: 180px;
 max-height: 280px;
 overflow-y: auto;
 overflow-x: hidden;
 box-sizing: border-box;
 box-shadow: 0 12px 32px rgba(0,0,0,.55), 0 2px 6px rgba(0,0,0,.35);
 }
 body[data-ce-theme="dark"] .CodeMirror-hints {
 background: #252526;
 border-color: #4a4a4a;
 color: #d4d4d4;
 }
 body[data-ce-theme="light"] .CodeMirror-hints {
 background: #ffffff;
 border-color: #c9c9c9;
 color: #1f1f1f;
 box-shadow: 0 12px 32px rgba(0,0,0,.22), 0 2px 6px rgba(0,0,0,.12);
 }
 body .CodeMirror-hints li.CodeMirror-hint {
 padding: 4px 12px;
 border-radius: 5px;
 cursor: pointer;
 white-space: pre;
 color: inherit;
 overflow: hidden;
 text-overflow: ellipsis;
 }
 body[data-ce-theme="dark"] .CodeMirror-hints li.CodeMirror-hint:hover {
 background: #2f2f30;
 color: #ffffff;
 }
 body[data-ce-theme="dark"] .CodeMirror-hints li.CodeMirror-hint-active,
 body[data-ce-theme="dark"] .CodeMirror-hints li.CodeMirror-hint-active:hover {
 background: #094771;
 color: #ffffff;
 }
 body[data-ce-theme="light"] .CodeMirror-hints li.CodeMirror-hint:hover {
 background: #eef4fb;
 color: #000000;
 }
 body[data-ce-theme="light"] .CodeMirror-hints li.CodeMirror-hint-active,
 body[data-ce-theme="light"] .CodeMirror-hints li.CodeMirror-hint-active:hover {
 background: #cfe4fb;
 color: #000000;
 }
 body .CodeMirror-hints::-webkit-scrollbar { width: 8px; }
 body .CodeMirror-hints::-webkit-scrollbar-thumb {
 background: rgba(128,128,128,.5);
 border-radius: 4px;
 }
 body .CodeMirror-hints::-webkit-scrollbar-track { background: transparent; }

 /* ============ Свёрнутое состояние ============ */
 .code-editor-modal.minimized {
 inset: auto 20px 20px auto;
 width: auto;
 height: auto;
 background: var(--ce-bg);
 border-radius: 8px;
 box-shadow: 0 8px 24px rgba(0,0,0,0.5);
 overflow: hidden;
 }
 .code-editor-modal.minimized .modal-body,
 .code-editor-modal.minimized .modal-footer {
 display: none;
 }
 .code-editor-modal.minimized .modal-header {
 cursor: pointer;
 background: var(--ce-accent);
 color: #fff;
 }
 .code-editor-modal.minimized .modal-header h3::before {
 content: '▶ ';
 font-size: 11px;
 }

 .modal-footer {
 display: flex;
 justify-content: space-between;
 padding: 10px 16px;
 background: var(--ce-bg);
 border-top: 1px solid var(--ce-border);
 gap: 10px;
 }
 .modal-footer .left,
 .modal-footer .right { display: flex; gap: 8px; }

 /* Индикаторы */
 .update-indicator,
 .save-indicator {
 font-size: 11px;
 opacity: 0;
 transition: opacity 0.3s;
 align-self: center;
 }
 .update-indicator { color: #4ec9b0; }
 .save-indicator { color: #6bcb77; }
 .update-indicator.show,
 .save-indicator.show { opacity: 1; }

 /* ================================================================
 МОБИЛЬНАЯ АДАПТАЦИЯ
 ================================================================ */
 @media (max-width: 768px) {

 .code-editor-modal { background: var(--ce-bg); }

 .modal-header { padding: 8px 10px; gap: 6px; }
 .modal-header h3 {
 font-size: 13px;
 max-width: 40vw;
 white-space: nowrap;
 overflow: hidden;
 text-overflow: ellipsis;
 }
 .header-actions { gap: 4px; }
 .modal-btn {
 min-height: 40px;
 padding: 8px 12px;
 font-size: 14px;
 border-radius: 6px;
 }
 .btn-theme { padding: 8px 12px; font-size: 15px; }
 .update-indicator,
 .save-indicator { display: none; }

 .modal-body { flex-direction: column; }

 .modal-preview {
 flex: none;
 height: 38vh;
 height: 38dvh;
 min-height: 140px;
 border-bottom: 1px solid var(--ce-border);
 }

 .modal-editors {
 width: 100%;
 min-width: 0;
 flex: 1 1 auto;
 min-height: 0;
 border-left: none;
 }

 .modal-resizer {
 flex: 0 0 12px;
 border-left: none;
 border-right: none;
 border-top: 1px solid var(--ce-border);
 border-bottom: 1px solid var(--ce-border);
 cursor: row-resize;
 }
 .modal-resizer::before {
 width: 44px;
 height: 3px;
 border-radius: 2px;
 }

 .preview-toolbar { padding: 5px 8px; gap: 5px; }
 .preview-device-select { padding: 6px 8px; font-size: 13px; }
 .preview-btn { padding: 6px 12px; font-size: 15px; }
 .preview-size { display: none; }

 .resources-panel {
 right: 4px;
 left: 4px;
 min-width: 0;
 }

 .editor-tabs {
 overflow-x: auto;
 -webkit-overflow-scrolling: touch;
 width: 100%;
 }
 .editor-tab {
 flex: 1 1 0;
 min-width: 72px;
 min-height: 46px;
 padding: 12px 8px;
 font-size: 14px;
 text-align: center;
 }
 .editor-split-btn {
 padding: 0 12px;
 min-width: 44px;
 min-height: 46px;
 }

 .modal-footer {
 padding: 8px 10px;
 padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
 flex-wrap: wrap;
 gap: 8px;
 }
 .modal-footer .left,
 .modal-footer .right {
 flex: 1 1 auto;
 gap: 6px;
 }
 .modal-footer .right { justify-content: flex-end; }
 .modal-footer .modal-btn {
 flex: 1 1 auto;
 min-width: 110px;
 }

 .code-editor-modal.minimized {
 inset: auto 0 0 0;
 width: 100%;
 max-width: 100%;
 margin: 0;
 border-radius: 14px 14px 0 0;
 box-shadow: 0 -8px 28px rgba(0,0,0,.4);
 padding-bottom: env(safe-area-inset-bottom, 0px);
 }
 .code-editor-modal.minimized .modal-header {
 padding: 18px 16px 12px;
 border-radius: 14px 14px 0 0;
 background: var(--ce-accent);
 color: #fff;
 }
 .code-editor-modal.minimized .modal-header::before {
 content: '';
 position: absolute;
 top: 6px;
 left: 50%;
 transform: translateX(-50%);
 width: 42px;
 height: 4px;
 border-radius: 2px;
 background: rgba(255,255,255,.55);
 }
 .code-editor-modal.minimized .modal-header h3 {
 font-size: 14px;
 max-width: none;
 }
 .code-editor-modal.minimized .modal-header h3::before {
 content: '▲ ';
 font-size: 12px;
 }
 .code-editor-modal.minimized .modal-btn {
 min-height: 36px;
 padding: 6px 10px;
 font-size: 13px;
 }
 .code-editor-modal.minimized .btn-theme { display: none; }
 }

 @media (max-width: 380px) {
 .modal-header h3 { max-width: 32vw; font-size: 12px; }
 .modal-btn { padding: 7px 9px; font-size: 13px; }
 .modal-footer .modal-btn { min-width: 90px; }
 .editor-tab { min-width: 62px; font-size: 13px; }
 }

 @media (max-width: 900px) and (orientation: landscape) {
 .modal-preview { height: 32dvh; min-height: 100px; }
 }