/* ============================================================
   文档中心 — 暗金书卷 Dark Gold Theme
   ============================================================ */

:root {
  --bg: #0c0e12;
  --surface: #14171e;
  --surface2: #1a1e28;
  --border: #252a35;
  --border-light: #333a48;
  --text: #d4d8e0;
  --dim: #6b7280;
  --accent: #c9a55a;
  --accent-dim: #9e7c34;
  --accent-glow: rgba(201, 165, 90, 0.12);
  --danger: #e05252;
  --radius: 6px;
  --font-main: 'Noto Serif SC', 'Georgia', serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;
  --topbar-h: 56px;
  --sidebar-w: 280px;
  --outline-w: 220px;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-main);
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 600px 400px at 20% 30%, rgba(201,165,90,.06), transparent),
    radial-gradient(ellipse 500px 500px at 80% 70%, rgba(100,120,180,.05), transparent);
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--dim); }

/* ============================================================
   LOGIN SCREEN
   ============================================================ */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  position: relative;
}

.login-glow {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 400px 300px at 50% 40%, rgba(201,165,90,.1), transparent);
  pointer-events: none;
}

.login-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 48px 40px 40px;
  width: 380px;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
}

.login-icon { margin-bottom: 20px; }

.login-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 6px;
}

.login-subtitle {
  color: var(--dim);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

.login-input-wrap { margin-bottom: 12px; }

.login-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 1.2rem;
  letter-spacing: 0.3em;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}
.login-input:focus { border-color: var(--accent); }
.login-input::placeholder {
  font-family: var(--font-main);
  font-size: 0.85rem;
  letter-spacing: 0;
  color: var(--dim);
}

.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.4em;
  margin-bottom: 8px;
}

.login-btn { width: 100%; padding: 12px; font-size: 1rem; }

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  font-family: var(--font-main);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--border-light); background: var(--surface2); }

.btn-primary {
  background: var(--accent);
  color: #0c0e12;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-dim); border-color: var(--accent-dim); }

.btn-danger {
  color: var(--danger);
  border-color: rgba(224,82,82,.3);
}
.btn-danger:hover { background: rgba(224,82,82,.1); border-color: var(--danger); }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }

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

/* ============================================================
   TOPBAR
   ============================================================ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 20px;
  background: rgba(12,14,18,.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--dim);
  cursor: pointer;
  padding: 4px;
}
.topbar-menu-btn:hover { color: var(--text); }

.topbar-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.topbar-search {
  position: relative;
  flex: 1;
  max-width: 400px;
  margin: 0 12px;
}

.topbar-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--dim);
  pointer-events: none;
}

.topbar-search-input {
  width: 100%;
  padding: 7px 12px 7px 36px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-main);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
}
.topbar-search-input:focus { border-color: var(--accent); }
.topbar-search-input::placeholder { color: var(--dim); }

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
  max-height: 360px;
  overflow-y: auto;
  z-index: 200;
}

.search-item {
  display: block;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--surface2); }

.search-item-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 2px;
}
.search-item-folder {
  font-size: 0.78rem;
  color: var(--dim);
}
.search-item-snippet {
  font-size: 0.8rem;
  color: var(--dim);
  margin-top: 4px;
  line-height: 1.5;
}
.search-item-snippet mark {
  background: var(--accent-glow);
  color: var(--accent);
  padding: 0 2px;
  border-radius: 2px;
}

.search-empty {
  padding: 20px;
  text-align: center;
  color: var(--dim);
  font-size: 0.88rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.topbar-icon-btn {
  background: none;
  border: none;
  color: var(--dim);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
  transition: color 0.15s;
}
.topbar-icon-btn:hover { color: var(--danger); }

/* ============================================================
   LAYOUT
   ============================================================ */

.app { min-height: 100vh; }

.main-layout {
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  width: var(--sidebar-w);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

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

.sidebar-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

/* Folder */
.sb-folder { margin-bottom: 2px; }

.sb-folder-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}
.sb-folder-header:hover { background: var(--surface2); }

.sb-folder-arrow {
  color: var(--dim);
  font-size: 0.7rem;
  transition: transform 0.2s;
  flex-shrink: 0;
  width: 14px;
  text-align: center;
}
.sb-folder.open > .sb-folder-header .sb-folder-arrow { transform: rotate(90deg); }

.sb-folder-name {
  flex: 1;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-folder-actions {
  display: flex;
  gap: 2px;
  opacity: 0.4;
  transition: opacity 0.15s;
}
.sb-folder-header:hover .sb-folder-actions { opacity: 1; }

.sb-action-btn {
  background: none;
  border: none;
  color: var(--dim);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 0.75rem;
  border-radius: 3px;
}
.sb-action-btn:hover { color: var(--accent); background: var(--accent-glow); }
.sb-action-btn.danger:hover { color: var(--danger); background: rgba(224,82,82,.1); }

.sb-folder-docs {
  display: none;
  padding-left: 12px;
}
.sb-folder.open > .sb-folder-docs { display: block; }

/* Document item */
.sb-doc {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px 6px 24px;
  cursor: pointer;
  transition: all 0.1s;
  border-left: 2px solid transparent;
}
.sb-doc:hover { background: var(--surface2); }
.sb-doc.active {
  background: var(--accent-glow);
  border-left-color: var(--accent);
}

.sb-doc-icon {
  color: var(--dim);
  flex-shrink: 0;
  font-size: 0.7rem;
}

.sb-doc-title {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sb-doc.active .sb-doc-title { color: var(--accent); }

/* ============================================================
   CONTENT AREA
   ============================================================ */

.content-area {
  flex: 1;
  min-width: 0;
  padding: 32px 40px;
  max-width: 100%;
}

/* Home */
.view-home {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  text-align: center;
}
.home-icon { margin-bottom: 20px; opacity: 0.6; }
.home-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}
.home-desc { color: var(--dim); font-size: 0.95rem; }

/* Document view */
.doc-header { margin-bottom: 28px; }

.doc-breadcrumb { margin-bottom: 8px; }

.doc-folder-tag {
  display: inline-block;
  padding: 3px 10px;
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 3px;
}

.doc-title {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 10px;
}

.doc-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--dim);
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

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

.doc-body-wrap {
  display: flex;
  gap: 32px;
  align-items: flex-start;
}

/* Markdown rendered content */
.doc-content {
  flex: 1;
  min-width: 0;
  max-width: 860px;
}

/* ---- Markdown Typography ---- */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  color: var(--text);
  font-weight: 700;
  margin-top: 1.8em;
  margin-bottom: 0.6em;
  line-height: 1.3;
}
.markdown-body h1 { font-size: 1.6rem; color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.markdown-body h2 { font-size: 1.35rem; }
.markdown-body h3 { font-size: 1.15rem; }
.markdown-body h4 { font-size: 1rem; }

.markdown-body p { margin-bottom: 1em; }

.markdown-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-dim);
  transition: border-color 0.15s;
}
.markdown-body a:hover { border-color: var(--accent); }

.markdown-body ul, .markdown-body ol {
  margin-bottom: 1em;
  padding-left: 1.6em;
}
.markdown-body li { margin-bottom: 0.3em; }

.markdown-body blockquote {
  border-left: 3px solid var(--accent-dim);
  padding: 8px 16px;
  margin: 1em 0;
  color: var(--dim);
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 2px 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--accent);
}

.markdown-body pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 1em 0;
  overflow-x: auto;
  line-height: 1.55;
}
.markdown-body pre code {
  padding: 0;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.85rem;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.9rem;
}
.markdown-body th {
  background: var(--surface2);
  color: var(--accent);
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  border: 1px solid var(--border);
}
.markdown-body td {
  padding: 8px 14px;
  border: 1px solid var(--border);
}
.markdown-body tr:hover td { background: var(--surface); }

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

.markdown-body img {
  max-width: 100%;
  border-radius: var(--radius);
  margin: 1em 0;
}

.markdown-body strong { color: var(--text); font-weight: 700; }
.markdown-body em { font-style: italic; }

/* ============================================================
   OUTLINE (Table of Contents)
   ============================================================ */

.doc-outline {
  position: sticky;
  top: calc(var(--topbar-h) + 32px);
  width: var(--outline-w);
  flex-shrink: 0;
  max-height: calc(100vh - var(--topbar-h) - 64px);
  overflow-y: auto;
}

.outline-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.outline-item {
  display: block;
  padding: 4px 0 4px 0;
  font-size: 0.82rem;
  color: var(--dim);
  cursor: pointer;
  text-decoration: none;
  border-left: 2px solid transparent;
  padding-left: 10px;
  margin-bottom: 2px;
  transition: all 0.15s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.outline-item:hover { color: var(--text); }
.outline-item.active {
  color: var(--accent);
  border-left-color: var(--accent);
}
.outline-item.level-2 { padding-left: 10px; }
.outline-item.level-3 { padding-left: 22px; font-size: 0.8rem; }

/* ============================================================
   MODALS
   ============================================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-dialog {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  width: 440px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
}

.modal-dialog-lg {
  width: 720px;
  display: flex;
  flex-direction: column;
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 20px;
}

.modal-desc {
  font-size: 0.9rem;
  color: var(--dim);
  margin-bottom: 16px;
}

.modal-field { margin-bottom: 16px; }
.modal-field-grow { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.modal-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--dim);
  margin-bottom: 6px;
}

.modal-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-main);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s;
}
.modal-input:focus { border-color: var(--accent); }
.modal-input.mono { font-family: var(--font-mono); letter-spacing: 0.15em; text-align: center; }

select.modal-input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%236b7280' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}
select.modal-input option {
  background: var(--surface);
  color: var(--text);
}

.modal-textarea {
  width: 100%;
  flex: 1;
  min-height: 250px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.6;
  outline: none;
  resize: vertical;
  transition: border-color 0.2s;
}
.modal-textarea:focus { border-color: var(--accent); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ============================================================
   REORDER LIST
   ============================================================ */

.reorder-list { margin: 8px 0; }

.reorder-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: grab;
  transition: border-color 0.15s;
  user-select: none;
}
.reorder-item:hover { border-color: var(--border-light); }
.reorder-item.dragging {
  opacity: 0.5;
  border-color: var(--accent);
}

.reorder-grip {
  color: var(--dim);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.reorder-name {
  flex: 1;
  font-size: 0.9rem;
}

.reorder-arrows {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reorder-arrow-btn {
  background: none;
  border: none;
  color: var(--dim);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 0.7rem;
  border-radius: 3px;
}
.reorder-arrow-btn:hover { color: var(--accent); background: var(--accent-glow); }

/* ============================================================
   SIDEBAR OVERLAY (mobile)
   ============================================================ */

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 49;
  background: rgba(0,0,0,.5);
}

/* ============================================================
   LOADING / TOAST
   ============================================================ */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  z-index: 600;
  animation: toast-in 0.3s ease;
}
.toast.error { border-color: rgba(224,82,82,.4); color: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1100px) {
  .doc-outline { display: none; }
}

@media (max-width: 768px) {
  :root {
    --sidebar-w: 280px;
    --topbar-h: 50px;
  }

  .topbar-menu-btn { display: flex; }

  .topbar-search { max-width: none; margin: 0 8px; }

  .topbar-actions .btn { display: none; }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    height: calc(100vh - var(--topbar-h));
  }
  .sidebar.open { transform: translateX(0); }

  .content-area { padding: 20px 16px; }

  .doc-title { font-size: 1.4rem; }

  .doc-meta { flex-direction: column; align-items: flex-start; }

  .doc-outline { display: none; }

  .modal-dialog { padding: 24px 20px; }
  .modal-dialog-lg { width: 100%; max-width: calc(100vw - 24px); }
  .modal-textarea { min-height: 180px; }
}

/* FAB: hidden by default, shown only on mobile */
.mobile-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #0c0e12;
  border: none;
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(201,165,90,.3);
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
}

@media (max-width: 768px) {
  .mobile-fab { display: flex; }
}

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal:not(.hidden) { animation: fadeIn 0.2s ease; }