/* ═══════════════════════════════════════════════════════════
   Notes Panel — Obsidian-like layout
   ═══════════════════════════════════════════════════════════ */

.notes-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: calc(100% - 60px);
  overflow: hidden;
}

/* ── Sidebar tree ─────────────────────────────────────── */

.notes-sidebar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.notes-search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.notes-search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13px;
}

.notes-tree {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.notes-tree-folder {
  user-select: none;
}

.notes-tree-folder-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 4px;
  margin: 0 4px;
  transition: background .12s;
}

.notes-tree-folder-row:hover {
  background: var(--bg-2);
}

.notes-tree-folder-row .folder-actions {
  margin-left: auto;
  display: none;
  gap: 2px;
}

.notes-tree-folder-row:hover .folder-actions {
  display: inline-flex;
}

.notes-tree-children {
  padding-left: 12px;
}

.notes-tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  border-radius: 4px;
  margin: 1px 4px;
  transition: background .12s;
  position: relative;
}

.notes-tree-item:hover {
  background: var(--bg-2);
}

.notes-tree-item.active {
  background: var(--accent-muted, rgba(99, 102, 241, .12));
  color: var(--accent);
}

.notes-tree-item .item-actions {
  margin-left: auto;
  display: none;
  gap: 2px;
}

.notes-tree-item:hover .item-actions {
  display: inline-flex;
}

.notes-tree-item .pin-marker {
  position: absolute;
  right: 6px;
  top: 4px;
  opacity: .35;
}

.notes-tree-root-label {
  padding: 6px 12px 2px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  font-weight: 600;
}

.notes-color-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Editor pane ──────────────────────────────────────── */

.notes-editor-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.notes-editor-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
}

.notes-editor-active {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.notes-editor-header {
  padding: 12px 16px 0;
  flex-shrink: 0;
}

.notes-title-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  padding: 0;
  margin-bottom: 8px;
}

.notes-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.notes-meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.notes-tags-area,
.notes-links-area {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 150px;
}

.notes-tags-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 12px;
}

.notes-link-select {
  flex: 1;
  background: var(--bg-secondary, #1e1e2e);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  padding: 3px 6px;
  max-width: 200px;
}

.notes-linked-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.notes-linked-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--accent-muted, rgba(99, 102, 241, .12));
  color: var(--accent);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  cursor: default;
}

.notes-linked-badge .remove-link {
  cursor: pointer;
  opacity: .5;
  margin-left: 2px;
}

.notes-linked-badge .remove-link:hover {
  opacity: 1;
}

.notes-md-editor {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 14px;
  line-height: 1.7;
  padding: 16px;
  tab-size: 4;
  overflow-y: auto;
}

.notes-preview {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  line-height: 1.7;
  color: var(--text-primary);
  cursor: text;
  min-height: 120px;
}

.notes-preview:empty::before {
  content: 'Нажмите, чтобы начать редактирование...';
  color: var(--text-3);
  font-style: italic;
  pointer-events: none;
}

.notes-rich-editor {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
  outline: none;
  min-height: 120px;
  background: transparent;
}

.notes-rich-editor:empty::before {
  content: 'Начните вводить текст...';
  color: var(--text-3);
  font-style: italic;
  pointer-events: none;
}

.notes-rich-editor h1,
.notes-rich-editor h2,
.notes-rich-editor h3 {
  margin: 16px 0 8px;
  color: var(--accent);
}

.notes-rich-editor p {
  margin: 0 0 8px;
}

.notes-rich-editor ul,
.notes-rich-editor ol {
  padding-left: 24px;
  margin: 4px 0 8px;
}

.notes-rich-editor blockquote {
  border-left: 3px solid var(--accent);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--text-2);
  font-style: italic;
}

.notes-rich-editor code {
  background: var(--bg-3);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85em;
}

.notes-preview h1,
.notes-preview h2,
.notes-preview h3 {
  margin: 16px 0 8px;
  color: var(--accent);
}

.notes-preview h1 {
  font-size: 1.6rem;
}

.notes-preview h2 {
  font-size: 1.3rem;
}

.notes-preview h3 {
  font-size: 1.1rem;
}

.notes-preview p {
  margin: 0 0 10px;
}

.notes-preview ul,
.notes-preview ol {
  padding-left: 24px;
  margin: 0 0 10px;
}

.notes-preview blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 12px;
  margin: 8px 0;
  opacity: .85;
}

.notes-preview code {
  background: var(--bg-2);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 13px;
}

.notes-preview pre {
  background: var(--bg-2);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
}

.notes-preview pre code {
  background: none;
  padding: 0;
}

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

.notes-preview input[type="checkbox"] {
  margin-right: 6px;
}

.notes-save-indicator {
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 16px 8px;
  text-align: right;
  flex-shrink: 0;
}

/* Back button — hidden on desktop */
.notes-mobile-back {
  display: none;
}

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
  .notes-layout {
    grid-template-columns: 1fr;
    height: calc(100vh - 120px);
    height: calc(100dvh - 120px);
  }

  /* By default: show sidebar, hide editor */
  .notes-sidebar {
    max-height: none;
    height: 100%;
    border-right: none;
    border-bottom: none;
  }

  .notes-editor-pane {
    display: none;
  }

  /* When editing: hide sidebar, show editor */
  .notes-layout.notes-editing .notes-sidebar {
    display: none;
  }

  .notes-layout.notes-editing .notes-editor-pane {
    display: flex;
    height: 100%;
  }

  /* Back button */
  .notes-mobile-back {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--accent);
    font-size: .85rem;
    font-weight: 500;
    padding: 8px 12px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  .notes-mobile-back:active {
    opacity: .7;
  }

  /* Touch-friendly tree items */
  .notes-tree-item {
    padding: 10px 12px 10px 14px;
    font-size: 14px;
    gap: 8px;
  }

  .notes-tree-folder-row {
    padding: 10px 12px;
    font-size: 14px;
  }

  /* Always show actions on touch */
  .notes-tree-item .item-actions {
    display: inline-flex;
  }

  .notes-tree-folder-row .folder-actions {
    display: inline-flex;
  }

  /* Editor header compact */
  .notes-editor-header {
    padding: 8px 12px 0;
  }

  .notes-title-input {
    font-size: 1.15rem;
    margin-bottom: 6px;
  }

  /* Toolbar scrollable */
  .notes-editor-toolbar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    gap: 1px;
    padding: 4px 0;
    scrollbar-width: none;
  }

  .notes-editor-toolbar::-webkit-scrollbar {
    display: none;
  }

  .notes-editor-toolbar .btn {
    flex-shrink: 0;
    min-width: 32px;
    min-height: 32px;
  }

  /* Meta bar compact */
  .notes-meta-bar {
    padding: 6px 12px;
    gap: 6px;
    flex-direction: column;
  }

  .notes-tags-area,
  .notes-links-area {
    min-width: 0;
  }

  .notes-link-select {
    max-width: none;
  }

  /* Editor area */
  .notes-md-editor {
    padding: 12px;
    font-size: 14px;
  }

  .notes-rich-editor {
    padding: 12px;
    font-size: 14px;
  }

  .notes-preview {
    padding: 12px;
  }
}

/* ═══════════════════════════════════════════════════════════
   Settings Modal
   ═══════════════════════════════════════════════════════════ */

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(4px);
  animation: modalFadeIn 0.2s ease;
}

.settings-box {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 680px;
  max-width: 95vw;
  height: 520px;
  max-height: 90vh;
  display: flex;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}

/* — Sidebar — */
.settings-sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 0;
}

.settings-sidebar-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  padding: 0 16px 12px;
}

.settings-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  font-size: 0.88rem;
  color: var(--text-2);
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  font-family: var(--font);
}

.settings-nav-item:hover {
  background: var(--bg-3);
  color: var(--text-1);
}

.settings-nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.settings-nav-item i,
.settings-nav-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* — Content — */
.settings-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border);
}

.settings-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-1);
  margin: 0;
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.settings-section {
  display: none;
}

.settings-section.active {
  display: block;
}

.settings-group {
  margin-bottom: 22px;
}

.settings-group-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-bottom: 12px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-row-label {
  font-size: 0.9rem;
  color: var(--text-1);
  font-weight: 500;
}

.settings-row-desc {
  font-size: 0.78rem;
  color: var(--text-3);
}

.settings-row .input {
  width: 200px;
}

.settings-row select.input {
  width: 200px;
}

.settings-row textarea.input {
  width: 200px;
  min-height: 60px;
  resize: vertical;
}

/* Toggle switch */
.settings-toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.settings-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.settings-toggle-track {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--bg-4);
  border-radius: 11px;
  transition: background var(--transition);
}

.settings-toggle-track::before {
  content: '';
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: var(--text-2);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}

.settings-toggle input:checked+.settings-toggle-track {
  background: var(--accent);
}

.settings-toggle input:checked+.settings-toggle-track::before {
  transform: translateX(18px);
  background: #fff;
}

/* Danger zone */
.settings-danger-zone {
  margin-top: 24px;
  padding: 16px;
  border: 1px solid var(--red-dim);
  border-radius: var(--radius-md);
  background: rgba(248, 113, 113, 0.04);
}

.settings-danger-zone h4 {
  color: var(--red);
  font-size: 0.88rem;
  font-weight: 600;
  margin: 0 0 8px;
}

.settings-danger-zone p {
  font-size: 0.8rem;
  color: var(--text-3);
  margin: 0 0 12px;
}

/* Footer */
.settings-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 24px;
  border-top: 1px solid var(--border);
}

/* Responsive */
@media (max-width: 600px) {
  .settings-box {
    flex-direction: column;
    height: 90vh;
  }

  .settings-sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px;
  }

  .settings-nav-item {
    white-space: nowrap;
    padding: 8px 12px;
  }

  .settings-sidebar-title {
    display: none;
  }
}

/* ── App Toast Notification System ──────────────────────── */
#app-toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: 420px;
  width: calc(100% - 48px);
}

.app-toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--text-1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(12px);
  pointer-events: auto;
  transform: translateX(calc(100% + 32px));
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.21, 1.02, 0.73, 1), opacity 0.25s ease;
  overflow: hidden;
}

.app-toast--visible {
  transform: translateX(0);
  opacity: 1;
}

.app-toast--exit {
  transform: translateX(calc(100% + 32px));
  opacity: 0;
  transition: transform 0.3s ease-in, opacity 0.2s ease-in;
}

/* Цветовое кодирование — акцентная полоска слева */
.app-toast::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.app-toast--info::before {
  background: var(--accent);
}

.app-toast--error::before {
  background: #ef4444;
}

.app-toast--success::before {
  background: #22c55e;
}

.app-toast--warning::before {
  background: #f59e0b;
}

.app-toast--info .app-toast__icon {
  color: var(--accent);
}

.app-toast--error .app-toast__icon {
  color: #ef4444;
}

.app-toast--success .app-toast__icon {
  color: #22c55e;
}

.app-toast--warning .app-toast__icon {
  color: #f59e0b;
}

.app-toast__icon {
  flex-shrink: 0;
  margin-top: 1px;
}

.app-toast__msg {
  flex: 1;
  word-break: break-word;
}

.app-toast__close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0 0 0 8px;
  line-height: 1;
  transition: color 0.15s;
}

.app-toast__close:hover {
  color: var(--text-1);
}

@media (max-width: 600px) {
  #app-toast-container {
    top: 12px;
    right: 12px;
    max-width: calc(100% - 24px);
    width: calc(100% - 24px);
  }

  .app-toast {
    font-size: 0.82rem;
    padding: 12px 14px;
  }
}

.settings-row {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.settings-row .input,
.settings-row select.input,
.settings-row textarea.input {
  width: 100%;
}
