/* Memo module */

.memo-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  height: calc(100vh - 64px);
  overflow: hidden;
}
.memo-sidebar {
  border-right: 1px solid var(--border-light);
  background: var(--bg-panel);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.memo-sidebar-top {
  padding: 1rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: .6rem;
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  z-index: 1;
}
.memo-search {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: var(--bg-page);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: .4rem .6rem;
}
.memo-search input {
  border: none;
  background: transparent;
  color: var(--text-main);
  font-size: .875rem;
  outline: none;
  flex: 1;
  min-width: 0;
}
.memo-search input::placeholder { color: var(--text-muted); }
.memo-tags-list { padding: .5rem 0; }
.memo-tag-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .4rem 1rem;
  cursor: pointer;
  font-size: .82rem;
  color: var(--text-muted);
  border-radius: 0;
  transition: background .12s;
  text-decoration: none;
}
.memo-tag-item:hover { background: var(--bg-page); color: var(--text-main); }
.memo-tag-item.active { background: #eff6ff; color: var(--primary); font-weight: 600; }
.memo-tag-count {
  font-size: .72rem;
  background: var(--bg-page);
  color: var(--text-muted);
  padding: 1px 6px;
  border-radius: 999px;
  min-width: 20px;
  text-align: center;
}
.memo-tag-item.active .memo-tag-count { background: #dbeafe; color: var(--primary); }

/* Main area */
.memo-main { overflow-y: auto; background: var(--bg-page); }

/* Pages */
.memo-page { display: none; }
.memo-page.active { display: block; }

/* Note list */
.memo-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-light);
  gap: .75rem;
}
.memo-list-header h2 { font-size: 1rem; font-weight: 700; margin: 0; }
.memo-list-subtitle { font-size: .82rem; color: var(--text-muted); }
.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  padding: 1.25rem 1.5rem;
}
.note-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .1s;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  text-decoration: none;
}
.note-card:hover { border-color: var(--primary); box-shadow: 0 4px 12px rgba(59,130,246,.1); transform: translateY(-1px); }
.note-card-title { font-size: .95rem; font-weight: 700; color: var(--text-main); }
.note-card-snippet { font-size: .8rem; color: var(--text-muted); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-card-meta { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-top: .25rem; }
.note-card-date { font-size: .72rem; color: var(--text-muted); margin-left: auto; }
.note-tag-chip {
  font-size: .7rem; font-weight: 600;
  background: #eff6ff; color: var(--primary);
  padding: .15rem .45rem; border-radius: 999px;
  cursor: pointer;
}
.note-tag-chip:hover { background: #dbeafe; }

/* Note view */
.memo-view-header {
  padding: 1.5rem 1.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-panel);
}
.memo-view-title { font-size: 1.6rem; font-weight: 800; color: var(--text-main); margin-bottom: .5rem; line-height: 1.2; }
.memo-view-meta { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; font-size: .8rem; color: var(--text-muted); }
.memo-view-actions { display: flex; gap: .5rem; margin-left: auto; }
.memo-content-area {
  padding: 1.5rem 1.75rem;
  background: var(--bg-panel);
  margin: 1rem 1.5rem;
  border: 1px solid var(--border-light);
  border-radius: 12px;
}
.memo-content-area.empty { color: var(--text-muted); font-style: italic; }

/* Markdown rendered content */
.md-body { color: var(--text-main); line-height: 1.7; font-size: .95rem; }
.md-body h1,.md-body h2,.md-body h3,.md-body h4 { font-weight: 700; margin: 1.25em 0 .5em; line-height: 1.3; color: var(--text-main); }
.md-body h1 { font-size: 1.5rem; }
.md-body h2 { font-size: 1.25rem; }
.md-body h3 { font-size: 1.05rem; }
.md-body p { margin: .75em 0; }
.md-body ul,.md-body ol { padding-left: 1.5rem; margin: .75em 0; }
.md-body li { margin: .25em 0; }
.md-body code { font-family: monospace; background: #f1f5f9; color: #c7254e; padding: .1em .35em; border-radius: 4px; font-size: .88em; }
.md-body pre { background: #1e293b; color: #e2e8f0; padding: 1rem; border-radius: 8px; overflow-x: auto; margin: 1em 0; }
.md-body pre code { background: none; color: inherit; padding: 0; }
.md-body blockquote { border-left: 3px solid var(--primary); margin: 1em 0; padding: .5em 1em; background: #eff6ff; color: var(--text-muted); border-radius: 0 6px 6px 0; }
.md-body a { color: var(--primary); }
.md-body hr { border: none; border-top: 1px solid var(--border-light); margin: 1.5em 0; }
.md-body table { width: 100%; border-collapse: collapse; margin: 1em 0; }
.md-body table th { background: #f8fafc; text-align: left; padding: .5rem .75rem; border: 1px solid var(--border-light); font-weight: 600; }
.md-body table td { padding: .5rem .75rem; border: 1px solid var(--border-light); }
.md-body mark { background: #fef3c7; color: #92400e; padding: .1em .2em; border-radius: 3px; }
.md-body img { max-width: 100%; border-radius: 8px; margin: .5em 0; }

/* Attachments */
.memo-attachments { padding: 0 1.5rem 1.5rem; }
.memo-att-section { margin-bottom: 1.25rem; }
.memo-att-title { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: .6rem; }
.att-img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .6rem; }
.att-img-item { position: relative; border-radius: 8px; overflow: hidden; aspect-ratio: 1; background: #f1f5f9; cursor: pointer; }
.att-img-item img { width: 100%; height: 100%; object-fit: cover; }
.att-img-item .att-del { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.5); color: #fff; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: .75rem; cursor: pointer; display: none; line-height: 1; }
.att-img-item:hover .att-del { display: flex; align-items: center; justify-content: center; }
.att-file-list { display: flex; flex-direction: column; gap: .4rem; }
.att-file-item { display: flex; align-items: center; gap: .6rem; padding: .4rem .7rem; background: var(--bg-panel); border: 1px solid var(--border-light); border-radius: 8px; font-size: .82rem; }
.att-file-item a { color: var(--primary); flex: 1; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file-item a:hover { text-decoration: underline; }
.att-file-size { color: var(--text-muted); font-size: .72rem; white-space: nowrap; }
.att-url-list { display: flex; flex-direction: column; gap: .4rem; }
.att-url-item { display: flex; align-items: center; gap: .6rem; padding: .4rem .7rem; background: var(--bg-panel); border: 1px solid var(--border-light); border-radius: 8px; font-size: .82rem; }
.att-url-item a { color: var(--primary); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Edit form */
.memo-edit-area { padding: 1.25rem 1.5rem; }
.memo-edit-form { background: var(--bg-panel); border: 1px solid var(--border-light); border-radius: 12px; padding: 1.5rem; }
.form-group { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1.1rem; }
.form-label { font-size: .82rem; font-weight: 600; color: var(--text-muted); }
.form-control { background: #fff; border: 1px solid var(--border-light); color: var(--text-main); border-radius: 8px; padding: .5rem .75rem; font-size: .875rem; width: 100%; outline: none; transition: border-color .15s, box-shadow .15s; font-family: inherit; }
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.1); }
.form-control::placeholder { color: #cbd5e1; }
.edit-split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.edit-textarea { font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace; font-size: .82rem; min-height: 320px; resize: vertical; line-height: 1.6; }
.md-preview-box { min-height: 320px; padding: .75rem 1rem; background: #fafafa; border: 1px solid var(--border-light); border-radius: 8px; overflow-y: auto; }
.tags-input-wrap { display: flex; flex-wrap: wrap; gap: .35rem; padding: .35rem .6rem; border: 1px solid var(--border-light); border-radius: 8px; background: #fff; min-height: 42px; align-items: center; cursor: text; transition: border-color .15s; }
.tags-input-wrap:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.1); }
.tags-input-wrap input { border: none; outline: none; background: transparent; font-size: .875rem; color: var(--text-main); min-width: 80px; flex: 1; }
.tag-chip { display: inline-flex; align-items: center; gap: .25rem; background: #eff6ff; color: var(--primary); font-size: .78rem; font-weight: 600; padding: .2rem .5rem; border-radius: 999px; }
.tag-chip button { background: none; border: none; cursor: pointer; font-size: .8rem; color: var(--primary); line-height: 1; padding: 0; }
.attach-drop { border: 2px dashed var(--border-light); border-radius: 10px; padding: 1.25rem; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; color: var(--text-muted); font-size: .875rem; }
.attach-drop:hover,.attach-drop.drag-over { border-color: var(--primary); background: #eff6ff; color: var(--primary); }
.attach-preview-list { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
.attach-preview-item { position: relative; }
.attach-preview-item img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border-light); }
.attach-preview-item .rm { position: absolute; top: -6px; right: -6px; background: var(--danger); color: #fff; border: none; border-radius: 50%; width: 18px; height: 18px; font-size: .65rem; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.url-row { display: flex; gap: .5rem; }
.url-row input:first-child { flex: 1.5; }
.url-row input:last-child { flex: 1; }

/* Tags autocomplete */
.tags-suggestions { position: absolute; z-index: 100; background: var(--bg-panel); border: 1px solid var(--border-light); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,.1); max-height: 160px; overflow-y: auto; min-width: 160px; }
.tags-suggestions div { padding: .4rem .75rem; cursor: pointer; font-size: .82rem; color: var(--text-main); }
.tags-suggestions div:hover { background: var(--bg-page); }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 10000; display: none; align-items: center; justify-content: center; cursor: zoom-out; }
.lightbox.show { display: flex; }
.lightbox img { max-width: 90vw; max-height: 90vh; border-radius: 8px; object-fit: contain; }

/* Empty state */
.memo-empty { text-align: center; padding: 4rem 2rem; color: var(--text-muted); }
.memo-empty .icon { font-size: 3rem; opacity: .3; margin-bottom: 1rem; }

/* Btns */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .9rem; border-radius: 8px; font-size: .875rem; font-weight: 500; cursor: pointer; border: 1px solid transparent; transition: all .15s; white-space: nowrap; }
.btn-primary  { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-secondary { background: var(--bg-panel); color: var(--text-main); border-color: var(--border-light); }
.btn-secondary:hover { background: var(--bg-page); }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: .28rem .65rem; font-size: .8rem; }

/* Toast */
.memo-toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; }
.memo-toast { background: var(--bg-panel); border: 1px solid var(--border-light); border-radius: 10px; padding: .7rem 1rem; font-size: .875rem; min-width: 200px; color: var(--text-main); box-shadow: 0 4px 16px rgba(0,0,0,.12); border-left: 4px solid var(--primary); animation: toastIn .2s ease; }
.memo-toast.error { border-left-color: var(--danger); }
@keyframes toastIn { from { opacity:0;transform:translateX(16px); } to { opacity:1;transform:none; } }

/* Responsive */
@media (max-width: 768px) {
  .memo-layout { grid-template-columns: 1fr; height: auto; }
  .memo-sidebar { display: none; }
  .memo-sidebar.open { display: flex; position: fixed; inset: 0; z-index: 200; width: 260px; height: 100vh; box-shadow: 4px 0 20px rgba(0,0,0,.2); }
  .edit-split { grid-template-columns: 1fr; }
  .notes-grid { grid-template-columns: 1fr; padding: 1rem; }
  .memo-view-header { padding: 1rem; }
  .memo-content-area { margin: .75rem; }
  .memo-attachments { padding: 0 .75rem .75rem; }
  .memo-edit-area { padding: .75rem; }
}

/* Dark mode */
[data-theme="dark"] .memo-sidebar { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .memo-sidebar-top { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .memo-search { background: var(--bg-page); border-color: var(--border-light); }
[data-theme="dark"] .memo-search input { color: var(--text-main); }
[data-theme="dark"] .memo-tag-item { color: var(--text-muted); }
[data-theme="dark"] .memo-tag-item:hover { background: var(--bg-page); }
[data-theme="dark"] .memo-tag-item.active { background: rgba(59,130,246,.15); color: var(--primary); }
[data-theme="dark"] .memo-main { background: var(--bg-page); }
[data-theme="dark"] .memo-list-header { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .note-card { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .note-card:hover { border-color: var(--primary); }
[data-theme="dark"] .note-card-title { color: var(--text-main); }
[data-theme="dark"] .memo-view-header { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .memo-content-area { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .md-body code { background: #1c2128; color: #f87171; }
[data-theme="dark"] .md-body blockquote { background: rgba(59,130,246,.08); }
[data-theme="dark"] .md-body table th { background: #1c2128; border-color: var(--border-light); }
[data-theme="dark"] .md-body table td { border-color: var(--border-light); }
[data-theme="dark"] .att-file-item,.att-url-item { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .memo-edit-form { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .form-control { background: #1c2128; border-color: var(--border-light); color: var(--text-main); }
[data-theme="dark"] .tags-input-wrap { background: #1c2128; border-color: var(--border-light); }
[data-theme="dark"] .md-preview-box { background: #1c2128; border-color: var(--border-light); }
[data-theme="dark"] .attach-drop { border-color: var(--border-light); }
[data-theme="dark"] .attach-drop:hover,.attach-drop.drag-over { background: rgba(59,130,246,.1); }
[data-theme="dark"] .btn-secondary { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .btn-secondary:hover { background: rgba(255,255,255,.06); }
[data-theme="dark"] .tags-suggestions { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .tags-suggestions div:hover { background: var(--bg-page); }
[data-theme="dark"] .memo-toast { background: var(--bg-panel); border-color: var(--border-light); color: var(--text-main); }
