/**
 * description-templates.css
 * Listeo Description Templates — modal & button styles (v1.3.0)
 */

/* ================================================================
 *  BUTTON next to the TinyMCE editor
 * ================================================================ */
.ldt-template-btn-wrap {
  margin-top: 10px;
}

.ldt-template-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  color: #fff !important;
  background: #3e8ef7 !important;
  border: none !important;
  border-radius: 4px !important;
  cursor: pointer;
  transition: background 0.2s;
  line-height: 1.4 !important;
  height: auto !important;
}

.ldt-template-btn:hover,
.ldt-template-btn:focus {
  background: #2a6dd6 !important;
  color: #fff !important;
}

.ldt-template-btn .dashicons {
  font-size: 18px;
  width: 18px;
  height: 18px;
  line-height: 18px;
}

/* ================================================================
 *  OVERLAY
 * ================================================================ */
.ldt-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100050;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

body.ldt-modal-open {
  overflow: hidden !important;
}

/* ================================================================
 *  MODAL CONTAINER
 * ================================================================ */
.ldt-modal {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 820px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: ldtSlideUp 0.25s ease-out;
}

@keyframes ldtSlideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ================================================================
 *  HEADER
 * ================================================================ */
.ldt-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid #e5e7eb;
}

.ldt-modal-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: #1f2937;
}

.ldt-modal-close {
  background: none;
  border: none;
  font-size: 26px;
  color: #6b7280;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
}

.ldt-modal-close:hover {
  color: #1f2937;
}

/* ================================================================
 *  BODY (scrollable)
 * ================================================================ */
.ldt-modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

/* ================================================================
 *  FOOTER
 * ================================================================ */
.ldt-modal-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 0 0 8px 8px;
}

.ldt-footer-spacer {
  flex: 1;
}

.ldt-btn-cancel {
  color: #6b7280 !important;
}

.ldt-btn-insert {
  min-width: 120px;
}

/* ================================================================
 *  STEP 1: Template card grid
 * ================================================================ */
.ldt-template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.ldt-template-card {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.ldt-template-card:hover {
  border-color: #3e8ef7;
  box-shadow: 0 2px 10px rgba(62, 142, 247, 0.15);
}

.ldt-card-body {
  padding: 16px;
  flex: 1;
}

.ldt-card-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
}

.ldt-card-desc {
  margin: 0;
  font-size: 13px;
  color: #6b7280;
  line-height: 1.4;
}

.ldt-card-footer {
  padding: 12px 16px;
  border-top: 1px solid #f3f4f6;
  background: #f9fafb;
}

.ldt-use-btn {
  width: 100%;
  text-align: center;
  font-size: 13px !important;
  padding: 6px 12px !important;
}

.ldt-no-templates {
  text-align: center;
  color: #9ca3af;
  padding: 40px 20px;
  font-size: 15px;
}

/* ================================================================
 *  STEP 2: Per-block editor
 * ================================================================ */
.ldt-insert-mode {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 6px;
  font-size: 13px;
}

.ldt-radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: #92400e;
}

.ldt-radio-label input[type="radio"] {
  margin: 0;
}

/* System variables info box */
.ldt-sys-vars-info {
  margin-bottom: 16px;
  padding: 10px 14px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  font-size: 13px;
  color: #166534;
  line-height: 1.5;
}

.ldt-sys-vars-info code {
  background: #dcfce7;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
  font-family: monospace;
  color: #15803d;
}

.ldt-sys-vars-info.ldt-sys-vars-warning {
  background: #fffbeb;
  border-color: #fcd34d;
  color: #92400e;
}

.ldt-sys-vars-note {
  margin: 0;
}

.ldt-sys-vars-note em {
  background: #dcfce7;
  padding: 1px 4px;
  border-radius: 3px;
  font-style: normal;
  font-weight: 500;
}

/* Blocks editor (per-block TinyMCE editors) */
.ldt-blocks-editor {
  margin-bottom: 24px;
}

.ldt-blocks-editor h4 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
  color: #374151;
}

.ldt-block-edit-row {
  margin-bottom: 16px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
}

.ldt-block-edit-heading {
  background: #f3f4f6;
  padding: 10px 14px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ldt-block-edit-heading h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #1f2937;
  line-height: 1.4;
  text-decoration: underline;
  flex: 1;
}

/* Block TinyMCE editor wrapper */
.ldt-block-editor-wrap {
  min-height: 100px;
}

.ldt-block-editor-wrap .mce-tinymce {
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

.ldt-block-editor-wrap .mce-top-part {
  border-bottom: 1px solid #e5e7eb !important;
}

/* Fallback textarea (shown before TinyMCE initializes) */
.ldt-block-textarea {
  display: block;
  width: 100%;
  min-height: 80px;
  padding: 10px 14px !important;
  border: none !important;
  border-radius: 0 !important;
  font-size: 14px !important;
  line-height: 1.6 !important;
  resize: vertical;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif !important;
  box-sizing: border-box;
}

.ldt-block-textarea:focus {
  outline: none;
  background: #fefce8 !important;
}

/* ================================================================
 *  AI GENERATE BUTTON (per block)
 * ================================================================ */
.ldt-ai-generate-btn {
  display: inline-flex !important;
  align-items: center;
  gap: 4px;
  padding: 4px 12px !important;
  font-size: 12px !important;
  font-weight: 600;
  color: #7c3aed !important;
  background: #f5f3ff !important;
  border: 1px solid #c4b5fd !important;
  border-radius: 4px !important;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.ldt-ai-generate-btn:hover {
  background: #ede9fe !important;
  border-color: #7c3aed !important;
  color: #6d28d9 !important;
}

.ldt-ai-generate-btn:disabled {
  opacity: 0.7;
  cursor: wait;
}

.ldt-ai-icon {
  font-size: 14px;
  line-height: 1;
}

/* AI spinner */
.ldt-ai-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #c4b5fd;
  border-top-color: #7c3aed;
  border-radius: 50%;
  animation: ldtSpin 0.6s linear infinite;
  vertical-align: middle;
}

@keyframes ldtSpin {
  to { transform: rotate(360deg); }
}

/* ================================================================
 *  STEP 2: Live Preview
 *  (Issue 3: Do NOT set explicit font-size on h2/p — let them
 *   inherit from the Listeo editor's default styles)
 * ================================================================ */
.ldt-preview-wrap {
  margin-top: 20px;
}

.ldt-preview-wrap h4 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  color: #374151;
}

.ldt-preview-content {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 20px;
  font-size: inherit;
  line-height: 1.7;
  color: #1f2937;
  max-height: 300px;
  overflow-y: auto;
}

.ldt-preview-content h2 {
  margin: 16px 0 6px;
  font-weight: 700;
  color: #111827;
  line-height: 1.3;
  text-decoration: underline;
}

.ldt-preview-content h2:first-child {
  margin-top: 0;
}

.ldt-preview-content p {
  margin: 0 0 12px;
}

.ldt-preview-content h3 {
  margin: 0 0 10px;
}

.ldt-preview-content h4 {
  margin: 16px 0 8px;
}

.ldt-preview-content ul {
  margin: 8px 0;
  padding-left: 20px;
}

.ldt-preview-content li {
  margin-bottom: 4px;
}

/* Placeholder markers (unfilled fields shown in preview) */
.ldt-placeholder-marker {
  background: #fef3c7;
  color: #92400e;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
  font-family: monospace;
  border: 1px dashed #f59e0b;
}

/* ================================================================
 *  RESPONSIVE
 * ================================================================ */
@media (max-width: 600px) {
  .ldt-modal {
    max-height: 95vh;
    border-radius: 6px;
  }

  .ldt-modal-body {
    padding: 16px;
  }

  .ldt-template-grid {
    grid-template-columns: 1fr;
  }

  .ldt-block-edit-heading {
    padding: 8px 12px;
    flex-direction: column;
    align-items: flex-start;
  }

  .ldt-block-textarea {
    padding: 8px 12px !important;
    min-height: 60px;
  }

  .ldt-insert-mode {
    flex-direction: column;
    gap: 10px;
  }

  .ldt-sys-vars-info {
    font-size: 12px;
  }

  .ldt-ai-generate-btn {
    width: 100%;
    justify-content: center;
  }
}
