body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
body.is-resizing .sidebar, body.is-resizing .preview-panel { transition: none !important; }

.workspace { display: flex; flex: 1; overflow: hidden; width: 100%; transition: all 0.3s; }
.panels-wrapper { display: flex; flex: 1; min-width: 0; overflow-x: auto; overflow-y: hidden; position: relative; flex-direction: row; }

/* Panel Fullscreen Options */
body.panel-fullscreen-preview .sidebar, body.panel-fullscreen-preview .editor-panel, body.panel-fullscreen-preview .resizer { display: none !important; }
body.panel-fullscreen-preview .panels-wrapper { overflow: hidden !important; }
body.panel-fullscreen-preview .preview-panel { width: 100% !important; height: 100% !important; flex: 1 !important; min-width: 0 !important; }

body.panel-fullscreen-editor .sidebar, body.panel-fullscreen-editor .preview-panel, body.panel-fullscreen-editor .resizer { display: none !important; }
body.panel-fullscreen-editor .panels-wrapper { overflow: hidden !important; }
body.panel-fullscreen-editor .editor-panel { width: 100% !important; height: 100% !important; flex: 1 !important; min-width: 0 !important; }

body.true-fullscreen header { display: none !important; }
body.true-fullscreen .panel-bar { display: none !important; }
body.true-fullscreen #exitTrueFsBtn { display: flex !important; }

/* Stacked Layout Overrides */
body.stacked-layout .panels-wrapper { flex-direction: column; }
body.stacked-layout .editor-panel, body.stacked-layout .preview-panel { width: 100% !important; min-width: 0 !important; }
body.stacked-layout #resizerPreview { width: 100%; height: 4px; cursor: row-resize; }

/* Sidebar */
.sidebar { background-color: var(--bg-sidebar); display: flex; flex-direction: column; overflow-y: auto; width: 200px; max-width: 45vw; flex-shrink: 0; position: relative; transition: width 0.3s; }
.sidebar.sidebar-closed { width: 44px !important; }
.sidebar.sidebar-closed .sidebar-title-bar { justify-content: center; padding: 0; }
.sidebar.sidebar-closed #ide-project-title { display: none; }
.sidebar-tools-normal { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.sidebar-tools-closed { display: none; justify-content: center; align-items: center; width: 100%; }
.sidebar.sidebar-closed .sidebar-tools-normal { display: none; }
.sidebar.sidebar-closed .sidebar-tools-closed { display: flex; }
.sidebar.sidebar-closed .file-list { display: block; }
.sidebar.sidebar-closed .tree-row { justify-content: center; padding: 0.45rem 0 !important; border-right: 3px solid transparent; }
.sidebar.sidebar-closed .node-meta { flex: none; width: auto; gap: 0; justify-content: center; margin: 0; padding: 0 !important; }
.sidebar.sidebar-closed .node-meta span { display: none; }
.sidebar.sidebar-closed .folder-toggle-zone { flex: none; width: auto; gap: 0; justify-content: center; padding: 0 !important; }
.sidebar.sidebar-closed .folder-arrow { display: none !important; }
.sidebar.sidebar-closed .folder-toggle-zone + .node-meta { display: none; }
.sidebar.sidebar-closed .indent-guide-line { left: 0 !important; width: 2px; }
.sidebar.sidebar-closed .node-actions { display: none !important; }

.sidebar-header { display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-title-bar, .panel-bar { height: 44px; min-height: 44px; max-height: 44px; box-sizing: border-box; display: flex; justify-content: space-between; align-items: center; padding: 0 0.5rem 0 1rem; border-bottom: 1px solid var(--border-color); flex-shrink: 0; flex-wrap: nowrap; position: relative; overflow: hidden; }
.sidebar-title-bar span { font-size: 0.85rem; font-weight: 600; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default; }
.sidebar-tools { display: flex; justify-content: space-between; align-items: center; padding: 0 0.5rem; background: rgba(0,0,0,0.1); border-bottom: 1px solid var(--border-color); height: 44px; min-height: 44px; flex-shrink: 0; box-sizing: border-box; }
.file-list { flex: 1; padding: 0 0 0.5rem 0; overflow-y: auto; position: relative; }
.tree-row { position: relative; display: flex; align-items: center; justify-content: space-between; min-height: 36px; padding: 0.45rem 0.5rem; color: var(--text-muted); cursor: pointer; font-size: 0.85rem; outline: none; border-left: 3px solid transparent; transition: background 0.1s; }
.tree-row:hover, .tree-row:focus-visible { background-color: rgba(255, 255, 255, 0.05); color: var(--text-main); }
.tree-row:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }
.tree-row.active-folder { background-color: rgba(255, 255, 255, 0.08); color: var(--text-main); }
.tree-row.active-file { background-color: rgba(59, 130, 246, 0.12); color: var(--text-main); border-left-color: var(--accent); }
.tree-row.folder-row { padding-left: calc(var(--node-depth) * 16px + 12px); }
.folder-toggle-zone { padding-left: 0; display:flex; align-items:center; gap:4px; align-self:stretch; cursor:pointer; padding-right:6px; }
.tree-row.file-row { padding-left: calc(var(--node-depth) * 16px + 30px); }
.indent-guide-line { position: absolute; top: 0; bottom: 0; width: 1px; background-color: rgba(255, 255, 255, 0.08); pointer-events: none; z-index: 0; left: calc(var(--line-depth) * 16px + 22px); }
.node-meta, .folder-toggle-zone, .node-actions { position: relative; z-index: 2; }
.node-meta { display: flex; align-items: center; gap: 0.4rem; overflow: hidden; white-space: nowrap; flex: 1; }
.node-meta i, .node-meta svg { flex-shrink: 0; }
.node-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-actions { display: flex; align-items: center; justify-content: center; opacity: 0.4; transition: opacity 0.1s; flex-shrink: 0; }
.tree-row:hover .node-actions, .tree-row:focus-visible .node-actions, .tree-row.menu-open .node-actions { opacity: 1; }
.row-action-btn { background: transparent; border: none; color: inherit; cursor: pointer; outline: none; padding: 0; border-radius: 3px; width: 22px; height: 22px; display: flex; justify-content: center; align-items: center;}
.row-action-btn:hover, .row-action-btn:focus-visible, .row-action-btn.active { color: var(--text-main); background: rgba(255,255,255,0.15); }

/* Context Menus */
.context-menu { position: absolute; background: var(--bg-sidebar); border: 1px solid var(--border-color); border-radius: 0.375rem; box-shadow: 0 10px 25px rgba(0,0,0,0.5); display: none; flex-direction: column; z-index: 9999; padding: 0.25rem; min-width: 120px; }
.context-menu.fixed { position: fixed; }
.context-menu.show { display: flex; }
.context-menu button { background: transparent; border: none; color: var(--text-main); padding: 0.4rem 0.6rem; text-align: left; cursor: pointer; border-radius: 0.25rem; display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; font-family: inherit; transition: background 0.1s; }
.context-menu button:hover { background: rgba(255,255,255,0.1); }
.context-menu button.danger { color: #fca5a5; }
.context-menu button.danger:hover { background: rgba(239, 68, 68, 0.15); color: #f87171; }

.resizer { width: 4px; background-color: var(--border-color); cursor: col-resize; position: relative; z-index: 5; flex-shrink: 0; transition: background-color 0.15s; }
.resizer:hover, .resizer.active { background-color: var(--accent); }
.sidebar.sidebar-closed + .resizer { pointer-events: none; background-color: var(--border-color); }

/* Panels (min-height: 0 prevents flex items from breaking container dimensions) */
.editor-panel { background-color: var(--bg-editor); flex: 1 1 0; min-width: 134px; min-height: 0; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.preview-panel { background-color: #0b0f19; flex: 0 0 45%; min-width: 134px; min-height: 0; display: flex; flex-direction: column; container-type: inline-size; container-name: preview; position: relative; }

/* Force nowrap so buttons never flow to a second line and cause scrollbar pushing */
.panel-bar .header-actions { gap: 0.25rem; flex-shrink: 0; flex-wrap: nowrap; }

.panel-title { font-size: 0.85rem; font-weight: 500; color: var(--text-muted); display: flex; align-items: center; gap: 0.5rem; white-space: nowrap; flex: 1; min-width: 0; overflow: hidden; }

/* Force SVGs to never shrink, maintain native size */
.panel-title svg { flex-shrink: 0; display: block; min-width: 16px; min-height: 16px; }
.panel-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }

/* Dynamic Hiding for Toolbar */
@container preview (max-width: 475px) {
    .device-controls { display: none !important; }
}
@container preview (max-width: 260px) {
    .preview-toggles { display: none !important; }
}

/* Editor Specific */
.editor-container { display: flex; flex: 1; overflow: hidden; position: relative; background: var(--bg-editor); }
.code-typography, .code-typography *, code[class*="language-"], pre[class*="language-"] { font-family: ui-monospace, SFMono-Regular, "Consolas", "Courier New", monospace !important; font-size: 14px !important; line-height: 21px !important; letter-spacing: normal !important; word-spacing: normal !important; text-rendering: auto !important; font-weight: 400 !important; font-style: normal !important; font-variant-ligatures: none !important; -webkit-font-smoothing: antialiased !important; tab-size: 4 !important; -moz-tab-size: 4 !important; }
.editor-gutter { width: 55px; min-width: 55px; flex-shrink: 0; background: var(--bg-editor); color: #4b5563; text-align: right; padding: 16px 14px 30vh 0; overflow: hidden; user-select: none; z-index: 3; }
.editor-gutter div { height: 21px !important; line-height: 21px !important; box-sizing: border-box !important; opacity: 0.6; }
.editor-gutter .active-num { color: #e2e8f0; font-weight: bold; opacity: 1; }
.editor-stack { position: relative; flex: 1; overflow: hidden; margin-left: 4px; }
.sync-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; margin: 0 !important; padding: 16px 16px 30vh 0 !important; border: none !important; background: transparent !important; white-space: pre !important; word-wrap: normal !important; overflow-wrap: normal !important; box-sizing: border-box !important; text-shadow: none !important; outline: none !important; }
#indentGuides { pointer-events: none; z-index: 1; overflow: hidden; color: transparent; }
#codeEditor { color: transparent !important; caret-color: #f8fafc; resize: none; z-index: 3; overflow: auto; }
#codeEditor::selection { background: rgba(59, 130, 246, 0.3); color: transparent; }
pre[class*="language-"] { overflow: hidden !important; pointer-events: none; z-index: 2; }
code[class*="language-"] { display: block !important; min-width: 100%; padding: 0 !important; margin: 0 !important; }
.indent-guide { display: inline-block; box-sizing: border-box; border-left: 1px solid rgba(255, 255, 255, 0.08); height: 21px; vertical-align: top; width: 4ch; }

/* Preview Specific */
.preview-viewport-container { flex: 1; display: flex; align-items: flex-start; justify-content: flex-start; overflow: auto; background-color: #06090f; position: relative; padding: 0.5rem; -webkit-overflow-scrolling: touch; }
.preview-frame-wrapper { background-color: transparent; width: 100%; height: 100%; margin: auto; position: relative; flex-shrink: 0; border-radius: 4px; }
iframe { width: 100%; height: 100%; border: none; background-color: #0b0f19; pointer-events: auto; border-radius: inherit; box-shadow: 0 10px 40px -10px rgba(0,0,0,0.5); }
.resize-handle { position: absolute; z-index: 10; background: transparent; transition: background-color 0.15s; }
.resize-handle:hover, .resize-handle.active { background-color: rgba(59, 130, 246, 0.4); }
.rh-t { top: -5px; left: 0; width: 100%; height: 10px; cursor: ns-resize; }
.rh-b { bottom: -5px; left: 0; width: 100%; height: 10px; cursor: ns-resize; }
.rh-r { top: 0; right: -5px; width: 10px; height: 100%; cursor: ew-resize; }
.rh-l { top: 0; left: -5px; width: 10px; height: 100%; cursor: ew-resize; }
.rh-tl { top: -5px; left: -5px; width: 15px; height: 15px; cursor: nwse-resize; }
.rh-tr { top: -5px; right: -5px; width: 15px; height: 15px; cursor: nesw-resize; }
.rh-bl { bottom: -5px; left: -5px; width: 15px; height: 15px; cursor: nesw-resize; }
.rh-br { bottom: -5px; right: -5px; width: 15px; height: 15px; cursor: nwse-resize; }

.preview-toggles { display: flex; align-items: center; gap: 0.15rem; background: var(--bg-main); border: 1px solid var(--border-color); border-radius: 0.375rem; padding: 0 0.2rem; height: 28px; box-sizing: border-box; flex-shrink: 0; }
.preview-toggles .icon-btn { padding: 0; width: 22px; height: 22px; min-width: 22px; min-height: 22px; border-radius: 0.25rem; }
.device-controls { display: flex; align-items: center; gap: 0; background: var(--bg-main); border-radius: 0.375rem; border: 1px solid var(--border-color); flex-wrap: nowrap; height: 28px; box-sizing: border-box; flex-shrink: 0; }
.custom-select { position: relative; font-size: 0.75rem; width: 105px; min-width: 105px; max-width: 105px; border-right: 1px solid var(--border-color); padding: 0 0.25rem; user-select: none; height: 100%; box-sizing: border-box; display: flex; align-items: center; }
.select-trigger { display: flex; justify-content: space-between; align-items: center; cursor: pointer; color: var(--text-main); padding: 0 0.25rem; border-radius: 4px; width: 100%; height: 22px; overflow: hidden; }
.select-trigger span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; width: calc(100% - 14px); text-align: left; }
.select-trigger:hover { background: rgba(255,255,255,0.05); }
.select-options { position: fixed; background: var(--bg-sidebar); border: 1px solid var(--border-color); border-radius: 0.375rem; width: 202px; box-shadow: 0 10px 25px rgba(0,0,0,0.5); display: none; z-index: 1000; max-height: 300px; overflow-y: auto; padding: 0.25rem 0; }
.select-options.show { display: block; }
.select-group { color: var(--text-muted); background: rgba(0,0,0,0.15); padding: 0.5rem 0.75rem 0.2rem; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; margin-top: 0.2rem; }
.select-option { padding: 0.4rem 0.75rem; cursor: pointer; display: flex; justify-content: space-between; color: var(--text-main); transition: background 0.1s; }
.select-option:hover { background: var(--accent); color: white; }
.select-option .dim { color: var(--text-muted); font-family: monospace; font-size: 0.7rem; }
.select-option:hover .dim { color: rgba(255,255,255,0.7); }

.dim-inputs-wrapper { display: flex; align-items: center; justify-content: center; width: 105px; height: 100%; padding: 0 0.25rem; box-sizing: border-box; }
.dim-input { background: transparent; border: none; color: var(--text-muted); width: 35px; text-align: center; font-size: 0.75rem; font-family: monospace; outline: none; height: 100%; box-sizing: border-box; }
.dim-input:focus { color: white; }
.dim-sep { color: var(--border-color); font-size: 1.2rem; font-weight: 400; line-height: 1; width: 14px; text-align: center; display: inline-block; padding: 0; }

/* True Fullscreen Interactive Controls */
.true-fs-trigger { display: none; color: var(--accent); }
body.panel-fullscreen-editor .editor-panel .true-fs-trigger,
body.panel-fullscreen-preview .preview-panel .true-fs-trigger {
    display: flex;
}

/* Modals & Toasts */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.75); display: none; justify-content: center; align-items: center; z-index: 1000; backdrop-filter: blur(4px); opacity: 0; transition: opacity 0.2s ease-in-out; }
.modal-overlay.show { display: flex; opacity: 1; }
.modal-card { background: var(--bg-sidebar); border: 1px solid var(--border-color); border-radius: 0.5rem; width: 380px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); transform: scale(0.95); transition: transform 0.2s ease-in-out; display: flex; flex-direction: column; }
.modal-overlay.show .modal-card { transform: scale(1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border-color); }
.modal-header h3 { font-size: 1.1rem; display: flex; align-items: center; gap: 0.5rem; color: #fff; margin: 0; }
.modal-body { padding: 1.5rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 1.25rem 1.5rem; border-top: 1px solid var(--border-color); background: rgba(0,0,0,0.1); border-radius: 0 0 0.5rem 0.5rem; }
.modal-footer .btn { padding: 0.5rem 1.25rem; font-size: 0.9rem; }
.modal-card label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--text-muted); margin-bottom: 0.5rem; }
.modal-card input { width: 100%; background: var(--bg-main); border: 1px solid var(--border-color); color: white; padding: 0.6rem; border-radius: 0.375rem; outline: none; font-size: 0.9rem; margin-bottom: 1rem; }
.modal-card input:focus { border-color: var(--accent); }
.modal-card select { width: 100%; background: var(--bg-main); border: 1px solid var(--border-color); color: white; padding: 0.6rem; border-radius: 0.375rem; outline: none; font-size: 0.9rem; margin-bottom: 1rem; cursor: pointer; appearance: auto; }
.modal-card select:focus { border-color: var(--accent); }
.toast:empty { display: none; }
.toast { position: fixed; bottom: 1.5rem; right: 1.5rem; background: var(--bg-sidebar); border-left: 4px solid var(--success); padding: 1rem; border-radius: 0.375rem; display: flex; gap: 0.75rem; transform: translateY(150%); transition: transform 0.3s; z-index: 9999; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.3); }
.toast.show { transform: translateY(0); }
#exitTrueFsBtn { opacity: 1; transition: opacity 0.3s ease-in-out; }