/**
 * Custom WYSIWYG Editor Styles
 */

/* コンテナ */
.custom-editor-container {
  position: relative;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: visible !important;
}

/* ツールバーもoverflowを許可 */
.custom-editor-toolbar {
  overflow: visible !important;
}

/* ダークモード対応 */
[data-theme="dark"] .custom-editor-container,
.dark-mode .custom-editor-container {
  background: #1e1e1e;
  border-color: #444;
}

/* エディタ本体 */
.custom-editor-content {
  padding: 12px 16px;
  min-height: 100px;
  max-height: 500px;
  overflow-y: auto;
  outline: none;
  font-size: 16px;
  line-height: 1.6;
  color: #333;
  transition: height 0.2s ease;
}

[data-theme="dark"] .custom-editor-content,
.dark-mode .custom-editor-content {
  color: #e0e0e0;
}

.custom-editor-content:focus {
  outline: none;
}

.custom-editor-content.dragover {
  background: rgba(66, 133, 244, 0.1);
  border: 2px dashed #4285f4;
}

/* 画像・動画スタイル */
.custom-editor-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 10px auto;
  border-radius: 4px;
}

.custom-editor-content video {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 10px auto;
  border-radius: 4px;
}

/* プレースホルダー */
.custom-editor-placeholder {
  position: absolute;
  top: 12px;
  left: 16px;
  right: 16px;
  color: #999;
  pointer-events: none;
  font-size: 14px;
  line-height: 1.6;
  z-index: 1;
}

[data-theme="dark"] .custom-editor-placeholder,
.dark-mode .custom-editor-placeholder {
  color: #666;
}

/* ツールバー */
.custom-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 12px;
  padding-right: 180px; /* 下書保存・投稿ボタン用のスペース */
  background: #f8f9fa;
  border-top: 1px solid #e0e0e0;
  border-radius: 0 0 8px 8px;
  position: relative;
  min-height: 52px;
}

[data-theme="dark"] .custom-editor-toolbar,
.dark-mode .custom-editor-toolbar {
  background: #2d2d2d;
  border-top-color: #444;
}

/* ツールバー上部配置時 */
.custom-editor-container > .custom-editor-toolbar:first-child {
  border-top: none;
  border-bottom: 1px solid #e0e0e0;
  border-radius: 8px 8px 0 0;
}

[data-theme="dark"] .custom-editor-container > .custom-editor-toolbar:first-child,
.dark-mode .custom-editor-container > .custom-editor-toolbar:first-child {
  border-bottom-color: #444;
}

/* ツールバーボタン */
.custom-editor-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #555;
  cursor: pointer;
  transition: all 0.15s ease;
}

.custom-editor-btn:hover {
  background: #e8e8e8;
  color: #333;
}

.custom-editor-btn:active {
  background: #d0d0d0;
}

[data-theme="dark"] .custom-editor-btn,
.dark-mode .custom-editor-btn {
  color: #aaa;
}

[data-theme="dark"] .custom-editor-btn:hover,
.dark-mode .custom-editor-btn:hover {
  background: #3d3d3d;
  color: #fff;
}

.custom-editor-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* セパレーター */
.custom-editor-separator {
  width: 1px;
  height: 24px;
  background: #ddd;
  margin: 6px 4px;
}

[data-theme="dark"] .custom-editor-separator,
.dark-mode .custom-editor-separator {
  background: #444;
}

/* ポップアップ共通 */
.custom-editor-popup {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 10px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  z-index: 9999;
  display: none;
}

.custom-editor-popup.visible {
  display: block !important;
}

[data-theme="dark"] .custom-editor-popup,
.dark-mode .custom-editor-popup {
  background: #2d2d2d;
  border-color: #444;
}

/* カラーピッカー */
.custom-editor-color-popup {
  width: 240px;
  padding: 12px;
}

.custom-editor-color-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
}

.custom-editor-color-btn {
  width: 20px;
  height: 20px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s ease;
}

.custom-editor-color-btn:hover {
  transform: scale(1.2);
  z-index: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* フォントサイズ */
.custom-editor-fontsize-popup {
  width: 120px;
  padding: 8px;
}

.custom-editor-fontsize-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.custom-editor-fontsize-btn {
  padding: 8px 12px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  border-radius: 4px;
  color: #333;
  transition: background 0.15s ease;
}

.custom-editor-fontsize-btn:hover {
  background: #f0f0f0;
}

[data-theme="dark"] .custom-editor-fontsize-btn,
.dark-mode .custom-editor-fontsize-btn {
  color: #e0e0e0;
}

[data-theme="dark"] .custom-editor-fontsize-btn:hover,
.dark-mode .custom-editor-fontsize-btn:hover {
  background: #3d3d3d;
}

/* URL埋め込みポップアップ */
.custom-editor-embed-popup {
  width: 400px;
  padding: 0;
  overflow: hidden;
}

.custom-editor-popup-content {
  display: flex;
  flex-direction: column;
}

/* 埋め込みポップアップヘッダー */
.custom-editor-embed-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #f5f5f5;
  border-bottom: 1px solid #e0e0e0;
}

[data-theme="dark"] .custom-editor-embed-header,
.dark-mode .custom-editor-embed-header {
  background: #2a2a2a;
  border-bottom-color: #444;
}

.custom-editor-embed-title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
}

[data-theme="dark"] .custom-editor-embed-title,
.dark-mode .custom-editor-embed-title {
  color: #e0e0e0;
}

.custom-editor-embed-close {
  background: none;
  border: none;
  font-size: 20px;
  color: #666;
  cursor: pointer;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.custom-editor-embed-close:hover {
  background: #e0e0e0;
  color: #333;
}

[data-theme="dark"] .custom-editor-embed-close:hover,
.dark-mode .custom-editor-embed-close:hover {
  background: #444;
  color: #fff;
}

/* 埋め込みポップアップボディ */
.custom-editor-embed-body {
  padding: 16px;
}

.custom-editor-embed-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  box-sizing: border-box;
}

.custom-editor-embed-input:focus {
  border-color: #4285f4;
  box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.15);
}

[data-theme="dark"] .custom-editor-embed-input,
.dark-mode .custom-editor-embed-input {
  background: #1e1e1e;
  border-color: #444;
  color: #e0e0e0;
}

/* 埋め込みプレビュー */
.custom-editor-embed-preview {
  margin-top: 12px;
  min-height: 0;
}

.custom-editor-embed-preview:empty {
  display: none;
}

.custom-editor-embed-loading {
  text-align: center;
  padding: 16px;
  color: #666;
  font-size: 13px;
}

.custom-editor-embed-preview-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #f9f9f9;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
}

[data-theme="dark"] .custom-editor-embed-preview-card,
.dark-mode .custom-editor-embed-preview-card {
  background: #2a2a2a;
  border-color: #444;
}

.custom-editor-embed-preview-card img {
  width: 80px;
  height: 45px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.custom-editor-embed-preview-card .preview-icon {
  width: 45px;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e0e0e0;
  border-radius: 8px;
  font-size: 20px;
  flex-shrink: 0;
}

[data-theme="dark"] .custom-editor-embed-preview-card .preview-icon,
.dark-mode .custom-editor-embed-preview-card .preview-icon {
  background: #444;
}

.custom-editor-embed-preview-card .preview-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}

.custom-editor-embed-preview-card .preview-type {
  font-size: 12px;
  font-weight: 600;
  color: #4285f4;
}

.custom-editor-embed-preview-card .preview-url {
  font-size: 12px;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-theme="dark"] .custom-editor-embed-preview-card .preview-url,
.dark-mode .custom-editor-embed-preview-card .preview-url {
  color: #999;
}

/* 埋め込みポップアップフッター */
.custom-editor-embed-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  background: #f5f5f5;
  border-top: 1px solid #e0e0e0;
}

[data-theme="dark"] .custom-editor-embed-footer,
.dark-mode .custom-editor-embed-footer {
  background: #2a2a2a;
  border-top-color: #444;
}

.custom-editor-embed-cancel {
  padding: 8px 16px;
  background: #fff;
  color: #666;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.custom-editor-embed-cancel:hover {
  background: #f5f5f5;
  border-color: #bbb;
}

[data-theme="dark"] .custom-editor-embed-cancel,
.dark-mode .custom-editor-embed-cancel {
  background: #333;
  border-color: #555;
  color: #ccc;
}

[data-theme="dark"] .custom-editor-embed-cancel:hover,
.dark-mode .custom-editor-embed-cancel:hover {
  background: #444;
}

.custom-editor-embed-submit {
  padding: 8px 20px;
  background: #4285f4;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

.custom-editor-embed-submit:hover {
  background: #3367d6;
}

.custom-editor-embed-submit:disabled {
  background: #a0c4ff;
  cursor: not-allowed;
}

/* プログレスバー */
.custom-editor-progress {
  position: absolute;
  bottom: 60px;
  left: 16px;
  right: 16px;
  height: 24px;
  background: #f0f0f0;
  border-radius: 12px;
  overflow: hidden;
}

.custom-editor-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #4285f4, #34a853);
  border-radius: 12px;
  transition: width 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 500;
}

/* 埋め込みコンテンツ */
.custom-editor-content .url_embed_area,
.custom-editor-content .fr-embedly {
  position: relative;
  margin: 16px 0;
  padding: 16px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: #fafafa;
  overflow: visible;
}

.custom-editor-content .url_embed_official {
  padding: 12px;
  background: #fff;
  min-height: auto;
  overflow: visible;
}

[data-theme="dark"] .custom-editor-content .url_embed_area,
[data-theme="dark"] .custom-editor-content .fr-embedly,
.dark-mode .custom-editor-content .url_embed_area,
.dark-mode .custom-editor-content .fr-embedly {
  background: #2d2d2d;
  border-color: #444;
}

[data-theme="dark"] .custom-editor-content .url_embed_official,
.dark-mode .custom-editor-content .url_embed_official {
  background: #1e1e1e;
}

/* 公式埋め込みのレスポンシブ対応 */
.custom-editor-content .url_embed_official iframe {
  max-width: 100%;
  height: auto;
}

/* Instagram埋め込み */
.custom-editor-content .instagram-media,
.custom-editor-content .instagram-embed-wrapper .instagram-media {
  margin: 0 auto !important;
  min-width: 326px !important;
  max-width: 540px !important;
  width: 100% !important;
  min-height: 480px !important;
  background: #fff;
  border: 1px solid #dbdbdb !important;
  border-radius: 4px;
}

.custom-editor-content .instagram-embed-wrapper {
  margin: 10px auto;
  max-width: 540px;
}

.custom-editor-content .instagram-media iframe,
.custom-editor-content .instagram-embed-wrapper iframe {
  min-height: 500px !important;
}

/* Twitter/X埋め込み */
.custom-editor-content .url_embed_official .twitter-tweet {
  margin: 0 auto !important;
}

.custom-editor-content .url_embed_official .twitter-tweet-rendered {
  margin: 0 auto !important;
}

/* TikTok埋め込み */
.custom-editor-content .url_embed_official .tiktok-embed {
  margin: 0 auto !important;
}

/* Amazon埋め込みカード */
.custom-editor-content .amazon-embed-card {
  display: flex;
  gap: 16px;
  padding: 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  max-width: 540px;
  margin: 10px 0;
  transition: box-shadow 0.2s ease;
}

.custom-editor-content .amazon-embed-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.custom-editor-content .amazon-embed-card img {
  max-width: 120px;
  height: auto;
  object-fit: contain;
}

.custom-editor-content .amazon-embed-card a {
  text-decoration: none;
}

.custom-editor-content .amazon-embed-card a:hover {
  text-decoration: underline;
}

[data-theme="dark"] .custom-editor-content .amazon-embed-card,
.dark-mode .custom-editor-content .amazon-embed-card {
  background: #2d2d2d;
  border-color: #444;
}

[data-theme="dark"] .custom-editor-content .amazon-embed-card a,
.dark-mode .custom-editor-content .amazon-embed-card a {
  color: #6db3f2;
}

/* 埋め込み削除ボタン */
.custom-editor-content .embed_buttons {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: rgba(255, 68, 68, 0.9);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.custom-editor-content .url_embed_area:hover .embed_buttons {
  opacity: 1;
}

.custom-editor-content .embed_buttons:hover {
  background: #cc0000;
}

/* レスポンシブ */
@media (max-width: 768px) {
  .custom-editor-toolbar {
    gap: 2px;
    padding: 6px 8px;
  }

  .custom-editor-btn {
    width: 32px;
    height: 32px;
  }

  .custom-editor-btn svg {
    width: 18px;
    height: 18px;
  }

  .custom-editor-content {
    padding: 10px 12px;
    font-size: 15px;
  }

  .custom-editor-popup {
    left: 10px;
    right: 10px;
    transform: none;
    width: auto !important;
  }

  .custom-editor-color-popup {
    width: auto !important;
  }

  .custom-editor-color-grid {
    grid-template-columns: repeat(8, 1fr);
  }
}

/* アニメーション */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.custom-editor-popup.visible {
  animation: fadeIn 0.15s ease;
}

/* スクロールバー */
.custom-editor-content::-webkit-scrollbar {
  width: 8px;
}

.custom-editor-content::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.custom-editor-content::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}

.custom-editor-content::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

[data-theme="dark"] .custom-editor-content::-webkit-scrollbar-track,
.dark-mode .custom-editor-content::-webkit-scrollbar-track {
  background: #2d2d2d;
}

[data-theme="dark"] .custom-editor-content::-webkit-scrollbar-thumb,
.dark-mode .custom-editor-content::-webkit-scrollbar-thumb {
  background: #555;
}

/* Froala互換スタイル */
.fr-fic {
  display: block;
  margin: 10px auto;
}

.fr-dib {
  display: block;
}

.fr-fvc {
  display: block;
}

.fr-dvi {
  display: block;
}

.fr-draggable {
  user-select: none;
}

/* 投稿ボタン配置調整 */
.top_editor {
  position: relative;
}

.top_editor #draft_button,
.top_editor #submit_button {
  z-index: 100;
  bottom: 13px !important;
}

/* タブコンテンツ内のエディタ配置調整 */
.tab-content {
  position: relative;
  padding-bottom: 0;
}

/* ボタン用のスペース確保 */
.custom-editor-container {
  margin-bottom: 0;
}

/* =====================================================
   SNS埋め込みコンテンツ用スタイル（表示用）
   ===================================================== */

/* YouTube埋め込み */
.youtube-embed-wrapper {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  max-width: 100%;
  margin: 10px 0;
}
.youtube-embed-wrapper iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Instagram埋め込み */
.instagram-embed-wrapper {
  max-width: 540px;
  margin: 10px auto;
}

/* Twitter/X, Instagram, TikTok共通 */
.twitter-tweet,
.instagram-media,
.tiktok-embed {
  margin: 10px auto !important;
}

/* 投稿表示エリア内のiframe制限 */
.quest_text iframe[src*="youtube.com"],
.c_content_text iframe[src*="youtube.com"] {
  max-width: 100%;
}

/* タイムライン内のYouTube埋め込みサイズ制限 */
.c_content_text .youtube-embed-wrapper,
.ct_frame .youtube-embed-wrapper,
div[class*="youtube-embed"] {
  position: relative !important;
  padding-bottom: 56.25% !important;
  height: 0 !important;
  overflow: hidden !important;
  max-width: 100% !important;
  margin: 10px 0 !important;
}
.c_content_text .youtube-embed-wrapper iframe,
.ct_frame .youtube-embed-wrapper iframe,
div[class*="youtube-embed"] iframe {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
}

/* タイムライン内の埋め込みコンテナ */
.ct_frame .c_content_text {
  overflow: hidden;
}
.ct_frame iframe {
  max-width: 100% !important;
}

/* YouTube iframe直接制限（フォールバック） */
.c_content_text iframe[src*="youtube.com/embed"],
.ct_frame iframe[src*="youtube.com/embed"],
#content_area iframe[src*="youtube.com/embed"],
#my_content_area iframe[src*="youtube.com/embed"] {
  max-width: 100% !important;
  width: 100% !important;
  height: auto !important;
  aspect-ratio: 16 / 9;
}

/* videoクラスを持つYouTube埋め込み用スタイル */
.c_content_text .video,
.ct_frame .video,
#content_area .video,
#my_content_area .video {
  position: relative !important;
  padding-bottom: 56.25% !important;
  height: 0 !important;
  overflow: hidden !important;
  max-width: 100% !important;
  margin: 10px 0 !important;
}
.c_content_text .video iframe,
.ct_frame .video iframe,
#content_area .video iframe,
#my_content_area .video iframe {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
}
/* ネストされたvideoクラスはpadding-bottomをリセット */
.video .video {
  padding-bottom: 0 !important;
  position: static !important;
}
