/* Prevent Flash of Unstyled Content (FOUC) during page boot */
body.app-booting {
  background-color: #f8fafc !important;
  overflow: hidden !important;
}

body.app-booting header {
  height: 70px !important;
  min-height: 70px !important;
}

body.app-booting #site-footer {
  height: 52px !important;
  min-height: 52px !important;
  max-height: 52px !important;
}

body.app-booting header,
body.app-booting main,
body.app-booting #site-footer,
body.app-booting #auth-modal,
body.app-booting #auth-public-view {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.app-booting #app-loader {
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  background-color: var(--bg-color) !important;
  z-index: 4000 !important;
}

body.app-booting #boot-placeholder-layer {
  position: fixed !important;
  top: 70px !important;
  right: 0 !important;
  bottom: 52px !important;
  left: 0 !important;
  display: block !important;
  overflow: hidden !important;
  z-index: 850 !important;
}

@media (max-width: 480px) {
  body.app-booting #site-footer {
    height: 84px !important;
    min-height: 84px !important;
    max-height: 84px !important;
  }

  body.app-booting #boot-placeholder-layer {
    top: 70px !important;
    bottom: 84px !important;
  }
}

html[data-boot-session-hint="registered"] body.app-booting #open-auth-modal-btn {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

html[data-boot-session-hint="registered"] body.app-booting #controls {
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: none !important;
  transition: none !important;
}

html[data-boot-session-hint="registered"] body.app-booting #logout-btn,
html[data-boot-session-hint="registered"] body.app-booting #contributions-btn,
html[data-boot-session-hint="registered"] body.app-booting #posts-btn {
  display: inline-flex !important;
}

html[data-boot-session-hint="registered"][data-boot-role-hint="viewer"] body.app-booting #gallery-btn,
html[data-boot-session-hint="registered"][data-boot-role-hint="scholar"] body.app-booting #gallery-btn,
html[data-boot-session-hint="registered"][data-boot-role-hint="admin"] body.app-booting #gallery-btn,
html[data-boot-session-hint="registered"][data-boot-role-hint="founder"] body.app-booting #gallery-btn,
html[data-boot-session-hint="registered"][data-boot-role-hint="scholar"] body.app-booting #logs-btn,
html[data-boot-session-hint="registered"][data-boot-role-hint="admin"] body.app-booting #logs-btn,
html[data-boot-session-hint="registered"][data-boot-role-hint="founder"] body.app-booting #logs-btn,
html[data-boot-session-hint="registered"][data-boot-role-hint="admin"] body.app-booting #history-btn,
html[data-boot-session-hint="registered"][data-boot-role-hint="founder"] body.app-booting #history-btn,
html[data-boot-session-hint="registered"][data-boot-role-hint="admin"] body.app-booting #ai-proposals-btn,
html[data-boot-session-hint="registered"][data-boot-role-hint="founder"] body.app-booting #ai-proposals-btn,
html[data-boot-session-hint="registered"][data-boot-role-hint="founder"] body.app-booting #mr-toggle-btn,
html[data-boot-session-hint="registered"][data-boot-role-hint="founder"] body.app-booting #open-users-btn,
html[data-boot-session-hint="registered"][data-boot-role-hint="founder"] body.app-booting #test-health-btn {
  display: inline-flex !important;
}

html[data-boot-session-hint="registered"] body.app-booting .header-top-actions {
  display: none !important;
  width: 0 !important;
  min-width: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

body:not(.app-booting) #boot-placeholder-layer {
  display: none !important;
}

body.app-booting [data-boot-panel] {
  display: none !important;
}

html[data-boot-view="public"] body.app-booting [data-boot-panel="public"],
html[data-boot-view="tree"] body.app-booting [data-boot-panel="tree"],
html[data-boot-view="profile"] body.app-booting [data-boot-panel="profile"] {
  display: block !important;
  height: 100% !important;
}

/* Specific overrides for the Auth/Public landing surface */
html.boot-auth-surface body.app-booting {
  background-color: #0f172a !important;
  background-image: linear-gradient(rgba(15, 23, 42, 0.78), rgba(15, 23, 42, 0.68)), url('/background_login.jpg') !important;
  background-size: cover !important;
  background-position: center !important;
  background-attachment: fixed !important;
  --header-surface: linear-gradient(135deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.06)) !important;
  --header-border-color: rgba(255, 255, 255, 0.18) !important;
  --header-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08) !important;
  --header-backdrop-filter: blur(18px) saturate(145%) !important;
  --footer-surface: linear-gradient(135deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.06)) !important;
  --footer-border-color: rgba(255, 255, 255, 0.18) !important;
  --footer-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08) !important;
  --footer-backdrop-filter: blur(18px) saturate(145%) !important;
}

html.boot-auth-surface body.app-booting #app-loader {
  background-color: transparent !important;
}

/* Global utility to prevent FOUC of hidden elements before external CSS is parsed */
.hidden {
  display: none !important;
}

/* Surgical lint fixes: shifting inline styles to internal CSS */
.search-wrapper-relative { position: relative; }
.icon-violet { color: #8b5cf6 !important; }
.btn-admin-sm { width: 32px !important; height: 32px !important; padding: 0 !important; display: flex !important; align-items: center; justify-content: center; }
.btn-admin-sm span { font-size: 18px !important; }
.btn-delete-forever { color: #dc2626 !important; }
.info-header-flex { display: flex; align-items: center; gap: 10px; margin-bottom: 1rem; }
.info-header-title { margin: 0 !important; }

/* Stemma Section Classes */
.stemma-detail-card { max-width: 800px; margin: 0 auto; padding: 20px; text-align: center; background: white; min-height: 100%; box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1); }
.stemma-header-flex { display: flex; justify-content: flex-start; margin-bottom: 20px; }
.stemma-image-main { max-height: 300px; max-width: 100%; object-fit: contain; margin-bottom: 30px; filter: drop-shadow(0px 4px 8px rgba(0,0,0,0.2)); }
.stemma-title-main { font-size: 2rem; color: #1e293b; margin-bottom: 10px; }
.stemma-desc-main { font-size: 1.1rem; color: #475569; line-height: 1.6; max-width: 600px; margin: 0 auto; white-space: pre-wrap; }
.btn-stemma-edit { margin-top: 20px; display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; }
.stemma-edit-form { max-width: 600px; margin: 0 auto; text-align: left; }
.form-label-surgical { display: block; font-weight: 500; margin-bottom: 8px; color: #334155; }
.form-input-surgical { width: 100%; padding: 12px; margin-bottom: 20px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 1.1rem; box-sizing: border-box; }
.form-textarea-surgical { width: 100%; padding: 12px; margin-bottom: 20px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 1rem; resize: vertical; font-family: inherit; box-sizing: border-box; }
.form-actions-flex { display: flex; gap: 10px; justify-content: flex-end; }
.btn-form-cancel { padding: 10px 20px; border-radius: 8px; border: 1px solid #e2e8f0; background: white; cursor: pointer; font-weight: 500; color: #475569; }
.btn-form-save { padding: 10px 20px; border-radius: 8px; border: none; background: var(--primary-color, #3b82f6); color: white; cursor: pointer; font-weight: 500; }

/* AI Proposals Classes */
.proposals-main-container { width: 100%; margin: 0 auto; padding: 20px; box-sizing: border-box; text-align: left; background: transparent; }
.proposals-header-flex { display: flex; align-items: center; margin-bottom: 20px; gap: 12px; }
.proposals-title-main { margin: 0; font-family: var(--font-fancy); font-size: 2rem; }
.btn-outline-surgical { padding: 6px 10px; }
.btn-outline-surgical span { font-size: 20px; }
.btn-ai-scan { margin-left: auto; display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: #f8fafc; border: 1.5px solid #e2e8f0; border-radius: 10px; color: #475569; font-weight: 600; cursor: pointer; transition: all 0.2s; }
.btn-ai-scan span { font-size: 20px; }
.ai-scan-progress-box { display: flex; align-items: center; gap: 10px; margin-left: auto; background: #f1f5f9; padding: 8px 16px; border-radius: 10px; border: 1px solid #e2e8f0; }
.ai-scan-status-text { font-size: 0.85rem; color: #475569; font-weight: 500; }
.icon-spinner-sm { width: 16px; height: 16px; border-width: 2px; margin: 0; }
.icon-spinner-md { width: 32px; height: 32px; border-width: 3px; border-top-color: #94a3b8; border-bottom-color: rgba(148, 163, 184, 0.1); border-left-color: rgba(148, 163, 184, 0.1); border-right-color: rgba(148, 163, 184, 0.1); margin-right: 0; }
.proposals-grid-flex { display: flex; flex-direction: column; gap: 20px; padding-bottom: 40px; }
.proposals-loader-box { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; padding: 40px 0; }

/* Runtime section / template extraction classes */
.runtime-flex-gap-8 { display: flex; gap: 8px; }
.runtime-flex-gap-8 > .runtime-flex-1 { flex: 1; }
.runtime-flex-between-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.runtime-flex-between-top-sm { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; }
.runtime-flex-center { display: flex; align-items: center; }
.runtime-flex-1-min0 { flex: 1; min-width: 0; }
.runtime-hidden-input { display: none; }
.runtime-icon-18 { font-size: 18px !important; }
.runtime-icon-20 { font-size: 20px !important; }
.runtime-icon-32-primary { font-size: 32px; color: #4f46e5; }
.runtime-icon-no-pointer { pointer-events: none; }

.runtime-ai-header-main { display: flex; align-items: center; gap: 12px; flex: 1; }
.runtime-ai-back-btn { padding: 6px 10px; color: white; border-color: rgba(255, 255, 255, 0.3); }
.runtime-ai-upload-icon { font-size: 20px; }

.runtime-family-edit-card { margin-top: 10px; padding: 8px 0 0; border: none; border-top: 1px solid #f1f5f9; background: transparent; }
.runtime-family-edit-date-group { margin-bottom: 8px; }
.runtime-family-edit-place { width: 100%; box-sizing: border-box; margin-bottom: 8px; text-align: left !important; }
.runtime-family-edit-actions { display: flex; gap: 6px; justify-content: flex-end; }
.runtime-family-edit-btn { width: 30px; height: 30px; border-radius: 50%; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; transition: all 0.2s; }
.runtime-family-edit-btn-save { background: rgba(22, 163, 74, 0.1); color: #16a34a; }
.runtime-family-edit-btn-cancel { background: rgba(239, 68, 68, 0.1); color: #ef4444; }

.runtime-card-top-gap { margin-top: 20px; }
.runtime-muted-copy { font-size: 0.9rem; color: #666; }
.runtime-muted-copy-with-gap { font-size: 0.9rem; color: #666; margin-bottom: 10px; }
.runtime-session-icon { color: #64748b; font-size: 20px; }
.runtime-form-label-sm { display: block; font-size: 0.8rem; font-weight: 500; margin-bottom: 4px; }
.runtime-form-label-sm-wide { display: block; font-size: 0.8rem; font-weight: 500; margin-bottom: 6px; }
.runtime-form-control { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; margin-bottom: 10px; }
.runtime-upload-wrapper { margin-bottom: 15px; }
.runtime-file-name-display { font-weight: 600; color: #475569; }
.runtime-dropzone-hint { font-size: 0.75rem; color: #94a3b8; }
.runtime-submit-btn-full { width: 100%; height: 42px; border-radius: 8px !important; }
.runtime-send-icon { margin-right: 8px; }

.runtime-lb-tag-list { display: flex; flex-direction: column; gap: 12px; }
.runtime-lb-actions-grid { margin-top: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; flex-shrink: 0; }
.runtime-lb-search-panel { margin-top: 16px; border-top: 1px solid #f1f5f9; padding-top: 16px; flex-shrink: 0; }
.runtime-lb-search-input { width: 100%; padding: 8px; border: 1px solid #cbd5e1; border-radius: 6px; box-sizing: border-box; font-size: 0.9rem; }
.runtime-lb-results { max-height: 150px; overflow-y: auto; margin-top: 8px; border: 1px solid #e2e8f0; border-radius: 6px; background: white; display: none; }

.runtime-vh-row { display: flex; align-items: center; justify-content: space-between; padding: 12px; border-radius: 8px; margin-bottom: 6px; border: 1px solid #e2e8f0; transition: background 0.15s; }
.runtime-vh-action-label { font-size: 0.85rem; font-weight: 500; color: #334155; }
.runtime-vh-meta { font-size: 0.75rem; color: #64748b; margin-top: 2px; }
.runtime-vh-actions { display: flex; gap: 8px; }
.runtime-vh-restore-btn { padding: 8px; border-radius: 8px; border: 1px solid #e2e8f0; background: white; cursor: pointer; color: #3b82f6; }
