/* ============================================
   FORM APP LAYOUT - Desktop-class form experience
   Inspired by form-render.html mockup
   ============================================ */

/* ===== CSS Variables ===== */
:root {
  --fa-primary: #2D5A87;
  --fa-primary-hover: #244C6F;
  --fa-bg: #F8F9FA;
  --fa-sidebar-bg: #212121;
  --fa-card-white: #FFFFFF;
  --fa-border: #E2E8F0;
  --fa-text-dark: #1A202C;
  --fa-text-muted: #718096;
  --fa-success: #48BB78;
  --fa-in-progress: #ECC94B;
  --fa-locked: #A0AEC0;
  --fa-sidebar-width: 260px;
  --fa-topbar-height: 56px;
  --fa-footer-height: 68px;
  --fa-radius-lg: 12px;
  --fa-radius-md: 8px;
  --fa-radius-sm: 4px;
  --fv-browser-bottom-inset: 0px;
  --fa-font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ===== Form App Layout Override ===== */
/* Only activate on form page with new layout */
body[data-page="form"].form-app-layout {
  padding: 0 !important;
  margin: 0 !important;
  background-color: var(--fa-bg);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body[data-page="form"].form-app-layout .navbar {
  display: none !important;
}

/* ===== App Container ===== */
.form-app-container {
  display: flex;
  flex: 1;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

/* ===== 1. SIDEBAR ===== */
.form-app-sidebar {
  width: var(--fa-sidebar-width);
  min-width: var(--fa-sidebar-width);
  background-color: var(--fa-sidebar-bg);
  color: white;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 200;
  overflow: hidden;
}

.form-app-sidebar .sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 24px 16px;
  text-decoration: none;
  flex-shrink: 0;
}

.form-app-sidebar .sidebar-logo img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.form-app-sidebar .sidebar-logo span {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

/* Sidebar section list */
.sidebar-sections {
  list-style: none;
  margin: 0;
  padding: 0 12px;
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.sidebar-sections::-webkit-scrollbar {
  width: 4px;
}

.sidebar-sections::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

.sidebar-section-item {
  margin-bottom: 2px;
}

.sidebar-section-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.65);
  border-radius: var(--fa-radius-sm);
  font-size: 0.875rem;
  font-weight: 400;
  transition: background-color 0.2s, color 0.2s;
  cursor: pointer;
  position: relative;
}

.sidebar-section-link:hover {
  background-color: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.9);
}

.sidebar-section-link.active {
  background-color: rgba(45, 90, 135, 0.2);
  color: white;
  font-weight: 500;
  box-shadow: inset 3px 0 0 var(--fa-primary);
}

.sidebar-section-link .section-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.1);
  transition: background-color 0.2s;
}

.sidebar-section-link.active .section-num {
  background: var(--fa-primary);
}

.sidebar-section-link.completed .section-num {
  background: var(--fa-success);
}

.sidebar-section-link .section-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Status badge */
.sidebar-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-status-dot.completed {
  background-color: var(--fa-success);
}

.sidebar-status-dot.in-progress {
  background-color: var(--fa-in-progress);
}

.sidebar-status-dot.locked {
  background-color: var(--fa-locked);
}

/* Sidebar footer actions */
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.sidebar-checklist-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  box-sizing: border-box;
  width: calc(100% - 24px);
  margin: 0 12px;
  padding: 10px 12px;
  background: rgba(45, 90, 135, 0.15);
  border: 1px solid rgba(45, 90, 135, 0.3);
  border-radius: var(--fa-radius-md);
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.2s;
}

.sidebar-checklist-btn:hover {
  background: rgba(45, 90, 135, 0.25);
  color: white;
}

.sidebar-checklist-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.8;
}


/* ===== 2. MAIN CONTENT WRAPPER ===== */
.form-app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}


/* ===== 3. TOP BAR ===== */
.form-app-topbar {
  height: var(--fa-topbar-height);
  min-height: var(--fa-topbar-height);
  background-color: var(--fa-card-white);
  border-bottom: 1px solid var(--fa-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  z-index: 100;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--fa-text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
  padding: 0;
  border: none;
  text-align: left;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
}

.topbar-autosave {
  font-size: 0.8125rem;
  color: var(--fa-text-muted);
  white-space: nowrap;
}

.form-app-lang-switcher {
  padding: 8px 30px 8px 12px !important;
  font-size: 0.875rem;
  line-height: 1.4;
  border: 1px solid var(--fa-border);
  border-radius: var(--fa-radius-sm);
  background-color: white;
  color: var(--fa-text-dark);
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 8px center;
  background-repeat: no-repeat;
  background-size: 16px 16px;
  margin: auto 0;
}

/* ===== 4. MAIN CANVAS (Scrollable Form Area) ===== */
.form-app-canvas {
  flex: 1 0 auto;
  min-height: 0;
  height: calc(100vh - var(--fa-topbar-height) - var(--fa-footer-height));
  padding: 24px 40px;
  padding-bottom: calc(var(--fa-footer-height) + 24px);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  transition: padding 0.4s ease;
}

.form-app-canvas-inner {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding-bottom: 50px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  transition: max-width 0.4s ease, padding 0.4s ease;
}

.form-app-card {
  background-color: var(--fa-card-white);
  border: 1px solid var(--fa-border);
  border-radius: var(--fa-radius-lg);
  padding: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  position: relative;
  overflow: visible;
  transition: all 0.4s ease;
}

.form-app-card-body {
  padding: 40px;
  transition: padding 0.4s ease;
}

.form-app-section-label {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fa-text-muted);
  margin-bottom: 4px;
}

.form-app-section-title {
  display: none;
  margin-top: 0;
  margin-bottom: 24px;
}

.form-app-stepper {
  height: 4px;
  background-color: #EDF2F7;
  width: 100%;
}

.form-app-stepper-bar {
  height: 100%;
  background: linear-gradient(to right, var(--fa-primary), #4A90E2);
  width: 0;
  transition: width 0.3s ease;
}

.form-app-footer {
  height: var(--fa-footer-height);
  min-height: var(--fa-footer-height);
  background-color: var(--fa-card-white);
  border-top: 1px solid var(--fa-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(40px, calc((100vw - var(--fa-sidebar-width) - 860px) / 2));
  position: fixed;
  left: var(--fa-sidebar-width);
  bottom: 0;
  right: 0;
  z-index: 100;
  box-shadow: 0 -3px 10px rgba(0, 0, 0, 0.03);
  box-sizing: border-box;
  transition: padding 0.4s ease, width 0.4s ease, left 0.4s ease;
}

.footer-group {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* Footer buttons */
.fa-btn {
  height: 42px;
  padding: 0 20px;
  font-family: var(--fa-font);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--fa-radius-md);
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}

.fa-btn:active {
  transform: scale(0.98);
}

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

.fa-btn-secondary {
  background-color: #F1F3F5;
  color: var(--fa-text-dark);
  border-color: var(--fa-border);
}

.fa-btn-secondary:hover {
  background-color: #E2E8F0;
}

.fa-btn-outline {
  background-color: white;
  color: var(--fa-primary);
  border-color: var(--fa-primary);
}

.fa-btn-outline:hover {
  background-color: rgba(45, 90, 135, 0.04);
}

.fa-btn-primary {
  background-color: var(--fa-primary);
  color: white;
  border-color: var(--fa-primary);
  box-shadow: 0 2px 8px rgba(45, 90, 135, 0.3);
}

.fa-btn-primary:hover {
  background-color: var(--fa-primary-hover);
}

.fa-btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== OVERRIDES for existing form elements inside new layout ===== */
/* Make existing form elements play nice with the new card layout */

body[data-page="form"].form-app-layout .page-title-container {
  display: none !important;
}

body[data-page="form"].form-app-layout .main-container {
  display: contents;
}

body[data-page="form"].form-app-layout #mainForm {
  display: contents;
}

body[data-page="form"].form-app-layout #dataControlNotice {
  display: none !important;
}

body[data-page="form"].form-app-layout #requiredNotice {
  display: none !important;
}

/* Progress sidebar - hidden in new layout (replaced by sidebar) */
body[data-page="form"].form-app-layout .progress-sidebar,
body[data-page="form"].form-app-layout .progress-sidebar-wrapper {
  display: none !important;
}

/* Submit button - hidden in new layout (replaced by footer) */
body[data-page="form"].form-app-layout #submitBtn {
  display: none !important;
}

/* Mobile section menu - hidden in new layout */
body[data-page="form"].form-app-layout .mobile-section-btn,
body[data-page="form"].form-app-layout .mobile-section-menu,
body[data-page="form"].form-app-layout .mobile-section-overlay {
  display: none !important;
}

/* Wizard navigation - integrated into footer in new layout */
body[data-page="form"].form-app-layout .wizard-navigation {
  display: none !important;
}

/* Form zone - reset margins for new layout */
body[data-page="form"].form-app-layout #formZone {
  margin: 0;
  max-width: 100%;
}

body[data-page="form"].form-app-layout #visaForm {
  padding-bottom: 20px;
}

/* Fieldset styling inside new layout */
body[data-page="form"].form-app-layout fieldset {
  background-color: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  margin-bottom: 8px;
  box-shadow: none;
}

body[data-page="form"].form-app-layout fieldset+fieldset {
  border-top: 1px solid var(--fa-border);
  padding-top: 20px;
  margin-top: 12px;
}

body[data-page="form"].form-app-layout legend {
  font-size: 1.1em;
  color: var(--fa-primary);
  padding: 0;
  margin-bottom: 16px;
}

/* Input styling upgrade */
body[data-page="form"].form-app-layout input[type="text"],
body[data-page="form"].form-app-layout input[type="date"],
body[data-page="form"].form-app-layout input[type="number"],
body[data-page="form"].form-app-layout input[type="email"],
body[data-page="form"].form-app-layout select,
body[data-page="form"].form-app-layout textarea {
  border-color: var(--fa-border);
  border-radius: var(--fa-radius-md);
  padding: 10px 14px;
  font-size: 0.9375rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

body[data-page="form"].form-app-layout input:hover,
body[data-page="form"].form-app-layout select:hover,
body[data-page="form"].form-app-layout textarea:hover {
  border-color: #CBD5E0;
}

body[data-page="form"].form-app-layout input:focus,
body[data-page="form"].form-app-layout select:focus,
body[data-page="form"].form-app-layout textarea:focus {
  outline: none;
  border-color: var(--fa-primary);
  box-shadow: 0 0 0 3px rgba(45, 90, 135, 0.1);
}

body[data-page="form"].form-app-layout label {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--fa-text-dark);
}

/* Preview zone adjustments */
body[data-page="form"].form-app-layout #previewZone {
  padding: 0 20px;
}

/* Invalid session message */
body[data-page="form"].form-app-layout #invalidSessionMessage {
  margin: 20px auto;
}


/* ===== 6. MOBILE RESPONSIVE ===== */

/* Tablet: collapse sidebar, show mobile toggle */
@media (max-width: 1024px) {
  .form-app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1000;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);
  }

  .form-app-sidebar.mobile-open {
    transform: translateX(0);
  }

  .form-app-footer {
    left: 0;
    width: 100%;
    padding: 0 max(16px, calc((100vw - 860px) / 2));
  }

  .form-app-canvas {
    padding: 20px 16px;
    padding-bottom: calc(var(--fa-footer-height) + 20px);
  }

  .form-app-card-body {
    padding: 24px 20px;
  }

  .form-app-topbar {
    padding: 0 16px;
  }
}

/* Mobile sidebar overlay */
.form-app-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s;
}

.form-app-sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* Mobile sidebar toggle button */
.form-app-sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--fa-radius-sm);
  color: var(--fa-text-dark);
  transition: background-color 0.2s;
}

.form-app-sidebar-toggle:hover {
  background-color: #F1F3F5;
}

.form-app-sidebar-toggle svg {
  width: 22px;
  height: 22px;
}

@media (max-width: 1024px) {
  .form-app-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Tablet Footer Optimization */
@media (max-width: 768px) {
  .form-app-footer {
    padding: 0 max(12px, calc((100vw - 860px) / 2));
    gap: 10px;
  }

  .footer-group {
    gap: 8px;
    flex: 1;
  }

  .fa-btn {
    padding: 0 12px;
    font-size: 0.8125rem;
    flex: 1;
    justify-content: center;
  }
}

/* Mobile Footer Optimization (Premium Look) */
@media (max-width: 580px) {
  .form-app-footer {
    height: 80px;
    padding: 0 max(8px, calc((100vw - 860px) / 2));
    gap: 4px;
    justify-content: space-around;
  }

  .footer-group {
    gap: 4px;
    flex: 1;
    justify-content: center;
  }

  .fa-btn {
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    height: 60px !important;
    padding: 4px !important;
    font-size: 0.625rem !important;
    gap: 2px !important;
    border: none !important;
    background: transparent !important;
    flex: 1 !important;
    min-width: 0 !important;
  }

  .fa-btn:hover {
    background-color: rgba(0, 0, 0, 0.03);
  }

  .fa-btn-primary {
    background-color: var(--fa-primary) !important;
    color: white !important;
    border-radius: 12px !important;
    box-shadow: 0 4px 10px rgba(45, 90, 135, 0.25) !important;
    height: 68px !important;
    padding: 8px 4px !important;
  }

  .fa-btn-secondary,
  .fa-btn-outline {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: var(--fa-text-muted);
  }

  .fa-btn svg {
    width: 22px;
    height: 22px;
    margin: 0;
  }

  .fa-btn .btn-label {
    display: block !important;
    font-size: 0.625rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
}

/* Small mobile & specific UI tweaks */
@media (max-width: 480px) {
  .form-app-canvas {
    padding: 12px 10px;
    padding-bottom: calc(var(--fa-footer-height) + 16px);
  }

  .form-app-card-body {
    padding: 20px 16px;
  }

  .topbar-title {
    font-size: 0.875rem;
  }

  .topbar-autosave {
    display: none;
  }
}

@media (max-width: 360px) {
  .fa-btn .btn-label {
    font-size: 0.55rem;
  }

  .fa-btn {
    padding: 8px 2px;
  }
}

/* ===== 7. SMOOTH TRANSITIONS ===== */

/* Animate fieldset appearance */
body[data-page="form"].form-app-layout fieldset[data-wizard-step] {
  animation: formAppFadeIn 0.35s ease;
}

@keyframes formAppFadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== SPLIT SCREEN PREVIEW (DESKTOP ONLY) ===== */
@media (min-width: 1200px) {
  body[data-page="form"].form-app-layout.split-screen-active .form-app-canvas {
    padding-left: 30px !important;
    padding-right: 40px !important;
    /* Slightly larger to ensure visual balance */
    overflow-y: hidden;
  }

  body[data-page="form"].form-app-layout.split-screen-active .form-app-canvas-inner {
    max-width: 100% !important;
    padding: 0;
    transition: max-width 0.4s ease, padding 0.4s ease;
  }

  body[data-page="form"].form-app-layout.split-screen-active .form-app-card {
    background: transparent;
    border: none;
    box-shadow: none;
    transition: all 0.4s ease;
  }

  body[data-page="form"].form-app-layout.split-screen-active .form-app-card-body {
    padding: 10px 0 0 0;
    display: flex;
    flex-direction: row;
    gap: 10px;
    /* Reduced from 30px to save space */
    align-items: flex-start;
  }

  body[data-page="form"].form-app-layout.split-screen-active .main-form-wrapper {
    flex: 0 0 calc(45% - 5px);
    /* Half of 10px gap */
    max-width: calc(45% - 5px);
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--fa-topbar-height) - var(--fa-footer-height) - 58px);
    overflow-y: auto;
    padding-right: 15px;
    /* Prevent scrollbar overlapping */
    padding-bottom: 20px;
    /* Space at bottom */
  }

  body[data-page="form"].form-app-layout.split-screen-active #mainForm {
    width: 100%;
  }

body[data-page="form"].form-app-layout.split-screen-active #previewZone {
    display: block !important;
    flex: 0 0 calc(55% - 5px);
    /* Half of 10px gap */
    max-width: calc(55% - 5px);
    height: calc(100vh - var(--fa-topbar-height) - var(--fa-footer-height) - 38px);
    overflow-y: auto;
    background: #f1f5f9;
    padding: 20px;
    padding-bottom: calc(var(--fa-footer-height) + 28px);
    border-radius: 12px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    margin-top: 0;
  }

  body[data-page="form"].form-app-layout.split-screen-active #previewTitle {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    font-size: 18px;
    margin-bottom: 15px;
  }

  body[data-page="form"].form-app-layout.split-screen-active #backButton {
    display: none !important;
  }

  .split-screen-close-btn {
    background: #e2e8f0;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #475569;
    transition: background 0.2s;
  }

  .split-screen-close-btn:hover {
    background: #cbd5e1;
    color: #0f172a;
  }

  body[data-page="form"].form-app-layout.split-screen-active #pdfPreviewContainer canvas {
    max-width: 100% !important;
    height: auto !important;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }

  /* Keep footer visible and align buttons with form in split screen mode */
  body[data-page="form"].form-app-layout.split-screen-active .form-app-footer {
    display: flex !important;
    height: calc(var(--fa-footer-height) + 1px) !important;
    min-height: calc(var(--fa-footer-height) + 1px) !important;
    padding-left: 30px !important;
    padding-right: calc((100vw - var(--fa-sidebar-width)) - 30px - ((100vw - var(--fa-sidebar-width) - 70px) * 0.45 - 5px)) !important;
    background: transparent !important;
    border-top-color: transparent !important;
    box-shadow: none !important;
    pointer-events: none;
  }

  body[data-page="form"].form-app-layout.split-screen-active .form-app-footer::before {
    content: "";
    position: absolute;
    top: -1px;
    left: 0;
    bottom: 0;
    width: calc(30px + ((100vw - var(--fa-sidebar-width) - 70px) * 0.45 - 5px) + 25px);
    /* Extended 20px further right */
    background-color: var(--fa-card-white);
    border-top: 1px solid var(--fa-border);
    box-shadow: 0 -3px 10px rgba(0, 0, 0, 0.03);
    z-index: -1;
    pointer-events: auto;
  }

  body[data-page="form"].form-app-layout.split-screen-active .form-app-footer .footer-group {
    pointer-events: auto;
  }

  /* Responsive fixes for medium/large screens (1200px - 1550px) */
  @media (max-width: 1655px) {
    body[data-page="form"].form-app-layout.split-screen-active .form-app-footer .fa-btn {
      padding: 6px 10px;
      font-size: 13px;
    }

    body[data-page="form"].form-app-layout.split-screen-active .form-app-footer .footer-group {
      gap: 6px;
    }

    body[data-page="form"].form-app-layout.split-screen-active #formAppSaveBtn .btn-label {
      display: none;
    }

    body[data-page="form"].form-app-layout.split-screen-active #formAppSaveBtn svg {
      margin-right: 0 !important;
    }
  }

  /* === LIVE PREVIEW STATUS BAR === */
  .live-preview-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 12px;
    font-family: var(--fa-font);
    font-size: 0.8125rem;
    color: #475569;
    transition: background 0.2s, border-color 0.2s;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .live-preview-status.has-changes {
    background: #fffbeb;
    border-color: #fbbf24;
  }

  .live-preview-status.rendering {
    background: #eff6ff;
    border-color: #93c5fd;
  }

  .live-preview-status-left {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .live-preview-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    flex-shrink: 0;
    transition: background 0.2s;
  }

  .live-preview-status.has-changes .live-preview-dot {
    background: #f59e0b;
    animation: dotPulse 1.5s ease-in-out infinite;
  }

  .live-preview-status.rendering .live-preview-dot {
    background: #3b82f6;
    animation: dotSpin 0.8s linear infinite;
  }

  @keyframes dotPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
  }

  @keyframes dotSpin {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.7); }
  }

  .live-preview-status-text {
    font-weight: 500;
    white-space: nowrap;
  }

  .live-preview-countdown {
    font-variant-numeric: tabular-nums;
    min-width: 20px;
  }

  .live-preview-refresh-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--fa-font);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--fa-primary);
    transition: all 0.15s;
    white-space: nowrap;
  }

  .live-preview-refresh-btn:hover:not(:disabled) {
    background: var(--fa-primary);
    color: white;
    border-color: var(--fa-primary);
  }

  .live-preview-refresh-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .live-preview-refresh-btn svg {
    width: 14px;
    height: 14px;
  }
}

/* === INLINE PAYMENT (split-screen) === */
.inline-payment-wrapper {
  display: none;
  overflow-y: auto;
  box-sizing: border-box;
}

body[data-page="form"].form-app-layout.split-screen-active.inline-payment-active .main-form-wrapper {
  display: none !important;
}

body[data-page="form"].form-app-layout.split-screen-active.inline-payment-active .form-app-stepper {
  display: none !important;
}

/* Hide all existing footer buttons, keep footer bar for the back button */
body[data-page="form"].form-app-layout.split-screen-active.inline-payment-active .form-app-footer .footer-group {
  display: none !important;
}

/* Show the inline payment back footer */
body[data-page="form"].form-app-layout.split-screen-active.inline-payment-active .form-app-footer .inline-payment-footer-back {
  display: flex !important;
}

body[data-page="form"].form-app-layout.split-screen-active.inline-payment-active .inline-payment-wrapper {
  display: block !important;
  flex: 0 0 calc(45% + 10px);
  max-width: calc(45% + 10px);
  height: calc(100vh - var(--fa-topbar-height) - var(--fa-footer-height) - 58px);
  overflow-y: auto;
  padding: 10px 15px 20px 0;
  animation: inlinePaymentFadeIn 0.25s ease-out;
}

@keyframes inlinePaymentFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Fade back to form */
.main-form-wrapper.fade-back-in {
  animation: formFadeBackIn 0.25s ease-out;
}

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

/* Hide close button (X) when modal content is inline */
body.inline-payment-active #paymentModalContent #closeModal {
  display: none !important;
}

/* Override modal content styles when inline */
body.inline-payment-active #inlinePaymentContent #paymentModalContent {
  position: static;
  width: 100%;
  max-width: 100% !important;
  max-height: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  background: transparent;
  overflow: visible;
}

body.inline-payment-active #inlinePaymentContent #paymentModal {
  position: static !important;
  display: block !important;
  background: transparent !important;
  padding: 0 !important;
  overflow: visible !important;
}

.inline-payment-back-btn {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  margin-bottom: 20px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--fa-font);
  font-size: 0.8125rem;
  font-weight: 600;
  color: #475569;
  transition: all 0.15s;
}

.inline-payment-back-btn:hover {
  background: #e2e8f0;
  color: #1e293b;
}

/* Footer "Back to form" button (hidden by default) */
.inline-payment-footer-back {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px 0;
}

.inline-payment-footer-back button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--fa-font);
  font-size: 0.875rem;
  font-weight: 600;
  color: #475569;
  transition: all 0.15s;
  pointer-events: auto;
}

.inline-payment-footer-back button:hover {
  background: #e2e8f0;
  color: #1e293b;
}

/* Darken preview area when inline payment is active — focus user on payment decision */
body[data-page="form"].form-app-layout.split-screen-active.inline-payment-active #previewZone {
  opacity: 0.55;
  filter: grayscale(0.4);
  pointer-events: none;
  user-select: none;
  transition: opacity 0.35s ease, filter 0.35s ease;
}

/* When user goes back to form, restore preview */
body[data-page="form"].form-app-layout.split-screen-active:not(.inline-payment-active) #previewZone {
  opacity: 1;
  filter: none;
  pointer-events: auto;
  user-select: auto;
  transition: opacity 0.35s ease, filter 0.35s ease;
}

/* ===== 8. PREVIEW MODE STYLES ===== */
/* Higher specificity to ensure footer is hidden */
body[data-page="form"].form-app-layout.preview-active .form-app-footer {
  display: none !important;
}

body[data-page="form"].form-app-layout.preview-active .form-app-canvas {
  display: block !important;
  /* Switch from flex to block for reliable scrolling */
  overflow-y: auto !important;
  height: calc(100vh - var(--fa-topbar-height));
}

body[data-page="form"].form-app-layout.preview-active .form-app-canvas-inner {
  max-width: 900px;
  margin: 0 auto;
  display: block;
}

body[data-page="form"].form-app-layout.preview-active .form-app-card {
  overflow: visible !important;
  margin-bottom: 0;
}

body[data-page="form"].form-app-layout.preview-active .form-app-card-body {
  overflow: visible !important;
  padding: 0;
}

body[data-page="form"].form-app-layout.preview-active .form-app-section-label,
body[data-page="form"].form-app-layout.preview-active .form-app-section-title {
  display: none;
}

body[data-page="form"].form-app-layout.preview-active #previewZone {
  margin-top: 0;
  padding: 0;
}

body[data-page="form"].form-app-layout.preview-active #pdfPreviewContainer {
  padding: 0;
  gap: 0;
}

body[data-page="form"].form-app-layout.preview-active #pdfPreviewContainer canvas {
  max-width: 100% !important;
  height: auto !important;
  border-radius: 0;
  border: none;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.08),
    0 4px 12px rgba(0, 0, 0, 0.06);
  margin-bottom: 24px;
}

body[data-page="form"].form-app-layout.preview-active #pdfPreviewContainer canvas:last-child {
  margin-bottom: 0;
}

/* Preview action buttons container - Sticky at bottom of canvas, styled like a premium footer */
.preview-actions-container {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 40px 0 0 0;
  flex-wrap: wrap;
  padding: 16px 40px;
  background: white;
  border-top: 1px solid var(--fa-border);
  border-radius: 0 0 var(--fa-radius-lg) var(--fa-radius-lg);
  position: sticky;
  bottom: 0;
  z-index: 10;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.03);
  width: 100%;
  box-sizing: border-box;
  transition: all 0.2s ease;
}

/* Split-screen layout specific styling: Dock buttons at bottom of right preview panel */
body[data-page="form"].form-app-layout.split-screen-active .preview-actions-container {
  position: fixed !important;
  left: calc(var(--fa-sidebar-width) + 30px + ((100vw - var(--fa-sidebar-width) - 70px) * 0.45) + 20px) !important;
  right: 0 !important;
  bottom: 0 !important;
  height: calc(var(--fa-footer-height) + 1px) !important;
  min-height: calc(var(--fa-footer-height) + 1px) !important;
  margin: 0 !important;
  padding: 0 28px !important;
  background: var(--fa-card-white) !important;
  border-top: 1px solid var(--fa-border) !important;
  border-left: 1px solid var(--fa-border) !important;
  border-radius: 0 !important;
  box-shadow: 0 -3px 10px rgba(0, 0, 0, 0.03) !important;
  z-index: 101 !important;
  width: auto !important;
  box-sizing: border-box !important;
  align-items: center !important;
  justify-content: center !important;
  flex-wrap: nowrap !important;
}

/* Ensure right PDF container has padding so we can scroll past sticky footer */
body[data-page="form"].form-app-layout.split-screen-active #pdfPreviewContainer {
  padding-bottom: 24px !important;
}

/* Also add padding-bottom to full-screen preview container */
body[data-page="form"].form-app-layout.preview-active #pdfPreviewContainer {
  padding-bottom: 40px !important;
}

.preview-action-btn {
  height: 46px;
  padding: 0 24px;
  font-family: var(--fa-font);
  font-size: 0.9375rem;
  font-weight: 600;
  border-radius: var(--fa-radius-md);
  cursor: pointer;
  border: 1px solid var(--fa-border);
  background-color: #f8fafc;
  color: var(--fa-text-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.preview-action-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: block;
  stroke: currentColor;
}

.preview-action-btn:hover {
  background-color: #f1f5f9;
  border-color: #cbd5e1;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.preview-action-btn.primary {
  background-color: var(--fa-primary);
  border: none;
  color: white;
}

.preview-action-btn.primary:hover {
  background-color: var(--fa-primary-hover);
  box-shadow: 0 6px 15px rgba(45, 90, 135, 0.25);
}

/* PDF canvas styling - Professional Look */
#pdfPreviewContainer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 10px 0;
}

#pdfPreviewContainer canvas {
  max-width: 100% !important;
  height: auto !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  border: 1px solid #d1d5db;
}

/* Ensure preview notice is premium */
body[data-page="form"].form-app-layout #previewNotice {
  border-radius: var(--fa-radius-md) !important;
  border: none !important;
  box-shadow: inset 4px 0 0 var(--fa-primary);
  padding: 18px 24px !important;
  font-size: 0.95rem !important;
  line-height: 1.6 !important;
  margin-bottom: 24px !important;
  background-color: #f0f7ff !important;
}

body[data-page="form"].form-app-layout #previewReportNotice {
  border-radius: var(--fa-radius-md) !important;
  border: none !important;
  box-shadow: inset 4px 0 0 #ef4444;
  padding: 18px 24px !important;
  font-size: 0.95rem !important;
  line-height: 1.6 !important;
  margin-bottom: 24px !important;
  background-color: #fef2f2 !important;
}

/* Mobile preview buttons - Horizontal row */
@media (max-width: 640px) {
  .preview-actions-container {
    flex-direction: row !important;
    gap: 8px !important;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom)) !important;
    position: fixed !important;
    bottom: calc(var(--fv-browser-bottom-inset, 0px) + 10px) !important;
    left: 12px !important;
    right: 12px !important;
    margin: 0 !important;
    background: white !important;
    border: 1px solid rgba(226, 232, 240, 0.95) !important;
    box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.12) !important;
    z-index: 1000 !important;
    border-radius: 14px !important;
    max-width: calc(100vw - 24px) !important;
    box-sizing: border-box !important;
  }

  /* Add padding-bottom to the scrollable canvas so elements aren't hidden behind the fixed bottom bar */
  body[data-page="form"].form-app-layout.preview-active .form-app-canvas {
    padding-bottom: calc(300px + var(--fv-browser-bottom-inset, 0px) + env(safe-area-inset-bottom)) !important;
  }

  body[data-page="form"].form-app-layout.preview-active #previewZone {
    padding-bottom: calc(150px + var(--fv-browser-bottom-inset, 0px) + env(safe-area-inset-bottom)) !important;
  }

  .preview-action-btn {
    flex: 1 !important;
    width: auto !important;
    padding: 8px 4px !important;
    font-size: 0.65rem !important;
    height: 72px !important;
    flex-direction: column !important;
    gap: 6px !important;
    line-height: 1.2 !important;
    text-align: center !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    white-space: normal !important;
  }

  .preview-action-btn svg {
    width: 24px !important;
    height: 24px !important;
    margin: 0 0 2px 0 !important;
    display: block !important;
  }

  .preview-action-btn span {
    display: block !important;
    width: 100% !important;
  }
}

@media (max-width: 400px) {
  .preview-action-btn {
    font-size: 0.65rem;
    gap: 2px;
  }
}

/* 3-Tier Freemium PDF Preview blur styles */
.pdf-page-wrapper {
  position: relative;
  display: block;
  width: 100%;
}

.preview-blur-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(255, 255, 255, 0.45);
  z-index: 5;
  pointer-events: none;
}

.preview-blur-overlay span {
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--fa-radius-lg);
  font-family: var(--fa-font);
  font-size: 0.9375rem;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  pointer-events: auto;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  user-select: none;
}

.preview-blur-overlay span:hover {
  background: rgba(30, 48, 70, 0.92);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

.preview-blur-overlay span:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
