/* ===== Admin Panel CSS ===== */
:root {
  --c-bg: #ffffff;
  --c-bg-soft: #f6f6f7;
  --c-bg-mute: #ebedef;
  --c-border: #e2e2e2;
  --c-divider: #f0f0f0;
  --c-text-1: #213547;
  --c-text-2: #5a6370;
  --c-text-3: #8e8e8e;
  --c-brand: #3451b2;
  --c-brand-light: #3a5ccc;
  --c-brand-soft: rgba(52, 81, 178, 0.1);
  --c-green: #3ba776;
  --c-red: #ed3c50;
  --c-yellow: #ffc517;
  --radius: 8px;
  --nav-h: 56px;
  --sidebar-w: 260px;
}

.dark {
  --c-bg: #1a1a1a;
  --c-bg-soft: #242424;
  --c-bg-mute: #343434;
  --c-border: #2e2e2e;
  --c-divider: #2e2e2e;
  --c-text-1: rgba(255,255,255,0.86);
  --c-text-2: rgba(255,255,255,0.6);
  --c-text-3: rgba(255,255,255,0.38);
  --c-brand: #a5b4fc;
  --c-brand-light: #8189b4;
  --c-brand-soft: rgba(165, 180, 252, 0.12);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--c-bg);
  color: var(--c-text-1);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--c-brand); text-decoration: none; }
a:hover { color: var(--c-brand-light); }

/* ===== Login ===== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--c-bg-soft);
}

.login-card {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  max-width: 90vw;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.login-card h1 {
  font-size: 22px;
  margin-bottom: 8px;
  text-align: center;
}

.login-card p {
  text-align: center;
  color: var(--c-text-3);
  font-size: 13px;
  margin-bottom: 24px;
}

.login-card input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--c-bg);
  color: var(--c-text-1);
  margin-bottom: 12px;
  transition: border-color 0.2s;
}

.login-card input:focus {
  outline: none;
  border-color: var(--c-brand);
}

.login-card .error-msg {
  color: var(--c-red);
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}

.login-card .error-msg.show { display: block; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-bg);
  color: var(--c-text-1);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:hover { border-color: var(--c-brand); color: var(--c-brand); }

.btn-primary {
  background: var(--c-brand);
  color: #fff;
  border-color: var(--c-brand);
}

.btn-primary:hover {
  background: var(--c-brand-light);
  border-color: var(--c-brand-light);
  color: #fff;
}

.btn-danger {
  color: var(--c-red);
  border-color: var(--c-border);
}

.btn-danger:hover {
  border-color: var(--c-red);
  color: var(--c-red);
  background: rgba(237, 60, 80, 0.05);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-block { width: 100%; }

/* ===== Admin Layout ===== */
.admin-layout {
  display: flex;
  min-height: 100vh;
}

.admin-sidebar {
  width: var(--sidebar-w);
  background: var(--c-bg-soft);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.admin-sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-sidebar-header a {
  font-size: 16px;
  font-weight: 700;
  color: var(--c-text-1);
}

.admin-sidebar-header a:hover { color: var(--c-brand); }

.admin-sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.sidebar-group-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--c-text-3);
  padding: 8px 12px 4px;
  font-weight: 600;
}

.sidebar-doc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--c-text-2);
  transition: all 0.2s;
  margin-bottom: 2px;
}

.sidebar-doc-item:hover {
  background: var(--c-bg-mute);
  color: var(--c-text-1);
}

.sidebar-doc-item.active {
  background: var(--c-brand-soft);
  color: var(--c-brand);
  font-weight: 600;
}

.sidebar-doc-item .doc-icon {
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-doc-item .doc-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--c-border);
}

/* ===== Admin Main ===== */
.admin-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.admin-topbar {
  height: var(--nav-h);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

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

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

.admin-topbar h2 {
  font-size: 18px;
  font-weight: 600;
}

.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ===== Editor ===== */
.editor-container {
  display: flex;
  gap: 16px;
  height: calc(100vh - var(--nav-h) - 48px - 80px);
}

.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.editor-pane-header {
  padding: 8px 12px;
  background: var(--c-bg-soft);
  border-bottom: 1px solid var(--c-border);
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.editor-textarea {
  flex: 1;
  border: none;
  padding: 16px;
  font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.7;
  background: var(--c-bg);
  color: var(--c-text-1);
  resize: none;
  outline: none;
  tab-size: 2;
}

.editor-preview {
  flex: 1;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.editor-preview-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.editor-preview-body h1 { font-size: 28px; margin-bottom: 16px; border-bottom: 1px solid var(--c-divider); padding-bottom: 8px; }
.editor-preview-body h2 { font-size: 22px; margin-top: 32px; margin-bottom: 12px; border-bottom: 1px solid var(--c-divider); padding-bottom: 8px; }
.editor-preview-body h3 { font-size: 18px; margin-top: 24px; margin-bottom: 8px; }
.editor-preview-body p { margin: 12px 0; }
.editor-preview-body ul, .editor-preview-body ol { margin: 12px 0; padding-left: 24px; }
.editor-preview-body li { margin: 4px 0; }
.editor-preview-body a { color: var(--c-brand); }
.editor-preview-body code { background: var(--c-bg-soft); padding: 2px 6px; border-radius: 4px; font-size: 0.85em; font-family: ui-monospace, Menlo, monospace; }
.editor-preview-body pre { background: var(--c-bg-soft); border-radius: 8px; padding: 16px; margin: 12px 0; overflow-x: auto; }
.editor-preview-body pre code { background: none; padding: 0; }
.editor-preview-body strong { font-weight: 600; }
.editor-preview-body s { text-decoration: line-through; color: var(--c-text-3); }

.editor-preview-body .custom-block {
  margin: 12px 0;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 12px 16px;
}

.editor-preview-body .custom-block.tip { background: var(--c-brand-soft); border-color: var(--c-brand); }
.editor-preview-body .custom-block.warning { background: rgba(255,197,23,0.1); border-color: var(--c-yellow); }
.editor-preview-body .custom-block.danger { background: rgba(237,60,80,0.08); border-color: var(--c-red); }
.editor-preview-body .custom-block.details { background: var(--c-bg-soft); border-color: var(--c-border); }
.editor-preview-body .custom-block-title { font-weight: 600; margin-bottom: 4px; }
.editor-preview-body .custom-block.tip .custom-block-title { color: var(--c-brand); }
.editor-preview-body .custom-block.warning .custom-block-title { color: var(--c-yellow); }
.editor-preview-body .custom-block.danger .custom-block-title { color: var(--c-red); }

/* ===== Editor Toolbar ===== */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  flex-wrap: wrap;
}

.editor-toolbar .spacer { flex: 1; }

.editor-status {
  font-size: 13px;
  color: var(--c-text-3);
}

.editor-status.saved { color: var(--c-green); }
.editor-status.saving { color: var(--c-yellow); }
.editor-status.error { color: var(--c-red); }

/* ===== New Doc Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--c-bg);
  border-radius: 12px;
  padding: 32px;
  width: 420px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-2);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--c-bg);
  color: var(--c-text-1);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--c-brand);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  color: #fff;
  font-size: 14px;
  z-index: 300;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--c-green); }
.toast.error { background: var(--c-red); }
.toast.info { background: var(--c-brand); }

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--c-text-3);
  text-align: center;
}

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

.empty-state h3 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--c-text-2);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .admin-sidebar { display: none; }
  .editor-container { flex-direction: column; height: auto; }
  .editor-preview { display: none; }
}
