/* --- Base Styles (from user's original file) --- */
.recipe-preview-content {
  font-family: "Lexend", Arial, "sans-serif";
  line-height: 1.6;
  color: #333;
}

/* --- UPDATED: Font styling for headings --- */
/* h1 (title) and h3 (unused) base styles */
.recipe-preview-content h1,
.recipe-preview-content h3 {
  /* font-family removed, will be applied by class */
  font-weight: 700;
  color: #222;
}
.recipe-preview-content h1 {
  text-align: center;
  border-bottom: 2px solid #eee;
  padding-bottom: 10px;
  font-size: 2.25rem; /* Tailwind text-4xl */
}
/* h2 (dynamic headings) gets base styles */
.recipe-preview-content h2 {
  font-weight: 700;
  color: #222;
  border-bottom: 1px solid #eee;
  padding-bottom: 5px;
  margin-top: 30px;
  font-size: 1.875rem; /* Tailwind text-3xl */
}

/* NEW: Dynamic font classes for h1 AND h2 */
.recipe-preview-content h1.font-style-display,
.recipe-preview-content h2.font-style-display {
  font-family: '"Baloo 2"', cursive;
}

.recipe-preview-content h1.font-style-serif,
.recipe-preview-content h2.font-style-serif {
  font-family: "Merriweather", serif;
}

.recipe-preview-content h1.font-style-sans,
.recipe-preview-content h2.font-style-sans {
  font-family: "Lexend", sans-serif;
}

.recipe-preview-content h3 {
  margin-top: 25px;
  font-style: normal;
  font-weight: 700;
  font-size: 1.5rem; /* Tailwind text-2xl */
}
/* --- End of heading font update --- */

.recipe-preview-content ul,
.recipe-preview-content ol {
  padding-left: 30px;
  list-style-position: outside;
}
.recipe-preview-content ol {
  list-style-type: decimal;
}
.recipe-preview-content ul {
  list-style-type: disc;
}
.recipe-preview-content li {
  margin-bottom: 10px;
}
.recipe-preview-content img {
  display: block;
  height: auto;
  margin: 20px auto;
  border-radius: 8px;
  background-color: #f0f0f0;
  object-fit: cover;
}

.recipe-preview-content p#recipe-desc-preview {
  text-align: center;
  font-style: italic;
  color: #555;
  margin-bottom: 1rem;
}
/* --- End of Original Styles --- */

/* --- New Plain Text Block Style --- */
.recipe-text-block {
  text-align: left;
  font-style: normal;
  color: #333;
  margin: 1rem 0;
  line-height: 1.6;
}

/* --- Rich text formatting output --- */
.rt-underline {
  text-decoration: underline;
}

.rt-strike {
  text-decoration: line-through;
}

.rt-scale {
  line-height: 1.35;
}

.rt-highlight {
  color: inherit;
  padding: 0 0.08em;
  border-radius: 0.18em;
}

.rt-highlight-y {
  background: #fef08a;
}

.rt-highlight-b {
  background: #bfdbfe;
}

.rt-highlight-g {
  background: #bbf7d0;
}

.rt-highlight-p {
  background: #fbcfe8;
}

/* --- Selection formatting toolbar --- */
.selection-format-toolbar {
  position: absolute;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
}

.selection-format-toolbar.hidden {
  display: none;
}

.selection-toolbar-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.selection-toolbar-btn {
  min-width: 34px;
  height: 30px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #f8fafc;
  color: #111827;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.selection-toolbar-btn:hover {
  background: #e2e8f0;
}

.selection-toolbar-palette {
  display: flex;
  align-items: center;
  gap: 6px;
  border-left: 1px solid #e5e7eb;
  padding-left: 8px;
}

.selection-toolbar-swatch {
  width: 22px;
  height: 22px;
  border-radius: 9999px;
  border: 2px solid #94a3b8;
  cursor: pointer;
}

.selection-toolbar-swatch.swatch-y {
  background: #fef08a;
}

.selection-toolbar-swatch.swatch-b {
  background: #bfdbfe;
}

.selection-toolbar-swatch.swatch-g {
  background: #bbf7d0;
}

.selection-toolbar-swatch.swatch-p {
  background: #fbcfe8;
}

/* --- Template gallery (shop-like slot grid) --- */
.template-slot-card {
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
  display: flex;
  flex-direction: column;
  min-height: 190px;
  gap: 10px;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease;
}

.template-slot-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.12);
  border-color: #cbd5e1;
}

.template-slot-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.template-slot-index {
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #475569;
  font-weight: 700;
}

.template-slot-badge {
  font-size: 0.72rem;
  line-height: 1;
  border-radius: 9999px;
  padding: 6px 9px;
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 700;
}

.template-slot-title {
  margin: 0;
  color: #0f172a;
  font-size: 1.05rem;
  font-weight: 700;
}

.template-slot-subtitle {
  margin: 0;
  color: #475569;
  font-size: 0.88rem;
  line-height: 1.35;
  flex-grow: 1;
}

.template-slot-action {
  width: 100%;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 10px 12px;
}

.template-slot-action-load {
  background: #2563eb;
  color: #ffffff;
}

.template-slot-action-load:hover {
  background: #1d4ed8;
}

.template-slot-empty {
  border-style: dashed;
  border-color: #93c5fd;
  background: linear-gradient(180deg, #f8fbff 0%, #eef6ff 100%);
}

.template-slot-empty .template-slot-badge {
  background: #e2e8f0;
  color: #334155;
}

.template-slot-action-add {
  background: #ffffff;
  color: #2563eb;
  border: 2px dashed #60a5fa;
  font-size: 1.75rem;
  line-height: 1;
  min-height: 64px;
}

.template-slot-action-add:hover {
  background: #eff6ff;
}

/* --- Top toolbar icon-only controls --- */
.top-toolbar-icon-btn {
  width: 42px;
  height: 42px;
  padding: 0;
}

/* --- New "Text Bubble" Style (Stylized as a sticky note) --- */
/* Base style for all "toasts" */
.toast-base {
  border-radius: 8px;
  padding: 12px 16px;
  margin: 20px 0;
  font-family: "Kalam", cursive; /* Playful font */
  font-size: 1.1rem; /* Slightly larger */
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.05);
  transform: rotate(-1deg); /* Slight playful tilt */
}
.toast-base::before {
  font-weight: 700;
  font-style: normal;
}

/* Note Style (Yellow) */
.toast-note {
  background-color: #fefce8; /* yellow-50 */
  border-left: 5px solid #eab308; /* yellow-500 */
  color: #713f12; /* yellow-900 */
}
.toast-note::before {
  content: "💡 Note: ";
}

/* Tip Style (Blue) */
.toast-tip {
  background-color: #e0f2fe; /* light-blue-100 */
  border-left: 5px solid #0ea5e9; /* sky-500 */
  color: #0c4a6e; /* sky-900 */
}
.toast-tip::before {
  content: "📘 Tip: ";
}

/* Warning Style (Red) */
.toast-warning {
  background-color: #fef2f2; /* red-50 */
  border-left: 5px solid #ef4444; /* red-500 */
  color: #991b1b; /* red-900 */
}
.toast-warning::before {
  content: "⚠️ Warning: ";
}

/* --- Builder & Print Styles --- */
/* Base style for all item buttons (move, delete) */
.item-btn {
  font-weight: bold;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  transition: all 0.2s ease;
}

/* New Move Button Styles */
.move-up-btn,
.move-down-btn {
  color: #3b82f6; /* blue-500 */
}
.move-up-btn:hover,
.move-down-btn:hover {
  color: #1d4ed8; /* blue-700 */
  transform: scale(1.25);
}
/* Class to hide arrows when at top/bottom */
.hidden-arrow {
  visibility: hidden;
  cursor: default;
}
.hidden-arrow:hover {
  transform: none;
  color: inherit;
}

.delete-btn {
  color: #ef4444; /* red-500 */
}
.delete-btn:hover {
  color: #b91c1c; /* red-700 */
  transform: scale(1.25) rotate(10deg); /* Added playful hover */
}

/* --- NEW: Material Icons Base Style --- */
.material-icons {
  font-family: "Material Icons";
  font-weight: normal;
  font-style: normal;
  font-size: 24px; /* Default icon size */
  display: inline-block;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "liga";
}

/* --- NEW: Inline Icon Style for Preview --- */
.recipe-preview-content .material-icons {
  font-size: 1.1em; /* Make icon match text size */
  vertical-align: -0.15em; /* Align icon nicely with text */
  line-height: 1;
}

/* --- Preview Mode (continuous vs paged) --- */
.paged-preview-shell {
  max-width: min(1400px, 96vw) !important;
}

.preview-layout {
  display: block;
}

.preview-stats {
  width: 220px;
  flex: 0 0 220px;
  align-self: flex-start;
  position: sticky;
  top: 24px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  padding: 14px;
}

.preview-stats-title {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 700;
  color: #111827;
}

.preview-stats-list {
  margin: 0;
}

.preview-stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid #f3f4f6;
  font-size: 0.94rem;
}

.preview-stats-row:first-child {
  border-top: none;
  padding-top: 0;
}

.preview-stats-row dt {
  color: #4b5563;
}

.preview-stats-row dd {
  margin: 0;
  font-weight: 700;
  color: #111827;
}

#recipe-panel.paged-preview-active .preview-layout {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 18px;
}

#recipe-panel.paged-preview-active #recipe-preview {
  --preview-page-width: 700px;
  --preview-page-gap: 28px;
  --preview-page-height: 980px;
  flex: 0 1 auto;
  width: min(calc(var(--preview-page-width) + 36px), 100%);
  max-width: 100%;
  margin: 0;
  padding: 14px !important;
  background: #e5e7eb;
  box-shadow: inset 0 0 0 1px #d1d5db;
  overflow: hidden;
}

#recipe-panel.paged-preview-active #recipe-flow {
  column-width: var(--preview-page-width);
  column-gap: var(--preview-page-gap);
  column-fill: auto;
  height: var(--preview-page-height);
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 28px;
  background: #ffffff;
  border-radius: 8px;
  box-sizing: border-box;
  scrollbar-gutter: stable both-edges;
}

#recipe-panel.paged-preview-active #recipe-content-preview {
  display: contents;
}

#recipe-panel.paged-preview-active #recipe-flow > * {
  break-inside: auto;
}

#recipe-panel.paged-preview-active #recipe-flow img,
#recipe-panel.paged-preview-active #recipe-flow h1,
#recipe-panel.paged-preview-active #recipe-flow h2,
#recipe-panel.paged-preview-active #recipe-flow h3,
#recipe-panel.paged-preview-active #recipe-flow ul,
#recipe-panel.paged-preview-active #recipe-flow ol,
#recipe-panel.paged-preview-active #recipe-flow .toast-base {
  break-inside: avoid-column;
}

@media (max-width: 1220px) {
  #recipe-panel.paged-preview-active .preview-layout {
    flex-direction: column;
    align-items: center;
  }

  #recipe-panel.paged-preview-active .preview-stats {
    position: static;
    width: min(760px, 100%);
    flex: 0 1 auto;
  }

  #recipe-panel.paged-preview-active #recipe-preview {
    width: min(760px, 100%);
  }
}

@media (max-width: 768px) {
  #recipe-panel.paged-preview-active #recipe-preview {
    --preview-page-width: 620px;
  }

  #recipe-panel.paged-preview-active #recipe-flow {
    --preview-page-height: 900px;
    padding: 20px;
  }
}

@media print {
  /* Hide the builder panel and all buttons */
  .builder-panel,
  .no-print,
  .preview-controls {
    display: none !important;
  }

  /* Make the recipe panel take full width */
  .recipe-panel {
    width: 100%;
    padding: 0;
    margin: 0;
    display: block !important; /* Ensure it's visible for print */
  }

  #preview-stats {
    display: none !important;
  }

  #recipe-panel.paged-preview-active #recipe-flow {
    column-width: auto !important;
    column-gap: 0 !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    background: transparent !important;
    border-radius: 0 !important;
  }

  #recipe-panel.paged-preview-active #recipe-content-preview {
    display: block !important;
  }

  body {
    background-color: #ffffff;
    margin: 0;
    padding: 0;
    font-family: "Lexend", sans-serif;
    color: #000;
  }

  /* Reset recipe container for printing */
  .recipe-preview-content.container {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    box-shadow: none;
  }

  /* Ensure images print well */
  .recipe-preview-content img {
    /* Allow the inline `style="max-width:...px"` set by the preview to take precedence
           while still preventing images from overflowing the printed page. Removing the
           previous `!important` cap lets element inline styles (the user's chosen size)
           apply. Use max-width:100% so very large values still fit the page. */
    max-width: 100%;
    height: auto;
    display: block;
    margin: 20px auto;
    page-break-inside: avoid;
  }

  /* Style text bubble for print */
  .text-bubble,
  .toast-base {
    background-color: #f8f8f8 !important;
    border: 1px solid #ddd !important;
    color: #333 !important;
    font-family: "Lexend", sans-serif !important; /* Reset font for print */
    font-style: italic;
    font-size: 1rem;
    transform: rotate(0deg); /* Straighten for print */
    page-break-inside: avoid;
  }
  .text-bubble::before,
  .toast-base::before {
    color: #000 !important;
    font-family: "Lexend", sans-serif !important;
  }
  /* Specific print "before" content */
  .toast-note::before {
    content: "Note: ";
  }
  .toast-tip::before {
    content: "Tip: ";
  }
  .toast-warning::before {
    content: "Warning: ";
  }

  /* --- NEW: Hide icons in print only for UI chrome areas (not the recipe preview) --- */
  .no-print .material-icons,
  .builder-panel .material-icons,
  .preview-controls .material-icons {
    display: none !important;
  }

  /* General print typography */
  .recipe-preview-content h1,
  .recipe-preview-content h3 {
    color: #000;
    /* font-family applied by class */
  }
  /* UPDATED: h1/h2 print styles */
  .recipe-preview-content h1,
  .recipe-preview-content h2 {
    color: #000;
  }

  .recipe-preview-content h1.font-style-display,
  .recipe-preview-content h2.font-style-display {
    font-family: '"Baloo 2"', cursive;
  }

  .recipe-preview-content h1.font-style-serif,
  .recipe-preview-content h2.font-style-serif {
    font-family: "Merriweather", serif;
  }

  .recipe-preview-content h1.font-style-sans,
  .recipe-preview-content h2.font-style-sans {
    font-family: "Lexend", sans-serif;
  }

  .recipe-preview-content p#recipe-desc-preview,
  .recipe-preview-content li,
  .recipe-text-block {
    color: #000;
  }

  .recipe-preview-content li {
    color: #000;
  }

  /* Prevent page breaks where we don't want them */
  .recipe-preview-content li,
  .recipe-preview-content h2,
  .recipe-preview-content h3 {
    page-break-after: avoid;
    page-break-inside: avoid;
  }
  .recipe-preview-content h1 {
    page-break-after: avoid;
  }
}

/* --- Text Scale: builder panel scale preview --- */
.scale-input-container .scale-preview {
  display: none;
}
.scale-input-container:focus-within .scale-preview {
  display: block;
}

/* --- Inline Scale Handle --- */
.inline-scale-handle {
  width: 100%;
  height: 10px;
  cursor: ns-resize;
  border-radius: 0 0 4px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease;
  user-select: none;
  touch-action: none;
}
.inline-scale-handle::after {
  content: "";
  display: block;
  width: 32px;
  height: 3px;
  border-radius: 2px;
  background: #cbd5e1; /* slate-300 */
  transition:
    background 0.15s ease,
    width 0.15s ease;
}
.inline-item:hover .inline-scale-handle {
  opacity: 1;
}
.inline-scale-handle:hover::after,
.inline-scale-handle:active::after {
  background: #6366f1; /* indigo-500 */
  width: 48px;
}

@media print {
  .inline-scale-handle {
    display: none !important;
  }
  .inline-frame-handle {
    display: none !important;
  }
}

/* --- Inline Editor & Floating Add Button Styles --- */
.inline-edit-image {
  cursor: pointer;
  border-radius: 6px;
  transition:
    box-shadow 0.15s ease,
    transform 0.12s ease;
}
.inline-edit-image:hover {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}
.inline-item--floating-image .inline-edit-image:hover {
  transform: none;
}

.image-resizer-overlay input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  height: 6px;
  border-radius: 6px;
  background: linear-gradient(90deg, #60a5fa, #7c3aed);
}

/* Floating add menu default styles (menu created dynamically) */
#floating-add-menu button:hover {
  background: #f3f4f6;
}

.inline-preview-shell {
  width: min(1600px, calc(100vw - 2rem));
  max-width: none;
  margin: 1.5rem auto 0;
  padding: 1.5rem 2rem;
  border-radius: 0.75rem;
  background: #ffffff;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
  box-sizing: border-box;
}

#inline-preview.inline-content-surface {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  align-content: flex-start;
  gap: 0.8rem;
  position: relative;
  min-height: 220px;
}

#inline-preview.hidden {
  display: none !important;
}

#inline-preview .inline-full-span {
  flex: 1 1 100%;
  width: 100%;
}

#inline-preview.inline-paged-preview-active {
  max-width: min(1400px, 96vw);
  padding: 0;
  background: transparent;
  box-shadow: none;
}

#inline-preview.inline-paged-preview-active .inline-preview-layout {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 18px;
}

#inline-preview.inline-paged-preview-active .inline-preview-canvas {
  --preview-page-width: 700px;
  --preview-page-gap: 28px;
  --preview-page-height: 980px;
  flex: 0 1 auto;
  width: min(calc(var(--preview-page-width) + 36px), 100%);
  max-width: 100%;
  margin: 0;
  padding: 14px;
  background: #e5e7eb;
  box-shadow: inset 0 0 0 1px #d1d5db;
  border-radius: 0.75rem;
  overflow: hidden;
}

#inline-preview.inline-paged-preview-active .inline-preview-flow {
  column-width: var(--preview-page-width);
  column-gap: var(--preview-page-gap);
  column-fill: auto;
  height: var(--preview-page-height);
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 28px;
  background: #ffffff;
  border-radius: 8px;
  box-sizing: border-box;
  scrollbar-gutter: stable both-edges;
  position: relative;
}

#inline-preview.inline-paged-preview-active
  .inline-preview-flow
  .inline-layout-item {
  display: inline-flex;
  vertical-align: top;
  margin: 0 0.8rem 0.8rem 0;
}

#inline-preview.inline-paged-preview-active
  .inline-preview-flow
  .inline-layout-item
  .inline-item-frame {
  width: 100%;
}

#inline-preview.inline-paged-preview-active .inline-preview-flow img,
#inline-preview.inline-paged-preview-active .inline-preview-flow h1,
#inline-preview.inline-paged-preview-active .inline-preview-flow h2,
#inline-preview.inline-paged-preview-active .inline-preview-flow h3,
#inline-preview.inline-paged-preview-active .inline-preview-flow ul,
#inline-preview.inline-paged-preview-active .inline-preview-flow ol,
#inline-preview.inline-paged-preview-active .inline-preview-flow .toast-base {
  break-inside: avoid-column;
}

@media (max-width: 1220px) {
  #inline-preview.inline-paged-preview-active .inline-preview-layout {
    flex-direction: column;
    align-items: center;
  }

  #inline-preview.inline-paged-preview-active .inline-preview-stats {
    position: static;
    width: min(760px, 100%);
    flex: 0 1 auto;
  }

  #inline-preview.inline-paged-preview-active .inline-preview-canvas {
    width: min(760px, 100%);
  }
}

@media (max-width: 768px) {
  .inline-preview-shell {
    width: calc(100vw - 0.8rem);
    padding: 1rem;
  }

  #inline-preview.inline-paged-preview-active .inline-preview-canvas {
    --preview-page-width: 620px;
  }

  #inline-preview.inline-paged-preview-active .inline-preview-flow {
    --preview-page-height: 900px;
    padding: 20px;
  }
}

/* Ensure inline preview looks like the recipe preview */
#inline-preview .recipe-text-block {
  margin: 0.75rem 0;
}
#inline-preview .inline-edit-link {
  cursor: pointer;
}
#inline-preview .inline-edit-link:hover {
  text-decoration-style: dashed;
}

/* Global font-style helper classes so inline preview headings respect settings */
.font-style-display {
  font-family: '"Baloo 2"', cursive !important;
}
.font-style-serif {
  font-family: "Merriweather", serif !important;
}
.font-style-sans {
  font-family: "Lexend", sans-serif !important;
}

/* New text outline to make freshly added text visible */
.new-text-outline {
  outline: 2px dashed rgba(59, 130, 246, 0.6); /* blue-500-ish */
  padding: 2px;
  border-radius: 4px;
}

/* Inline item wrapper */
.inline-item {
  cursor: grab;
}
.inline-layout-item {
  display: flex;
  flex-direction: column;
  flex: 1 1 340px;
  min-width: min(100%, 240px);
  max-width: 100%;
  gap: 6px;
}
.inline-item--floating-image {
  position: absolute !important;
  margin: 0 !important;
  flex: 0 0 auto !important;
}
.inline-item--floating-image.inline-item--image-over {
  z-index: 9;
}
.inline-item--floating-image.inline-item--image-under {
  z-index: 1;
}
.inline-item--floating-image .inline-item-frame {
  cursor: move;
}
.inline-content-surface > .inline-item:not(.inline-item--floating-image),
.inline-content-surface > .inline-full-span,
.inline-content-surface > .inline-step-list,
.inline-content-surface > .inline-bullet-list {
  position: relative;
  z-index: 2;
}
.inline-list-content-wrap {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  gap: 4px;
}
.inline-item-frame {
  position: relative;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.98);
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}
.inline-item:hover .inline-item-frame,
.inline-item:focus-within .inline-item-frame,
.inline-item-frame.inline-item-frame--resizing {
  border-color: rgba(99, 102, 241, 0.45);
  box-shadow:
    0 0 0 1px rgba(99, 102, 241, 0.12),
    0 8px 20px rgba(79, 70, 229, 0.12);
}
.inline-frame-handle {
  position: absolute;
  width: 30px;
  height: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  background: transparent;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 3;
  touch-action: none;
  user-select: none;
}
.inline-frame-handle::after {
  content: "";
  display: block;
  width: 30px;
  height: 3px;
  border-radius: 2px;
  background: #14b8a6; /* teal-500 */
  box-shadow: 0 0 8px rgba(20, 184, 166, 0.45);
  transition:
    background 0.15s ease,
    width 0.15s ease;
}
.inline-item:hover .inline-frame-handle,
.inline-item:focus-within .inline-frame-handle,
.inline-item-frame.inline-item-frame--resizing .inline-frame-handle {
  opacity: 1;
}
.inline-item:hover .inline-frame-handle::after,
.inline-item:focus-within .inline-frame-handle::after,
.inline-item-frame.inline-item-frame--resizing .inline-frame-handle::after,
.inline-frame-handle:hover::after,
.inline-frame-handle:active::after {
  width: 42px;
  background: #0f766e; /* teal-700 */
}
.inline-frame-handle--east {
  top: calc(50% - 6px);
  right: -15px;
  cursor: ew-resize;
  transform: rotate(90deg);
}
.inline-frame-handle--west {
  top: calc(50% - 6px);
  left: -15px;
  cursor: ew-resize;
  transform: rotate(90deg);
}
.inline-frame-handle--south-east {
  right: -11px;
  bottom: -6px;
  cursor: nwse-resize;
  transform: rotate(45deg);
}
.inline-frame-handle--south-west {
  left: -11px;
  bottom: -6px;
  cursor: nesw-resize;
  transform: rotate(-45deg);
}
.inline-item.dragging {
  opacity: 0.5;
}
.inline-item.drop-target {
  outline: 2px solid rgba(79, 70, 229, 0.25);
}

/* Step badge styling (numbered prefix for inline steps) */
.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9999px;
  background: #e5e7eb; /* gray-200 */
  border: 1px solid #d1d5db; /* gray-300 */
  color: #111827; /* gray-900 */
  font-weight: 700;
  flex: 0 0 32px;
}
.step-content {
  display: inline;
  padding-top: 4px;
}
.bullet-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9999px;
  background: #e5e7eb; /* gray-200 */
  border: 1px solid #d1d5db; /* gray-300 */
  color: #111827; /* gray-900 */
  font-size: 1.6rem;
  line-height: 1;
  flex: 0 0 32px;
}
.bullet-content {
  display: inline;
  padding-top: 4px;
}

#inline-preview .inline-step-list,
#inline-preview .inline-bullet-list {
  list-style: none;
  margin: 0.75rem 0;
  padding-left: 0;
}
#inline-preview .inline-list-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}
#inline-preview .inline-list-item:last-child {
  margin-bottom: 0;
}

/* Print helpers: when JS adds body.print-inline-only or body.print-recipe-only
   we make only the chosen preview visible for printing. This prevents UI chrome
   from appearing in the printout when using the experimental inline editor. */
@media print {
  /* Hide everything first */
  body.print-inline-only * {
    visibility: hidden !important;
  }
  /* Show inline preview only */
  body.print-inline-only #inline-preview,
  body.print-inline-only #inline-preview * {
    visibility: visible !important;
  }
  body.print-inline-only #inline-preview {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }
  body.print-inline-only #inline-preview .inline-preview-stats {
    display: none !important;
  }
  body.print-inline-only
    #inline-preview.inline-paged-preview-active
    .inline-preview-canvas {
    width: 100% !important;
    max-width: 100% !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    overflow: visible !important;
  }
  body.print-inline-only
    #inline-preview.inline-paged-preview-active
    .inline-preview-flow {
    column-width: auto !important;
    column-gap: 0 !important;
    height: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
    padding: 0 !important;
    background: transparent !important;
    border-radius: 0 !important;
  }

  /* Classic/preview-only print (used when printing from the recipe preview) */
  body.print-recipe-only * {
    visibility: hidden !important;
  }
  body.print-recipe-only #recipe-preview,
  body.print-recipe-only #recipe-preview * {
    visibility: visible !important;
  }
  body.print-recipe-only #recipe-preview {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }

  /* Ensure we don't print editor outlines or floating controls */
  .new-text-outline {
    outline: none !important;
    padding: 0 !important;
  }
  #floating-add-btn,
  #icon-key-btn,
  #settings-btn {
    display: none !important;
  }
}

/* --- Document Tab Bar --- */
.tabs-bar {
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  gap: 0;
  border-bottom: 2px solid #e5e7eb;
  margin-bottom: 1.25rem;
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
  min-height: 36px;
}

.tab-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px 4px 12px;
  cursor: grab;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  font-size: 0.8125rem;
  font-weight: 500;
  max-width: 180px;
  min-width: 80px;
  white-space: nowrap;
  user-select: none;
  transition:
    background 0.1s,
    color 0.1s;
  color: #6b7280;
  background: transparent;
  position: relative;
  bottom: -2px;
}

.tab-item:hover {
  background: #f3f4f6;
  color: #374151;
}

.tab-item--active {
  background: #fff;
  color: #1d4ed8;
  border-color: #e5e7eb;
  border-bottom-color: #fff;
  font-weight: 600;
}

.tab-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: #9ca3af;
  cursor: pointer;
  flex-shrink: 0;
  transition:
    background 0.1s,
    color 0.1s;
  line-height: 1;
}

.tab-close-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}

.tab-rename-input {
  flex: 1;
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid #93c5fd;
  border-radius: 3px;
  padding: 0 4px;
  outline: none;
  min-width: 0;
  background: #eff6ff;
  color: #1e40af;
  max-width: 130px;
}

.tab-new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #9ca3af;
  cursor: pointer;
  transition:
    background 0.1s,
    color 0.1s;
  align-self: center;
  margin-left: 4px;
}

.tab-new-btn:hover {
  background: #dbeafe;
  color: #2563eb;
}

.tab-item--dragging {
  opacity: 0.45;
  cursor: grabbing;
}

.tab-item--drag-over {
  border-left: 2px solid #2563eb;
  background: #eff6ff;
  color: #1d4ed8;
}

/* --- Tab Groups --- */

.tab-group-header {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px 2px 6px;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  user-select: none;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  position: relative;
  bottom: -2px;
  border: 1px solid transparent;
  border-bottom: none;
  transition: filter 0.1s;
  flex-shrink: 0;
}

.tab-group-header:hover {
  filter: brightness(0.95);
}

.tab-group-header--dragging {
  opacity: 0.45;
  cursor: grabbing;
}

.tab-group-header--collapsed {
  border-radius: 6px;
  opacity: 0.85;
}

.tab-group-header--drag-over {
  outline: 2px solid #2563eb;
  outline-offset: -1px;
}

.tab-group-collapse-icon {
  flex-shrink: 0;
  opacity: 0.75;
}

.tab-group-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}

/* Group colour variants */
.tab-group-color-y {
  background: #fef9c3;
  color: #713f12;
  border-color: #fde047;
}
.tab-group-color-b {
  background: #dbeafe;
  color: #1e3a8a;
  border-color: #93c5fd;
}
.tab-group-color-g {
  background: #dcfce7;
  color: #14532d;
  border-color: #86efac;
}
.tab-group-color-p {
  background: #fce7f3;
  color: #831843;
  border-color: #f9a8d4;
}

/* Left border accent on grouped tabs */
.tab-item--grouped {
  border-left-width: 3px;
  border-left-style: solid;
}
.tab-group-color-y-tab {
  border-left-color: #fde047;
}
.tab-group-color-b-tab {
  border-left-color: #93c5fd;
}
.tab-group-color-g-tab {
  border-left-color: #86efac;
}
.tab-group-color-p-tab {
  border-left-color: #f9a8d4;
}

/* Tab context menu */
.tab-ctx-menu {
  position: fixed;
  z-index: 200;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.13);
  padding: 6px;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tab-ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 10px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: #374151;
  font-size: 0.8125rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}

.tab-ctx-item:hover {
  background: #f3f4f6;
}

.tab-ctx-icon {
  font-size: 15px !important;
  line-height: 1;
  color: #6b7280;
  flex-shrink: 0;
}

.tab-ctx-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 4px 0;
}

.tab-ctx-color-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
}

.tab-ctx-color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #94a3b8;
  cursor: pointer;
  transition:
    transform 0.1s,
    border-color 0.1s;
  flex-shrink: 0;
}

.tab-ctx-color-swatch:hover {
  transform: scale(1.2);
}

.tab-ctx-color-swatch--active {
  border-color: #1d4ed8;
  transform: scale(1.15);
}

.tab-ctx-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid #94a3b8;
  flex-shrink: 0;
}

.swatch-y {
  background: #fef08a;
}
.swatch-b {
  background: #bfdbfe;
}
.swatch-g {
  background: #bbf7d0;
}
.swatch-p {
  background: #fbcfe8;
}
