/* ==========================================================================
   Universal Letter Studio - Design System & Stylesheet
   Crafted for Non-Technical Users · Swiss Editorial Excellence
   ========================================================================== */

:root {
  /* Document Dynamic Theme Variables */
  --accent-color: #1e3a8a;          /* Primary Accent (Navy default) */
  --accent-light: #eff6ff;          /* Light tint for accents */
  --divider-color: #1e3a8a;         /* Header divider color */
  --doc-font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --doc-font-size: 14px;
  --doc-line-height: 1.54;
  --doc-text-color: #111827;
  --doc-text-muted: #4b5563;

  /* Stamp & Watermark Variables */
  --stamp-rotation: -4deg;
  --stamp-opacity: 0.85;
  --stamp-color: #1e3a8a;
  --watermark-opacity: 0.06;

  /* ------------------------------------------------------------------------
     Studio Workspace UI Colors — LIGHT THEME (default)

     These tokens style the STUDIO CHROME only (header, sidebar, canvas stage,
     toolbars, modals). They are deliberately kept separate from the --doc-*
     and --accent-color tokens above, which style the A4 sheet itself and must
     never follow the UI theme — the paper stays white so the screen matches
     the print/PDF output. See the [data-theme="dark"] block below.
     ------------------------------------------------------------------------ */

  color-scheme: light;

  /* Backgrounds & Surfaces */
  --ui-bg: #e8ecf0;                 /* app + canvas stage backdrop */
  --ui-surface: #ffffff;            /* header, sidebar, panel bars */
  --ui-surface-raised: #ffffff;     /* modals, dropdowns, tour cards */
  --ui-surface-2: #f8fafc;          /* inset cards, tab strips, drawers */
  --ui-surface-3: #f1f5f9;          /* deeper inset, hover fills */
  --ui-surface-4: #e2e8f0;          /* strong hover fill */
  --ui-control-bg: #ffffff;         /* buttons/pills sitting on a panel */
  --ui-control-bg-hover: #f8fafc;
  --ui-input-bg: #ffffff;

  /* Borders */
  --ui-border: #e5e7eb;
  --ui-border-dark: #d1d5db;
  --ui-border-strong: #cbd5e1;
  --ui-border-stronger: #94a3b8;

  /* Text */
  --ui-text-main: #111827;
  --ui-text-sub: #4b5563;
  --ui-text-muted: #6b7280;

  /* Accent */
  --ui-accent: #1e3a8a;
  --ui-accent-hover: #172554;
  --ui-accent-strong: #1d4ed8;              /* accent text on a soft tint */
  --ui-accent-soft: #eff6ff;                /* accent tint background */
  --ui-accent-soft-hover: #dbeafe;
  --ui-accent-soft-border: #bfdbfe;
  --ui-accent-soft-border-hover: #93c5fd;
  --ui-on-accent: #ffffff;                  /* text on a solid accent fill */
  --ui-input-focus: rgba(30, 58, 138, 0.15);

  /* Status: Success */
  --ui-success: #16a34a;
  --ui-success-text: #15803d;
  --ui-success-soft: #f0fdf4;
  --ui-success-border: #bbf7d0;

  /* Status: Warning */
  --ui-warning: #eab308;
  --ui-warning-strong: #d97706;
  --ui-warning-text: #713f12;
  --ui-warning-soft: #fffbeb;
  --ui-warning-border: #fef3c7;

  /* Status: Danger */
  --ui-danger: #dc2626;
  --ui-danger-hover: #b91c1c;
  --ui-danger-active: #991b1b;
  --ui-danger-text: #ef4444;
  --ui-danger-soft: #fef2f2;
  --ui-danger-soft-strong: #fee2e2;
  --ui-danger-border: #fecaca;
  --ui-danger-border-strong: #fca5a5;

  /* Scrollbars */
  --ui-scroll-thumb: #cbd5e1;
  --ui-scroll-thumb-hover: #94a3b8;

  /* Elevation */
  --ui-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --ui-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --ui-shadow-paper: 0 1px 3px rgba(0, 0, 0, 0.12), 0 8px 24px -4px rgba(0, 0, 0, 0.10);

  /* A4 sheet framing on the stage (the sheet fill itself is always white) */
  --ui-sheet-border: rgba(15, 23, 42, 0.08);
  --ui-sheet-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 8px 24px rgba(0, 0, 0, 0.10);

  /* Layout Sizing */
  --header-height: 48px;
  --panel-width: 380px;
}

/* ==========================================================================
   DARK THEME
   Applied when <html data-theme="dark"> is set (see initTheme() in app.js:
   follows the OS preference on first visit, overridable by the header toggle
   and persisted to localStorage).

   Only studio chrome is re-themed. The A4 sheet keeps its white fill and its
   own --doc-* / --accent-color typography tokens, so the on-screen document
   remains a true preview of the printed page.
   ========================================================================== */

:root[data-theme="dark"] {
  color-scheme: dark;

  /* Backgrounds & Surfaces — stage is darkest so the white sheet reads as paper */
  --ui-bg: #0a0e14;
  --ui-surface: #141922;
  --ui-surface-raised: #1a202b;
  --ui-surface-2: #1b212c;
  --ui-surface-3: #222936;
  --ui-surface-4: #2b3341;
  --ui-control-bg: #1c222d;
  --ui-control-bg-hover: #252d3a;
  --ui-input-bg: #101620;

  /* Borders */
  --ui-border: #272e3b;
  --ui-border-dark: #323b4a;
  --ui-border-strong: #3b4553;
  --ui-border-stronger: #55606f;

  /* Text */
  --ui-text-main: #e9edf4;
  --ui-text-sub: #b2bccb;
  --ui-text-muted: #8791a2;

  /* Accent — navy is unreadable on a dark ground, so it lifts to a bright blue */
  --ui-accent: #5b95f7;
  --ui-accent-hover: #7fb0fa;
  --ui-accent-strong: #93c5fd;
  --ui-accent-soft: rgba(91, 149, 247, 0.14);
  --ui-accent-soft-hover: rgba(91, 149, 247, 0.24);
  --ui-accent-soft-border: rgba(91, 149, 247, 0.34);
  --ui-accent-soft-border-hover: rgba(91, 149, 247, 0.55);
  --ui-on-accent: #0a1020;
  --ui-input-focus: rgba(91, 149, 247, 0.28);

  /* Status: Success */
  --ui-success: #22c55e;
  --ui-success-text: #4ade80;
  --ui-success-soft: rgba(34, 197, 94, 0.13);
  --ui-success-border: rgba(34, 197, 94, 0.32);

  /* Status: Warning */
  --ui-warning: #f0b429;
  --ui-warning-strong: #fbbf24;
  --ui-warning-text: #f5cf6b;
  --ui-warning-soft: rgba(240, 180, 41, 0.13);
  --ui-warning-border: rgba(240, 180, 41, 0.32);

  /* Status: Danger */
  --ui-danger: #e5484d;
  --ui-danger-hover: #f0666a;
  --ui-danger-active: #f8898c;
  --ui-danger-text: #f87171;
  --ui-danger-soft: rgba(229, 72, 77, 0.13);
  --ui-danger-soft-strong: rgba(229, 72, 77, 0.22);
  --ui-danger-border: rgba(229, 72, 77, 0.34);
  --ui-danger-border-strong: rgba(229, 72, 77, 0.5);

  /* Scrollbars */
  --ui-scroll-thumb: #333c4b;
  --ui-scroll-thumb-hover: #4a5566;

  /* Elevation — deeper, since dark surfaces need more separation */
  --ui-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --ui-shadow-md: 0 4px 8px -2px rgba(0, 0, 0, 0.55), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
  --ui-shadow-paper: 0 1px 3px rgba(0, 0, 0, 0.6), 0 12px 32px -6px rgba(0, 0, 0, 0.7);

  /* A4 sheet framing — a light hairline ring instead of a soft grey shadow */
  --ui-sheet-border: rgba(255, 255, 255, 0.12);
  --ui-sheet-shadow: 0 0 0 1px rgba(255, 255, 255, 0.05), 0 18px 48px -12px rgba(0, 0, 0, 0.85);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--ui-bg);
  color: var(--ui-text-main);
  line-height: 1.5;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Top Studio Navigation Bar
   ========================================================================== */

.app-header {
  height: var(--header-height);
  background-color: var(--ui-surface);
  border-bottom: 1px solid var(--ui-border);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 50;
  gap: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 0;
  min-width: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 7px;
}

.header-logo-icon {
  width: 26px;
  height: 26px;
  background-color: var(--ui-accent-soft);
  color: var(--ui-accent);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ui-text-main);
  letter-spacing: -0.2px;
  line-height: 1;
}

.header-separator {
  width: 1px;
  height: 20px;
  background-color: var(--ui-border);
  flex-shrink: 0;
}

/* History Controls (Undo / Redo) */
.history-controls {
  display: flex;
  align-items: center;
  gap: 2px;
}


.btn-icon-subtle {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: none;
  color: var(--ui-text-sub);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.12s ease;
}

.btn-icon-subtle:hover:not(:disabled) {
  background-color: var(--ui-surface-3);
  color: var(--ui-text-main);
  border-color: var(--ui-border);
}

.btn-icon-subtle:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Auto-Save Indicator */
.autosave-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--ui-success-text);
  background-color: var(--ui-success-soft);
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--ui-success-border);
  min-width: 76px;
  box-sizing: border-box;
  white-space: nowrap;
  flex-shrink: 0;
}

.autosave-status .status-text {
  display: inline-block;
  min-width: 48px;
  text-align: left;
}

.status-dot {
  width: 6px;
  height: 6px;
  background-color: var(--ui-success);
  border-radius: 50%;
  flex-shrink: 0;
}

/* Center Actions: Templates & Quick Theme */
.header-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 0 0 auto;
}

.btn-showcase {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  background-color: var(--ui-control-bg);
  border: 1px solid var(--ui-border-dark);
  color: var(--ui-text-main);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-showcase:hover {
  background-color: var(--ui-control-bg-hover);
  border-color: var(--ui-accent);
  color: var(--ui-accent);
}

.badge-pill {
  font-size: 10px;
  font-weight: 700;
  background-color: var(--ui-accent-soft);
  color: var(--ui-accent);
  padding: 1px 6px;
  border-radius: 10px;
}

/* Google Docs-Style Search Bar in Studio Header */
.header-search-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background-color: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  color: var(--ui-text-sub);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  height: 28px;
  box-sizing: border-box;
}

.header-search-btn:hover {
  background-color: var(--ui-control-bg-hover);
  border-color: var(--ui-accent);
  color: var(--ui-text-main);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.header-search-btn .search-btn-text {
  font-size: 11.5px;
  font-weight: 500;
}

.header-search-btn .search-kbd {
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  background: var(--ui-surface-3);
  color: var(--ui-text-muted);
  border: 1px solid var(--ui-border);
  border-radius: 3px;
  padding: 1px 5px;
  line-height: 1.2;
}

.quick-theme-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background-color: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  padding: 3px 8px;
  border-radius: 6px;
}

.theme-pill-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text-muted);
}

.theme-pill-select {
  border: none;
  background: transparent;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ui-text-main);
  cursor: pointer;
  outline: none;
}

/* Right Actions */
.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex: 1 1 0;
  min-width: 0;
}

/* Dropdown Menu */
.dropdown {
  position: relative;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 180px;
  background-color: var(--ui-surface-raised);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.03);
  padding: 4px;
  z-index: 80;
}

.dropdown-menu.open {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: none;
  border-radius: 5px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ui-text-main);
  cursor: pointer;
  text-align: left;
  transition: background-color 0.1s;
}

.dropdown-item:hover {
  background-color: var(--ui-surface-3);
}

.dropdown-item svg {
  color: var(--ui-text-muted);
  flex-shrink: 0;
}

.dropdown-divider {
  height: 1px;
  background-color: var(--ui-border);
  margin: 4px 6px;
}

.page-fit-gauge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 4px;
  background-color: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  user-select: none;
  flex-shrink: 0;
  white-space: nowrap;
}

.fit-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.fit-perfect { background-color: var(--ui-success); }
.fit-warning { background-color: var(--ui-warning); }
.fit-overflow { background-color: var(--ui-danger); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 13px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s ease-in-out;
  user-select: none;
  line-height: 1.4;
}

.btn-nav {
  padding: 6px 11px;
  font-size: 12px;
}

.btn-primary {
  background-color: var(--ui-accent);
  color: var(--ui-on-accent);
  border-color: var(--ui-accent);
}

.btn-primary:hover {
  background-color: var(--ui-accent-hover);
  border-color: var(--ui-accent-hover);
}

.btn-secondary {
  background-color: var(--ui-control-bg);
  color: var(--ui-text-main);
  border-color: var(--ui-border);
}

.btn-secondary:hover {
  background-color: var(--ui-control-bg-hover);
  border-color: var(--ui-border-strong);
}

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

.btn-full {
  width: 100%;
  justify-content: center;
}

.btn-link {
  background: none;
  border: none;
  color: var(--ui-accent);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.btn-micro {
  background-color: var(--ui-surface-3);
  color: var(--ui-accent);
  border: 1px solid var(--ui-border-strong);
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
}

.btn-micro-text {
  background: none;
  border: none;
  font-size: 11px;
  color: var(--ui-text-muted);
  cursor: pointer;
  text-decoration: underline;
}

.btn-micro-text:hover {
  color: var(--ui-danger-text);
}

/* ==========================================================================
   Main Workspace Layout
   ========================================================================== */

.app-workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ==========================================================================
   Left Control Panel
   ========================================================================== */

.control-panel {
  width: var(--panel-width);
  min-width: 0 !important;
  background-color: var(--ui-surface);
  border-right: 1px solid var(--ui-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-x: hidden;
  overflow-y: hidden;
  z-index: 20;
  transition: width 0.22s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s;
}

.panel-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--ui-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-heading {
  font-size: 13px;
  font-weight: 700;
  color: var(--ui-text-main);
  line-height: 1;
}

/* Draggable Sidebar Resizer Divider */
.sidebar-resizer {
  width: 10px;
  position: relative;
  z-index: 50;
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: -5px;
  margin-right: -5px;
  user-select: none;
  touch-action: none;
}

.resizer-handle-line {
  width: 2px;
  height: 100%;
  background-color: transparent;
  transition: background-color 0.15s ease;
}

.sidebar-resizer:hover .resizer-handle-line,
.sidebar-resizer.is-dragging .resizer-handle-line {
  background-color: var(--ui-accent);
}

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

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

body.is-resizing .control-panel {
  transition: none !important;
}

/* Panel Collapse Toggle Button */
.panel-collapse-btn {
  position: absolute;
  top: 10px;
  left: 5px;
  width: 20px;
  height: 38px;
  display: flex !important;
  align-items: center;
  justify-content: center;
  background-color: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-left: none;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  color: var(--ui-text-muted);
  transition: color 0.12s, background-color 0.12s, transform 0.2s, box-shadow 0.15s ease;
  z-index: 55;
  box-shadow: 2px 1px 5px rgba(0, 0, 0, 0.14);
  pointer-events: auto;
}

.panel-collapse-btn:hover {
  color: var(--ui-text-main);
  background-color: var(--ui-surface-3);
  box-shadow: 3px 2px 8px rgba(0, 0, 0, 0.2);
}

.panel-collapse-btn.collapsed {
  left: 5px;
  border-left: 1px solid var(--ui-border);
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.22);
}

.panel-collapse-btn.collapsed svg {
  transform: rotate(180deg);
}

.control-panel.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  border-right: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}


/* Navigation Tabs */
.control-tabs {
  display: flex;
  background-color: var(--ui-surface-2);
  border-bottom: 1px solid var(--ui-border);
  padding: 0 2px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex-shrink: 0;
  min-width: 0;
}

.control-tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  flex: 1 0 auto;
  min-width: 0;
  padding: 9px 7px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ui-text-sub);
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.12s ease;
}

.tab-btn:hover {
  color: var(--ui-text-main);
}

.tab-btn.active {
  color: var(--ui-accent);
  border-bottom-color: var(--ui-accent);
  background-color: var(--ui-surface);
}

/* Interactive Tip Banner */
.interactive-tip-banner {
  background-color: var(--ui-surface-2);
  border-bottom: 1px solid var(--ui-border);
  padding: 7px 14px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--ui-text-sub);
  line-height: 1.35;
}

.interactive-tip-banner svg {
  color: var(--ui-accent);
  flex-shrink: 0;
}

/* Tab Content Container */
.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: none;
}

.tab-content.active {
  display: block;
}

/* Forms & Cards */
.form-group {
  margin-bottom: 10px;
}

.group-label,
.form-group label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ui-text-main);
  margin-bottom: 5px;
}

.label-with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}

.label-with-action label {
  margin-bottom: 0;
}

.form-row {
  display: flex;
  gap: 8px;
}

.col-5 { flex: 5; }
.col-6 { flex: 6; }
.col-7 { flex: 7; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--ui-text-main);
  background-color: var(--ui-input-bg);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  padding: 7px 9px;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--ui-accent);
  box-shadow: 0 0 0 3px var(--ui-input-focus);
}

.form-textarea {
  resize: vertical;
  line-height: 1.45;
}

.body-editor-textarea {
  min-height: 160px;
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.5;
}

.input-hint {
  font-size: 10.5px;
  color: var(--ui-text-muted);
}

.form-card {
  background-color: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;
}

.card-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.card-title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ui-text-main);
}

.card-sub-hint {
  font-size: 10.5px;
  color: var(--ui-text-muted);
  margin-top: 1px;
}

/* Switch Toggle */
.switch-toggle {
  position: relative;
  display: inline-block;
  width: 28px;
  height: 16px;
  cursor: pointer;
}

.switch-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--ui-border-strong);
  transition: 0.2s;
  border-radius: 16px;
}

.toggle-track:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}

.switch-toggle input:checked + .toggle-track {
  background-color: var(--ui-accent);
}

.switch-toggle input:checked + .toggle-track:before {
  transform: translateX(12px);
}

/* Layout Pill Grid */
.layout-pill-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.layout-card-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 7px 2px;
  border: 1px solid var(--ui-border);
  border-radius: 5px;
  background-color: var(--ui-control-bg);
  cursor: pointer;
  transition: all 0.12s ease;
}

.layout-card-btn:hover {
  background-color: var(--ui-control-bg-hover);
  border-color: var(--ui-border-strong);
}

.layout-card-btn.active {
  border-color: var(--ui-accent);
  background-color: var(--ui-accent-soft);
  color: var(--ui-accent);
  font-weight: 600;
}

.card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 16px;
  margin-bottom: 3px;
  color: inherit;
  line-height: 1;
}

.card-label {
  font-size: 10px;
}

/* Drag & Drop Logo Box */
.logo-dropzone {
  border: 1.5px dashed var(--ui-border-strong);
  border-radius: 6px;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--ui-control-bg);
  cursor: pointer;
  transition: all 0.15s ease;
}

.logo-dropzone:hover,
.logo-dropzone.dragover {
  border-color: var(--ui-accent);
  background-color: var(--ui-accent-soft);
}

.logo-thumb-box {
  width: 50px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
}

.logo-thumb-box img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.dropzone-text-group {
  display: flex;
  flex-direction: column;
}

.dropzone-primary-text {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ui-text-main);
}

.dropzone-sub-text {
  font-size: 10px;
  color: var(--ui-text-muted);
}

.logo-actions-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.logo-presets-group {
  padding-top: 6px;
  border-top: 1px solid var(--ui-border);
}

.logo-presets-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.logo-preset-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 3px;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  font-size: 10px;
  color: var(--ui-text-sub);
  cursor: pointer;
  transition: all 0.15s ease;
}

.logo-preset-pill:hover {
  background: var(--ui-surface-3);
  border-color: var(--ui-accent);
  color: var(--ui-accent);
}

.logo-preset-pill.active {
  background: var(--ui-accent-soft);
  border-color: var(--ui-accent);
  color: var(--ui-accent);
  font-weight: 600;
}

.logo-preset-pill .preset-icon,
.sig-pill-icon,
.stamp-pill-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  color: inherit;
}

.form-field-hint {
  font-size: 10.5px;
  color: var(--ui-text-muted);
  line-height: 1.35;
  margin-top: 4px;
  margin-bottom: 0;
}

/* Professional Enterprise Callout Box */
.alert-box-info {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  padding: 9px 11px;
  font-size: 11px;
  line-height: 1.45;
  color: var(--ui-text-muted);
}

.alert-box-info .alert-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--ui-accent);
}

.alert-box-info .alert-text {
  flex: 1;
}

.alert-box-info .alert-text strong {
  color: var(--ui-text-main);
  font-weight: 600;
}

/* Theme Swatch List */
.theme-swatch-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.theme-card-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--ui-border);
  border-radius: 5px;
  background-color: var(--ui-control-bg);
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  color: var(--ui-text-main);
  transition: all 0.12s ease;
}

.theme-card-btn:hover {
  background-color: var(--ui-control-bg-hover);
}

.theme-card-btn.active {
  border-color: var(--ui-accent);
  background-color: var(--ui-accent-soft);
  font-weight: 600;
}

.theme-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.custom-color-inline {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mini-color-input {
  width: 22px;
  height: 22px;
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  cursor: pointer;
  padding: 1px;
  background: none;
}

.mini-hex {
  font-size: 10.5px;
  font-family: monospace;
  background-color: var(--ui-surface-3);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Editor Spacing Toolbar */
.editor-spacing-toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 7px;
  flex-wrap: wrap;
}

.toolbar-hint-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ui-text-muted);
  margin-right: 2px;
}

.btn-micro-chip {
  padding: 3px 8px;
  font-size: 11px;
  background-color: var(--ui-surface-3);
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
  cursor: pointer;
  color: var(--ui-text-sub);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  transition: all 0.1s ease;
}

.btn-micro-chip:hover {
  background-color: var(--ui-surface-4);
  color: var(--ui-text-main);
  border-color: var(--ui-border-stronger);
}

/* Modern Segmented Control */
.segmented-control {
  display: flex;
  background-color: var(--ui-surface-3);
  padding: 2.5px;
  border-radius: 6px;
  border: 1px solid var(--ui-border);
  gap: 2px;
}

.segment-btn {
  flex: 1;
  padding: 5px 6px;
  font-size: 11px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
  color: var(--ui-text-muted);
  font-weight: 500;
  text-align: center;
  transition: all 0.12s ease;
  white-space: nowrap;
}

.segment-btn:hover {
  color: var(--ui-text-main);
}

.segment-btn.active {
  background-color: var(--ui-control-bg);
  color: var(--ui-text-main);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* Quick Chips Row */
.quick-chips-row {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.quick-chip {
  flex: 1;
  padding: 3px 4px;
  font-size: 10.5px;
  text-align: center;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--ui-text-sub);
  transition: all 0.1s ease;
}

.quick-chip:hover {
  background: var(--ui-surface-3);
  color: var(--ui-text-main);
}

.quick-chip.active {
  background: var(--ui-accent-soft);
  border-color: var(--ui-accent);
  color: var(--ui-accent-strong);
  font-weight: 600;
}

/* ==========================================================================
   Stamp Studio Controls in Sidebar
   ========================================================================== */

.stamp-style-pills {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 3px;
}

.stamp-pill-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px;
  border: 1px solid var(--ui-border);
  border-radius: 5px;
  background-color: var(--ui-control-bg);
  cursor: pointer;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ui-text-main);
  transition: all 0.12s ease;
}

.stamp-pill-btn:hover {
  background-color: var(--ui-control-bg-hover);
}

.stamp-pill-btn.active {
  border-color: var(--ui-accent);
  background-color: var(--ui-accent-soft);
  color: var(--ui-accent);
  font-weight: 600;
}

.stamp-color-swatches {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.stamp-swatch-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 7px;
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  background-color: var(--ui-control-bg);
  font-size: 10.5px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.stamp-swatch-btn:hover {
  background-color: var(--ui-control-bg-hover);
}

.stamp-swatch-btn.active {
  border-width: 1.5px;
  font-weight: 700;
  background-color: var(--ui-accent-soft);
}

.swatch-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* Signature Pill Grid */
.signature-pill-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
}

.sig-pill-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border: 1px solid var(--ui-border);
  border-radius: 5px;
  background-color: var(--ui-control-bg);
  cursor: pointer;
  font-size: 11.5px;
  color: var(--ui-text-main);
  text-align: left;
  transition: all 0.12s ease;
}

.sig-pill-btn:hover {
  background-color: var(--ui-control-bg-hover);
}

.sig-pill-btn.active {
  border-color: var(--ui-accent);
  background-color: var(--ui-accent-soft);
  color: var(--ui-accent);
  font-weight: 600;
}

.sig-pill-btn:last-child {
  grid-column: span 2;
}

/* Calligraphic Script Radio Options */
.script-font-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.script-radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  background-color: var(--ui-control-bg);
  cursor: pointer;
  font-size: 18px;
  color: var(--ui-text-main);
}

.script-radio-label.active {
  border-color: var(--ui-accent);
  background-color: var(--ui-accent-soft);
}

.script-radio-label input {
  accent-color: var(--ui-accent);
}

.font-caveat { font-family: 'Caveat', cursive; }
.font-dancing { font-family: 'Dancing Script', cursive; }
.font-sacramento { font-family: 'Sacramento', cursive; font-size: 22px; }

/* Signature Dropzone */
.signature-dropzone {
  border: 1.5px dashed var(--ui-border-strong);
  border-radius: 6px;
  padding: 12px;
  text-align: center;
  font-size: 11.5px;
  color: var(--ui-text-sub);
  background-color: var(--ui-control-bg);
  cursor: pointer;
}

.signature-dropzone:hover {
  border-color: var(--ui-accent);
  background-color: var(--ui-accent-soft);
}

/* Dynamic Detail Rows */
.detail-rows-container {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.detail-row-item {
  display: flex;
  gap: 5px;
  align-items: center;
}

.detail-row-item .row-label-input {
  flex: 4;
  font-size: 12px;
  padding: 4px 7px;
}

.detail-row-item .row-value-input {
  flex: 6;
  font-size: 12px;
  padding: 4px 7px;
}

.btn-remove-row {
  background: none;
  border: none;
  color: var(--ui-danger-text);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
}

/* Token Helper Chips */
.token-helper-chips {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.token-chip-label {
  font-size: 10px;
  color: var(--ui-text-muted);
  font-weight: 600;
}

.token-chip {
  background-color: var(--ui-surface-3);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10.5px;
  font-family: monospace;
  color: var(--ui-accent);
  cursor: pointer;
}

.token-chip:hover {
  background-color: var(--ui-surface-4);
}

/* Slider Controls */
.slider-row {
  margin-top: 8px;
}

.slider-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}

.slider-label-row label {
  margin-bottom: 0;
  font-size: 11px;
}

.slider-val {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text-sub);
}

.form-range {
  width: 100%;
  accent-color: var(--ui-accent);
  cursor: pointer;
}

/* Checkbox Inline */
.checkbox-group-inline {
  display: flex;
  gap: 8px;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--ui-text-sub);
  cursor: pointer;
}

.checkbox-inline input[type="checkbox"] {
  accent-color: var(--ui-accent);
}

/* Utilities */
.hidden { display: none !important; }
.visually-hidden {
  position: absolute !important;
  height: 1px; width: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap;
}
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-2 { margin-bottom: 8px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--ui-text-muted); }

/* Focus-Visible for Keyboard Navigation */
button:focus-visible,
select:focus-visible,
input[type="checkbox"]:focus-visible,
input[type="range"]:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.btn:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 1px;
}

/* ==========================================================================
   Right Live Preview Canvas Area
   ========================================================================== */

.preview-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--ui-bg);
  overflow: hidden;
  position: relative;
}

.preview-toolbar {
  min-height: 38px;
  background-color: var(--ui-surface);
  border-bottom: 1px solid var(--ui-border);
  padding: 4px 16px 4px 44px; /* Generous clearance past the 23px sidebar collapse button */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  z-index: 25;
  position: relative;
  overflow: visible;
}
.toolbar-nav-wrap {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  gap: 3px;
}

.toolbar-nav-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 26px;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  color: var(--ui-text-sub);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: all 0.12s ease;
  z-index: 2;
}

.toolbar-nav-btn:hover {
  background: var(--ui-surface-3);
  color: var(--ui-text-main);
  border-color: var(--ui-border-strong);
}

.toolbar-nav-btn.visible {
  display: inline-flex;
}

.doc-formatting-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  /* Scroll horizontally instead of clipping the trailing groups (Margins) when
     the sidebar is expanded and the toolbar runs out of room */
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scroll-padding-inline: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
  padding-bottom: 2px;
}

.doc-formatting-toolbar::-webkit-scrollbar {
  height: 5px;
  display: block;
}

.doc-formatting-toolbar::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 3px;
}

.doc-formatting-toolbar::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.35);
  border-radius: 4px;
}

.doc-formatting-toolbar::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.6);
}

:root[data-theme="dark"] .doc-formatting-toolbar {
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

:root[data-theme="dark"] .doc-formatting-toolbar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.22);
}

:root[data-theme="dark"] .doc-formatting-toolbar::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.45);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.toolbar-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text-sub);
  user-select: none;
  white-space: nowrap;
}

.toolbar-label svg {
  color: var(--ui-text-sub);
  flex-shrink: 0;
}

.toolbar-chips-group {
  display: inline-flex;
  align-items: center;
  background: var(--ui-surface-3);
  border: 1px solid var(--ui-border);
  border-radius: 5px;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}

.toolbar-chip-btn {
  background: transparent;
  border: none;
  font-size: 11px;
  font-weight: 500;
  color: var(--ui-text-sub);
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1.4;
  white-space: nowrap;
  transition: all 0.12s ease;
}

.toolbar-chip-btn:hover {
  color: var(--ui-text-main);
  background: var(--ui-control-bg);
}

.toolbar-chip-btn.active {
  background: var(--ui-control-bg);
  color: var(--ui-accent);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.toolbar-divider {
  width: 1px;
  height: 18px;
  background-color: var(--ui-border);
  flex-shrink: 0;
  margin: 0 2px;
}

.toolbar-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-accent);
  background: var(--ui-accent-soft);
  border: 1px solid var(--ui-accent-soft-border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.12s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.toolbar-action-btn:hover {
  background: var(--ui-accent-soft-hover);
  border-color: var(--ui-accent-soft-border-hover);
  color: var(--ui-accent-strong);
}

.toolbar-action-btn:active {
  transform: translateY(1px);
}

.toolbar-accent-btn {
  background: var(--ui-accent);
  color: var(--ui-on-accent) !important;
  border-color: var(--ui-accent);
}

.toolbar-accent-btn:hover {
  background: var(--ui-accent-hover);
  border-color: var(--ui-accent-hover);
  color: #ffffff !important;
}

/* Toolbar Insert Section Dropdown */
.toolbar-dropdown-wrapper {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.toolbar-dropdown-menu {
  display: none;
  /* Fixed, not absolute: the toolbar is a horizontal scroll container, which
     would otherwise clip this menu. Coordinates are set in JS on open. */
  position: fixed;
  top: -9999px;
  left: -9999px;
  right: auto;
  min-width: 240px;
  max-height: min(420px, calc(100vh - 80px));
  overflow-y: auto;
  overscroll-behavior: contain;
  background-color: var(--ui-surface-raised);
  border: 1px solid var(--ui-border-strong);
  border-radius: 8px;
  box-shadow: 0 14px 32px -4px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(0, 0, 0, 0.05);
  padding: 6px;
  z-index: 99999;
  text-align: left;
}

.toolbar-dropdown-menu::-webkit-scrollbar {
  width: 5px;
}

.toolbar-dropdown-menu::-webkit-scrollbar-thumb {
  background: var(--ui-border-strong);
  border-radius: 3px;
}

.toolbar-dropdown-menu::-webkit-scrollbar-track {
  background: transparent;
}

.toolbar-dropdown-menu.open {
  display: block;
}

.toolbar-dropdown-menu .dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.12s ease;
}

.toolbar-dropdown-menu .dropdown-item:hover {
  background-color: var(--ui-surface-3);
}

.toolbar-dropdown-menu .dropdown-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 5px;
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.toolbar-dropdown-menu .dropdown-item-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.toolbar-dropdown-menu .dropdown-item-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--ui-text-main);
  line-height: 1.3;
}

.toolbar-dropdown-menu .dropdown-item-desc {
  font-size: 10.5px;
  color: var(--ui-text-muted);
  line-height: 1.25;
}

/* --- Google Docs Responsive Alignment (Expanded vs Compact Dropdown) --- */
.tb-align-expanded {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.tb-align-collapsed {
  display: none;
}

.toolbar-align-btn {
  width: 38px !important;
  min-width: 38px !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0 4px !important;
}

.tb-align-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.menu-item-align {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: none;
  border-radius: 5px;
  color: var(--ui-text-main);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.12s ease;
}

.menu-item-align:hover {
  background-color: var(--ui-surface-3);
}

.menu-item-align.active {
  background-color: var(--ui-accent-soft);
  color: var(--ui-accent);
  font-weight: 600;
}

.menu-item-align svg {
  flex-shrink: 0;
}

/* --- Google Docs Overflow (More Tools) Menu --- */
.toolbar-overflow-wrapper {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.toolbar-overflow-btn {
  width: 28px !important;
  min-width: 28px !important;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tb-overflow-menu {
  width: 290px;
  max-height: min(440px, calc(100vh - 100px));
  overflow-y: auto;
  padding: 8px;
}

.overflow-menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  margin-top: 5px;
}

.overflow-action-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  color: var(--ui-text-main);
  text-align: left;
  transition: all 0.12s ease;
}

.overflow-action-item:hover {
  background: var(--ui-surface-3);
  border-color: var(--ui-border-strong);
}

.overflow-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
  font-weight: 700;
  font-size: 11px;
  flex-shrink: 0;
}

.overflow-menu-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
}

.overflow-pill-btn {
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 500;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  color: var(--ui-text-main);
  cursor: pointer;
  transition: all 0.12s ease;
}

.overflow-pill-btn:hover {
  background: var(--ui-surface-3);
  border-color: var(--ui-border-strong);
}

.overflow-pill-btn.active {
  background: var(--ui-accent-soft);
  border-color: var(--ui-accent);
  color: var(--ui-accent);
  font-weight: 600;
}

/* Responsive Rules for Small Screens */
@media (max-width: 1240px) {
  .tb-align-expanded {
    display: none;
  }
  .tb-align-collapsed {
    display: inline-flex;
  }
}

@media (max-width: 992px) {
  .toolbar-font-family-btn {
    width: 96px !important;
    min-width: 96px !important;
  }
  .zoom-controls #zoomFitBtn,
  .zoom-controls #zoom100Btn {
    display: none;
  }
}

@media (max-width: 768px) {
  .preview-toolbar {
    padding: 4px 10px 4px 38px;
  }
  .toolbar-font-family-btn {
    width: 84px !important;
    min-width: 84px !important;
  }
  .toolbar-font-size-input {
    width: 24px;
  }
}

/* Page Manager & Strip Custom Buttons */
.btn-page-action.btn-page-blank {
  background: var(--ui-surface-3);
  border-color: var(--ui-border-strong);
  color: var(--ui-text-main);
}

.btn-page-action.btn-page-blank:hover {
  background: var(--ui-surface-4);
  border-color: var(--ui-border-stronger);
}

.strip-btn.btn-make-blank {
  color: var(--ui-accent);
  background: var(--ui-accent-soft);
  border-color: var(--ui-accent-soft-border);
}

.strip-btn.btn-make-blank:hover {
  background: var(--ui-accent-soft-hover);
  border-color: var(--ui-accent-soft-border-hover);
}

.strip-btn.btn-add-blank-after {
  color: var(--ui-text-main);
  background: var(--ui-surface-2);
}

.strip-btn.btn-add-blank-after:hover {
  background: var(--ui-surface-3);
}

/* --- Google Docs-Grade Formatting Ribbon Controls --- */
.toolbar-cluster {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.rich-text-controls {
  display: contents;
}

.toolbar-tool-btn {
  background: transparent;
  border: 1px solid transparent;
  width: 28px;
  min-width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  cursor: pointer;
  color: var(--ui-text-sub);
  font-size: 12px;
  padding: 0;
  transition: all 0.12s ease;
  user-select: none;
  flex-shrink: 0;
  box-sizing: border-box;
}

.toolbar-tool-btn:hover {
  background: var(--ui-surface-3);
  color: var(--ui-text-main);
}

.toolbar-tool-btn.active {
  background: rgba(59, 130, 246, 0.16) !important;
  color: #2563eb !important;
  border-color: rgba(59, 130, 246, 0.28) !important;
}

.toolbar-tool-btn:disabled {
  opacity: 0.32;
  cursor: not-allowed;
  pointer-events: none;
}

.tool-sub-divider {
  width: 1px;
  height: 16px;
  background: var(--ui-border);
  margin: 0 3px;
  flex-shrink: 0;
}

.highlight-btn .hl-badge {
  background: #fef08a;
  color: #854d0e;
  font-weight: 700;
  font-size: 9px;
  padding: 1px 3px;
  border-radius: 2px;
}

.toolbar-tool-btn:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 1px;
}

/* --- Google Docs-Grade Typography & Word Formatting Controls --- */
.toolbar-font-family-wrapper {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.toolbar-font-family-btn {
  width: 124px !important;
  min-width: 124px !important;
  max-width: 130px !important;
  height: 28px !important;
  padding: 0 8px !important;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  color: var(--ui-text-main);
  cursor: pointer;
  transition: all 0.12s ease;
  user-select: none;
}

.toolbar-font-family-btn:hover {
  background: var(--ui-surface-3);
  border-color: var(--ui-border-strong);
}

.font-family-name-text {
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  flex: 1;
}

.font-caret {
  color: var(--ui-text-muted);
  flex-shrink: 0;
}

.toolbar-font-menu {
  display: none;
  position: fixed;
  top: -9999px;
  left: -9999px;
  width: 220px;
  max-height: 280px;
  overflow-y: auto;
  background-color: var(--ui-surface-raised);
  border: 1px solid var(--ui-border-strong);
  border-radius: 8px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 0, 0, 0.08);
  padding: 5px;
  z-index: 99999;
}

.toolbar-font-menu.open {
  display: block;
}

.font-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 10px;
  background: transparent;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  color: var(--ui-text-main);
  text-align: left;
  transition: background-color 0.1s ease;
}

.font-menu-item:hover {
  background-color: var(--ui-surface-3);
}

.font-menu-item.active {
  background-color: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
  font-weight: 700;
}

.font-item-name {
  font-size: 11.5px;
}

.font-item-preview {
  font-size: 10px;
  color: var(--ui-text-muted);
  opacity: 0.8;
}

/* --- Font Size Stepper & Typable Box (Exact Google Docs Layout: [ - ] [ 11 ▾ ] [ + ]) --- */
.toolbar-font-size-group {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  background: transparent;
  border: none;
  padding: 0;
  flex-shrink: 0;
}

.font-size-step-btn {
  width: 24px !important;
  height: 28px !important;
  padding: 0 !important;
  color: var(--ui-text-sub);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.12s ease;
  flex-shrink: 0;
}

.font-size-step-btn:hover {
  background: var(--ui-surface-3);
  color: var(--ui-text-main);
}

.font-size-combo-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 28px;
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  background: var(--ui-surface);
  box-sizing: border-box;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
}

.font-size-combo-wrapper:focus-within {
  border-color: #3b82f6;
  box-shadow: 0 0 0 1.5px rgba(59, 130, 246, 0.35);
}

.toolbar-font-size-input {
  width: 32px !important;
  min-width: 32px !important;
  max-width: 34px !important;
  height: 26px !important;
  padding: 0 !important;
  margin: 0 !important;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  color: var(--ui-text-main);
  background: transparent;
  border: none;
  box-sizing: border-box;
  outline: none;
  appearance: textfield;
  -moz-appearance: textfield;
}

.toolbar-font-size-input::-webkit-inner-spin-button,
.toolbar-font-size-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.font-size-caret-btn {
  width: 14px;
  height: 26px;
  background: transparent;
  border: none;
  border-left: 1px solid var(--ui-border);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ui-text-muted);
  cursor: pointer;
  transition: background-color 0.1s ease;
}

.font-size-caret-btn:hover {
  background: var(--ui-surface-3);
  color: var(--ui-text-main);
}

.font-size-menu {
  display: none;
  position: fixed;
  top: -9999px;
  left: -9999px;
  min-width: 72px;
  max-height: 220px;
  overflow-y: auto;
  background-color: var(--ui-surface-raised);
  border: 1px solid var(--ui-border-strong);
  border-radius: 6px;
  box-shadow: 0 10px 24px -4px rgba(0, 0, 0, 0.3);
  padding: 4px;
  z-index: 99999;
}

.font-size-menu.open {
  display: block;
}

.font-size-option {
  display: block;
  width: 100%;
  padding: 4px 6px;
  font-size: 11px;
  font-weight: 500;
  text-align: center;
  color: var(--ui-text-main);
  background: none;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.1s ease;
}

.font-size-option:hover {
  background-color: var(--ui-surface-3);
}

.font-size-option.active {
  background-color: #3b82f6;
  color: #ffffff;
  font-weight: 700;
}

/* --- Spacing, Margins & Insert Section Dropdowns --- */
.toolbar-spacing-btn,
.toolbar-margins-btn,
.toolbar-insert-btn {
  width: auto !important;
  min-width: unset !important;
  height: 28px !important;
  padding: 0 7px !important;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  display: inline-flex !important;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ui-text-sub);
  cursor: pointer;
  user-select: none;
  transition: all 0.12s ease;
  flex-shrink: 0;
  white-space: nowrap;
}

.toolbar-spacing-btn:hover,
.toolbar-margins-btn:hover,
.toolbar-insert-btn:hover {
  background: var(--ui-surface-3);
  color: var(--ui-text-main);
  border-color: var(--ui-border);
}

.toolbar-spacing-btn[aria-expanded="true"],
.toolbar-margins-btn[aria-expanded="true"],
.toolbar-insert-btn[aria-expanded="true"] {
  background: var(--ui-surface-3) !important;
  color: var(--ui-text-main) !important;
  border-color: var(--ui-border-strong) !important;
}

.tb-spacing-indicator,
.tb-margins-indicator,
.tb-insert-label {
  font-weight: 500;
  font-size: 11.5px;
  line-height: 1;
  white-space: nowrap;
}

.tb-caret,
.font-caret,
.font-size-caret,
.color-caret {
  width: 10px;
  height: 10px;
  color: var(--ui-text-muted);
  flex-shrink: 0;
  margin-left: 2px;
  display: inline-block;
  vertical-align: middle;
  transition: transform 0.15s ease, color 0.15s ease;
}

.toolbar-tool-btn:hover .tb-caret,
.toolbar-tool-btn:hover .font-caret,
.toolbar-tool-btn:hover .color-caret,
.font-size-combo-wrapper:hover .font-size-caret,
.font-size-caret-btn:hover .font-size-caret {
  color: var(--ui-text-main);
}

.toolbar-tool-btn[aria-expanded="true"] .tb-caret,
.toolbar-tool-btn[aria-expanded="true"] .font-caret,
.toolbar-tool-btn[aria-expanded="true"] .color-caret,
.font-size-combo-wrapper.open .font-size-caret {
  transform: rotate(180deg);
  color: var(--ui-text-main);
}

.toolbar-compact-menu {
  display: none;
  position: fixed;
  top: -9999px;
  left: -9999px;
  min-width: 165px;
  background-color: var(--ui-surface-raised);
  border: 1px solid var(--ui-border-strong);
  border-radius: 8px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 0, 0, 0.08);
  padding: 4px;
  z-index: 99999;
}

.toolbar-compact-menu.open {
  display: block;
}

.menu-section-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ui-text-muted);
  padding: 4px 8px 2px 8px;
}

.menu-item-spacing,
.menu-item-gap,
.menu-item-margin {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 8px;
  font-size: 11.5px;
  color: var(--ui-text-main);
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.1s ease;
}

.menu-item-spacing:hover,
.menu-item-gap:hover,
.menu-item-margin:hover {
  background-color: var(--ui-surface-3);
}

.menu-item-spacing.active,
.menu-item-gap.active,
.menu-item-margin.active {
  background-color: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
  font-weight: 700;
}

.menu-divider {
  height: 1px;
  background: var(--ui-border);
  margin: 3px 0;
}

/* Text Color & Highlight Dropdowns */
.toolbar-color-dropdown-wrapper {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.text-color-btn,
.highlight-btn {
  width: 32px !important;
  min-width: 32px !important;
  height: 28px !important;
  padding: 0 3px !important;
  gap: 2px !important;
}

.text-color-icon-wrap,
.hl-marker-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.text-color-letter {
  font-size: 13px;
  font-weight: 700;
  font-family: 'Times New Roman', serif;
  line-height: 1;
}

.text-color-bar,
.hl-color-bar {
  width: 14px;
  height: 3px;
  border-radius: 1px;
  margin-top: 1px;
  transition: background-color 0.15s ease;
}

.color-caret {
  color: var(--ui-text-muted);
  flex-shrink: 0;
}

/* Palette Dropdown Card */
.toolbar-palette-dropdown {
  display: none;
  position: fixed;
  top: -9999px;
  left: -9999px;
  width: 210px;
  background-color: var(--ui-surface-raised);
  border: 1px solid var(--ui-border-strong);
  border-radius: 8px;
  box-shadow: 0 14px 28px -4px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(0, 0, 0, 0.05);
  padding: 8px;
  z-index: 99999;
}

.toolbar-palette-dropdown.open {
  display: block;
}

.palette-header {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.palette-reset-btn,
.palette-brand-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ui-text-main);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.1s ease;
}

.palette-reset-btn:hover,
.palette-brand-btn:hover {
  background-color: var(--ui-surface-3);
}

.palette-swatch-circle {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--ui-border);
  flex-shrink: 0;
}

.transparent-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--ui-text-muted);
  border-style: dashed;
}

.palette-divider {
  height: 1px;
  background-color: var(--ui-border);
  margin: 6px 0;
}

.palette-section-title {
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ui-text-muted);
  margin-bottom: 5px;
  padding-left: 2px;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.hl-palette-grid {
  grid-template-columns: repeat(4, 1fr);
}

.palette-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.palette-swatch:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  z-index: 2;
}

.palette-custom-row {
  margin-top: 2px;
}

.palette-custom-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  font-size: 11px;
  color: var(--ui-text-main);
  cursor: pointer;
  border-radius: 4px;
  position: relative;
  transition: background-color 0.1s ease;
}

.palette-custom-label:hover {
  background-color: var(--ui-surface-3);
}

.palette-native-picker {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.palette-custom-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--ui-border);
  flex-shrink: 0;
  background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
}

/* Floating Selection Quick-Format Bubble Menu */
.floating-format-bubble {
  position: fixed !important;
  display: none;
  align-items: center;
  gap: 3px;
  background-color: var(--ui-surface-raised, #1e293b);
  border: 1px solid var(--ui-border-strong, #334155);
  border-radius: 8px;
  padding: 3px 5px;
  box-shadow: 0 12px 28px -4px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.08);
  z-index: 1200;
  pointer-events: auto;
  user-select: none;
  margin: 0 !important;
}

.floating-format-bubble.placement-above {
  transform: translate(-50%, -100%);
  animation: bubblePopInAbove 0.14s cubic-bezier(0.16, 1, 0.3, 1);
}

.floating-format-bubble.placement-below {
  transform: translate(-50%, 0);
  animation: bubblePopInBelow 0.14s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes bubblePopInAbove {
  from {
    opacity: 0;
    transform: translate(-50%, -90%) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -100%);
  }
}

@keyframes bubblePopInBelow {
  from {
    opacity: 0;
    transform: translate(-50%, 6px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.floating-format-bubble.visible {
  display: flex;
}

.bubble-btn {
  background: transparent;
  border: none;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ui-text-sub);
  font-size: 11px;
  transition: all 0.1s ease;
}

.bubble-btn:hover {
  background: var(--ui-surface-3);
  color: var(--ui-text-main);
}

.bubble-btn.active {
  background: var(--ui-accent);
  color: var(--ui-on-accent);
}

.bubble-step-btn {
  font-size: 14px;
  font-weight: 700;
  width: 20px;
}

.bubble-size-display {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text-main);
  padding: 0 2px;
  min-width: 16px;
  text-align: center;
}

.bubble-divider {
  width: 1px;
  height: 14px;
  background: var(--ui-border);
  margin: 0 2px;
}

.bubble-color-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.bubble-color-letter {
  font-size: 11px;
  font-weight: 700;
  font-family: serif;
}

.bubble-color-bar {
  width: 12px;
  height: 2px;
  border-radius: 1px;
  margin-top: 1px;
}

.bubble-hl-marker {
  font-size: 8.5px;
  font-weight: 800;
  background: #fef08a;
  color: #854d0e;
  padding: 1px 2px;
  border-radius: 2px;
}

/* Sidebar Callout */
.universal-toolbar-callout {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px 10px;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  margin-bottom: 10px;
}

.universal-toolbar-callout .callout-icon {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.universal-toolbar-callout .callout-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.universal-toolbar-callout .callout-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text-main);
}

.universal-toolbar-callout .callout-desc {
  font-size: 10.5px;
  color: var(--ui-text-sub);
  line-height: 1.35;
}

/* --- Custom Edge Margins Drawer --- */
.custom-margins-drawer {
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  padding: 8px 10px;
}

.custom-margins-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.margin-input-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.margin-input-col label {
  font-size: 10px;
  font-weight: 600;
  color: var(--ui-text-sub);
  text-transform: uppercase;
}

.margin-input-unit {
  display: flex;
  align-items: center;
  background: var(--ui-input-bg);
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
  padding: 2px 4px;
}

.margin-input-unit input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--ui-text-main);
  background: transparent;
  padding: 0;
}

.margin-input-unit span {
  font-size: 10px;
  color: var(--ui-text-muted);
  font-weight: 500;
}

.switch-toggle-inline {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.toggle-track-micro {
  width: 24px;
  height: 14px;
  background-color: var(--ui-border-strong);
  border-radius: 8px;
  position: relative;
  transition: background-color 0.2s ease;
}

.toggle-track-micro::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  background-color: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.switch-toggle-inline input:checked + .toggle-track-micro {
  background-color: var(--ui-accent);
}

.switch-toggle-inline input:checked + .toggle-track-micro::after {
  transform: translateX(10px);
}

/* --- Document Multi-Page Manager Bar --- */
.doc-page-manager-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  background: var(--ui-surface);
  border-bottom: 1px solid var(--ui-border);
  flex-shrink: 0;
  z-index: 9;
}

.doc-page-manager-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-badge-counter {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--ui-surface-3);
  border: 1px solid var(--ui-border);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text-main);
}

.page-manager-note {
  font-size: 11px;
  color: var(--ui-text-muted);
}

.btn-page-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--ui-accent-soft);
  border: 1px solid var(--ui-accent-soft-border);
  border-radius: 5px;
  color: var(--ui-accent);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-page-action:hover {
  background: var(--ui-accent-soft-hover);
  border-color: var(--ui-accent-soft-border-hover);
}

/* --- Page Sheet Container & Attached Strip --- */
/* --- Page Sheet Container & Attached Floating Strip (Word-Grade Visual Document Model) --- */
.page-sheet-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 auto;
  margin-bottom: 0 !important;
  flex-shrink: 0;
  width: 794px;
  max-width: 100%;
  position: relative;
}

.page-sheet-strip {
  width: 100%;
  max-width: 794px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  background: var(--ui-control-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--ui-border-strong);
  border-radius: 6px;
  font-size: 11px;
  user-select: none;
  margin: 0 0 10px 0 !important;
  position: relative;
  z-index: 10;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  gap: 8px;
  flex-wrap: nowrap !important;
  white-space: nowrap !important;
  height: 34px !important;
  min-height: 34px !important;
  max-height: 34px !important;
  overflow: visible !important;
  transition: all 0.15s ease;
}

.page-sheet-strip:hover {
  background: var(--ui-control-bg-hover);
  border-color: var(--ui-border-stronger);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
}

.strip-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap !important;
  white-space: nowrap !important;
  flex-shrink: 0;
}

.strip-page-pill {
  font-weight: 700;
  color: var(--ui-accent);
  background: var(--ui-accent-soft);
  border: 1px solid var(--ui-accent-soft-border);
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.3px;
  display: inline-flex;
  align-items: center;
  font-size: 10.5px;
}

.strip-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-weight: 500;
  color: var(--ui-text-sub);
  font-size: 11px;
}

.strip-toggle-label:hover {
  color: var(--ui-text-main);
}

.strip-toggle-label input {
  cursor: pointer;
  accent-color: var(--ui-accent);
}

.strip-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap !important;
  white-space: nowrap !important;
  flex-shrink: 0;
}

.strip-btn {
  background: var(--ui-control-bg);
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ui-text-sub);
  cursor: pointer;
  transition: all 0.12s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  box-sizing: border-box;
}

.strip-btn.strip-icon-btn {
  padding: 3px 6px;
  min-width: 26px;
  justify-content: center;
}

.strip-btn.strip-icon-btn svg {
  flex-shrink: 0;
}

.strip-btn:hover {
  background: var(--ui-control-bg-hover);
  color: var(--ui-text-main);
  border-color: var(--ui-border-stronger);
}

.strip-btn.btn-delete-sheet:hover {
  background: var(--ui-danger-soft);
  border-color: var(--ui-danger-border-strong);
  color: var(--ui-danger);
}

/* Page Control Strip Section Menu Dropdown */
.strip-dropdown-wrapper {
  position: relative;
  display: inline-flex;
}

.strip-section-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 175px;
  background-color: var(--ui-surface-raised);
  border: 1px solid var(--ui-border-strong);
  border-radius: 6px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
  padding: 4px;
  z-index: 100;
  flex-direction: column;
  gap: 2px;
}

.strip-section-menu.open {
  display: flex;
}

.strip-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 8px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--ui-text-main);
  font-size: 11px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s ease;
}

.strip-menu-item:hover {
  background-color: var(--ui-surface-3);
  color: var(--ui-accent);
}

.strip-menu-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  background-color: var(--ui-surface-2);
  color: var(--ui-text-sub);
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

.strip-menu-item:hover .strip-menu-icon {
  background-color: var(--ui-accent-soft);
  color: var(--ui-accent);
}

/* ==========================================================================
   Google Docs-Style Command Palette & Feature Search (Cmd+K)
   ========================================================================== */
.feature-search-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 14vh;
  z-index: 9999;
}

.feature-search-backdrop.hidden {
  display: none !important;
}

.feature-search-dialog {
  width: 100%;
  max-width: 560px;
  background-color: var(--ui-surface-raised);
  border: 1px solid var(--ui-border-stronger);
  border-radius: 10px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.25), 0 4px 12px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: searchPaletteAppear 0.12s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes searchPaletteAppear {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.feature-search-header {
  padding: 11px 14px;
  border-bottom: 1px solid var(--ui-border);
  background-color: var(--ui-surface);
}

.feature-search-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.feature-search-input-wrap .search-input-icon {
  color: var(--ui-text-muted);
  flex-shrink: 0;
}

.feature-search-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--ui-text-main);
  outline: none;
  padding: 2px 0;
}

.feature-search-input::placeholder {
  color: var(--ui-text-muted);
}

.feature-search-esc-hint {
  font-size: 10px;
  font-family: inherit;
  font-weight: 600;
  padding: 2px 6px;
  background: var(--ui-surface-3);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  color: var(--ui-text-muted);
  line-height: 1.2;
  cursor: pointer;
}

.feature-search-body {
  max-height: 380px;
  overflow-y: auto;
  padding: 6px;
}

.feature-search-category-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ui-text-muted);
  padding: 8px 10px 4px 10px;
}

.feature-search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s ease;
  user-select: none;
}

.feature-search-item:hover,
.feature-search-item.selected {
  background-color: var(--ui-accent-soft);
}

.feature-search-item-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.feature-search-item-icon {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--ui-text-sub);
  flex-shrink: 0;
}

.feature-search-item.selected .feature-search-item-icon,
.feature-search-item:hover .feature-search-item-icon {
  background: var(--ui-accent);
  color: #ffffff;
  border-color: var(--ui-accent);
}

.feature-search-item-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.feature-search-item-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ui-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.feature-search-item.selected .feature-search-item-title {
  color: var(--ui-accent);
}

.feature-search-item-desc {
  font-size: 11px;
  color: var(--ui-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.feature-search-item-tag {
  font-size: 10px;
  font-weight: 600;
  color: var(--ui-text-muted);
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: 3px;
  padding: 1px 6px;
  flex-shrink: 0;
}

.feature-search-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--ui-text-muted);
  font-size: 12.5px;
}

.feature-search-footer {
  padding: 7px 14px;
  background-color: var(--ui-surface-2);
  border-top: 1px solid var(--ui-border);
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 11px;
  color: var(--ui-text-muted);
}

.search-hint-item kbd {
  font-family: inherit;
  font-weight: 600;
  padding: 1px 4px;
  background: var(--ui-surface-3);
  border: 1px solid var(--ui-border);
  border-radius: 3px;
  font-size: 10px;
  margin-right: 3px;
}

.page-sheet-container .a4-sheet {
  margin-top: 0 !important;
  border-radius: 3px !important;
}

/* --- Document Page Overflow Warning Bar & 1-Click Auto-Flow Action --- */
.page-overflow-warning-bar {
  width: 100%;
  max-width: 794px;
  box-sizing: border-box;
  margin-top: 10px;
  margin-bottom: 14px;
  z-index: 10;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.page-overflow-warning-bar.hidden {
  display: none !important;
}

.overflow-warning-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-left: 4px solid #d97706;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.08);
}

body.theme-dark .overflow-warning-inner {
  background: rgba(180, 83, 9, 0.16);
  border-color: rgba(245, 158, 11, 0.35);
  border-left-color: #f59e0b;
}

.overflow-warning-content {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.overflow-warning-icon {
  color: #d97706;
  flex-shrink: 0;
}

body.theme-dark .overflow-warning-icon {
  color: #f59e0b;
}

.overflow-warning-texts {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.overflow-warning-title {
  font-size: 12.5px;
  font-weight: 600;
  color: #92400e;
  letter-spacing: -0.01em;
}

body.theme-dark .overflow-warning-title {
  color: #fde68a;
}

.overflow-warning-sub {
  font-size: 11.5px;
  color: #b45309;
  line-height: 1.35;
}

body.theme-dark .overflow-warning-sub {
  color: #fcd34d;
}

.overflow-warning-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-overflow-autoflow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #d97706;
  color: #ffffff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(217, 119, 6, 0.25);
  transition: all 0.15s ease;
  user-select: none;
}

.btn-overflow-autoflow:hover {
  background: #b45309;
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(217, 119, 6, 0.3);
}

.btn-overflow-autoflow:active {
  transform: translateY(0);
}

.continuation-body-content {
  flex: 1;
  outline: none;
  font-size: inherit;
  line-height: inherit;
  min-height: 200px;
}

/* --- Document Inserted Sections (Render Cleanly On-Screen & In PDF/Print) --- */
.doc-section-heading {
  font-size: 12.5pt;
  font-weight: 700;
  color: var(--accent-color, #1e3a8a);
  margin: 18px 0 8px 0;
  padding-bottom: 4px;
  border-bottom: 1.5px solid var(--accent-color, #1e3a8a);
  letter-spacing: -0.01em;
}

/* =========================================================================
   Document Structured Section Blocks (Google Docs Level Hover & Removal)
   ========================================================================= */

.doc-section-block {
  position: relative;
  margin: 12px 0 16px 0;
  border-radius: 4px;
  transition: outline 0.15s ease, background-color 0.15s ease;
}

.doc-section-block:hover {
  outline: 1px dashed rgba(59, 130, 246, 0.4);
  outline-offset: 3px;
}

.doc-section-actions {
  position: absolute;
  top: -14px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
  z-index: 15;
  opacity: 0;
  transform: translateY(2px);
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  user-select: none;
}

.doc-section-block:hover > .doc-section-actions,
.doc-section-actions:focus-within {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.doc-section-tag {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  background: #0f172a;
  color: #f8fafc;
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.14);
}

.doc-section-delete-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  font-size: 10.5px;
  font-weight: 600;
  color: #dc2626;
  background: #ffffff;
  border: 1px solid #fecaca;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  transition: all 0.12s ease;
}

.doc-section-delete-btn:hover {
  background: #fef2f2;
  border-color: #f87171;
  color: #b91c1c;
}

.doc-section-delete-btn svg {
  stroke-width: 2.2;
}

.doc-section-move-up-btn,
.doc-section-move-down-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  color: #475569;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  transition: all 0.12s ease;
}

.doc-section-move-up-btn:hover,
.doc-section-move-down-btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
  color: #0f172a;
}

.doc-section-table-add-row-btn,
.doc-section-table-del-row-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 600;
  color: #2563eb;
  background: #ffffff;
  border: 1px solid #bfdbfe;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  transition: all 0.12s ease;
}

.doc-section-table-add-row-btn:hover {
  background: #eff6ff;
  border-color: #60a5fa;
  color: #1d4ed8;
}

.doc-section-table-del-row-btn {
  color: #d97706;
  border-color: #fde68a;
}

.doc-section-table-del-row-btn:hover {
  background: #fffbeb;
  border-color: #f59e0b;
  color: #b45309;
}

@media print {
  .doc-section-actions {
    display: none !important;
  }
  .doc-section-block {
    outline: none !important;
    box-shadow: none !important;
    border: none !important;
    margin: 12px 0 16px 0 !important;
  }
}

.doc-section-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0 16px 0;
  font-size: 10pt;
}

.doc-section-table th {
  padding: 8px 10px;
  font-weight: 700;
  background: #f1f5f9;
  border-bottom: 2px solid #cbd5e1;
  color: #334155;
}

.doc-section-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #e2e8f0;
  color: #1e293b;
}

.doc-section-details-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 12px 14px;
  margin: 14px 0 16px 0;
  font-size: 10.5pt;
}

.doc-section-callout {
  border-left: 4px solid var(--accent-color, #1e3a8a);
  background: #f8fafc;
  padding: 10px 14px;
  margin: 14px 0 16px 0;
  border-radius: 0 6px 6px 0;
  font-size: 10.5pt;
  color: #334155;
}

.doc-section-clause {
  margin: 14px 0;
  font-size: 10.5pt;
  line-height: 1.6;
}

.doc-section-signatures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin: 24px 0 16px 0;
  font-size: 10pt;
}

.doc-section-divider {
  height: 1px;
  background: #e2e8f0;
  margin: 18px 0;
  border: none;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.btn-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--ui-control-bg);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}

.btn-icon:hover {
  background-color: var(--ui-control-bg-hover);
}

.zoom-text {
  font-size: 11px;
  font-weight: 600;
  min-width: 36px;
  text-align: center;
  color: var(--ui-text-main);
}

.btn-toolbar {
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  background-color: var(--ui-control-bg);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  cursor: pointer;
}

.btn-toolbar:hover {
  background-color: var(--ui-control-bg-hover);
}

/* Paper Viewport & Multi-Page Document Stage (Word & Google Docs-Grade Vertical Flow) */
.paper-viewport {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  scroll-behavior: smooth;
  padding: 36px 32px 140px 32px;
  display: flex;
  flex-direction: column;
  /* flex-start + margin:0 auto on the child = centered when room exists,
     scrollable in all directions when zoomed past viewport width.
     align-items:center clips the left overflow and makes it unreachable. */
  align-items: flex-start;
  justify-content: flex-start;
  box-sizing: border-box;
  background-color: var(--ui-bg);
}

/* Custom Sleek Word-Grade Scrollbar for Canvas Viewport */
.paper-viewport::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.paper-viewport::-webkit-scrollbar-track {
  background: transparent;
}
.paper-viewport::-webkit-scrollbar-thumb {
  background: var(--ui-scroll-thumb);
  border-radius: 5px;
  border: 2px solid var(--ui-bg);
}
.paper-viewport::-webkit-scrollbar-thumb:hover {
  background: var(--ui-scroll-thumb-hover);
}

.document-canvas-wrapper {
  display: block;
  width: 794px;
  margin: 0 auto;
  align-self: flex-start;
  position: relative;
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  transition: width 0.12s ease-out, height 0.12s ease-out;
}

.document-pages-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
  width: 794px;
  transform-origin: top left;
  position: relative;
  box-sizing: border-box;
  transition: transform 0.12s ease-out;
}

/* ==========================================================================
   PIXEL-PERFECT A4 LETTER SHEET
   ISO 216 Standard: 210mm × 297mm
   Screen Rendering with Interactive WYSIWYG Editable Fields
   ========================================================================== */

.a4-sheet {
  --doc-line-height: 1.54;
  --doc-section-gap: 16px;
  --doc-para-gap: 10px;
  --doc-signature-gap: 36px;
  --doc-page-padding: 15mm 18mm 15mm 18mm;
  width: 794px;
  min-width: 794px;
  max-width: 794px;
  height: 1123px;
  min-height: 1123px;
  max-height: 1123px;
  flex-shrink: 0;
  background-color: #ffffff;
  border: 1px solid var(--ui-sheet-border);
  border-radius: 3px;
  box-shadow: var(--ui-sheet-shadow);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding-top: var(--doc-margin-top, 15mm);
  padding-right: var(--doc-margin-right, 18mm);
  padding-bottom: var(--doc-margin-bottom, 15mm);
  padding-left: var(--doc-margin-left, 18mm);
  color: var(--doc-text-color);
  font-family: var(--doc-font-family);
  font-size: var(--doc-font-size);
  line-height: var(--doc-line-height);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.page-sheet-container:focus-within .a4-sheet,
.page-sheet-container.active-page-sheet .a4-sheet {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08), 0 12px 32px rgba(30, 58, 138, 0.12);
  border-color: rgba(30, 58, 138, 0.25);
}

/* Paper Size Standards: ISO A4 vs US Letter */
.a4-sheet.size-letter {
  width: 816px !important;
  min-width: 816px !important;
  max-width: 816px !important;
  height: 1056px !important;
  min-height: 1056px !important;
  max-height: 1056px !important;
}

/* Margin Presets & Custom Margins */
.a4-sheet.margin-narrow {
  --doc-margin-top: 10mm;
  --doc-margin-right: 12mm;
  --doc-margin-bottom: 10mm;
  --doc-margin-left: 12mm;
}
.a4-sheet.margin-standard {
  --doc-margin-top: 15mm;
  --doc-margin-right: 18mm;
  --doc-margin-bottom: 15mm;
  --doc-margin-left: 18mm;
}
.a4-sheet.margin-wide {
  --doc-margin-top: 20mm;
  --doc-margin-right: 24mm;
  --doc-margin-bottom: 20mm;
  --doc-margin-left: 24mm;
}
.a4-sheet.margin-custom {
  /* Reads custom values set dynamically via style.setProperty */
}

/* Font Family Classes */
.a4-sheet.font-inter { font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; }
.a4-sheet.font-timesnewroman,
.a4-sheet.font-tinos,
.a4-sheet.font-garamond,
.a4-sheet.font-ebgaramond { font-family: 'Times New Roman', 'Tinos', 'EB Garamond', Georgia, serif; }
.a4-sheet.font-calibri,
.a4-sheet.font-carlito { font-family: 'Calibri', 'Carlito', 'Segoe UI', system-ui, sans-serif; }
.a4-sheet.font-arial,
.a4-sheet.font-arimo { font-family: 'Arial', 'Arimo', Helvetica, sans-serif; }
.a4-sheet.font-georgia { font-family: 'Georgia', 'Cambria', serif; }
.a4-sheet.font-merriweather { font-family: 'Merriweather', Georgia, serif; }
.a4-sheet.font-playfairdisplay { font-family: 'Playfair Display', Georgia, serif; }
.a4-sheet.font-jetbrainsmono { font-family: 'JetBrains Mono', monospace; }

/* Security Watermark in Center of Sheet - Stamped OVER all content, tables, and boxes */
.center-watermark-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-32deg);
  pointer-events: none !important;
  user-select: none !important;
  z-index: 45; /* Cleanly overlays all content, tables, cards, and details boxes */
  opacity: var(--watermark-opacity, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 90%;
  max-width: 700px;
  mix-blend-mode: multiply; /* Authentic security stamp overlay effect */
}

.watermark-text {
  font-size: 76px;
  font-weight: 900;
  letter-spacing: 12px;
  color: #000000;
  text-transform: uppercase;
  white-space: nowrap;
}

.watermark-logo-img {
  width: 260px;
  height: auto;
  opacity: 0.8;
}

/* ==========================================================================
   WYSIWYG Inline-Editable Fields on Paper
   ========================================================================== */

.editable-field {
  cursor: text;
  border-radius: 2px;
  outline: 1px dashed transparent;
  transition: outline-color 0.12s, background-color 0.12s;
  position: relative;
  z-index: 2;
  -webkit-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
  touch-action: manipulation;
}

.editable-field:hover {
  outline-color: rgba(30, 58, 138, 0.25);
  background-color: rgba(30, 58, 138, 0.02);
}

.editable-field:focus {
  outline: 1.5px solid var(--accent-color) !important;
  background-color: rgba(30, 58, 138, 0.04) !important;
}

/* Header Elements */
.letter-header {
  display: flex;
  margin-bottom: 4px;
  position: relative;
  z-index: 2;
}

.letter-header.layout-modern {
  justify-content: space-between;
  align-items: center;
}

.letter-header.layout-modern .header-brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-right-composite {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-secondary-logo-container {
  display: flex;
  align-items: center;
}

.secondary-logo-img {
  height: 36px;
  width: auto;
  max-width: 120px;
  object-fit: contain;
}

.letter-header.layout-modern .header-contact-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  gap: 1px;
}

.letter-header.layout-centered {
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
}

.letter-header.layout-centered .header-brand-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.letter-header.layout-centered .header-right-composite {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.letter-header.layout-centered .header-contact-block {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 2px;
}

.letter-header.layout-split {
  justify-content: space-between;
  align-items: flex-end;
}

.letter-header.layout-split .header-brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
}

.letter-header.layout-split .header-contact-block {
  text-align: right;
  font-size: 9px;
}

.letter-header.layout-minimal {
  justify-content: space-between;
  align-items: flex-end;
}

.letter-header.layout-minimal .header-logo-container {
  display: flex;
}

.letter-header.layout-preprinted {
  visibility: hidden;
  height: 36mm;
  margin-bottom: 0;
}

.header-logo-container {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.header-logo-img {
  height: 42px;
  width: auto;
  max-width: 170px;
  object-fit: contain;
  display: block;
}

.header-titles-group {
  display: flex;
  flex-direction: column;
}

.header-org-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--accent-color);
  line-height: 1.25;
}

.header-org-tagline {
  font-size: 10px;
  font-weight: 500;
  color: var(--doc-text-muted);
  letter-spacing: 0.3px;
  line-height: 1.3;
}

.header-contact-block {
  font-size: 10px;
  color: var(--doc-text-muted);
  line-height: 1.4;
}

.header-contact-item {
  white-space: nowrap;
}

/* Header Contact Placement Variations */
.letter-header.contact-placement-left {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}
.letter-header.contact-placement-left .header-right-composite {
  width: 100%;
  justify-content: flex-start;
}
.letter-header.contact-placement-left .header-contact-block {
  align-items: flex-start;
  text-align: left;
}

.letter-header.contact-placement-center {
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}
.letter-header.contact-placement-center .header-right-composite {
  justify-content: center;
}
.letter-header.contact-placement-center .header-contact-block {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.letter-header.contact-placement-none .header-contact-block {
  display: none !important;
}

/* Header Divider Line */
.header-divider-line {
  width: 100%;
  margin-top: 6px;
  margin-bottom: 12px;
  position: relative;
  z-index: 2;
}

.header-divider-line.style-solid { border-bottom: 1.5px solid var(--divider-color); margin-bottom: var(--doc-section-gap, 12px); }
.header-divider-line.style-accent { border-bottom: 2.5px solid var(--accent-color); margin-bottom: var(--doc-section-gap, 12px); }
.header-divider-line.style-double { border-bottom: 3px double var(--divider-color); margin-bottom: var(--doc-section-gap, 12px); }
.header-divider-line.style-dashed { border-bottom: 1px dashed var(--divider-color); margin-bottom: var(--doc-section-gap, 12px); }
.header-divider-line.style-none { border-bottom: none; margin-bottom: var(--doc-section-gap, 8px); }

/* Date & Reference Row */
.letter-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--doc-section-gap, 14px);
  font-size: var(--doc-font-size);
  position: relative;
  z-index: 2;
}

.letter-date {
  font-weight: 500;
  color: var(--doc-text-color);
}

.letter-reference {
  font-weight: 600;
  font-size: 11.5px;
  color: var(--doc-text-muted);
  letter-spacing: 0.2px;
}

/* Recipient Block ('To:') */
.recipient-block {
  margin-bottom: var(--doc-section-gap, 16px);
  line-height: 1.4;
  position: relative;
  z-index: 2;
}

.recipient-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--doc-text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 2px;
  text-transform: uppercase;
}

.recipient-name {
  font-weight: 700;
  color: var(--doc-text-color);
}

.recipient-title-comp {
  font-weight: 500;
  color: var(--doc-text-muted);
}

.recipient-address-lines {
  color: var(--doc-text-muted);
}

/* Subject Line */
.letter-subject-wrap {
  margin-top: 4px;
  margin-bottom: var(--doc-section-gap, 14px);
  position: relative;
  z-index: 2;
}

.letter-subject {
  font-size: 13.5px;
  color: var(--doc-text-color);
  line-height: 1.3;
}

.letter-subject.uppercase {
  text-transform: uppercase;
  letter-spacing: 0.2px;
}

.letter-subject.bold {
  font-weight: 700;
}

/* Salutation */
.letter-salutation {
  margin-bottom: var(--doc-section-gap, 14px);
  font-weight: 500;
  position: relative;
  z-index: 2;
}

/* Main Body Content */
.letter-body-content {
  margin-bottom: var(--doc-section-gap, 12px);
  position: relative;
  z-index: 2;
}

.letter-body-content p {
  margin-bottom: var(--doc-para-gap, 10px);
  text-align: justify;
  text-justify: inter-word;
  line-height: var(--doc-line-height, 1.54);
  font-size: var(--body-font-size, 11pt);
}

.letter-body-content p.body-spacer-line {
  min-height: 1.3em;
  height: 1.3em;
  margin: 0;
  display: block;
}

/* Bulleted & Numbered Lists */
.letter-body-content ul,
.letter-body-content ol,
.continuation-body-content ul,
.continuation-body-content ol {
  margin: 6px 0 12px 24px;
  padding: 0;
  line-height: var(--doc-line-height, 1.54);
  font-size: var(--body-font-size, 11pt);
}

.letter-body-content li,
.continuation-body-content li {
  margin-bottom: 4px;
}

/* Summary Highlights Box */
.details-table-block {
  margin: calc(var(--doc-section-gap, 14px) * 0.4) 0 var(--doc-section-gap, 14px) 0;
  background-color: #f9fafb;
  border-left: 3px solid var(--accent-color);
  padding: 7px 12px;
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
  z-index: 2;
}

.details-table-row {
  display: flex;
  font-size: 13px;
  line-height: 1.4;
}

.details-table-label {
  font-weight: 600;
  width: 160px;
  flex-shrink: 0;
  color: var(--doc-text-color);
}

.details-table-value {
  color: #111827;
}

/* Closing Courtesy */
.closing-courtesy {
  margin-bottom: var(--doc-section-gap, 14px);
  font-size: var(--doc-font-size);
  position: relative;
  z-index: 2;
}

/* Sign-off & Signatory - Natural Flow with Configurable Gap */
.letter-signoff-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: var(--doc-signature-gap, 36px);
  padding-bottom: 6px;
  position: relative;
  z-index: 2;
}

.letter-signoff-row.pin-to-bottom {
  margin-top: auto !important;
}

.letter-signoff-row.pin-to-bottom ~ .letter-footer {
  margin-top: 12px !important;
}

.letter-signoff-row.dual-active {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 24px;
  align-items: flex-end;
}

.counterpart-signatory-column {
  display: flex;
  flex-direction: column;
}

.counterpart-signatory-column.hidden {
  display: none !important;
}

.dual-signatory-fields {
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border-subtle);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

.dual-signatory-fields.hidden {
  display: none !important;
}

.dual-signatory-fields label {
  color: var(--ui-text-sub);
  font-size: 11px;
}

/* On-Canvas Section Spacing Widgets */
.section-spacer-widget {
  position: relative;
  height: 14px;
  margin-top: -7px;
  margin-bottom: -7px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 15;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: auto;
}

.section-spacer-widget:hover,
.section-spacer-widget.active {
  opacity: 1;
}

.section-spacer-widget::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  border-bottom: 1px dashed rgba(37, 99, 235, 0.4);
  pointer-events: none;
}

.btn-spacer-action {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #1e293b;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  transition: all 0.1s ease;
  position: relative;
  z-index: 2;
}

.btn-spacer-action:hover {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
  transform: scale(1.1);
}

.spacer-tag {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  color: #475569;
  background: #ffffff;
  padding: 1.5px 6px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  margin: 0 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  user-select: none;
  position: relative;
  z-index: 2;
}

/* Direct Canvas Drop Target Cues */
.canvas-drop-target {
  position: relative;
  transition: outline 0.15s ease, box-shadow 0.15s ease;
  outline: 1.5px dashed transparent;
  outline-offset: 3px;
  border-radius: 4px;
}

.canvas-drop-target:hover {
  outline: 1.5px dashed rgba(37, 99, 235, 0.45);
}

.canvas-drop-target.dragover {
  outline: 2px dashed #2563eb !important;
  background-color: rgba(37, 99, 235, 0.08) !important;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

.signatory-column {
  display: flex;
  flex-direction: column;
}

.complimentary-close {
  margin-bottom: 3px;
  font-weight: 500;
}

.signature-display-box {
  min-height: 42px;
  margin: 3px 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  cursor: pointer;
}

.signature-graphic {
  height: 42px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  display: block;
}

.signature-typed-script {
  font-size: 30px;
  color: #0f172a;
  line-height: 1.1;
  padding-left: 4px;
}

.signature-manual-line {
  width: 150px;
  height: 1.5px;
  background-color: #374151;
  margin-top: 2px;
  margin-bottom: 5px;
}

.signatory-meta {
  line-height: 1.25;
}

.signatory-name {
  font-weight: 700;
  font-size: 13.5px;
  color: #111827;
}

.signatory-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--doc-text-muted);
}

.signatory-department {
  font-size: 11px;
  color: var(--doc-text-muted);
}

/* ==========================================================================
   Complete Official Seal & Rubber Stamp Styles
   ========================================================================== */

.seal-column {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-right: 8px;
  position: relative;
}

.official-seal-graphic {
  width: 105px;
  height: 105px;
  color: var(--stamp-color);
  opacity: var(--stamp-opacity);
  transform: rotate(var(--stamp-rotation)) scale(var(--stamp-scale, 1));
  transform-origin: center center;
  transition: transform 0.1s ease, opacity 0.1s ease;
  mix-blend-mode: multiply;
}

.seal-svg {
  width: 100%;
  height: 100%;
}

.official-rectangular-stamp {
  width: 150px;
  height: 58px;
  color: var(--stamp-color);
  opacity: var(--stamp-opacity);
  transform: rotate(var(--stamp-rotation)) scale(var(--stamp-scale, 1));
  transform-origin: center center;
  transition: transform 0.1s ease, opacity 0.1s ease;
  mix-blend-mode: multiply;
}

.rect-stamp-svg {
  width: 100%;
  height: 100%;
}

.official-custom-stamp-img {
  max-width: 140px;
  max-height: 70px;
  opacity: var(--stamp-opacity);
  transform: rotate(var(--stamp-rotation)) scale(var(--stamp-scale, 1));
  transform-origin: center center;
  transition: transform 0.1s ease, opacity 0.1s ease;
  mix-blend-mode: multiply;
}

.official-custom-stamp-img img {
  max-width: 100%;
  max-height: 70px;
  object-fit: contain;
  display: block;
}

/* ==========================================================================
   UNIVERSAL CUSTOMIZABLE FOOTER STUDIO STYLING
   ========================================================================== */

.letter-footer {
  margin-top: auto !important;
  width: 100%;
  padding-top: 6px;
  position: relative;
  z-index: 2;
  transition: border 0.15s ease;
}

/* Footer Dividers */
.letter-footer.footer-divider-solid { border-top: 1px solid #d1d5db; }
.letter-footer.footer-divider-accent { border-top: 1.5px solid var(--accent-color, #1e3a8a); }
.letter-footer.footer-divider-double { border-top: 3px double #9ca3af; }
.letter-footer.footer-divider-dashed { border-top: 1px dashed #9ca3af; }
.letter-footer.footer-divider-none { border-top: none; padding-top: 2px; }

/* Digital Verification QR Code Badge */
.footer-qr-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background-color: #fafafa;
  margin-bottom: 6px;
  width: fit-content;
}

.footer-qr-img {
  width: 24px;
  height: 24px;
}

.footer-qr-text {
  display: flex;
  flex-direction: column;
}

.qr-verify-title {
  font-size: 8px;
  font-weight: 700;
  color: #111827;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.qr-verify-url {
  font-size: 7.5px;
  color: var(--doc-text-muted);
}

/* Footer Content Stage */
.footer-content-stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Footer Column Grid Layouts */
.footer-contact-grid {
  display: flex;
  justify-content: space-between;
  font-size: 8.5px;
  color: #4b5563;
  line-height: 1.35;
  width: 100%;
}

/* 3-Column Corporate (Default minimal) */
.letter-footer.style-minimal .footer-contact-grid {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

/* 2-Column Split (HQ & Reg vs Banking Settlement) */
.letter-footer.style-split .footer-contact-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 18px;
}

/* 4-Column Global Grid */
.letter-footer.style-grid4 .footer-contact-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

/* 1-Column Centered Editorial */
.letter-footer.style-centered .footer-contact-grid {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 10px;
}

.letter-footer.style-centered .footer-col {
  justify-content: center;
}

/* Footer Alignment Utilities */
.letter-footer.align-justify .footer-contact-grid { justify-content: space-between; text-align: left; }
.letter-footer.align-center .footer-contact-grid { justify-content: center; text-align: center; }
.letter-footer.align-left .footer-contact-grid { justify-content: flex-start; text-align: left; }
.letter-footer.align-right .footer-contact-grid { justify-content: flex-end; text-align: right; }

.letter-footer.align-center .footer-meta-row { justify-content: center; text-align: center; }
.letter-footer.align-left .footer-meta-row { justify-content: flex-start; text-align: left; }
.letter-footer.align-right .footer-meta-row { justify-content: flex-end; text-align: right; }
.letter-footer.align-justify .footer-meta-row { justify-content: space-between; }

.letter-footer.align-center .footer-custom-grid { justify-content: center; }
.letter-footer.align-left .footer-custom-grid { justify-content: flex-start; }
.letter-footer.align-right .footer-custom-grid { justify-content: flex-end; }

/* Columns & Labels */
.footer-col {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.footer-label {
  font-weight: 700;
  color: #1f2937;
  white-space: nowrap;
}

/* Dedicated Corporate Metadata Rows (Registration & Banking) */
.footer-meta-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 8px;
  color: #4b5563;
  line-height: 1.35;
  margin-top: 2px;
  padding-top: 2px;
  border-top: 1px dashed #e5e7eb;
}

/* Dynamic Custom Footer Items Row */
.footer-custom-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 2px;
  padding-top: 2px;
  border-top: 1px dotted #e5e7eb;
  font-size: 8px;
  color: #4b5563;
}

.footer-custom-item {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

/* Page Numbering Row */
.footer-page-num-row {
  display: flex;
  font-size: 8.5pt;
  color: var(--doc-text-muted, #64748b);
  font-weight: 500;
  letter-spacing: 0.2px;
  margin-top: 4px;
  margin-bottom: 2px;
  line-height: 1.4;
  width: 100%;
}

.footer-page-num-row.align-right { justify-content: flex-end; text-align: right; }
.footer-page-num-row.align-center { justify-content: center; text-align: center; }
.footer-page-num-row.align-left { justify-content: flex-start; text-align: left; }

@keyframes pageNumPulse {
  0% {
    outline: 2px solid rgba(59, 130, 246, 0.85);
    background: rgba(59, 130, 246, 0.12);
    border-radius: 4px;
  }
  50% {
    outline: 2px solid rgba(59, 130, 246, 0.45);
    background: rgba(59, 130, 246, 0.06);
    border-radius: 4px;
  }
  100% {
    outline: 2px solid transparent;
    background: transparent;
  }
}

.footer-page-num-row.page-num-highlight-pulse {
  animation: pageNumPulse 1.5s ease-out forwards;
}

/* Legal Disclaimer */
.footer-legal-notice {
  font-size: 7.5px;
  color: #9ca3af;
  text-align: center;
  line-height: 1.3;
  margin-top: 2px;
}

/* Bottom Banner Bar */
.footer-banner-bar {
  display: none;
  width: calc(100% + 36mm);
  margin-left: -18mm;
  margin-bottom: -15mm;
  margin-top: 6px;
  background-color: var(--accent-color);
  color: #ffffff;
  padding: 5px 0;
  text-align: center;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 1.5px;
}

.letter-footer.style-banner .footer-banner-bar { display: block; }
.letter-footer.style-banner { border-top: none; padding-top: 0; }
.letter-footer.style-none:not(.footer-only-page-num) { display: none !important; }
.letter-footer.footer-only-page-num {
  border-top: none !important;
  padding-top: 0 !important;
  margin-top: auto !important;
}
.letter-footer.footer-only-page-num .footer-content-stage,
.letter-footer.footer-only-page-num .footer-qr-badge,
.letter-footer.footer-only-page-num .footer-banner-bar {
  display: none !important;
}
.a4-sheet.layout-preprinted-active .letter-footer { visibility: hidden; }

/* Sidebar Custom Fields Card Styling */
.custom-fields-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.custom-field-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  padding: 5px 8px;
}

.custom-field-input-label {
  width: 32%;
  font-size: 11px;
  padding: 3px 6px;
  color: var(--ui-text-main);
  background-color: var(--ui-input-bg);
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
}

.custom-field-input-val {
  flex: 1;
  font-size: 11px;
  padding: 3px 6px;
  color: var(--ui-text-main);
  background-color: var(--ui-input-bg);
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
}

.btn-remove-custom-field {
  color: var(--ui-danger-text);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  font-size: 14px;
  line-height: 1;
  border-radius: 4px;
}

.btn-remove-custom-field:hover {
  background: var(--ui-danger-soft-strong);
}

/* ==========================================================================
   ANIMATED FIRST-TIME USER GUIDELINES (SPOTLIGHT ONBOARDING TOUR)
   ========================================================================== */

.onboarding-tour-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 150;
  pointer-events: none; /* Allows clicks inside the transparent cutout to pass straight through to tools! */
}

.tour-backdrop-svg {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 151;
}

#tourBackdropPath {
  pointer-events: auto; /* Dimmed background captures clicks; cutout hole has no fill so tools are clickable! */
  transition: d 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.tour-backdrop-mask {
  display: none; /* Replaced by dynamic SVG cutout with true transparent hole */
}

.tour-spotlight-ring {
  position: fixed;
  border: 2.5px solid var(--ui-accent);
  box-shadow: 0 0 16px rgba(37, 99, 235, 0.45), inset 0 0 12px rgba(37, 99, 235, 0.12);
  border-radius: 8px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  z-index: 155;
}

.tour-active-target {
  position: relative !important;
  z-index: 156 !important;
  pointer-events: auto !important;
}

.tour-card {
  position: fixed;
  background: var(--ui-surface-raised);
  border-radius: 12px;
  box-shadow: 0 25px 40px -10px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.05);
  padding: 20px 22px;
  width: 380px;
  max-width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  z-index: 160;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  animation: tourCardSlide 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-sizing: border-box;
  pointer-events: auto;
}

@keyframes tourCardSlide {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.tour-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.tour-step-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--ui-accent-strong);
  background-color: var(--ui-accent-soft);
  padding: 2px 8px;
  border-radius: 12px;
}

.tour-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--ui-text-muted);
  cursor: pointer;
}

.tour-card-content {
  margin-bottom: 18px;
}

.tour-icon-pulse {
  font-size: 28px;
  margin-bottom: 8px;
  display: inline-block;
  animation: pulseIcon 2s infinite ease-in-out;
}

@keyframes pulseIcon {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.tour-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--ui-text-main);
  margin-bottom: 6px;
  line-height: 1.25;
}

.tour-description {
  font-size: 13px;
  color: var(--ui-text-sub);
  line-height: 1.5;
}

.tour-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  border-top: 1px solid var(--ui-border);
}

.tour-dots-indicator {
  display: flex;
  gap: 5px;
}

.tour-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--ui-border-strong);
  transition: all 0.2s ease;
}

.tour-dot.active {
  width: 18px;
  border-radius: 4px;
  background-color: var(--ui-accent);
}

.tour-nav-actions {
  display: flex;
  gap: 8px;
}

/* ==========================================================================
   Modals & Drawers
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(17, 24, 39, 0.65);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-dialog {
  width: 100%;
  background-color: var(--ui-surface-raised);
  border-radius: 8px;
  box-shadow: 0 25px 35px -5px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow: hidden;
}

.modal-md { max-width: 580px; }
.modal-lg { max-width: 740px; }
.modal-xl { max-width: 860px; }
.modal-gallery { max-width: 860px; }

.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--ui-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--ui-text-main);
}

.modal-header-subtitle {
  font-size: 11.5px;
  color: var(--ui-text-muted);
  margin-top: 1px;
}

.btn-close {
  background: transparent;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--ui-text-muted);
  line-height: 1;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.15s ease;
  flex-shrink: 0;
  padding: 0;
}

.btn-close:hover {
  background-color: var(--ui-surface-3);
  color: var(--ui-text-main);
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--ui-border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ==========================================================================
   Custom Confirmation & Alert Modal
   ========================================================================== */
.confirm-modal-backdrop {
  z-index: 9999;
  background-color: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-confirm {
  max-width: 440px;
  background: var(--ui-surface-raised);
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 20px 35px -5px rgba(15, 23, 42, 0.22), 0 10px 15px -5px rgba(15, 23, 42, 0.08);
  padding: 24px;
  position: relative;
  overflow: visible;
  animation: confirmPopIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes confirmPopIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.confirm-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: transparent;
  border: none;
  font-size: 22px;
  color: var(--ui-text-muted);
  cursor: pointer;
  line-height: 1;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.confirm-close-btn:hover {
  background-color: var(--ui-surface-3);
  color: var(--ui-text-main);
}

.confirm-modal-inner {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.confirm-icon-wrap {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.confirm-icon-wrap.danger {
  background-color: var(--ui-danger-soft);
  color: var(--ui-danger);
  border: 1px solid var(--ui-danger-border);
}

.confirm-icon-wrap.warning {
  background-color: var(--ui-warning-soft);
  color: var(--ui-warning-strong);
  border: 1px solid var(--ui-warning-border);
}

.confirm-icon-wrap.info {
  background-color: var(--ui-accent-soft);
  color: var(--ui-accent);
  border: 1px solid var(--ui-accent-soft-border);
}

.confirm-content-wrap {
  flex: 1;
  min-width: 0;
}

.confirm-modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--ui-text-main);
  letter-spacing: -0.01em;
  margin: 0 0 6px 0;
  line-height: 1.35;
}

.confirm-modal-message {
  font-size: 13.5px;
  color: var(--ui-text-sub);
  line-height: 1.5;
  margin: 0;
}

.confirm-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--ui-border);
}

.btn-danger {
  background-color: var(--ui-danger);
  color: #ffffff;
  border-color: var(--ui-danger);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(220, 38, 38, 0.2);
}

.btn-danger:hover {
  background-color: var(--ui-danger-hover);
  border-color: var(--ui-danger-hover);
}

.btn-danger:active {
  background-color: var(--ui-danger-active);
  border-color: var(--ui-danger-active);
}

.btn-danger:focus-visible {
  outline: 2px solid rgba(220, 38, 38, 0.4);
  outline-offset: 2px;
}

@media (max-width: 600px) {
  .modal-confirm {
    width: calc(100% - 32px);
    margin: 16px;
    padding: 20px 16px;
  }
  .confirm-modal-footer button {
    flex: 1;
    text-align: center;
  }
}

/* ==========================================================================
   Visual Template Showcase Gallery Cards
   ========================================================================== */

.template-gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.gallery-card {
  border: 1.5px solid var(--ui-border);
  border-radius: 8px;
  background-color: var(--ui-control-bg);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
}

.gallery-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px -4px rgba(0, 0, 0, 0.1);
  border-color: var(--ui-border-strong);
}

.gallery-card.active {
  border-color: var(--ui-accent);
  box-shadow: 0 0 0 2px var(--ui-accent);
}

.gallery-card-preview {
  height: 140px;
  background-color: var(--ui-surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.mini-paper {
  width: 90px;
  height: 125px;
  background-color: #ffffff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
  border-radius: 2px;
  padding: 8px 7px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mini-header {
  display: flex;
  align-items: center;
  gap: 4px;
}

.mini-header.center {
  justify-content: center;
}

.mini-logo {
  width: 12px;
  height: 8px;
  background-color: var(--ui-accent);
  border-radius: 1px;
}

.mini-emblem {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid #831843;
}

.mini-divider {
  width: 100%;
  height: 1px;
  background-color: #cbd5e1;
}

.mini-divider.double {
  height: 2px;
  border-top: 1px solid #cbd5e1;
  border-bottom: 1px solid #cbd5e1;
  background: none;
}

.mini-line {
  height: 2px;
  background-color: #e2e8f0;
  border-radius: 1px;
}

.mini-bold-line {
  height: 3px;
  background-color: #94a3b8;
  border-radius: 1px;
}

.mini-details-box {
  background-color: #f8fafc;
  border-left: 1.5px solid var(--ui-accent);
  padding: 3px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mini-signoff {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.mini-sig {
  width: 22px;
  height: 8px;
  border-bottom: 1px solid #334155;
}

.mini-seal {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--ui-accent);
}

.w-25 { width: 25%; }
.w-30 { width: 30%; }
.w-35 { width: 35%; }
.w-40 { width: 40%; }
.w-50 { width: 50%; }
.w-60 { width: 60%; }
.w-65 { width: 65%; }
.w-70 { width: 70%; }
.w-75 { width: 75%; }
.w-80 { width: 80%; }
.w-85 { width: 85%; }
.w-90 { width: 90%; }

.gallery-card-info {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.gallery-card-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ui-text-main);
  margin-bottom: 3px;
}

.gallery-card-desc {
  font-size: 11px;
  color: var(--ui-text-muted);
  line-height: 1.35;
  margin-bottom: 10px;
  flex: 1;
}

/* ==========================================================================
   Spreadsheet Table Batch Generator
   ========================================================================== */

.batch-helper-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 7px 10px;
  background-color: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
}

.helper-tips {
  font-size: 11.5px;
  color: var(--ui-text-sub);
}

.tip-badge {
  font-weight: 700;
  color: var(--ui-accent);
}

.helper-tips code {
  font-family: monospace;
  background-color: var(--ui-surface-4);
  padding: 1px 4px;
  border-radius: 3px;
}

.helper-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.spreadsheet-container {
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  max-height: 240px;
  overflow-y: auto;
}

.spreadsheet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.spreadsheet-table th {
  background-color: var(--ui-surface-3);
  font-weight: 600;
  color: var(--ui-text-sub);
  padding: 6px 8px;
  border-bottom: 1px solid var(--ui-border);
  border-right: 1px solid var(--ui-border);
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 2;
}

.spreadsheet-table td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--ui-border);
  border-right: 1px solid var(--ui-border);
}

.spreadsheet-cell {
  width: 100%;
  border: none;
  outline: none;
  font-size: 11.5px;
  color: var(--ui-text-main);
  background: transparent;
  padding: 3px 4px;
}

.spreadsheet-cell:focus {
  background-color: var(--ui-accent-soft);
  border-radius: 2px;
}

.row-num {
  text-align: center;
  color: var(--ui-text-muted);
  font-size: 11px;
}

.btn-del-grid-row {
  background: none;
  border: none;
  color: var(--ui-danger-text);
  cursor: pointer;
  font-size: 14px;
}

.batch-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.batch-count-text {
  font-size: 12px;
  font-weight: 700;
  color: var(--ui-text-main);
}

/* Signature Drawing Canvas */
.signature-canvas-container {
  border: 1.5px dashed var(--ui-border-dark);
  border-radius: 6px;
  background-color: #f9fafb;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

#signaturePadCanvas {
  width: 100%;
  height: 190px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  max-width: 100%;
  cursor: crosshair;
  background: transparent;
  display: block;
}

.canvas-baseline {
  position: absolute;
  bottom: 45px;
  left: 30px;
  right: 30px;
  height: 1px;
  border-bottom: 1px dashed #cbd5e1;
  pointer-events: none;
}

.canvas-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.canvas-hint {
  font-size: 11px;
  color: var(--ui-text-muted);
}

.batch-print-container {
  display: none;
}

/* ==========================================================================
   WORD-STYLE CUSTOM MARGINS MODAL & LIVE PREVIEW
   ========================================================================== */
.modal-custom-margins {
  max-width: 540px;
}

.custom-margins-modal-body {
  padding: 20px;
}

.margins-modal-layout {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 24px;
  align-items: start;
}

.margins-inputs-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.margins-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ui-text-sub);
}

.margins-compass-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border-subtle);
  border-radius: 8px;
  padding: 14px;
}

.compass-margin-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.compass-margin-item label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text-sub);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.compass-middle-row {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.margin-stepper-wrap {
  display: inline-flex;
  align-items: center;
  background: var(--ui-surface-1);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  overflow: hidden;
  height: 32px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.margin-stepper-wrap:focus-within {
  border-color: var(--ui-accent);
  box-shadow: 0 0 0 2px var(--ui-accent-soft);
}

.stepper-btn {
  width: 26px;
  height: 100%;
  background: transparent;
  border: none;
  color: var(--ui-text-sub);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: background-color 0.1s ease, color 0.1s ease;
}

.stepper-btn:hover {
  background: var(--ui-surface-3);
  color: var(--ui-text-main);
}

.stepper-btn:active {
  background: var(--ui-border);
}

.margin-num-input {
  width: 40px;
  height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--ui-text-main);
  outline: none;
  padding: 0;
  -moz-appearance: textfield;
}

.margin-num-input::-webkit-outer-spin-button,
.margin-num-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.unit-tag {
  font-size: 10.5px;
  color: var(--ui-text-muted);
  padding-right: 4px;
  user-select: none;
}

.margins-preset-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.preset-pills-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text-muted);
}

.margin-preset-btn {
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 4px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  color: var(--ui-text-sub);
  cursor: pointer;
  transition: all 0.12s ease;
}

.margin-preset-btn:hover {
  border-color: var(--ui-accent);
  color: var(--ui-text-main);
  background: var(--ui-surface-3);
}

.margins-preview-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.word-sheet-mini {
  width: 120px;
  height: 170px;
  background: #ffffff;
  border: 1px solid var(--ui-sheet-border, #cbd5e1);
  border-radius: 3px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  position: relative;
  box-sizing: border-box;
  padding: 12px 14px;
  transition: padding 0.15s ease;
  display: flex;
  overflow: hidden;
}

.mini-margin-guide {
  width: 100%;
  height: 100%;
  border: 1.5px dashed var(--ui-accent, #3b82f6);
  border-radius: 2px;
  background-color: rgba(59, 130, 246, 0.04);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 6px 4px;
}

.mini-content-lines {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.mini-line {
  height: 3px;
  background: #94a3b8;
  border-radius: 1.5px;
  opacity: 0.6;
}

.mini-line.w-80 { width: 80%; }
.mini-line.w-100 { width: 100%; }
.mini-line.w-95 { width: 95%; }
.mini-line.w-90 { width: 90%; }
.mini-line.w-60 { width: 60%; }

.margins-preview-info {
  font-size: 10.5px;
  color: var(--ui-text-muted);
  text-align: center;
}

/* Page Number Presets Chips */
.page-num-presets-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
}

.preset-chip {
  padding: 3px 7px;
  border-radius: 4px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  color: var(--ui-text-sub);
  font-size: 11px;
  font-family: var(--ui-font-family);
  cursor: pointer;
  transition: all 0.12s ease;
  user-select: none;
}

.preset-chip:hover {
  border-color: var(--ui-accent);
  color: var(--ui-text-main);
  background: var(--ui-surface-3);
}

.preset-chip.active {
  background: var(--ui-accent-light, #eff6ff);
  border-color: var(--ui-accent, #2563eb);
  color: var(--ui-accent, #1d4ed8);
  font-weight: 600;
}

/* ==========================================================================
   CANVA-GRADE MOBILE RESPONSIVE SUITE
   Touch-Optimized Layout, Dynamic View Switching & Mobile Bottom Dock
   ========================================================================== */

/* Desktop defaults: Hide mobile controls */
.mobile-mode-switcher,
.mobile-bottom-dock,
.mobile-floating-preview-btn,
.mobile-canvas-hint {
  display: none;
}

/* Mobile & Small Tablet Stylesheet (<= 840px) */
@media screen and (max-width: 840px) {
  /* 1. App Header Optimization */
  .app-header {
    height: 48px;
    padding: 0 10px;
    gap: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    overflow: visible !important;
    position: relative;
    z-index: 120;
  }

  .header-brand {
    gap: 0;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    min-width: 0;
  }

  .header-logo-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
  }

  /* Only show logo on mobile - hide text brand title to prevent ANY clipping or cropping */
  .header-title {
    display: none !important;
  }

  /* Hide verbose desktop items and redundant page bar in mobile header */
  .header-separator,
  .history-controls,
  .header-center .btn-showcase,
  .quick-theme-pill,
  .autosave-status,
  .page-fit-gauge,
  .sidebar-resizer,
  .panel-collapse-btn,
  .header-actions #printBtn,
  .mobile-mode-switcher,
  .doc-page-manager-bar {
    display: none !important;
  }

  /* Header center on mobile */
  .header-center {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
  }

  /* Compact touch search button on mobile */
  .header-search-btn {
    padding: 6px 9px !important;
    height: 32px !important;
    border-radius: 8px !important;
    gap: 0 !important;
  }

  .header-search-btn .search-btn-text,
  .header-search-btn .search-kbd {
    display: none !important;
  }

  /* Header action buttons */
  .header-actions {
    gap: 6px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    position: relative;
    overflow: visible;
  }

  .header-actions .btn-nav {
    padding: 5px 9px;
    font-size: 11.5px;
  }

  /* More Dropdown on Mobile */
  #moreActionsDropdown {
    position: relative;
  }

  #moreActionsDropdown .dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 210px;
    background: var(--ui-surface-raised);
    border: 1px solid var(--ui-border-strong);
    border-radius: 12px;
    box-shadow: 0 16px 36px -4px rgba(15, 23, 42, 0.22), 0 4px 12px -2px rgba(15, 23, 42, 0.08);
    padding: 6px;
    z-index: 9999;
  }

  #moreActionsDropdown .dropdown-item {
    padding: 11px 14px;
    font-size: 13.5px;
    font-weight: 500;
    border-radius: 8px;
    gap: 10px;
  }

  #moreActionsDropdown .dropdown-item:active {
    background-color: var(--ui-surface-3);
  }

  /* 2. Workspace View Switching */
  .app-workspace {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* Default on mobile: SHEET / PREVIEW MODE */
  /* Default on mobile: SHEET / PREVIEW MODE */
  body:not(.mobile-view-editor) .control-panel,
  body:not(.mobile-view-editor) .control-panel.collapsed {
    display: none !important;
  }

  body:not(.mobile-view-editor) .preview-area {
    display: flex !important;
    width: 100% !important;
    flex: 1;
    height: 100%;
    overflow: hidden;
  }

  /* EDIT MODE on mobile: CUSTOMIZE */
  body.mobile-view-editor .control-panel,
  body.mobile-view-editor .control-panel.collapsed {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    flex: 1 1 auto !important;
    height: 100% !important;
    border-right: none !important;
    padding: 0 !important;
    padding-bottom: 74px !important; /* Space for mobile dock */
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    opacity: 1 !important;
    pointer-events: auto !important;
    visibility: visible !important;
    background-color: var(--ui-surface) !important;
  }

  body.mobile-view-editor .preview-area {
    display: none !important;
  }

  /* 3. Mobile Inspector Panel & Tabs */
  .control-panel .panel-header {
    padding: 10px 14px;
    background: var(--ui-surface);
    border-bottom: 1px solid var(--ui-border);
  }

  .control-tabs {
    position: sticky;
    top: 0;
    z-index: 25;
    padding: 6px 8px;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    background: var(--ui-surface-2);
    border-bottom: 1px solid var(--ui-border);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
  }

  .control-tabs::-webkit-scrollbar {
    display: none;
  }

  .tab-btn {
    padding: 8px 12px;
    font-size: 12px;
    border-radius: 6px;
    border-bottom: none;
    background: var(--ui-control-bg);
    border: 1px solid var(--ui-border);
    flex-shrink: 0;
  }

  .tab-btn.active {
    background: var(--ui-accent);
    color: var(--ui-on-accent);
    border-color: var(--ui-accent);
  }

  .tab-btn.active svg {
    color: var(--ui-on-accent);
  }

  .tab-content {
    padding: 12px 14px 80px 14px;
  }

  /* Floating "View Sheet" pill button visible exclusively in mobile Editor mode */
  body.mobile-view-editor .mobile-floating-preview-btn {
    display: inline-flex;
    position: fixed;
    bottom: 68px;
    right: 14px;
    align-items: center;
    gap: 6px;
    padding: 8px 15px;
    background: var(--ui-accent);
    color: var(--ui-on-accent);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 22px;
    font-size: 12px;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(30, 58, 138, 0.38);
    z-index: 95;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.15s ease;
  }

  body.mobile-view-editor .mobile-floating-preview-btn:active {
    transform: scale(0.95);
  }

  /* Form Elements Touch Target Optimization */
  input[type="text"],
  input[type="number"],
  input[type="color"],
  select,
  textarea {
    font-size: 16px !important; /* CRITICAL: Prevents iOS Safari automatic zoom-in! */
    min-height: 42px;
  }

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

  .btn {
    min-height: 42px;
    font-size: 13px;
  }

  .btn-sm {
    min-height: 36px;
    font-size: 12px;
  }

  .btn-micro,
  .btn-micro-chip {
    min-height: 30px;
    padding: 4px 8px;
  }

  /* Document Multi-Page Manager Bar on Mobile */
  .doc-page-manager-bar {
    padding: 6px 12px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .doc-page-manager-left {
    min-width: 0 !important;
  }

  .page-manager-note {
    display: none !important;
  }

  /* 4. Mobile Paper Viewport & Multi-Page Document Auto-Scaling */
  .paper-viewport {
    width: 100% !important;
    max-width: 100% !important;
    padding: 10px 6px calc(68px + env(safe-area-inset-bottom, 12px)) 6px !important;
    overflow-x: auto !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    box-sizing: border-box !important;
  }

  .document-canvas-wrapper {
    margin: 0 auto !important;
    display: block !important;
    position: relative !important;
    flex-shrink: 0 !important;
    /* overflow:hidden stops the 794px stage from expanding mobile scroll width.
       contain:paint removed — it broke native scroll inertia & stacking context.
       transition removed — stage scale is instant; animating wrapper size creates a
       visible clip flash where content appears clipped mid-transition. */
    overflow: hidden !important;
    transition: none !important;
    border-radius: 4px !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
  }

  .document-pages-stage {
    gap: 20px !important;
    margin: 0 !important;
    width: 794px !important;
    transform-origin: top left !important;
  }

  .page-sheet-container {
    width: 794px !important;
  }

  .page-sheet-strip {
    width: 794px !important;
  }

  .a4-sheet {
    width: 794px !important;
    min-width: 794px !important;
    max-width: 794px !important;
    height: 1123px !important;
    min-height: 1123px !important;
    max-height: 1123px !important;
    flex-shrink: 0 !important;
    margin: 0 auto !important;
    box-shadow: none !important;
  }

  /* Canvas Tap-to-Edit Visual Tactile Highlight */
  .canvas-tap-highlight {
    outline: 2.5px solid var(--ui-accent) !important;
    outline-offset: 3px !important;
    background: rgba(30, 58, 138, 0.06) !important;
    border-radius: 4px;
    transition: outline 0.15s ease, background 0.15s ease;
  }

  /* Mobile Quick Hint Banner on Canvas */
  .mobile-canvas-hint {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #ffffff;
    font-size: 11px;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 20px;
    margin: 0 auto 10px auto;
    width: fit-content;
    max-width: 90%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 20;
    flex-shrink: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
  }

  .mobile-canvas-hint.fade-out {
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
  }

  .mobile-canvas-hint .hint-close-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0 0 0 4px;
    margin-left: 2px;
  }

  /* Hide desktop quick formatting toolbar on mobile to maximize canvas viewport */
  .preview-toolbar {
    display: none !important;
  }

  .toolbar-chip-btn {
    padding: 3px 8px;
    font-size: 11.5px;
    min-height: 28px;
  }

  /* Canva-Grade Floating Canvas Zoom Widget */
  .zoom-controls {
    display: flex !important;
    position: fixed;
    bottom: 66px;
    right: 12px;
    background: rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 22px;
    padding: 3px 5px;
    gap: 3px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
    z-index: 85;
    align-items: center;
  }

  .zoom-controls .btn-icon,
  .zoom-controls .btn-toolbar {
    color: #f8fafc;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    border-radius: 12px;
    height: 26px;
    min-width: 26px;
    padding: 0 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
  }

  .zoom-controls .btn-icon:active,
  .zoom-controls .btn-toolbar:active {
    background: rgba(255, 255, 255, 0.28);
  }

  .zoom-controls .zoom-text {
    font-size: 10.5px;
    font-weight: 700;
    color: #ffffff;
    min-width: 32px;
    text-align: center;
  }

  /* In mobile editor mode, hide floating zoom controls so it doesn't block inputs */
  body.mobile-view-editor .zoom-controls {
    display: none !important;
  }

  /* 5. Canva-Style Floating Mobile Bottom Dock */
  .mobile-bottom-dock {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 58px;
    background: var(--ui-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--ui-border);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
    z-index: 100;
    align-items: center;
    justify-content: space-around;
    padding: 0 4px;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .mobile-dock-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    padding: 6px 2px;
    gap: 3px;
    cursor: pointer;
    color: var(--ui-text-muted);
    transition: all 0.12s ease;
    border-radius: 8px;
  }

  .mobile-dock-btn .dock-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 20px;
  }

  .mobile-dock-btn .dock-label {
    font-size: 10.5px;
    font-weight: 600;
    line-height: 1;
  }

  .mobile-dock-btn.active {
    color: var(--ui-accent);
  }

  .mobile-dock-btn.active .dock-icon svg {
    stroke: var(--ui-accent);
    stroke-width: 2.4;
  }

  .mobile-dock-btn.highlight {
    color: var(--ui-accent);
  }

  .mobile-dock-btn.highlight .dock-icon {
    background: var(--ui-accent-soft);
    width: 28px;
    height: 24px;
    border-radius: 12px;
  }

  .mobile-dock-btn:active {
    transform: scale(0.95);
  }

  /* 6. Native-Feel Mobile Export Action Sheet */
  .mobile-export-backdrop {
    display: flex;
    align-items: flex-end !important;
    justify-content: center !important;
    padding: 0 !important;
    background: rgba(0, 0, 0, 0.45) !important;
    backdrop-filter: blur(6px) !important;
    -webkit-backdrop-filter: blur(6px) !important;
    z-index: 2000 !important;
  }

  .mobile-export-sheet {
    background: var(--ui-surface);
    width: 100%;
    max-width: 520px;
    border-top-left-radius: 22px;
    border-top-right-radius: 22px;
    border: 1px solid var(--ui-border);
    border-bottom: none;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.25);
    padding: 12px 18px calc(18px + env(safe-area-inset-bottom, 12px)) 18px;
    box-sizing: border-box;
    animation: slideUpExportSheet 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes slideUpExportSheet {
    from {
      transform: translateY(100%);
      opacity: 0.8;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }

  .mobile-sheet-handle {
    width: 38px;
    height: 4.5px;
    background: var(--ui-border-strong);
    border-radius: 3px;
    margin: 0 auto 12px auto;
  }

  .mobile-export-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
  }

  .mobile-export-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--ui-text-main);
    letter-spacing: -0.2px;
  }

  .mobile-export-subtitle {
    margin: 2px 0 0 0;
    font-size: 11.5px;
    color: var(--ui-text-muted);
  }

  .mobile-sheet-close {
    background: var(--ui-surface-3);
    border: 1px solid var(--ui-border);
    color: var(--ui-text-muted);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
  }

  .mobile-sheet-close:active {
    background: var(--ui-surface-4);
  }

  .mobile-export-options {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-bottom: 14px;
  }

  .mobile-export-card {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 12px 14px;
    background: var(--ui-surface-2);
    border: 1px solid var(--ui-border);
    border-radius: 12px;
    text-align: left;
    cursor: pointer;
    transition: all 0.14s ease;
    width: 100%;
    box-sizing: border-box;
  }

  .mobile-export-card:active {
    transform: scale(0.985);
    background: var(--ui-surface-3);
  }

  .mobile-export-card.primary {
    background: var(--ui-accent-soft);
    border-color: var(--ui-accent);
  }

  .export-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .export-card-icon.pdf-icon {
    background: var(--ui-accent);
    color: #ffffff;
  }

  .export-card-icon.print-icon {
    background: var(--ui-surface-3);
    color: var(--ui-text-main);
    border: 1px solid var(--ui-border);
  }

  .export-card-icon.copy-icon {
    background: var(--ui-surface-3);
    color: var(--ui-text-main);
    border: 1px solid var(--ui-border);
  }

  .export-card-text {
    flex: 1;
    min-width: 0;
  }

  .export-card-title {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--ui-text-main);
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .export-badge {
    font-size: 9.5px;
    font-weight: 700;
    padding: 2px 6px;
    background: var(--ui-accent);
    color: #ffffff;
    border-radius: 4px;
    letter-spacing: 0.2px;
  }

  .export-card-desc {
    font-size: 11.5px;
    color: var(--ui-text-muted);
    margin-top: 2px;
    line-height: 1.3;
  }

  .mobile-export-footer {
    display: flex;
  }

  .mobile-sheet-cancel {
    width: 100%;
    padding: 10px 0;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
    background: var(--ui-surface-3);
    color: var(--ui-text-main);
    border: 1px solid var(--ui-border);
    cursor: pointer;
  }

  /* 7. Touch Dialogs / Modals */
  .modal-dialog {
    width: 95% !important;
    max-width: 95% !important;
    margin: 14px auto !important;
    max-height: 88vh !important;
    border-radius: 14px !important;
  }

  .modal-header {
    padding: 14px 16px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
  }

  /* Large touch-friendly, prominent close button */
  .btn-close {
    font-size: 28px !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: var(--ui-text-main) !important;
    background-color: var(--ui-surface-3) !important;
    border-radius: 10px !important;
    border: 1px solid var(--ui-border) !important;
    flex-shrink: 0 !important;
    cursor: pointer !important;
    line-height: 1 !important;
    padding: 0 !important;
    margin: -4px -4px 0 0;
  }

  .btn-close:active {
    background-color: var(--ui-surface-4) !important;
    transform: scale(0.92);
  }

  .confirm-close-btn {
    font-size: 26px !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: var(--ui-text-main) !important;
    background-color: var(--ui-surface-3) !important;
    border-radius: 10px !important;
    border: 1px solid var(--ui-border) !important;
  }

  .confirm-close-btn:active {
    background-color: var(--ui-surface-4) !important;
    transform: scale(0.92);
  }

  .modal-body {
    padding: 12px 14px;
  }

  .modal-footer {
    padding: 10px 14px;
  }

  /* Template gallery 1-column on small screens */
  .template-gallery-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Onboarding tour on mobile */
  .tour-card {
    width: 92vw !important;
    left: 4vw !important;
    top: auto !important;
    bottom: 74px !important;
    transform: none !important;
  }

  .tour-spotlight-ring {
    display: none !important; /* Rings clip on small viewports */
  }
}


/* ==========================================================================
   STRICT @media print STYLESHEET
   Flawless 1:1 Vector Print to A4
   Removes all editing highlights, cursor outlines, and tour overlays
   ========================================================================== */

@page {
  size: A4 portrait;
  margin: 0mm;
}

@media print {
  html, body {
    width: 210mm !important;
    height: 297mm !important;
    max-height: 297mm !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .app-header,
  .control-panel,
  .panel-collapse-btn,
  .sidebar-resizer,
  .section-spacer-widget,
  .preview-toolbar,
  .doc-page-manager-bar,
  .page-sheet-strip,
  .page-overflow-warning-bar,
  .mobile-canvas-hint,
  .mobile-bottom-dock,
  #mobileExportModal,
  .mobile-export-backdrop,
  .mobile-export-sheet,
  #pdfExportProgressModal,
  .pdf-export-backdrop,
  .pdf-export-dialog,
  .no-print,
  [data-html2canvas-ignore="true"],
  .modal-backdrop,
  .onboarding-tour-overlay {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    max-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    opacity: 0 !important;
  }

  .app-workspace,
  .preview-area,
  .paper-viewport,
  .document-canvas-wrapper,
  .document-pages-stage {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    width: 210mm !important;
    height: auto !important;
    transform: none !important;
    overflow: visible !important;
    background: none !important;
  }

  /* Strip all interactive outlines and highlights for clean print */
  .editable-field {
    outline: none !important;
    background: transparent !important;
    cursor: default !important;
  }

  .center-watermark-overlay {
    z-index: 45 !important;
    pointer-events: none !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Single letter: height 296.5mm guarantees zero overflow onto page 2 */
  body:not(.printing-batch):not(.has-multiple-pages) .a4-sheet {
    width: 210mm !important;
    height: 296.5mm !important;
    max-height: 296.5mm !important;
    min-height: 296.5mm !important;
    box-shadow: none !important;
    border: none !important;
    margin: 0 auto !important;
    transform: none !important;
    page-break-after: avoid !important;
    page-break-before: avoid !important;
    page-break-inside: avoid !important;
    break-after: avoid !important;
    break-before: avoid !important;
    break-inside: avoid !important;
    position: relative !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  /* Multi-page document print mode */
  body.has-multiple-pages,
  body.has-multiple-pages html {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  body.has-multiple-pages .app-workspace,
  body.has-multiple-pages .preview-area,
  body.has-multiple-pages .paper-viewport,
  body.has-multiple-pages .document-canvas-wrapper,
  body.has-multiple-pages .document-pages-stage {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  body.has-multiple-pages .a4-sheet {
    width: 210mm !important;
    height: 296.5mm !important;
    max-height: 296.5mm !important;
    min-height: 296.5mm !important;
    box-shadow: none !important;
    border: none !important;
    margin: 0 auto !important;
    transform: none !important;
    page-break-after: always !important;
    break-after: page !important;
    position: relative !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  body.has-multiple-pages .page-sheet-container:last-child .a4-sheet {
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  /* Batch print mode */
  body.printing-batch {
    height: auto !important;
    overflow: visible !important;
  }

  body.printing-batch html {
    height: auto !important;
    overflow: visible !important;
  }

  body.printing-batch .app-workspace,
  body.printing-batch .preview-area,
  body.printing-batch .paper-viewport {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  body.printing-batch #letterSheet,
  body.printing-batch .page-sheet-container {
    display: none !important;
  }

  body.printing-batch .batch-print-container {
    display: block !important;
  }

  body.printing-batch .batch-sheet {
    width: 210mm !important;
    height: 296.5mm !important;
    min-height: 296.5mm !important;
    max-height: 296.5mm !important;
    box-shadow: none !important;
    border: none !important;
    margin: 0 auto !important;
    padding: 15mm 18mm 15mm 18mm !important;
    transform: none !important;
    page-break-after: always !important;
    page-break-inside: avoid !important;
    break-after: page !important;
    break-inside: avoid !important;
    position: relative !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  body.printing-batch .batch-sheet:last-child {
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  /* Single-page natural overflow fallback when content exceeds 1 sheet */
  body.document-has-overflow:not(.printing-batch):not(.has-multiple-pages),
  body.document-has-overflow:not(.printing-batch):not(.has-multiple-pages) html {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  body.document-has-overflow:not(.printing-batch):not(.has-multiple-pages) .a4-sheet {
    height: auto !important;
    max-height: none !important;
    min-height: 296.5mm !important;
    overflow: visible !important;
    page-break-after: auto !important;
    break-after: auto !important;
  }

  /* US Letter Print Overrides */
  body.size-letter-print {
    width: 215.9mm !important;
    height: 279.4mm !important;
    max-height: 279.4mm !important;
  }

  body.size-letter-print:not(.printing-batch):not(.has-multiple-pages) .a4-sheet,
  body.size-letter-print.has-multiple-pages .a4-sheet,
  body.size-letter-print.printing-batch .batch-sheet {
    width: 215.9mm !important;
    height: 278.5mm !important;
    min-height: 278.5mm !important;
    max-height: 278.5mm !important;
  }

  body.size-letter-print.document-has-overflow:not(.printing-batch):not(.has-multiple-pages) .a4-sheet {
    min-height: 278.5mm !important;
  }
}

/* ==========================================================================
   Utility & Missing Component Classes
   ========================================================================== */

.col-12 {
  flex: 0 0 100%;
  max-width: 100%;
  width: 100%;
}

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 4px !important; }
.ml-1 { margin-left: 4px !important; }
.w-45 { width: 45% !important; }
.w-55 { width: 55% !important; }
.w-full { width: 100% !important; }
.font-semibold { font-weight: 600 !important; }
.bold { font-weight: 700 !important; }
.uppercase { text-transform: uppercase !important; }
.align-justify { text-align: justify !important; }
.align-right { text-align: right !important; }

.sub-card {
  background: var(--ui-control-bg);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-top: 8px;
}

.form-card.sub-card {
  background: var(--ui-control-bg);
}

.form-input-sm {
  height: 28px;
  padding: 3px 8px;
  font-size: 11.5px;
  border-radius: 4px;
}

.doc-page-manager-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.btn-add-next-page,
.btn-duplicate-page {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  background: var(--ui-control-bg);
  border: 1px solid var(--ui-border);
  color: var(--ui-text-main);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-add-next-page:hover,
.btn-duplicate-page:hover {
  background: var(--ui-control-bg-hover);
  border-color: var(--ui-border-dark);
}

.btn-delete-sheet {
  color: var(--ui-danger-text) !important;
}

.btn-spacer-minus,
.btn-spacer-plus {
  user-select: none;
}

.btn-spacer-minus:hover {
  background: #dc2626 !important;
  border-color: #dc2626 !important;
  color: #ffffff !important;
}

.btn-spacer-plus:hover {
  background: #16a34a !important;
  border-color: #16a34a !important;
  color: #ffffff !important;
}

.fit-label {
  font-size: 11px;
  font-weight: 600;
  color: inherit;
}

.footer-page-num-text {
  font-size: 8.5pt;
  color: inherit;
}

.page-footer-toggle,
.page-header-toggle {
  cursor: pointer;
  accent-color: var(--ui-accent);
}

.sig-pill-text {
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1;
}

.signature-extra-box {
  padding: 8px 10px;
  background: var(--ui-control-bg);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  margin-top: 8px;
}

.status-text {
  font-size: 11px;
  color: var(--ui-text-muted);
}

.theme-name {
  font-size: 11px;
  font-weight: 500;
  color: var(--ui-text-main);
}

.tour-step-current {
  font-weight: 700;
  color: var(--ui-accent);
}

.typed-sig-picker {
  padding: 8px 10px;
  background: var(--ui-control-bg);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  margin-top: 8px;
}

.mini-signoff.dual,
.dual {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.mini-body {
  display: flex;
  flex-direction: column;
  gap: 2.5px;
  width: 100%;
}

.mini-date-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 3px;
}

.mini-recipient {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 60%;
  margin-bottom: 4px;
}

.mini-subject {
  width: 100%;
  margin-bottom: 4px;
}

.mini-subject.center {
  display: flex;
  justify-content: center;
}

.theme-navy-bg {
  background: linear-gradient(135deg, #0f172a, #1e3a8a) !important;
  color: #ffffff !important;
}

.theme-slate-bg {
  background: linear-gradient(135deg, #1e293b, #334155) !important;
  color: #ffffff !important;
}

.theme-emerald-bg {
  background: linear-gradient(135deg, #022c22, #065f46) !important;
  color: #ffffff !important;
}

.theme-crimson-bg {
  background: linear-gradient(135deg, #450a0a, #991b1b) !important;
  color: #ffffff !important;
}

.theme-mono-bg {
  background: linear-gradient(135deg, #09090b, #27272a) !important;
  color: #ffffff !important;
}


/* ==========================================================================
   START SCREEN MODAL — First-Launch Welcome
   ========================================================================== */

#startScreenModal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeInOverlay 0.28s ease;
}

#startScreenModal.hidden { display: none; }

@keyframes fadeInOverlay {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.start-screen-card {
  background: var(--ui-surface-raised);
  border-radius: 16px;
  padding: 48px 56px 44px;
  max-width: 580px;
  width: calc(100vw - 40px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  animation: slideUpCard 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  text-align: center;
}

@keyframes slideUpCard {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.start-screen-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ui-text-muted);
  margin-bottom: 18px;
}

.start-screen-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--ui-text-main);
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 10px;
}

.start-screen-subtitle {
  font-size: 14px;
  color: var(--ui-text-muted);
  line-height: 1.6;
  margin-bottom: 36px;
}

.start-screen-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 24px;
}

.start-choice-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--ui-border);
  background: var(--ui-surface-2);
  cursor: pointer;
  transition: all 0.18s ease;
  font-family: inherit;
  text-decoration: none;
  color: inherit;
}

.start-choice-btn:hover {
  border-color: var(--ui-accent);
  background: var(--ui-accent-soft);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(30, 58, 138, 0.12);
}

.start-choice-btn.primary-choice {
  border-color: var(--ui-accent);
  background: var(--ui-accent);
  color: var(--ui-on-accent);
}

.start-choice-btn.primary-choice:hover {
  background: var(--ui-accent-hover);
  border-color: var(--ui-accent-hover);
  box-shadow: 0 4px 20px rgba(30, 58, 138, 0.30);
}

.start-choice-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(255,255,255,0.18);
  flex-shrink: 0;
}

.start-choice-btn:not(.primary-choice) .start-choice-icon {
  background: var(--ui-accent-soft);
}

.start-choice-title {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
}

.start-choice-desc {
  font-size: 11px;
  opacity: 0.75;
  line-height: 1.4;
}

.start-screen-hint {
  font-size: 11px;
  color: var(--ui-text-muted);
}

@media (max-width: 500px) {
  .start-screen-card {
    padding: 32px 24px 28px;
  }
  .start-screen-choices {
    grid-template-columns: 1fr;
  }
  .start-screen-title {
    font-size: 22px;
  }
}


/* ==========================================================================
   GALLERY FILTER TABS
   ========================================================================== */

.gallery-filter-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--ui-border);
}

.gallery-filter-tab {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--ui-border);
  background: transparent;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ui-text-sub);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
}

.gallery-filter-tab:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.gallery-filter-tab.active {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: #fff;
  font-weight: 600;
}


/* ==========================================================================
   SALUTATION & CLOSING QUICK-FILL CHIPS
   ========================================================================== */

.quick-fill-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.quick-fill-chip {
  padding: 3px 9px;
  border-radius: 12px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-3);
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ui-text-sub);
  cursor: pointer;
  transition: all 0.14s;
  font-family: inherit;
  white-space: nowrap;
}

.quick-fill-chip:hover {
  background: var(--accent-color);
  color: #fff;
  border-color: var(--accent-color);
}


/* ==========================================================================
   BODY FORMATTING CONTROLS (Font Size + Alignment + Letterhead-Free)
   ========================================================================== */

.body-format-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.body-align-group {
  display: flex;
  gap: 3px;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  padding: 2px;
  background: var(--ui-surface-2);
}

.body-align-btn {
  width: 28px;
  height: 26px;
  border: none;
  background: transparent;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ui-text-muted);
  transition: all 0.14s;
}

.body-align-btn:hover,
.body-align-btn.active {
  background: var(--accent-color);
  color: #fff;
}

.body-format-sep {
  width: 1px;
  height: 20px;
  background: var(--ui-border);
  flex-shrink: 0;
}

.font-size-select-sm {
  height: 30px;
  padding: 0 6px;
  font-size: 11.5px;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  background: var(--ui-input-bg);
  color: var(--ui-text-main);
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 5px center;
  padding-right: 20px;
}

.clear-content-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ui-danger);
  background: var(--ui-danger-soft);
  border: 1px solid var(--ui-danger-border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.clear-content-btn:hover {
  background: var(--ui-danger);
  color: #fff;
  border-color: var(--ui-danger);
}

.letterhead-free-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--ui-warning-soft);
  border: 1px solid var(--ui-warning-border);
  margin-top: 8px;
}

.letterhead-free-label {
  font-size: 11.5px;
  color: var(--ui-warning-text);
  line-height: 1.4;
}

.letterhead-free-label strong {
  display: block;
  font-weight: 600;
  margin-bottom: 1px;
}

/* Continuation body content use the same font size variable */
.continuation-body-content,
.letter-body-content {
  font-size: var(--body-font-size, 11pt);
}

/* ==========================================================================
   PAGE-SPECIFIC CONTINUATION TEMPLATES
   ========================================================================== */

/* Sheet Strip Template & Continue Same Buttons */
.strip-btn.btn-page-template {
  background: var(--ui-accent-soft);
  border-color: var(--ui-accent-soft-border);
  color: var(--ui-accent);
  font-weight: 600;
}

.strip-btn.btn-page-template:hover {
  background: var(--ui-accent);
  color: var(--ui-on-accent);
}

.strip-btn.btn-continue-same {
  background: var(--ui-success-soft);
  border-color: var(--ui-success-border);
  color: var(--ui-success-text);
  font-weight: 600;
}

.strip-btn.btn-continue-same:hover {
  background: var(--ui-success);
  color: #ffffff;
}

/* Curated Page Template Semantic HTML Elements (Rendered on Paper) */
.continuation-flow-marker {
  font-size: 10.5pt;
  color: #64748b;
  margin-bottom: 16px;
  border-bottom: 1px dashed #e2e8f0;
  padding-bottom: 6px;
}

.terms-header-title {
  font-size: 14pt;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent-color, #1e3a8a);
  border-bottom: 2px solid var(--accent-color, #1e3a8a);
  padding-bottom: 6px;
  margin-bottom: 18px;
}

.terms-clause-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.terms-clause-item {
  line-height: 1.5;
}

.terms-clause-heading {
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 3px;
}

.annexure-banner {
  background: #f8fafc;
  border: 1.5px solid var(--accent-color, #1e3a8a);
  border-left-width: 6px;
  padding: 10px 14px;
  margin-bottom: 18px;
}

.annexure-title {
  font-size: 13pt;
  font-weight: 800;
  color: var(--accent-color, #1e3a8a);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 0 0 4px 0;
}

.annexure-meta {
  font-size: 9.5pt;
  color: #64748b;
}

.annexure-table,
.fee-schedule-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0 18px 0;
  font-size: 10pt;
}

.annexure-table th,
.fee-schedule-table th {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  padding: 8px 10px;
  font-weight: 700;
  text-align: left;
  color: #1e293b;
}

.annexure-table td,
.fee-schedule-table td {
  border: 1px solid #e2e8f0;
  padding: 8px 10px;
  color: #334155;
  vertical-align: top;
}

.fee-total-box {
  margin: 14px 0;
  padding: 10px 14px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
}

.fee-summary-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 10.5pt;
}

.fee-summary-row.total-due {
  font-size: 12pt;
  font-weight: 800;
  border-top: 1.5px solid #0f172a;
  margin-top: 6px;
  padding-top: 6px;
  color: var(--accent-color, #1e3a8a);
}

.multi-signatory-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 28px;
  margin: 22px 0;
}

.signatory-slot {
  border: 1px solid #e2e8f0;
  background: #fcfcfc;
  border-radius: 4px;
  padding: 14px;
}

.signatory-slot-title {
  font-weight: 700;
  font-size: 10.5pt;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent-color, #1e3a8a);
  margin-bottom: 12px;
}

.signatory-sign-line {
  border-bottom: 1.5px solid #0f172a;
  margin: 36px 0 8px 0;
}

.signatory-field-label {
  font-size: 9pt;
  color: #64748b;
  margin-top: 6px;
}

.exec-memo-card {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 18px;
}

.exec-memo-badge {
  display: inline-block;
  font-size: 9pt;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #991b1b;
  background: #fee2e2;
  padding: 2px 8px;
  border-radius: 3px;
  margin-bottom: 10px;
}

/* Print Suppression for Modals & Mobile Chrome */
@media print {
  .modal-backdrop,
  .mobile-bottom-dock,
  #mobileExportModal,
  #pdfExportProgressModal,
  .mobile-canvas-hint {
    display: none !important;
  }
}

/* ==========================================================================
   THEME TOGGLE CONTROL (Header)
   ========================================================================== */

.theme-mode-toggle {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 6px;
  border: 1px solid var(--ui-border);
  background-color: var(--ui-control-bg);
  color: var(--ui-text-sub);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.theme-mode-toggle:hover {
  background-color: var(--ui-control-bg-hover);
  border-color: var(--ui-border-strong);
  color: var(--ui-text-main);
}

.theme-mode-toggle:focus-visible {
  outline: none;
  border-color: var(--ui-accent);
  box-shadow: 0 0 0 3px var(--ui-input-focus);
}

/* Show the sun in dark mode (click = go light) and the moon in light mode. */
.theme-mode-toggle .icon-sun { display: none !important; }
.theme-mode-toggle .icon-moon { display: block !important; }
:root[data-theme="dark"] .theme-mode-toggle .icon-sun,
html[data-theme="dark"] .theme-mode-toggle .icon-sun { display: block !important; }
:root[data-theme="dark"] .theme-mode-toggle .icon-moon,
html[data-theme="dark"] .theme-mode-toggle .icon-moon { display: none !important; }

/* ==========================================================================
   DARK THEME — STRUCTURAL OVERRIDES
   For the handful of places a token swap alone cannot express. Everything
   else is driven by the --ui-* tokens redefined in :root[data-theme="dark"].
   ========================================================================== */

/* Paper-content previews stay on a light ground. .logo-thumb-box backs the
   primary logo, the accreditation badge and the stamp thumbnails — all preview
   artwork destined for a white A4 sheet, and navy/black vector art disappears
   against a dark card. */
:root[data-theme="dark"] .logo-thumb-box {
  background-color: #f1f5f9;
  border-color: var(--ui-border-strong);
}

/* The freehand signature pad captures dark ink, so its canvas stays light. */
:root[data-theme="dark"] .signature-canvas-container {
  background-color: #f1f5f9;
  border-color: var(--ui-border-stronger);
}

/* Gallery thumbnails are miniature sheets of paper — keep their light chrome. */
:root[data-theme="dark"] .gallery-card-preview {
  background-color: #e2e8f0;
}

/* The autosave pill and status dot read as decoration at dark-mode weights. */
:root[data-theme="dark"] .autosave-status {
  border-color: var(--ui-success-border);
}

/* Keep the floating zoom pill readable: it already sits on its own dark glass
   surface, which needs a touch more lift against the near-black stage. */
:root[data-theme="dark"] .zoom-controls {
  background: rgba(30, 41, 59, 0.92);
  border-color: rgba(255, 255, 255, 0.14);
}

/* Modal scrim goes deeper so the raised surface still separates from it. */
:root[data-theme="dark"] .modal-backdrop {
  background-color: rgba(0, 0, 0, 0.72);
}

/* Three chrome controls borrow the DOCUMENT accent (--accent-color, driven by
   the Theme picker) for their selected state. That reads fine on light chrome,
   but a saturated navy/burgundy pill is unreadable on a dark surface — so in
   dark mode only, they fall back to the studio accent. Light mode keeps
   following the document theme exactly as before. */
:root[data-theme="dark"] .gallery-filter-tab:hover {
  border-color: var(--ui-accent);
  color: var(--ui-accent);
}

:root[data-theme="dark"] .gallery-filter-tab.active {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: var(--ui-on-accent);
}

:root[data-theme="dark"] .quick-fill-chip:hover {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: var(--ui-on-accent);
}

:root[data-theme="dark"] .body-align-btn:hover,
:root[data-theme="dark"] .body-align-btn.active {
  background: var(--ui-accent);
  color: var(--ui-on-accent);
}

/* Native date/number/color pickers and the select popups follow color-scheme,
   which is declared on :root — this only covers controls that set their own
   light background explicitly elsewhere in the sheet. */
:root[data-theme="dark"] input[type="color"] {
  background-color: var(--ui-input-bg);
  border-color: var(--ui-border-dark);
}

/* ==========================================================================
   PRINT SAFETY NET
   The A4 sheet never consumes --ui-* tokens, but if a chrome element is ever
   captured by the print/html2pdf pass it must not carry dark-theme colors.
   ========================================================================== */

@media print {
  :root,
  :root[data-theme="dark"] {
    color-scheme: light;
    --ui-bg: #ffffff;
    --ui-surface: #ffffff;
    --ui-surface-raised: #ffffff;
    --ui-surface-2: #f8fafc;
    --ui-surface-3: #f1f5f9;
    --ui-surface-4: #e2e8f0;
    --ui-control-bg: #ffffff;
    --ui-control-bg-hover: #f8fafc;
    --ui-input-bg: #ffffff;
    --ui-border: #e5e7eb;
    --ui-border-dark: #d1d5db;
    --ui-border-strong: #cbd5e1;
    --ui-border-stronger: #94a3b8;
    --ui-text-main: #111827;
    --ui-text-sub: #4b5563;
    --ui-text-muted: #6b7280;
    --ui-accent: #1e3a8a;
    --ui-accent-hover: #172554;
    --ui-accent-strong: #1d4ed8;
    --ui-accent-soft: #eff6ff;
    --ui-on-accent: #ffffff;
    --ui-sheet-border: transparent;
    --ui-sheet-shadow: none;
  }
}

/* ==========================================================================
   CANVA-STYLE ANIMATED PDF EXPORT PROGRESS MODAL (Desktop & Mobile)
   ========================================================================== */

.pdf-export-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 1;
  transition: opacity 0.25s ease;
}

.pdf-export-backdrop.hidden {
  display: none !important;
  opacity: 0;
  pointer-events: none;
}

.pdf-export-dialog {
  background: var(--ui-surface-raised, #ffffff);
  border: 1px solid var(--ui-border-strong, #cbd5e1);
  border-radius: 16px;
  width: 90%;
  max-width: 420px;
  padding: 32px 28px 26px 28px;
  box-shadow: 0 24px 48px -12px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  animation: pdfExportPopIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes pdfExportPopIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.pdf-export-visual {
  margin-bottom: 20px;
  position: relative;
}

.pdf-export-icon-stage {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: var(--ui-surface-2, #f1f5f9);
  border: 1px solid var(--ui-border, #e2e8f0);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ui-accent, #1e3a8a);
  position: relative;
  transition: all 0.3s ease;
}

.pdf-export-icon-stage.exporting {
  animation: pdfPulseIcon 1.8s ease-in-out infinite;
}

@keyframes pdfPulseIcon {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(30, 58, 138, 0.2);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 0 10px rgba(30, 58, 138, 0);
  }
}

.pdf-export-icon-stage.success {
  background: #ecfdf5;
  border-color: #6ee7b7;
  color: #059669;
  transform: scale(1.08);
}

.pdf-export-check-badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  color: #059669;
}

.pdf-export-icon-stage.success .pdf-export-doc-icon {
  opacity: 0;
  transform: scale(0.5);
}

.pdf-export-icon-stage.success .pdf-export-check-badge {
  opacity: 1;
  transform: scale(1);
}

.pdf-export-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ui-text-main, #0f172a);
  margin: 0 0 6px 0;
  letter-spacing: -0.015em;
  transition: color 0.2s ease;
}

.pdf-export-subtitle {
  font-size: 0.875rem;
  color: var(--ui-text-sub, #64748b);
  margin: 0 0 22px 0;
  line-height: 1.4;
}

.pdf-export-progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--ui-surface-3, #e2e8f0);
  overflow: hidden;
  position: relative;
  margin-bottom: 14px;
}

.pdf-export-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--ui-accent, #1e3a8a);
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.pdf-export-progress-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  animation: pdfShimmer 1.5s infinite;
}

@keyframes pdfShimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.pdf-export-footer-meta {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.775rem;
}

.pdf-export-status-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--ui-surface-2, #f1f5f9);
  color: var(--ui-text-sub, #64748b);
  font-weight: 500;
  border: 1px solid var(--ui-border, #e2e8f0);
}

.pdf-export-percent {
  font-weight: 600;
  color: var(--ui-text-main, #0f172a);
  font-variant-numeric: tabular-nums;
}

:root[data-theme="dark"] .pdf-export-icon-stage.success {
  background: rgba(6, 78, 59, 0.4);
  border-color: #059669;
  color: #34d399;
}

:root[data-theme="dark"] .pdf-export-check-badge {
  color: #34d399;
}

/* ==========================================================================
   WORD-STYLE CUSTOM MARGINS MODAL
   ========================================================================== */

.custom-margins-backdrop {
  z-index: 9998;
}

.modal-custom-margins {
  max-width: 640px;
  width: 95vw;
}

.custom-margins-modal-body {
  padding: 16px 20px;
}

/* Two-column layout: inputs on left, preview on right */
.margins-modal-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

/* --- Left: Inputs Section --- */
.margins-inputs-section {
  flex: 1;
  min-width: 0;
}

.margins-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ui-text-muted, #64748b);
}

/* Compass-style 4-edge layout */
.margins-compass-grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.compass-middle-row {
  display: flex;
  gap: 16px;
  width: 100%;
  justify-content: center;
}

.compass-margin-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.compass-margin-item label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text-sub, #475569);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Stepper wrapper: [−] [input] mm [+] */
.margin-stepper-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--ui-surface-2, #f1f5f9);
  border: 1px solid var(--ui-border, #e2e8f0);
  border-radius: 7px;
  padding: 3px 6px;
}

.stepper-btn {
  background: transparent;
  border: none;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  color: var(--ui-text-sub, #475569);
  line-height: 1;
  transition: background 0.12s ease, color 0.12s ease;
  flex-shrink: 0;
  padding: 0;
}

.stepper-btn:hover {
  background: var(--ui-surface-3, #e2e8f0);
  color: var(--ui-text-main, #0f172a);
}

.stepper-btn:active {
  background: var(--ui-accent, #1e40af);
  color: white;
}

.margin-num-input {
  width: 46px;
  border: none;
  background: transparent;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--ui-text-main, #0f172a);
  outline: none;
  -moz-appearance: textfield;
  padding: 0 2px;
}

.margin-num-input::-webkit-outer-spin-button,
.margin-num-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.unit-tag {
  font-size: 11px;
  color: var(--ui-text-muted, #94a3b8);
  font-weight: 500;
  flex-shrink: 0;
}

/* Inline toggle for "Lock Equal" */
.switch-toggle-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.toggle-track-micro {
  display: inline-block;
  width: 28px;
  height: 15px;
  background: var(--ui-border, #e2e8f0);
  border-radius: 99px;
  position: relative;
  transition: background 0.18s ease;
  flex-shrink: 0;
}

.toggle-track-micro::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18);
  transition: transform 0.18s ease;
}

.switch-toggle-inline input[type="checkbox"] {
  display: none;
}

.switch-toggle-inline input[type="checkbox"]:checked + .toggle-track-micro {
  background: var(--ui-accent, #1e40af);
}

.switch-toggle-inline input[type="checkbox"]:checked + .toggle-track-micro::after {
  transform: translateX(13px);
}

/* Quick preset pills inside modal */
.margins-preset-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.preset-pills-label {
  font-size: 11px;
  color: var(--ui-text-muted, #94a3b8);
  font-weight: 600;
  margin-right: 2px;
}

.modal-preset-btn {
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--ui-border, #e2e8f0);
  background: var(--ui-surface-2, #f8fafc);
  color: var(--ui-text-sub, #475569);
  cursor: pointer;
  transition: all 0.12s ease;
  white-space: nowrap;
}

.modal-preset-btn:hover {
  border-color: var(--ui-accent, #1e40af);
  color: var(--ui-accent, #1e40af);
  background: var(--ui-accent-bg, #eff6ff);
}

/* --- Right: Live Mini Sheet Preview --- */
.margins-preview-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-width: 130px;
}

/* Word-style mini A4 sheet with visible content area */
.word-sheet-mini {
  width: 110px;
  height: 155px;
  background: white;
  border: 1.5px solid #cbd5e1;
  border-radius: 3px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.10), 2px 3px 0 0 #e2e8f0;
  position: relative;
  display: flex;
  box-sizing: border-box;
  transition: padding 0.2s ease;
}

.mini-margin-guide {
  flex: 1;
  background: #f0f4ff;
  border: 1px dashed #93c5fd;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6px 4px;
  box-sizing: border-box;
  overflow: hidden;
  border-radius: 1px;
}

.mini-content-lines {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.mini-line {
  height: 3px;
  background: #93c5fd;
  border-radius: 2px;
}
.mini-line.w-80 { width: 80%; }
.mini-line.w-100 { width: 100%; }
.mini-line.w-95 { width: 95%; }
.mini-line.w-90 { width: 90%; }
.mini-line.w-60 { width: 60%; }

.margins-preview-info {
  font-size: 10.5px;
  color: var(--ui-text-muted, #94a3b8);
  text-align: center;
  line-height: 1.3;
}

/* Dark theme overrides for Custom Margins Modal */
:root[data-theme="dark"] .word-sheet-mini {
  background: #1e293b;
  border-color: #334155;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3), 2px 3px 0 0 #1e293b;
}

:root[data-theme="dark"] .mini-margin-guide {
  background: rgba(30, 64, 175, 0.12);
  border-color: #3b82f6;
}

:root[data-theme="dark"] .mini-line {
  background: #3b82f6;
}

:root[data-theme="dark"] .margin-stepper-wrap {
  background: var(--ui-surface-3, #1e293b);
  border-color: var(--ui-border, #334155);
}

:root[data-theme="dark"] .toggle-track-micro {
  background: var(--ui-border, #334155);
}

:root[data-theme="dark"] .toggle-track-micro::after {
  background: #94a3b8;
}

:root[data-theme="dark"] .modal-preset-btn {
  background: var(--ui-surface-3, #1e293b);
  border-color: var(--ui-border, #334155);
  color: var(--ui-text-sub, #94a3b8);
}

:root[data-theme="dark"] .modal-preset-btn:hover {
  border-color: #3b82f6;
  color: #60a5fa;
  background: rgba(30, 64, 175, 0.15);
}

:root[data-theme="dark"] .margin-num-input {
  color: var(--ui-text-main, #f1f5f9);
}

/* ==========================================================================
   SIDEBAR CUSTOM MARGINS DRAWER (inline, inside control panel)
   ========================================================================== */

.custom-margins-drawer {
  background: var(--ui-surface-2, #f8fafc);
  border: 1px solid var(--ui-border, #e2e8f0);
  border-radius: 8px;
  padding: 10px 12px;
}

.custom-margins-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.margin-input-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.margin-input-col label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ui-text-muted, #64748b);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.margin-input-unit {
  display: flex;
  align-items: center;
  gap: 2px;
}

.margin-input-unit span {
  font-size: 10px;
  color: var(--ui-text-muted, #94a3b8);
}

:root[data-theme="dark"] .custom-margins-drawer {
  background: var(--ui-surface-3, #1e293b);
  border-color: var(--ui-border, #334155);
}

/* Responsive: narrow sidebar stacks to 2 columns */
@media (max-width: 400px) {
  .custom-margins-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ==========================================================================
   PAGE NUMBER PRESET CHIPS
   ========================================================================== */

.page-num-presets-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 2px;
}

.preset-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 99px;
  border: 1.5px solid var(--ui-border, #e2e8f0);
  background: var(--ui-surface-2, #f8fafc);
  color: var(--ui-text-sub, #475569);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
  white-space: nowrap;
  font-family: var(--font-mono, 'Courier New', monospace);
  letter-spacing: 0.02em;
}

.preset-chip:hover {
  border-color: var(--ui-accent, #1e40af);
  color: var(--ui-accent, #1e40af);
  background: var(--ui-accent-bg, #eff6ff);
}

.preset-chip.active {
  border-color: var(--ui-accent, #1e40af);
  background: var(--ui-accent, #1e40af);
  color: white;
}

:root[data-theme="dark"] .preset-chip {
  background: var(--ui-surface-3, #1e293b);
  border-color: var(--ui-border, #334155);
  color: var(--ui-text-sub, #94a3b8);
}

:root[data-theme="dark"] .preset-chip:hover {
  border-color: #3b82f6;
  color: #60a5fa;
  background: rgba(30, 64, 175, 0.15);
}

:root[data-theme="dark"] .preset-chip.active {
  border-color: #3b82f6;
  background: #1e40af;
  color: white;
}
