/* ========== Variables ========== */
:root {
  --bg: #F7F6FF;
  --surface: #ffffff;
  --surface-hover: #F0EFF9;
  --border: #E2E0F0;
  --border-strong: #C8C4E8;
  --text: #1a1825;
  --text-secondary: #6B6880;
  --text-tertiary: #A09DB8;
  --primary: #3C3489;
  --primary-mid: #534AB7;
  --primary-hover: #2E2870;
  --primary-light: #EEEDFE;
  --primary-light2: #CECBF6;
  --danger: #993C1D;
  --danger-light: #FAECE7;
  --save-green: #0F6E56;
  --save-orange: #BA7517;
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --transition: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-mid); text-decoration: none; }

/* ========== Auth Pages ========== */
.auth-container {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
  background: var(--bg);
}

.auth-brand {
  text-align: center; margin-bottom: 32px;
}

.auth-brand-icon {
  width: 48px; height: 48px; border-radius: 14px;
  background: var(--primary); display: inline-flex;
  align-items: center; justify-content: center;
  margin-bottom: 12px;
}

.auth-brand-icon svg {
  width: 24px; height: 24px; stroke: #fff;
  fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

.auth-brand h1 {
  font-size: 22px; font-weight: 500; color: var(--text);
  letter-spacing: -0.3px; margin-bottom: 4px;
}

.auth-brand p { font-size: 13px; color: var(--text-secondary); }

.auth-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 36px 40px;
  width: 100%; max-width: 400px;
  border: 0.5px solid var(--border);
}

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

.form-group label {
  display: block; font-size: 11px; font-weight: 500;
  color: var(--text-secondary); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: 0.5px;
}

.form-group input {
  width: 100%; padding: 10px 14px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; color: var(--text);
  background: var(--bg); transition: all var(--transition); outline: none;
}

.form-group input:focus {
  border-color: var(--primary-mid);
  box-shadow: 0 0 0 3px rgba(83,74,183,0.12);
  background: var(--surface);
}

.form-group input::placeholder { color: var(--text-tertiary); }

.captcha-group { display: flex; gap: 10px; align-items: flex-end; }
.captcha-group .form-group { flex: 1; }

.captcha-svg {
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border);
  cursor: pointer; height: 44px;
  transition: border-color var(--transition);
}
.captcha-svg:hover { border-color: var(--primary-mid); }

/* ========== Buttons ========== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 18px; border-radius: var(--radius-sm); font-size: 13px;
  font-weight: 500; cursor: pointer; border: none;
  transition: all var(--transition); gap: 5px;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--primary);
  color: #fff; width: 100%; font-size: 14px; padding: 11px;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(0.99); }

.btn-danger {
  background: var(--danger-light); color: var(--danger);
  border: 0.5px solid transparent; font-size: 12px; padding: 6px 12px;
}
.btn-danger:hover { background: #F0997B; color: #4A1B0C; }

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

.btn-ghost {
  background: transparent; color: var(--text-secondary);
  border-radius: var(--radius-xs);
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

/* ========== Auth Footer ========== */
.auth-footer {
  text-align: center; margin-top: 24px; font-size: 13px; color: var(--text-secondary);
}
.auth-footer a { font-weight: 500; color: var(--primary-mid); }

/* ========== Error Message ========== */
.error-msg {
  background: var(--danger-light); color: var(--danger);
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 16px; display: none;
  border: 0.5px solid #F5C4B3;
}
.error-msg.show { display: block; }

/* ========== App Layout ========== */
.app-container {
  display: flex; height: 100vh; height: 100dvh; overflow: hidden;
}

/* ---- Sidebar ---- */
.sidebar {
  width: 248px;
  background: var(--bg);
  border-right: 0.5px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}

.sidebar-header {
  padding: 18px 14px 12px;
  border-bottom: 0.5px solid var(--border);
}

.sidebar-brand {
  display: flex; align-items: center; gap: 9px; margin-bottom: 14px;
}

.sidebar-brand-icon {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--primary); display: flex;
  align-items: center; justify-content: center; flex-shrink: 0;
}

.sidebar-brand-icon svg {
  width: 15px; height: 15px; stroke: #fff;
  fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
}

.sidebar-brand-name {
  font-size: 16px; font-weight: 500; color: var(--text); letter-spacing: -0.2px;
}

.sidebar-user {
  font-size: 11px; color: var(--text-tertiary);
}

.search-box {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 10px; margin-bottom: 10px;
  cursor: text; transition: border-color var(--transition);
}
.search-box:focus-within { border-color: var(--primary-mid); }
.search-box svg { width: 13px; height: 13px; stroke: var(--text-tertiary); flex-shrink: 0; }
.search-box input {
  border: none; outline: none; background: transparent;
  font-size: 12px; color: var(--text); width: 100%;
}
.search-box input::placeholder { color: var(--text-tertiary); }

.new-note-btn {
  width: 100%; background: var(--primary);
  color: #fff; border: none; padding: 9px 14px;
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; gap: 6px; transition: background var(--transition);
}
.new-note-btn:hover { background: var(--primary-hover); }
.new-note-btn:active { transform: scale(0.99); }
.new-note-btn svg {
  width: 14px; height: 14px; stroke: #fff;
  fill: none; stroke-width: 2.5; stroke-linecap: round;
}

.notes-list {
  flex: 1; overflow-y: auto; padding: 8px 8px;
  -webkit-overflow-scrolling: touch;
}
.notes-list::-webkit-scrollbar { width: 4px; }
.notes-list::-webkit-scrollbar-track { background: transparent; }
.notes-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.notes-section-label {
  font-size: 10px; font-weight: 500; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.07em;
  padding: 0 8px; margin: 8px 0 4px;
}
.notes-section-label:first-child { margin-top: 0; }

.notes-divider {
  height: 0.5px; background: var(--border); margin: 6px 0;
}

.note-item {
  display: flex; align-items: flex-start; gap: 0;
  padding: 9px 10px; border-radius: var(--radius-sm);
  cursor: pointer; margin-bottom: 1px;
  border: 0.5px solid transparent;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.note-item:hover { background: var(--surface); }
.note-item.active {
  background: var(--surface);
  border-color: var(--primary-light2);
}

.note-dot {
  width: 6px; height: 6px; border-radius: 50%;
  margin-top: 5px; margin-right: 9px; flex-shrink: 0;
}

.note-body { flex: 1; min-width: 0; }

.note-title {
  font-size: 13px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 2px; line-height: 1.4;
}
.note-preview {
  font-size: 11px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 4px;
}
.note-foot {
  display: flex; align-items: center; justify-content: space-between;
}
.note-date {
  font-size: 10px; color: var(--text-tertiary);
}
.note-tag {
  font-size: 9px; padding: 2px 7px; border-radius: 10px; font-weight: 500;
}

.sidebar-footer {
  padding: 10px 14px; border-top: 0.5px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.sidebar-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary-light); display: flex; align-items: center;
  justify-content: center; font-size: 11px; font-weight: 500;
  color: var(--primary); flex-shrink: 0;
}
.sidebar-username { font-size: 12px; color: var(--text-secondary); flex: 1; }
.sidebar-logout {
  background: none; border: none; cursor: pointer;
  color: var(--text-tertiary); padding: 5px;
  border-radius: var(--radius-xs); transition: all var(--transition);
  display: flex; align-items: center;
}
.sidebar-logout:hover { color: var(--text); background: var(--surface-hover); }
.sidebar-logout svg {
  width: 15px; height: 15px; stroke: currentColor;
  fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---- Editor ---- */
.editor-area {
  flex: 1; display: flex; flex-direction: column;
  background: var(--surface); overflow: hidden;
}

.mobile-back-bar { display: none; }

.editor-toolbar {
  padding: 11px 20px; border-bottom: 0.5px solid var(--border);
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}

.editor-toolbar .note-title-input {
  flex: 1; min-width: 0; border: none;
  font-size: 20px; font-weight: 500; color: var(--text);
  background: transparent; outline: none;
  letter-spacing: -0.3px; padding: 3px 0;
}
.editor-toolbar .note-title-input::placeholder { color: var(--text-tertiary); font-weight: 400; }

.save-indicator {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; white-space: nowrap; color: var(--text-secondary);
  background: var(--bg); padding: 4px 10px; border-radius: 20px;
  border: 0.5px solid var(--border);
}
.save-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-tertiary); transition: all 0.3s; flex-shrink: 0;
}
.save-dot.saved { background: var(--save-green); }
.save-dot.unsaved { background: var(--save-orange); animation: pulse-dot 1.5s infinite; }
.save-dot.saving { background: var(--primary-mid); animation: pulse-dot 0.6s infinite; }
.save-dot.error { background: var(--danger); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.4); }
}

.save-text { font-size: 11px; color: var(--text-secondary); }

.save-btn {
  font-size: 16px; padding: 6px 10px; cursor: pointer;
  border-radius: var(--radius-sm); transition: all var(--transition);
  background: none; border: none; color: var(--text-tertiary);
}
.save-btn:hover { background: #E1F5EE; color: var(--save-green); }

/* ---- Editor Content ---- */
.editor-content {
  flex: 1; padding: 28px 32px; overflow-y: auto;
  font-size: 15px; line-height: 1.85; outline: none; border: none;
  color: var(--text); -webkit-overflow-scrolling: touch;
}
#editorContainer { flex: 1; flex-direction: column; }

.editor-content:empty::before {
  content: '写点什么…';
  color: var(--text-tertiary); pointer-events: none; font-style: italic;
}
.editor-content::-webkit-scrollbar { width: 5px; }
.editor-content::-webkit-scrollbar-track { background: transparent; }
.editor-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.editor-content img {
  display: block; max-width: 100%; max-height: 320px;
  object-fit: contain; border-radius: var(--radius-sm);
  margin: 16px 0; cursor: zoom-in;
  border: 0.5px solid var(--border);
}
.editor-content .img-thumb-wrapper { display: block; position: relative; }
.editor-content .img-thumb-wrapper::after {
  content: '点击放大';
  position: absolute; bottom: 22px; right: 10px;
  background: rgba(0,0,0,0.55); color: #fff;
  padding: 4px 10px; border-radius: 5px;
  font-size: 11px; pointer-events: none;
  opacity: 0; transition: opacity 0.2s;
}
.editor-content .img-thumb-wrapper:hover::after { opacity: 1; }

/* ---- Status Bar ---- */
.editor-status {
  padding: 8px 24px; font-size: 11px; color: var(--text-tertiary);
  border-top: 0.5px solid var(--border); flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
}

/* ---- Empty State ---- */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-tertiary); gap: 14px;
}
.empty-state .empty-icon {
  width: 52px; height: 52px; border-radius: 14px;
  background: var(--primary-light); display: flex;
  align-items: center; justify-content: center;
}
.empty-state .empty-icon svg {
  width: 24px; height: 24px; stroke: var(--primary-mid);
  fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.empty-state .empty-title {
  font-size: 15px; font-weight: 500; color: var(--text);
}
.empty-state p {
  font-size: 13px; max-width: 220px; text-align: center;
  line-height: 1.7; color: var(--text-secondary); margin-top: -6px;
}
.empty-state .empty-cta {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 20px; background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; cursor: pointer;
  margin-top: 2px; transition: background var(--transition);
}
.empty-state .empty-cta:hover { background: var(--primary-hover); }
.empty-state .empty-cta svg {
  width: 14px; height: 14px; stroke: #fff;
  fill: none; stroke-width: 2.5; stroke-linecap: round;
}

/* ========== Lightbox ========== */
.lightbox {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(10,8,20,0.92);
  align-items: center; justify-content: center; cursor: zoom-out;
  animation: fadeIn 0.2s ease;
}
.lightbox.show { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.lightbox img {
  max-width: 95vw; max-height: 95vh;
  object-fit: contain; border-radius: var(--radius-sm);
  animation: zoomIn 0.22s ease;
}
@keyframes zoomIn { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.lightbox-close {
  position: absolute; top: 18px; right: 22px;
  color: rgba(255,255,255,0.6); font-size: 20px; cursor: pointer; z-index: 1001;
  width: 36px; height: 36px; display: flex;
  align-items: center; justify-content: center;
  background: rgba(255,255,255,0.08); border-radius: 50%;
  transition: all var(--transition);
}
.lightbox-close:hover { background: rgba(255,255,255,0.16); color: #fff; }

/* ========== Toast ========== */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--text); color: #fff;
  padding: 10px 24px; border-radius: 20px;
  font-size: 13px; font-weight: 500; z-index: 1100;
  opacity: 0; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ========== Mobile ========== */
@media (max-width: 768px) {
  .app-container { position: relative; }
  .sidebar {
    position: absolute; inset: 0; width: 100%; height: 100%;
    border-right: none; z-index: 1;
  }
  body.editor-view .sidebar { display: none; }
  body.notes-view .editor-area {
    position: absolute; inset: 0; width: 100%;
  }
  body.notes-view .editor-area #editorContainer { display: none !important; }
  body.notes-view .editor-area #emptyState { display: flex; }
  body.notes-view .editor-area .mobile-back-bar { display: none; }
  body.editor-view .editor-area {
    position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2;
  }
  body.editor-view .editor-area #emptyState { display: none !important; }
  body.editor-view .editor-area #editorContainer { display: flex !important; }
  .mobile-back-bar {
    display: flex; align-items: center;
    padding: 10px 12px; border-bottom: 0.5px solid var(--border);
    background: var(--surface); flex-shrink: 0; gap: 8px;
  }
  .mobile-back-btn {
    font-size: 13px; font-weight: 500; color: var(--primary-mid);
    padding: 6px 4px; white-space: nowrap; background: none; border: none;
    cursor: pointer; display: flex; align-items: center; gap: 4px;
  }
  .mobile-title {
    font-size: 14px; font-weight: 500; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .editor-toolbar { padding: 9px 12px; gap: 7px; }
  .editor-toolbar .note-title-input { font-size: 16px; }
  .save-indicator .save-text { display: none; }
  .save-indicator { padding: 4px 8px; }
  .editor-content { padding: 16px; font-size: 15px; }
  .editor-status { padding: 7px 14px; }
  .editor-hint { display: none; }
  .auth-card { padding: 28px 24px; }
  .sidebar-header { padding: 16px 12px 10px; }
  .notes-list { padding: 6px 8px; }
}
