/**
 * File: framework/gutenberg/assets/editor.css
 * Conpacts Framework: Native Gutenberg Editor Styles
 *
 * Specific styles for the Conturalis Gutenberg integration.
 * Includes custom UI tweaks, component presets, and the Shortcode Generator UI.
 *
 * @package Conturalis
 * @subpackage Conpacts WP Engine
 */

/* --- 0.0 Admin UI Tokens --- */
/* 
 * We cannot use our standard admin tokens natively in Gutenberg because the 
 * editor iframe strictly encapsulates styles and prevents inheritance from the 
 * WordPress dashboard :root. Therefore, we hardcode them here scoped to the 
 * editor wrappers to ensure consistent UI for badges, tools, and presets.
 */
:root, .editor-styles-wrapper {
    --cts-admin-color-success-bg:     #f0fdf4;
    --cts-admin-color-success-border: #bbf7d0;
    --cts-admin-color-success-text:   #166534;

    --cts-admin-color-warning-bg:     #fffbeb;
    --cts-admin-color-warning-border: #fde68a;
    --cts-admin-color-warning-text:   #92400e;

    --cts-admin-color-danger-bg:      #fef2f2;
    --cts-admin-color-danger-border:  #fecaca;
    --cts-admin-color-danger-text:    #991b1b;

    --cts-admin-color-info-bg:        #e3f2fd;
    --cts-admin-color-info-border:    #bbdefb;
    --cts-admin-color-info-text:      #1565C0;

    --cts-admin-color-accent-bg:      #f3e5f5;
    --cts-admin-color-accent-border:  #e1bee7;
    --cts-admin-color-accent-text:    #7B1FA2;

    --cts-admin-color-dark-bg:        #0f172a;  /* Slate-900 */
    --cts-admin-color-dark-surface:   #1e293b;  /* Slate-800 */
    --cts-admin-color-dark-border:    #334155;  /* Slate-700 */
    --cts-admin-color-dark-text:      #e2e8f0;  /* Slate-200 */
    --cts-admin-color-dark-muted:     #94a3b8;  /* Slate-400 */
}

/* --- 1.0 Custom Icons --- */

.dashicons-cts-cat-logo, 
.dashicons-cts-shortcode-logo {
    background-color: currentColor !important;
    -webkit-mask-repeat: no-repeat !important; 
    mask-repeat: no-repeat !important;
    -webkit-mask-position: center !important; 
    mask-position: center !important;
    -webkit-mask-size: contain !important; 
    mask-size: contain !important;
    width: 20px !important; 
    height: 20px !important;
}

.dashicons-cts-cat-logo { 
    -webkit-mask-image: url('../../assets/media/Logo-Icon_SVG.svg') !important; 
    mask-image: url('../../assets/media/Logo-Icon_SVG.svg') !important; 
}

.dashicons-cts-shortcode-logo { 
    -webkit-mask-image: url('../../assets/media/Conturalis-shortcode-logo.svg') !important; 
    mask-image: url('../../assets/media/Conturalis-shortcode-logo.svg') !important; 
}

.dashicons-cts-cat-logo::before, 
.dashicons-cts-shortcode-logo::before { 
    display: none !important; 
}

/* --- 2.0 Preset Editor UI Tweaks --- */

/* Hide draft button but keep Publish/Update visible on Preset Canvas */
body.post-type-cts_component_preset .components-button.editor-post-save-draft {
    display: none !important;
}

/* Hide the native Gutenberg title block on the canvas to prevent focus hijacking.
   Users can still rename the preset via the top bar or document settings menu. */
body.post-type-cts_component_preset .edit-post-visual-editor__post-title-wrapper {
    display: none !important;
}

/* Add spacing to the top of the canvas so the component isn't cramped against the toolbar */
body.post-type-cts_component_preset .is-root-container,
body.post-type-cts_component_preset .block-editor-block-list__layout {
    padding-top: 48px !important;
}

/* --- 3.0 Style Preset Warning & Dimming --- */

.cts-style-warning-msg {
    display: none;
    background: #fff3cd;
    color: #856404;
    border-left: 4px solid #ffeeba;
    padding: 12px 16px;
    margin-bottom: 20px;
    border-radius: 4px;
    font-size: 13px;
}

/* Activate CSS when React adds body class */
body.cts-is-style-preset .cts-style-warning-msg {
    display: block !important;
}

/* --- 4.0 Info Notices --- */

.cts-info-notice-msg {
    display: block;
    background: #e3f2fd;
    color: #1565C0;
    border-left: 4px solid #bbdefb;
    padding: 12px 16px;
    margin-bottom: 20px;
    border-radius: 4px;
    font-size: 13px;
    line-height: 1.4;
}

.cts-inspector-notice-inner {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cts-inspector-notice-row-1 {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cts-inspector-notice-row-2 {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

/* --- 5.0 Shortcode Preview Styles (Dev Tools) --- */

.cts-sc-container {
    margin-top: 15px;
    margin-bottom: 5px;
    position: relative;
}

.cts-sc-btn {
    width: 100%;
    display: block;
    text-align: center;
}

.cts-sc-results-area {
    margin-top: 15px;
}

.cts-sc-item {
    position: relative;
    margin-bottom: 16px;
}

.cts-sc-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: #8c8f94;
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}

.cts-sc-box {
    background: #26292c;
    color: #81d29d;
    border: 1px solid #404349;
    padding: 10px;
    border-radius: 4px;
    font-family: 'Roboto Mono', monospace;
    font-size: 11px;
    line-height: 1.4;
    word-break: break-all;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 36px;
    user-select: none;
    margin: 0;
}

.cts-sc-box:hover {
    background: #2e3236;
    border-color: #556068;
}

.cts-sc-box:active {
    background: #202326;
}

.cts-sc-toast {
    position: absolute;
    top: -20px;
    right: 0;
    background: #46b450;
    color: #fff;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transform: translateY(5px);
    transition: all 0.2s ease;
    z-index: 10;
}

.cts-sc-toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* --- 6.0 Preview Warning Banners --- */

.cts-preview-warning-banner {
    background: var(--cts-admin-color-warning-bg);
    color: var(--cts-admin-color-warning-text);
    border-left: 4px solid var(--cts-admin-color-warning-border);
    padding: 12px 16px;
    margin-bottom: 20px;
    border-radius: 4px;
    font-size: 13px;
    line-height: 1.4;
}

.cts-preview-warning-banner strong {
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* --- 7.0 Expanded Editor Modal --- */

.cts-expanded-editor-modal {
    max-width: 900px !important;
    width: 90vw !important;
    height: 85vh !important;
    max-height: 850px !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

.cts-expanded-editor-modal .components-modal__header {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    flex-shrink: 0 !important;
    margin: 0 !important;
    padding: 14px 24px !important;
    border-bottom: 1px solid #e2e8f0 !important;
    background: #ffffff !important;
    box-sizing: border-box !important;
}

.cts-expanded-editor-modal .components-modal__content {
    flex: 1 1 auto !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 0 !important;
    margin: 0 !important;
    height: 100% !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

/* Target Gutenberg's unclassed wrapper <div> around modal children */
.cts-expanded-editor-modal .components-modal__content > :not(.components-modal__header) {
    flex: 1 1 auto !important;
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

.cts-expanded-editor-content img {
    max-width: 100% !important;
    height: auto !important;
    border-radius: 4px;
    display: block;
    margin: 16px auto;
    cursor: pointer;
    transition: outline 0.2s ease;
}
.cts-expanded-editor-content img:hover {
    outline: 3px solid var(--wp-admin-theme-color, #007cba);
}

/* --- 8.0 Smart Layout & AI Canvas Styles --- */

body.post-type-cts_smart_layout .components-button.editor-post-save-draft {
    display: none !important;
}

body.post-type-cts_smart_layout .is-root-container,
body.post-type-cts_smart_layout .block-editor-block-list__layout {
    padding-top: 32px !important;
}

.cts-smart-canvas-block {
    cursor: default;
    user-select: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.cts-smart-canvas-block:hover {
    border-color: #7B1FA2 !important;
    box-shadow: 0 2px 8px rgba(123, 31, 162, 0.12);
}

/* --- CTS WYSIWYG Editor Modal & ProseMirror Canvas --- */

.cts-wysiwyg-modal-layout {
  display: flex !important;
  flex-direction: column !important;
  flex: 1 1 auto !important;
  height: 100% !important;
  min-height: 0 !important;
  width: 100% !important;
  box-sizing: border-box !important;
  background: #ffffff !important;
  overflow: hidden !important;
}

.cts-wysiwyg-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.cts-wysiwyg-toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.cts-wysiwyg-toolbar-divider {
  width: 1px;
  height: 20px;
  background: #cbd5e1;
  margin: 0 4px;
}

.cts-wysiwyg-toolbar-btn.components-button {
  min-width: 32px;
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: #475569;
}

.cts-wysiwyg-toolbar-btn.components-button:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.cts-wysiwyg-toolbar-btn.components-button.is-active,
.cts-wysiwyg-toolbar-btn.components-button.is-pressed {
  background: #007cba;
  color: #ffffff !important;
}

.cts-wysiwyg-canvas-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 32px;
  background: #ffffff;
  cursor: text;
}

.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror {
  min-height: 100%;
  outline: none;
  font-family: var(--cts-theme-font-sans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
  font-size: 16px;
  line-height: 1.6;
  color: #1e293b;
}

.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror p {
  margin: 0 0 1em 0;
}

.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror h1,
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror h2,
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror h3,
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror h4 {
  font-family: var(--cts-theme-font-headers, inherit);
  font-weight: 700;
  line-height: 1.25;
  margin: 1.25em 0 0.5em 0;
  color: #0f172a;
}

.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror h1:first-child,
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror h2:first-child,
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror h3:first-child,
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror h4:first-child,
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror p:first-child {
  margin-top: 0;
}

.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror h1 { font-size: 2em; }
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror h2 { font-size: 1.6em; }
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror h3 { font-size: 1.3em; }
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror h4 { font-size: 1.1em; }

.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror ul,
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror ol {
  padding-left: 24px;
  margin: 0 0 1em 0;
}

.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror ul {
  list-style-type: disc;
}

.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror ol {
  list-style-type: decimal;
}

.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror li {
  margin-bottom: 0.35em;
}

.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror blockquote {
  border-left: 3px solid #007cba;
  margin: 1em 0;
  padding-left: 16px;
  color: #64748b;
  font-style: italic;
}

.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror a {
  color: #007cba;
  text-decoration: underline;
}

.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 1em 0;
  cursor: pointer;
  border: 1px solid #e2e8f0;
  transition: box-shadow 0.2s ease;
}

.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror img:hover,
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror img.ProseMirror-selectednode {
  box-shadow: 0 0 0 3px #007cba;
}

/* Live Lead Paragraph in WYSIWYG Canvas */
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror .cts-lead-paragraph {
  font-size: 1.15em;
  line-height: 1.6;
  color: #1e293b;
}

/* Live Drop Cap in WYSIWYG Canvas */
.cts-wysiwyg-canvas-wrap .tiptap.ProseMirror .cts-drop-cap::first-letter {
  float: left;
  font-family: var(--cts-theme-font-headers, inherit);
  font-size: 3.5em;
  line-height: 0.8;
  font-weight: 700;
  margin-right: 0.1em;
  margin-bottom: -0.05em;
  color: var(--wp-admin-theme-color, #007cba);
  text-transform: uppercase;
}

.cts-wysiwyg-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
}

/* --- 9.0 Preset Selector Controls & In-Editor Save Modal --- */

.cts-preset-selector-row {
  margin-bottom: 16px;
}

.cts-preset-actions-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: 6px;
}

.cts-preset-save-btn.components-button {
  font-size: 11px !important;
  height: 28px !important;
  line-height: 26px !important;
  padding: 0 10px !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 4px !important;
  border-radius: 4px !important;
}

.cts-preset-save-modal {
  max-width: 480px !important;
  width: 90vw !important;
}

.cts-preset-save-modal .components-modal__content {
  padding: 20px 24px !important;
  overflow: visible !important;
}

.cts-preset-save-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #e2e8f0;
}

/* Force visibility of animated elements inside the Gutenberg and Elementor iframes */