.editor-toolbar {
  row-gap: 8px;
}

.editor-toolbar .btn,
.saved-actions .btn,
.preview-actions .btn {
  white-space: normal;
  text-align: center;
}

.saved-list {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 18px;
  display: grid;
  gap: 12px;
}

.saved-card {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.08);
}

.saved-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(16, 24, 40, 0.06);
  font-size: 24px;
}

.saved-body {
  min-width: 0;
}

.saved-body h2 {
  margin: 0;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.saved-body p {
  margin: 5px 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.saved-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 150px));
  gap: 8px;
}

.pdf-page-image {
  min-height: 180px;
}

.restore-original-form {
  width: min(920px, 100%);
  margin: 12px auto 26px;
  padding: 0 4px;
}

.restore-original-btn {
  width: 100%;
  min-height: 48px;
}

@media (max-width: 640px) {
  .editor-toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .editor-toolbar .btn {
    min-height: 42px;
    font-size: 12px;
    padding: 0 6px;
  }

  .saved-list {
    padding: 10px;
  }

  .saved-card {
    grid-template-columns: 42px 1fr;
    gap: 10px;
    padding: 12px;
    border-radius: 14px;
  }

  .saved-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    font-size: 21px;
  }

  .saved-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Fullscreen mobile editor */
.mobile-editor-page {
  --topbar-h: 54px;
  --bottombar-h: 72px;
  --keyboard-offset: 0px;
  --doc-font-size: 17px;
  --doc-line-height: 1.55;
  min-height: 100vh;
  margin: 0;
  color: #111827;
  background: #f3f4f6;
  overflow: hidden;
}

.mobile-editor-topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 8px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  border-bottom: 1px solid rgba(17, 24, 39, 0.1);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(18px);
}

.mobile-icon-btn {
  flex: 0 0 auto;
  width: 42px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: transparent;
  color: #111827;
  font-size: 25px;
  font-weight: 800;
}

.mobile-icon-btn.done {
  color: #1d4ed8;
  background: #eff6ff;
}

.mobile-title {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.mobile-title strong {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 16px;
  line-height: 1.15;
}

.mobile-title span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #667085;
  font-size: 11px;
}

.mobile-save-state {
  min-width: 84px;
  max-width: 112px;
  padding: 6px 8px;
  border-radius: 999px;
  text-align: center;
  color: #344054;
  background: #f2f4f7;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.mobile-save-state.saved {
  color: #067647;
  background: #ecfdf3;
}

.mobile-save-state.saving,
.mobile-save-state.dirty {
  color: #92400e;
  background: #fffbeb;
}

.mobile-save-state.error {
  color: #b42318;
  background: #fef3f2;
}

.mobile-editor-main {
  position: fixed;
  inset: calc(var(--topbar-h) + env(safe-area-inset-top)) 0 calc(var(--bottombar-h) + env(safe-area-inset-bottom) + var(--keyboard-offset)) 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0;
  background: #f3f4f6;
}

.mobile-editor-form {
  min-height: 100%;
}

.mobile-doc-stage {
  min-height: 100%;
  padding: 0;
  background: #fff;
}

.mobile-doc-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.mobile-word-editor {
  --doc-font-size: 17px;
  --doc-line-height: 1.55;
  width: 100%;
  min-height: calc(100vh - var(--topbar-h) - var(--bottombar-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  display: block;
  border: 0;
  outline: 0;
  resize: none;
  padding: 16px 15px 96px;
  color: #111827;
  background: #fff;
  font: 400 var(--doc-font-size)/var(--doc-line-height) -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.mobile-word-editor.format-bold {
  font-weight: 700;
}

.mobile-word-editor.format-italic {
  font-style: italic;
}

.mobile-word-editor.format-underline {
  text-decoration: underline;
}

.mobile-word-editor.align-left {
  text-align: left;
}

.mobile-word-editor.align-center {
  text-align: center;
}

.mobile-word-editor.align-right {
  text-align: right;
}

.mobile-editor-page.page-mode .mobile-editor-main {
  background: #d9dee8;
  padding: 14px 10px;
}

.mobile-editor-page.page-mode .mobile-doc-stage {
  width: min(100%, 794px);
  min-height: 1123px;
  margin: 0 auto 18px;
  padding: 52px 38px;
  background: #fff;
  box-shadow: 0 16px 44px rgba(16, 24, 40, 0.18);
}

.mobile-editor-page.page-mode.landscape-page .mobile-doc-stage {
  width: min(100%, 1123px);
  min-height: 794px;
}

.mobile-editor-page.page-mode.narrow-margins .mobile-doc-stage {
  padding: 28px 22px;
}

.mobile-editor-page.page-mode .mobile-word-editor {
  min-height: 980px;
  padding: 0 0 80px;
}

.editor-note {
  margin: 0;
  padding: 10px 15px 90px;
  color: #667085;
  background: #fff;
  font-size: 13px;
  line-height: 1.35;
}

.restore-original-form {
  margin: 0;
  padding: 10px 14px 98px;
  background: #f3f4f6;
}

.restore-original-btn {
  width: 100%;
  min-height: 46px;
  border-radius: 14px;
}

.mobile-editor-bottom {
  position: fixed;
  inset: auto 0 var(--keyboard-offset) 0;
  z-index: 32;
  min-height: calc(58px + env(safe-area-inset-bottom));
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  display: flex;
  gap: 7px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  gap: 6px;
  border-top: 1px solid rgba(17, 24, 39, 0.1);
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(18px);
}

.mobile-editor-bottom::-webkit-scrollbar {
  display: none;
}

.format-tool,
.mobile-tool {
  flex: 0 0 46px;
  min-width: 46px;
  min-height: 44px;
  border: 0;
  border-radius: 13px;
  display: grid;
  place-items: center;
  color: #111827;
  background: #f2f4f7;
  font-size: 17px;
  font-weight: 800;
}

.format-tool:active,
.mobile-tool.primary {
  color: #fff;
  background: #1d4ed8;
}

.keyboard-done {
  position: fixed;
  right: 12px;
  bottom: calc(var(--bottombar-h) + var(--keyboard-offset) + env(safe-area-inset-bottom) + 8px);
  z-index: 33;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  display: none;
  color: #fff;
  background: #111827;
  font-weight: 800;
}

.mobile-editor-page.keyboard-open .keyboard-done {
  display: block;
}

.mobile-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  background: rgba(15, 23, 42, 0.28);
}

.mobile-sheet-backdrop.open {
  display: block;
}

.mobile-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  max-height: min(78vh, 620px);
  padding: 8px 14px calc(18px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: #fff;
  box-shadow: 0 -20px 60px rgba(16, 24, 40, 0.22);
  overflow: auto;
  transform: translateY(110%);
  transition: transform 0.2s ease;
}

.mobile-sheet.open {
  transform: translateY(0);
}

.sheet-grip {
  width: 46px;
  height: 5px;
  margin: 0 auto 12px;
  border-radius: 999px;
  background: #d0d5dd;
}

.mobile-sheet h2 {
  margin: 0 0 12px;
  color: #111827;
  font-size: 17px;
}

.format-grid,
.sheet-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.sheet-actions.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.format-grid button,
.sheet-actions button,
.search-row button,
.version-row button {
  min-height: 46px;
  border: 0;
  border-radius: 14px;
  color: #111827;
  background: #f2f4f7;
  font-size: 15px;
  font-weight: 800;
}

.sheet-actions button.danger {
  color: #b42318;
  background: #fef3f2;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px;
  border-radius: 16px;
  background: #f2f4f7;
}

.mode-switch button {
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  font-weight: 800;
}

.mode-switch button.active {
  color: #fff;
  background: #111827;
}

.search-row,
.replace-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px 48px 48px;
  gap: 8px;
  margin-bottom: 8px;
}

.replace-row {
  grid-template-columns: minmax(0, 1fr) 96px 58px;
}

.search-row input,
.replace-row input {
  min-width: 0;
  min-height: 48px;
  border: 1px solid #d0d5dd;
  border-radius: 14px;
  padding: 0 12px;
  font-size: 16px;
}

.more-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px;
  border-radius: 16px;
  background: #f9fafb;
}

.more-head strong,
.more-head span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.more-head strong {
  font-size: 16px;
}

.more-head span {
  color: #067647;
  font-size: 13px;
  font-weight: 800;
}

.more-head button {
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 900;
}

.comment-box {
  display: grid;
  gap: 8px;
}

.comment-box textarea {
  min-height: 92px;
  border: 1px solid #d0d5dd;
  border-radius: 14px;
  padding: 10px;
  font-size: 16px;
}

.comment-box button {
  min-height: 46px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  background: #1d4ed8;
  font-weight: 800;
}

.comment-row {
  margin-top: 8px;
  padding: 10px;
  border-radius: 14px;
  background: #f9fafb;
}

.comment-row p {
  margin: 0 0 8px;
}

.comment-row button {
  min-height: 36px;
  border: 0;
  border-radius: 999px;
  padding: 0 12px;
  color: #067647;
  background: #ecfdf3;
  font-weight: 800;
}

.stats-box {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stats-box p {
  margin: 0;
  padding: 12px;
  border-radius: 14px;
  background: #f9fafb;
}

.format-grid button:disabled,
.sheet-actions button:disabled {
  color: #98a2b3;
  background: #f2f4f7;
}

.sheet-hint {
  color: #667085;
  font-size: 13px;
}

.versions-list {
  display: grid;
  gap: 8px;
}

.version-row {
  padding: 10px;
  border: 1px solid #eaecf0;
  border-radius: 14px;
  display: grid;
  gap: 7px;
}

.version-row span {
  color: #667085;
  font-size: 12px;
}

.version-row div {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.check-result {
  margin-bottom: 12px;
  padding: 12px;
  border-radius: 14px;
  color: #344054;
  background: #f9fafb;
  line-height: 1.4;
}

.mobile-empty-state,
.mobile-pdf-reader {
  padding: 16px;
}

.panels-hidden .mobile-editor-topbar,
.panels-hidden .mobile-editor-bottom {
  transform: translateY(-120%);
}

.panels-hidden .mobile-editor-bottom {
  transform: translateY(120%);
}

.mobile-toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom) + 14px);
  z-index: 60;
  padding: 12px;
  border-radius: 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  background: #111827;
  box-shadow: 0 16px 36px rgba(16, 24, 40, 0.28);
}

.mobile-toast button {
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  padding: 0 12px;
  font-weight: 800;
}

@media (max-width: 430px) {
  .mobile-icon-btn {
    width: 39px;
    font-size: 23px;
  }

  .optional-top {
    display: none;
  }

  .format-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
