/**
 * uNotes Web - WYSIWYG Editor & Document Styling
 * Chrome-less paper canvas, Apple Notes typography.
 */

.app-editor-pane .editor-header-bar {
  height: 44px;
  min-height: 44px;
  padding: 0 var(--space-5);
  border-bottom: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: var(--bg-editor);
  flex-shrink: 0;
  gap: var(--space-3);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.header-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
}

.mobile-drawer-toggle {
  display: none;
}

@media (max-width: 860px) {
  .mobile-drawer-toggle {
    display: inline-flex;
  }

  .app-editor-pane .note-folder-breadcrumb-btn {
    min-height: 44px;
  }
}

body.force-mobile-view .mobile-drawer-toggle {
  display: inline-flex;
}

.app-editor-pane .note-folder-breadcrumb-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
  min-height: 36px;
  padding: var(--space-1) var(--space-2);
  background: none;
  border: none;
  border-radius: var(--radius-search);
  color: var(--orange-text);
  font-family: var(--font-text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.app-editor-pane .note-folder-breadcrumb-btn:hover {
  background: var(--cream-surface-1);
  color: var(--orange-text);
}

.note-folder-breadcrumb-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.app-editor-pane .note-folder-breadcrumb-btn svg {
  display: block;
  width: 20px;
  height: 20px;
}

#note-folder-breadcrumb {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-status-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 12px;
  color: var(--slate-text);
  white-space: nowrap;
}

.header-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--notes-orange);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.header-btn svg {
  width: 24px;
  height: 24px;
}

.header-btn:hover:not(:disabled) {
  background: var(--cream-surface-1);
  color: var(--notes-orange);
}

.header-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.header-btn.btn-delete {
  color: var(--slate);
}

.header-btn.btn-delete:hover:not(:disabled) {
  background: var(--error-tint);
  color: var(--error);
}

/* Conflict Banner */
.conflict-banner {
  background: var(--notes-orange-tint);
  border-bottom: 1px solid var(--divider);
  padding: var(--space-2) var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--orange-text);
}

.conflict-info {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.conflict-actions {
  display: flex;
  gap: var(--space-2);
}

.conflict-btn {
  background: var(--notes-orange);
  color: var(--accent-text);
  border: none;
  padding: 3px 8px;
  border-radius: var(--radius-badge);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

/* Rich Text Formatting Toolbar */
.editor-toolbar {
  padding: var(--space-2) var(--space-5);
  background: var(--bg-editor);
  border-bottom: none;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.tb-btn {
  width: 36px;
  height: 36px;
  background: var(--cream-surface-1);
  border: none;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  cursor: pointer;
  font-family: var(--font-text);
  font-size: 15px;
  font-weight: 600;
}

.tb-btn svg {
  width: 18px;
  height: 18px;
}

.tb-btn:hover,
.tb-btn:active,
.tb-btn.active {
  background: var(--cream-surface-2);
  color: var(--ink);
}

.tb-btn.active {
  color: var(--orange-text);
}

.tb-btn:disabled,
.tb-btn:disabled:hover,
.tb-btn:disabled:active {
  background: var(--cream-surface-1);
  color: var(--mute);
  cursor: default;
}

.tb-history-group {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  flex: 0 0 auto;
}

.tb-sep {
  width: 1px;
  height: 20px;
  background: var(--divider);
  margin: 0 var(--space-1);
}

/* Scrollable Note Content */
.editor-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5) var(--space-5) calc(var(--space-16) + var(--space-4));
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 1200px) {
  .editor-scroll-area {
    max-width: 848px;
    padding-left: var(--space-16);
    padding-right: var(--space-16);
  }
}

.note-date-indicator {
  font-size: 12px;
  color: var(--slate-text);
  text-align: center;
  margin-bottom: var(--space-4);
  font-weight: 400;
  user-select: none;
}

.note-title-editor {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.2px;
  color: var(--ink);
  margin-bottom: var(--space-3);
  outline: none;
  word-break: break-word;
  caret-color: var(--notes-orange);
}

.note-body-editor {
  font-family: var(--font-text);
  font-size: 17px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--ink);
  outline: none;
  word-break: break-word;
  caret-color: var(--notes-orange);
}

.note-title-editor::selection,
.note-title-editor *::selection,
.note-body-editor::selection,
.note-body-editor *::selection {
  background: var(--highlight-yellow);
  color: var(--ink);
}

.note-title-editor[contenteditable="true"],
.note-body-editor[contenteditable="true"] {
  border-radius: var(--radius-badge);
}

.note-title-editor[contenteditable="true"]:focus,
.note-body-editor[contenteditable="true"]:focus {
  outline: none;
  background: transparent;
}

.note-title-editor[contenteditable="true"]:empty::before {
  content: "Note title";
  color: var(--slate-text);
}

.note-body-editor[contenteditable="true"] {
  min-height: 45vh;
}

.note-body-editor p {
  margin-bottom: var(--space-3);
}

.note-body-editor h1 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.2px;
  color: var(--ink);
  margin-top: var(--space-6);
  margin-bottom: var(--space-2);
}

.note-body-editor h2,
.note-body-editor h3,
.note-body-editor h4,
.note-body-editor h5,
.note-body-editor h6 {
  font-family: var(--font-text);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink);
  margin-top: var(--space-5);
  margin-bottom: var(--space-1);
}

.note-body-editor ul,
.note-body-editor ol {
  margin-bottom: var(--space-3);
  padding-left: var(--space-6);
}

.note-body-editor li {
  margin-bottom: var(--space-1);
}

.note-body-editor blockquote {
  background: var(--cream-surface-1);
  border: 1px solid var(--divider);
  border-left: 3px solid var(--notes-orange);
  border-radius: var(--radius-search);
  padding: var(--space-3) var(--space-4);
  margin: var(--space-4) 0;
  color: var(--ink);
  font-style: italic;
}

.note-body-editor code {
  background: var(--cream-surface-2);
  color: var(--ink);
  padding: 2px 6px;
  border-radius: var(--radius-badge);
  font-family: ui-monospace, 'SF Mono', Menlo, Monaco, 'Cascadia Code', monospace;
  font-size: 15px;
}

.app-editor-pane .note-body-editor pre {
  background: var(--cream-surface-1);
  border: 1px solid var(--divider);
  border-radius: var(--radius-search);
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
  margin-bottom: var(--space-3);
}

.note-body-editor pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 15px;
}

.note-body-editor a {
  color: var(--orange-text);
  text-decoration: underline;
}

.note-body-editor img {
  max-width: 100%;
  height: auto;
}

.note-body-editor hr {
  border: none;
  border-top: 1px solid var(--divider);
  margin: var(--space-4) 0;
}

.inline-hashtag {
  color: var(--orange-text);
  background: var(--accent-tint);
  border-radius: var(--radius-badge);
  padding: 1px 5px;
  font-weight: 500;
  white-space: nowrap;
}

/* Interactive Checklists */
.checklist-group {
  margin: var(--space-4) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  cursor: default;
  user-select: none;
  font-size: 17px;
  line-height: 1.5;
}

.checklist-item input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.custom-checkbox {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--slate);
  margin-top: 1px;
  flex-shrink: 0;
  position: relative;
}

.checklist-item:hover .custom-checkbox {
  border-color: var(--notes-orange);
}

.checklist-item.checked .custom-checkbox {
  background: var(--notes-orange);
  border-color: var(--notes-orange);
}

.checklist-item.checked .custom-checkbox::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 4px;
  width: 5px;
  height: 10px;
  border: solid var(--accent-text);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.checklist-item.checked .checklist-text {
  text-decoration: line-through;
  opacity: 0.5;
}

.note-body-editor ul.checklist {
  list-style: none;
  padding-left: 0;
}

.note-body-editor ul.checklist li,
.note-body-editor li[data-checked] {
  position: relative;
  padding-left: 36px;
  cursor: text;
  list-style: none;
  line-height: 1.5;
  margin-bottom: var(--space-2);
}

.note-body-editor ul.checklist li::before,
.note-body-editor li[data-checked]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 1px;
  width: 24px;
  height: 24px;
  border: 1.5px solid var(--slate);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.note-body-editor ul.checklist li[data-checked="true"]::before,
.note-body-editor ul.checklist li.checked::before,
.note-body-editor li[data-checked="true"]::before {
  border-color: var(--notes-orange);
  background: var(--notes-orange);
}

.note-body-editor ul.checklist li[data-checked="true"]::after,
.note-body-editor ul.checklist li.checked::after,
.note-body-editor li[data-checked="true"]::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 4px;
  width: 5px;
  height: 10px;
  border: solid var(--accent-text);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  pointer-events: none;
}

.note-body-editor ul.checklist li[data-checked="true"],
.note-body-editor ul.checklist li.checked,
.note-body-editor li[data-checked="true"] {
  color: var(--ink);
  opacity: 0.5;
  text-decoration: line-through;
}

.note-body-editor .resource-block {
  margin-bottom: var(--space-4);
}

/* Protocol Tables */
.protocol-table-wrapper {
  overflow-x: auto;
  margin: var(--space-4) 0;
  border: 1px solid var(--divider);
  border-radius: var(--radius-search);
  background: var(--cream-surface-1);
}

.protocol-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  text-align: left;
}

.protocol-table th {
  background: var(--cream-surface-2);
  color: var(--ink);
  padding: var(--space-2) var(--space-3);
  font-weight: 600;
  border-bottom: 1px solid var(--divider);
}

.protocol-table td {
  color: var(--ink);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--divider);
}

.protocol-table tr:last-child td {
  border-bottom: none;
}

/* Joplin PDF Preview Container */
.joplin-pdf-preview {
  margin: var(--space-4) 0;
  border-radius: var(--radius-search);
  border: 1px solid var(--divider);
  overflow: hidden;
  background: var(--cream-surface-1);
  box-shadow: none;
  user-select: none;
}

.joplin-pdf-preview.pdf-compact .pdf-canvas-container {
  display: none;
}

.pdf-header {
  padding: var(--space-2) var(--space-3);
  background: var(--cream-surface-1);
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.pdf-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.pdf-icon {
  color: var(--error);
  flex-shrink: 0;
}

.pdf-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.pdf-badge {
  font-size: 12px;
  background: transparent;
  color: var(--slate-text);
  border: 1px solid var(--divider);
  padding: 2px 7px;
  border-radius: var(--radius-badge);
  font-weight: 500;
  white-space: nowrap;
}

.pdf-header-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.pdf-btn {
  background: transparent;
  border: 1px solid var(--divider);
  border-radius: var(--radius-badge);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--slate-text);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.pdf-btn:hover {
  background: var(--cream-surface-2);
  color: var(--ink);
  border-color: var(--divider);
}

.pdf-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.pdf-btn:disabled:hover {
  background: none;
  color: var(--slate-text);
  border-color: var(--divider);
}

.pdf-btn.open-btn {
  width: auto;
  padding: 0 9px;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  background: var(--cream-surface-2);
}

.pdf-btn.open-btn:hover {
  background: var(--cream-surface-2);
  color: var(--orange-text);
  border-color: var(--divider);
}

.pdf-btn.attachment-remove-btn {
  color: var(--ink);
}

.pdf-btn.attachment-remove-btn:hover {
  color: var(--ink);
}

.pdf-canvas-container {
  padding: 0;
  background: var(--cream-surface-2);
  position: relative;
  width: 100%;
  max-height: 580px;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.pdf-stage {
  width: 100%;
  min-height: 100%;
  padding: var(--space-5) var(--space-4);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  box-sizing: border-box;
}

.pdf-render-canvas {
  display: block;
  margin: 0 auto;
  background: var(--notes-cream);
  border-radius: var(--radius-badge);
  box-shadow: none;
  max-width: 100%;
  height: auto;
  image-rendering: -webkit-optimize-contrast;
}

.pdf-native-viewer {
  display: block;
  width: 100%;
  height: 520px;
  min-height: 420px;
  border: 1px solid var(--divider);
  border-radius: var(--radius-badge);
  background: var(--slate);
  box-shadow: none;
}

.pdf-modal-native-viewer {
  display: block;
  width: 100%;
  height: 72vh;
  min-height: 480px;
  border: none;
  border-radius: var(--radius-badge);
  background: var(--slate);
}

.pdf-header-actions .zoom-level {
  width: auto;
  min-width: 44px;
  padding: 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--slate-text);
}

.pdf-page-indicator {
  font-size: 12px;
  font-weight: 500;
  color: var(--slate-text);
  padding: 0 var(--space-1);
  white-space: nowrap;
}

/* PDF Lightbox Modal */
.pdf-lightbox-backdrop {
  z-index: 10000;
}

.pdf-lightbox-card {
  width: 92vw;
  max-width: 960px;
  height: 88vh;
  display: flex;
  flex-direction: column;
}

.pdf-lightbox-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
}

.pdf-modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}

.pdf-modal-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.pdf-modal-zoom-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--slate-text);
  min-width: 40px;
  text-align: center;
}

.pdf-lightbox-body {
  flex: 1;
  overflow: auto;
  padding: var(--space-6);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: var(--cream-surface-2);
}

.pdf-modal-canvas-wrapper {
  margin: auto;
  display: flex;
  justify-content: center;
}

.pdf-modal-canvas {
  display: block;
  background: var(--notes-cream);
  border-radius: var(--radius-badge);
  max-width: 100%;
}

.pdf-lightbox-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) var(--space-5);
}

.pdf-modal-page-info {
  font-size: 12px;
  font-weight: 500;
  color: var(--slate-text);
}

.pdf-embed-object,
.pdf-embed-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.pdf-fallback-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 100%;
  padding: var(--space-6);
  color: var(--slate-text);
  font-size: 15px;
  text-align: center;
}

.pdf-empty-state {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-6);
  text-align: left;
}

.pdf-empty-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pdf-empty-info strong {
  font-size: 15px;
  color: var(--ink);
}

.pdf-empty-info span {
  font-size: 12px;
  color: var(--slate-text);
}

/* Attachment Chip */
.attachment-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--cream-surface-1);
  border: 1px solid var(--divider);
  border-radius: var(--radius-search);
  padding: var(--space-3) var(--space-4);
  margin: var(--space-4) 0;
  box-shadow: none;
}

.attachment-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-badge);
  background: var(--error-tint);
  color: var(--error);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.attachment-info {
  flex: 1;
  min-width: 0;
}

.attachment-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.attachment-details {
  font-size: 12px;
  color: var(--slate-text);
  margin-top: 2px;
}

.attachment-action {
  background: none;
  border: 1px solid var(--divider);
  border-radius: var(--radius-badge);
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--slate-text);
  cursor: pointer;
}

.attachment-action:hover {
  background: var(--cream-surface-2);
  color: var(--ink);
  border-color: var(--divider);
}

.save-status-indicator[data-state="saving"],
.save-status-indicator[data-state="editing"],
.save-status-indicator[data-state="synced"] {
  color: var(--slate-text);
}

.save-status-indicator[data-state="error"] {
  color: var(--error);
}

/* Attachment image previews and sync feedback */
.note-image-attachment,
.image-resource-block {
  margin: var(--space-4) 0;
  border: 1px solid var(--divider);
  border-radius: var(--radius-search);
  overflow: hidden;
  background: var(--cream-surface-1);
  box-shadow: none;
  user-select: none;
}

.note-image-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--cream-surface-2);
  overflow: hidden;
}

.note-image {
  display: block;
  max-width: 100%;
  max-height: 520px;
  border-radius: 0;
  object-fit: contain;
  cursor: zoom-in;
}

.note-image-attachment.zoomed .note-image,
.image-resource-block.zoomed .note-image {
  max-height: none;
  width: 100%;
  cursor: zoom-out;
}

.note-inline-image {
  display: inline-block;
  max-width: 100%;
  margin: var(--space-2) 0;
  user-select: none;
}

.note-inline-image .note-image {
  max-height: 280px;
  vertical-align: middle;
}

.note-image-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--divider);
  background: var(--cream-surface-1);
  font-size: 12px;
}

.note-image-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  color: var(--ink);
}

.note-image-size {
  color: var(--slate-text);
  white-space: nowrap;
}

.editor-scroll-area.drag-attachment-target,
.note-body-editor.drag-attachment-target {
  outline: 2px dashed var(--notes-orange);
  outline-offset: -6px;
  background: var(--notes-orange-tint);
}

@media (prefers-reduced-motion: no-preference) {
  .header-btn,
  .tb-btn,
  .note-folder-breadcrumb-btn,
  .attachment-action,
  .pdf-btn,
  .custom-checkbox,
  .note-body-editor ul.checklist li::before,
  .note-body-editor li[data-checked]::before,
  .note-body-editor ul.checklist li,
  .note-body-editor li[data-checked] {
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
  }
}

@media (max-width: 860px) {
  .app-editor-pane .editor-header-bar {
    padding: 0 var(--space-3);
    gap: var(--space-2);
  }

  .tb-btn {
    width: 44px;
    height: 44px;
    position: relative;
    z-index: 0;
    isolation: isolate;
    background: transparent;
  }

  .tb-btn::before {
    content: "";
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    background: var(--cream-surface-1);
    z-index: -1;
  }

  .tb-btn:hover::before,
  .tb-btn:active::before,
  .tb-btn.active::before {
    background: var(--cream-surface-2);
  }

  .tb-btn:disabled,
  .tb-btn:disabled:hover,
  .tb-btn:disabled:active {
    background: transparent;
  }

  .tb-btn:disabled:hover::before,
  .tb-btn:disabled:active::before {
    background: var(--cream-surface-1);
  }
}

@media (max-width: 640px) {
  .app-editor-pane .editor-header-bar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .app-editor-pane .note-folder-breadcrumb-btn {
    flex: 1 1 auto;
    max-width: none;
  }

  .editor-toolbar {
    flex-wrap: nowrap;
    gap: var(--space-1);
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .editor-toolbar::-webkit-scrollbar {
    display: none;
  }

  .tb-btn {
    flex: 0 0 auto;
  }

  .tb-history-group {
    position: sticky;
    left: 0;
    z-index: 2;
    padding-right: var(--space-1);
    background: var(--bg-editor);
  }

  .pdf-header {
    align-items: flex-start;
  }

  .pdf-header-left {
    flex: 1 1 100%;
  }

  .pdf-header-actions {
    flex: 1 1 100%;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .pdf-header-actions .pdf-btn {
    height: 44px;
  }

  .pdf-header-actions .pdf-btn.open-btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
  }

  .pdf-header-actions .pdf-btn:not(.open-btn) {
    flex: 0 0 44px;
    width: 44px;
  }

  .note-image-meta {
    flex-wrap: wrap;
  }

  .note-image-meta .pdf-btn {
    height: 44px;
    min-height: 44px;
  }

  .note-image-meta .pdf-btn.open-btn {
    padding: 0 12px;
  }

  .editor-header-bar #mobile-drawer-toggle {
    display: none;
  }

  .editor-scroll-area {
    padding: var(--space-5) var(--space-5) calc(var(--space-14) + var(--space-1));
  }

  .pdf-title {
    max-width: 160px;
  }

  .conflict-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-size: 12px;
  }

  .conflict-actions {
    align-self: flex-end;
  }
}

@media (max-width: 430px) {
  .app-editor-pane .editor-header-bar {
    padding: 0 var(--space-2);
  }

  .header-left {
    gap: var(--space-1);
  }

  .header-right {
    gap: 0;
  }

  .note-folder-breadcrumb-icon {
    display: none;
  }

  .editor-toolbar {
    padding: var(--space-2) var(--space-2);
  }

  .tb-sep {
    margin: 0;
  }

  .note-image {
    max-height: 320px;
  }

  .pdf-header {
    padding: var(--space-2);
  }

  .protocol-table th,
  .protocol-table td {
    padding: var(--space-2);
    font-size: 14px;
  }

  .protocol-table th,
  .protocol-table td:first-child,
  .protocol-table td:last-child {
    white-space: nowrap;
  }

  .pdf-canvas-container {
    min-height: 200px;
  }

  .attachment-chip {
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
  }

  .attachment-action {
    padding: 4px 9px;
    font-size: 12px;
  }
}

/* Phone editor toolbar: a full-width bar docked to the editor bottom and
   lifted above the on-screen keyboard with --keyboard-offset. */
@media (max-width: 860px) {
  :root {
    --editor-toolbar-height: 56px;
  }

  .editor-toolbar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    width: auto;
    max-width: none;
    height: calc(var(--editor-toolbar-height) + max(0px, env(safe-area-inset-bottom) - var(--keyboard-offset, 0px)));
    padding: var(--space-1) var(--space-3) max(0px, env(safe-area-inset-bottom) - var(--keyboard-offset, 0px));
    border-top: 1px solid var(--divider);
    border-bottom: none;
    background: var(--bg-editor);
    flex-wrap: nowrap;
    gap: var(--space-1);
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    transform: translateY(calc(-1 * var(--keyboard-offset, 0px)));
    transition: none;
  }

  .editor-toolbar::-webkit-scrollbar {
    display: none;
  }

  .tb-btn {
    flex: 0 0 auto;
  }

  .tb-history-group {
    position: sticky;
    left: 0;
    z-index: 2;
    padding-right: var(--space-1);
    background: var(--bg-editor);
  }

  .editor-scroll-area {
    padding-bottom: calc(var(--editor-toolbar-height) + var(--keyboard-offset, 0px) + max(0px, env(safe-area-inset-bottom) - var(--keyboard-offset, 0px)) + var(--space-4));
  }

  body.note-selected .toast-notification {
    bottom: calc(var(--keyboard-offset, 0px) + var(--editor-toolbar-height) + max(0px, env(safe-area-inset-bottom) - var(--keyboard-offset, 0px)) + var(--space-4));
  }

  body.note-selected .mobile-new-note-fab {
    bottom: calc(var(--keyboard-offset, 0px) + var(--editor-toolbar-height) + max(0px, env(safe-area-inset-bottom) - var(--keyboard-offset, 0px)) + var(--space-4));
  }

  .pdf-header-actions .pdf-btn {
    min-height: 44px;
    height: 44px;
  }

  .pdf-header-actions .pdf-btn:not(.open-btn) {
    width: 44px;
    min-width: 44px;
  }

  .note-image-meta .pdf-btn {
    min-height: 44px;
    height: 44px;
  }

  .pdf-lightbox-header {
    flex-wrap: wrap;
  }

  .pdf-modal-actions {
    flex: 1 1 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .pdf-modal-actions .pdf-btn {
    width: 44px;
    height: 44px;
  }

  .pdf-modal-actions .pdf-btn.open-btn {
    width: auto;
  }

  .app-editor-pane .note-folder-breadcrumb-btn {
    min-height: 44px;
  }
}

/* At tablet widths the editor pane stays visible even before a note is
   selected, so the fixed FAB and toasts still need to clear the docked bar. */
@media (min-width: 641px) and (max-width: 860px) {
  .toast-notification {
    bottom: calc(var(--keyboard-offset, 0px) + var(--editor-toolbar-height) + max(0px, env(safe-area-inset-bottom) - var(--keyboard-offset, 0px)) + var(--space-4));
  }

  .mobile-new-note-fab {
    bottom: calc(var(--keyboard-offset, 0px) + var(--editor-toolbar-height) + max(0px, env(safe-area-inset-bottom) - var(--keyboard-offset, 0px)) + var(--space-4));
  }
}
