/* ==================================================
   Yuibi Repo Prototype — css/style_create.css
   (v3: Integrated UI Improvements)
   ================================================== */

/* Reset & Base */
body {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden; /* Body自体のスクロールは禁止 */
  display: flex;
  flex-direction: column;
}

.site-header {
  height: 50px;
  flex-shrink: 0;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #ddd;
  background: #fff;
  z-index: 2000;
}

/* [CH1] Editor Layout Grid */
.editor-layout {
  flex-grow: 1;
  display: grid;
  grid-template-columns: 5fr 2fr 3fr; 
  height: calc(100vh - 50px); /* ヘッダー分を引く */
  overflow: hidden;
}

/* --- Column 1: Map (No Scroll) --- */
.col-map {
  position: relative;
  border-right: 1px solid #ccc;
  height: 100%;
  overflow: hidden;
}
#spot-map { width: 100%; height: 100%; z-index: 1; background: #fff; }

.map-overlay-controls {
  position: absolute; top: 10px; left: 50px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px; /* 縦並び */
  pointer-events: none; /* 個別の子要素でautoに戻す */
}

.map-instruction {
    background: rgba(255,255,255,0.9); padding: 5px 10px;
    border-radius: 4px; font-size: 0.8rem;
    border: 1px solid #ccc;
    pointer-events: auto;
}

.map-layer-control {
    background: rgba(255,255,255,0.95);
    padding: 6px 10px;
    border-radius: 4px;
    border: 1px solid #ccc;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
}

/* --- Column 2: List (Scrollable) --- */
.col-list {
  background: #f7f9fc;
  border-right: 1px solid #ccc;
  display: flex; 
  flex-direction: column; 
  height: 100%;
  overflow: hidden;
}
.col-header {
  padding: 0.5rem 1rem; background: #fff; border-bottom: 1px solid #eee;
  display: flex; justify-content: space-between; align-items: center; 
  flex-shrink: 0;
  height: 40px;
}
.col-header h3 { margin: 0; font-size: 1rem; }

.scrollable-content {
  flex-grow: 1; 
  overflow-y: auto;
  padding: 0.5rem;
  height: calc(100% - 40px);
}

/* --- Column 3: Editor (Scrollable) --- */
.col-editor {
  background: #fff; 
  height: 100%; 
  padding: 0;
  display: flex; 
  flex-direction: column; 
  overflow: hidden;
}
#route-editor-form { 
    display: flex; 
    flex-direction: column; 
    height: 100%; 
}
.editor-scroll-area { 
    flex-grow: 1; 
    overflow-y: auto;
    padding: 1rem;
}

/* ★ Footer (Slim & Fixed) */
.editor-footer {
  height: 40px;
  flex-shrink: 0;
  border-top: 1px solid #ddd;
  background: #f9f9f9;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 1rem;
}

.footer-tool-btn {
  background: transparent; border: none; cursor: pointer;
  color: #666; font-size: 0.9rem; font-weight: bold;
  padding: 4px 8px; border-radius: 4px;
  display: flex; align-items: center; gap: 4px;
}
.footer-tool-btn:hover { background: #e2e2e2; color: #333; }

/* --- Drag & Drop Overlay --- */
#drop-overlay {
    display: none;
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(49, 130, 206, 0.85);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #fff;
}
#drop-overlay.active { display: flex; }
#drop-overlay h2 { margin: 0 0 1rem; font-size: 2rem; }
#drop-overlay p { font-size: 1.2rem; }

/* --- Timeline Section (★ Phase 2.1 視認性向上＋折りたたみ) --- */
.timeline-section-header {
    background: #F3F2EE;
    border-left: 4px solid #d0cfca;
    padding: 7px 10px;
    margin-top: 12px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 0 6px 6px 0;
    transition: background 0.2s, border-color 0.2s, box-shadow 0.2s, border-left-width 0.15s;
    gap: 6px;
}
.timeline-section-header.clickable { cursor: pointer; }
.timeline-section-header.clickable:hover { background: #eae8e3; }

/* ★ アクティブレイヤ — はっきり目立たせる */
.timeline-section-header.section-active {
    background: #e4ebe1;
    border-left: 6px solid #7A8C73;
    box-shadow: 0 2px 8px rgba(122, 140, 115, 0.22);
    padding-left: 8px;
}
.timeline-section-header.section-active .section-title { color: #3a4d34; font-weight: 800; }
.timeline-section-header.section-active .section-count { background: #7A8C73; color: #fff; }
.timeline-section-header.section-active .btn-move-section { border-color: #b5c4ae; }
.timeline-section-header.section-active .btn-move-section:hover { background: #6A7C63; border-color: #6A7C63; }

/* 非アクティブレイヤは控えめに */
.timeline-section-header:not(.section-active) { opacity: 0.65; }
.timeline-section-header:not(.section-active):hover { opacity: 0.9; }

/* ★ 折りたたみ状態 — さらにコンパクト */
.timeline-section-header.section-collapsed {
    margin-bottom: 2px;
    padding-top: 5px;
    padding-bottom: 5px;
}
.timeline-section-header.section-collapsed:not(.section-active) { opacity: 0.45; }
.timeline-section-header.section-collapsed:not(.section-active):hover { opacity: 0.75; }
.timeline-section-header.section-collapsed .section-title { color: #9a9a94; }
.timeline-section-header.section-collapsed .layer-badge { opacity: 0.5; }
/* アクティブ＆折りたたみ */
.timeline-section-header.section-active.section-collapsed { opacity: 0.85; }
.timeline-section-header.section-active.section-collapsed:hover { opacity: 1; }

/* ★ 折りたたみ/展開ボタン */
.section-collapse-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    color: #9a9a94;
    padding: 2px 4px;
    margin-right: 2px;
    border-radius: 3px;
    line-height: 1;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}
.section-collapse-btn:hover { background: rgba(0,0,0,0.06); color: #5a5a54; }
.section-active .section-collapse-btn { color: #6A7C63; }
.section-active .section-collapse-btn:hover { background: rgba(122,140,115,0.15); }

/* ★ レイヤ種別バッジ */
.layer-badge {
    font-size: 0.68rem;
    padding: 1px 7px;
    border-radius: 10px;
    margin-left: 6px;
    white-space: nowrap;
    vertical-align: middle;
    transition: opacity 0.2s;
}
.layer-badge-route { background: #EDF0EB; color: #6A7C63; }
.layer-badge-sub   { background: #FEF3CD; color: #8B6914; }

/* ★ スポット数バッジ */
.section-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    font-size: 0.65rem;
    font-weight: bold;
    background: #d0cfca;
    color: #fff;
    padding: 0 4px;
    border-radius: 9px;
    margin-left: 5px;
    vertical-align: middle;
    transition: background 0.2s, color 0.2s;
}

.section-title { font-weight: bold; color: #5a5a54; font-size: 0.88rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ★ 編集中バッジ */
.section-editing-badge {
    display: inline-block;
    font-size: 0.62rem;
    font-weight: 700;
    background: #7A8C73;
    color: #fff;
    padding: 1px 6px;
    border-radius: 3px;
    margin-left: 6px;
    vertical-align: middle;
    letter-spacing: 0.02em;
    animation: editing-pulse 2s ease-in-out infinite;
}
@keyframes editing-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.65; }
}
.section-controls { display: flex; gap: 4px; flex-shrink: 0; }
.btn-move-section {
    background: #fff; border: 1px solid #d5d0c8; border-radius: 4px;
    width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 0.7rem; color: #8a8a84; transition: all 0.15s;
}
.btn-move-section:hover { background: #7A8C73; color: #fff; border-color: #7A8C73; }

/* Empty State */
.empty-guide {
    text-align: center; padding: 2rem 1rem; color: #666;
    background: #fff; border: 1px dashed #ccc; border-radius: 6px; margin-top: 2rem;
}

/* --- (A) Timeline Cards (Indented) --- */
.timeline-row { display: grid; grid-template-columns: 1fr 20px; gap: 5px; margin-bottom: 0; }

.card-spot-wrapper { 
    grid-column: 1 / 2; padding: 4px 0; 
    padding-left: 12px; /* Indent */
    padding-right: 4px;
}
.card-spot {
  background: #fff; border: 1px solid #ddd; border-left: 3px solid #7A8C73;
  padding: 8px; border-radius: 4px; font-size: 0.9rem; cursor: pointer; position: relative;
  transition: background 0.1s, border-color 0.15s;
}
/* (E) Hover Effect */
.card-spot:hover { background: #f8f9f7; border-color: #b5c4ae; }
.card-spot.active { background: #EDF0EB; border-color: #7A8C73; box-shadow: 0 0 0 2px rgba(122, 140, 115, 0.15); }

.card-route-wrapper { 
    grid-column: 1 / 2; padding: 5px 0;
    padding-left: 24px; /* More Indent */
    padding-right: 4px;
}
.card-route {
  background: #fff; border: 1px solid #d5d0c8; border-left: 4px solid #9aae8f;
  border-radius: 6px; padding: 8px 10px; font-size: 0.85rem; color: #5a5a54;
  cursor: pointer; display: flex; align-items: center; gap: 0.5rem;
  transition: background 0.15s, border-color 0.15s;
}
.card-route:hover { background: #f5f7f3; border-color: #9aae8f; }
.card-route.active { background: #EDF0EB; border-color: #6A7C63; box-shadow: 0 0 0 2px rgba(122, 140, 115, 0.15); }

/* ★ 経路キャプション リッチエディタ */
.route-desc-editor-wrapper {
  margin-top: 4px;
  border: 1px solid #d5d0c8;
  border-radius: 5px;
  overflow: hidden;
  background: #fff;
}
.route-desc-toolbar.ql-toolbar {
  padding: 4px 6px !important;
  border: none !important;
  border-bottom: 1px solid #e8e5df !important;
  background: #faf9f7;
}
.route-desc-toolbar .ql-formats { margin-right: 8px !important; }
.route-desc-toolbar button { width: 24px !important; height: 24px !important; }
#route-desc-editor {
  min-height: 60px;
  max-height: 150px;
  overflow-y: auto;
  font-size: 0.88rem;
}
#route-desc-editor .ql-editor {
  padding: 8px 10px;
  min-height: 60px;
}
#route-desc-editor .ql-editor.ql-blank::before {
  font-style: italic;
  color: #b0afa8;
  font-size: 0.85rem;
}

/* ★ Spot Lock Section */
.lock-section {
  margin-top: 1.2rem;
  border: 1px solid #e2ddd5;
  border-radius: 6px;
  background: #faf9f7;
  overflow: hidden;
}
.lock-section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  font-size: 0.85rem;
  font-weight: 600;
  color: #5a5a54;
  transition: background 0.15s;
}
.lock-section-header:hover { background: #f3f1ed; }
.lock-section-icon { font-size: 0.9rem; }
.lock-section-title { flex: 1; }
.lock-section-status {
  font-size: 0.72rem;
  font-weight: bold;
  padding: 1px 6px;
  border-radius: 3px;
}
.lock-section-status.lock-on {
  background: #FEF3CD;
  color: #8B6914;
}
.lock-section-chevron {
  font-size: 0.75rem;
  color: #9a9a94;
  transition: transform 0.2s;
}
.lock-section-body {
  padding: 0 12px 12px;
  border-top: 1px solid #e2ddd5;
}
.lock-section-desc {
  font-size: 0.78rem;
  color: #8a8a84;
  line-height: 1.5;
  margin: 8px 0 12px;
}

/* ★ ロック条件ブロック */
.lock-condition {
  border: 1px solid #e8e5df;
  border-radius: 6px;
  margin-bottom: 10px;
  background: #fff;
  overflow: hidden;
}
.lock-condition-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #faf9f7;
}
.lock-condition-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #5a5a54;
}
.lock-condition-body {
  padding: 10px;
  border-top: 1px solid #e8e5df;
}

/* ★ ON/OFFトグルスイッチ */
.lock-toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
}
.lock-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.lock-toggle-slider {
  position: absolute;
  inset: 0;
  background: #d0cfca;
  border-radius: 10px;
  transition: background 0.25s;
}
.lock-toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  bottom: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.25s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.lock-toggle input:checked + .lock-toggle-slider {
  background: #7A8C73;
}
.lock-toggle input:checked + .lock-toggle-slider::before {
  transform: translateX(16px);
}

/* ★ ロック入力フィールド */
.lock-field-label {
  display: block;
  margin-bottom: 0.7rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #5a5a54;
}
.lock-field-label input[type="text"],
.lock-field-label input[type="number"] {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #d5d0c8;
  border-radius: 5px;
  margin-top: 4px;
  font-size: 0.88rem;
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.lock-field-label input:focus {
  outline: none;
  border-color: #7A8C73;
  box-shadow: 0 0 0 3px rgba(122, 140, 115, 0.15);
}
.lock-radius-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}
.lock-radius-row input { flex: 1; }
.lock-radius-unit {
  font-size: 0.85rem;
  color: #6b6b66;
  white-space: nowrap;
}
.lock-radius-hint {
  display: block;
  font-size: 0.72rem;
  color: #9a9a94;
  margin-top: 4px;
  line-height: 1.4;
}

/* ★ ロックプレビュー */
.lock-preview {
  margin-top: 10px;
  border: 1px dashed #d5d0c8;
  border-radius: 5px;
  padding: 10px;
  background: #fff;
}
.lock-preview-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #9a9a94;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.lock-preview-box {
  position: relative;
  min-height: 60px;
  border-radius: 4px;
  overflow: hidden;
}
.lock-preview-blur {
  padding: 12px;
  font-size: 0.85rem;
  color: #aaa;
  filter: blur(4px);
  user-select: none;
}
.lock-preview-gate {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.7);
  font-size: 0.8rem;
  color: #8B6914;
}
.lock-preview-kw {
  font-size: 0.72rem;
  color: #6b5b45;
  background: #FEF3CD;
  padding: 1px 8px;
  border-radius: 3px;
}
.lock-preview-hint {
  font-size: 0.72rem;
  color: #7A8C73;
  font-style: italic;
}
.lock-clear-btn {
  margin-top: 10px;
  width: 100%;
  padding: 6px;
  background: #fff5f5;
  color: #c53030;
  border: 1px solid #feb2b2;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  transition: background 0.15s;
}
.lock-clear-btn:hover { background: #fee; }

/* Reference Form */
.ref-section { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px dashed #ccc; }
.ref-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.ref-add-area { background: #f0f0f0; padding: 8px; border-radius: 4px; margin-top: 10px; }
.ref-list-container { margin-bottom: 1rem; border: 1px solid #eee; border-radius: 4px; background: #fafafa; }
.ref-item { display: flex; align-items: center; padding: 6px 4px; border-bottom: 1px solid #eee; background: #fff; cursor: grab; }
.ref-item:last-child { border-bottom: none; }
.ref-content { line-height: 1.4; margin-right: 8px; }
.ref-del-btn { width: 24px; height: 24px; border-radius: 50%; border: none; background: #fee; color: #c00; font-size: 1.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center; margin-left: auto; }

/* Modal */
.modal-overlay {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.4); z-index: 3000;
  align-items: center; justify-content: center;
}
.modal-window {
  background: #fff; width: 90%; max-width: 500px;
  border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  overflow: hidden; display: flex; flex-direction: column; max-height: 80vh;
}
.modal-header {
  padding: 1rem; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; background: #fafafa;
}
.modal-body { padding: 1.5rem; overflow-y: auto; }
.modal-close-btn { background: none; border: none; font-size: 1.5rem; color: #888; cursor: pointer; }

.json-preview-box {
  background: #f4f4f4; border: 1px solid #ddd; border-radius: 4px;
  padding: 10px; font-size: 0.8rem; font-family: monospace;
  white-space: pre-wrap; word-break: break-all; max-height: 150px; overflow-y: auto;
  user-select: all; margin-top: 0.5rem;
}

/* --- (C) Map Edit Handles (Improved) --- */
/* コンテナ：透明で大きい（当たり判定用） */
.edit-handle-container {
    background: transparent;
}
.edit-handle-container:hover .edit-handle-inner {
    transform: translate(-50%, -50%) scale(1.3);
    background: #ebf8ff;
}

/* 中身：視覚的なドット */
.edit-handle-inner {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 12px; height: 12px;
    border: 2px solid #3182ce;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    pointer-events: none; /* クリックは親に任せる */
}

/* 実体ハンドル */
.edit-handle-inner.solid {
    background: #fff;
}
/* ゴーストハンドル */
.edit-handle-inner.ghost {
    background: rgba(49, 130, 206, 0.5);
    width: 10px; height: 10px; /* 少し小さく */
}

/* ドラッグ中のカーソル */
.leaflet-dragging .leaflet-grab { cursor: grabbing; }

/* Inputs */
.meta-details { border: 1px solid #eee; border-radius: 4px; padding: 0.5rem; margin-bottom: 1rem; background: #fafafa; }
.props-header { border-bottom: 2px solid #eee; margin-bottom: 1rem; padding-bottom: 0.5rem; }
.badge { display: inline-block; padding: 2px 6px; border-radius: 3px; color: #fff; font-size: 0.7rem; margin-bottom: 4px; }
.badge.spot { background: #7A8C73; } .badge.route { background: #9aae8f; }
.props-body label { display: block; margin-bottom: 0.8rem; font-size: 0.9rem; font-weight: bold; }
.props-body input, .props-body textarea, .props-body select {
  width: 100%; padding: 6px; border: 1px solid #ddd; border-radius: 4px; margin-top: 4px;
}
.danger-btn { background: #fff5f5; color: #c53030; border: 1px solid #feb2b2; padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer; width: 100%; }
.main-btn { background: #7A8C73; color: #fff; border: none; padding: 4px 10px; border-radius: 4px; cursor: pointer; transition: background 0.15s; }
.main-btn:hover { background: #6A7C63; }

/* --- (B) Sub Button (Sage Base) --- */
.sub-btn {
  background: #7A8C73;
  color: #fff;
  border: 1px solid #7A8C73;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}
.sub-btn:hover {
  background: #5c6e56;
  border-color: #5c6e56;
}

/* Responsive */
@media (max-width: 900px) {
  .editor-layout { grid-template-columns: 1fr; grid-template-rows: 40vh 30vh auto; height: auto; overflow-y: auto; }
}

.ref-mode-tabs {
  display: flex; gap: 1rem; margin-bottom: 1rem; background: #f0f0f0; padding: 0.5rem; border-radius: 6px;
}
.ref-tab {
  display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-size: 0.9rem; font-weight: bold; color: #555; padding: 4px 8px; border-radius: 4px; transition: background 0.2s;
}
.ref-tab:hover { background: #e2e2e2; color: #222; }
.ref-tab input[type="radio"] { margin: 0; accent-color: #3182ce; width: 16px; height: 16px; }
/* ★ 挿入ボタン行 */
.insert-row {
  display: flex;
  justify-content: center;
  padding: 2px 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.col-list:hover .insert-row,
.insert-row:focus-within {
  opacity: 1;
}
.btn-insert-between {
  background: #fff;
  border: 1px dashed #90cdf4;
  color: #3182ce;
  border-radius: 99px;
  padding: 1px 14px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  align-self: auto;
}
.btn-insert-between:hover {
  background: #ebf8ff;
  border-color: #3182ce;
}

/* ★ Sortable ゴーストクラス */
.spot-group--ghost {
  opacity: 0.4;
  background: #ebf8ff;
  border: 1px dashed #90cdf4;
  border-radius: 6px;
}

/* ★ Caption Rich Editor */
.caption-editor-wrapper {
  margin-bottom: 0.8rem;
}
.caption-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.caption-close-btn {
  background: transparent;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 2px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  color: #666;
  transition: background 0.15s;
}
.caption-close-btn:hover {
  background: #f0f0f0;
  color: #333;
}

/* Quill editor sizing */
#spot-caption-editor {
  min-height: 80px;
  max-height: 200px;
  overflow-y: auto;
  overflow-x: visible;
  border: 1px solid #ddd;
  border-radius: 0 0 4px 4px;
  font-size: 0.95rem;
  background: #fff;
  transition: min-height 0.3s ease, max-height 0.3s ease;
}
/* 数式ツールチップがエディタ外にはみ出せるようにする */
.caption-editor-wrapper {
  position: relative;
  overflow: visible;
}
.caption-editor-wrapper .ql-tooltip {
  z-index: 100;
  position: fixed !important;
  left: 50% !important;
  top: auto !important;
  bottom: 60px !important;
  transform: translateX(-50%);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  border-radius: 6px;
}
#caption-toolbar {
  border: 1px solid #ddd;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  background: #fafafa;
}

/* Expanded caption mode */
.editor-layout.caption-expanded #spot-caption-editor {
  min-height: 300px;
  max-height: none;
  flex-grow: 1;
}
/* Quill内のKaTeX数式 */
#spot-caption-editor .ql-formula {
  cursor: pointer;
}

/* ★ Layout transition for caption expand/collapse */
.editor-layout {
  transition: grid-template-columns 0.3s ease;
}
.editor-layout.caption-expanded {
  grid-template-columns: 2fr 2fr 6fr;
}

/* ★ 脚注引用バッジ [n] */
.ref-cite-badge {
  display: inline;
  background: #e8f0fe;
  color: #1a56db;
  font-weight: bold;
  font-size: 0.8em;
  padding: 0 3px;
  border-radius: 3px;
  cursor: default;
  vertical-align: super;
  line-height: 1;
  user-select: all;
}

/* ★ Spoiler (Discord風ネタバレ隠し) — エディタ内表示 */
.ql-spoiler {
  background: #2f3136;
  color: #2f3136;
  border-radius: 3px;
  padding: 0 3px;
  cursor: pointer;
  transition: color 0.2s;
  position: relative;
}
.ql-spoiler::before {
  content: "||";
  color: #7A8C73;
  font-size: 0.7em;
  font-weight: bold;
  opacity: 0.5;
}
.ql-spoiler::after {
  content: "||";
  color: #7A8C73;
  font-size: 0.7em;
  font-weight: bold;
  opacity: 0.5;
}
/* エディタ内ではホバーで内容を見せる */
.ql-spoiler:hover {
  color: #dcddde;
}
/* ツールバーのspoilerボタン */
.ql-spoiler[class*="ql-"] {
  background: none;
  color: inherit;
}
button.ql-spoiler {
  background: none !important;
  color: #5a5a54 !important;
  border-radius: 3px;
}

/* ★ カスタム Figure（リサイズ可能画像 + キャプション） */
.ql-figure {
  margin: 1rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
}

/* 横並びモード: inline-block + 50%幅 */
.ql-figure--half {
  display: inline-flex;
  width: 48%;
  vertical-align: top;
  margin: 0.5rem 1%;
}

.ql-figure-img-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
}

.ql-figure-img-wrap img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 4px;
}

/* リサイズハンドル */
.ql-figure-resize-handle {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 14px;
  height: 14px;
  background: #3182ce;
  border: 2px solid #fff;
  border-radius: 2px;
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
}

.ql-figure:hover .ql-figure-resize-handle,
.ql-figure--resizing .ql-figure-resize-handle {
  opacity: 1;
}

.ql-figure--resizing .ql-figure-img-wrap {
  outline: 2px solid #3182ce;
  outline-offset: 2px;
}

/* キャプション */
.ql-figure-caption {
  font-size: 0.85rem;
  color: #555;
  margin-top: 6px;
  padding: 4px 8px;
  min-height: 1.4em;
  border: 1px solid transparent;
  border-radius: 4px;
  transition: border-color 0.15s, background 0.15s;
  max-width: 100%;
  cursor: text;
}

.ql-figure-caption:hover {
  border-color: #ddd;
  background: #fafafa;
}

.ql-figure-caption:focus {
  outline: none;
  border-color: #3182ce;
  background: #fff;
}

.ql-figure-caption:empty::before {
  content: attr(placeholder);
  color: #bbb;
  font-style: italic;
  pointer-events: none;
}

/* レイアウト切替ボタン */
.ql-figure-layout-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.15);
  background: rgba(255,255,255,0.9);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
  padding: 0;
  color: #555;
}
.ql-figure:hover .ql-figure-layout-btn {
  opacity: 1;
}
.ql-figure-layout-btn:hover {
  background: #fff;
  border-color: #3182ce;
  color: #3182ce;
}

/* 画像選択ハイライト */
.ql-figure--selected {
  outline: 2px solid #3182ce;
  outline-offset: 3px;
  border-radius: 4px;
}
.ql-figure--selected::after {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  border: 1px dashed rgba(49, 130, 206, 0.4);
  border-radius: 6px;
  pointer-events: none;
}
