* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --surface-2: #fbfaf8;
  --border: #e6e1d9;
  --border-strong: #d7d0c6;
  --text: #1f2933;
  --muted: #5b6771;
  --accent: #2f4a3f;
  --accent-2: #3b5c4f;
  --focus: rgba(47, 74, 63, 0.25);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 10px 25px rgba(15, 23, 42, 0.06);
  --radius: 12px;
  --radius-sm: 10px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  --space-5: 24px;

  /* Layout: split-view (topics | content | images) */
  --header-h: 52px;
  --sidebar-w: 220px;
  --content-w: 320px;
  --panel-gap: 0;
  --panel-radius: 0;

  /* Compact theme accents */
  --accent-soft: rgba(47, 74, 63, 0.08);
  --accent-border: rgba(47, 74, 63, 0.18);
}

html {
  font-size: 15px;
}

html,
body {
  width: 100%;
  height: 100%;
  font-family:
    "Rubik", "Heebo", "Assistant", "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  direction: rtl;
  color: var(--text);
  line-height: 1.5;
}

/* Better default text rendering */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  line-height: 1.55;
  background: #f4f2ef;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

/* Focus ring (keyboard only) */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.topic-item:focus-visible,
.section-title:focus-visible,
.section-item:focus-visible {
  outline: 2px solid rgba(47, 74, 63, 0.5);
  outline-offset: 2px;
}

/* =============================================
   Header Styles
   ============================================= */

.main-header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 6px 18px;
  background: var(--bg);
  border-bottom: 1px solid #e4e0da;
  height: var(--header-h);
  box-sizing: border-box;
}

.site-title {
  font-size: 1.6rem;
  line-height: 1.1;
  font-weight: 700;
  color: var(--accent);
  margin: 0;
  font-family:
    "Rubik", "Heebo", "Assistant", "Segoe UI", Tahoma, Arial, sans-serif;
  letter-spacing: 0;
  cursor: pointer;
}

#login-box {
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: center;
}

#connected-as {
  font-size: 0.88rem;
  color: #6b7280;
}

.login-button {
  background: linear-gradient(to bottom, var(--accent-2), var(--accent));
  color: #fff;
  border: 1px solid rgba(47, 74, 63, 0.6);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    filter 0.12s ease;
  box-shadow: var(--shadow-sm);
}

.login-button:hover {
  filter: brightness(1.02);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.login-button:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.modeButton {
  /* Same green family as other buttons, slightly different shade */
  background: linear-gradient(to bottom, #2f6f66, #1f4e47);
  color: #fff;
  border: 1px solid rgba(31, 78, 71, 0.75);
  box-shadow:
    var(--shadow-sm),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.modeButton:hover {
  filter: brightness(1.03);
}

/* =============================================
   Main Container Layout
   ============================================= */

.main-container {
  display: flex;
  flex-direction: row;
  flex: 1 1 auto;
  min-height: 0;
  gap: var(--panel-gap);
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* =============================================
   Gutter (drag-to-resize divider)
   ============================================= */

.gutter {
  flex: 0 0 1px;
  background: #e4e0da;
  cursor: col-resize;
  position: relative;
  z-index: 10;
  transition: background 0.15s;
}

.gutter:hover,
.gutter.is-dragging {
  flex: 0 0 2px;
  background: #73877f;
}

body.is-resizing {
  cursor: col-resize !important;
  user-select: none !important;
}

/* =============================================
   Topics Sidebar (Right Side)
   ============================================= */

.topics-sidebar {
  flex: 0 0 var(--sidebar-w);
  min-width: 140px;
  max-width: 50vw;
  background: #fff;
  border-left: 1px solid #e4e0da;
  border-radius: 0;
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#search-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: var(--space-3);
}

#search-box label {
  font-size: 0.85rem;
  margin-bottom: 4px;
  display: block;
  color: #6b7280;
  font-weight: 600;
}

#search-input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background-color: var(--surface-2);
  direction: rtl;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
  width: 100%;
}

#search-input:hover {
  border-color: var(--border-strong);
}

#search-input::placeholder {
  color: #999;
}

#search-input:focus {
  outline: none;
  border-color: rgba(47, 74, 63, 0.55);
  box-shadow: 0 0 0 4px var(--focus);
}

.sidebar-mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: var(--space-2);
}

.sidebar-tab {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 750;
  font-size: 0.92rem;
}

.sidebar-tab:hover {
  border-color: var(--border-strong);
}

.sidebar-tab.is-active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.topics-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: var(--space-2);
  border-top: 1px solid #e4e0da;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.topics-actions {
  display: flex;
  flex-direction: row;
  justify-content: stretch;
  margin-bottom: var(--space-2);
}

.topics-actions .topic-print-button {
  width: 100%;
  justify-content: center;
}

.topic-item {
  padding: 9px 10px;
  cursor: pointer;
  border-radius: 8px;
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--text);
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    transform 0.15s ease;
  border: 1px solid transparent;
  background: transparent;
}

.topic-item:hover {
  background-color: rgba(47, 74, 63, 0.06);
  border-color: rgba(47, 74, 63, 0.12);
}

.topic-item.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  font-weight: 650;
}

.topic-item:focus {
  outline: none;
  box-shadow: none;
}

/* =============================================
   Content Area (Left Side)
   ============================================= */

.content-area {
  flex: 0 0 var(--content-w);
  min-width: 180px;
  max-width: 60vw;
  background: #faf9f7;
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  /* border-left: 1px solid #e4e0da;
  border-right: 1px solid var(--border); */
  border-radius: 0;
  box-shadow: none;
}

/* Lessons mode: make the middle panel wider than topics mode */
body:not(.is-topics-mode) .content-area {
  flex-basis: 370px;
  max-width: 65vw;
}

#content-header {
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid #e4e0da;
}

.topic-toolbar {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-top: 0;
}

.topic-search {
  flex: 0 0 100%;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
  background-color: var(--surface-2);
  direction: rtl;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.topic-search:hover {
  border-color: var(--border-strong);
}

.topic-search:focus {
  outline: none;
  border-color: rgba(47, 74, 63, 0.55);
  box-shadow: 0 0 0 4px var(--focus);
}

.topic-print-button {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  transition:
    background-color 0.12s ease,
    border-color 0.12s ease,
    transform 0.12s ease;
  white-space: nowrap;
}

.topic-print-button:hover {
  background-color: rgba(47, 74, 63, 0.06);
  border-color: rgba(47, 74, 63, 0.2);
}

.topic-print-button:active {
  transform: translateY(1px);
}

#topic-toolbar .topic-print-button,
#global-toolbar .topic-print-button {
  padding: 4px 9px;
  font-size: 0.78rem;
}

/* Toolbar action buttons: subtle color + icon */
#topic-toolbar .topic-print-button.topic-action-btn,
#topic-toolbar .topic-print-button.lesson-action-btn {
  border-color: var(--accent-border);
  box-shadow: var(--shadow-sm);
}

#topic-toolbar .topic-print-button.topic-action-btn:hover,
#topic-toolbar .topic-print-button.lesson-action-btn:hover {
  background-color: var(--accent-soft);
  border-color: var(--accent-border);
  /* box-shadow: var(--shadow-md); */
  transform: translateY(-1px);
}

#topic-toolbar .topic-print-button.topic-action-btn:active,
#topic-toolbar .topic-print-button.lesson-action-btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.topic-print-button.has-icon {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.topic-print-button.has-icon::before {
  content: "";
  width: 16px;
  height: 16px;
  display: inline-block;
  background: currentColor;
  -webkit-mask-image: var(--icon);
  mask-image: var(--icon);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
  opacity: 0.95;
}

#topic-add-topic-btn.has-icon,
#topic-add-lesson-btn.has-icon,
#topic-add-section-btn.has-icon,
#topic-add-image-btn.has-icon {
  --icon: var(--icon-plus);
}

#topic-download-pdf-btn.has-icon,
#lesson-download-pdf-btn.has-icon,
.lesson-section-download-btn.has-icon {
  --icon: var(--icon-download);
}

/* .lesson-section-word-btn.has-icon {
  --icon: var(--icon-plus);
} */

.lesson-section-download-btn {
  padding: 3px 8px;
  font-size: 0.76rem;
}

/* .edit-icon-btn.lesson-section-word-btn {
  padding: 3px 8px;
  font-size: 0.76rem;
} */

/* Offscreen PDF export rendering */
#pdf-export-root {
  position: fixed;
  top: -10000px;
  right: 0;
  width: 820px;
  background: transparent;
  /* color: var(--text); */
  padding: 0;
}

#pdf-export-root .pdf-page {
  background: var(--surface);
  /* color: var(--text); */
  padding: 24px;
  box-sizing: border-box;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#pdf-export-root .pdf-page-header {
  flex: 0 0 auto;
  padding-bottom: 10px;
  margin-bottom: 12px;
  color: rgb(13, 13, 13);
}

#pdf-export-root .pdf-topic-line {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: rgba(13, 13, 13, 0.92);
}

#pdf-export-root .pdf-item-line {
  margin-top: 4px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
  color: rgb(13, 13, 13);
  white-space: normal;
  overflow-wrap: anywhere;
}

#pdf-export-root .pdf-doc-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.3;
}

#pdf-export-root .pdf-sec-title {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

#pdf-export-root .pdf-item-title {
  margin-top: 4px;
  font-size: 15px;
  font-weight: 750;
  line-height: 1.35;
}

#pdf-export-root .pdf-page-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#pdf-export-root .pdf-page-image-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#pdf-export-root .pdf-page-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

#pdf-export-root .pdf-no-image {
  color: var(--muted);
  font-size: 14px;
}

#pdf-export-root h1 {
  font-size: 22px;
  margin: 0 0 12px 0;
}

#pdf-export-root h3 {
  margin: 18px 0 8px 0;
  color: var(--accent);
  font-size: 16px;
}

#pdf-export-root .print-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface);
  margin: 10px 0;
}

#pdf-export-root .print-item-title {
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.6;
}

#pdf-export-root .print-images {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#pdf-export-root .print-image-wrap {
  position: relative;
  width: 100%;
  max-width: 360px;
}

#pdf-export-root .print-image {
  max-width: 360px;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: block;
}

#pdf-export-root .print-pointer {
  position: absolute;
  --pointer-size: 26px;
  width: calc(var(--pointer-size) * 1);
  height: calc(var(--pointer-size) * 0.62);
  transform: none;
  pointer-events: none;
}

#pdf-export-root .print-pointer {
  animation: none !important;
}

#pdf-export-root .print-no-images {
  color: var(--muted);
  font-size: 0.95rem;
}

#current-topic-title {
  font-size: 1.25rem;
  color: var(--text);
  font-weight: 700;
  margin: 0 0 6px 0;
  line-height: 1.25;
}

#content-sections {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.topic-toolbar.is-hidden {
  display: none;
}

.no-topic,
.no-content {
  font-size: 0.95rem;
  color: #888;
  padding: var(--space-3);
  text-align: center;
}

.content-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.95rem;
  padding: var(--space-3);
}

.content-loading-spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: contentLoadingSpin 0.8s linear infinite;
}

@keyframes contentLoadingSpin {
  to {
    transform: rotate(360deg);
  }
}

.global-results {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.global-results-title {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}

.global-result {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px 12px;
  cursor: pointer;
  transition:
    background-color 0.12s ease,
    border-color 0.12s ease,
    transform 0.12s ease;
}

.global-result:hover {
  background-color: rgba(47, 74, 63, 0.04);
  border-color: rgba(47, 74, 63, 0.18);
}

.global-result:active {
  transform: translateY(1px);
}

.global-result-topic {
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 4px;
}

.global-result-parent {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.global-result-text {
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.55;
}

.section-item.is-highlight {
  background-color: rgba(47, 74, 63, 0.08);
}

.section-item.is-selected {
  background-color: rgba(31, 41, 51, 0.06);
  box-shadow: inset -4px 0 0 rgba(47, 74, 63, 0.55);
}

.section-item.is-selected .item-text {
  font-weight: 650;
}

/* In edit mode, don't emphasize selected item text as bold */
body.is-edit-mode .section-item.is-selected .item-text {
  font-weight: 400;
}

/* Section group styling */
.content-section {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: var(--space-2);
  padding: 0;
  background: transparent;
  border: 0;
  padding-right: 0;
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 26px;
  transition: color 0.2s ease;
}

.section-title:hover {
  color: rgba(47, 74, 63, 0.85);
}

.section-title::before {
  content: "▾";
  position: absolute;
  right: 0;
  top: 0;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition:
    color 0.2s ease,
    background-color 0.2s ease,
    border-color 0.2s ease;
  color: rgba(47, 74, 63, 0.7);
  line-height: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.content-section.is-collapsed .section-title::before {
  content: "◂";
  color: rgba(47, 74, 63, 0.65);
}

.section-title:hover::before {
  border-color: rgba(47, 74, 63, 0.2);
  background-color: rgba(47, 74, 63, 0.06);
}

.section-title::after {
  content: "";
  display: block;
  margin-top: 6px;
  height: 1px;
  background: var(--border);
}

.section-items {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}

.content-section.is-collapsed .section-items {
  display: none;
}

.content-section.is-collapsed .section-title {
  margin-bottom: var(--space-2);
  opacity: 0.85;
}

.content-section.is-collapsed .section-title:hover {
  opacity: 1;
}

.section-item {
  background: transparent;
  padding: 10px 12px;
  font-size: 0.9rem;
  border-radius: 0;
  cursor: pointer;
  transition: background-color 0.12s ease;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  border: 0;
  box-shadow: none;
}

.item-select {
  margin-top: 0;
  margin-bottom: 0;
  align-self: center;
  width: 15px;
  height: 15px;
  margin-left: 8px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.lesson-section-select {
  margin-top: 0;
  margin-bottom: 0;
  align-self: center;
  width: 15px;
  height: 15px;
  margin-left: 8px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.section-item + .section-item {
  border-top: 1px solid var(--border);
}

.section-item:hover {
  background-color: rgba(47, 74, 63, 0.06);
}

.section-item:active {
  background-color: rgba(47, 74, 63, 0.09);
}

.item-text {
  color: rgba(31, 41, 51, 0.92);
  line-height: 1.6;
  flex: 1;
}

/* =============================================
   Edit Controls (new design)
   ============================================= */

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

body.is-edit-mode .section-title {
  flex-wrap: wrap;
}

body.is-edit-mode .content-section {
  border: 1px solid var(--accent-border);
  background: #fff;
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

body.is-edit-mode .section-title {
  align-items: flex-start;
  gap: 6px 8px;
  margin-bottom: 8px;
}

body.is-edit-mode .section-title-controls {
  flex: 0 0 100%;
  order: 4;
  justify-content: flex-start;
  padding-top: 6px;
}

body.is-edit-mode .section-title .topic-print-button {
  padding: 3px 8px;
  font-size: 0.74rem;
  border-radius: 7px;
}

/* In edit mode, keep only the download action hidden for lesson sections */
body.is-edit-mode .lesson-section-download-btn {
  display: none !important;
}

/* In edit mode, hide checkbox used for download selection */
body.is-edit-mode .section-item .item-select {
  display: none !important;
}

body.is-edit-mode .section-items {
  border-radius: 10px;
  background: #f8faf9;
}

.section-title-text {
  flex: 1 1 auto;
  min-width: 0;
}

.section-title-controls,
.item-controls {
  flex: 0 0 auto;
  display: inline-flex;
  flex-direction: row;
  gap: 4px;
  align-items: center;
}

:root {
  /* Edit buttons: softer palette (still clear/legible) */
  --edit-btn-bg: #f1f5f9;
  --edit-btn-bg-hover: #e2e8f0;
  --edit-btn-fg: #14532d;
  --edit-btn-border: rgba(15, 23, 42, 0.22);
  --edit-btn-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
  --edit-btn-danger-bg: #fff1f2;
  --edit-btn-danger-bg-hover: #ffe4e6;
  --edit-btn-danger-fg: #9f1239;

  /* Inline SVG icons (masked so color matches currentColor) */
  --icon-up: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 7.4l-6.3 6.3a1 1 0 0 1-1.4-1.4l7-7a1 1 0 0 1 1.4 0l7 7a1 1 0 1 1-1.4 1.4L12 7.4z'/%3E%3C/svg%3E");
  --icon-down: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 16.6l6.3-6.3a1 1 0 1 1 1.4 1.4l-7 7a1 1 0 0 1-1.4 0l-7-7a1 1 0 0 1 1.4-1.4L12 16.6z'/%3E%3C/svg%3E");
  --icon-download: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 3a1 1 0 0 1 1 1v9.59l2.3-2.3a1 1 0 1 1 1.4 1.42l-4.01 4a1 1 0 0 1-1.4 0l-4-4a1 1 0 1 1 1.41-1.42L11 13.59V4a1 1 0 0 1 1-1zm-7 16a1 1 0 0 1 1-1h12a1 1 0 1 1 0 2H6a1 1 0 0 1-1-1z'/%3E%3C/svg%3E");
  --icon-plus: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M11 5a1 1 0 0 1 2 0v6h6a1 1 0 1 1 0 2h-6v6a1 1 0 1 1-2 0v-6H5a1 1 0 1 1 0-2h6V5z'/%3E%3C/svg%3E");
  --icon-x: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M7.05 7.05a1 1 0 0 1 1.41 0L12 10.59l3.54-3.54a1 1 0 1 1 1.41 1.41L13.41 12l3.54 3.54a1 1 0 1 1-1.41 1.41L12 13.41l-3.54 3.54a1 1 0 1 1-1.41-1.41L10.59 12L7.05 8.46a1 1 0 0 1 0-1.41z'/%3E%3C/svg%3E");
}

.edit-icon-btn {
  appearance: none;
  border: 1px solid var(--edit-btn-border);
  background: var(--edit-btn-bg);
  color: var(--edit-btn-fg);
  height: 26px;
  min-width: 26px;
  padding: 0 6px;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 800;
  font-size: 0;
  line-height: 24px;
  box-shadow:
    var(--edit-btn-shadow),
    0 0 0 1px rgba(15, 23, 42, 0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

body.is-edit-mode .edit-icon-btn {
  height: 24px;
  border-radius: 8px;
}

body.is-edit-mode .item-controls {
  gap: 3px;
}

/* In edit mode place item controls above each value on the left */
body.is-edit-mode .section-item {
  position: relative;
  flex-wrap: wrap;
  padding-top: 30px;
}

body.is-edit-mode .section-item.no-content {
  padding-top: 10px;
}

body.is-edit-mode .section-item .item-controls {
  position: absolute;
  top: 5px;
  left: 8px;
}

body.is-edit-mode .section-item .item-text {
  flex: 1 1 100%;
}

.edit-icon-btn::before {
  content: "";
  width: 14px;
  height: 14px;
  display: block;
  background-color: currentColor;
  -webkit-mask-image: var(--icon);
  mask-image: var(--icon);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: 14px 14px;
  mask-size: 14px 14px;
}

/* Icon mapping by action */
.sec-up,
.item-up,
.sec-lesson-up,
.item-lesson-up,
.img-up {
  --icon: var(--icon-up);
}

.sec-down,
.item-down,
.sec-lesson-down,
.item-lesson-down,
.img-down {
  --icon: var(--icon-down);
}

.pdf-up {
  --icon: var(--icon-up);
}

.pdf-down {
  --icon: var(--icon-down);
}

.pdf-remove {
  --icon: var(--icon-x);
}

.sec-add,
.sec-add-lesson {
  --icon: var(--icon-plus);
}

.edit-icon-btn.sec-add-text {
  font-size: 0.78rem;
  line-height: 1;
  min-width: auto;
  padding: 0 9px;
  gap: 6px;
}

.edit-icon-btn.sec-add-text span {
  display: inline-block;
  white-space: nowrap;
}

.edit-icon-btn.lesson-section-word-btn::before {
  display: none;
}

.sec-del,
.item-del,
.sec-lesson-del,
.item-lesson-del,
.img-del,
.topic-del-btn {
  --icon: var(--icon-x);
}

/* In edit mode keep controls always visible */
body.is-edit-mode .section-title-controls,
body.is-edit-mode .item-controls {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.edit-icon-btn:hover {
  background: var(--edit-btn-bg-hover);
  border-color: rgba(15, 23, 42, 0.28);
  transform: translateY(-1px);
}

.edit-icon-btn:active {
  transform: translateY(0);
}

.edit-icon-btn.danger {
  background: var(--edit-btn-danger-bg);
  color: var(--edit-btn-danger-fg);
  border-color: rgba(159, 18, 57, 0.28);
}

.edit-icon-btn.danger:hover {
  background: var(--edit-btn-danger-bg-hover);
  border-color: rgba(159, 18, 57, 0.38);
}

.edit-icon-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* =============================================
   PDF Export Modal (multi-topic + reorder)
   ============================================= */

.pdf-export-overlay {
  position: fixed;
  inset: 0;
  z-index: 4500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(2, 6, 23, 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.pdf-export-dialog {
  width: min(760px, 96vw);
  max-height: min(86vh, 900px);
  background: var(--surface, #fff);
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  direction: rtl;
}

.pdf-export-header {
  display: grid;
  grid-template-columns: 34px 1fr 34px;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface-2, #f6f6f6);
  border-bottom: 1px solid var(--border, rgba(15, 23, 42, 0.12));
}

.pdf-export-header::after {
  content: "";
  grid-column: 3;
  width: 34px;
  height: 34px;
}

.pdf-export-header h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 850;
  grid-column: 2;
  justify-self: center;
  text-align: center;
}

.pdf-export-close {
  grid-column: 1;
  justify-self: start;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border, rgba(15, 23, 42, 0.12));
  background: #ffffff;
  color: #0f172a;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.pdf-export-close:hover {
  background: var(--surface-2, #f6f6f6);
}

.pdf-export-close:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(47, 74, 63, 0.22),
    0 0 0 1px rgba(15, 23, 42, 0.18);
}

.pdf-export-body {
  padding: 12px 14px;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.lesson-assign {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 12px;
  background: var(--surface-2, #f6f6f6);
  margin-bottom: 12px;
}

.lesson-assign-row {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: 10px;
  align-items: center;
}

.lesson-assign-label {
  font-weight: 800;
  color: var(--text);
}

.lesson-assign-select,
.lesson-assign-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

.lesson-assign-input::placeholder {
  color: #8a93a0;
}

.pdf-export-hint {
  color: var(--muted);
  font-weight: 650;
  margin-bottom: 10px;
}

.pdf-export-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pdf-export-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 12px;
  background: #fff;
}

.pdf-export-row.ui-sortable-helper {
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
}

.pdf-export-row-main {
  flex: 1 1 auto;
  min-width: 0;
}

.pdf-export-row-title {
  font-weight: 850;
  color: rgba(31, 41, 51, 0.96);
  overflow-wrap: anywhere;
}

.pdf-export-row-sub {
  margin-top: 2px;
  font-size: 0.9rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.pdf-export-row-actions {
  flex: 0 0 auto;
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.pdf-export-empty {
  text-align: center;
  padding: 22px 10px;
  color: var(--muted);
  font-weight: 750;
}

.pdf-export-footer {
  padding: 12px 14px;
  background: var(--surface-2, #f6f6f6);
  border-top: 1px solid var(--border, rgba(15, 23, 42, 0.12));
  display: flex;
  flex-direction: row;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Primary action inside PDF modal */
#pdfExportModal #pdf-export-download.topic-print-button {
  background: linear-gradient(to bottom, var(--accent-2), var(--accent));
  color: #fff;
  border-color: rgba(47, 74, 63, 0.6);
  box-shadow:
    0 8px 18px rgba(47, 74, 63, 0.18),
    0 1px 0 rgba(255, 255, 255, 0.25) inset;
}

#pdfExportModal #pdf-export-download.topic-print-button:hover {
  background: linear-gradient(to bottom, #4b7565, #2f4a3f);
  border-color: rgba(47, 74, 63, 0.72);
}

#pdfExportModal #pdf-export-download.topic-print-button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  box-shadow: none;
}

/* Topic row controls (delete) */
.topic-item {
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: flex-start;
}

.topic-item-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

body.is-edit-mode .topic-item-text[contenteditable="true"] {
  cursor: text;
  display: block;
  border-radius: 8px;
  padding: 2px 6px;
  border: 1px dashed rgba(47, 74, 63, 0.18);
  background: rgba(47, 74, 63, 0.04);
  transition:
    border-color 0.12s ease,
    background-color 0.12s ease;
}

body.is-edit-mode .topic-item-text[contenteditable="true"]:hover {
  border-color: rgba(47, 74, 63, 0.3);
  background: rgba(47, 74, 63, 0.07);
}

body.is-edit-mode .topic-item-text[contenteditable="true"]:focus {
  outline: none;
  border: 1px solid rgba(15, 23, 42, 0.75);
  /* box-shadow: 0 0 0 4px var(--focus); */
  background: #fff;
}

/* Same inline-edit focus styling for items/sections */
body.is-edit-mode .item-text[contenteditable="true"],
body.is-edit-mode .section-title-text[contenteditable="true"] {
  border-radius: 8px;
  padding: 2px 6px;
  border: 1px dashed rgba(47, 74, 63, 0.2);
  background: rgba(47, 74, 63, 0.04);
  font-weight: inherit;
  margin-top: 6px;
  transition:
    border-color 0.12s ease,
    background-color 0.12s ease;
}

body.is-edit-mode .item-text[contenteditable="true"]:hover,
body.is-edit-mode .section-title-text[contenteditable="true"]:hover {
  border-color: rgba(47, 74, 63, 0.32);
  background: rgba(47, 74, 63, 0.08);
}

body.is-edit-mode .item-text[contenteditable="true"]:focus,
body.is-edit-mode .section-title-text[contenteditable="true"]:focus {
  outline: none;
  border: 1px solid rgba(15, 23, 42, 0.75);
  /* box-shadow: 0 0 0 4px var(--focus); */
  background: #fff;
  font-weight: inherit;
}

.topic-item-controls {
  flex: 0 0 auto;
  display: none;
  align-items: center;
  margin-top: 1px;
}

body.is-edit-mode .topic-item-controls {
  display: inline-flex;
}

.topic-del-btn {
  /* When used with .edit-icon-btn, keep it consistent */
  width: 26px;
}

.topic-del-btn:hover {
  background: var(--edit-btn-danger-bg-hover);
  transform: translateY(-1px);
}

.topic-del-btn:active {
  transform: translateY(0);
}

/* =============================================
   Edit Mode Elements (Hidden by default)
   ============================================= */

.edit-mode-only {
  display: none !important;
}

.mode-hide {
  display: none !important;
}

.hidden {
  visibility: hidden;
}

/* Legacy styles for edit mode */
#toolbox.edit-mode-only.show {
  display: flex !important;
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: white;
  padding: 15px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  z-index: 1000;
}

/* =============================================
   Legacy Breadcrumb Styles (for edit mode)
   ============================================= */

.breadcrumb-container {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-content: center;
  background-color: #eee;
}

.image-toolbar {
  display: flex;
  flex-direction: row;
  gap: 8px;
  align-self: center;
  align-content: center;
  padding-left: 1em;
}

#image-title {
  align-self: center;
}

ul.breadcrumb {
  padding: 6px 10px;
  list-style: none;
  background-color: #eee;
  margin-block-start: 0.2em;
  margin-block-end: 0.2em;
}

ul.breadcrumb li {
  display: inline;
  font-size: 14px;
}

ul.breadcrumb li + li:before {
  padding: 5px;
  color: black;
  content: ">";
}

ul.breadcrumb li a {
  color: #0275d8;
  text-decoration: none;
}

ul.breadcrumb li a:hover {
  color: #01447e;
  text-decoration: underline;
}

.deleted-item > .kttext {
  text-decoration: line-through;
}

body #item-container {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

.item-box {
  height: 100%;
  overflow: auto;
}

body .image-box {
  width: 100%;
  overflow: auto;
}

.image-box img.page {
  width: 96%;
  overflow: auto;
}

.v-splitter {
  background-color: black;
  width: 6px;
}

/* Keep close button size consistent (compact override) */
.close,
.gs-close {
  font-size: 22px;
}

span.kttext[contenteditable] {
  display: inline-block;
  cursor: text;
}

span.kttext[contenteditable]:empty::before {
  content: "נושא חדש";
  display: inline-block;
  color: gray;
}

span.kttext[contenteditable]:empty:focus::before {
  content: "התחל להקליד";
}

span.changed-item {
  font-weight: bold;
}

span.new-item {
  color: blue;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 5px;
}

td {
  display: grid;
  grid-template-areas:
    ". edit-buttons"
    "enter-button item-text";
  grid-template-columns: 4em 1fr auto;
  grid-template-rows: auto 1fr;
  column-gap: 0.5em;
  justify-content: space-between;
  align-content: center;
}

.kttext {
  grid-area: item-text;
  cursor: pointer;
  transition: 0.2s;
}

.kttext:hover {
  background-color: #e8e2d8;
}

.enterBtn {
  grid-area: enter-button;
  -webkit-appearance: button;
  -moz-appearance: button;
  appearance: button;
  text-decoration: none;
  color: initial;
}

.k-main {
  display: flex;
  flex-direction: row;
  gap: 5px;
}

.edit-button-box {
  display: none;
  grid-area: edit-buttons;
  flex-direction: row;
  align-self: flex-start;
  gap: 5px;
}

.item-selected .edit-button-box {
  display: flex;
}

.item-cutted {
  opacity: 60%;
}

.button-success {
  color: white;
  border-radius: 4px;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  background: #6b8f7a;
}

.button-error {
  color: white;
  border-radius: 4px;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  background: rgb(202, 60, 60);
}

.button-warning {
  color: white;
  border-radius: 4px;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  background: rgb(223, 117, 20);
}

/* .button-secondary {
  color: white;
  border-radius: 4px;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  background: #6b8f7a;
} */

.delItemBtn {
  margin-right: auto;
}

.bc-item-a {
  pointer-events: none;
}

.item-selected > .kttext {
  background-color: #d0c9be !important;
}

div.image-container {
  display: flex;
  justify-content: center;
  position: relative;
  width: 100%;
}

div.image-container > div.image-buttons {
  position: absolute;
  top: 0;
  right: 0;
  padding: 0;
  display: flex;
  flex-direction: row;
  background-color: rgba(211, 211, 211, 0.8);
}

img.pointer {
  width: 35px;
  height: 35px;
  position: absolute;
}

img.page {
  height: 100%;
  width: 100%;
}

.undoItemBtn {
  display: none;
}

pre {
  overflow-x: auto;
  white-space: pre-wrap;
  white-space: -moz-pre-wrap;
  white-space: -pre-wrap;
  white-space: -o-pre-wrap;
  word-wrap: break-word;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
}

/* =============================================
   Responsive Design
   ============================================= */

@media (max-width: 1100px) {
  :root {
    --sidebar-w: 180px;
    --content-w: 280px;
  }
}

@media (max-width: 900px) {
  :root {
    --sidebar-w: 160px;
    --content-w: 240px;
  }

  .site-title {
    font-size: 1.4rem;
  }
}

/* -- Mobile back buttons (hidden on desktop) -- */
.mobile-back-btn,
.mobile-back-images {
  display: none;
}

@media (max-width: 768px) {
  html {
    font-size: 14px;
  }

  body {
    overflow: hidden;
  }

  /* No edit mode on mobile */
  #mode-toggle-btn,
  [mode="edit"],
  .topics-actions[mode="edit"],
  body.is-edit-mode .img-page-controls,
  body.is-edit-mode #imagesViewModal .images-view-header {
    display: none !important;
  }

  /* -- Header -------------------------------- */
  .main-header {
    padding: 6px 10px;
    height: auto;
    min-height: 44px;
    flex-wrap: wrap;
    gap: 6px;
  }

  .site-title {
    font-size: 1.15rem;
  }

  #login-box {
    gap: 4px;
    flex-wrap: wrap;
    max-width: 72%;
  }

  #login-box .login-button {
    padding: 5px 9px;
    font-size: 0.78rem;
  }

  /* -- Main container: full remaining height -- */
  .main-container {
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    position: relative;
  }

  .gutter {
    display: none;
  }

  /* -- All 3 panels: stack on top of each other -- */
  .topics-sidebar,
  .content-area,
  #imagesViewModal.images-view-modal {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    min-width: 0 !important;
    min-height: 0 !important;
    flex: none !important;
    border: none !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    transition: transform 0.25s ease;
    background: #fff !important;
  }

  /* Layer 1: Topics = default visible */
  .topics-sidebar {
    z-index: 2;
    transform: translateX(0);
  }

  /* Layer 2: Content = off-screen left (RTL) */
  .content-area {
    z-index: 3;
    transform: translateX(-100%);
  }

  /* Layer 3: Images = off-screen left (RTL), above content */
  #imagesViewModal.images-view-modal {
    z-index: 4 !important;
    transform: translateX(-100%);
  }

  /* --- State: show content --- */
  body.mobile-show-content .topics-sidebar {
    transform: translateX(100%);
  }

  body.mobile-show-content .content-area {
    transform: translateX(0);
  }

  /* --- State: show images --- */
  body.mobile-show-images .topics-sidebar {
    transform: translateX(100%);
  }

  body.mobile-show-images .content-area {
    transform: translateX(100%);
  }

  body.mobile-show-images #imagesViewModal.images-view-modal {
    transform: translateX(0) !important;
  }

  /* Content area: normal column on mobile */
  .content-area {
    display: flex !important;
    flex-direction: column;
  }

  #content-sections {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
  }

  /* Images panel: full scroll */
  #imagesViewModal .images-view-content {
    height: auto;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
  }

  #imagesViewModal .images-view-body {
    overflow: visible;
    padding: 10px;
  }

  /* -- Mobile back button -- */
  .mobile-back-btn {
    display: inline-flex;
    align-self: flex-start;
    align-items: center;
    gap: 6px;
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid var(--accent-border);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    margin-bottom: 8px;
    position: sticky;
    top: 0;
    z-index: 10;
    width: auto;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }

  .mobile-back-btn:active {
    transform: scale(0.97);
  }

  .mobile-back-btn svg {
    width: 16px;
    height: 16px;
  }

  /* Images panel header visibility on mobile */
  #imagesViewModal .images-view-header {
    display: none;
  }

  body.is-edit-mode #imagesViewModal .images-view-header {
    display: flex;
    padding: 8px 10px;
  }

  /* Mobile: align selection checkboxes to text baseline (slight upward nudge) */
  .item-select,
  .lesson-section-select {
    position: relative;
    top: -1px;
  }

  /* Images panel back button */
  .mobile-back-images {
    display: inline-flex;
    align-self: flex-start;
    align-items: center;
    gap: 6px;
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid var(--accent-border);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    margin: 10px;
    position: sticky;
    top: 0;
    z-index: 10;
    width: auto;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }

  .mobile-back-images:active {
    transform: scale(0.97);
  }

  .mobile-back-images svg {
    width: 16px;
    height: 16px;
  }
}

/* =============================================
   Additional Styles for Errors
   ============================================= */

.error {
  text-align: center;
  padding: 40px;
  color: #c00;
  font-size: 1.1rem;
}

/* Scrollbar styling */
.topics-list::-webkit-scrollbar,
#content-sections::-webkit-scrollbar {
  width: 8px;
}

.topics-list::-webkit-scrollbar-track,
#content-sections::-webkit-scrollbar-track {
  background: transparent;
}

.topics-list::-webkit-scrollbar-thumb,
#content-sections::-webkit-scrollbar-thumb {
  background: rgba(215, 208, 198, 0.9);
  border-radius: 4px;
}

.topics-list::-webkit-scrollbar-thumb:hover,
#content-sections::-webkit-scrollbar-thumb:hover {
  background: rgba(182, 174, 162, 0.95);
}

/* =============================================
   Images View Modal
   ============================================= */

.images-view-modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  overflow: auto;
}

.images-view-content {
  background-color: var(--surface);
  margin: 2% auto;
  padding: 0;
  width: 90%;
  max-width: 1000px;
  max-height: 94vh;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.images-view-header {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: linear-gradient(to bottom, var(--accent-2), var(--accent));
  color: #fff;
}

.images-view-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1;
  text-align: right;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.images-view-header .close {
  color: white;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  height: 28px;
  width: 28px;
  text-align: center;
  line-height: 28px;
  margin: 0;
  flex: 0 0 auto;
  box-shadow: none;
  align-self: flex-start;
  margin-top: 2px;
  /* padding: 1px; */
  /* margin-left: auto; */
}

.images-view-header .close:hover {
  color: white;
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.65);
  transform: scale(1.05);
  transition: transform 0.12s;
}

.images-view-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.images-view-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  min-height: 260px;
}

.images-loading {
  width: 100%;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.images-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: imagesSpinnerSpin 0.9s linear infinite;
}

@keyframes imagesSpinnerSpin {
  to {
    transform: rotate(360deg);
  }
}

.image-container-modal {
  width: 100%;
  display: flex;
  justify-content: center;
  position: relative;
}

/* Per-page controls (reorder/delete) */
.img-page-controls {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  z-index: 5;
  gap: 3px;
  background: #fff;
  border-radius: 12px;
}

body.is-edit-mode .img-page-controls {
  display: inline-flex;
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.img-page-controls .edit-icon-btn {
  height: 26px;
  min-width: 26px;
  padding: 0 6px;
}

.page-modal {
  max-width: 100%;
  height: auto;
  /* border: 1px solid #e8e4dc; */
  border-radius: 4px;
}

.image-container-modal {
  container-type: inline-size;
}

.pointer-modal {
  position: absolute;
  z-index: 3;
  width: clamp(18px, 4.6cqw, 46px);
  height: clamp(11.2px, 2.85cqw, 27.6px);
  transform: none;
  pointer-events: none;
  /* Keep it integrated with the page (no “3D” shadow) */
  filter: none;
  opacity: 0.96;
}

.pointer-modal .pointer-svg,
#pdf-export-root .print-pointer .pointer-svg {
  display: block;
  width: 100%;
  height: 100%;
  shape-rendering: geometricPrecision;
}

.pointer-modal .pointer-arrow-outline,
#pdf-export-root .print-pointer .pointer-arrow-outline {
  fill: none;
  stroke: rgba(255, 255, 255, 0.84);
  stroke-width: 6.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pointer-modal .pointer-arrow,
#pdf-export-root .print-pointer .pointer-arrow {
  fill: none;
  stroke: var(--pointer-color, rgba(47, 74, 63, 0.9));
  stroke-width: 4.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Enable pointer editing (drag/delete/add) in edit mode */
body.is-edit-mode.is-topics-mode .pointer-modal {
  pointer-events: auto;
  cursor: grab;
}

body.is-edit-mode.is-topics-mode .pointer-modal.is-dragging {
  cursor: grabbing;
}

/* =============================================
   Images Panel (always visible) — compact overrides
   ============================================= */

#imagesViewModal.images-view-modal {
  display: block !important;
  position: static;
  flex: 1;
  min-width: 0;
  height: 100%;
  background: #fff;
  z-index: 1;
  overflow: hidden;
}

#imagesViewModal .images-view-content {
  margin: 0;
  width: 100%;
  max-width: none;
  max-height: none;
  height: 100%;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  background: #fff;
}

#imagesViewModal.is-empty-editable .images-view-content {
  position: relative;
}

#imagesViewModal .images-view-header {
  display: none;
}

body.is-edit-mode #imagesViewModal .images-view-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 10px 14px;
  background: transparent;
}

body.is-edit-mode #imagesViewModal.is-empty-editable .images-view-header {
  justify-content: center;
  padding: 0;
}

#imagesViewModal .images-view-header .close {
  display: none;
}

/* No title above the images panel (keep only actions) */
#imagesViewModal .modal-title {
  display: none;
}

#imagesViewModal .images-view-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

#imagesViewModal.is-empty-editable .images-view-actions {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
}

/* In the images header, reuse the small button style but keep it readable */
/* Make the add-image action look like an edit control */
body.is-edit-mode #imagesViewModal #topic-add-image-btn.topic-print-button {
  background: var(--surface-2);
  color: var(--accent);
  border: 1px solid rgba(47, 74, 63, 0.34);
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 700;
  transition:
    background-color 0.14s ease,
    border-color 0.14s ease,
    color 0.14s ease,
    transform 0.12s ease,
    box-shadow 0.14s ease;
}

body.is-edit-mode
  #imagesViewModal.is-empty-editable
  #topic-add-image-btn.topic-print-button {
  border-width: 2px;
  border-style: dashed;
  border-radius: 16px;
  padding: 28px 48px;
  font-size: 1.25rem;
}

body.is-edit-mode
  #imagesViewModal
  #topic-add-image-btn.topic-print-button:hover {
  background: rgba(47, 74, 63, 0.14);
  border-color: rgba(47, 74, 63, 0.48);
}

body.is-edit-mode
  #imagesViewModal
  #topic-add-image-btn.topic-print-button:active {
  transform: translateY(1px);
}

#imagesViewModal .images-view-header .modal-title {
  /* font-size: 1rem; */
  font-weight: 500;
  color: #2f4a3f;
  margin: 0;
}

#imagesViewModal .images-view-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* padding: 20px 18px; */
}

#imagesViewModal .images-view-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  align-items: center;
}

#imagesViewModal .image-container-modal {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0 0 22px;
  margin: 0 0 10px;
  border-bottom: 1px solid #ddd6ca;
}

#imagesViewModal .image-page-shell {
  position: relative;
}

#imagesViewModal .image-container-modal:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: 0;
}

#imagesViewModal .page-modal {
  width: 100%;
  max-width: none;
  height: auto;
  display: block;
  border-radius: 8px;
}

#imagesViewModal .image-ilui-footer {
  padding: 10px 14px 0;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 600;
  font-family: "David", "Times New Roman", serif;
  letter-spacing: 0.01em;
  line-height: 1.5;
  color: #000000;
  background: linear-gradient(
    to bottom,
    rgba(47, 74, 63, 0.035),
    rgba(47, 74, 63, 0.012)
  );
}

#imagesViewModal .images-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  color: #888;
}

#imagesViewModal .images-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e4e0da;
  border-top-color: #2f4a3f;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#imagesViewModal .images-loading-text {
  font-size: 0.95rem;
}

#imagesViewModal .pointer-modal {
  position: absolute;
  --pointer-size: 36px;
  --pointer-color: #b3261e;
  pointer-events: none;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.28));
}

/* Keep PDF more formal (black) */
#pdf-export-root .print-pointer {
  --pointer-color: #111;
}

body.is-edit-mode #imagesViewModal .pointer-modal {
  pointer-events: auto;
}

/* =============================================
   In-app toast + confirm (replaces alert/confirm)
   ============================================= */

#ui-toast-root {
  position: fixed;
  z-index: 2500;
  left: 16px;
  right: auto;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(420px, calc(100vw - 32px));
}

.ui-toast {
  direction: rtl;
  text-align: right;
  font-family: inherit;
  background: rgba(17, 24, 39, 0.98);
  color: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  /* box-shadow:
    0 12px 30px rgba(0, 0, 0, 0.25),
    0 0 0 1px rgba(255, 255, 255, 0.08); */
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-weight: 650;
  opacity: 1;
  transform: translateY(0);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.ui-toast.ui-toast-success {
  background: #0f5132;
}

.ui-toast.ui-toast-error {
  background: #7f1d1d;
}

.ui-toast.ui-toast-info {
  background: #111827;
}

.ui-toast.is-hiding {
  opacity: 0;
  transform: translateY(6px);
}

.ui-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 2600;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 6, 23, 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  padding: 20px;
}

.ui-confirm-overlay.is-open .ui-confirm-dialog {
  animation: ui-confirm-pop 160ms ease-out;
}

@keyframes ui-confirm-pop {
  from {
    transform: translateY(6px) scale(0.985);
    opacity: 0.01;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ui-confirm-overlay.is-open .ui-confirm-dialog {
    animation: none;
  }
}

.ui-confirm-dialog {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  direction: rtl;
  text-align: center;
}

.ui-confirm-title {
  display: none;
}

.ui-confirm-title::before {
  content: "";
  width: 18px;
  height: 18px;
  display: inline-block;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z'/%3E%3C/svg%3E")
    center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z'/%3E%3C/svg%3E")
    center / contain no-repeat;
  opacity: 0.9;
}

.ui-confirm-message {
  padding: 18px 18px 12px;
  color: var(--text);
  line-height: 1.6;
  font-size: 1.02rem;
  text-align: center;
}

.ui-confirm-input {
  width: calc(100% - 36px);
  margin: 0 18px 6px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 0.95rem;
  text-align: right;
}

.ui-confirm-input:focus {
  outline: none;
  border-color: rgba(47, 74, 63, 0.55);
  box-shadow: 0 0 0 4px var(--focus);
}

.ui-confirm-error {
  margin: 0 18px 2px;
  font-size: 0.82rem;
  color: #b91c1c;
  text-align: right;
  min-height: 1em;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.ui-confirm-error.is-visible {
  opacity: 1;
}

.ui-confirm-actions {
  display: flex;
  flex-direction: row;
  gap: 10px;
  justify-content: center;
  padding: 10px 16px 16px;
}

.ui-confirm-actions button {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  padding: 9px 12px;
  font-weight: 800;
  cursor: pointer;
  min-width: 92px;
  transition:
    background 0.12s ease,
    border-color 0.12s ease,
    transform 0.12s ease,
    filter 0.12s ease;
}

.ui-confirm-actions button:hover {
  border-color: rgba(47, 74, 63, 0.28);
  transform: translateY(-0.5px);
}

.ui-confirm-actions button:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(47, 74, 63, 0.22),
    0 0 0 1px rgba(15, 23, 42, 0.18);
}

.ui-confirm-actions .ui-confirm-cancel {
  color: #0f172a;
  background: #ffffff;
}

.ui-confirm-actions .ui-confirm-ok {
  background: linear-gradient(to bottom, var(--accent-2), var(--accent));
  color: #fff;
  border-color: rgba(47, 74, 63, 0.55);
}

.ui-confirm-actions .ui-confirm-ok:hover {
  filter: brightness(1.03);
}

/* Danger variant (delete confirmations) */
.ui-confirm-overlay[data-variant="danger"] .ui-confirm-title {
  color: #b91c1c;
  background: #fff1f2;
}

.ui-confirm-overlay[data-variant="danger"] .ui-confirm-ok {
  background: linear-gradient(to bottom, #ef4444, #b91c1c);
  border-color: rgba(185, 28, 28, 0.55);
}

#imagesViewModal .images-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  color: #9ca3af;
  font-size: 1.05rem;
  text-align: center;
  padding: 60px 40px;
  line-height: 1.6;
}

#imagesViewModal .images-empty-state::before {
  content: "📄";
  font-size: 4rem;
  margin-bottom: 20px;
  opacity: 0.4;
}

#imagesViewModal .error {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: #b91c1c;
  font-size: 1rem;
  padding: 40px;
}

#imagesViewModal .no-content {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: #9ca3af;
  font-size: 1rem;
  padding: 40px;
}

.pool-img {
  position: relative;
  z-index: 1;
  transition: opacity 0.2s;
}
.pool-img.is-loading {
  opacity: 0.6;
}
.pool-img-wrap {
  position: relative;
}

/* ── Ilui Nishmat Modal ─────────────────────────────────────────────────── */

/* Centered header */
.gs-modal-header.ilui-nishmat-header {
  position: relative;
  justify-content: space-between;
}

.ilui-nishmat-header h2 {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  pointer-events: none;
}

.ilui-nishmat-header-spacer {
  display: inline-block;
  width: 34px;
}

/* Green add button */
.ilui-nishmat-add-btn {
  padding: 7px 18px !important;
  font-size: 0.86rem !important;
  white-space: nowrap;
  flex-shrink: 0;
}

.ilui-nishmat-list {
  margin-bottom: 16px;
  min-height: 20px;
}

.ilui-nishmat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border, rgba(15, 23, 42, 0.1));
  font-size: 0.92rem;
}

.ilui-nishmat-row:last-child {
  border-bottom: none;
}

.ilui-nishmat-name {
  font-weight: 700;
}

.ilui-nishmat-views {
  color: var(--muted, #64748b);
  font-size: 0.85rem;
  white-space: nowrap;
}

.ilui-nishmat-empty {
  text-align: center;
  padding: 16px 10px;
  color: var(--muted, #64748b);
  margin: 0;
}

.ilui-nishmat-add-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid var(--border, rgba(15, 23, 42, 0.1));
}

.ilui-nishmat-input {
  flex: 1 1 120px;
  padding: 7px 10px;
  border: 1px solid var(--border, rgba(15, 23, 42, 0.15));
  border-radius: 8px;
  font-size: 0.88rem;
  background: var(--surface);
  color: var(--text);
  direction: rtl;
  outline: none;
  transition: border-color 0.15s;
}

.ilui-nishmat-input:focus {
  border-color: var(--accent, #2f4a3f);
}

.ilui-nishmat-input-num {
  flex: 0 0 110px;
}

.ilui-nishmat-delete-btn {
  flex-shrink: 0;
  background: rgba(180, 35, 24, 0.06);
  border: 1px solid rgba(180, 35, 24, 0.22);
  color: #b42318;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 7px;
  line-height: 1;
  white-space: nowrap;
  transition:
    background 0.14s ease,
    border-color 0.14s ease,
    transform 0.1s ease;
  margin-inline-start: 8px;
}

.ilui-nishmat-delete-btn:hover {
  background: rgba(180, 35, 24, 0.12);
  border-color: rgba(180, 35, 24, 0.4);
}

.ilui-nishmat-delete-btn:active {
  transform: translateY(1px);
}
