/**
 * FogEditor - Portable Lite Word / Google Docs WYSIWYG Textarea Editor
 * Standalone stylesheet - scoped with .fe-* to prevent host-site CSS collisions.
 * Works with Font Awesome 6 (Free or Pro) and gracefully falls back if omitted.
 */

/* ==========================================================================
   Theme Variables (Dark Mode by default; add .fe-theme-light for Light Mode)
   ========================================================================== */
.fe-wrapper,
.fe-dropdown,
.fe-modal-backdrop,
.fe-wrapper.fe-theme-dark,
.fe-dropdown.fe-theme-dark,
.fe-modal-backdrop.fe-theme-dark {
  --fe-bg: #181a1e;
  --fe-canvas-bg: #181a1e;
  --fe-chrome-bg: #22252a;
  --fe-menubar-bg: #1a1c20;
  --fe-surface: #282c32;
  --fe-surface-hover: #353a42;
  --fe-surface-active: #274066;
  --fe-border: #383d46;
  --fe-border-strong: #4c535f;
  --fe-text: #e8eaed;
  --fe-text-muted: #9aa0a6;
  --fe-accent: #6ea8fe;
  --fe-accent-hover: #8bb9fe;
  --fe-accent-soft: rgba(110, 168, 254, 0.18);
  --fe-danger: #f28b82;
  --fe-danger-soft: rgba(242, 139, 130, 0.16);
  --fe-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  --fe-shadow-lg: 0 12px 34px rgba(0, 0, 0, 0.65);
  --fe-radius: 6px;
  --fe-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.fe-wrapper.fe-theme-light,
.fe-dropdown.fe-theme-light,
.fe-modal-backdrop.fe-theme-light {
  --fe-bg: #ffffff;
  --fe-canvas-bg: #ffffff;
  --fe-chrome-bg: #f8f9fa;
  --fe-menubar-bg: #f1f3f4;
  --fe-surface: #ffffff;
  --fe-surface-hover: #e8eaed;
  --fe-surface-active: #d3e3fd;
  --fe-border: #dadce0;
  --fe-border-strong: #bdc1c6;
  --fe-text: #202124;
  --fe-text-muted: #5f6368;
  --fe-accent: #1a73e8;
  --fe-accent-hover: #1557b0;
  --fe-accent-soft: #e8f0fe;
  --fe-danger: #d93025;
  --fe-danger-soft: #fce8e6;
  --fe-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
  --fe-shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.25);
}

/* ==========================================================================
   Host-Site CSS Contamination Shield
   Prevents global site rules (e.g. I { color }, TABLE#fancy, FORM#fncy)
   from leaking into FogEditor buttons, icons, menus, quickbars, and modals.
   ========================================================================== */
.fe-wrapper,
.fe-wrapper *,
.fe-dropdown,
.fe-dropdown *,
.fe-modal-backdrop,
.fe-modal-backdrop * {
  box-sizing: border-box !important;
  text-shadow: none !important;
}

.fe-wrapper i,
.fe-dropdown i,
.fe-modal-backdrop i {
  color: inherit !important;
  font-style: normal !important;
  background: transparent !important;
  border: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  line-height: 1 !important;
  vertical-align: middle !important;
  text-decoration: none !important;
  box-shadow: none !important;
}

.fe-wrapper .fe-btn,
.fe-wrapper .fe-menu-trigger,
.fe-wrapper .fe-mini-btn,
.fe-wrapper .fe-wordcount-btn,
.fe-wrapper .fe-path-crumb,
.fe-dropdown .fe-dropdown-item,
.fe-dropdown .fe-emoji-tab,
.fe-dropdown .fe-emoji-btn,
.fe-modal-backdrop .fe-modal-btn,
.fe-modal-backdrop .fe-modal-close,
.fe-modal-backdrop .fe-char-btn,
.fe-modal-backdrop .fe-charmap-tab {
  font-family: var(--fe-font) !important;
  text-decoration: none !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  box-shadow: none !important;
  background-image: none !important;
}

.fe-wrapper .fe-btn {
  color: var(--fe-text) !important;
  background-color: transparent !important;
}

.fe-wrapper .fe-btn:hover:not(:disabled) {
  background-color: var(--fe-surface-hover) !important;
  color: var(--fe-text) !important;
}

.fe-wrapper .fe-btn.fe-active,
.fe-wrapper .fe-btn.fe-open {
  background-color: var(--fe-surface-active) !important;
  color: var(--fe-accent) !important;
}

.fe-wrapper .fe-menu-trigger {
  color: var(--fe-text) !important;
  background-color: transparent !important;
  font-size: 12.5px !important;
  font-weight: 500 !important;
}

.fe-wrapper .fe-menu-trigger:hover {
  background-color: var(--fe-surface-hover) !important;
  color: var(--fe-text) !important;
}

.fe-wrapper .fe-menu-trigger.fe-open {
  background-color: var(--fe-surface-active) !important;
  color: var(--fe-accent) !important;
}

.fe-wrapper .fe-split-btn {
  background-color: var(--fe-surface) !important;
  border-color: var(--fe-border) !important;
}

.fe-wrapper .fe-mini-btn {
  background-color: var(--fe-surface) !important;
  color: var(--fe-text) !important;
  border: 1px solid var(--fe-border-strong) !important;
  font-size: 12px !important;
}

.fe-wrapper .fe-mini-btn:hover {
  background-color: var(--fe-surface-hover) !important;
}

.fe-wrapper .fe-mini-btn.fe-primary {
  background-color: var(--fe-accent) !important;
  border-color: var(--fe-accent) !important;
  color: #ffffff !important;
}

.fe-wrapper .fe-mini-btn.fe-primary:hover {
  background-color: var(--fe-accent-hover) !important;
}

.fe-wrapper a.fe-quickbar-url,
.fe-wrapper a.fe-quickbar-url:visited,
.fe-wrapper a.fe-quickbar-url:hover {
  font-family: var(--fe-font) !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  color: var(--fe-accent) !important;
  background: transparent !important;
}

.fe-wrapper .fe-statusbar,
.fe-wrapper .fe-wordcount-btn,
.fe-wrapper .fe-path-crumb,
.fe-wrapper .fe-resize-handle {
  color: var(--fe-text-muted) !important;
  font-family: var(--fe-font) !important;
  font-size: 11.5px !important;
}

.fe-wrapper .fe-wordcount-btn:hover,
.fe-wrapper .fe-path-crumb:hover {
  background-color: var(--fe-surface-hover) !important;
  color: var(--fe-text) !important;
}

.fe-dropdown .fe-dropdown-item {
  color: var(--fe-text) !important;
  background-color: transparent !important;
  font-size: 13px !important;
}

.fe-dropdown .fe-dropdown-item:hover:not(:disabled) {
  background-color: var(--fe-surface-hover) !important;
}

.fe-dropdown .fe-dropdown-item.fe-active {
  background-color: var(--fe-accent-soft) !important;
  color: var(--fe-accent) !important;
}

.fe-dropdown .fe-dropdown-item-left i {
  color: var(--fe-text-muted) !important;
}

.fe-dropdown .fe-dropdown-item.fe-active .fe-dropdown-item-left i {
  color: var(--fe-accent) !important;
}

.fe-modal-backdrop .fe-modal-title {
  font-family: var(--fe-font) !important;
  font-size: 15px !important;
  font-weight: 600 !important;
  color: var(--fe-text) !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
}

.fe-modal-backdrop .fe-input,
.fe-modal-backdrop .fe-select,
.fe-modal-backdrop .fe-textarea,
.fe-dropdown .fe-color-hex,
.fe-dropdown .fe-emoji-search {
  background-color: var(--fe-bg) !important;
  color: var(--fe-text) !important;
  border: 1px solid var(--fe-border-strong) !important;
  font-family: var(--fe-font) !important;
  box-shadow: none !important;
  margin: 0 !important;
}

.fe-modal-backdrop .fe-textarea {
  font-family: "Cascadia Code", Consolas, "Courier New", monospace !important;
}

.fe-modal-backdrop .fe-modal-btn {
  background-color: var(--fe-surface) !important;
  border: 1px solid var(--fe-border-strong) !important;
  color: var(--fe-text) !important;
}

.fe-modal-backdrop .fe-modal-btn:hover {
  background-color: var(--fe-surface-hover) !important;
}

.fe-modal-backdrop .fe-modal-btn-primary {
  background-color: var(--fe-accent) !important;
  border-color: var(--fe-accent) !important;
  color: #ffffff !important;
}

.fe-modal-backdrop .fe-modal-btn-primary:hover {
  background-color: var(--fe-accent-hover) !important;
}

.fe-modal-backdrop .fe-modal-btn-danger {
  background-color: var(--fe-danger-soft) !important;
  border-color: var(--fe-danger) !important;
  color: var(--fe-danger) !important;
}

.fe-modal-backdrop .fe-modal-close {
  background: transparent !important;
  color: var(--fe-text-muted) !important;
}

.fe-modal-backdrop .fe-modal-close:hover {
  background-color: var(--fe-surface-hover) !important;
  color: var(--fe-text) !important;
}

.fe-modal-backdrop .fe-info-table,
.fe-modal-backdrop .fe-info-table th,
.fe-modal-backdrop .fe-info-table td {
  font-family: var(--fe-font) !important;
  font-size: 13px !important;
  color: var(--fe-text) !important;
  background-image: none !important;
}

.fe-modal-backdrop .fe-info-table th {
  color: var(--fe-text-muted) !important;
  background-color: var(--fe-chrome-bg) !important;
}

/* ==========================================================================
   Main Editor Wrapper
   ========================================================================== */
.fe-wrapper {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin: 4px 0 8px 0;
  background: var(--fe-bg);
  border: 1px solid var(--fe-border);
  border-radius: var(--fe-radius);
  font-family: var(--fe-font) !important;
  font-size: 13px !important;
  line-height: 1.4 !important;
  color: var(--fe-text) !important;
  text-align: left !important;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.fe-wrapper.fe-focused {
  border-color: var(--fe-accent);
  box-shadow: 0 0 0 2px var(--fe-accent-soft);
}

.fe-wrapper.fe-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-height: none !important;
  margin: 0 !important;
  border-radius: 0 !important;
  border: none !important;
  z-index: 99990 !important;
}

.fe-wrapper.fe-fullscreen .fe-body {
  flex: 1 1 auto;
  height: auto !important;
  max-height: none !important;
}

.fe-textarea-hidden {
  display: none !important;
}

/* ==========================================================================
   Menubar (Google Docs / Word style)
   ========================================================================== */
.fe-menubar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 3px 8px;
  background: var(--fe-menubar-bg);
  border-bottom: 1px solid var(--fe-border);
  user-select: none;
}

.fe-menu-trigger {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 8px;
  margin: 0;
  font-family: var(--fe-font);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--fe-text);
  cursor: pointer;
  line-height: 1.4;
  text-shadow: none;
  box-shadow: none;
  transition: background 0.1s ease;
}

.fe-menu-trigger:hover,
.fe-menu-trigger.fe-open {
  background: var(--fe-surface-hover);
}

.fe-menu-trigger.fe-open {
  background: var(--fe-surface-active);
  color: var(--fe-accent);
}

/* ==========================================================================
   Toolbar
   ========================================================================== */
.fe-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 5px 8px;
  background: var(--fe-chrome-bg);
  border-bottom: 1px solid var(--fe-border);
  user-select: none;
}

.fe-toolbar-group {
  display: inline-flex;
  align-items: center;
  gap: 1px;
}

.fe-toolbar-sep {
  display: inline-block;
  width: 1px;
  height: 20px;
  margin: 0 5px;
  background: var(--fe-border);
  flex-shrink: 0;
}

.fe-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  margin: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--fe-text);
  font-family: var(--fe-font);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  text-shadow: none;
  box-shadow: none;
  transition: background 0.1s ease, color 0.1s ease, border-color 0.1s ease;
  white-space: nowrap;
}

.fe-btn:hover:not(:disabled) {
  background: var(--fe-surface-hover);
}

.fe-btn:active:not(:disabled) {
  background: var(--fe-surface-active);
}

.fe-btn.fe-active {
  background: var(--fe-surface-active);
  color: var(--fe-accent);
  border-color: rgba(26, 115, 232, 0.25);
}

.fe-btn:disabled,
.fe-btn.fe-disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.fe-btn i {
  font-size: 13px;
  pointer-events: none;
}

.fe-btn .fe-caret {
  font-size: 9px;
  opacity: 0.7;
  margin-left: 1px;
}

/* Custom select-like dropdown triggers (blocks, fontfamily, fontsize) */
.fe-select-btn {
  justify-content: space-between;
  padding: 0 7px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 500;
}

.fe-select-btn:hover:not(:disabled) {
  border-color: var(--fe-border);
}

.fe-select-btn.fe-select-blocks {
  min-width: 96px;
  max-width: 112px;
}

.fe-select-btn.fe-select-font {
  min-width: 98px;
  max-width: 118px;
}

.fe-select-btn.fe-select-size {
  min-width: 58px;
}

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

/* Color picker toolbar button */
.fe-color-btn {
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  overflow: hidden;
}

.fe-color-main {
  flex-direction: column;
  gap: 2px;
  padding: 2px 5px;
  min-width: 26px;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.fe-color-bar {
  display: block;
  width: 14px;
  height: 3px;
  border-radius: 1px;
  background: #202124;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.fe-color-caret {
  min-width: 15px;
  padding: 0 3px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/* Custom Split Button (e.g., FogML) */
.fe-split-btn {
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  border: 1px solid var(--fe-border);
  background: var(--fe-surface);
  overflow: hidden;
}

.fe-split-btn .fe-split-main {
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 0;
  border: none;
}

.fe-split-btn .fe-split-caret {
  height: 26px;
  min-width: 18px;
  padding: 0 4px;
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--fe-border);
}

/* ==========================================================================
   Draft Restore Banner & Find/Replace Bar
   ========================================================================== */
.fe-draft-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 12px;
  background: var(--fe-accent-soft);
  border-bottom: 1px solid var(--fe-border);
  font-size: 12px;
  color: var(--fe-text);
}

.fe-draft-actions {
  display: inline-flex;
  gap: 6px;
}

.fe-findbar {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--fe-chrome-bg);
  border-bottom: 1px solid var(--fe-border);
}

.fe-findbar.fe-visible {
  display: flex;
}

.fe-find-input {
  appearance: none !important;
  width: 170px !important;
  height: 28px !important;
  padding: 3px 8px !important;
  margin: 0 !important;
  background: var(--fe-surface) !important;
  color: var(--fe-text) !important;
  border: 1px solid var(--fe-border-strong) !important;
  border-radius: 4px !important;
  font-family: var(--fe-font) !important;
  font-size: 12.5px !important;
  box-shadow: none !important;
}

.fe-find-input:focus {
  outline: none !important;
  border-color: var(--fe-accent) !important;
  background: var(--fe-surface) !important;
  color: var(--fe-text) !important;
}

.fe-find-count {
  font-size: 11.5px;
  color: var(--fe-text-muted);
  min-width: 58px;
  text-align: center;
}

.fe-mini-btn {
  appearance: none;
  height: 26px;
  padding: 0 9px;
  margin: 0;
  background: var(--fe-surface);
  color: var(--fe-text);
  border: 1px solid var(--fe-border-strong);
  border-radius: 4px;
  font-family: var(--fe-font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  line-height: 1;
  text-shadow: none;
  box-shadow: none;
}

.fe-mini-btn:hover {
  background: var(--fe-surface-hover);
}

.fe-mini-btn.fe-primary {
  background: var(--fe-accent);
  border-color: var(--fe-accent);
  color: #ffffff;
}

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

/* ==========================================================================
   Editor Canvas Body (iframe + Source Code textarea)
   ========================================================================== */
.fe-body {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 160px;
  background: var(--fe-canvas-bg);
}

.fe-iframe {
  display: block;
  width: 100%;
  height: 100%;
  flex: 1 1 auto;
  border: 0;
  margin: 0;
  padding: 0;
  background: transparent;
}

.fe-source {
  display: none !important;
  width: 100% !important;
  height: 100% !important;
  flex: 1 1 auto !important;
  margin: 0 !important;
  padding: 12px !important;
  border: 0 !important;
  outline: none !important;
  resize: none !important;
  background: #1e1e1e !important;
  color: #d4d4d4 !important;
  font-family: "Cascadia Code", Consolas, "Courier New", monospace !important;
  font-size: 13px !important;
  line-height: 1.55 !important;
  box-shadow: none !important;
  tab-size: 2;
}

.fe-wrapper.fe-source-mode .fe-iframe {
  display: none !important;
}

.fe-wrapper.fe-source-mode .fe-source {
  display: block !important;
}

.fe-wrapper.fe-source-mode .fe-toolbar .fe-btn:not([data-fe-cmd="code"]):not([data-fe-cmd="fullscreen"]):not([data-fe-cmd="cleanword"]):not(.fe-split-main):not(.fe-split-caret),
.fe-wrapper.fe-source-mode .fe-toolbar .fe-color-btn {
  opacity: 0.35;
  pointer-events: none;
}

/* ==========================================================================
   Floating Contextual Quickbar (Link / Image / Table)
   ========================================================================== */
.fe-quickbar {
  position: absolute;
  display: none;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  background: var(--fe-surface);
  border: 1px solid var(--fe-border);
  border-radius: 6px;
  box-shadow: var(--fe-shadow);
  z-index: 25;
  max-width: calc(100% - 16px);
  flex-wrap: wrap;
}

.fe-quickbar.fe-visible {
  display: inline-flex;
}

.fe-quickbar-url {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--fe-accent);
  text-decoration: none;
  padding: 0 6px;
}

.fe-quickbar-url:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Status Bar
   ========================================================================== */
.fe-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 26px;
  padding: 2px 8px;
  background: var(--fe-chrome-bg);
  border-top: 1px solid var(--fe-border);
  font-size: 11.5px;
  color: var(--fe-text-muted);
  user-select: none;
}

.fe-path {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.fe-path-crumb {
  appearance: none;
  background: transparent;
  border: none;
  padding: 1px 4px;
  margin: 0;
  border-radius: 3px;
  font-family: var(--fe-font);
  font-size: 11.5px;
  color: var(--fe-text-muted);
  cursor: pointer;
}

.fe-path-crumb:hover {
  background: var(--fe-surface-hover);
  color: var(--fe-text);
}

.fe-path-sep {
  opacity: 0.5;
}

.fe-status-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.fe-status-notice {
  display: none;
  padding: 1px 8px;
  border-radius: 10px;
  background: var(--fe-accent-soft);
  color: var(--fe-accent);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.fe-status-notice.fe-visible {
  display: inline-block;
}

.fe-wordcount-btn {
  appearance: none;
  background: transparent;
  border: none;
  padding: 2px 5px;
  margin: 0;
  border-radius: 3px;
  font-family: var(--fe-font);
  font-size: 11.5px;
  color: var(--fe-text-muted);
  cursor: pointer;
}

.fe-wordcount-btn:hover {
  background: var(--fe-surface-hover);
  color: var(--fe-text);
}

.fe-resize-handle {
  width: 14px;
  height: 14px;
  cursor: ns-resize;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--fe-text-muted);
  opacity: 0.65;
}

.fe-resize-handle:hover {
  opacity: 1;
}

/* ==========================================================================
   Portaled Dropdowns (Appended to document.body)
   ========================================================================== */
.fe-dropdown {
  position: fixed;
  z-index: 100000;
  min-width: 185px;
  max-width: 340px;
  max-height: 380px;
  overflow-y: auto;
  padding: 4px 0;
  background: var(--fe-surface);
  border: 1px solid var(--fe-border);
  border-radius: var(--fe-radius);
  box-shadow: var(--fe-shadow);
  font-family: var(--fe-font);
  font-size: 13px;
  color: var(--fe-text);
  text-align: left;
}

.fe-dropdown-item {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 7px 12px;
  margin: 0;
  background: transparent;
  border: 0;
  color: var(--fe-text);
  font-family: var(--fe-font);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  text-shadow: none;
  box-shadow: none;
}

.fe-dropdown-item:hover:not(:disabled) {
  background: var(--fe-surface-hover);
}

.fe-dropdown-item.fe-active {
  background: var(--fe-accent-soft);
  color: var(--fe-accent);
  font-weight: 600;
}

.fe-dropdown-item:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.fe-dropdown-item-left {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.fe-dropdown-item-left i {
  width: 15px;
  text-align: center;
  color: var(--fe-text-muted);
  font-size: 13px;
  flex-shrink: 0;
}

.fe-dropdown-item.fe-active .fe-dropdown-item-left i {
  color: var(--fe-accent);
}

.fe-shortcut {
  font-size: 11px;
  color: var(--fe-text-muted);
  margin-left: auto;
  white-space: nowrap;
}

.fe-dropdown-sep {
  height: 1px;
  margin: 4px 0;
  background: var(--fe-border);
}

/* Color Picker Dropdown */
.fe-color-popover {
  padding: 10px;
  width: 244px;
}

.fe-color-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}

.fe-color-swatch {
  appearance: none;
  width: 19px;
  height: 19px;
  padding: 0;
  margin: 0;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  cursor: pointer;
  transition: transform 0.08s ease;
}

.fe-color-swatch:hover {
  transform: scale(1.18);
  border-color: var(--fe-accent);
}

.fe-color-custom-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--fe-border);
}

.fe-color-native {
  width: 30px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--fe-border-strong);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}

.fe-color-hex {
  width: 80px;
  height: 26px;
  padding: 2px 6px;
  border: 1px solid var(--fe-border-strong);
  border-radius: 4px;
  background: var(--fe-bg);
  color: var(--fe-text);
  font-family: monospace;
  font-size: 12px;
}

/* Table Grid Picker */
.fe-table-popover {
  padding: 10px;
  width: auto;
}

.fe-table-grid {
  display: grid;
  grid-template-columns: repeat(8, 18px);
  gap: 3px;
  margin-bottom: 8px;
}

.fe-table-cell {
  width: 18px;
  height: 18px;
  border: 1px solid var(--fe-border-strong);
  border-radius: 2px;
  background: var(--fe-bg);
  cursor: pointer;
}

.fe-table-cell.fe-selected {
  background: var(--fe-accent-soft);
  border-color: var(--fe-accent);
}

.fe-table-dims {
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--fe-text-muted);
}

/* Emoji Picker Popover */
.fe-emoji-popover {
  padding: 8px;
  width: 292px;
}

.fe-emoji-search {
  width: 100%;
  height: 28px;
  padding: 4px 8px;
  margin-bottom: 6px;
  border: 1px solid var(--fe-border-strong);
  border-radius: 4px;
  background: var(--fe-bg);
  color: var(--fe-text);
  font-family: var(--fe-font);
  font-size: 12.5px;
}

.fe-emoji-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--fe-border);
  padding-bottom: 4px;
}

.fe-emoji-tab {
  appearance: none;
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 4px;
  padding: 4px;
  cursor: pointer;
  font-size: 15px;
}

.fe-emoji-tab:hover,
.fe-emoji-tab.fe-active {
  background: var(--fe-surface-active);
}

.fe-emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-height: 200px;
  overflow-y: auto;
}

.fe-emoji-btn {
  appearance: none;
  background: transparent;
  border: none;
  border-radius: 4px;
  height: 30px;
  font-size: 17px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fe-emoji-btn:hover {
  background: var(--fe-surface-hover);
}

/* ==========================================================================
   Portaled Modals (Appended to document.body)
   ========================================================================== */
.fe-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100010;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.55);
  font-family: var(--fe-font);
  font-size: 13px;
  color: var(--fe-text);
  text-align: left;
}

.fe-modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  background: var(--fe-surface);
  border: 1px solid var(--fe-border);
  border-radius: 8px;
  box-shadow: var(--fe-shadow-lg);
  overflow: hidden;
}

.fe-modal.fe-modal-lg {
  max-width: 720px;
}

.fe-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--fe-border);
  background: var(--fe-chrome-bg);
}

.fe-modal-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--fe-text);
}

.fe-modal-close {
  appearance: none;
  background: transparent;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  color: var(--fe-text-muted);
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.fe-modal-close:hover {
  background: var(--fe-surface-hover);
  color: var(--fe-text);
}

.fe-modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fe-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fe-field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--fe-text-muted);
}

.fe-row {
  display: flex;
  gap: 10px;
}

.fe-row > .fe-field {
  flex: 1;
}

.fe-input,
.fe-select,
.fe-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--fe-border-strong);
  border-radius: 5px;
  background: var(--fe-bg);
  color: var(--fe-text);
  font-family: var(--fe-font);
  font-size: 13px;
  outline: none;
}

.fe-input:focus,
.fe-select:focus,
.fe-textarea:focus {
  border-color: var(--fe-accent);
  box-shadow: 0 0 0 2px var(--fe-accent-soft);
}

.fe-textarea {
  min-height: 120px;
  resize: vertical;
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: 12.5px;
}

.fe-checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
}

.fe-help-text {
  font-size: 11.5px;
  color: var(--fe-text-muted);
}

.fe-img-preview {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: var(--fe-chrome-bg);
  border: 1px dashed var(--fe-border-strong);
  border-radius: 5px;
  max-height: 160px;
  overflow: hidden;
}

.fe-img-preview.fe-visible {
  display: flex;
}

.fe-img-preview img {
  max-width: 100%;
  max-height: 140px;
  object-fit: contain;
}

.fe-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--fe-border);
  background: var(--fe-chrome-bg);
}

.fe-modal-btn {
  appearance: none;
  padding: 7px 14px;
  border-radius: 5px;
  border: 1px solid var(--fe-border-strong);
  background: var(--fe-surface);
  color: var(--fe-text);
  font-family: var(--fe-font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.fe-modal-btn:hover {
  background: var(--fe-surface-hover);
}

.fe-modal-btn-primary {
  background: var(--fe-accent);
  border-color: var(--fe-accent);
  color: #ffffff;
}

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

.fe-modal-btn-danger {
  background: var(--fe-danger-soft);
  border-color: var(--fe-danger);
  color: var(--fe-danger);
  margin-right: auto;
}

/* Charmap Modal */
.fe-charmap-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.fe-charmap-tab {
  appearance: none;
  padding: 5px 10px;
  border: 1px solid var(--fe-border);
  border-radius: 4px;
  background: var(--fe-bg);
  color: var(--fe-text);
  font-size: 12px;
  cursor: pointer;
}

.fe-charmap-tab.fe-active {
  background: var(--fe-accent);
  border-color: var(--fe-accent);
  color: #ffffff;
}

.fe-charmap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 4px;
  max-height: 260px;
  overflow-y: auto;
}

.fe-char-btn {
  appearance: none;
  height: 36px;
  border: 1px solid var(--fe-border);
  border-radius: 4px;
  background: var(--fe-bg);
  color: var(--fe-text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fe-char-btn:hover {
  background: var(--fe-accent-soft);
  border-color: var(--fe-accent);
}

/* Preview Modal Iframe */
.fe-preview-frame {
  width: 100%;
  height: 440px;
  border: 1px solid var(--fe-border);
  border-radius: 4px;
  background: #ffffff;
}

/* Stats / Shortcuts Table in Modal */
.fe-info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.fe-info-table th,
.fe-info-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--fe-border);
  text-align: left;
}

.fe-info-table th {
  font-weight: 600;
  color: var(--fe-text-muted);
  background: var(--fe-chrome-bg);
}

.fe-kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: monospace;
  font-size: 11.5px;
  background: var(--fe-chrome-bg);
  border: 1px solid var(--fe-border-strong);
  border-radius: 4px;
  color: var(--fe-text);
}

@media (max-width: 640px) {
  .fe-toolbar {
    padding: 4px;
  }
  .fe-row {
    flex-direction: column;
  }
  .fe-find-input {
    width: 130px !important;
  }
}
