/* ===========================
   Editor Layout
   =========================== */

.editor-page {
  min-height: 100vh;
  /* Plain block layout. The body used to be `display:flex; flex-direction:column`
     with `height:100vh; overflow:hidden`, which worked when the footer didn't
     exist. The big shared footer now competes for vertical space and collapsed
     the workspace's flex-basis to 0. Block flow + an explicit workspace height
     fixes both layouts. */
}
.editor-page > .workspace {
  /* Subtracts: flat site nav (64px) + editor toolbar (56px) + console (~36px) +
     status bar (~32px) ≈ 188px. (Nav is now the 64px sticky bar, not the old
     96px floating pill.) */
  height: calc(100vh - 188px);
  min-height: 440px;
}

.editor-toolbar {
  flex: 0 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}

.editor-toolbar .brand { font-size: 16px; }

.title-input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  width: 280px;
  max-width: 40vw;
  transition: all var(--transition);
}
.title-input:hover { background: var(--bg-elev-2); }
.title-input:focus {
  outline: none;
  background: var(--bg-elev-2);
  border-color: var(--border-strong);
}

.toolbar-spacer { flex: 1; }

.toolbar-group {
  display: flex;
  gap: 4px;
  align-items: center;
  border-right: 1px solid var(--border);
  padding-right: 12px;
  margin-right: 4px;
}
.toolbar-group:last-child { border-right: none; padding-right: 0; margin-right: 0; }

.layout-toggle {
  display: flex;
  background: var(--bg-elev-2);
  border-radius: var(--radius-sm);
  padding: 2px;
  border: 1px solid var(--border);
}
.layout-toggle button {
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text-dim);
  border-radius: 4px;
  transition: all var(--transition);
}
.layout-toggle button.active {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ===========================
   Workspace Splitter
   =========================== */

.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.workspace.layout-horizontal { flex-direction: row; }
.workspace.layout-vertical { flex-direction: column; }

.panes {
  display: flex;
  background: var(--bg);
  overflow: hidden;
}

.workspace.layout-horizontal .panes {
  flex-direction: column;
  width: 50%;
  border-right: 1px solid var(--border);
}

.workspace.layout-vertical .panes {
  flex-direction: row;
  height: 50%;
  border-bottom: 1px solid var(--border);
}

.preview-wrap {
  flex: 1;
  background: white;
  position: relative;
  overflow: hidden;
}

.preview-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: white;
}

.preview-overlay {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  pointer-events: none;
}

.preview-overlay .badge {
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--font-mono);
  pointer-events: auto;
}

/* ===========================
   Pane (Editor)
   =========================== */

.pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.workspace.layout-vertical .panes .pane { border-bottom: none; border-right: 1px solid var(--border); }
.pane:last-child { border-bottom: none; border-right: none; }

.pane-header {
  flex: 0 0 auto;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}

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

.pane-header .lang::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.pane[data-lang="html"] .pane-header .lang::before { background: #ff5fa2; }
.pane[data-lang="css"] .pane-header .lang::before { background: #2dd4ff; }
.pane[data-lang="js"] .pane-header .lang::before { background: #f5a623; }

.pane-actions {
  display: flex;
  gap: 4px;
}

.pane-action {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 14px;
  transition: all var(--transition);
}
.pane-action:hover { background: var(--bg-elev); color: var(--text); }

.pane-body {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.pane.collapsed { flex: 0 0 36px; }
.pane.collapsed .pane-body { display: none; }

/* CodeMirror sizing */
.CodeMirror {
  height: 100% !important;
  font-family: var(--font-mono) !important;
  font-size: 13.5px;
  line-height: 1.55;
}

/* ===========================
   Console
   =========================== */

.console {
  flex: 0 0 auto;
  max-height: 30%;
  background: #0b0d12;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: max-height 200ms ease;
}
[data-theme="light"] .console { background: #1a1d29; }

.console.collapsed { max-height: 36px; }
.console.collapsed .console-body { display: none; }

.console-header {
  flex: 0 0 auto;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.console-count {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
}

.console-body {
  flex: 1;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: #d4d8e1;
}

.console-line {
  padding: 6px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex;
  gap: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.console-line .level {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  height: fit-content;
  margin-top: 1px;
}

.console-line.log .level { background: #1d2130; color: #9aa0b4; }
.console-line.info .level { background: rgba(45, 212, 255, 0.15); color: #2dd4ff; }
.console-line.warn .level { background: rgba(245, 166, 35, 0.18); color: #f5a623; }
.console-line.error .level { background: rgba(255, 84, 112, 0.18); color: #ff5470; }
.console-line.error { color: #ffaab5; }

/* ===========================
   Sidebar (Library / Settings)
   =========================== */

.editor-sidebar {
  position: fixed;
  top: var(--nv-h, 64px);   /* sit below the sticky site nav, not behind it */
  right: 0;
  bottom: 0;
  width: 360px;
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  z-index: 80;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 240ms ease;
}
.editor-sidebar.open { transform: translateX(0); }

.editor-sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.editor-sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.editor-sidebar h4 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
  margin-top: 20px;
}
.editor-sidebar h4:first-child { margin-top: 0; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  padding: 5px 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition);
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.lib-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.lib-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-family: var(--font-mono);
  word-break: break-all;
}

.lib-item .url { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.lib-item .del {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: var(--text-muted);
}
.lib-item .del:hover { background: rgba(255, 84, 112, 0.1); color: var(--danger); }

.preset-list {
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr 1fr;
}

.preset-btn {
  padding: 8px 10px;
  text-align: left;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-dim);
  transition: all var(--transition);
}
.preset-btn:hover { color: var(--text); border-color: var(--border-strong); }

/* ===========================
   Splitter Handle
   =========================== */

.splitter {
  flex: 0 0 4px;
  background: var(--border);
  cursor: col-resize;
  transition: background var(--transition);
  position: relative;
}
.splitter:hover, .splitter.dragging { background: var(--accent); }

.workspace.layout-vertical .splitter { cursor: row-resize; }

/* ===========================
   Status Bar
   =========================== */

.status-bar {
  flex: 0 0 auto;
  height: 28px;
  background: var(--bg-elev-2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  font-size: 11.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.status-item { display: flex; align-items: center; gap: 6px; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}
.status-dot.error { background: var(--danger); }
.status-dot.warn { background: var(--warning); }

/* ===========================
   Responsive Editor
   =========================== */

@media (max-width: 900px) {
  .editor-toolbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px 6px; }
  .toolbar-group { padding-right: 6px; margin-right: 0; border-right: none; }
  .toolbar-spacer { display: none; }
  .title-input { flex: 1 1 100%; width: 100%; max-width: 100%; order: 99; }
  .editor-toolbar .btn { min-height: 38px; }
  .layout-toggle button { min-height: 34px; padding: 7px 12px; }
  /* On narrow viewports the panes stack vertically. Let workspace grow to fit
     all 3 panes + preview instead of constraining to viewport height. */
  .editor-page > .workspace { height: auto; min-height: 0; overflow: visible; }
  .workspace.layout-horizontal,
  .workspace.layout-vertical { flex-direction: column; overflow: visible; }
  .workspace .panes { width: 100% !important; height: auto !important; border-right: none; border-bottom: 1px solid var(--border); }
  .workspace .panes .pane { min-height: 180px; flex: 0 0 auto; }
  .workspace .panes .pane .pane-body,
  .workspace .panes .pane .CodeMirror { min-height: 144px; }
  .workspace .preview-wrap { min-height: 260px; flex: 0 0 auto; }
  .editor-sidebar { width: 100%; }
}
