*,
*::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__suite {
  margin: 0.375rem 0 0;
}

.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-auto {
  margin-bottom: 1rem;
}

.commit-auto__message {
  margin: 0.375rem 0 0;
  padding: 0.5rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  white-space: pre-wrap;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.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;
  }
}

/* Merge: unchanged context, conflict cards and the editable result */

.merge {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.merge__summary {
  margin: 0;
  font-size: 0.875rem;
}

.merge__tabs {
  align-self: flex-start;
}

.merge__chunks {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 58vh;
  overflow-y: auto;
}

.merge__same {
  margin: 0;
  padding: 0.375rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  white-space: pre-wrap;
  color: var(--text-muted);
  background: var(--code-bg);
  border-radius: var(--radius);
}

.merge__gap {
  display: block;
  font-style: italic;
}

.merge-conflict {
  border: 1px solid #d29922;
  border-radius: var(--radius);
  padding: 0.625rem 0.75rem;
}

.merge-conflict--resolved {
  border-color: #3fb950;
}

.merge-conflict__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
}

.merge-conflict__state {
  font-weight: 400;
  color: var(--text-muted);
}

.merge-conflict__sides {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.merge-conflict__title {
  margin-bottom: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

.merge-conflict__text {
  margin: 0;
  min-height: 2rem;
  max-height: 30vh;
  overflow: auto;
  padding: 0.375rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  white-space: pre-wrap;
  background: var(--code-bg);
  border-radius: var(--radius);
}

.merge-conflict__text--mine {
  border-left: 3px solid var(--accent);
}

.merge-conflict__text--theirs {
  border-left: 3px solid #a371f7;
}

.merge-conflict__base {
  margin-top: 0.375rem;
  font-size: 0.8125rem;
}

.merge-conflict__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.5rem;
}

.merge-conflict__actions .btn {
  padding: 0.25rem 0.625rem;
  font-size: 0.8125rem;
}

.merge-conflict__actions .btn[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.merge-conflict__custom {
  width: 100%;
  margin-top: 0.5rem;
  min-height: 5rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

.merge__text {
  width: 100%;
  height: 52vh;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  resize: vertical;
}

.merge__manual {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

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

.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;
}

.newdoc__ai {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.newdoc__ai[hidden],
.newdoc__ai [hidden] {
  display: none;
}

.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);
}

.history__compare {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.8125rem;
}

.history__compare .form-control {
  flex: 1 1 220px;
  width: auto;
  padding: 0.3rem 0.5rem;
  font-size: 0.8125rem;
}

/* Properties (YAML front matter) at the top of a note */
.markdown-body .properties {
  margin: 0 0 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.875rem;
}

.markdown-body .properties summary {
  padding: 0.4rem 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.markdown-body .properties table {
  display: table;
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  border-top: 1px solid var(--border);
}

.markdown-body .properties th,
.markdown-body .properties td {
  padding: 0.35rem 0.75rem;
  border: none;
  text-align: left;
  vertical-align: top;
  background: transparent;
}

.markdown-body .properties tr + tr th,
.markdown-body .properties tr + tr td {
  border-top: 1px solid var(--border);
}

.markdown-body .properties th {
  width: 28%;
  color: var(--text-muted);
  font-weight: 500;
  word-break: break-word;
}

.markdown-body .properties td {
  word-break: break-word;
}

.markdown-body .properties__chip {
  display: inline-block;
  margin: 0 0.3rem 0.2rem 0;
  padding: 0.05rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
}

.markdown-body .properties--error {
  padding: 0.5rem 0.75rem;
  border-color: #d29922;
}

.markdown-body .properties__warning {
  margin: 0 0 0.5rem;
  color: #d29922;
}

.markdown-body .properties--error pre {
  margin: 0;
}

/* Tags */
.markdown-body a.tag {
  display: inline-block;
  padding: 0 0.45em;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-size: 0.875em;
  line-height: 1.6;
  text-decoration: none;
  white-space: nowrap;
}

.markdown-body a.tag:hover {
  background: color-mix(in srgb, var(--accent) 24%, transparent);
}

.tag-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 100%;
  margin-top: 0.375rem;
  padding: 0.1rem 0.25rem 0.1rem 0.5rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-size: 0.75rem;
}

.tag-filter__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-filter__clear {
  border: none;
  background: none;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.2rem;
}

.tag-panel {
  flex-shrink: 0;
  max-height: 35%;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
}

.tag-panel__toggle {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  width: 100%;
  padding: 0.45rem 0.75rem;
  border: none;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.tag-panel__twisty {
  width: 14px;
  height: 14px;
  transform: rotate(90deg);
  transition: transform 0.15s;
}

.tag-panel--collapsed .tag-panel__twisty {
  transform: none;
}

.tag-panel__total {
  margin-left: auto;
  font-weight: 400;
}

.tag-panel__list {
  overflow-y: auto;
  margin: 0;
  padding: 0 0.375rem 0.5rem;
  list-style: none;
}

.tag-panel__item {
  --depth: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.2rem 0.5rem 0.2rem calc(0.5rem + var(--depth) * 1rem);
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.tag-panel__item:hover {
  background: var(--drop-bg);
}

.tag-panel__item--active {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}

.tag-panel__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-panel__count {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.graph__groups {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

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

/* Search panel (replaces the tree in the sidebar) */
.sidebar--search .sidebar__filter,
.sidebar--search .tree,
.sidebar--search .tag-panel {
  display: none !important;
}

.search-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  font-size: 0.8125rem;
}

.search-panel__bar {
  display: flex;
  gap: 0.25rem;
  padding: 0 0.75rem 0.5rem;
}

.search-panel__bar .form-control {
  flex: 1;
  min-width: 0;
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
}

.search-panel__bar .toolbar-btn {
  min-width: 28px;
  height: 30px;
  padding: 0 0.4rem;
  font-weight: 600;
}

.search-panel__help {
  margin: 0 0.75rem 0.5rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.search-panel__help ul {
  margin: 0 0 0.375rem;
  padding-left: 1rem;
}

.search-panel__help li + li {
  margin-top: 0.2rem;
}

.search-panel__help code {
  color: var(--text);
}

.search-panel__help p {
  margin: 0;
}

.search-panel__status {
  padding: 0 0.75rem 0.375rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.375rem 1rem;
}

.search-result + .search-result {
  margin-top: 0.375rem;
}

.search-result__file,
.search-result__snippet {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.search-result__file {
  align-items: center;
  padding: 0.3rem 0.5rem;
  font-weight: 600;
}

.search-result__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result__count {
  margin-left: auto;
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.75rem;
}

.search-result__snippet {
  padding: 0.2rem 0.5rem 0.2rem 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.search-result__file:hover,
.search-result__snippet:hover,
.search-result__file:focus-visible,
.search-result__snippet:focus-visible {
  background: var(--drop-bg);
}

.search-result__line {
  flex-shrink: 0;
  min-width: 2ch;
  text-align: right;
  opacity: 0.7;
}

.search-result__text {
  overflow-wrap: anywhere;
}

.search-result__text mark,
.search-flash {
  background: color-mix(in srgb, #f2cc60 55%, transparent);
  color: inherit;
  border-radius: 2px;
}

.search-flash {
  transition: background-color 1.5s;
}

.search-panel__more {
  padding: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.markdown-body a.properties__value {
  color: inherit;
  text-decoration: none;
}

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

/* Offline work */
.offline-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.4rem 1rem;
  background: color-mix(in srgb, #d29922 18%, var(--surface));
  border-bottom: 1px solid color-mix(in srgb, #d29922 45%, var(--border));
  font-size: 0.8125rem;
}

.offline-bar--error {
  background: color-mix(in srgb, #f85149 16%, var(--surface));
  border-bottom-color: color-mix(in srgb, #f85149 45%, var(--border));
}

.offline-bar__text {
  flex: 1;
  min-width: 12rem;
}

.offline-bar__btn {
  padding: 0.2rem 0.75rem;
  font-size: 0.8125rem;
}

.tree-item--unavailable .tree-item__name,
.tree-item--unavailable .tree-item__icon {
  opacity: 0.45;
}

.tree-item__badge--pending {
  background: color-mix(in srgb, #d29922 22%, transparent);
  color: #d29922;
}

/* AI assistant */
.header__ai {
  gap: 0.3rem;
}

.header__ai--on {
  color: var(--accent);
}

.ai-panel {
  position: sticky;
  top: var(--header-h);
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  flex: 0 0 380px;
  width: 380px;
  max-width: 100vw;
  height: calc(100dvh - var(--header-h));
  background: var(--surface);
  border-left: 1px solid var(--border);
  font-size: 0.8125rem;
}

.ai-panel__header {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.6rem 0.75rem 0.4rem;
}

.ai-panel__title {
  font-size: 0.875rem;
  white-space: nowrap;
}

.ai-panel__header select {
  flex: 1;
  min-width: 0;
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
}

.ai-panel__where {
  padding: 0 0.75rem 0.5rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}

.ai-panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0 0.75rem 0.5rem;
}

.ai-panel__actions .btn,
.ai-ask .btn,
.ai-context__actions .btn,
.ai-panel__footer .btn,
.ai-message__actions .btn {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
}

.ai-ask {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.375rem;
  padding: 0 0.75rem 0.5rem;
}

.ai-ask textarea {
  width: 100%;
  resize: vertical;
  font-size: 0.8125rem;
}

.ai-context {
  margin: 0 0.75rem 0.5rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.ai-context__title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.ai-context__list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.ai-context__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.1rem 0;
  overflow-wrap: anywhere;
}

.ai-context__item--omitted {
  opacity: 0.5;
  text-decoration: line-through;
}

.ai-context__remove {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
}

.ai-context__omitted {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.ai-context__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.375rem;
  margin-top: 0.5rem;
}

.ai-conversation {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.25rem 0.75rem 0.75rem;
}

.ai-message {
  margin-top: 0.625rem;
}

.ai-message--user .ai-message__body {
  margin-left: 2rem;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  white-space: pre-wrap;
}

.ai-message--assistant .ai-message__body {
  font-size: 0.8125rem;
}

.ai-message--assistant .ai-message__body > :first-child {
  margin-top: 0;
}

.ai-message--streaming .ai-message__body::after {
  content: "▍";
  color: var(--accent);
}

.ai-message__note {
  margin: 0.375rem 0 0;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.ai-message__note--error {
  color: #f85149;
}

.ai-message__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.375rem;
}

.ai-message__diff {
  margin-top: 0.5rem;
  max-height: 16rem;
  overflow: auto;
  font-size: 0.75rem;
}

.ai-panel__footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border);
}

.ai-usage {
  flex: 1;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.ai-notice {
  margin-bottom: 0.75rem;
  padding: 0.625rem 0.75rem;
  border: 1px solid color-mix(in srgb, #d29922 45%, var(--border));
  border-radius: 6px;
  background: color-mix(in srgb, #d29922 10%, transparent);
  font-size: 0.8125rem;
}

.ai-notice p {
  margin: 0;
}

.ai-notice p + p {
  margin-top: 0.4rem;
}

.ai-settings__heading {
  margin: 1rem 0 0.5rem;
  font-size: 0.9375rem;
}

.ai-profile {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.ai-profile__info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ai-profile__info small {
  color: var(--text-muted);
}

.ai-profile--active {
  border-color: var(--accent);
}

.ai-profile .btn {
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
}

.input-with-button {
  display: flex;
  gap: 0.375rem;
}

.input-with-button .form-control {
  flex: 1;
  min-width: 0;
}

.ai-settings__danger {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

@media (max-width: 900px) {
  .ai-panel {
    position: fixed;
    right: 0;
    z-index: 60;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.25);
  }
}

/* Coding agents */
.agent-intro {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.agent-section + .agent-section {
  margin-top: 1rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}

.agent-block {
  margin-top: 0.75rem;
}

.agent-block summary,
.agent-block__title {
  margin-bottom: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: default;
}

.agent-block summary {
  cursor: pointer;
}

.agent-code {
  margin: 0 0 0.375rem;
  padding: 0.5rem 0.625rem;
  max-height: 14rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* BPMN diagrams: always on a light card (bpmn-js draws dark lines), in both themes */
.bpmn-canvas {
  position: relative;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  color: #1f2328;
  overflow: hidden;
}

.bpmn-canvas--file {
  height: calc(100dvh - var(--header-h) - 9rem);
  min-height: 360px;
}

.bpmn-canvas--embed {
  height: 380px;
}

.bpmn-canvas--error {
  height: auto;
  min-height: 0;
  padding: 0.75rem;
}

.markdown-body--bpmn {
  max-width: none;
}

.bpmn-embed {
  margin: 1rem 0;
}

.bpmn-embed figcaption {
  margin-top: 0.375rem;
  font-size: 0.875rem;
  text-align: center;
}

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

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

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

.bpmn-editor__status {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.bpmn-editor__status--error {
  color: #f85149;
}

.bpmn-editor__canvas {
  flex: 1;
  min-height: 420px;
  border-radius: 0;
  border-width: 0;
}

/* ```query blocks: tables and lists of notes from their properties and tags */

.query-result {
  margin: 0 0 16px;
}

.query-result .query-table {
  margin-bottom: 4px;
}

.query-list {
  margin-bottom: 4px;
}

.query-result__meta,
.query-result__message {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.query-result--error .query-result__message {
  color: #ef4444;
}

.query-result--error pre {
  margin-top: 6px;
}

/* Quick start guide: one screen, shown on start until the user turns it off */

.quickstart {
  font-size: 0.875rem;
  line-height: 1.5;
}

.quickstart__lead {
  margin: 0 0 1rem;
}

.quickstart__columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.quickstart__block h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9375rem;
}

.quickstart__steps,
.quickstart__tips {
  margin: 0;
  padding-left: 1.25rem;
}

.quickstart__steps li,
.quickstart__tips li {
  margin-bottom: 0.375rem;
}

.quickstart__steps ul {
  margin: 0.25rem 0 0;
  padding-left: 1.1rem;
}

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

.quickstart code {
  font-size: 0.8125rem;
}

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

.quickstart kbd {
  padding: 0.05em 0.4em;
  font-family: var(--font-mono);
  font-size: 0.8125em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
}

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