* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --sidebar-width: 280px;
  --radius: 8px;

  /* Light theme (default) */
  --bg: #ffffff;
  --bg-sidebar: #f6f8fa;
  --bg-content: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --text-secondary: #656d76;
  --accent: #0969da;
  --hover: #f3f4f6;
  --code-bg: #f6f8fa;
  --blockquote-bg: #f6f8fa;
  --blockquote-border: #d0d7de;
  --table-row-alt: #f6f8fa;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

/* Dark theme via data attribute */
[data-theme="dark"] {
  --bg: #0d1117;
  --bg-sidebar: #161b22;
  --bg-content: #0d1117;
  --border: #30363d;
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --accent: #58a6ff;
  --hover: #1c2128;
  --code-bg: #161b22;
  --blockquote-bg: #161b22;
  --blockquote-border: #3b434b;
  --table-row-alt: #161b22;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
}

[data-theme="dark"] .content img {
  opacity: 0.85;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s ease, color 0.2s ease;
}

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.25s ease, background 0.2s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 40px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo-img {
  height: 18px;
  width: auto;
  display: block;
}

/* 다크모드 로고 반전 */
[data-theme="dark"] .logo-img {
  filter: invert(1);
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-secondary);
  cursor: pointer;
}

.sidebar-actions {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-action-btn {
  width: 100%;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.sidebar-action-btn:hover {
  opacity: 0.9;
}

.sidebar-action-btn.sidebar-action-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.sidebar-action-btn.sidebar-action-secondary:hover {
  background: var(--hover);
  opacity: 1;
}

.sidebar-actions {
  display: flex;
  gap: 6px;
}

/* Drag & Drop overlay */
.drop-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(9, 105, 218, 0.12);
  border: 3px dashed var(--accent);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drop-overlay.active {
  display: flex;
}

.drop-overlay-text {
  padding: 20px 32px;
  background: var(--bg);
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  box-shadow: var(--shadow-md);
}

.breadcrumb {
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
}

.breadcrumb:empty {
  display: none;
}

.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.breadcrumb .sep {
  margin: 0 4px;
  color: var(--text-secondary);
}

.file-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0;
}

.file-list li {
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  transition: background 0.15s;
  border-radius: 0;
}

.file-list li:hover {
  background: var(--hover);
}

.file-list li.active {
  background: var(--accent);
  color: #fff;
}

.file-list li .icon {
  font-size: 16px;
  flex-shrink: 0;
}

.file-list li .meta {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.file-list li.active .meta {
  color: rgba(255,255,255,0.7);
}

.file-list li.dragging {
  opacity: 0.4;
}

.file-list li.drop-target {
  background: rgba(9, 105, 218, 0.1);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

.file-list li[draggable="true"] {
  cursor: grab;
}

.file-list li[draggable="true"]:active {
  cursor: grabbing;
}

.folder-delete-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.file-list li:hover .folder-delete-btn {
  opacity: 1;
}

.folder-delete-btn:hover {
  color: #e5534b;
}

/* ── Main ── */
.main {
  margin-left: var(--sidebar-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}

.mobile-back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
  align-items: center;
}

.doc-title {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  color: var(--text);
}

/* ── Content wrapper ── */
.content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

/* ── Document Actions (header bar) ── */
.doc-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 40px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.doc-action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.doc-action-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.doc-action-btn.doc-action-danger:hover {
  color: #e5534b;
  border-color: #e5534b;
}

/* ── Content — Markdown Reader style ── */
.content {
  flex: 1;
  padding: 32px 40px 80px;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  line-height: 1.8;
  font-size: 16px;
  color: var(--text);
  word-wrap: break-word;
}

/* Headings */
.content h1, .content h2, .content h3,
.content h4, .content h5, .content h6 {
  margin-top: 1.6em;
  margin-bottom: 0.6em;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}

.content h1 {
  font-size: 2em;
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--border);
}

.content h2 {
  font-size: 1.5em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border);
}

.content h3 { font-size: 1.25em; }
.content h4 { font-size: 1em; }
.content h5 { font-size: 0.875em; }
.content h6 { font-size: 0.85em; color: var(--text-secondary); }

.content p {
  margin-bottom: 1.2em;
}

/* Links */
.content a {
  color: var(--accent);
  text-decoration: none;
}

.content a:hover {
  text-decoration: underline;
}

/* Lists */
.content ul, .content ol {
  margin-bottom: 1.2em;
  padding-left: 2em;
}

.content li {
  margin-bottom: 0.35em;
}

.content li > p {
  margin-bottom: 0.5em;
}

.content li + li {
  margin-top: 0.25em;
}

/* Blockquote — Markdown Reader style */
.content blockquote {
  margin: 1.2em 0;
  padding: 1px 1.2em;
  border-left: 4px solid var(--blockquote-border);
  background: var(--blockquote-bg);
  color: var(--text-secondary);
  border-radius: 0 6px 6px 0;
}

.content blockquote p {
  margin: 0.8em 0;
}

/* Inline code */
.content code {
  background: var(--code-bg);
  padding: 0.2em 0.45em;
  border-radius: 4px;
  font-size: 0.875em;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  border: 1px solid var(--border);
}

/* Code blocks */
.content pre {
  margin: 1.2em 0;
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
}

.content pre code {
  display: block;
  padding: 16px 20px;
  background: var(--code-bg);
  font-size: 13.5px;
  line-height: 1.55;
  border: none;
  border-radius: 0;
}

/* Tables — Markdown Reader style */
.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2em 0;
  font-size: 14px;
  overflow-x: auto;
  display: block;
}

.content thead {
  display: table-header-group;
}

.content tbody {
  display: table-row-group;
}

.content tr {
  display: table-row;
  border-top: 1px solid var(--border);
}

.content table {
  display: table;
}

.content tbody tr:nth-child(even) {
  background: var(--table-row-alt);
}

.content th, .content td {
  border: 1px solid var(--border);
  padding: 8px 14px;
  text-align: left;
}

.content th {
  background: var(--code-bg);
  font-weight: 600;
}

/* Images */
.content img {
  max-width: 100%;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* Horizontal rule */
.content hr {
  border: none;
  border-top: 2px solid var(--border);
  margin: 2.5em 0;
}

/* Task list (GFM) */
.content input[type="checkbox"] {
  margin-right: 6px;
  vertical-align: middle;
}

/* Definition lists */
.content dl {
  margin-bottom: 1.2em;
}

.content dt {
  font-weight: 600;
  margin-top: 0.8em;
}

.content dd {
  margin-left: 1.5em;
  margin-bottom: 0.5em;
}

/* ── Auth Screen ── */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #ffffff;
  color: #1f2328;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 40px 32px;
  text-align: center;
}

.auth-logo-img {
  width: 200px;
  height: auto;
  margin: 0 auto 32px;
  display: block;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form input[type="text"],
.auth-form input[type="password"] {
  padding: 12px 14px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  font-size: 15px;
  background: #ffffff;
  color: #1f2328;
  outline: none;
  transition: border-color 0.15s;
}

.auth-form input:focus {
  border-color: #0969da;
}

.auth-btn {
  padding: 12px;
  background: #0969da;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.auth-btn:hover {
  opacity: 0.9;
}

.auth-error {
  color: #e5534b;
  font-size: 13px;
  min-height: 18px;
}

.auth-switch {
  margin-top: 16px;
  font-size: 13px;
}

.auth-switch a {
  color: #0969da;
  text-decoration: none;
}

.auth-switch a:hover {
  text-decoration: underline;
}

.main-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* ── TOC Panel ── */
.toc-panel {
  width: 240px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  flex-shrink: 0;
  overflow: hidden;
}

.toc-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  height: 40px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.toc-header-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.toc-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0;
}

.toc-item {
  display: flex;
  align-items: flex-start;
  gap: 2px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  transition: background 0.12s, color 0.12s;
}

.toc-item:hover {
  background: var(--hover);
}

.toc-item.active {
  color: var(--accent);
}

.toc-item-label {
  flex: 1;
  padding: 5px 12px 5px 0;
  min-width: 0;
  word-break: break-word;
}

.toc-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 26px;
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  transition: transform 0.15s;
}

.toc-toggle.collapsed {
  transform: rotate(-90deg);
}

.toc-toggle.hidden {
  visibility: hidden;
}

.toc-children {
  overflow: hidden;
}

.toc-children.collapsed {
  display: none;
}

/* indent levels */
.toc-depth-1 .toc-item-label { padding-left: 14px; font-weight: 600; }
.toc-depth-2 .toc-item-label { padding-left: 14px; font-weight: 600; }
.toc-depth-3 .toc-item-label { padding-left: 28px; }
.toc-depth-4 .toc-item-label { padding-left: 42px; }
.toc-depth-5 .toc-item-label { padding-left: 56px; }
.toc-depth-6 .toc-item-label { padding-left: 70px; }

@media (max-width: 768px) {
  .toc-panel {
    display: none !important;
  }
  .toc-panel.mobile-active {
    display: flex !important;
    position: fixed;
    top: 40px;
    left: 0;
    width: 100%;
    height: calc(100% - 40px);
    z-index: 50;
    border-right: none;
  }

  .toc-panel.mobile-active .toc-header {
    display: none;
  }
}

/* ── Right Panel (채팅, 히스토리 공통) ── */
.right-panel {
  width: 380px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  flex-shrink: 0;
  overflow: hidden;
}

.right-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 40px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.right-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  flex: 1;
}

.panel-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.panel-close-btn:hover {
  background: var(--hover);
  color: var(--text);
}


.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-welcome {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  padding: 40px 16px;
}

.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-bubble .file-link {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

.chat-bubble .file-link:hover {
  background: var(--border);
}

.chat-typing {
  align-self: flex-start;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 8px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.typing-dots {
  display: inline-flex;
  gap: 3px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes typingBounce {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  resize: none;
  max-height: 120px;
  outline: none;
  transition: border-color 0.15s;
}

.chat-input:focus {
  border-color: var(--accent);
}

.chat-send {
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.chat-send:hover {
  opacity: 0.9;
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: var(--text);
  color: var(--bg);
  border-radius: 8px;
  font-size: 14px;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  color: var(--text-secondary);
  text-align: center;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

/* ── Topbar buttons ── */
.topbar-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.topbar-btn:hover {
  background: var(--hover);
  color: var(--text);
}

/* ── History Panel ── */

.history-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0;
}

.commit-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.commit-item:hover {
  background: var(--hover);
}

.commit-hash {
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 12px;
  color: var(--accent);
}

.commit-message {
  font-size: 14px;
  margin: 4px 0;
  color: var(--text);
}

.commit-date {
  font-size: 12px;
  color: var(--text-secondary);
}

.commit-actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.commit-btn {
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}

.commit-btn:hover {
  background: var(--hover);
}

.commit-btn.restore {
  color: var(--accent);
  border-color: var(--accent);
}

/* Diff view */
.diff-view {
  padding: 12px 16px;
}

.diff-view pre {
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.diff-line-add {
  background: #e6ffec;
  color: #1a7f37;
}

.diff-line-del {
  background: #ffeef0;
  color: #cf222e;
}

.diff-line-hunk {
  background: var(--code-bg);
  color: var(--text-secondary);
  font-style: italic;
}

[data-theme="dark"] .diff-line-add {
  background: #0d2818;
  color: #56d364;
}

[data-theme="dark"] .diff-line-del {
  background: #2d0b0d;
  color: #f85149;
}

/* ── Loading ── */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

/* ── Mobile ── */
@media (max-width: 768px) {
  /* 사이드바를 풀스크린 목록 화면으로 전환 */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: none;
    z-index: 100;
    border-right: none;
  }

  /* 문서 선택 시 사이드바 숨김 */
  .sidebar.mobile-hidden {
    display: none !important;
  }

  .sidebar-close {
    display: none;
  }

  .sidebar-toggle {
    display: none;
  }

  /* 뒤로가기 버튼 */
  .mobile-back-btn {
    display: flex;
  }

  .main {
    margin-left: 0;
  }

  /* 문서 미선택 시 main 숨김 */
  .main.mobile-hidden {
    display: none !important;
  }

  .content {
    padding: 20px 16px 40px;
    font-size: 15px;
  }

  .doc-actions {
    padding: 0 8px;
  }

  .right-panel {
    position: fixed;
    top: 40px;
    right: 0;
    width: 100%;
    height: calc(100% - 40px);
    z-index: 50;
  }

  .right-panel-header {
    display: none;
  }

  .content h1 { font-size: 1.5em; }
  .content h2 { font-size: 1.25em; }

  .content pre code {
    font-size: 12px;
  }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}

.sidebar-overlay.active {
  display: block;
}

/* ── Sidebar Footer ── */
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  flex-shrink: 0;
}

.sidebar-footer-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 8px;
  background: none;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sidebar-footer-btn:hover {
  background: var(--hover);
  color: var(--text);
}

/* ── Account Page (본문 영역) ── */
.account-page {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  z-index: 10;
  overflow-y: auto;
}

.account-page-inner {
  display: flex;
  max-width: 960px;
  margin: 0 auto;
  min-height: 100%;
}

.account-nav {
  width: 200px;
  padding: 32px 16px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}

.account-nav-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  padding: 0 8px;
}

.account-nav-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
  margin-bottom: 2px;
}

.account-nav-item:hover {
  background: var(--hover);
}

.account-nav-item.active {
  background: var(--hover);
  font-weight: 600;
}

.account-nav-spacer {
  flex: 1;
  min-height: 16px;
}

.account-nav-danger {
  color: #e5534b;
}

.account-nav-danger:hover {
  background: rgba(229, 83, 75, 0.1);
}

.account-detail {
  flex: 1;
  padding: 32px 40px;
  min-width: 0;
}

.account-section-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 20px;
}

.account-field {
  margin-bottom: 20px;
}

.account-label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.account-value {
  padding: 10px 14px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
  color: var(--text);
}

.account-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

.account-theme-options {
  display: flex;
  gap: 16px;
}

.account-theme-card {
  background: none;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s;
}

.account-theme-card:hover {
  border-color: var(--text-secondary);
}

.account-theme-card.active {
  border-color: var(--accent);
}

.account-theme-card span {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 0;
}

.theme-preview {
  width: 120px;
  height: 72px;
  border-radius: 6px;
  display: flex;
  overflow: hidden;
}

.theme-preview-light {
  background: #ffffff;
  border: 1px solid #d0d7de;
}

.theme-preview-light .theme-preview-sidebar {
  width: 30%;
  background: #f6f8fa;
  border-right: 1px solid #d0d7de;
}

.theme-preview-light .theme-preview-content {
  flex: 1;
}

.theme-preview-dark {
  background: #0d1117;
  border: 1px solid #30363d;
}

.theme-preview-dark .theme-preview-sidebar {
  width: 30%;
  background: #161b22;
  border-right: 1px solid #30363d;
}

.theme-preview-dark .theme-preview-content {
  flex: 1;
}

/* ── Invite Management ── */
.invite-create-btn {
  width: 100%;
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-bottom: 20px;
}

.invite-create-btn:hover {
  opacity: 0.9;
}

.invite-create-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.invite-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.invite-list:empty,
.invite-list:has(.invite-empty),
.invite-list:has(.invite-loading) {
  background: none;
  border: none;
}

.invite-empty,
.invite-loading {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  padding: 32px 16px;
}

.invite-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg);
}

.invite-item-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--code-bg);
  border: 1px solid var(--border);
  font-size: 14px;
  flex-shrink: 0;
}

.invite-item-icon-used {
  background: #e6ffec;
  border-color: #a7f3d0;
  color: #1a7f37;
}

[data-theme="dark"] .invite-item-icon-used {
  background: #0d2818;
  border-color: #1a4731;
  color: #56d364;
}

.invite-item-info {
  flex: 1;
  min-width: 0;
}

.invite-item-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.invite-item-url {
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
}

.invite-item-date {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.invite-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.invite-action-btn {
  padding: 5px 12px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.invite-action-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.invite-delete-btn:hover {
  color: #e5534b;
  border-color: #e5534b;
}

/* ── Invite Status (signup page, Phase 2) ── */
.invite-status {
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}

.invite-status-checking {
  background: var(--code-bg);
  color: var(--text-secondary);
}

.invite-status-valid {
  background: #e6ffec;
  color: #1a7f37;
  border: 1px solid #a7f3d0;
}

.invite-status-invalid {
  background: #ffeef0;
  color: #cf222e;
  border: 1px solid #ffc1c7;
}

[data-theme="dark"] .invite-status-valid {
  background: #0d2818;
  color: #56d364;
  border-color: #1a4731;
}

[data-theme="dark"] .invite-status-invalid {
  background: #2d0b0d;
  color: #f85149;
  border-color: #5c1a1a;
}

@media (max-width: 768px) {
  .account-page-inner {
    flex-direction: column;
  }

  .account-nav {
    width: 100%;
    padding: 16px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
  }

  .account-nav-title {
    width: 100%;
    margin-bottom: 8px;
  }

  .account-nav-spacer {
    display: none;
  }

  .account-detail {
    padding: 20px 16px;
  }
}

/* ── Bottom Navigation (Mobile Only) ── */
.bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    z-index: 200;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 10px;
    cursor: pointer;
    padding: 6px 0;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-nav-item.active {
    color: var(--accent, #2563eb);
  }

  .bottom-nav-item svg {
    flex-shrink: 0;
  }

  /* 하단 네비 높이만큼 콘텐츠 패딩 */
  .content {
    padding-bottom: 72px !important;
  }

  .content-wrapper {
    padding-bottom: 0;
  }

  /* 우측 패널(채팅/히스토리)이 하단 네비 위에 표시 */
  .right-panel {
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
  }

  /* TOC 모바일 풀스크린일 때도 하단 패딩 */
  .toc-panel.mobile-active {
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
  }

  /* doc-actions에서 채팅/이력/다운로드/이름변경/삭제 버튼 숨김 (하단 네비로 대체) */
  #chat-toggle,
  #history-toggle,
  #download-toggle,
  #rename-toggle,
  #delete-toggle {
    display: none !important;
  }
}
