
.feature-content {
  border: none;
  border-radius: 4px;
  min-height: 100px;
  position: relative;
  background-color: transparent;
  text-align: center;
  padding: 20px;
}

/* Editor-only frame around inserted features */
#doc-page.doc-shell--edit .feature-content {
  border: 1px dashed #ccc !important;
}

/* ----------------------------
   Editor: Left toolbar (doceditor.html)
---------------------------- */

.edit-tools {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px;
  width: 80px;
  flex-shrink: 0;
}

.edit-tools-row {
  display: flex;
  gap: 5px;
  width: 100%;
}

.edit-tools-row--tight { gap: 2px; }
.edit-tools-row--gap6 { gap: 6px; }
.edit-tools-row--mt6 { margin-top: 6px; }
.edit-tools-row--mt10 { margin-top: 10px; }

.edit-tools-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  filter: grayscale(0.35);
}

.edit-tools-btn {
  flex: 1;
  cursor: pointer;
}

/* Shared locked state for auth-gated toolbar actions (visible but unavailable). */
#edit-tools .edit-tools-btn.is-unavailable,
#edit-tools .edit-tools-btn.auth-logged-in-only:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
  filter: grayscale(0.35);
}

/* Toolbar buttons: explicit surfaces (UA default grey + dark text color looks broken in dark mode) */
#edit-tools .edit-tools-btn {
  background-color: #f3f4f6;
  border: 1px solid #c4c4c4;
  border-radius: 5px;
  color: #111827;
  box-sizing: border-box;
}
#edit-tools .edit-tools-btn:hover:not(:disabled) {
  background-color: #e5e7eb;
  border-color: #9ca3af;
}
#edit-tools .edit-tools-btn:active:not(:disabled) {
  background-color: #d1d5db;
}

.edit-tools-btn--icon {
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.edit-tools-btn--pad2 { padding: 2px; }
.edit-tools-btn--pad6 { padding: 6px; }

.edit-tools-btn--text {
  font-family: 'Times New Roman', serif;
}
.edit-tools-btn--bold { font-weight: bold; }
.edit-tools-btn--italic { font-style: italic; }
.edit-tools-btn--underline { text-decoration: underline; }

.edit-tools-btn--small-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 4px;
}

.edit-tools-icon { height: 18px; width: 18px; }
.edit-tools-icon--18 { height: 18px; width: 18px; }
.edit-tools-icon--20 { height: 20px; width: 20px; }

/* Inline math nodes inserted into doc-body (pure HTML) */
.math-inline {
  display: inline-block;
  padding: 0 2px;
  border-radius: 3px;
  cursor: pointer;
}
.math-inline:hover {
  background: rgba(0, 140, 255, 0.08);
}

.math-var {
  cursor: pointer;
  /* visually neutral by default (no "link" feel); only show affordance on hover */
  border-bottom: none;
}
.math-var:hover {
  background: rgba(0, 120, 255, 0.08);
  border-bottom: 1px dotted rgba(0, 120, 255, 0.6);
}

/* Floating Math editor (MathLive) */
.math-dock {
  position: fixed;
  right: 16px;
  top: 80px;
  /* Wider by default; still constrained for small screens */
  width: clamp(420px, 45vw, 720px);
  max-width: calc(100vw - 32px);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid #ccc;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  z-index: 10050;
  overflow: hidden;
  /* User-resizable panel */
  resize: both;
  min-width: 360px;
  min-height: 240px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
}
.math-dock-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid #e5e5e5;
  background: linear-gradient(to bottom, #fff, #f7f7ff);
  cursor: move;
  user-select: none;
}
.math-dock-title {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.9;
}
.math-dock-body {
  padding: 10px;
  flex: 1 1 auto;
  overflow: auto;
}
.math-dock-body math-field {
  width: 100%;
  min-height: 44px;
}
.math-dock-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  padding: 8px 10px;
  border-top: 1px solid #eee;
}
.math-dock-btn {
  border: 1px solid #ccc;
  background: white;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}
.math-dock-btn--primary {
  border-color: #2c7be5;
  background: #2c7be5;
  color: white;
}

/* Publish/link states (moved from inline <style> in doceditor.html) */
#publish-btn.published {
  background-color: #4CAF50 !important;
  color: white !important;
  font-weight: bold;
}
#publish-btn.published:hover {
  background-color: #45a049 !important;
}
#link-btn.flash {
  animation: flash 0.3s ease-in-out;
}
@keyframes flash {
  0%, 100% { background-color: transparent; }
  50% { background-color: #4CAF50; }
}

/* Floating feature toolbar (doceditor.html) */
.feature-fly-toolbar {
  position: fixed;
  top: -1000px;
  left: -1000px;
  display: none;
  /* Keep below the top header (main.html z-index: 1000) */
  z-index: 910;
  background: rgba(255,255,255,0.95);
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  padding: 4px;
  gap: 2px;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.feature-control-btn {
  border: none;
  background: transparent;
  cursor: pointer;
}

.feature-control-btn--gear { font-size: 14px; }
.feature-control-btn--close { font-size: 16px; line-height: 1; }

/* Static feature controls toolbar (created in doceditor.js) */
.feature-static-controls {
  background: rgba(255,255,255,0.95);
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  padding: 4px;
  display: none;
  gap: 2px;
  align-items: center;
}

/* Generic editor modals (created in doceditor.js) */
.editor-modal {
  background-color: lightgrey;
  border-radius: 8px;
  padding: 20px;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
.editor-modal--wide { max-width: 600px; }

.editor-modal-header {
  margin-bottom: 15px;
  border-bottom: 1px solid #ccc;
  padding-bottom: 10px;
}
.editor-modal-title {
  margin: 0;
  font-size: 18px;
}
.editor-modal-group { margin-bottom: 20px; }
.editor-modal-group-title {
  margin: 0 0 10px 0;
  font-size: 16px;
  color: #333;
}
.editor-modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  gap: 8px;
}
.editor-modal-charbtn {
  padding: 10px;
  font-size: 20px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background-color: white;
  cursor: pointer;
  transition: background-color 0.2s;
}
.editor-modal-charbtn:hover { background-color: #f0f0f0; }

.editor-modal-scroll {
  margin-bottom: 20px;
  max-height: 400px;
  overflow-y: auto;
}
.editor-modal-checkbox-row {
  display: flex;
  align-items: center;
  padding: 5px;
  cursor: pointer;
}
.editor-modal-checkbox { margin-right: 10px; cursor: pointer; }
.editor-modal-checkbox-label { cursor: pointer; flex: 1; }

.editor-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.editor-modal-btn {
  padding: 8px 16px;
  cursor: pointer;
  border: 1px solid #ccc;
  border-radius: 4px;
  background-color: #f5f5f5;
}
.editor-modal-btn--primary {
  background-color: #4CAF50;
  color: white;
}

/* Paragraph context menu — AI icon row (doceditor.js) */
#paragraph-context-menu {
  position: fixed;
  z-index: 10000;
  box-sizing: border-box;
  margin: 0;
  padding: 1px;
  min-width: 0;
  max-width: 100vw;
  overflow: hidden;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  font-family: Arial, sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
}

.paragraph-context-menu__ai {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  box-sizing: border-box;
  width: 25px;
  height: 25px;
  min-width: 25px;
  min-height: 25px;
  max-width: 25px;
  max-height: 25px;
  padding: 0;
  margin: 0;
  line-height: 0;
  overflow: hidden;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
  border-radius: 2px;
  background: transparent;
}

.paragraph-context-menu__ai:hover {
  background: #f0f0f0;
}

.paragraph-context-menu__ai img {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  max-width: 25px;
  max-height: 25px;
  margin: 0;
  padding: 0;
  object-fit: contain;
  pointer-events: none;
}

/* ----------------------------
   Editor: Title / Subtitle
---------------------------- */

#doctitle,
#docsubtitle {
  font-family: inherit;
  line-height: 1.25;
  outline: none;
  box-shadow: none;
  border: none;
  padding: 10px;
  text-align: center;
}

#doc-page.doc-shell--edit #doctitle,
#doc-page.doc-shell--edit #docsubtitle {
  border: 1px dashed lightgrey;
}

#doctitle {
  display: none; /* toggled by toolbar */
  min-height: 50px;
  font-weight: 600;
  font-size: 24px;
  margin-top: 5px;
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#docsubtitle {
  display: none; /* toggled by toolbar */
  min-height: 28px;
  font-weight: 400;
  font-size: 14px;
  color: #555;
  margin-top: 0;
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#doctitle:empty:before,
#docsubtitle:empty:before {
  content: attr(data-placeholder);
  color: #999;
  font-weight: normal;
}

#doc-page.doc-shell--edit #doctitle:focus,
#doc-page.doc-shell--edit #docsubtitle:focus {
  border: 1px dashed lightgrey;
  outline: none;
  box-shadow: none;
}

#doctitle:focus-visible,
#docsubtitle:focus-visible {
  outline: none;
  box-shadow: none;
}

/* Document editor — dark mode (toolbar, title band, floating panels) */
body.dark-mode #edit-tools .edit-tools-btn,
html.dark-mode #edit-tools .edit-tools-btn {
  background-color: #2d3748;
  border-color: #4a5568;
  color: #e2e8f0;
}
body.dark-mode #edit-tools .edit-tools-btn:hover:not(:disabled),
html.dark-mode #edit-tools .edit-tools-btn:hover:not(:disabled) {
  background-color: #3d4e69;
  border-color: #718096;
}
body.dark-mode #edit-tools .edit-tools-btn:active:not(:disabled),
html.dark-mode #edit-tools .edit-tools-btn:active:not(:disabled) {
  background-color: #4a5f7a;
}

body.dark-mode #doctitle,
body.dark-mode #docsubtitle,
html.dark-mode #doctitle,
html.dark-mode #docsubtitle {
  background-color: transparent;
  border-color: #555;
  color: #f1f5f9;
}
body.dark-mode #docsubtitle,
html.dark-mode #docsubtitle {
  color: #94a3b8;
}
body.dark-mode #doctitle:empty:before,
body.dark-mode #docsubtitle:empty:before,
html.dark-mode #doctitle:empty:before,
html.dark-mode #docsubtitle:empty:before {
  color: #64748b;
}
body.dark-mode #doctitle:focus,
body.dark-mode #docsubtitle:focus,
html.dark-mode #doctitle:focus,
html.dark-mode #docsubtitle:focus {
  border-color: #64748b;
}

body.dark-mode .feature-fly-toolbar,
html.dark-mode .feature-fly-toolbar {
  background: rgba(30, 41, 59, 0.97);
  border-color: #4a5568;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}
body.dark-mode .feature-static-controls,
html.dark-mode .feature-static-controls {
  background: rgba(30, 41, 59, 0.97);
  border-color: #4a5568;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}
body.dark-mode .feature-control-btn,
html.dark-mode .feature-control-btn {
  color: #e2e8f0;
}
body.dark-mode .feature-control-btn:hover,
html.dark-mode .feature-control-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

body.dark-mode .math-dock,
html.dark-mode .math-dock {
  background: rgba(30, 33, 40, 0.98);
  border-color: #4a5568;
}
body.dark-mode .math-dock-header,
html.dark-mode .math-dock-header {
  background: linear-gradient(to bottom, #2d333b, #252830);
  border-bottom-color: #4a5568;
}
body.dark-mode .math-dock-title,
html.dark-mode .math-dock-title {
  color: #e2e8f0;
}
body.dark-mode .math-dock-actions,
html.dark-mode .math-dock-actions {
  border-top-color: #4a5568;
}
body.dark-mode .math-dock-btn,
html.dark-mode .math-dock-btn {
  border-color: #5c6778;
  background: #2d3748;
  color: #e2e8f0;
}
body.dark-mode .math-dock-btn:hover:not(:disabled),
html.dark-mode .math-dock-btn:hover:not(:disabled) {
  background: #3d4e69;
}

body.dark-mode .editor-modal,
html.dark-mode .editor-modal {
  background-color: #2d333b;
  color: #e8eaef;
  border: 1px solid #4a5568;
}
body.dark-mode .editor-modal-header,
html.dark-mode .editor-modal-header {
  border-bottom-color: #4a5568;
}
body.dark-mode .editor-modal-title,
html.dark-mode .editor-modal-title {
  color: #f1f5f9;
}
body.dark-mode .editor-modal-group-title,
html.dark-mode .editor-modal-group-title {
  color: #cbd5e1;
}
body.dark-mode .editor-modal-charbtn,
html.dark-mode .editor-modal-charbtn {
  background-color: #374151;
  border-color: #5c6778;
  color: #e8eaef;
}
body.dark-mode .editor-modal-charbtn:hover,
html.dark-mode .editor-modal-charbtn:hover {
  background-color: #4b5563;
}
body.dark-mode .editor-modal-btn,
html.dark-mode .editor-modal-btn {
  background-color: #374151;
  border-color: #5c6778;
  color: #e8eaef;
}
body.dark-mode .editor-modal-btn:hover:not(:disabled),
html.dark-mode .editor-modal-btn:hover:not(:disabled) {
  background-color: #4b5563;
}

body.dark-mode #paragraph-context-menu,
html.dark-mode #paragraph-context-menu {
  background: #2d333b;
  border-color: #4a5568;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}
body.dark-mode .paragraph-context-menu__ai:hover,
html.dark-mode .paragraph-context-menu__ai:hover {
  background: #3d4654;
}

/* ----------------------------
   Editor: Overlays / Menus (charts, calcs, etc.)
---------------------------- */

body.dark-mode .settings-container,
body.dark-mode .analysis-menu {
  background-color: #2d2d2d;
  color: #e0e0e0;
}

/* Overlay styles */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Popup rows (charts/calcs picker): never use bare `.container` — third-party CSS targets it */
.editor-menu-card {
  box-sizing: border-box;
}

.analysis-menu-error {
  margin: 12px 8px 8px;
  padding: 10px 12px;
  color: #5c2a2a;
  background: #fdecec;
  border-radius: 6px;
  font-size: 14px;
}

/* Analysis popup container */
.analysis-menu {
  background-color: #d3d3d3;
  width: fit-content;
  max-width: 90vw;
  max-height: 90vh;
  height: fit-content;
  border-radius: 8px;
  padding: 40px 50px 15px 15px;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Chart/calc picker rows: simple button-like [icon][name] entries */
.chart-menu-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background-color: #bcbcbc;
  color: #222;
  cursor: pointer;
  font: inherit;
  text-align: left;
  box-sizing: border-box;
  white-space: nowrap;
}
.chart-menu-row:hover,
.chart-menu-row:focus-visible {
  background-color: #a8a8a8;
  outline: none;
}
.chart-menu-row__icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: block;
  pointer-events: none;
}
.chart-menu-row__label {
  font-size: 14px;
  color: inherit;
  pointer-events: none;
}
body.dark-mode .chart-menu-row,
html.dark-mode .chart-menu-row {
  background-color: #3a3a3a !important;
  color: #eaeaea !important;
}
body.dark-mode .chart-menu-row:hover,
body.dark-mode .chart-menu-row:focus-visible,
html.dark-mode .chart-menu-row:hover,
html.dark-mode .chart-menu-row:focus-visible {
  background-color: #4a4a4a !important;
}

.analysis-menu h2 {
  margin-top: 0;
}

/* Settings container for feature overlay */
.settings-container {
  /* Feature settings overlay should be lightgrey (distinct from doc content) */
  background-color: #d3d3d3;
  width: 50%;
  height: 80%;
  border-radius: 8px;
  padding: 20px;
  overflow: hidden; /* only the content area scrolls */
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  box-sizing: border-box;
}

.settings-container h2 {
  margin-top: 0;
}

/* Scrollable body of the settings dialog */
.settings-content {
  flex: 1 1 auto;
  min-height: 0; /* required for overflow to work in flex children */
  overflow-y: auto;
  padding-right: 2px;
}

/* Settings button container (at bottom, NOT in scroller) */
.settings-button-container {
  margin-top: 12px;
  padding-top: 12px;
  background-color: inherit;
  border-top: 1px solid #e0e0e0;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  box-sizing: border-box;
}

/* Settings close button */
.settings-close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 24px;
  border: none;
  background: transparent;
  cursor: pointer;
}

/* Phone: feature settings (including formula/math) should fill screen and scroll cleanly */
@media (max-width: 768px) {
  .settings-container {
    width: 100vw;
    height: 100dvh;
    max-width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
    padding: calc(env(safe-area-inset-top, 0px) + 12px) 10px calc(env(safe-area-inset-bottom, 0px) + 10px) 10px;
    box-sizing: border-box;
  }

  .settings-container h2 {
    margin-right: 34px; /* keep title clear of × close button */
    font-size: 18px;
  }

  .settings-content {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-right: 0;
  }

  .settings-button-container {
    position: sticky;
    bottom: 0;
    padding-bottom: 2px;
  }

  .analysis-menu {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 16px);
    min-height: min(45dvh, 420px);
    padding: 38px 12px 12px;
    box-sizing: border-box;
  }
}

/* Overlay close button */
.overlay-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  font-size: 24px;
  border: none;
  background: transparent;
  cursor: pointer;
}

/* Dialogue message box */
.dialogue-message {
  background-color: lightgrey;
  padding: 10px;
  border-radius: 5px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  font-family: Arial, sans-serif;
  font-size: 16px;
  text-align: center;
}

/* Menu button styles */
.menubutton {
  padding: 8px 16px;
  cursor: pointer;
  border: 1px solid #ccc;
  background-color: #f5f5f5;
  border-radius: 4px;
  font-family: Arial, sans-serif;
  font-size: 14px;
  transition: background-color 0.2s;
}

.menubutton:hover {
  background-color: #e0e0e0;
}

.child.expanded {
  padding: 8px 12px;
}

/* File dialog style buttons (match fileDialogueBox look) */
.file-dialog-button {
  padding: 8px 16px;
  cursor: pointer;
  border: 1px solid #ccc;
  background-color: #f5f5f5;
  border-radius: 4px;
  font-family: Arial, sans-serif;
  font-size: 14px;
  transition: background-color 0.2s;
}

.file-dialog-button:hover {
  background-color: #e0e0e0;
}