/* ================================================================
   Workspace — 3-column writing studio
   ================================================================ */
html, body { height: 100%; margin: 0; }
body.workspace-page {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100vh;
}
body.workspace-page .app-header { flex: 0 0 auto; }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--left-w, 248px) 1fr var(--right-w, 380px);
  grid-template-rows: minmax(0, 1fr);
  background: var(--bg);
}
.workspace.left-collapsed  { grid-template-columns: 36px 1fr var(--right-w, 380px); }
.workspace.right-collapsed { grid-template-columns: var(--left-w, 248px) 1fr 36px; }
.workspace.left-collapsed.right-collapsed { grid-template-columns: 36px 1fr 36px; }

/* ===== Side panels (shared) ===== */
.left-panel, .right-panel {
  background: var(--bg-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.left-panel  { border-right: 1px solid var(--border); }
.right-panel { border-left:  1px solid var(--border); }
.left-collapsed  .left-panel  .panel-body { display: none; }
.right-collapsed .right-panel .panel-body,
.right-collapsed .right-panel .insert-mode-toggle { display: none; }

.panel-header {
  display: flex; align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  gap: 6px;
  min-height: 42px;
}
.panel-header .panel-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  flex: 1;
}
.panel-header .icon-btn {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  color: var(--fg-muted);
  transition: background .15s, color .15s;
}
.panel-header .icon-btn:hover { background: var(--bg-hover); color: var(--fg); }

.panel-body { flex: 1; overflow-y: auto; padding: 8px; }

/* ===== Left panel ===== */
.left-tabs {
  display: flex;
  gap: 2px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
.left-tabs button {
  flex: 1;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 500;
  color: var(--fg-muted);
  transition: background .15s, color .15s, box-shadow .15s;
}
.left-tabs button.active {
  background: var(--bg-elevated);
  color: var(--fg);
  box-shadow: var(--shadow-xs);
}
.left-tabs button:hover:not(.active) { background: var(--bg-hover); color: var(--fg); }

.left-tab-pane { display: none; }
.left-tab-pane.active { display: block; }

.chapter-list-item, .character-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: background .15s, border-color .15s, color .15s;
  border: 1px solid transparent;
  margin-bottom: 2px;
}
.chapter-list-item:hover,
.character-list-item:hover {
  background: var(--bg-elevated);
  border-color: var(--border);
}
.chapter-list-item.active {
  background: var(--accent-soft);
  color: var(--fg);
  font-weight: 500;
  border-color: transparent;
}
.chapter-list-item .num {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-faint);
  min-width: 28px;
  font-weight: 500;
}
.chapter-list-item.active .num {
  color: var(--accent);
  font-weight: 700;
}
.chapter-list-item .name {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chapter-list-item .wc {
  font-size: 10px;
  color: var(--fg-faint);
  font-family: var(--font-mono);
}

/* ===== Editor ===== */
.editor-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  background: var(--bg);
  overflow: hidden;
}

/* #editor-wrapper — 인라인 style 의존성 제거. CSS 로 명시적 보장 */
#editor-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.editor-toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 70%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-height: 46px;
}
.editor-toolbar .chap-num {
  font-family: var(--font-mono);
  background: var(--accent-soft);
  color: var(--accent);
  padding: 3px 11px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.editor-toolbar .chap-title-input {
  border: none;
  background: transparent;
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  outline: none;
  padding: 6px 8px;
  border-radius: var(--radius);
  color: var(--fg);
  letter-spacing: -0.015em;
  font-family: inherit;
}
.editor-toolbar .chap-title-input::placeholder { color: var(--fg-faint); font-weight: 400; }
.editor-toolbar .chap-title-input:focus { background: var(--bg-muted); }
.editor-toolbar .save-status {
  font-size: 11px;
  color: var(--fg-faint);
  min-width: 84px;
  text-align: right;
  font-weight: 500;
  font-feature-settings: "tnum";
}

.editor-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at top, color-mix(in srgb, var(--accent) 4%, transparent) 0%, transparent 50%),
    var(--bg);
}
.editor-textarea {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  overflow-y: auto;       /* textarea 자체에서 스크롤 — 가장 단순·확실 */
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 2;
  color: var(--fg);
  padding: 40px clamp(16px, 5vw, 72px) 80px;
  letter-spacing: -0.005em;
  font-weight: 400;
  box-sizing: border-box;
}
.editor-textarea::placeholder { color: var(--fg-faint); }
.editor-footer {
  padding: 8px 18px;
  font-size: 11px;
  color: var(--fg-faint);
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex; gap: 16px; align-items: center;
  font-feature-settings: "tnum";
}
.editor-footer .spacer { flex: 1; }
.editor-empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--fg-muted);
}

/* ===== Right AI panel ===== */
.right-panel .panel-body { padding: 14px; }

.insert-mode-toggle {
  display: flex;
  background: var(--bg-muted);
  border-radius: var(--radius);
  padding: 3px;
  margin: 0 14px 14px;
}
.insert-mode-toggle button {
  flex: 1;
  padding: 7px 8px;
  border-radius: calc(var(--radius) - 2px);
  font-size: 11px;
  color: var(--fg-muted);
  font-weight: 500;
  transition: all .2s;
}
.insert-mode-toggle button:hover:not(.active) { color: var(--fg); }
.insert-mode-toggle button.active {
  background: var(--bg-elevated);
  color: var(--fg);
  box-shadow: var(--shadow-xs);
}

.agent-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
  background: var(--bg-elevated);
  overflow: hidden;
  transition: border-color .2s, box-shadow .2s, transform .15s;
}
.agent-section:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.agent-section .head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg-muted) 30%, transparent), transparent);
}
.agent-section .head .icon { font-size: 17px; }
.agent-section .head .title { font-weight: 600; font-size: 13px; flex: 1; letter-spacing: -0.01em; }
.agent-section .controls {
  padding: 12px 14px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.agent-section .controls .instruction-input {
  flex: 1 1 100%;
  min-height: 70px;
  font-size: 12px;
  font-family: var(--font-sans);
}
.agent-section .result { padding: 0 14px 14px; }
.agent-section .result-empty {
  color: var(--fg-faint);
  font-size: 12px;
  padding: 6px 0;
  font-style: italic;
}
.agent-section .result-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  padding: 14px 16px;
  font-size: 13.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 360px;
  overflow-y: auto;
  margin-bottom: 8px;
  color: var(--fg);
}
.agent-section .result-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.agent-status {
  font-size: 11px;
  color: var(--fg-muted);
  padding: 0 14px 8px;
  font-family: var(--font-mono);
}
.agent-status.error { color: var(--danger); }

/* ===== Diff ===== */
.diff-block {
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  line-height: 1.65;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  max-height: 420px;
  overflow-y: auto;
}
.diff-add {
  background: color-mix(in srgb, var(--success) 22%, transparent);
  border-radius: 2px;
  padding: 1px 0;
}
.diff-del {
  background: color-mix(in srgb, var(--danger) 22%, transparent);
  text-decoration: line-through;
  border-radius: 2px;
  padding: 1px 0;
}

/* 에디터 푸터 — 저장 버튼 정렬 */
.editor-footer { padding: 10px 18px; }
.editor-footer #footer-save-status { font-size: 11px; margin-left: 10px; min-width: 80px; }
.editor-footer #footer-save-btn { margin-left: 8px; }

/* ================================================================
   Collapsed side panel — 토글 버튼만 보이게
   ================================================================ */
.left-collapsed  .left-panel  .panel-title,
.right-collapsed .right-panel .panel-title {
  display: none;
}
.left-collapsed  .left-panel  .panel-header,
.right-collapsed .right-panel .panel-header {
  justify-content: center;
  padding: 8px 4px;
  border-bottom-color: transparent;
}
.left-collapsed  .left-panel  .panel-header .icon-btn,
.right-collapsed .right-panel .panel-header .icon-btn {
  width: 28px; height: 28px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}
.left-collapsed  .left-panel  .panel-header .icon-btn:hover,
.right-collapsed .right-panel .panel-header .icon-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

/* 축소 폭 살짝 늘려서 버튼 클릭 영역 확보 */
.workspace.left-collapsed  { grid-template-columns: 40px 1fr var(--right-w, 380px); }
.workspace.right-collapsed { grid-template-columns: var(--left-w, 248px) 1fr 40px; }
.workspace.left-collapsed.right-collapsed { grid-template-columns: 40px 1fr 40px; }

/* 화 목록 항목에 hover 시 표시되는 삭제 버튼 */
.chapter-list-item { position: relative; }
.chapter-list-item .chapter-delete-btn {
  width: 22px; height: 22px;
  border-radius: var(--radius-sm);
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--fg-faint);
  font-size: 16px;
  font-family: inherit;
  flex-shrink: 0;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  padding: 0;
  margin-left: 4px;
  line-height: 1;
}
.chapter-list-item:hover .chapter-delete-btn { display: inline-flex; }
.chapter-list-item .chapter-delete-btn:hover {
  background: var(--danger);
  color: white;
}


/* ================================================================
   Right panel tabs (글쓰기 / 검수)
   ================================================================ */
.right-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  margin: 0 0 14px 0;
}
.right-tabs button {
  flex: 1;
  padding: 7px 10px;
  border-radius: calc(var(--radius) - 2px);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--fg-muted);
  transition: background .2s, color .2s, box-shadow .2s;
  font-family: inherit;
}
.right-tabs button:hover:not(.active) { color: var(--fg); }
.right-tabs button.active {
  background: var(--bg-elevated);
  color: var(--fg);
  box-shadow: var(--shadow-xs);
}

.right-tab-pane { display: none; }
.right-tab-pane.active { display: block; animation: fade-in-up .15s ease-out; }

/* 에이전트 헤더의 톱니 버튼 */
.agent-section .head .agent-gear {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  color: var(--fg-faint);
  font-size: 14px;
  background: transparent;
  border: 1px solid transparent;
  transition: all .15s;
  flex-shrink: 0;
}
.agent-section .head .agent-gear:hover {
  background: var(--bg-muted);
  color: var(--accent);
  border-color: var(--border);
}

/* writer 카드 안의 insert-mode-toggle 위치 조정 */
.agent-section[data-agent="writer"] .insert-mode-toggle {
  margin: 10px 14px 0;
}
