/**
 * File: framework/gutenberg/assets/editor.css
 * Title: 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 Engine > Main Editor
 */

/* --- 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 Structured Content & Style-Safe Editor Modal --- */

.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-canvas-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 32px;
  background: #ffffff;
}

.cts-wysiwyg-mode-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.cts-wysiwyg-mode-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cts-wysiwyg-mode-hint {
  font-size: 12px;
  color: #64748b;
}

.cts-structured-editor-canvas {
  background: #f1f5f9;
  padding: 20px 24px;
  cursor: default;
}

.cts-structured-blocks-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 820px;
  margin: 0 auto;
}

.cts-structured-block-card {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.cts-structured-block-card.is-type-callout {
  border-left: 4px solid #0284c7;
}

.cts-structured-block-card.is-type-code {
  border-left: 4px solid #475569;
}

.cts-structured-block-card.is-type-heading {
  border-left: 4px solid #6366f1;
}

.cts-structured-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f1f5f9;
}

.cts-structured-block-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #334155;
  background: #f1f5f9;
  padding: 3px 8px;
  border-radius: 4px;
}

.cts-structured-block-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.cts-structured-grid-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
}

.cts-structured-add-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  background: #ffffff;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  margin-top: 4px;
}

.cts-structured-add-bar .components-base-control {
  margin-bottom: 0 !important;
}

.cts-structured-add-bar .components-base-control__field {
  margin-bottom: 0 !important;
}

.cts-raw-html-editor-wrap {
  max-width: 820px;
  margin: 0 auto;
}

/* Light-Mode Monospace Code & Raw HTML Textareas */
.cts-light-code-textarea textarea.components-textarea-control__input {
  font-family: 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace !important;
  font-size: 12.5px !important;
  line-height: 1.6 !important;
  background-color: #f8fafc !important;
  color: #0f172a !important;
  border: 1px solid #cbd5e1 !important;
  border-radius: 6px !important;
  padding: 12px 14px !important;
  tab-size: 2;
}

.cts-light-code-textarea textarea.components-textarea-control__input:focus {
  background-color: #ffffff !important;
  border-color: var(--wp-admin-theme-color, #007cba) !important;
  box-shadow: 0 0 0 1px var(--wp-admin-theme-color, #007cba) !important;
}

/* Scoped Mini-Tiptap Rich-Text Field inside Structured Cards */
.cts-mini-richtext-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.cts-mini-richtext-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  color: #1e1e1e;
  display: block;
}

.cts-mini-richtext-box {
  border: 1px solid #949494;
  border-radius: 4px;
  background: #ffffff;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.cts-mini-richtext-box:focus-within {
  border-color: var(--wp-admin-theme-color, #007cba);
  box-shadow: 0 0 0 1px var(--wp-admin-theme-color, #007cba);
}

.cts-mini-richtext-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.cts-mini-rt-sep {
  width: 1px;
  height: 18px;
  background: #cbd5e1;
  margin: 0 4px;
}

.cts-mini-rt-btn.components-button {
  min-width: 28px !important;
  width: 28px !important;
  height: 28px !important;
  padding: 0 !important;
  border-radius: 4px !important;
  color: #475569 !important;
  justify-content: center;
}

.cts-mini-rt-btn.components-button:hover {
  background: #e2e8f0 !important;
  color: #0f172a !important;
}

.cts-mini-rt-btn.components-button.is-active {
  background: var(--wp-admin-theme-color, #007cba) !important;
  color: #ffffff !important;
}

.cts-mini-richtext-canvas {
  padding: 10px 12px;
  min-height: 64px;
  cursor: text;
}

.cts-mini-richtext-canvas .tiptap.ProseMirror {
  outline: none;
  min-height: 44px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: #1e293b;
}

.cts-mini-richtext-canvas .tiptap.ProseMirror p {
  margin: 0 0 0.6em 0;
}

.cts-mini-richtext-canvas .tiptap.ProseMirror p:last-child {
  margin-bottom: 0;
}

.cts-mini-richtext-canvas .tiptap.ProseMirror code {
  font-family: 'Roboto Mono', monospace;
  font-size: 12.5px;
  background: #f1f5f9;
  color: #0f172a;
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
}

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

.cts-mini-richtext-canvas .tiptap.ProseMirror ul,
.cts-mini-richtext-canvas .tiptap.ProseMirror ol {
  margin: 0;
  padding-left: 20px;
}

.cts-mini-richtext-canvas .tiptap.ProseMirror li {
  margin-bottom: 4px;
}

.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;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.cts-preset-save-btn.components-button,
.cts-preset-edit-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;
  text-decoration: none !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;
}

/* --- 10.0 Actions Inspector Panel --- */

.cts-action-field {
  margin-bottom: 16px;
}

.cts-action-field:last-child {
  margin-bottom: 0;
}

.cts-action-field-btn.components-button {
  width: 100%;
  justify-content: center;
  margin-top: 8px;
}

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