/* ============================================
   J-UP — Admin CSS
   ============================================ */

/* === ADMIN NAV === */
.admin-nav {
  background: var(--ink);
  color: white;
  padding: 12px 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: var(--nav-h);
  z-index: 80;
  flex-wrap: wrap;
}
.admin-nav-title { font-size: 0.88rem; font-weight: 700; letter-spacing: 0.05em; }
.admin-nav-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.admin-body { padding: 32px 40px; max-width: 960px; }

/* === ADMIN SECTIONS === */
.admin-section { margin-bottom: 48px; }
.admin-section-title {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* === CHAPTER LIST ADMIN === */
.chapter-list-admin { display: flex; flex-direction: column; gap: 10px; }
.chapter-item-admin {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--trans);
}
.chapter-item-admin:hover { box-shadow: var(--shadow-md); }
.ch-info { flex: 1; }
.ch-level { font-size: 0.7rem; font-weight: 700; color: white; background: var(--accent); padding: 2px 8px; border-radius: 20px; }
.ch-title { font-family: var(--font-jp); font-size: 0.9rem; margin-top: 4px; color: var(--ink2); }
.ch-actions { display: flex; gap: 6px; }

/* === EDITOR CARDS === */
.editor-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.editor-card-header {
  background: var(--bg2);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.editor-card-num { font-size: 0.75rem; font-weight: 700; color: var(--ink3); }
.editor-card-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.editor-conv-line {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.vex-block, .gex-block {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* === ETC WYSIWYG === */
.editor-subsection-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink3);
  margin: 20px 0 14px;
}
.editor-subsection-label::before {
  content: '';
  width: 4px; height: 14px;
  background: var(--gold);
  border-radius: 2px;
}
.editor-subsection-label.accent::before { background: var(--accent); }

.wysiwyg-toolbar {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.wysiwyg-btn {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  line-height: 1.4;
  transition: all var(--trans);
}
.wysiwyg-btn:hover { background: var(--bg3); border-color: var(--border2); }
.wysiwyg-area {
  min-height: 120px;
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.9rem;
  line-height: 1.75;
  outline: none;
  font-family: var(--font-jp);
  background: var(--bg2);
  transition: background var(--trans);
}
.wysiwyg-area:focus { background: var(--surface); }

/* Table editor */
.tbl-editor { border-collapse: collapse; min-width: 400px; }
.tbl-editor th, .tbl-editor td { border: 1px solid var(--border2); padding: 4px; }
.tbl-editor th .form-input, .tbl-editor td .form-input {
  margin: 0; border: none; background: transparent; padding: 4px 6px; font-weight: 600;
}
.tbl-editor td .form-input { font-weight: 400; }
.tbl-editor .form-input:focus { background: rgba(192,57,43,0.06); outline: none; }

/* etc-block-card */
.etc-block-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 10px; }
.etc-img-preview { margin-bottom: 8px; min-height: 40px; }

/* === IMAGE LIBRARY === */
.image-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.img-lib-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  text-align: center;
  transition: box-shadow var(--trans);
}
.img-lib-item:hover { box-shadow: var(--shadow-md); }
.img-lib-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.img-lib-name { font-size: 0.68rem; color: var(--ink3); padding: 4px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.img-lib-size { font-size: 0.65rem; color: var(--ink4); padding: 0 6px 2px; }
.img-lib-actions { display: flex; gap: 4px; padding: 6px; justify-content: center; }

/* === ADD ITEM BUTTON === */
.btn-add-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px;
  border: 2px dashed var(--border2);
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  color: var(--ink3);
  transition: all var(--trans);
  background: transparent;
  cursor: pointer;
  margin-top: 4px;
}
.btn-add-item:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }

/* === FORM FIELDS === */
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 0.74rem; font-weight: 600; color: var(--ink3); letter-spacing: 0.03em; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-input, .form-textarea, .form-select {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.875rem;
  width: 100%;
  transition: border-color var(--trans);
  font-family: inherit;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.form-textarea { resize: vertical; min-height: 80px; line-height: 1.6; }
.form-textarea.jp, .form-input.jp { font-family: var(--font-jp); }

/* === PRINT BOOKMARK AREA === */
@media print {
  #main-page, .site-header, .side-tabs, .fixed-actions,
  .modal-overlay, .toast-wrap, #admin-page { display: none !important; }
  #bookmark-print-area { display: block !important; }
  body.print-test .bm-print-meaning,
  body.print-test .bm-print-grammar-meaning {
    color: transparent !important;
    border-bottom: 1px solid #ccc;
    display: block;
    min-height: 20px;
  }
  body.print-test ruby rt { visibility: hidden; }
  body.print-test .conv-ko, body.print-test .vocab-ex-ko,
  body.print-test .grammar-ex-ko { visibility: hidden; }
}
.bm-print-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bm-print-card { border: 1px solid #ddd; border-radius: 6px; padding: 10px 14px; }
.bm-print-word { font-family: var(--font-jp); font-size: 1.05rem; font-weight: 700; }
.bm-print-meaning { font-size: 0.82rem; color: #777; margin-top: 3px; }
.bm-print-ch { font-size: 0.65rem; color: #aaa; margin-top: 2px; }
.bm-empty { color: var(--ink4); font-size: 0.82rem; text-align: center; padding: 12px; }

/* === Responsive === */
@media (max-width: 768px) {
  .admin-body { padding: 20px 16px; }
  .form-row { grid-template-columns: 1fr; }
  .image-library-grid { grid-template-columns: repeat(auto-fill, minmax(100px,1fr)); }
}

/* ================================================
   CHAPTER FOLDER BOXES
   ================================================ */
.ch-folder-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ch-folder-box {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  cursor: pointer;
  transition: all var(--trans);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.ch-folder-box::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent);
  border-radius: 2px 0 0 2px;
}
.ch-folder-box:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateX(3px);
}
.ch-folder-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
  line-height: 1;
}
.ch-folder-content { flex: 1; min-width: 0; }
.ch-folder-title {
  font-family: var(--font-jp);
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
}
.ch-folder-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.ch-folder-tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-family: var(--font-jp);
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--ink3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.ch-folder-total {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}
.ch-folder-total span {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--ink3);
  margin-top: 2px;
  letter-spacing: 0.04em;
}
.ch-folder-arrow {
  font-size: 1.4rem;
  color: var(--ink4);
  flex-shrink: 0;
  transition: transform var(--trans);
  font-weight: 300;
}
.ch-folder-box:hover .ch-folder-arrow {
  transform: translateX(4px);
  color: var(--accent);
}

/* ================================================
   THIS WEEK (이번주 목록) — ADMIN
   ================================================ */
.tw-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}
.tw-item-main { flex: 1; min-width: 200px; }
.tw-item-words {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
  background: var(--accent);
  padding: 2px 9px;
  border-radius: 20px;
  margin-bottom: 6px;
}
.tw-item-sentence { font-family: var(--font-jp); font-size: 0.88rem; color: var(--ink2); }
.tw-used-date { display: block; font-size: 0.68rem; color: var(--ink4); margin-top: 4px; }
.tw-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* 본문 편집기: 단어/문법/추가단어 카드를 여러 열로 */
.tw-editor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.tw-editor-grid .editor-card { margin-bottom: 0; }

/* ================================================
   CHAPTER DRAWER
   ================================================ */
.ch-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,23,20,0.3);
  backdrop-filter: blur(2px);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--trans-slow);
}
.ch-drawer-overlay.open {
  opacity: 1;
  pointer-events: all;  /* 배경 클릭 차단 */
  cursor: default;
}

.ch-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(500px, 96vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 201;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--trans-slow);
}
.ch-drawer.open { transform: translateX(0); }

.ch-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 2px solid var(--border);
  background: var(--ink);
  flex-shrink: 0;
}
.ch-drawer-title {
  font-family: var(--font-jp);
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
}
.ch-drawer-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  transition: all var(--trans);
  flex-shrink: 0;
}
.ch-drawer-close:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  transform: rotate(90deg);
}

.ch-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.ch-drawer-item {
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: var(--bg2);
  border: 1px solid var(--border);
  transition: background var(--trans);
}
.ch-drawer-item:hover { background: var(--accent-bg); }

@media (max-width: 768px) {
  .ch-drawer { width: 100%; }
  .ch-folder-tag { max-width: 110px; }
}

/* ================================================
   WYSIWYG 추가: 구분선, 크기버튼, 루비버튼
   ================================================ */
.wysiwyg-divider {
  display: inline-block;
  width: 1px;
  height: 16px;
  background: var(--border2);
  margin: 0 4px;
  vertical-align: middle;
}
.wysiwyg-size-btn {
  font-family: var(--font-body);
  font-size: 0.76rem;
  font-weight: 700;
  min-width: 24px;
  letter-spacing: 0;
}
.ruby-btn {
  font-family: var(--font-jp);
  font-size: 0.72rem;
  padding: 3px 7px;
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-bg);
}
.ruby-btn:hover { background: var(--accent); color: #fff; }

/* label + 버튼 가로 배치 */
.form-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}
.form-label-row .form-label { margin-bottom: 0; }

/* etc-text: nl2br()로 줄바꿈 처리하므로 pre-wrap 불필요
   pre-wrap이 있으면 ruby 위치가 깨짐 */
.etc-text {
  word-break: break-word;
}

/* ================================================
   ADMIN CONVERSATION TABS
   ================================================ */
.conv-admin-tab-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 4px;
  flex-wrap: wrap;
}
.conv-admin-tab {
  flex: 1;
  min-width: 40px;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink3);
  cursor: pointer;
  border: none;
  background: transparent;
  transition: all var(--trans);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  position: relative;
}
.conv-admin-tab:hover { background: var(--surface); color: var(--ink); }
.conv-admin-tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
/* 내용 있음 표시 점 */
.conv-tab-dot {
  width: 5px; height: 5px;
  background: currentColor;
  border-radius: 50%;
  opacity: 0.8;
  display: inline-block;
}
/* 내레이션 카드 강조 */
.narration-card .editor-card-header {
  background: linear-gradient(135deg, var(--gold-bg), var(--bg2));
  border-left: 3px solid var(--gold);
}

/* ================================================
   BLOCK MOVE / DELETE SUB BUTTONS
   ================================================ */
.sub-move-btn {
  color: var(--ink3);
  font-size: 0.85rem;
  min-width: 26px;
}
.sub-move-btn:hover {
  background: var(--bg3);
  color: var(--ink);
}

.del-sub-btn {
  font-size: 0.72rem;
  color: var(--accent) !important;
  border-color: rgba(192,57,43,0.3) !important;
  background: transparent;
  padding: 3px 7px;
  min-width: 24px;
}
.del-sub-btn:hover {
  background: var(--accent-bg) !important;
}

/* ================================================
   CHARACTER MANAGER
   ================================================ */
.char-manager-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 6px;
}
.char-manager-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink3);
  letter-spacing: 0.04em;
  margin-bottom: 10px;
  text-transform: uppercase;
}
.char-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
}
.char-empty-hint {
  font-size: 0.75rem;
  color: var(--accent);
  font-style: italic;
}

/* 라디오 버튼 → 색깔 칩 */
.char-radio-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.char-radio-label {
  cursor: pointer;
  user-select: none;
}
.char-radio-label input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.char-radio-chip {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  color: rgba(255,255,255,0.55);
  border: 2px solid transparent;
  transition: all var(--trans);
  cursor: pointer;
}
.char-radio-label input:checked + .char-radio-chip {
  color: #fff;
  border-color: rgba(255,255,255,0.8);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  transform: scale(1.06);
}
.char-radio-label:hover .char-radio-chip {
  color: #fff;
  opacity: 0.85;
}

/* 단어 나레이션 편집 카드 */
.vocab-narration-card .editor-card-header {
  background: linear-gradient(135deg, var(--gold-bg), var(--bg2));
  border-left: 3px solid var(--gold);
}

/* ================================================
   EDITOR CARD — 활성화 상태 (클릭 선택)
   ================================================ */
.editor-card.card-active,
.etc-block-card.card-active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  box-shadow: 0 0 0 4px rgba(192,57,43,0.12), var(--shadow-md);
}
.editor-card.card-active .editor-card-header,
.etc-block-card.card-active .editor-card-header {
  background: var(--accent-bg);
}
/* 활성 카드 헤더에 힌트 표시 */
.editor-card.card-active .editor-card-num::after,
.etc-block-card.card-active .editor-card-num::after {
  content: '  ↕ Ctrl+↑↓';
  font-size: 0.62rem;
  color: var(--accent);
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* ================================================
   GRAMMAR EXP WYSIWYG + INLINE TABLE (관리자)
   ================================================ */
.grammar-exp-area {
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-height: 90px;
  font-size: 0.88rem;
  line-height: 1.75;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}
.grammar-exp-area:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(192,57,43,0.1);
}

/* wysiwyg 툴바: 설명 레이블 옆에 붙음 */
.form-label-row .wysiwyg-btn {
  font-size: 0.72rem;
  padding: 3px 7px;
  min-width: 26px;
}
/* 표 버튼: 구분된 스타일 */
.form-label-row .wysiwyg-btn:last-child {
  color: var(--navy);
  border-color: var(--navy);
  background: rgba(26,46,90,0.06);
}
.form-label-row .wysiwyg-btn:last-child:hover {
  background: var(--navy);
  color: #fff;
}

/* 관리자 contenteditable 표 */
.grammar-exp-area .grammar-inline-table th[contenteditable],
.grammar-exp-area .grammar-inline-table td[contenteditable] {
  outline: none;
  cursor: text;
}
.grammar-exp-area .grammar-inline-table th[contenteditable]:focus,
.grammar-exp-area .grammar-inline-table td[contenteditable]:focus {
  background: rgba(192,57,43,0.07);
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
