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

[hidden] {
  display: none !important;
}

:root,
[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --btn-primary-text: #0d1117;
  --drop-bg: #1c2128;
  --preview-bg: #0d1117;
  --code-bg: #161b22;
  --blockquote-border: #3d444d;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --radius: 8px;
  --header-h: 56px;
}

[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f6f8fa;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #656d76;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --btn-primary-text: #ffffff;
  --drop-bg: #f6f8fa;
  --preview-bg: #ffffff;
  --code-bg: #f6f8fa;
  --blockquote-border: #d0d7de;
}

html {
  color-scheme: light dark;
}

[data-theme="dark"] {
  color-scheme: dark;
}

[data-theme="light"] {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 17, 23, 0.75);
  border: 3px dashed var(--accent);
  pointer-events: none;
}

.drop-overlay__text {
  margin: 0;
  padding: 0.75rem 1.25rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(15, 17, 23, 0.5);
}

.drop-overlay[hidden] {
  display: none;
}

/* Header */

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--header-h);
  padding: 0 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.header__logo {
  width: 22px;
  height: 22px;
  display: block;
  object-fit: contain;
}

.header__title {
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.header__actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.header__filename {
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4375rem 0.875rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn--primary {
  background: var(--accent);
  color: var(--btn-primary-text);
}

.btn--primary:hover {
  background: var(--accent-hover);
}

.btn--secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--drop-bg);
}

.btn--secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--icon {
  padding: 0.4375rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn--icon:hover {
  color: var(--text);
  background: var(--drop-bg);
}

.icon {
  width: 18px;
  height: 18px;
  display: block;
}

[data-theme="dark"] .icon--sun { display: block; }
[data-theme="dark"] .icon--moon { display: none; }
[data-theme="light"] .icon--sun { display: none; }
[data-theme="light"] .icon--moon { display: block; }

.icon--chevron {
  width: 14px;
  height: 14px;
  margin-left: 0.25rem;
}

.download-menu {
  position: relative;
}

.download-menu__panel {
  position: absolute;
  top: calc(100% + 0.375rem);
  right: 0;
  min-width: 11rem;
  padding: 0.375rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(15, 17, 23, 0.4);
  z-index: 20;
}

.download-menu__panel[hidden] {
  display: none;
}

.download-menu__item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
}

.download-menu__item:hover:not(:disabled) {
  background: var(--drop-bg);
}

.download-menu__item:disabled {
  opacity: 0.5;
  cursor: wait;
}

.download-menu__divider {
  height: 1px;
  margin: 0.375rem 0;
  background: var(--border);
}

.download-menu__item--danger {
  color: #ef4444;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.download-menu__item--danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.12);
  color: #dc2626;
}

.download-menu--open .icon--chevron {
  transform: rotate(180deg);
}

/* View Mode Toggle */

.view-toggle {
  display: inline-flex;
  align-items: center;
  padding: 0.1875rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.view-toggle[hidden] {
  display: none;
}

.view-toggle__btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.3125rem 0.625rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.view-toggle__btn:hover {
  color: var(--text);
}

.view-toggle__btn--active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .view-toggle__btn--active {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.icon--btn {
  width: 14px;
  height: 14px;
}

/* Main */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Dropzone */

.dropzone {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  margin: 1.5rem;
  border: 2px dashed var(--border);
  border-radius: calc(var(--radius) * 1.5);
  background: var(--drop-bg);
  transition: border-color 0.2s, background 0.2s;
}

.dropzone--active {
  border-color: var(--accent);
  background: rgba(88, 166, 255, 0.08);
}

[data-theme="light"] .dropzone--active {
  background: rgba(9, 105, 218, 0.08);
}

[data-theme="light"] .drop-overlay {
  background: rgba(255, 255, 255, 0.75);
}

[data-theme="light"] .drop-overlay__text {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .download-menu__panel {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.dropzone__content {
  text-align: center;
  max-width: 420px;
}

.dropzone__icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  color: var(--text-muted);
}

.dropzone__title {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 600;
}

.dropzone__text {
  margin: 0 0 0.75rem;
  color: var(--text-muted);
}

.dropzone__actions {
  margin: 1rem 0 1.25rem;
}

.dropzone__hint {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  opacity: 0.85;
}

/* Editor Container */

.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--preview-bg);
}

.editor-container[hidden] {
  display: none;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.5rem calc(10% + 1rem);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.toolbar-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.toolbar-group[hidden] {
  display: none !important;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-width: 32px;
  height: 32px;
  padding: 0 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.toolbar-btn:hover {
  color: var(--text);
  background: var(--drop-bg);
  border-color: var(--border);
}

.toolbar-btn:active {
  background: var(--bg);
}

.toolbar-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  background: transparent !important;
  border-color: transparent !important;
  color: var(--text-muted) !important;
}

.toolbar-btn--highlight {
  color: var(--accent);
}

.toolbar-btn--highlight:hover {
  color: var(--accent-hover);
  background: rgba(88, 166, 255, 0.1);
}

.toolbar-btn__label {
  font-size: 0.75rem;
  font-weight: 500;
}

.toolbar-divider {
  width: 1px;
  height: 18px;
  margin: 0 0.25rem;
  background: var(--border);
}

.editor-textarea {
  flex: 1;
  width: 100%;
  height: 100%;
  padding: 2rem calc(10% + 1rem);
  box-sizing: border-box;
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--preview-bg);
  border: none;
  outline: none;
  resize: none;
  tab-size: 2;
}

.editor-textarea::selection {
  background: rgba(88, 166, 255, 0.25);
}

[data-theme="light"] .editor-textarea::selection {
  background: rgba(9, 105, 218, 0.2);
}

/* Preview */

.preview {
  flex: 1;
  overflow: auto;
  padding: 2rem 0;
  background: var(--preview-bg);
  scroll-behavior: smooth;
}

/* Markdown body — GitHub-inspired */

.markdown-body {
  width: 80%;
  margin: 0 auto;
  font-size: 1rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: 1.5em;
  margin-bottom: 0.75em;
  font-weight: 600;
  line-height: 1.25;
}

.markdown-body h1 { font-size: 2em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1em; }

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table {
  margin-top: 0;
  margin-bottom: 1em;
}

.markdown-body a {
  color: var(--accent);
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body code {
  padding: 0.2em 0.4em;
  font-size: 0.875em;
  font-family: var(--font-mono);
  background: var(--code-bg);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.markdown-body pre {
  padding: 1rem;
  overflow: auto;
  font-size: 0.875rem;
  line-height: 1.45;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.markdown-body pre code {
  padding: 0;
  background: none;
  border: none;
  font-size: inherit;
}

.markdown-body pre.mermaid {
  padding: 1rem 0;
  overflow-x: auto;
  background: transparent;
  border: none;
  text-align: center;
}

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

.markdown-body blockquote {
  padding: 0 1em;
  color: var(--text-muted);
  border-left: 4px solid var(--blockquote-border);
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 2em;
}

.markdown-body li + li {
  margin-top: 0.25em;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.markdown-body th,
.markdown-body td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.markdown-body th {
  font-weight: 600;
  background: var(--surface);
}

.markdown-body tr:nth-child(even) {
  background: rgba(22, 27, 34, 0.35);
}

[data-theme="light"] .markdown-body tr:nth-child(even) {
  background: rgba(246, 248, 250, 0.9);
}

.markdown-body hr {
  height: 1px;
  margin: 1.5em 0;
  background: var(--border);
  border: 0;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* Footer */

.footer {
  padding: 0.75rem 1.25rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.footer p {
  margin: 0;
}

.footer__link {
  color: var(--accent);
  text-decoration: none;
}

.footer__link:hover {
  text-decoration: underline;
}

.footer__credit {
  margin: 0.375rem 0 0;
  font-size: 0.6875rem;
  opacity: 0.85;
}

/* Responsive */

@media (max-width: 600px) {
  .header__filename {
    display: none;
  }

  .markdown-body {
    width: 92%;
  }

  .dropzone {
    margin: 1rem;
    padding: 1.5rem;
  }

  .editor-textarea {
    padding: 1rem 4%;
  }
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  padding: 0.75rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
  z-index: 1000;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}

.toast--show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.markdown-body h1[id]:target,
.markdown-body h2[id]:target,
.markdown-body h3[id]:target,
.markdown-body h4[id]:target,
.markdown-body h5[id]:target,
.markdown-body h6[id]:target {
  animation: highlightTarget 1.5s ease-out;
}

@keyframes highlightTarget {
  0% {
    background-color: rgba(88, 166, 255, 0.25);
  }
  100% {
    background-color: transparent;
  }
}

/* Modal Dialog */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 17, 23, 0.75);
  backdrop-filter: blur(4px);
  padding: 1rem;
}

[data-theme="light"] .modal-overlay {
  background: rgba(0, 0, 0, 0.4);
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.25);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  animation: modalScale 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScale {
  from {
    opacity: 0;
    transform: scale(0.94);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.modal__close {
  padding: 0 0.375rem;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.15s;
}

.modal__close:hover {
  color: var(--text);
}

.modal__body {
  padding: 1.25rem;
  max-height: calc(85vh - 120px);
  overflow-y: auto;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
}

.form-control:focus {
  border-color: var(--accent);
}

.modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.625rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.modal__body .modal__footer {
  margin: 1.25rem -1.25rem -1.25rem -1.25rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.modal--wide {
  max-width: 760px;
}

.input-with-badge {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-badge .form-control {
  padding-right: 5rem;
}

.search-badge {
  position: absolute;
  right: 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  pointer-events: none;
}

.input-with-extension {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-extension .form-control {
  padding-right: 4.5rem;
}

.file-extension-badge {
  position: absolute;
  right: 0.625rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(99, 102, 241, 0.12);
  padding: 0.125rem 0.4rem;
  border-radius: 4px;
  pointer-events: none;
  user-select: none;
}

.form-help-text {
  display: block;
  margin-top: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.form-group--checkbox {
  margin-top: 0.75rem;
  margin-bottom: 0.5rem;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.modal__footer--space-between {
  justify-content: space-between;
}

.btn-group {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

/* File Management Modal */

.file-modal__actions {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.file-modal__action-btn {
  flex: 1 1 180px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  white-space: nowrap;
}

.file-modal__section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.file-modal__section-title {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.file-modal__count-badge {
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9999px;
  color: var(--text-muted);
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.file-list__empty {
  text-align: center;
  padding: 2.25rem 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.875rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, background 0.15s;
}

.file-item:hover {
  border-color: var(--accent);
}

.file-item--active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.08);
}

.file-item__info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
  cursor: pointer;
}

.file-item__icon {
  width: 22px;
  height: 22px;
  color: var(--accent);
  flex-shrink: 0;
}

.file-item__details {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 0.125rem;
}

.file-item__name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.file-item__name {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item__active-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(99, 102, 241, 0.15);
  padding: 0.0625rem 0.375rem;
  border-radius: 4px;
  text-transform: uppercase;
}

.file-item__dirty-badge {
  font-size: 0.6875rem;
  color: #f59e0b;
  font-weight: 600;
}

.file-item__meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.file-item__actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
  margin-left: 0.5rem;
}

.file-item__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) * 0.75);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.file-item__btn:hover {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

.file-item__btn--primary {
  color: var(--accent);
}

.file-item__btn--primary:hover {
  background: rgba(99, 102, 241, 0.12);
  color: var(--accent);
}

.file-item__btn--danger:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.2);
}

/* Git Integration Styles */

.form-row {
  display: flex;
  gap: 0.75rem;
}

.form-group--flex-1 {
  flex: 1;
  min-width: 0;
}

.form-group--flex-2 {
  flex: 2;
  min-width: 0;
}

.form-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.375rem;
}

.form-actions-row {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

.form-actions-inline {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  margin-bottom: 1rem;
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 0.8125rem;
  cursor: pointer;
  text-decoration: none;
}

.btn-link:hover {
  text-decoration: underline;
}

.input-with-action {
  display: flex;
  gap: 0.375rem;
  align-items: center;
}

.input-with-action .form-control {
  flex: 1;
}

.btn--sm {
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
}

.git-tree-container {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.git-tree-list {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  max-height: 250px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.git-tree-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.git-tree-item:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.08);
}

.git-tree-item__info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  flex: 1;
}

.git-tree-item__path {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8125rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.git-accounts-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  max-height: 180px;
  overflow-y: auto;
}

.git-account-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.875rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.git-account-card__info {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
  flex: 1;
}

.badge--provider {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  text-transform: uppercase;
}

.badge--github {
  background: rgba(36, 41, 47, 0.2);
  color: var(--text);
  border: 1px solid var(--border);
}

.badge--gitlab {
  background: rgba(226, 67, 41, 0.15);
  color: #fc6d26;
}

.git-account-card__name {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text);
}

.git-account-card__host {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.git-account-form-container {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.form-section-title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.git-meta-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.git-meta-row {
  display: flex;
  font-size: 0.8125rem;
  gap: 0.5rem;
}

.git-meta-label {
  color: var(--text-muted);
  font-weight: 500;
  min-width: 90px;
}

.git-meta-value {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}

.file-item__git-badge {
  font-size: 0.6875rem;
  color: #8b5cf6;
  background: rgba(139, 92, 246, 0.12);
  padding: 0.0625rem 0.375rem;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.toolbar-btn--git {
  color: #8b5cf6;
}

.toolbar-btn--git:hover {
  color: #7c3aed;
  background: rgba(139, 92, 246, 0.12);
}

.download-menu__item--git {
  color: #8b5cf6;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.download-menu__item--git:hover:not(:disabled) {
  background: rgba(139, 92, 246, 0.12);
  color: #7c3aed;
}

/* Custom Alert, Confirm & Branch Modals */

.modal--dialog {
  max-width: 440px;
}

.dialog-content {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.dialog-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dialog-icon .icon--lg {
  width: 22px;
  height: 22px;
}

.dialog-icon--success {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.dialog-icon--danger {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.dialog-icon--warning {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.dialog-icon--info {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent);
}

.dialog-message {
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text);
  margin: 0;
  word-break: break-word;
  padding-top: 0.25rem;
}

.branch-select-list {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.branch-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.branch-item:hover {
  background: rgba(99, 102, 241, 0.08);
  border-color: var(--accent);
}

.branch-item--active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.12);
}

.btn--danger {
  background: #ef4444;
  color: #fff;
  border: 1px solid transparent;
}

.btn--danger:hover {
  background: #dc2626;
}

/* Mermaid Diagram Zoom & Pan Container */

/* Mermaid Diagram Zoom & Pan Container */

.mermaid-wrapper {
  position: relative;
  margin: 1.5rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 500px;
  display: flex;
  flex-direction: column;
}

/* Standalone diagram / pure .mmd file full-screen layout for high-res monitors */
.markdown-body--mermaid,
.preview:has(.mermaid-wrapper:only-child) .markdown-body,
.markdown-body:has(> .mermaid-wrapper:only-child) {
  width: 98% !important;
  max-width: 100% !important;
  padding: 0 !important;
}

.markdown-body--mermaid > .mermaid-wrapper,
.markdown-body > .mermaid-wrapper:only-child,
.preview:has(.mermaid-wrapper:only-child) .mermaid-wrapper {
  width: 100% !important;
  max-width: 100% !important;
  min-height: calc(100vh - 120px) !important;
  height: calc(100vh - 120px) !important;
  margin: 0 !important;
}

.mermaid-zoom-toolbar {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  opacity: 0.85;
  transition: opacity 0.2s ease;
}

.mermaid-wrapper:hover .mermaid-zoom-toolbar {
  opacity: 1;
}

.mermaid-zoom-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) * 0.75);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.mermaid-zoom-btn:hover {
  color: var(--text);
  background: var(--drop-bg);
}

.mermaid-zoom-badge {
  padding: 0 0.5rem;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text-muted);
  user-select: none;
}

.mermaid-viewport {
  width: 100%;
  height: 100%;
  min-height: 480px;
  flex: 1;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  touch-action: none;
  position: relative;
}

.mermaid-viewport:active {
  cursor: grabbing;
}

.mermaid-viewport .mermaid {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mermaid-viewport svg {
  max-width: 100% !important;
  max-height: 100% !important;
  width: auto !important;
  height: auto !important;
  display: block;
  margin: auto;
  transform-origin: center center;
  transition: transform 0.05s ease-out;
}

/* ==========================================================================
   Vault: layout, sidebar and file tree
   ========================================================================== */

.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

.workspace > .main {
  min-width: 0;
}

.header__vault {
  gap: 0.375rem;
  max-width: 260px;
}

.header__vault-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar {
  position: sticky;
  top: var(--header-h);
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  flex: 0 0 280px;
  width: 280px;
  height: calc(100dvh - var(--header-h));
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 0.75rem 0.5rem;
}

.sidebar__vault {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar__vault-name {
  font-size: 0.875rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__vault-meta {
  font-size: 0.6875rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__actions {
  display: flex;
  flex-shrink: 0;
}

.sidebar__actions .toolbar-btn {
  min-width: 28px;
  height: 28px;
  padding: 0 0.375rem;
}

.sidebar__filter {
  padding: 0 0.75rem 0.5rem;
}

.sidebar__filter .form-control {
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
}

.tree {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0.375rem 1rem;
  font-size: 0.8125rem;
}

.tree-item {
  --depth: 0;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 28px;
  padding: 0.125rem 0.375rem 0.125rem calc(0.25rem + var(--depth) * 0.875rem);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  outline: none;
}

.tree-item:hover,
.tree-item:focus-visible {
  background: var(--drop-bg);
}

.tree-item:focus-visible {
  box-shadow: inset 0 0 0 1px var(--accent);
}

.tree-item--active {
  background: rgba(88, 166, 255, 0.14);
}

[data-theme="light"] .tree-item--active {
  background: rgba(9, 105, 218, 0.1);
}

.tree-item__twisty,
.tree-item__icon {
  display: inline-flex;
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

.tree-item__twisty svg,
.tree-item__icon svg {
  width: 14px;
  height: 14px;
}

.tree-item__twisty svg {
  transition: transform 0.15s;
}

.tree-item[aria-expanded="true"] .tree-item__twisty svg {
  transform: rotate(90deg);
}

.tree-item--dir .tree-item__icon {
  color: var(--accent);
}

.tree-item__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-item__dirty {
  color: var(--accent);
  font-size: 0.625rem;
}

.tree-item__badge {
  padding: 0 0.3rem;
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
}

.tree-item__actions {
  display: none;
  gap: 0.125rem;
}

.tree-item:hover .tree-item__actions,
.tree-item:focus-within .tree-item__actions {
  display: inline-flex;
}

.tree-item__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.tree-item__btn svg {
  width: 13px;
  height: 13px;
}

.tree-item__btn:hover {
  color: var(--text);
  background: var(--bg);
}

.tree__message {
  padding: 1rem 0.5rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
  text-align: center;
}

.tree__message p {
  margin: 0 0 0.75rem;
}

@media (hover: none) {
  .tree-item__actions {
    display: inline-flex;
  }
}

@media (max-width: 800px) {
  .sidebar {
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 50;
    width: min(85vw, 320px);
    height: auto;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.35);
  }

  .header__vault {
    max-width: 140px;
  }
}

/* Dialogs: connections, commit, paths, conflicts */

.download-menu__label {
  padding: 0.375rem 0.75rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

.git-account-card--active {
  border-color: var(--accent);
}

.git-account-card .file-item__actions {
  align-items: center;
}

.connection-status {
  margin-bottom: 1rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.connection-status--success {
  color: #3fb950;
  border-color: rgba(63, 185, 80, 0.4);
  background: rgba(63, 185, 80, 0.08);
}

.connection-status--error,
.form-error {
  color: #f85149;
  border-color: rgba(248, 81, 73, 0.4);
  background: rgba(248, 81, 73, 0.08);
}

[data-theme="light"] .connection-status--success {
  color: #1a7f37;
}

[data-theme="light"] .connection-status--error,
[data-theme="light"] .form-error {
  color: #cf222e;
}

.form-error {
  margin-bottom: 1rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  border: 1px solid rgba(248, 81, 73, 0.4);
  border-radius: var(--radius);
  white-space: pre-wrap;
}

.form-label {
  font-size: 0.8125rem;
  font-weight: 500;
}

.form-required {
  font-weight: 400;
  color: var(--text-muted);
}

.commit-file-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 180px;
  overflow-y: auto;
  padding: 0.375rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.form-group .commit-file {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0.25rem 0.375rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 400;
  border-radius: 4px;
  cursor: pointer;
}

.commit-file:hover {
  background: var(--drop-bg);
}

.commit-file__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.commit-file__note {
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

.commit-file__note--new {
  color: #3fb950;
}

.commit-summary {
  margin: 0 0 1rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  word-break: break-all;
}

.modal--xwide {
  max-width: 1040px;
}

.conflict-message {
  margin: 0 0 1rem;
  font-size: 0.875rem;
}

.conflict-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.conflict-pane__title {
  margin-bottom: 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

.conflict-pane__text {
  height: 45vh;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  resize: vertical;
}

@media (max-width: 700px) {
  .conflict-compare {
    grid-template-columns: 1fr;
  }

  .conflict-pane__text {
    height: 25vh;
  }
}

.toast--interactive {
  pointer-events: auto;
}

.toast__link {
  margin-left: 0.5rem;
  color: var(--accent);
}

/* ==========================================================================
   Phase 2: links, attachments and embedded media
   ========================================================================== */

.markdown-body a.link-broken {
  color: #f85149;
  text-decoration: underline dashed;
  text-underline-offset: 3px;
}

[data-theme="light"] .markdown-body a.link-broken {
  color: #cf222e;
}

.link-insecure {
  text-decoration: line-through;
  color: var(--text-muted);
  cursor: help;
}

.link-insecure::after {
  content: " (insecure link)";
  font-size: 0.75em;
  text-decoration: none;
  display: inline-block;
  margin-left: 0.25em;
}

.markdown-body a.attachment-link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  max-width: 100%;
  padding: 0.125rem 0.5rem;
  vertical-align: middle;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
}

.markdown-body a.attachment-link:hover {
  border-color: var(--accent);
}

.attachment-link__icon,
.content-notice__icon {
  display: inline-flex;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}

.attachment-link__icon svg,
.content-notice__icon svg {
  width: 16px;
  height: 16px;
}

.attachment-link__size {
  font-size: 0.75em;
  color: var(--text-muted);
}

.content-notice {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.375rem;
  max-width: 100%;
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  background: var(--code-bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  word-break: break-all;
}

.content-notice--blocked .content-notice__icon {
  color: #d29922;
}

.content-notice--missing .content-notice__icon {
  color: #f85149;
}

.media-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0;
  padding: 0.625rem 0.75rem;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.media-card__name {
  font-weight: 500;
}

.media-card__player {
  flex-basis: 100%;
  max-width: 100%;
}

video.media-card__player {
  max-height: 70vh;
}

.markdown-body img.vault-image--loading {
  min-width: 120px;
  min-height: 80px;
  background: var(--code-bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.markdown-body img.vault-image--error {
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
  color: #f85149;
  border: 1px dashed #f85149;
  border-radius: var(--radius);
}

.tree-item__size {
  flex-shrink: 0;
  font-size: 0.6875rem;
  color: var(--text-muted);
}

/* Upload rows inside the commit dialog */

.commit-extra {
  margin-bottom: 1rem;
}

.upload-intro {
  margin: 0 0 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.upload-list {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 0.75rem;
}

.upload-row {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.25rem 0.5rem;
  padding: 0.375rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.upload-row .attachment-link__icon {
  color: var(--text-muted);
}

.upload-row__name.form-control {
  padding: 0.25rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

.upload-row__size {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.upload-row__mode.form-control {
  grid-column: 2;
  width: auto;
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
}

.upload-row__note {
  grid-column: 2 / 4;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.upload-row__note:empty {
  display: none;
}

.upload-row--refused {
  opacity: 0.75;
}

.upload-row--refused .upload-row__note {
  color: #f85149;
}

.upload-progress {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 1rem;
}

.upload-progress__track {
  height: 6px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.upload-progress__bar {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}

.upload-progress__text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Files dragged over the window */

body.is-dragging-files .main {
  outline: 2px dashed var(--accent);
  outline-offset: -8px;
}

/* [[ autocomplete */

.editor-container {
  position: relative;
}

.wikilink-suggest {
  position: absolute;
  z-index: 20;
  width: 320px;
  max-width: calc(100% - 16px);
  padding: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.wikilink-suggest__item {
  display: flex;
  flex-direction: column;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
}

.wikilink-suggest__item--active,
.wikilink-suggest__item:hover {
  background: rgba(88, 166, 255, 0.14);
}

.wikilink-suggest__name {
  font-size: 0.8125rem;
  font-weight: 500;
}

.wikilink-suggest__path {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.wikilink-suggest__path:empty {
  display: none;
}

/* ==========================================================================
   F4: version history
   ========================================================================== */

.history {
  display: grid;
  grid-template-columns: minmax(220px, 300px) 1fr;
  gap: 1rem;
  height: calc(85vh - 140px);
  max-height: none;
  overflow: hidden;
}

.history__list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.5rem 0.625rem;
  text-align: left;
  color: var(--text);
  font-family: var(--font-sans);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.history-item:hover {
  border-color: var(--accent);
}

.history-item--active {
  border-color: var(--accent);
  background: rgba(88, 166, 255, 0.12);
}

.history-item__title {
  font-size: 0.8125rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item__meta {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.history__more {
  align-self: center;
  margin-top: 0.25rem;
}

.history__message {
  margin: 0.5rem 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.history__detail {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.history__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 0.8125rem;
}

.history__content {
  flex: 1;
  overflow: auto;
  padding: 0.75rem 1rem;
  background: var(--preview-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.history__preview {
  width: 100%;
}

.diff__summary {
  margin: 0 0 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.diff__lines {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff__line {
  display: block;
}

.diff__line--added {
  color: #3fb950;
  background: rgba(63, 185, 80, 0.12);
}

.diff__line--removed {
  color: #f85149;
  background: rgba(248, 81, 73, 0.12);
}

[data-theme="light"] .diff__line--added {
  color: #1a7f37;
}

[data-theme="light"] .diff__line--removed {
  color: #cf222e;
}

.diff__gap {
  display: block;
  color: var(--text-muted);
  font-style: italic;
}

@media (max-width: 800px) {
  .history {
    grid-template-columns: 1fr;
    grid-template-rows: 30% 1fr;
  }
}

.history__meta a {
  color: var(--accent);
}

/* ==========================================================================
   F6: link index, backlinks and graph
   ========================================================================== */

.sidebar__status {
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.backlinks {
  width: 80%;
  margin: 0 auto 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.backlinks__title {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.backlinks__list {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.backlink {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.125rem 0.75rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

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

.backlink__source {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent);
}

.backlink__line {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.backlink__context {
  grid-column: 1 / -1;
  font-size: 0.8125rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .backlinks {
    width: 92%;
  }
}

.modal--graph {
  display: flex;
  flex-direction: column;
  max-width: 1280px;
  height: 90vh;
}

.graph__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.graph__toolbar .form-control {
  width: auto;
  padding: 0.3rem 0.5rem;
  font-size: 0.8125rem;
}

.graph__toolbar .checkbox-label {
  font-size: 0.8125rem;
}

.graph__stats {
  margin-left: auto;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.graph__canvas {
  flex: 1;
  min-height: 0;
  background: var(--preview-bg);
}

.graph__legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.graph__key::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 0.3rem;
  vertical-align: -1px;
  border-radius: 50%;
  background: var(--accent);
}

.graph__key--mermaid::before {
  border-radius: 0;
  transform: rotate(45deg) scale(0.8);
  background: #a371f7;
}

.graph__key--attachment::before {
  border-radius: 2px;
  background: var(--text-muted);
}

.graph__key--ghost::before {
  background: transparent;
  border: 1.5px dashed #f85149;
}

.graph__hint {
  margin-left: auto;
}

/* ==========================================================================
   F8: document templates
   ========================================================================== */

.newdoc {
  display: grid;
  grid-template-columns: minmax(220px, 300px) 1fr;
  gap: 1rem;
  max-height: calc(85vh - 80px);
}

.newdoc__templates,
.newdoc__side {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
  min-height: 0;
}

.newdoc__list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
  max-height: 50vh;
}

.newdoc__preview {
  flex: 1;
  width: 100%;
  min-height: 160px;
  max-height: 42vh;
  overflow: auto;
  margin: 0;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  background: var(--preview-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.newdoc__side .form-group {
  margin-bottom: 0.25rem;
}

.modal__body.newdoc .modal__footer {
  margin: auto 0 0;
  padding: 0.75rem 0 0;
  background: none;
}

.tree-item--templates .tree-item__name {
  font-style: italic;
  color: var(--text-muted);
}

@media (max-width: 800px) {
  .newdoc {
    grid-template-columns: 1fr;
  }
}

/* Insert link dialog: vault documents */

.link-tabs {
  margin-bottom: 1rem;
}

.link-vault-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 1rem;
  padding: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.link-doc {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  text-align: left;
  font-family: var(--font-sans);
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

.link-doc:hover {
  background: var(--drop-bg);
}

.link-doc--active {
  background: rgba(88, 166, 255, 0.14);
  border-color: var(--accent);
}

.link-doc__name {
  font-size: 0.8125rem;
  font-weight: 500;
}

.link-doc__folder {
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-format .checkbox-label {
  margin-top: 0.25rem;
}

.link-format code {
  font-size: 0.75rem;
}

/* Attach dialog */

.attach-drop {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.75rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

body.is-dragging-files .attach-drop {
  border-color: var(--accent);
}

.attach-files {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
}

.attach-file {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.attach-file .attachment-link__icon {
  color: var(--text-muted);
}

.attach-file__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-file__size {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.attach-file--refused .attach-file__size {
  color: #f85149;
}

/* Import of Markdown files */

.upload-all-templates {
  margin-bottom: 0.5rem;
  font-size: 0.8125rem;
}

.upload-row__template {
  grid-column: 2;
  font-size: 0.8125rem;
}

/* Drag and drop of files between folders */

.tree-item--file[draggable="true"] {
  cursor: grab;
}

.tree-drop-target.tree-item,
.tree.tree-drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  background: rgba(88, 166, 255, 0.1);
}
