:root {
  --bg-root: #0e0d14;
  --bg-bar: #161420;
  --bg-card: #1c1a27;
  --bg-card-hover: #221f30;
  --bg-user: #27213b;
  --bg-thought: #14121d;
  --bg-code: #111018;
  --border: #2a273b;
  --border-accent: rgba(216, 180, 254, 0.35);
  --text-main: #ede9f7;
  --text-muted: #928ca6;
  --text-dim: #6c6782;
  --accent: #d8b4fe;
  --accent-pink: #f472b6;
  --accent-gold: #fbbf24;
  --accent-green: #4ade80;
  --danger: #fb7185;
  --radius: 14px;
  --font-sans: "Pretendard", "Segoe UI", "Malgun Gothic", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-root);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.65;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* 상단 바 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: var(--bg-bar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border-accent);
  background: #231f33;
}

.brand-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(216, 180, 254, 0.12);
  color: var(--accent);
  border: 1px solid var(--border-accent);
  font-family: var(--font-mono);
}

.sync-dot {
  font-size: 11px;
  color: var(--accent-green);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.sync-dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
}

.mode-tabs {
  display: flex;
  gap: 4px;
}

.mode-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-tab:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.mode-tab.active {
  color: var(--accent);
  background: rgba(216, 180, 254, 0.14);
  border-color: var(--border-accent);
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 12px;
  font-family: var(--font-mono);
}

.stat-icon {
  color: var(--accent-gold);
}

.stat-sub {
  color: var(--text-muted);
  font-size: 11px;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
}

.nav-btn.active {
  border-color: var(--accent);
  background: rgba(216, 180, 254, 0.16);
}

.nav-btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.nav-btn-ghost:hover {
  color: var(--danger);
  border-color: rgba(251, 113, 133, 0.4);
}

.badge-pt, .badge-count {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(244, 114, 182, 0.18);
  color: var(--accent-pink);
  font-weight: 600;
}

.badge-count {
  background: rgba(216, 180, 254, 0.16);
  color: var(--accent);
}

.badge-ver {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(74, 222, 128, 0.16);
  color: var(--accent-green);
  font-weight: 600;
  font-family: var(--font-mono);
}

/* 성장 일기 & 인과 타임라인 */
.growth-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.growth-lock-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(74, 222, 128, 0.14);
  color: var(--accent-green);
  border: 1px solid rgba(74, 222, 128, 0.3);
}

.growth-axis-group {
  margin-bottom: 10px;
}

.growth-axis-group:last-child {
  margin-bottom: 0;
}

.growth-axis-label {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.growth-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.growth-chip {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(216, 180, 254, 0.1);
  border: 1px solid var(--border);
  color: var(--text-main);
}

.growth-chip.short-term {
  background: rgba(244, 114, 182, 0.1);
  border-color: rgba(244, 114, 182, 0.3);
}

.causal-card {
  background: var(--bg-root);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  margin-bottom: 8px;
  font-size: 12.5px;
}

.causal-card.pending {
  border-color: var(--accent-gold);
  background: rgba(251, 191, 36, 0.06);
}

.causal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.causal-weight {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-gold);
}

.causal-impact {
  margin-top: 4px;
  color: var(--accent);
  font-size: 12px;
}

.version-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 12px;
}

.version-row:last-child {
  border-bottom: none;
}

.drawer-actions-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

/* 메인 작업영역 */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.chat-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-feed {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  max-width: 420px;
}

.empty-avatar {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border-accent);
  margin-bottom: 10px;
}

.empty-state h2 {
  margin: 0 0 6px;
  color: var(--text-main);
  font-size: 18px;
}

/* 메시지 카드 */
.msg-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.msg-row.user {
  justify-content: flex-end;
}

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--border-accent);
  flex-shrink: 0;
  margin-top: 2px;
}

.msg-body-wrap {
  max-width: min(740px, 88%);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg-row.user .msg-body-wrap {
  align-items: flex-end;
}

.msg-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
}

.msg-sender {
  font-weight: 700;
  color: var(--accent);
}

.msg-model-tag {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
  word-break: break-word;
}

.msg-row.user .msg-bubble {
  background: var(--bg-user);
  border-color: var(--border-accent);
}

.msg-bubble p {
  margin: 0 0 8px;
}

.msg-bubble p:last-child {
  margin-bottom: 0;
}

.msg-bubble ul, .msg-bubble ol {
  margin: 6px 0 8px;
  padding-left: 20px;
}

.msg-bubble h1, .msg-bubble h2, .msg-bubble h3, .msg-bubble h4 {
  margin: 10px 0 6px;
  line-height: 1.35;
  color: var(--text-main);
}

.msg-bubble h1 { font-size: 17px; }
.msg-bubble h2 { font-size: 15.5px; color: var(--accent); }
.msg-bubble h3 { font-size: 14.5px; }
.msg-bubble h4 { font-size: 13.5px; color: var(--text-muted); }

.msg-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.msg-bubble a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg-bubble del {
  color: var(--text-muted);
}

/* 마크다운 표 */
.md-table-wrap {
  margin: 10px 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #151320;
}

.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.5;
}

.md-table th,
.md-table td {
  padding: 8px 11px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  text-align: left;
  vertical-align: top;
}

.md-table th:last-child,
.md-table td:last-child {
  border-right: none;
}

.md-table thead th {
  background: rgba(216, 180, 254, 0.1);
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

.md-table tbody tr:last-child td {
  border-bottom: none;
}

.md-table tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

/* 인라인 생성 이미지 카드 */
.md-inline-img-wrap {
  margin: 10px 0;
  border: 1px solid var(--border-accent);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-code);
  max-width: 460px;
}

.md-inline-img {
  width: 100%;
  display: block;
  object-fit: contain;
  max-height: 520px;
  background: #0d0c13;
}

.md-inline-img-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* 작업방 멀티 스레드 사이드바 */
.thread-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-bar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.thread-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
}

.thread-sidebar-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.thread-new-btn {
  padding: 4px 9px;
  font-size: 11.5px;
}

.thread-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.thread-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 9px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.14s ease;
}

.thread-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
}

.thread-item.active {
  background: rgba(216, 180, 254, 0.13);
  border-color: var(--border-accent);
  color: var(--text-main);
}

.thread-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.thread-item-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-item-meta {
  font-size: 11px;
  color: var(--text-dim);
}

.thread-item-actions {
  display: flex;
  gap: 2px;
  opacity: 0.65;
}

.thread-item:hover .thread-item-actions {
  opacity: 1;
}

@media (max-width: 780px) {
  .workspace {
    flex-direction: column;
  }

  .thread-sidebar {
    width: 100%;
    max-height: 150px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .thread-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 8px;
  }

  .thread-item {
    flex-shrink: 0;
    max-width: 185px;
  }
}

.msg-bubble blockquote {
  margin: 8px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--accent);
  background: rgba(216, 180, 254, 0.06);
  color: var(--text-muted);
  border-radius: 0 8px 8px 0;
}

.msg-bubble code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 5px;
  border-radius: 5px;
}

/* 코드블록 + 복사 버튼 */
.code-block {
  margin: 10px 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-code);
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 12px;
  background: #1a1826;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.copy-code-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.copy-code-btn:hover {
  color: var(--text-main);
  border-color: var(--border-accent);
}

.code-block pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
}

.code-block pre code {
  background: transparent;
  padding: 0;
}

/* 메시지 하단 푸터: 속마음 엿보기 + 토큰 수치 */
.msg-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-dim);
  padding: 0 4px;
}

.thought-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 8px;
  background: rgba(216, 180, 254, 0.08);
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 11.5px;
  cursor: pointer;
}

.thought-toggle:hover {
  background: rgba(216, 180, 254, 0.16);
}

.thought-panel {
  margin-top: 4px;
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--bg-thought);
  border: 1px dashed var(--border-accent);
  color: #bfb9d6;
  font-size: 12.5px;
  line-height: 1.6;
}

.thought-panel p {
  margin: 0 0 8px;
}

.thought-panel p:last-child {
  margin-bottom: 0;
}

.mini-action {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 11.5px;
  padding: 2px 5px;
  border-radius: 5px;
}

.mini-action:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.sources-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.source-link {
  font-size: 11.5px;
  color: var(--accent);
  text-decoration: none;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(216, 180, 254, 0.08);
  border: 1px solid var(--border);
}

.source-link:hover {
  text-decoration: underline;
}

.typing-bubble {
  color: var(--text-muted);
  font-style: italic;
}

/* 하단 입력 영역 */
.composer-wrap {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 20px 16px;
  flex-shrink: 0;
}

.composer-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
  padding: 0 4px;
}

.composer-toggles {
  display: flex;
  gap: 10px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
}

.attach-preview {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 12px;
}

.attach-chip img {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  object-fit: cover;
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-bar);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 10px;
}

.composer-box:focus-within {
  border-color: var(--border-accent);
}

#chatInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  resize: none;
  max-height: 160px;
  padding: 4px;
  line-height: 1.5;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  color: var(--text-main);
  border-color: var(--border-accent);
}

.send-btn {
  padding: 7px 16px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, #a855f7, #ec4899);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* 우측 서랍 */
.drawer {
  width: 360px;
  max-width: 92vw;
  background: var(--bg-bar);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.drawer-header h3 {
  margin: 0;
  font-size: 14.5px;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.drawer-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.quest-bar {
  height: 8px;
  border-radius: 999px;
  background: #282438;
  overflow: hidden;
  margin: 8px 0;
}

.quest-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #a855f7, #f472b6);
}

.quest-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 13px;
}

.quest-item:last-child {
  border-bottom: none;
}

.quest-done {
  color: var(--accent-green);
}

.memory-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.memory-form input, .memory-form select, .memory-form textarea {
  background: var(--bg-root);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: 8px;
  padding: 7px 10px;
  font-family: var(--font-sans);
  font-size: 13px;
}

.memory-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}

.memory-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.album-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.album-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.album-card img {
  width: 100%;
  display: block;
  object-fit: cover;
}

.album-card-info {
  padding: 10px 12px;
  font-size: 13px;
}

/* 모달 & 토스트 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 7, 12, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-accent);
  border-radius: 14px;
  padding: 20px;
  width: min(360px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-card input {
  background: var(--bg-root);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 9px 12px;
  border-radius: 8px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #29243d;
  color: var(--text-main);
  border: 1px solid var(--border-accent);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 60;
}

[hidden] {
  display: none !important;
}
