.editor-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  height: calc(100vh - 350px);
  min-height: 500px;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.editor-layout.preview-hidden {
  grid-template-columns: 1fr;
}

.editor-layout.preview-hidden #editor-preview-pane {
  display: none;
}

body.focus-mode .sidebar,
body.focus-mode .topbar {
  display: none;
}

body.focus-mode .view-container {
  padding: 12px;
}

body.focus-mode .panel-section {
  border: 0;
  box-shadow: none;
  padding: 10px;
}

.editor-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.editor-pane textarea {
  flex: 1;
  min-height: 0;
  height: 100%;
  font-family: Consolas, "Courier New", monospace;
  font-size: var(--editor-content-font-size, 15px);
  line-height: 1.6;
  resize: none;
}

.preview-wrapper {
  flex: 1;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-main);
  padding: 24px;
  overflow-y: auto;
  box-shadow: inset 0 2px 4px 0 rgb(0 0 0 / 0.02);
}

#preview {
  background: var(--surface);
  color: var(--text-main);
  font-size: var(--editor-preview-font-size, 16px);
}

#preview h1,
#preview h2,
#preview h3,
#preview h4,
#preview h5,
#preview h6,
#preview p,
#preview li,
#preview td,
#preview th,
#preview strong,
#preview em {
  color: var(--text-main);
}

#preview hr {
  border: 0;
  border-top: 1px solid var(--border);
}

#preview .katex,
#preview .katex-display {
  color: var(--text-main);
}

[data-theme="dark"] #preview {
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.02);
}

.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 10px 0;
}

#preview h1 { font-size: 2em; border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 16px; }
#preview h2 { font-size: 1.5em; margin-top: 24px; }
#preview h3 { font-size: 1.25em; margin-top: 20px; }

#preview p,
#preview ul,
#preview ol,
#preview blockquote {
  margin: 12px 0;
  line-height: 1.7;
}

#preview pre {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  overflow: auto;
}

#preview code {
  font-family: Consolas, "Courier New", monospace;
  background: var(--surface-hover);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

#preview pre code {
  background: transparent;
  padding: 0;
}

#preview blockquote {
  border-left: 4px solid var(--border);
  padding-left: 16px;
  color: var(--text-muted);
}

#preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}

#preview th,
#preview td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
}

#preview th {
  background: var(--surface-hover);
}

.wiki-link-btn {
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
  cursor: pointer;
}

.wiki-link-btn:hover {
  background: var(--surface-hover);
}

.preview-wrapper a[href^="#wikilink:"] {
  color: #1d4ed8;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.mermaid {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
  margin: 12px 0;
  overflow: auto;
}

.mermaid svg {
  max-width: 100%;
  height: auto;
}

.mermaid-error {
  white-space: pre-wrap;
  font-family: Consolas, "Courier New", monospace;
  color: var(--text-main);
}

.math-block {
  display: block;
  margin: 12px 0;
  overflow-x: auto;
}

.editor-links-row {
  position: relative;
  z-index: 3;
}

@media (max-width: 1080px) {
  .editor-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .editor-pane textarea {
    min-height: 320px;
  }
}
