:root {
  --knowledge-border: rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --knowledge-border: rgba(255,255,255,0.08);
}

.knowledge-wrap {
  padding: 25px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

#knowledge-mindmap-container {
  width: 100%;
  height: 500px;
  position: relative;
  background: var(--color-bg-canvas, #f9fafb);
  border-radius: 16px;
  border: 1px solid var(--knowledge-border);
  overflow: hidden;
  margin-bottom: 20px;
}

[data-theme="dark"] #knowledge-mindmap-container {
  background: #0b1220;
}

.knowledge-folder-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.knowledge-back {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--knowledge-border);
  background: var(--color-card-bg, #ffffff);
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

[data-theme="dark"] .knowledge-back {
  background: #0b1220;
}

.knowledge-back svg {
  width: 18px;
  height: 18px;
}

.knowledge-folder-title {
  min-width: 0;
  flex: 1;
}

.knowledge-folder-title h1 {
  margin: 0 0 4px 0;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--color-text, #111827);
}

@media (max-width: 768px) {
  .knowledge-folder-title h1 {
    font-size: 22px;
  }
}

.knowledge-folder-sub {
  margin: 6px 0;
  font-size: 13px;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


.knowledge-btn-danger {
  border-color: rgba(239, 68, 68, 0.35);
  color: #b91c1c;
}

[data-theme="dark"] .knowledge-btn-danger {
  border-color: rgba(239, 68, 68, 0.35);
  color: #fecaca;
}

.knowledge-files {
  display: flex;
  flex-direction: column;
}

.knowledge-file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 4px;
  border-radius: 14px;
  border: 1px solid transparent;
}

.knowledge-file-row:hover {
  border-color: var(--knowledge-border);
  background: rgba(0,0,0,0.03);
}

[data-theme="dark"] .knowledge-file-row:hover {
  background: rgba(255,255,255,0.04);
}

.knowledge-file-left {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.knowledge-file-name {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.knowledge-file-meta {
  font-size: 12px;
  opacity: 0.75;
  display: flex;
  gap: 10px;
}

.knowledge-file-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.knowledge-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 6px;
}

.knowledge-title h1 {
  margin: 0 0 4px 0;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--color-text, #111827);
}

.knowledge-subtitle {
  margin-top: 6px;
  font-size: 14px;
  color: var(--color-text-muted, #6b7280);
}

.knowledge-actions {
  display: flex;
  gap: 8px;
}

.knowledge-btn {
  appearance: none;
  border: 1px solid var(--knowledge-border);
  background: var(--color-card-bg, #f7f7f7);
  color: var(--color-text, #111827);
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

[data-theme="dark"] .knowledge-btn {
  background: #0b1220;
  color: #e5e7eb;
}

.knowledge-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.knowledge-search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  border: 1px solid var(--knowledge-border);
  background: var(--color-card-bg, #ffffff);
  border-radius: 14px;
  padding: 10px 12px;
}

[data-theme="dark"] .knowledge-search {
  background: #0b1220;
}

.knowledge-search svg {
  width: 16px;
  height: 16px;
  opacity: 0.65;
}

.knowledge-search input {
  border: 0;
  outline: none;
  background: transparent;
  width: 100%;
  color: inherit;
  font-size: 14px;
}

.knowledge-card {
  position: relative;
  border: 1px solid var(--knowledge-border);
  border-radius: 18px;
  background: var(--color-card-bg, #ffffff);
  padding: 8px;
}

.knowledge-card-controls {
  position: absolute;
  top: 8px;
  right: 30px;
  display: flex;
  gap: 4px;
  z-index: 10;
}

.k-ctrl-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--knowledge-border);
  border-radius: 8px;
  background: var(--color-card-bg, #ffffff);
  color: var(--color-text-muted, #6b7280);
  cursor: pointer;
  padding: 6px;
  transition: all 0.2s;
}

[data-theme="dark"] .k-ctrl-btn {
  background: #1f2937;
  color: #e5e7eb;
}

.k-ctrl-btn:hover {
  background: var(--color-bg-hover, #f3f4f6);
  color: var(--color-primary, #2563eb);
}

[data-theme="dark"] .k-ctrl-btn:hover {
  background: #374151;
  color: #60a5fa;
}

.k-ctrl-btn svg {
  width: 16px;
  height: 16px;
}

[data-theme="dark"] .knowledge-card {
  background: #0b1220;
}

.knowledge-loading {
  padding: 10px;
  font-size: 13px;
  opacity: 0.8;
}

.knowledge-empty {
  padding: 20px 12px;
  text-align: center;
}

.knowledge-empty-title {
  font-weight: 700;
}

.knowledge-empty-subtitle {
  margin-top: 6px;
  font-size: 13px;
  opacity: 0.75;
}

.knowledge-empty .knowledge-btn {
  margin-top: 12px;
}

.knowledge-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.knowledge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px;
  border-radius: 14px;
  cursor: pointer;
  border: 1px solid transparent;
}

.knowledge-row:hover {
  border-color: var(--knowledge-border);
  background: rgba(0,0,0,0.03);
}

[data-theme="dark"] .knowledge-row:hover {
  background: rgba(255,255,255,0.04);
}

.knowledge-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.knowledge-row-name {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.knowledge-row-desc {
  font-size: 12px;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.knowledge-row-meta {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-shrink: 0;
  font-size: 12px;
  opacity: 0.75;
  width: 320px;
}

.knowledge-meta-item {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.knowledge-meta-count {
  width: 80px;
}

.knowledge-meta-size {
  width: 80px;
}

.knowledge-meta-time {
  width: 100px;
  text-align: right;
}

.knowledge-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.knowledge-icon-btn {
  appearance: none;
  border: 1px solid var(--knowledge-border);
  background: transparent;
  color: inherit;
  border-radius: 10px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.hidden { display: none !important; }

.knowledge-text-content {
  padding: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 70vh;
  overflow-y: auto;
  font-family: var(--font-mono, monospace);
  background: var(--color-bg, #ffffff);
  border-radius: 12px;
}

[data-theme="dark"] .knowledge-text-content {
  background: #0b1220;
}

@media (max-width: 768px) {
  .knowledge-wrap {
    padding: 30px 15px;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .knowledge-wrap:has(#knowledge-mindmap-container:not([style*="display:none"]):not([style*="display: none"])) {
    padding: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  #knowledge-mindmap-container {
    height: calc(100vh - 120px) !important;
    min-height: 500px;
    width: 100% !important;
  }

  .ai-container:has(#knowledge-mindmap-container:not([style*="display:none"]):not([style*="display: none"])) .ai-main-content {
    height: 100vh !important;
    overflow: hidden !important;
  }

  .knowledge-top {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .knowledge-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .knowledge-actions .knowledge-btn {
    min-height: 52px;
    justify-content: center;
  }

  .knowledge-actions .knowledge-btn-orange {
    grid-column: 1 / -1;
  }

  #knowledge-memories-view .knowledge-folder-top {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    position: relative;
    padding-top: 0;
  }

  #knowledge-memories-view .knowledge-back {
    position: fixed;
    top: 10px;
    right: 10px;
    left: auto;
    width: 44px;
    height: 44px;
    z-index: 4500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  }

  #knowledge-memories-view .knowledge-folder-actions {
    width: auto;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
  }

  #knowledge-memories-view .knowledge-folder-actions .knowledge-btn {
    min-height: 44px;
    width: auto;
    padding: 10px 14px;
    justify-content: center;
  }

  #knowledge-memories-view .knowledge-folder-title h1 {
    margin: 0 0 2px 0;
  }

  #knowledge-memories-view .knowledge-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  #knowledge-memories-view .knowledge-search {
    min-width: 0 !important;
    width: 100%;
  }

  #knowledge-memories-view .memory-filter-select {
    width: 100%;
    min-height: 44px;
    flex: none;
  }

  .knowledge-back {
    position: fixed;
    top: 10px;
    right: 10px;
    width: 44px;
    height: 44px;
    z-index: 5001;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  }

  #knowledge-text-view {
    margin-top: 30px;
  }
}

/* Selection Toolbar */
.selection-toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-bg-panel, #ffffff);
  border-top: 1px solid var(--color-border, #e5e7eb);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  z-index: 2000;
  padding: 12px 20px;
  transform: translateY(0);
  transition: transform 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.selection-toolbar.hidden {
  transform: translateY(100%);
  pointer-events: none;
}

.selection-toolbar-content {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1200px;
  width: 100%;
}

.selection-count {
  font-weight: 600;
  color: var(--color-text, #111827);
  flex: 1;
}

.selection-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.selection-toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--color-border, #e5e7eb);
  background: var(--color-bg-panel, #fff);
  color: var(--color-text, #374151);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s ease;
}

.selection-toolbar-btn:hover {
  background: rgba(0,0,0,0.03);
}

.selection-toolbar-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.selection-toolbar-btn.text-btn {
  border: none;
  background: transparent;
  padding: 10px 12px;
}

.selection-toolbar-btn.danger {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

.selection-toolbar-btn.danger:hover:not(:disabled) {
  background: #b91c1c;
}

[data-theme='dark'] .selection-toolbar {
  background: #1f2937;
  border-color: #374151;
}

[data-theme='dark'] .selection-count {
  color: #e5e7eb;
}

[data-theme='dark'] .selection-toolbar-btn {
  background: #1f2937;
  border-color: #374151;
  color: #e5e7eb;
}

[data-theme='dark'] .selection-toolbar-btn:hover {
  background: rgba(255,255,255,0.06);
}

@media (max-width: 768px) {
  .selection-toolbar-btn span {
    display: none;
  }
  .selection-toolbar-btn {
    padding: 10px;
  }
  .selection-toolbar-content {
    gap: 8px;
  }
}

/* ── Interest Cards Grid ── */
.interest-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--knowledge-border, #e5e7eb);
    transition: border-color 0.2s, box-shadow 0.2s;
    user-select: none;
    cursor: grab;
    touch-action: pan-y; /* Allow vertical scroll by default, overridden by JS during drag */
}

.interest-card:active {
    cursor: grabbing;
}

.knowledge-tree-row {
    position: relative;
    margin-left: calc(var(--tree-depth, 0) * 20px);
}

.knowledge-tree-row::before {
    content: '';
    position: absolute;
    left: calc(-10px + var(--tree-depth, 0) * 0px);
    top: -6px;
    bottom: -6px;
    width: 1px;
    background: rgba(148, 163, 184, 0.25);
    display: none;
}

.knowledge-tree-row.is-child::before { display: block; }

.knowledge-tree-caret {
    appearance: none;
    border: 1px solid transparent;
    background: transparent;
    color: inherit;
    width: 24px;
    height: 24px;
    min-width: 24px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-top: 2px;
}

.knowledge-tree-caret:hover { background: rgba(0,0,0,0.05); }
.knowledge-tree-caret.is-empty { opacity: 0.35; cursor: default; }

[data-theme="dark"] .knowledge-tree-caret:hover { background: rgba(255,255,255,0.08); }

.knowledge-tree-row-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    display: inline-flex;
    gap: 6px;
}

.knowledge-tree-action-btn {
    appearance: none;
    border: 1px solid var(--knowledge-border, #e5e7eb);
    background: var(--color-bg-panel, #fff);
    color: inherit;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transform: translateY(-2px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.knowledge-tree-action-btn-move {
    width: auto;
    min-width: 26px;
    padding: 0 8px;
    gap: 4px;
}

.knowledge-tree-action-btn-delete:hover {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.4);
}

.knowledge-tree-row:hover .knowledge-tree-action-btn,
.knowledge-tree-row:focus-within .knowledge-tree-action-btn {
    opacity: 1;
    transform: translateY(0);
}

[data-theme="dark"] .knowledge-tree-action-btn {
    background: #111827;
    border-color: #374151;
}

[data-theme="dark"] .knowledge-tree-action-btn-move {
    color: #e5e7eb;
}

.knowledge-tree-row.is-dragging {
    opacity: 0.55;
    cursor: grabbing;
}

.knowledge-tree-row.is-drop-target {
    border-color: #f97316 !important;
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.2);
}

.knowledge-tree-root-drop {
    margin-top: 10px;
    border: 1px dashed var(--knowledge-border, #cbd5e1);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--color-text-muted, #6b7280);
    font-size: 12px;
    text-align: center;
}

.knowledge-tree-root-drop.is-drop-target {
    border-color: #f97316;
    color: #ea580c;
    background: rgba(249, 115, 22, 0.08);
}

.interest-card:hover {
    border-color: #f97316;
    box-shadow: 0 2px 8px rgba(249, 115, 22, 0.1);
}

.interest-card-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.interest-card-icon {
    font-size: 24px;
    line-height: 1;
    flex-shrink: 0;
}

.interest-card-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: inherit;
}

.interest-card-desc {
    margin: 4px 0 0;
    font-size: 13px;
    color: #6b7280;
    line-height: 1.4;
}

[data-theme="dark"] .interest-card-desc {
    color: #9ca3af;
}

.interest-card-stats {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.interest-stat {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #6b7280;
}

.interest-stat svg {
    width: 14px;
    height: 14px;
    opacity: 0.6;
}

[data-theme="dark"] .interest-stat {
    color: #9ca3af;
}

.interest-badge-auto {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-radius: 9999px;
    background: #dbeafe;
    color: #2563eb;
}

[data-theme="dark"] .interest-badge-auto {
    background: #1e3a5f;
    color: #60a5fa;
}

.interest-card-meta {
    font-size: 12px;
    color: #9ca3af;
}

/* ── Memories Section in Interest Detail ── */
.interest-memories-section {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--knowledge-border, #e5e7eb);
}

.interest-memories-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.interest-memories-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.interest-memories-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.interest-memory-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #f9fafb;
    border: 1px solid transparent;
    transition: border-color 0.15s;
}

.interest-memory-card:hover {
    border-color: var(--knowledge-border, #e5e7eb);
}

[data-theme="dark"] .interest-memory-card {
    background: #1f2937;
}

.interest-memory-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.interest-memory-top {
    display: flex;
    align-items: center;
    gap: 8px;
}

.interest-memory-category {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #fff;
    white-space: nowrap;
    flex-shrink: 0;
}

.interest-memory-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
}

.interest-memory-time {
    font-size: 11px;
    color: #9ca3af;
    white-space: nowrap;
    flex-shrink: 0;
}

.interest-memory-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.interest-memory-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--knowledge-border, #e5e7eb);
    background: transparent;
    color: var(--color-text-muted, #6b7280);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.interest-memory-btn:hover {
    background: rgba(0,0,0,0.04);
}

[data-theme="dark"] .interest-memory-btn:hover {
    background: rgba(255,255,255,0.06);
}

.interest-memory-btn-unlink:hover {
    color: #f97316;
    border-color: rgba(249, 115, 22, 0.3);
}

.interest-memory-btn-delete:hover {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.3);
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .knowledge-tree-action-btn,
    .knowledge-tree-row:hover .knowledge-tree-action-btn,
    .knowledge-tree-row:focus-within .knowledge-tree-action-btn {
        opacity: 1;
        transform: translateY(0);
    }

    .interest-card-stats {
        gap: 10px;
    }

    .interest-memory-card {
        flex-direction: column;
        gap: 6px;
    }

    .interest-memory-actions {
        flex-direction: row;
        align-self: flex-end;
    }

    .interest-memory-time {
        align-self: flex-end;
    }
}

/* Interest Move Sheet (fallback when drag/drop is unavailable) */
.interest-move-sheet {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.interest-move-sheet.hidden {
  display: none !important;
}

.interest-move-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.interest-move-panel {
  position: relative;
  width: min(720px, 100%);
  max-height: 84vh;
  background: var(--color-bg-panel, #ffffff);
  border-radius: 20px;
  border: 1px solid var(--knowledge-border, #e5e7eb);
  box-shadow: 0 -12px 40px rgba(0,0,0,0.25);
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

[data-theme='dark'] .interest-move-panel {
  background: #0b1220;
  border-color: #374151;
}

.interest-move-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.interest-move-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.interest-move-close {
  appearance: none;
  border: 1px solid var(--knowledge-border, #e5e7eb);
  background: transparent;
  border-radius: 10px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

[data-theme='dark'] .interest-move-close {
  border-color: #374151;
  color: #e5e7eb;
}

.interest-move-list {
  overflow: auto;
  max-height: 56vh;
  padding: 4px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.interest-move-option {
  appearance: none;
  border: 1px solid var(--knowledge-border, #e5e7eb);
  background: transparent;
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  margin-left: calc(var(--move-depth, 0) * 14px);
}

.interest-move-option-name {
  font-size: 14px;
  font-weight: 600;
}

.interest-move-option-meta {
  font-size: 11px;
  color: var(--color-text-muted, #6b7280);
}

.interest-move-option.is-selected {
  border-color: #f97316;
  box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.22);
  background: rgba(249, 115, 22, 0.07);
}

[data-theme='dark'] .interest-move-option {
  border-color: #374151;
  color: #e5e7eb;
}

[data-theme='dark'] .interest-move-option.is-selected {
  border-color: #fb923c;
  background: rgba(251, 146, 60, 0.16);
}

.interest-move-status {
  min-height: 18px;
  font-size: 12px;
  color: var(--color-text-muted, #6b7280);
}

.interest-move-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 768px) {
  .interest-move-sheet {
    align-items: flex-end;
  }

  .interest-move-panel {
    width: 100%;
    border-radius: 18px 18px 0 0;
    padding: 12px 12px 10px;
  }

  .interest-move-option {
    padding: 12px 12px;
  }
}

/* ── Mindmap / Force-Directed Graph ── */
.mindmap-node {
    cursor: pointer;
}

.mindmap-node:hover {
    filter: brightness(1.1);
}

.mindmap-label {
    font-size: 11px;
    text-anchor: middle;
    fill: #374151;
    pointer-events: none;
}

[data-theme="dark"] .mindmap-label {
    fill: #d1d5db;
}

.mindmap-link {
    stroke: #d1d5db;
    stroke-opacity: 0.6;
}

[data-theme="dark"] .mindmap-link {
    stroke: #4b5563;
}

.mindmap-tooltip {
    position: absolute;
    padding: 8px 12px;
    background: #1f2937;
    color: #fff;
    border-radius: 8px;
    font-size: 12px;
    pointer-events: none;
    z-index: 100;
    white-space: nowrap;
}

.mindmap-empty {
    color: var(--color-text-muted, #6b7280);
}

[data-theme="dark"] .mindmap-empty {
    color: #9ca3af;
}

/* ── Mindmap Back Button ── */
.mindmap-back-btn {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 200;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 10px;
    border: 1px solid var(--knowledge-border, #e5e7eb);
    background: var(--color-card-bg, #ffffff);
    color: var(--color-text, #111827);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: all 0.15s;
}

.mindmap-back-btn:hover {
    background: var(--color-bg-hover, #f3f4f6);
    border-color: #f97316;
    color: #f97316;
}

.mindmap-back-btn svg {
    flex-shrink: 0;
}

[data-theme="dark"] .mindmap-back-btn {
    background: #1f2937;
    color: #e5e7eb;
    border-color: #374151;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

[data-theme="dark"] .mindmap-back-btn:hover {
    background: #374151;
    border-color: #f97316;
    color: #f97316;
}

@media (max-width: 768px) {
    .mindmap-back-btn {
        top: 12px;
        right: 12px;
        left: auto;
        width: auto;
        max-width: calc(100% - 88px);
        min-height: 40px;
        justify-content: center;
        padding: 8px 12px;
        border-radius: 10px;
    }

    .mindmap-back-btn span {
        display: inline;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Suggested Topics — Tag cloud of interest suggestions from memory analysis
   ═══════════════════════════════════════════════════════════════════════════ */
.suggested-topics-section {
  margin-bottom: 20px;
  padding: 20px 24px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.06) 0%, rgba(99, 102, 241, 0.04) 100%);
  border: 1px solid rgba(139, 92, 246, 0.15);
  animation: suggestedTopicsFadeIn 0.5s ease-out;
}

[data-theme="dark"] .suggested-topics-section {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(99, 102, 241, 0.06) 100%);
  border-color: rgba(139, 92, 246, 0.25);
}

@keyframes suggestedTopicsFadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.suggested-topics-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.suggested-topics-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text, #111827);
}

.suggested-topics-title svg {
  color: #8b5cf6;
  flex-shrink: 0;
}

.suggested-topics-dismiss {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--color-text-muted, #6b7280);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.suggested-topics-dismiss:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--color-text, #111827);
}

[data-theme="dark"] .suggested-topics-dismiss:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
}

.suggested-topics-desc {
  font-size: 0.85rem;
  color: var(--color-text-muted, #6b7280);
  margin: 0 0 14px;
  line-height: 1.5;
}

.suggested-topics-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.suggested-topic-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px 7px 14px;
  border-radius: 20px;
  border: 1px solid rgba(139, 92, 246, 0.25);
  background: rgba(255, 255, 255, 0.8);
  color: var(--color-text, #111827);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  user-select: none;
}

.suggested-topic-chip:hover {
  background: rgba(139, 92, 246, 0.12);
  border-color: #8b5cf6;
  color: #7c3aed;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.15);
}

.suggested-topic-chip:active {
  transform: translateY(0);
}

.suggested-topic-chip.creating {
  opacity: 0.6;
  pointer-events: none;
}

.suggested-topic-chip.created {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.4);
  color: #059669;
  cursor: default;
}

.suggested-topic-chip.dismissed {
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}

.suggested-topic-label {
  pointer-events: none;
}

/* × dismiss button on each chip */
.suggested-topic-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--color-text-muted, #9ca3af);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.suggested-topic-x:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
}

[data-theme="dark"] .suggested-topic-x:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
}

[data-theme="dark"] .suggested-topic-chip {
  background: rgba(30, 41, 59, 0.6);
  color: #e5e7eb;
  border-color: rgba(139, 92, 246, 0.3);
}

[data-theme="dark"] .suggested-topic-chip:hover {
  background: rgba(139, 92, 246, 0.2);
  color: #c4b5fd;
  border-color: #a78bfa;
}

[data-theme="dark"] .suggested-topic-chip.created {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}

.suggested-topic-count {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(139, 92, 246, 0.12);
  color: #8b5cf6;
}

[data-theme="dark"] .suggested-topic-count {
  background: rgba(167, 139, 250, 0.2);
  color: #c4b5fd;
}

.suggested-topic-chip.created .suggested-topic-count {
  background: rgba(16, 185, 129, 0.15);
  color: #059669;
}

[data-theme="dark"] .suggested-topic-chip.created .suggested-topic-count {
  background: rgba(52, 211, 153, 0.2);
  color: #34d399;
}

/* ── Suggested Topics Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .suggested-topics-section {
    padding: 16px 18px;
    margin-bottom: 16px;
  }

  .suggested-topic-chip {
    font-size: 0.82rem;
    padding: 6px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .suggested-topics-section {
    animation: none;
  }
  .suggested-topic-chip {
    transition: none;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   All Memories View — Full memory management UI
   ═══════════════════════════════════════════════════════════════════════════ */

/* Memory filter selects */
.memory-filter-select {
  appearance: none;
  -webkit-appearance: none;
  padding: 10px 32px 10px 12px;
  border: 1px solid var(--knowledge-border, rgba(0,0,0,0.08));
  border-radius: 12px;
  background: var(--color-card-bg, #ffffff) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--color-text, #111827);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  min-width: 130px;
}

[data-theme="dark"] .memory-filter-select {
  background-color: #0b1220;
  color: #e5e7eb;
  border-color: rgba(255,255,255,0.08);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

/* Memory toggle switch */
.memory-toggle-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.memory-toggle-label input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.memory-toggle-slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 12px;
  transition: background 0.2s;
}

.memory-toggle-slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.memory-toggle-label input:checked + .memory-toggle-slider {
  background: #f97316;
}

.memory-toggle-label input:checked + .memory-toggle-slider::before {
  transform: translateX(20px);
}

[data-theme="dark"] .memory-toggle-slider {
  background: #4b5563;
}

.memories-selection-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 4px 12px;
}

.memories-selection-toolbar.hidden {
  display: none !important;
}

.memories-selection-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text-muted, #6b7280);
}

.memories-selection-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

#memories-select-mode-btn.active {
  color: #f97316;
  border-color: rgba(249,115,22,0.35);
}

/* Memories list */
.memories-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
}

/* Memory card */
.memory-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid transparent;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}

.memory-card.selected {
  border-color: rgba(249,115,22,0.45);
  background: rgba(249,115,22,0.08);
}

[data-theme="dark"] .memory-card.selected {
  border-color: rgba(251,146,60,0.45);
  background: rgba(249,115,22,0.16);
}

.memory-card-selectable {
  cursor: pointer;
}

.memory-select-checkbox-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.memory-select-checkbox {
  width: 16px;
  height: 16px;
  accent-color: #f97316;
}

.memory-card:hover {
  border-color: var(--knowledge-border, #e5e7eb);
  background: rgba(0,0,0,0.015);
}

[data-theme="dark"] .memory-card:hover {
  background: rgba(255,255,255,0.025);
}

.memory-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Category badges with insights-cat-* color scheme */
.memory-category-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  flex-shrink: 0;
}

.memory-cat-identity { background: #dbeafe; color: #1d4ed8; }
.memory-cat-preferences { background: #fce7f3; color: #be185d; }
.memory-cat-goals { background: #fef3c7; color: #b45309; }
.memory-cat-relationships { background: #ede9fe; color: #6d28d9; }
.memory-cat-skills { background: #d1fae5; color: #065f46; }
.memory-cat-context { background: #e0e7ff; color: #3730a3; }
.memory-cat-other { background: #f3f4f6; color: #4b5563; }

[data-theme="dark"] .memory-cat-identity { background: rgba(29,78,216,0.2); color: #93bbfd; }
[data-theme="dark"] .memory-cat-preferences { background: rgba(190,24,93,0.2); color: #f9a8d4; }
[data-theme="dark"] .memory-cat-goals { background: rgba(180,83,9,0.2); color: #fcd34d; }
[data-theme="dark"] .memory-cat-relationships { background: rgba(109,40,217,0.2); color: #c4b5fd; }
[data-theme="dark"] .memory-cat-skills { background: rgba(6,95,70,0.2); color: #6ee7b7; }
[data-theme="dark"] .memory-cat-context { background: rgba(55,48,163,0.2); color: #a5b4fc; }
[data-theme="dark"] .memory-cat-other { background: rgba(75,85,99,0.2); color: #d1d5db; }

.memory-card-time {
  font-size: 11px;
  color: #9ca3af;
  white-space: nowrap;
  flex-shrink: 0;
}

.memory-card-interest {
  font-size: 11px;
  color: #6b7280;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  background: rgba(249,115,22,0.08);
  border-radius: 4px;
  white-space: nowrap;
}

[data-theme="dark"] .memory-card-interest {
  background: rgba(249,115,22,0.15);
  color: #fdba74;
}

.memory-card-interest.unassigned {
  background: transparent;
  color: #9ca3af;
}

/* Memory text */
.memory-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--color-text, #111827);
  word-break: break-word;
}

.memory-text-edit {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--knowledge-border, #e5e7eb);
  border-radius: 10px;
  background: var(--color-card-bg, #ffffff);
  color: var(--color-text, #111827);
  font-size: 14px;
  line-height: 1.55;
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}

[data-theme="dark"] .memory-text-edit {
  background: #111827;
  border-color: #374151;
  color: #e5e7eb;
}

/* Memory action buttons */
.memory-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.memory-action-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--knowledge-border, #e5e7eb);
  background: transparent;
  color: var(--color-text-muted, #6b7280);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.memory-action-btn:hover {
  background: rgba(0,0,0,0.04);
}

[data-theme="dark"] .memory-action-btn:hover {
  background: rgba(255,255,255,0.06);
}

.memory-action-btn.edit:hover { color: #2563eb; border-color: rgba(37,99,235,0.3); }
.memory-action-btn.assign:hover { color: #f97316; border-color: rgba(249,115,22,0.3); }
.memory-action-btn.delete:hover { color: #ef4444; border-color: rgba(239,68,68,0.3); }
.memory-action-btn.save { color: #059669; border-color: rgba(5,150,105,0.3); }
.memory-action-btn.save:hover { background: rgba(5,150,105,0.08); }
.memory-action-btn.cancel:hover { color: #6b7280; }

/* Memory assign dropdown */
.memory-assign-dropdown {
  position: absolute;
  right: 16px;
  top: 100%;
  z-index: 3000;
  min-width: 200px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--color-bg-panel, #ffffff);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(0,0,0,0.12);
  padding: 4px;
  animation: knowledge-fade-in 0.12s ease-out;
}

[data-theme="dark"] .memory-assign-dropdown {
  background: #1f2937;
  border-color: #374151;
}

.memory-assign-option {
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  background: none;
  color: var(--color-text, #111827);
  font-size: 13px;
  cursor: pointer;
  display: block;
  transition: background 0.15s;
}

.memory-assign-option:hover {
  background: var(--color-bg-hover, #f3f4f6);
}

[data-theme="dark"] .memory-assign-option {
  color: #e5e7eb;
}

[data-theme="dark"] .memory-assign-option:hover {
  background: #374151;
}

.memory-assign-option.remove {
  color: #ef4444;
}

/* Add Memory Modal */
.add-memory-modal {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.add-memory-modal.hidden {
  display: none !important;
}

.add-memory-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
}

.add-memory-modal-panel {
  position: relative;
  z-index: 1;
  width: 95%;
  max-width: 480px;
  background: var(--color-bg-panel, #ffffff);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

[data-theme="dark"] .add-memory-modal-panel {
  background: #0b1220;
  color: #e5e7eb;
}

.add-memory-textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--knowledge-border, #e5e7eb);
  border-radius: 12px;
  background: var(--color-card-bg, #ffffff);
  color: var(--color-text, #111827);
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  min-height: 80px;
  font-family: inherit;
  box-sizing: border-box;
}

[data-theme="dark"] .add-memory-textarea {
  background: #111827;
  border-color: #374151;
  color: #e5e7eb;
}

/* ── Memories View Responsive ── */
@media (max-width: 768px) {
  .memory-card {
    padding: 12px;
  }

  .memory-actions {
    flex-wrap: wrap;
  }

  .memory-filter-select {
    min-width: 0;
    flex: 1;
    font-size: 12px;
  }

  .memory-assign-dropdown {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 16px 16px 0 0;
    max-height: 50vh;
  }

  .memories-selection-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .memories-selection-count {
    text-align: center;
  }

  .memories-selection-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .memories-selection-actions .knowledge-btn {
    min-height: 44px;
    justify-content: center;
    text-align: center;
  }

  #memories-cancel-selection-btn {
    grid-column: 1 / -1;
  }
}
