/* ============================================================
   Realpad Template Editor — Design System
   Axiforma font · Realpad brand colors · Light-first
   ============================================================ */

/* ── Axiforma Font (local) ────────────────────────────────── */
@font-face {
  font-family: 'Axiforma';
  src: url('../fonts/New Axiforma/Axiforma-Light.otf') format('opentype');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Axiforma';
  src: url('../fonts/New Axiforma/Axiforma-Regular.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Axiforma';
  src: url('../fonts/New Axiforma/Axiforma-Medium.otf') format('opentype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Axiforma';
  src: url('../fonts/New Axiforma/Axiforma-SemiBold.otf') format('opentype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Axiforma';
  src: url('../fonts/New Axiforma/Axiforma-Bold.otf') format('opentype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Axiforma';
  src: url('../fonts/New Axiforma/Axiforma-Italic.otf') format('opentype');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'Axiforma';
  src: url('../fonts/New Axiforma/Axiforma-MediumItalic.otf') format('opentype');
  font-weight: 500;
  font-style: italic;
  font-display: swap;
}

/* ── CSS Variables (Dark theme default) ──────────────────── */
/* Realpad palette
   Primary blue  → CMYK C57 M40 Y0 K2   → #6B96F9
   Brand black   → CMYK C2  M1  Y0 K78  → #373839
   Brand white   → CMYK C1  M0  Y0 K0   → #FAFCFF             */
:root {
  /* Surfaces */
  --bg-base:     #13151a;
  --bg-surface:  #1c1f27;
  --bg-elevated: #232731;
  --bg-overlay:  #1c1f27;

  /* Borders */
  --border:        rgba(255, 255, 255, 0.08);
  --border-bright: rgba(255, 255, 255, 0.15);

  /* Realpad brand primary */
  --rp-blue:       #6B96F9;          /* Primary */
  --rp-blue-dark:  #4f7de8;          /* Hover */
  --rp-blue-dim:   rgba(107, 150, 249, 0.16);
  --rp-blue-dim2:  rgba(107, 150, 249, 0.08);
  --rp-black:      #373839;
  --rp-white:      #FAFCFF;

  /* Semantic accents */
  --accent-blue:   var(--rp-blue);
  --accent-green:  #22c77c;
  --accent-yellow: #f5a623;
  --accent-red:    #f04040;
  --accent-purple: #9b7af8;
  --accent-cyan:   #22d3e8;

  /* Text hierarchy */
  --text-primary:   #e8ecf5;
  --text-secondary: #8e97ae;
  --text-muted:     #50566a;

  /* Placeholder tints */
  --ph-blue:   rgba(107, 150, 249, 0.16);
  --ph-green:  rgba(34, 199, 124, 0.15);
  --ph-yellow: rgba(245, 166, 35, 0.15);
  --ph-red:    rgba(240, 64, 64, 0.15);

  /* Block colors */
  --block-if-color:      var(--rp-blue);
  --block-foreach-color: #9b7af8;

  /* Layout */
  --sidebar-width:     280px;
  --rightpanel-width:  300px;
  --topbar-height:     52px;
  --radius:    8px;
  --radius-sm: 5px;
  --transition: 0.16s ease;

  /* Shadows */
  --shadow-doc:     0 4px 24px rgba(0, 0, 0, 0.5);
  --shadow-popup:   0 12px 40px rgba(0, 0, 0, 0.55);
  --shadow-modal:   0 20px 56px rgba(0, 0, 0, 0.75);
  --shadow-toast:   0 6px 20px rgba(0, 0, 0, 0.4);
  --shadow-tooltip: 0 6px 20px rgba(0, 0, 0, 0.45);
}

/* ── Light theme override ───────────────────────────────── */
html[data-theme="light"] {
  --bg-base:     #f0f2f7;
  --bg-surface:  #ffffff;
  --bg-elevated: #f5f7fc;
  --bg-overlay:  #ffffff;
  --border:        #dde1ec;
  --border-bright: #c3c9d9;

  --rp-blue:       #4a7ef2;
  --rp-blue-dark:  #3366dd;
  --rp-blue-dim:   rgba(74, 126, 242, 0.12);
  --rp-blue-dim2:  rgba(74, 126, 242, 0.06);

  --accent-blue:   #4a7ef2;
  --accent-green:  #10a864;
  --accent-yellow: #d48f0c;
  --accent-red:    #d93030;
  --accent-purple: #7655d9;
  --accent-cyan:   #0ea6c0;

  --text-primary:   #1e2130;
  --text-secondary: #4a5168;
  --text-muted:     #8a90a4;

  --ph-blue:   rgba(74, 126, 242, 0.12);
  --ph-green:  rgba(16, 168, 100, 0.10);
  --ph-yellow: rgba(212, 143, 12, 0.10);
  --ph-red:    rgba(217, 48, 48, 0.10);

  --block-if-color:      #4a7ef2;
  --block-foreach-color: #7655d9;

  --shadow-doc:     0 2px 16px rgba(30, 33, 48, 0.10);
  --shadow-popup:   0 8px 28px rgba(30, 33, 48, 0.14);
  --shadow-modal:   0 12px 36px rgba(30, 33, 48, 0.18);
  --shadow-toast:   0 4px 14px rgba(30, 33, 48, 0.12);
  --shadow-tooltip: 0 4px 14px rgba(30, 33, 48, 0.12);
}

html[data-theme="light"] .btn-ghost {
  background: #ffffff;
  border-color: var(--border);
  color: var(--text-primary);
}

html[data-theme="light"] .btn-ghost:hover {
  background: var(--bg-elevated);
  border-color: var(--border-bright);
}



/* ── Reset ───────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  font-family: 'Axiforma', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Layout ──────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-columns: var(--sidebar-width) 1fr var(--rightpanel-width);
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns 0.2s ease;
}

#app.left-collapsed {
  grid-template-columns: 0 1fr var(--rightpanel-width);
}

#app.right-collapsed {
  grid-template-columns: var(--sidebar-width) 1fr 0;
}

#app.left-collapsed.right-collapsed {
  grid-template-columns: 0 1fr 0;
}

#toggle-left-btn svg,
#toggle-right-btn svg,
#uncollapse-left-btn svg,
#uncollapse-right-btn svg {
  transition: transform var(--transition);
}

#app:not(.left-collapsed) #uncollapse-left-btn {
  display: none;
}

#app:not(.right-collapsed) #uncollapse-right-btn {
  display: none;
}

#app.left-collapsed #toggle-left-btn svg,
#app.left-collapsed #uncollapse-left-btn svg,
#app.right-collapsed #toggle-right-btn svg,
#app.right-collapsed #uncollapse-right-btn svg {
  transform: rotate(180deg);
}

/* ── Top Bar ─────────────────────────────────────────────── */
#topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

#topbar .logo {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--rp-blue);
  display: flex;
  align-items: center;
  gap: 7px;
  margin-right: 12px;
  white-space: nowrap;
  line-height: 1;
}
#topbar .logo i {
  display: flex;
  align-items: center;
  justify-content: center;
}

#topbar .logo svg {
  width: 22px;
  height: 22px;
}

#topbar .divider {
  width: 1px;
  height: 24px;
  background: var(--border-bright);
  margin: 0 4px;
}

#topbar .spacer {
  flex: 1;
}

#topbar .doc-name {
  color: var(--text-secondary);
  font-size: 13px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1;
}
.btn i {
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  background: var(--rp-blue);
  color: #fff;
  border-color: var(--rp-blue);
}

.btn-primary:hover {
  background: var(--rp-blue-dark);
  border-color: var(--rp-blue-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(107, 150, 249, 0.38);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-bright);
  color: var(--text-primary);
}

.btn-success {
  background: var(--accent-green);
  color: #fff;
}

.btn-success:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(34, 199, 124, 0.38);
}

.btn-warning {
  background: var(--accent-yellow);
  color: #000;
}

.btn-warning:hover {
  background: #d97706;
}

.btn-danger {
  background: var(--accent-red);
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-icon {
  padding: 7px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 11px;
}

.btn-fade {
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  overflow: hidden;
  white-space: nowrap;
}

.hidden-btn {
  opacity: 0;
  max-width: 0;
  padding-left: 0;
  padding-right: 0;
  margin-left: 0;
  margin-right: 0;
  border-width: 0;
  pointer-events: none;
  transform: scaleX(0);
}

/* ── Left Sidebar ─────────────────────────────────────────── */
#sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-header {
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#ph-search {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px 7px 32px;
  outline: none;
  transition: border-color var(--transition);
}

#ph-search::placeholder {
  color: var(--text-muted);
}

#ph-search:focus {
  border-color: var(--accent-blue);
}

.search-wrapper {
  position: relative;
}

.search-wrapper .search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

#ph-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 6px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── Category sections ───────────────────────────────────── */
.ph-category {
  margin-bottom: 2px;
}

.ph-category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-top: 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--cat-color) 12%, transparent);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid var(--cat-color, transparent);
}

.ph-category-header:hover {
  background: color-mix(in srgb, var(--cat-color) 20%, transparent);
}

.ph-category-header .cat-icon {
  font-size: 13px;
  line-height: 1;
  opacity: 0.85;
  flex-shrink: 0;
}

.ph-category-header .cat-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cat-count {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--cat-color, var(--text-muted));
  background: color-mix(in srgb, var(--cat-color) 15%, var(--bg-surface));
  border-radius: 8px;
  padding: 2px 6px;
  flex-shrink: 0;
  line-height: 1;
}

svg.ph-category-toggle {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform var(--transition);
  opacity: 0.6;
}

.ph-category.collapsed svg.ph-category-toggle {
  transform: rotate(-90deg);
}

.ph-category.collapsed .ph-items {
  display: none;
}

/* ── Placeholder items ───────────────────────────────────── */
.ph-items {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 2px 2px 6px;
}

.ph-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}

.ph-item:hover {
  background: var(--rp-blue-dim2);
}

.ph-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ph-item .ph-var {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-blue);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color var(--transition);
}

.ph-item .ph-label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  transition: color var(--transition);
}

.ph-item:hover .ph-label {
  color: var(--text-secondary);
}

/* Insert icon (shown on hover) */
.ph-insert-icon {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  color: var(--rp-blue);
  background: var(--rp-blue-dim);
  transition: background var(--transition);
}

.ph-item:hover .ph-insert-icon {
  display: flex;
}

.ph-item:hover .ph-insert-icon:hover {
  background: rgba(107, 150, 249, 0.28);
}

/* Tooltip */
.ph-item-tooltip {
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 240px;
  z-index: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  box-shadow: var(--shadow-tooltip);
}

.ph-item:hover .ph-item-tooltip {
  opacity: 1;
}

.ph-item-tooltip .tt-var {
  font-family: monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-blue);
  margin-bottom: 5px;
}

.ph-item-tooltip .tt-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.ph-item-tooltip .tt-example {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  font-style: italic;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

/* ── Document Area ───────────────────────────────────────── */
#doc-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}

#doc-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

#doc-toolbar .section-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 4px;
}

#doc-viewport {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 32px;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  transition: background 0.2s ease;
}

/* ── Pagination mode ─────────────────────────────────────────── */
#doc-viewport.paginated {
  background: #9ea3ab;   /* gray "printer tray" */
  padding: 28px 32px;
}

/* In paginated mode the document-area card is replaced by per-page styling */
#doc-viewport.paginated #document-area {
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  padding: 0;
  /* Width is driven by JS (A4 in px) via .textutil-doc / .docx-body width.
     Keep document-area itself unconstrained so it centers the inner page. */
  max-width: none;
  width: fit-content;
  margin: 0 auto;
}

#doc-viewport.paginated #document-area.server-rendered {
  padding: 0;
}

/* The textutil-doc div = white page(s).
   width / max-width are set dynamically by JS to the exact A4 pixel width.
   padding is set dynamically by JS to match actual document margins.
   box-sizing is set to border-box by JS so padding is included in the width. */
#doc-viewport.paginated .textutil-doc,
#doc-viewport.paginated .docx-body {
  background: #fff;
  /* fallback padding — overridden by JS when server returns margins */
  padding: 48pt 56pt;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.15);
  box-sizing: border-box; /* ensures JS-set width includes padding */
}

/* Page separator: gray band between pages, contains footer + gap + header */
.page-separator {
  display: flex;
  flex-direction: column;
  /* margin-left/right set dynamically by applyPagination() to match actual doc margins */
  background: #9ea3ab;
  position: relative;
  pointer-events: none;
  min-height: 36px;
}

/* Top shadow (bottom edge of page above) */
.page-separator::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 8px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.22), transparent);
  z-index: 1;
}

/* Bottom shadow (top edge of page below) */
.page-separator::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 8px;
  background: linear-gradient(to top, rgba(0,0,0,0.22), transparent);
  z-index: 1;
}

/* Footer of the page above — inside separator, matching doc padding */
.sep-prev-footer,
.sep-next-header {
  background: #fff;
  font-family: inherit;
  font-size: 9pt;
  color: #555;
  pointer-events: none;
  /* horizontal padding matches the textutil-doc padding (set by JS) — use same margin offset */
  padding: 4pt 0 4pt 0;
}
/* Gap between footer and header inside separator */
.sep-gap {
  flex: 1;
  min-height: 16px;
}

/* First-page header (inserted above all content) */
.page-header-area {
  font-family: inherit;
  font-size: 9pt;
  color: #555;
  padding-bottom: 4pt;
  border-bottom: 1px solid #ddd;
  margin-bottom: 4pt;
}

/* Last-page footer (appended after all content) */
.page-footer-area {
  font-family: inherit;
  font-size: 9pt;
  color: #555;
  padding-top: 4pt;
  border-top: 1px solid #ddd;
  margin-top: 4pt;
}

/* Pagination toggle button: highlight when active */
#pagination-toggle-btn.active {
  color: var(--rp-blue);
  background: var(--rp-blue-dim);
  border-color: rgba(107, 150, 249, 0.3);
}

/* ── Document Rendering ──────────────────────────────────── */
/* ── AI Metrics Bar ────────────────────────────────────────── */
#ai-metrics-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(79, 142, 247, 0.04);
  font-size: 11px;
}
.metric-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
}
.metric-chip b { color: var(--text-primary); }
.metric-cov b  { color: var(--accent-blue); }
.metric-hi b   { color: var(--accent-green); }
.metric-med b  { color: var(--accent-yellow); }
.metric-lo b   { color: var(--accent-red); }
.metric-unm    { border-color: rgba(239,68,68,0.3); }
.metric-dur    { color: var(--text-muted); margin-left: auto; }

#docx-preview-container {
  max-width: 820px;
  margin: 0 auto;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-doc);
  padding: 40px;
  min-height: 500px;
}

#document-area {
  max-width: 900px;
  margin: 0 auto;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-doc);
  padding: 48px 56px;
  min-height: 500px;
  outline: none;
  position: relative;
  overflow-x: auto;
}

/* Server-rendered: let textutil/python-docx CSS through unmodified */
#document-area.server-rendered {
  padding: 32px 40px;
}

/* textutil wraps body content in .textutil-doc */
#document-area .textutil-doc {
  max-width: 600pt;
  margin: 0 auto;
  word-wrap: break-word;
}

/* python-docx fallback */
#document-area .docx-body {
  margin: 0 auto;
}

/* ph-span overlays: inherit surrounding run color */
#document-area.server-rendered .ph-span {
  color: inherit;
}

/* Mammoth fallback: apply sensible base styles since mammoth outputs minimal HTML */
#document-area.mammoth-rendered {
  padding: 48px 56px;
}

#document-area.mammoth-rendered * {
  color: #111;
  max-width: 100%;
  box-sizing: border-box;
  font-family: 'Times New Roman', Times, serif;
}

#document-area.mammoth-rendered p {
  margin-bottom: 8px;
  line-height: 1.7;
}

#document-area.mammoth-rendered table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  table-layout: fixed;
}

#document-area.mammoth-rendered td,
#document-area.mammoth-rendered th {
  border: 1px solid #ccc;
  padding: 6px 10px;
  word-break: break-word;
}

#document-area.mammoth-rendered h1,
#document-area.mammoth-rendered h2,
#document-area.mammoth-rendered h3 {
  margin-bottom: 12px;
  margin-top: 16px;
}

#document-area.mammoth-rendered ul,
#document-area.mammoth-rendered ol {
  padding-left: 24px;
  margin-bottom: 8px;
}

#document-area.mammoth-rendered li {
  margin-bottom: 3px;
}

/* ── Page Counter ──────────────────────────────────────── */
.page-counter {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 6px;
  background: var(--bg-base, #f3f4f6);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary, #6b7280);
  margin-left: 6px;
  user-select: none;
}

.page-counter.hidden {
  display: none;
}

.page-counter-icon {
  font-size: 13px;
}

.page-counter-text {
  white-space: nowrap;
}

/* ── docx-preview rendered ──────────────────────────────── */
#document-area.docx-preview-rendered {
  padding: 0;
  background: transparent;
  box-shadow: none;
  max-width: 100%;
  border-radius: 0;
}

/* docx-preview wrapper */
#document-area.docx-preview-rendered .docx-wrapper {
  background: transparent;
  padding: 0;
}

/* ── PAGINATED mode (breakPages: true) — A4 sheets on gray tray ── */
#doc-viewport.paginated #document-area.docx-preview-rendered .docx-wrapper {
  background: #9ea3ab;
  padding: 24px 0;
}

#doc-viewport.paginated #document-area.docx-preview-rendered section.docx {
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.15);
  margin: 20px auto;
  outline: none;
  cursor: text;
}

/* ── CONTINUOUS mode (breakPages: false) — single white page ── */
#doc-viewport:not(.paginated) #document-area.docx-preview-rendered .docx-wrapper {
  background: #fff;
  padding: 0;
  box-shadow: var(--shadow-doc, 0 1px 3px rgba(0,0,0,0.12));
  border-radius: var(--radius, 8px);
  max-width: 900px;
  margin: 0 auto;
}

#doc-viewport:not(.paginated) #document-area.docx-preview-rendered section.docx {
  background: #fff;
  box-shadow: none;
  margin: 0 auto;
  outline: none;
  cursor: text;
}

/* ── Headers & Footers styling ── */
#document-area.docx-preview-rendered header.docx {
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 4pt;
  margin-bottom: 8pt;
  opacity: 0.7;
  font-size: 0.9em;
}

#document-area.docx-preview-rendered footer.docx {
  border-top: 1px solid #e5e7eb;
  padding-top: 4pt;
  margin-top: 8pt;
  opacity: 0.7;
  font-size: 0.9em;
}

/* Keep placeholder spans styled consistently */
#document-area.docx-preview-rendered .ph-span {
  color: inherit;
}

/* Ensure images stay within bounds */
#document-area.docx-preview-rendered img {
  max-width: 100%;
  height: auto;
}

/* ── Drop Zone ───────────────────────────────────────────── */
#drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 380px;
  max-width: 480px;
  margin: 60px auto;
  border: 2px dashed var(--border-bright);
  border-radius: 16px;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  padding: 40px;
  background: var(--bg-surface);
}

#drop-zone:hover,
#drop-zone.drag-over {
  border-color: var(--rp-blue);
  background: var(--rp-blue-dim2);
}

#drop-zone .drop-icon {
  font-size: 52px;
  margin-bottom: 16px;
}

#drop-zone h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

#drop-zone p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

#drop-zone .btn {
  margin-top: 20px;
}

/* ── Placeholder spans ───────────────────────────────────── */
.ph-span {
  display: inline;
  background: var(--ph-blue);
  color: var(--accent-blue);
  border: 1px solid rgba(79, 142, 247, 0.3);
  border-radius: 4px;
  padding: 0 4px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace !important;
  font-size: 0.9em;
  cursor: pointer;
  position: relative;
  font-weight: 600;
  transition: all var(--transition);
}

.ph-span:hover {
  background: rgba(79, 142, 247, 0.30);
}

/* Pending AI suggestions — all blue with pulse, regardless of confidence */
.ph-span.ai-high,
.ph-span.ai-medium,
.ph-span.ai-low {
  background: var(--ph-blue);
  color: var(--accent-blue);
  border-color: rgba(79, 142, 247, 0.5);
}

.ph-span.pending-high,
.ph-span.pending-medium,
.ph-span.pending-low {
  animation: pulse-blue 2s infinite;
}

/* Confirmed placeholders — green */
.ph-span[data-confirmed="true"] {
  background: var(--ph-green);
  color: var(--accent-green);
  border-color: rgba(16, 185, 129, 0.4);
}

.ph-span[data-confirmed="true"]:hover {
  background: rgba(16, 185, 129, 0.25);
}

@keyframes pulse-blue {
  0%, 100% { box-shadow: 0 0 0 0 rgba(79, 142, 247, 0.5) }
  50%       { box-shadow: 0 0 0 4px rgba(79, 142, 247, 0.1) }
}

/* ── Block wrappers ──────────────────────────────────────── */
.rp-block {
  display: inline;
  position: relative;
}

.rp-block-label,
.rp-block-end-label {
  display: inline;
  font-family: 'JetBrains Mono', 'Fira Code', monospace !important;
  font-size: 0.88em;
  font-weight: 600;
  padding: 0 4px;
  border-radius: 3px;
  cursor: default;
  user-select: none;
  border: 1px solid transparent;
}

.rp-block-if .rp-block-label,
.rp-block-if .rp-block-end-label {
  background: var(--ph-blue);
  color: var(--accent-blue);
  border-color: rgba(79, 142, 247, 0.4);
}

.rp-block-foreach .rp-block-label,
.rp-block-foreach .rp-block-end-label {
  background: var(--ph-yellow);
  color: var(--accent-yellow);
  border-color: rgba(245, 158, 11, 0.4);
}

.rp-block-del-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.1);
  color: var(--accent-red);
  font-size: 10px;
  line-height: 1;
  margin-left: 4px;
  cursor: pointer;
  border: 1px solid rgba(239, 68, 68, 0.3);
  transition: all 0.15s;
  vertical-align: middle;
}

.rp-block-del-btn:hover {
  background: var(--accent-red);
  color: white;
}

.rp-block-content {
  display: inline;
  padding: 0 2px;
}

/* ── Selection Popup ─────────────────────────────────────── */
#selection-popup {
  position: fixed;
  z-index: 1000;
  background: var(--bg-overlay);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  box-shadow: var(--shadow-popup);
  width: 340px;
  max-height: 420px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(6px) scale(0.98);
  transition: all 0.15s ease;
  pointer-events: none;
}

#selection-popup.visible {
  opacity: 1;
  transform: none;
  pointer-events: all;
}

#popup-search-wrap {
  padding: 10px 10px 6px;
  border-bottom: 1px solid var(--border);
}

#popup-search {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 10px;
  outline: none;
}

#popup-search:focus {
  border-color: var(--accent-blue);
}

#popup-cats {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 6px 10px;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
}

#popup-cats::-webkit-scrollbar {
  display: none;
}

.popup-cat-btn {
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.popup-cat-btn.active,
.popup-cat-btn:hover {
  background: rgba(79, 142, 247, 0.2);
  border-color: var(--accent-blue);
  color: var(--text-primary);
}

#popup-list {
  overflow-y: auto;
  max-height: 260px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.popup-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.popup-item:last-child {
  border-bottom: none;
}

.popup-item:hover {
  background: rgba(79, 142, 247, 0.12);
}

.popup-item .pi-var {
  font-family: monospace;
  font-size: 11px;
  color: var(--accent-blue);
  flex-shrink: 0;
  line-height: 1.8;
}

.popup-item .pi-info {
  flex: 1;
}

.popup-item .pi-label {
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 500;
}

.popup-item .pi-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

#popup-actions {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ── Right Panel ─────────────────────────────────────────── */
#right-panel {
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-content-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 10px 8px;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  line-height: 1;
}
.panel-tab i {
  display: flex;
  align-items: center;
  justify-content: center;
}

.panel-tab.active {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
  background: rgba(79, 142, 247, 0.06);
}

.panel-tab:hover:not(.active) {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.panel-section {
  padding: 12px;
}

/* ── AI Suggestions ──────────────────────────────────────── */
#ai-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(79, 142, 247, 0.06);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#ai-header h4 {
  font-size: 12px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Suggestion group headers ────────────────────────────── */
.sugg-group-header {
  padding: 5px 12px 3px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-top: 6px;
}

.sugg-group-header:first-child { margin-top: 0; }

.sugg-group-high   { color: #10b981; }
.sugg-group-medium { color: #f59e0b; }
.sugg-group-low    { color: #ef4444; }

.suggestion-card {
  margin: 2px 8px 6px;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  background: var(--bg-elevated);
  font-size: 12px;
  cursor: pointer;
  transition: background var(--transition), opacity 0.2s ease, transform 0.2s ease, max-height 0.25s ease, padding 0.2s ease, margin 0.2s ease;
  overflow: hidden;
  max-height: 300px;
}

.suggestion-card.removing {
  opacity: 0;
  transform: translateX(16px);
  max-height: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  pointer-events: none;
}

.suggestion-card:hover {
  background: var(--bg-surface);
}

.suggestion-card.high {
  border-color: rgba(16, 185, 129, 0.4);
}

.suggestion-card.medium {
  border-color: rgba(245, 158, 11, 0.4);
}

.suggestion-card.low {
  border-color: rgba(239, 68, 68, 0.4);
}

.sugg-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  margin-bottom: 6px;
  letter-spacing: 0.04em;
}

.sugg-badge.high {
  background: rgba(16, 185, 129, 0.2);
  color: #10b981;
}

.sugg-badge.medium {
  background: rgba(245, 158, 11, 0.2);
  color: #f59e0b;
}

.sugg-badge.low {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.sugg-original {
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 4px;
  word-break: break-word;
}

.sugg-placeholder {
  font-family: monospace;
  color: var(--accent-blue);
  font-weight: 600;
  margin-bottom: 4px;
}

.sugg-reason {
  color: var(--text-secondary);
  margin-bottom: 8px;
  line-height: 1.4;
}

.sugg-block-hint {
  font-size: 10px;
  color: var(--accent-cyan);
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.2);
  border-radius: 3px;
  padding: 2px 6px;
  margin-bottom: 8px;
  display: inline-block;
  font-family: var(--font-mono);
}

/* ── Block suggestion cards ─────────────────────────────── */
.sugg-group-blocks {
  color: var(--accent-cyan) !important;
  border-color: rgba(34, 211, 238, 0.3) !important;
}

.block-suggestion-card {
  display: flex;
  gap: 10px;
  border-color: rgba(34, 211, 238, 0.3) !important;
  background: rgba(34, 211, 238, 0.04);
}

.sugg-block-icon {
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  padding-top: 2px;
}

.sugg-block-body {
  flex: 1;
  min-width: 0;
}

.sugg-block-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-cyan);
  margin-bottom: 4px;
  word-break: break-all;
}

.sugg-block-desc {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 6px;
}

.sugg-block-vars {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
}

.sugg-block-if-hint {
  font-size: 10px;
  color: var(--accent-yellow);
  margin-bottom: 6px;
}

.sugg-block-if-hint code {
  background: rgba(245, 158, 11, 0.1);
  padding: 1px 4px;
  border-radius: 2px;
  font-family: var(--font-mono);
}

.sugg-block-actions {
  display: flex;
  gap: 6px;
}

/* Flash animation for block-wrap targeting */
@keyframes block-flash {
  0%, 100% { background-color: transparent; }
  25%  { background-color: rgba(34, 211, 238, 0.15); }
  75%  { background-color: rgba(34, 211, 238, 0.08); }
}

.rp-block-flash {
  animation: block-flash 0.6s ease 2;
}

.sugg-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

/* ── Validation ──────────────────────────────────────────── */
.validation-item {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  cursor: pointer;
  transition: background var(--transition);
}

.validation-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.validation-item .vi-icon {
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 1px;
}

.validation-item .vi-text {
  flex: 1;
  color: var(--text-primary);
  line-height: 1.4;
}

.validation-item .vi-hint {
  color: var(--text-muted);
  margin-top: 2px;
}

.validation-item .vi-wrap-btn {
  font-size: 10px;
}

.validation-ok {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 20px;
  color: var(--accent-green);
  font-size: 13px;
  font-weight: 500;
}

/* ── Modals ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  border-radius: 14px;
  padding: 28px;
  width: 480px;
  max-width: 95vw;
  box-shadow: var(--shadow-modal);
  transform: scale(0.96);
  transition: transform 0.2s;
}

.modal-overlay.visible .modal {
  transform: scale(1);
}

.modal h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.modal p {
  color: var(--text-secondary);
  margin-bottom: 20px;
  font-size: 13px;
  line-height: 1.5;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  transition: border-color var(--transition);
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent-blue);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ── Block Dialog ────────────────────────────────────────── */
#block-dialog .block-type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.block-type-card {
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.block-type-card.selected {
  border-color: var(--accent-blue);
  background: rgba(79, 142, 247, 0.1);
}

.block-type-card .btc-icon {
  font-size: 24px;
  margin-bottom: 6px;
}

.block-type-card .btc-name {
  font-weight: 600;
  font-size: 13px;
}

.block-type-card .btc-desc {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── Spinner ─────────────────────────────────────────────── */
.spinner-overlay {
  position: absolute;
  inset: 0;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  border-radius: var(--radius);
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 20px;
}

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

.spinner-text {
  color: #f0f2f5;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.spinner-sub {
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  margin-top: 6px;
  font-weight: 500;
}

/* ── Toast notifications ─────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  box-shadow: var(--shadow-toast);
  font-size: 13px;
  color: var(--text-primary);
  animation: toastIn 0.2s ease;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.success {
  border-color: rgba(16, 185, 129, 0.5);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.5);
}

.toast.warning {
  border-color: rgba(245, 158, 11, 0.5);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

/* ── Rules Management ────────────────────────────────────── */
.rule-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.rule-item .rule-pattern {
  flex: 1;
}

.rule-item .rule-ph {
  font-family: monospace;
  color: var(--accent-blue);
  font-size: 11px;
}

.rule-item .rule-desc {
  color: var(--text-muted);
  margin-top: 2px;
}

.rule-item .rule-count {
  font-size: 10px;
  color: var(--text-muted);
  padding: 2px 6px;
  background: var(--bg-surface);
  border-radius: 10px;
  flex-shrink: 0;
}

/* ── Progress indicators ─────────────────────────────────── */
.progress-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* Pulsing fill when waiting for batch results */
.progress-pulsing .progress-fill {
  animation: progress-pulse 1.6s ease-in-out infinite;
}

@keyframes progress-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

.progress-meta {
  display: flex;
  justify-content: flex-end;
  margin-top: 5px;
}

.progress-pct-label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.spinner-cancel-btn {
  margin-top: 20px;
  opacity: 0.7;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}
.spinner-cancel-btn:hover { opacity: 1; color: #fff; }

/* ── Scrollbars universal ────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-bright);
}

/* ── Utility ─────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

.text-muted {
  color: var(--text-muted);
}

.text-sm {
  font-size: 12px;
}

.monospace {
  font-family: monospace;
}

.flex {
  display: flex;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.gap-2 {
  gap: 8px;
}

.mt-2 {
  margin-top: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.badge-blue {
  background: rgba(79, 142, 247, 0.2);
  color: var(--accent-blue);
}

.badge-green {
  background: rgba(16, 185, 129, 0.2);
  color: var(--accent-green);
}

.badge-yellow {
  background: rgba(245, 158, 11, 0.2);
  color: var(--accent-yellow);
}

.badge-red {
  background: rgba(239, 68, 68, 0.2);
  color: var(--accent-red);
}

/* ── Responsive adjustments ──────────────────────────────── */
@media (max-width: 1100px) {
  :root {
    --sidebar-width: 240px;
    --rightpanel-width: 260px;
  }
}

@media (max-width: 900px) {
  :root {
    --rightpanel-width: 0px;
  }

  #right-panel {
    display: none;
  }
}

/* ── Preview Mode ────────────────────────────────────────── */
.preview-mode #document-area {
  background: #fff;
  box-shadow: 0 0 0 2px var(--accent-blue), var(--shadow-doc);
  pointer-events: none;
}

.preview-mode #document-area .ph-span {
  background: transparent;
  border: none;
  padding: 0;
  color: inherit;
  font-family: inherit !important;
  font-size: inherit;
  font-weight: inherit;
  animation: none;
}

/* Missing data in preview */
.preview-mode #document-area .ph-span.missing-data,
.preview-mode #document-area span.missing-data {
  background: var(--ph-red);
  color: var(--accent-red);
  padding: 0 4px;
  border-radius: 3px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace !important;
}

.preview-mode #document-area .rp-block-label,
.preview-mode #document-area .rp-block-end-label,
.preview-mode #document-area .rp-block-del-btn {
  display: none !important;
}

/* ── Panel resize handles ────────────────────────────────── */
#sidebar, #right-panel { position: relative; }

.panel-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  z-index: 20;
  cursor: col-resize;
}

#sidebar > .panel-resize-handle  { right: 0; }
#right-panel > .panel-resize-handle { left: 0; }

.panel-resize-handle::after {
  content: '';
  position: absolute;
  top: 25%;
  bottom: 25%;
  left: 3px;
  width: 2px;
  border-radius: 2px;
  background: transparent;
  opacity: 0;
  transition: background 0.2s, opacity 0.2s;
}

.panel-resize-handle:hover::after,
.panel-resize-handle.is-dragging::after {
  background: var(--accent-blue);
  opacity: 0.65;
}

/* ── Panel edge arrows (shown when collapsed) ────────────── */
.panel-edge-arrow {
  position: fixed;
  top: calc(var(--topbar-height) + (100vh - var(--topbar-height)) / 2);
  transform: translateY(-50%);
  z-index: 150;
  width: 18px;
  height: 44px;
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  transition: color 0.15s, background 0.15s;
  border-radius: var(--radius-sm);
}

.panel-edge-arrow:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-primary);
}

.panel-edge-arrow.visible {
  display: flex;
}

#sidebar-edge-arrow    { left: 2px; }
#rightpanel-edge-arrow { right: 2px; }

/* Hide doc-toolbar uncollapse buttons — replaced by edge arrows */
#uncollapse-left-btn,
#uncollapse-right-btn { display: none !important; }

/* ── Validation item — navigable ────────────────────────── */
.vi-navigable { cursor: pointer; }

.vi-goto {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  transition: color 0.15s;
}

.vi-navigable:hover .vi-goto { color: var(--accent-blue); }

/* ── Validation flash highlight ──────────────────────────── */
@keyframes rp-validation-flash {
  0%   { box-shadow: 0 0 0 0 transparent; }
  20%  { box-shadow: 0 0 0 5px rgba(245, 158, 11, 0.7); }
  80%  { box-shadow: 0 0 0 5px rgba(245, 158, 11, 0.5); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.rp-validation-flash {
  animation: rp-validation-flash 1.8s ease !important;
  border-radius: 3px;
  position: relative;
}

/* ── Smart Search Highlights ──────────────────────────────── */
.ph-item mark,
.popup-item mark {
  background: rgba(255, 196, 0, 0.35);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Recently Used Section ───────────────────────────────── */
.ph-recent-section {
  border-bottom: 1px solid var(--border-subtle, #e5e7eb);
  margin-bottom: 4px;
  padding-bottom: 4px;
}

.ph-recent-header {
  --cat-color: #9ca3af;
}

.ph-item-recent .ph-var::after {
  content: '🕐';
  font-size: 9px;
  margin-left: 4px;
  opacity: 0.5;
}

/* Sidebar no-results */
.ph-no-results {
  padding: 24px 16px;
  color: var(--text-muted, #9ca3af);
  font-size: 12px;
  text-align: center;
  line-height: 1.5;
}

/* Flat search results (no category grouping) */
.ph-search-results {
  padding: 4px 0;
}

/* ── Popup: recently used header & separator ─────────────── */
.popup-recent-header {
  padding: 8px 14px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted, #9ca3af);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.popup-separator {
  height: 1px;
  background: var(--border-subtle, #e5e7eb);
  margin: 6px 14px;
}

/* Validation Badge */
#validation-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 800;
  line-height: 18px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* ── Learning Badge ──────────────────────────────────────────── */
.learning-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 12px;
  background: linear-gradient(135deg, #e0f2fe, #dbeafe);
  color: #1d4ed8;
  font-size: 11px;
  font-weight: 600;
  margin-left: 8px;
  cursor: default;
  user-select: none;
  transition: opacity 0.3s;
}
.learning-badge.hidden { display: none; }
.learning-badge i { color: #7c3aed; }
.learning-clear-btn {
  background: none;
  border: none;
  color: #93a3b8;
  cursor: pointer;
  padding: 0 0 0 4px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  transition: color 0.15s;
}
.learning-clear-btn:hover { color: #dc2626; }

/* ── Drag & Drop ─────────────────────────────────────────────── */
.ph-item[draggable="true"] { cursor: grab; }
.ph-item.ph-item-dragging { opacity: 0.5; }
#document-area.drag-over {
  outline: 2px dashed #3b82f6;
  outline-offset: -2px;
  background-color: rgba(59, 130, 246, 0.03);
}

/* ── Toast Undo Link ─────────────────────────────────────────── */
.toast .toast-undo {
  margin-left: 8px;
  color: #93c5fd;
  cursor: pointer;
  text-decoration: underline;
  font-weight: 600;
}
.toast .toast-undo:hover { color: #fff; }