/*
 * notes.css — Notes tab: sidebar, editor, preview, and rendered markdown.
 */

/* --- Container --- */

.notes {
  display: flex;
  flex-direction: row;
  height: 100%;
  overflow: hidden;
}

/* --- Sidebar --- */

.notes__sidebar {
  width: 220px;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg);
  transition: width 0.2s ease, min-width 0.2s ease;
}

.notes__actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem 0.5rem 0.25rem;
}

.notes__new-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex-shrink: 0;
  padding: 0;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}

.notes__new-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.notes__search {
  margin: 0.5rem 0.5rem 0.25rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition);
}

.notes__search:focus {
  border-color: var(--accent);
}

.notes__list {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0.5rem;
}

/* Collapsed sidebar: thin rail with just the expand button */
.notes__sidebar--collapsed {
  width: 36px;
  min-width: 36px;
}

.notes__sidebar--collapsed .notes__search,
.notes__sidebar--collapsed .notes__list {
  display: none;
}

.notes__sidebar--collapsed .notes__actions {
  flex-direction: column;
  padding: 0.25rem;
  gap: 0.25rem;
}

.notes__sidebar--collapsed .notes__actions .notes__new-btn:not(.notes__collapse-btn) {
  display: none;
}

.notes__row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--transition);
}

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

.notes__row--active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

.notes__row--active:hover {
  background: var(--accent-soft);
}

.notes__row-caret {
  width: 1rem;
  flex-shrink: 0;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Folders get a distinct look: folder glyph + semibold label + accent bar */
.notes__row--folder .notes__row-caret {
  font-size: 0.75rem;
}

.notes__row--folder .notes__row-label {
  font-weight: 600;
}

.notes__row--folder {
  border-left: 2px solid var(--accent);
}

.notes__row-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notes__row-badge {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 0.35rem;
  line-height: 1.3;
}

.notes__row-actions {
  display: none;
  gap: 0.1rem;
  flex-shrink: 0;
}

.notes__row:hover .notes__row-actions,
.notes__row:focus-within .notes__row-actions {
  display: inline-flex;
}

.notes__row-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1;
  padding: 0.15rem 0.25rem;
  border-radius: var(--radius-xs);
}

.notes__row-btn:hover {
  background: var(--border);
  color: var(--text);
}

.notes__row-btn--delete:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* --- Rename / delete overlays --- */

.notes__overlay-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.notes__overlay-msg {
  font-size: 0.875rem;
  color: var(--text);
  line-height: 1.5;
}

/* --- Drag & drop --- */

.notes__row--dragging {
  opacity: 0.5;
}

.notes__row--droppable {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  background: var(--accent-soft);
}

.notes__list--droppable {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

/* Grip handle: touch drag source (mobile only). Hidden on desktop, where the
   whole row is the HTML5 drag source. touch-action:none lets pointer events
   drive the drag instead of scrolling the sidebar. */
.notes__row-grip {
  display: none;
  flex-shrink: 0;
  touch-action: none;
  cursor: grab;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1;
  padding: 0.1rem 0.15rem;
  border-radius: var(--radius-xs);
}

@media (max-width: 768px) {
  .notes__row-grip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* Floating ghost while touch-dragging a note/folder row. pointer-events:none
   so elementFromPoint resolves the row beneath it. */
.notes__row--touch-ghost {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.9;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  cursor: grabbing;
}

.notes__list-empty {
  padding: 0.75rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
  text-align: center;
}

/* --- Content area --- */

.notes__content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.notes__breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  min-height: 1rem;
  margin: 0.5rem 1.5rem 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.notes__breadcrumb-part {
  color: var(--text-muted);
}

.notes__breadcrumb-part:last-child {
  color: var(--text);
  font-weight: 500;
}

.notes__breadcrumb-sep {
  color: var(--text-muted);
  opacity: 0.6;
}

.notes__title {
  display: block;
  width: 100%;
  padding: 0.75rem 1.5rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  outline: none;
}

.notes__title::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.notes__title-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.notes__title-row .notes__title {
  border-bottom: none;
  flex: 1;
}

.notes__title-actions {
  display: flex;
  gap: 0.25rem;
  padding-right: 0.75rem;
  flex-shrink: 0;
}

.notes__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Preview --- */

.notes__preview {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  cursor: text;
  line-height: 1.6;
}

.notes__preview:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}

.notes__empty {
  color: var(--text-muted);
  font-style: italic;
}

/* --- Editor --- */

.notes__editor {
  flex: 1;
  width: 100%;
  padding: 1.5rem;
  border: none;
  background: var(--surface);
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  resize: none;
  outline: none;
}

.notes__editor:focus {
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

/* --- Rendered Markdown --- */

.notes__preview h1 {
  font-size: 1.5rem;
  margin: 1.5rem 0 0.5rem;
  line-height: 1.3;
}

.notes__preview h2 {
  font-size: 1.25rem;
  margin: 1.25rem 0 0.4rem;
  line-height: 1.3;
}

.notes__preview h3 {
  font-size: 1.1rem;
  margin: 1rem 0 0.3rem;
  line-height: 1.3;
}

.notes__preview h1:first-child,
.notes__preview h2:first-child,
.notes__preview h3:first-child {
  margin-top: 0;
}

.notes__preview p {
  margin: 0.5rem 0;
}

.notes__preview a {
  color: var(--accent);
  text-decoration: underline;
}

.notes__preview a:hover {
  opacity: 0.8;
}

.notes__preview ul,
.notes__preview ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.notes__preview li {
  margin: 0.2rem 0;
}

/* Task lists */

.notes__preview .md-tasks {
  list-style: none;
  padding-left: 0.25rem;
}

.notes__preview .md-task {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0.3rem 0;
}

.notes__preview .md-task__check {
  width: 1rem;
  height: 1rem;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.notes__preview .md-task__check:checked + span {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* Blockquote */

.notes__preview blockquote {
  margin: 0.75rem 0;
  padding: 0.5rem 1rem;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Code */

.notes__preview code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
}

.notes__preview pre {
  margin: 0.75rem 0;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.notes__preview pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1.5;
}
