/* ========== CSS Reset & Variables ========== */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-hover: #f2f4f7;
  --border: #e8ecf1;
  --text: #1a1d23;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --primary: #5b6af0;
  --primary-hover: #4a56d4;
  --primary-light: #eef0ff;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-light: #fef2f2;
  --save-green: #22c55e;
  --save-orange: #f59e0b;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.03);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.03);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: 0.2s 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", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* ========== Auth Pages ========== */
.auth-container {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
  background: linear-gradient(135deg, #f0f2ff 0%, #f7f8fa 50%, #eef1ff 100%);
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 48px 44px;
  width: 100%; max-width: 420px;
  border: 1px solid var(--border);
}

.auth-card h1 {
  font-size: 30px; font-weight: 800; color: var(--text);
  margin-bottom: 2px; letter-spacing: -0.8px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-card .subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 36px; }

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

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

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

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(91, 106, 240, 0.1);
  background: var(--surface);
}

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

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

.captcha-svg {
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  cursor: pointer; height: 48px; transition: opacity 0.15s, box-shadow var(--transition);
}
.captcha-svg:hover { opacity: 0.85; box-shadow: 0 0 0 4px rgba(91,106,240,0.1); }

/* ========== Buttons ========== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 20px; border-radius: var(--radius-sm); font-size: 14px;
  font-weight: 600; cursor: pointer; border: none;
  transition: all var(--transition); gap: 6px; letter-spacing: 0.2px;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #7c6ff7);
  color: #fff; width: 100%; box-shadow: 0 2px 8px rgba(91,106,240,0.25);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(91,106,240,0.35); }
.btn-primary:active { transform: translateY(0); }

.btn-danger {
  background: var(--danger-light); color: var(--danger);
  border: 1px solid transparent; font-size: 13px; padding: 7px 14px;
}
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.btn-sm { padding: 7px 14px; font-size: 13px; }

.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: 28px; font-size: 14px; color: var(--text-secondary);
}
.auth-footer a { font-weight: 600; }

/* ========== Messages ========== */
.error-msg {
  background: var(--danger-light); color: var(--danger);
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 16px; display: none;
  border: 1px solid rgba(239,68,68,0.15);
}
.error-msg.show { display: block; }

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

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

.sidebar-header {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 22px; font-weight: 800; letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px;
}
.sidebar-header h2 .user-info {
  font-size: 22px; font-weight: 700; color: var(--text-secondary);
  -webkit-text-fill-color: var(--text-secondary);
}
.sidebar-header .device-info { font-size: 11px; color: var(--save-green); display: block; cursor: default; }
.sidebar-header .device-badge {
  display: inline-block; background: var(--bg); color: var(--text-secondary);
  font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 3px;
  margin-left: 4px; letter-spacing: 0.5px;
}

.new-note-btn {
  margin: 14px;
  background: linear-gradient(135deg, var(--primary), #7c6ff7);
  color: #fff; border: none;
  padding: 11px 16px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: all var(--transition);
  box-shadow: 0 1px 4px rgba(91,106,240,0.2);
}
.new-note-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(91,106,240,0.3);
}
.new-note-btn:active { transform: translateY(0); }

.notes-list {
  flex: 1; overflow-y: auto; padding: 4px 12px;
  -webkit-overflow-scrolling: touch;
}

.notes-list::-webkit-scrollbar { width: 6px; }
.notes-list::-webkit-scrollbar-track { background: transparent; }
.notes-list::-webkit-scrollbar-thumb { background: #c4c9d0; border-radius: 10px; }

.note-item {
  padding: 13px 14px; border-radius: var(--radius-sm); cursor: pointer;
  margin-bottom: 3px; transition: all var(--transition);
  border: 1px solid transparent;
  -webkit-tap-highlight-color: transparent;
}

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

.note-item.active {
  background: var(--primary-light);
  border-color: rgba(91,106,240,0.2);
  box-shadow: 0 1px 3px rgba(91,106,240,0.08);
}

.note-item .note-title {
  font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 3px; line-height: 1.4;
}

.note-item .note-preview {
  font-size: 12px; color: var(--text-tertiary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.note-item .note-date {
  font-size: 11px; color: var(--text-tertiary); margin-top: 3px;
  display: flex; align-items: center; gap: 4px;
}

.sidebar-footer {
  padding: 14px 20px; border-top: 1px solid var(--border);
}
.sidebar-footer .btn { width: 100%; font-size: 13px; }

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

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

.editor-toolbar {
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; flex-shrink: 0;
}

.editor-toolbar .note-title-input {
  flex: 1; min-width: 0; border: none;
  font-size: 22px; font-weight: 700; color: var(--text);
  background: transparent; outline: none;
  letter-spacing: -0.4px; padding: 4px 0;
}

.editor-toolbar .note-title-input::placeholder { color: var(--text-tertiary); font-weight: 400; }

/* Save indicator */
.save-indicator {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; white-space: nowrap; color: var(--text-secondary);
  background: var(--bg); padding: 5px 12px; border-radius: 20px;
}

.save-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-tertiary); transition: all 0.3s ease; flex-shrink: 0;
}

.save-dot.saved { background: var(--save-green); box-shadow: 0 0 8px rgba(34,197,94,0.35); }
.save-dot.unsaved { background: var(--save-orange); animation: pulse-dot 1.5s infinite; }
.save-dot.saving { background: var(--primary); 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: 12px; color: var(--text-secondary); font-weight: 500; }

.save-btn {
  font-size: 18px; padding: 8px 12px; cursor: pointer; border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.save-btn:hover { background: #e8f5e9; color: var(--save-green); }

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

#editorContainer { display: flex; flex: 1; flex-direction: column; min-height: 0; overflow: hidden; }

.editor-content:empty::before {
  content: '写点什么... 可以直接粘贴图片 ✨';
  color: var(--text-tertiary); pointer-events: none;
}

.editor-content::-webkit-scrollbar { width: 10px; }
.editor-content::-webkit-scrollbar-track { background: transparent; }
.editor-content::-webkit-scrollbar-thumb { background: #b0b5bd; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
.editor-content::-webkit-scrollbar-thumb:hover { background: #8b9099; background-clip: padding-box; }

/* Firefox scrollbar */
.editor-content { scrollbar-width: auto; scrollbar-color: #b0b5bd transparent; }

/* Image thumbnails */
.editor-content img {
  display: block; max-width: 100%; max-height: 320px;
  object-fit: contain; border-radius: var(--radius-sm);
  margin: 16px 0; box-shadow: var(--shadow-sm);
  cursor: zoom-in; transition: transform 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.editor-content img:hover {
  transform: scale(1.015); box-shadow: var(--shadow-md);
}

.editor-content .img-thumb-wrapper {
  display: block; position: relative;
}

.editor-content .img-thumb-wrapper::after {
  content: '🔍 点击放大';
  position: absolute; bottom: 24px; right: 12px;
  background: rgba(0,0,0,0.65); color: #fff;
  padding: 5px 12px; border-radius: 6px;
  font-size: 11px; pointer-events: none;
  opacity: 0; transition: opacity 0.2s;
  backdrop-filter: blur(4px);
}

.editor-content .img-thumb-wrapper:hover::after { opacity: 1; }

.editor-content:focus { outline: none; }

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

.editor-hint { color: var(--text-tertiary); }

/* ---- Empty State ---- */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-tertiary); gap: 16px;
}

.empty-state .empty-icon {
  font-size: 72px; opacity: 0.3; filter: grayscale(0.3);
}

.empty-state p {
  font-size: 15px; max-width: 280px; text-align: center;
  line-height: 1.7; color: var(--text-secondary);
}

/* ========== Lightbox ========== */
.lightbox {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.94);
  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);
  box-shadow: 0 0 60px rgba(0,0,0,0.5); cursor: default;
  animation: zoomIn 0.25s ease;
}

@keyframes zoomIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.lightbox-close {
  position: absolute; top: 20px; right: 24px;
  color: rgba(255,255,255,0.7); font-size: 30px; cursor: pointer; z-index: 1001;
  width: 44px; height: 44px; display: flex;
  align-items: center; justify-content: center;
  background: rgba(255,255,255,0.08); border-radius: 50%;
  transition: all var(--transition); -webkit-tap-highlight-color: transparent;
}
.lightbox-close:hover { background: rgba(255,255,255,0.18); color: #fff; }

/* ========== ICP Footer ========== */
.icp-footer {
  position: fixed;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  z-index: 5;
  pointer-events: auto;
}

.icp-footer a {
  color: var(--text-tertiary);
  text-decoration: none;
  opacity: 0.6;
  transition: opacity 0.2s;
  padding: 2px 6px;
}

.icp-footer a:hover { opacity: 1; }

/* ========== Toast ========== */
.toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text); color: #fff;
  padding: 12px 28px; border-radius: 24px;
  font-size: 13px; font-weight: 600; z-index: 1100;
  opacity: 0; transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none; white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  backdrop-filter: blur(12px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* =============================================== */
/* ==========      MOBILE   ≤ 768px      ========== */
/* =============================================== */
@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: 12px 12px; border-bottom: 1px solid var(--border);
    background: var(--surface); flex-shrink: 0; gap: 8px;
  }

  .mobile-back-btn {
    font-size: 14px; font-weight: 600; color: var(--primary);
    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: 600; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  .editor-toolbar { padding: 10px 14px; gap: 8px; }
  .editor-toolbar .note-title-input { font-size: 17px; }
  .save-indicator .save-text { display: none; }
  .save-indicator { padding: 5px 8px; }
  .delete-btn { font-size: 12px; padding: 7px 12px; }

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

  .editor-status { padding: 8px 16px; }
  .editor-hint { display: none; }

  .auth-card { padding: 36px 28px; }

  .lightbox-close { top: 12px; right: 12px; font-size: 26px; width: 40px; height: 40px; }
  .lightbox img { max-width: 98vw; max-height: 90vh; }

  .sidebar-header { padding: 18px 16px; }
  .new-note-btn { margin: 12px; }
  .notes-list { padding: 4px 10px; }
}
