*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
#root {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--app-bg, #e5e7eb);
  color: var(--text, #111827);
}

body {
  font-family: var(--font-ui, system-ui, sans-serif);
}

.app-root {
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: var(--text);
  background: var(--app-bg);
  font-family: var(--font-ui, system-ui, sans-serif);
}

/* Kindle 纸感：叠在纯色底上，避免覆盖 index 中的 background 简写 */
html[data-bg='22'] .app-root {
  background-color: var(--app-bg);
  background-image: repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(0, 0, 0, 0.014) 2px,
      rgba(0, 0, 0, 0.014) 3px
    ),
    radial-gradient(ellipse 120% 90% at 50% -10%, rgba(255, 255, 255, 0.55) 0%, transparent 55%),
    radial-gradient(ellipse 80% 60% at 100% 100%, rgba(0, 0, 0, 0.04) 0%, transparent 50%);
}

.no-api {
  padding: 24px;
}

.tab-bar {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 4px;
  padding: 6px 8px 0;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
  position: relative;
  z-index: 30;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.tab-bar::-webkit-scrollbar {
  height: 6px;
}

.tab-bar::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 50%, transparent);
  border-radius: 3px;
}

.tab {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: stretch;
  max-width: 320px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: inherit;
  overflow: hidden;
}

.tab.active {
  background: var(--app-bg);
  border-color: var(--border);
}

.tab-main {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 4px 6px 10px;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
  overflow: hidden;
}

.tab-close {
  flex: 0 0 28px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.tab-close:hover {
  color: var(--text);
  background: var(--hover);
}

.tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.tab.active .tab-title {
  font-size: 16px;
  font-weight: 700;
}

.tab .dot {
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
}

.toolbar {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
  position: relative;
  z-index: 120;
  isolation: isolate;
}

.toolbar button,
.sidebar-tabs button,
.path-row button,
.dir-item,
.outline-title,
.outline-level--branch {
  font: inherit;
  cursor: pointer;
}

.toolbar button {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
}

.toolbar button:hover {
  border-color: var(--accent);
}

.toolbar-tail {
  margin-left: auto;
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 8px;
  flex: 0 0 auto;
}

.bg-select {
  flex: 0 0 7.25rem;
  width: 7.25rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  margin-left: 0;
  font-size: 11px;
  color: var(--muted);
}

.bg-select select,
.bg-select .toolbar-mini-input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  position: relative;
  z-index: 130;
  font: inherit;
  font-size: 12px;
}

.bg-select .toolbar-mini-input {
  -moz-appearance: textfield;
}

.bg-select .toolbar-mini-input::-webkit-outer-spin-button,
.bg-select .toolbar-mini-input::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.main {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
  overflow: hidden;
}

.sidebar {
  flex: 0 0 auto;
  flex-shrink: 0;
  align-self: stretch;
  border-right: 1px solid var(--border);
  background: var(--panel-bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-resize {
  width: 5px;
  cursor: col-resize;
  flex: 0 0 5px;
  background: transparent;
}

.sidebar-resize:hover {
  background: var(--accent);
  opacity: 0.35;
}

.sidebar-reopen {
  flex: 0 0 22px;
  width: 22px;
  border: none;
  border-right: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
}

.sidebar-reopen:hover {
  background: var(--hover);
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.sidebar-tabs button {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}

.sidebar-tabs button.on {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.file-pane,
.outline {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.path-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.path-row-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

.path-row-actions button {
  width: 100%;
  min-width: 5.5rem;
  white-space: nowrap;
}

.path-row button {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
}

.path-row button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.path {
  flex: 1;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dir-error {
  padding: 8px;
  color: #c62828;
  font-size: 13px;
}

.dir-list,
.outline {
  list-style: none;
  margin: 0;
  padding: 4px 0;
}

.dir-item {
  width: 100%;
  text-align: left;
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
}

.outline-title,
.outline-level--branch {
  font: inherit;
  cursor: pointer;
}

.outline-entry {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 4px 8px 4px 6px;
  border-radius: 8px;
  transition: background 0.12s ease;
}

.outline-entry:hover {
  background: var(--hover);
}

.outline-entry--folded .outline-title {
  color: var(--muted);
}

.outline-level {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  font-weight: 700;
  line-height: 1;
  box-sizing: border-box;
}

.outline-level--leaf {
  cursor: default;
  border-style: solid;
  opacity: 0.92;
}

.outline-level--branch {
  position: relative;
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--btn-bg));
  color: var(--accent);
}

.outline-level--branch::after {
  content: '';
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--btn-bg);
}

.outline-level--branch.outline-level--collapsed {
  border-style: dashed;
  background: var(--btn-bg);
  color: var(--muted);
  border-color: var(--muted);
}

.outline-level--branch.outline-level--collapsed::after {
  background: transparent;
  border: 2px solid var(--muted);
  box-shadow: none;
}

.outline-level-num {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.outline-level--h1 {
  min-width: 34px;
  height: 34px;
  font-size: 15px;
  border-width: 2px;
}

.outline-level--h1 .outline-level-num {
  font-size: 15px;
}

.outline-level--h2 {
  min-width: 32px;
  height: 32px;
}

.outline-level--h3 {
  min-width: 30px;
  height: 28px;
  font-weight: 650;
}

.outline-level--h3 .outline-level-num {
  font-size: 13px;
}

.outline-level--h4,
.outline-level--h5,
.outline-level--h6 {
  min-width: 28px;
  height: 26px;
  font-weight: 600;
  color: var(--muted);
  border-color: color-mix(in srgb, var(--border) 90%, var(--muted));
}

.outline-level--h4 .outline-level-num,
.outline-level--h5 .outline-level-num,
.outline-level--h6 .outline-level-num {
  font-size: 12px;
}

.outline-title {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 6px 4px 6px 0;
  border: none;
  background: transparent;
  color: inherit;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
  word-break: break-word;
}

.outline-entry--h1 .outline-title {
  font-weight: 650;
  font-size: 14px;
}

.outline-entry--h2 .outline-title {
  font-weight: 600;
  font-size: 13px;
}

.outline-entry--h3 .outline-title {
  font-weight: 550;
  font-size: 13px;
}

.outline-entry--h4 .outline-title,
.outline-entry--h5 .outline-title,
.outline-entry--h6 .outline-title {
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
}

.outline-panel {
  padding: 6px 4px;
}

.outline-panel-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.outline-pane {
  padding: 0;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.outline-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.outline-toolbar-title {
  flex: 1;
  font-size: 12px;
  color: var(--muted);
}

.outline-toolbar-btn {
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.outline-toolbar-btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.outline-toolbar-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.outline-toolbar-meta {
  color: var(--muted);
  font-weight: 400;
}

.outline-tree--root {
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.outline-tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding: 2px 6px 2px 4px;
  border-radius: 6px;
}

.outline-tree-row:hover {
  background: var(--hover);
}

.outline-fold-btn {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--btn-bg);
  color: var(--accent);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  font: inherit;
}

.outline-fold-btn:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--btn-bg));
}

.outline-fold-btn.is-collapsed {
  color: var(--muted);
}

.outline-fold-spacer {
  flex: 0 0 22px;
  width: 22px;
}

.outline-tree-title {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.outline-tree-title:hover {
  color: var(--accent);
}

.outline-tree-title--h1 {
  font-weight: 700;
  font-size: 14px;
}

.outline-tree-title--h2 {
  font-weight: 650;
  font-size: 13.5px;
}

.outline-tree-title--h3 {
  font-weight: 600;
  font-size: 13px;
}

.outline-tree-title--h4,
.outline-tree-title--h5,
.outline-tree-title--h6 {
  font-weight: 500;
  font-size: 12.5px;
  color: var(--muted);
}

.outline-tree {
  list-style: none;
  margin: 0;
  padding: 4px 0 8px;
}

.outline-tree .outline-tree {
  margin: 2px 0 4px 6px;
  padding: 2px 0 2px 12px;
  border-left: 2px solid color-mix(in srgb, var(--accent) 22%, var(--border));
}

.outline-tree-node {
  margin: 0;
}

.outline-empty {
  margin: 12px 10px;
  font-size: 13px;
  color: var(--muted);
}

.outline-simple {
  list-style: none;
  margin: 0;
  padding: 6px 4px 10px;
}

.outline-simple-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.outline-simple-item:hover {
  background: var(--hover);
}

.outline-simple-item--h1 {
  font-weight: 700;
  font-size: 14px;
}

.outline-simple-item--h2 {
  font-weight: 650;
  font-size: 13.5px;
}

.outline-simple-item--h3 {
  font-weight: 600;
  font-size: 13px;
  color: color-mix(in srgb, var(--text) 88%, var(--muted));
}

.outline-simple-item--h4,
.outline-simple-item--h5,
.outline-simple-item--h6 {
  font-weight: 500;
  font-size: 12.5px;
  color: var(--muted);
}

.history-pane {
  padding-top: 4px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0 4px 8px;
}

.history-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.history-item:hover {
  background: var(--hover);
}

.history-item-name {
  font-weight: 600;
  font-size: 13px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-path {
  font-size: 11px;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-kind {
  flex: 0 0 24px;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  border-radius: 4px;
  padding: 3px 0;
  line-height: 1.1;
  color: #fff;
}

.entry-kind--dir {
  background: #4f46e5;
}

.entry-kind--file {
  background: #047857;
}

.entry-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.md-format-wrap {
  width: 100%;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
  position: relative;
  z-index: 25;
}

.md-format-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 8px;
  max-height: 120px;
  overflow-y: auto;
}

.md-format-bar button {
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.md-format-bar button:hover {
  border-color: var(--accent);
}

.dir-item[data-kind='dir'] {
  font-weight: 600;
}

.content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.editor-host {
  flex: 1;
  min-height: 0;
}

.editor-host .cm-editor {
  height: 100%;
}

.preview-outer {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12px 16px 16px;
}

.preview-shell {
  position: relative;
  flex: 0 1 auto;
  min-width: 0;
  width: 100%;
}

.preview-shell--tight {
  padding: 0 8px 8px;
}

.preview-resizer {
  position: absolute;
  top: 0;
  right: -10px;
  width: 16px;
  height: 100%;
  cursor: ew-resize;
  z-index: 5;
  border-radius: 4px;
  border: 2px solid var(--accent);
  background: var(--btn-bg);
  opacity: 0.95;
}

.preview-resizer:hover {
  opacity: 1;
  filter: brightness(1.05);
}

.preview-resizer::after {
  content: '‖';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--accent);
  pointer-events: none;
}

.preview {
  flex: 0 0 auto;
  overflow: visible;
  padding: 24px 32px 48px;
  width: 100%;
  font-size: 16px;
  line-height: var(--preview-line-height, 1.65);
  background: var(--preview-bg);
  color: var(--preview-text);
  border-radius: 8px;
  box-shadow: var(--preview-shadow);
  font-family: var(--font-preview, var(--font-ui, Georgia, serif));
}

.preview code {
  font-family: 'Cascadia Code', 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.9em;
  background: color-mix(in srgb, var(--code-bg) 85%, var(--border));
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

.preview .md-code-wrap {
  position: relative;
  margin: 1.1em 0;
  border: 1px solid color-mix(in srgb, var(--border) 90%, #000);
  border-radius: 6px;
  background: var(--code-bg);
  overflow: hidden;
}

.preview .md-code-wrap .md-code-lang {
  position: absolute;
  top: 0;
  right: 0;
  padding: 3px 10px;
  font-size: 11px;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.02em;
  pointer-events: none;
  user-select: none;
}

.preview .md-code-wrap pre.hljs {
  margin: 0;
  padding: 16px 18px;
  background: transparent;
  border-radius: 0;
  overflow-x: auto;
}

.preview .md-code-wrap pre.hljs code {
  font-family: 'Cascadia Code', 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.55;
  background: transparent;
  padding: 0;
}

.preview .md-diagram-wrap {
  margin: 1.5em 0;
  padding: 20px 16px 24px;
  background: var(--preview-bg);
  border: 1px solid color-mix(in srgb, var(--border) 85%, #000);
  border-radius: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
  contain: layout style;
}

.preview .md-diagram-wrap pre.mermaid {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  text-align: center;
}

.preview .md-diagram-wrap .mermaid-render-host {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 4rem;
  width: 100%;
  overflow: hidden;
}

.preview .md-diagram-wrap .mermaid-placeholder {
  min-height: 4rem;
  width: 100%;
}

.preview .md-diagram-wrap .mermaid-render-host svg {
  max-width: 100%;
  height: auto;
  display: block;
}

.preview .md-diagram-wrap .mermaid-error {
  margin: 0;
  padding: 12px;
  text-align: left;
  font-size: 12px;
  color: #b91c1c;
  background: color-mix(in srgb, #fecaca 40%, transparent);
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}

.hybrid-preview .preview .md-diagram-wrap {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.preview img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1em auto;
  border-radius: 6px;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.1);
}

.preview h1,
.preview h2,
.preview h3,
.preview h4,
.preview h5,
.preview h6 {
  font-family: inherit;
  color: inherit;
  margin-top: 1.25em;
  margin-bottom: 0.55em;
  line-height: 1.25;
}

.preview h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-top: 0.35em;
  padding-bottom: 0.2em;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.preview h2 {
  font-size: 1.55rem;
  font-weight: 650;
}

.preview h3 {
  font-size: 1.28rem;
  font-weight: 600;
}

.preview h4 {
  font-size: 1.12rem;
  font-weight: 600;
}

.preview h5 {
  font-size: 1.02rem;
  font-weight: 600;
}

.preview h6 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}

.preview pre {
  overflow: auto;
  padding: 12px;
  border-radius: 6px;
  background: var(--code-bg);
}

.preview .hljs,
.preview .hljs code {
  font-family: 'Cascadia Code', 'Consolas', 'Monaco', 'Courier New', monospace !important;
}

.preview a {
  color: #4183c4;
  text-decoration: none;
  cursor: pointer;
}

.preview a:hover {
  text-decoration: underline;
}

.preview a.md-internal-link {
  color: #4183c4;
  border-bottom: 1px dashed color-mix(in srgb, #4183c4 55%, transparent);
}

.preview a.md-internal-link:hover {
  border-bottom-style: solid;
}

.preview hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25em 0;
  height: 0;
  background: none;
}

.hybrid-row {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

.hybrid-editor {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.hybrid-sash {
  flex: 0 0 6px;
  cursor: col-resize;
  background: transparent;
}

.hybrid-sash:hover {
  background: var(--accent);
  opacity: 0.25;
}

.hybrid-preview {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  display: flex;
  justify-content: center;
}

.hybrid-preview-shell {
  position: relative;
}

.hybrid-line-pulse {
  position: absolute;
  left: 8px;
  right: 8px;
  height: 1.75em;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 2;
  border-radius: 6px;
  background: rgba(250, 204, 21, 0.42);
  box-shadow: 0 0 0 1px rgba(234, 179, 8, 0.35);
  animation: hybrid-line-pulse 1.35s ease-in-out forwards;
}

@keyframes hybrid-line-pulse {
  0%,
  100% {
    opacity: 0;
  }
  12%,
  30% {
    opacity: 1;
  }
  42% {
    opacity: 0;
  }
  54%,
  72% {
    opacity: 1;
  }
  84%,
  100% {
    opacity: 0;
  }
}

/* ── Search Bar ── */
.search-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
  z-index: 20;
}

.search-input {
  flex: 1;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.search-close-btn {
  flex: 0 0 auto;
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.search-close-btn:hover {
  color: var(--text);
}

/* ── Status Bar ── */
.status-bar {
  flex: 0 0 auto;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--panel-bg);
  text-align: center;
}

/* ── Save Toast ── */
.save-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  padding: 10px 20px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--panel-bg);
  color: var(--text);
  font-size: 14px;
  box-shadow: var(--preview-shadow);
  animation: save-toast-in 0.25s ease-out;
  max-width: min(90vw, 480px);
  text-align: center;
}

@keyframes save-toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ── Content Empty State ── */
.content-empty {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}

.content-empty-icon {
  font-size: 48px;
  line-height: 1;
}

.content-empty-hint {
  font-size: 13px;
  color: color-mix(in srgb, var(--muted) 80%, transparent);
}

.content-drop-zone {
  margin-top: 16px;
  padding: 24px 32px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.content-drop-zone-icon {
  font-size: 32px;
  line-height: 1;
}

/* ── Drag Over State ── */
.content-drag-over {
  outline: 3px dashed var(--accent);
  outline-offset: -3px;
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

/* ── Global Drop Overlay ── */
.global-drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.global-drop-overlay-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px 48px;
  border: 3px dashed var(--accent);
  border-radius: 16px;
  background: var(--panel-bg);
  box-shadow: var(--preview-shadow);
}

.global-drop-overlay-icon {
  font-size: 56px;
  line-height: 1;
}

.global-drop-overlay-text {
  font-size: 18px;
  color: var(--text);
  font-weight: 600;
}

/* ── Stats Panel ── */
.stats-resize {
  width: 5px;
  cursor: col-resize;
  flex: 0 0 5px;
  background: transparent;
}

.stats-resize:hover {
  background: var(--accent);
  opacity: 0.35;
}

.stats-panel {
  flex: 0 0 auto;
  align-self: stretch;
  border-left: 1px solid var(--border);
  background: var(--panel-bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.stats-panel-header {
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}

.stats-panel-header-icon {
  font-size: 16px;
  line-height: 1;
}

.stats-panel-body {
  padding: 8px 10px;
  flex: 1;
}

.stats-panel-section {
  margin-bottom: 14px;
}

.stats-panel-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.stats-panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.stats-panel-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--btn-bg);
}

.stats-panel-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stats-panel-label {
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  width: min(420px, calc(100% - 32px));
  background: var(--panel-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  box-shadow: var(--preview-shadow);
}

.modal-title {
  margin: 0 0 8px;
  font-size: 16px;
}

.modal-body {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--muted);
}

.modal-text-input {
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 16px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  font: inherit;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.modal-actions button {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
}

.modal-actions button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.modal-actions a.modal-link-btn {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font: inherit;
}

.modal-actions a.modal-link-btn:hover {
  filter: brightness(1.06);
}

.modal--wide {
  width: min(520px, calc(100% - 32px));
}

.web-notes-body {
  max-height: min(60vh, 420px);
  overflow-y: auto;
  line-height: 1.55;
  text-align: left;
}

.web-notes-body p {
  margin: 0 0 12px;
}

.web-notes-body p:last-child {
  margin-bottom: 0;
}

.web-notes-body code {
  font-size: 0.92em;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--btn-bg);
}

.web-notes-footer {
  margin-top: 4px !important;
  font-size: 13px;
  color: var(--muted);
}

.web-notes-list {
  margin: 0 0 12px;
  padding-left: 1.25em;
}

.web-notes-list li {
  margin-bottom: 6px;
}

.web-notes-muted {
  font-size: 13px;
  color: var(--muted);
}

.modal-hint {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

.modal-field {
  display: block;
  margin-bottom: 12px;
}

.modal-field .modal-text-input {
  margin-bottom: 0;
}

.modal-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.modal-row-btns {
  margin: -4px 0 12px;
}

.modal-row-btns button {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.modal-row-btns button:hover {
  border-color: var(--accent);
}

.color-picker-native {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.color-picker-spectrum {
  width: 56px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  background: var(--btn-bg);
}

.color-swatch-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

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

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 2px solid var(--border);
  padding: 0;
  cursor: pointer;
  box-sizing: border-box;
}

.color-swatch:hover {
  transform: scale(1.08);
}

.color-swatch.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.ctx-menu {
  position: fixed;
  z-index: 900;
  min-width: 120px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--preview-shadow);
  padding: 4px;
}

.ctx-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
}

.ctx-item.danger {
  color: #b91c1c;
}

.ctx-item:hover {
  background: var(--hover);
}

.preview .md-table-wrap {
  overflow-x: auto;
  margin: 1.25em 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}

.preview table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94em;
  line-height: 1.55;
}

.preview thead th {
  background: color-mix(in srgb, var(--accent) 10%, var(--preview-bg));
  font-weight: 650;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.preview tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  vertical-align: top;
}

.preview tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--text) 3%, transparent);
}

.preview tbody tr:hover td {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}

.preview tbody tr:last-child td {
  border-bottom: none;
}


.preview pre.mermaid:not(.md-diagram-wrap pre.mermaid) {
  margin: 1.5em 0;
  padding: 18px 16px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  text-align: center;
}

.preview-anchor-flash {
  animation: preview-anchor-flash 1.4s ease-out;
}

@keyframes preview-anchor-flash {
  0%,
  100% {
    background-color: transparent;
    box-shadow: none;
  }
  15%,
  40% {
    background-color: rgba(250, 204, 21, 0.35);
    box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.25);
    border-radius: 4px;
  }
  55% {
    background-color: transparent;
    box-shadow: none;
  }
  70% {
    background-color: rgba(250, 204, 21, 0.28);
    box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.2);
    border-radius: 4px;
  }
}
