/* ========== Notes Page ========== */

/* Notes page overrides main padding */
#page-notes.active {
    display: flex !important;
    flex-direction: column;
    padding: 0;
    margin: -32px -36px;
    width: calc(100% + 72px);
    height: calc(100vh);
    overflow: hidden;
}

/* Container */
.notes-container {
    display: flex;
    flex: 1;
    min-height: 0;
    background: var(--card-bg);
    border-bottom: 1px solid var(--card-border);
    overflow: hidden;
}

/* ===== Left Panel (Sidebar) ===== */
.notes-sidebar {
    width: 280px;
    min-width: 280px;
    border-right: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.notes-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--card-border);
}

.notes-sidebar-header h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.notes-sidebar-actions {
    display: flex;
    gap: 4px;
}

.notes-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--card-border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.notes-action-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
}

.notes-action-btn svg {
    width: 16px;
    height: 16px;
}

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

.notes-search svg {
    width: 16px;
    height: 16px;
    stroke: var(--text-secondary);
    flex-shrink: 0;
}

.notes-search input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 0.82rem;
    font-family: inherit;
}

.notes-search input::placeholder {
    color: var(--text-secondary);
}

/* Tag Filter */
.notes-tag-filter {
    padding: 0 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.notes-tag-filter:not(:empty) {
    padding-top: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--card-border);
}

.tag-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 100px;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    background: color-mix(in srgb, var(--chip-color, #6366f1) 6%, var(--card-bg));
    border: 1px solid color-mix(in srgb, var(--chip-color, #6366f1) 20%, var(--card-border));
    color: var(--text-secondary);
}

.tag-filter-chip:hover {
    background: color-mix(in srgb, var(--chip-color, #6366f1) 12%, var(--card-bg));
    border-color: color-mix(in srgb, var(--chip-color, #6366f1) 40%, var(--card-border));
    color: var(--text-primary);
}

.tag-filter-chip.active {
    background: color-mix(in srgb, var(--chip-color, #6366f1) 18%, var(--card-bg));
    border-color: color-mix(in srgb, var(--chip-color, #6366f1) 50%, var(--card-border));
    color: var(--text-primary);
}

.tag-filter-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chip-color, #6366f1);
    box-shadow: 0 0 6px color-mix(in srgb, var(--chip-color, #6366f1) 50%, transparent);
}

/* Tree View */
.notes-tree {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.notes-tree::-webkit-scrollbar {
    width: 3px;
}

.notes-tree::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.tree-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px 7px calc(12px + var(--depth, 0) * 16px);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.82rem;
    transition: all var(--transition);
    user-select: none;
    position: relative;
}

.tree-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
}

.tree-item.active {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.tree-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 3px;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
}

.tree-item.search-match {
    background: rgba(48, 92, 222, 0.08);
}

.tree-chevron {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    transition: transform 0.2s ease;
    stroke: var(--text-secondary);
}

.tree-chevron.collapsed {
    transform: rotate(-90deg);
}

.tree-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.tree-icon.folder {
    stroke: #f59e0b;
}

.tree-icon.note {
    stroke: var(--text-secondary);
}

.tree-item:hover .tree-icon.note {
    stroke: var(--accent);
}

.tree-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-children {
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.tree-children.collapsed {
    max-height: 0 !important;
}

/* Drag & Drop */
.tree-item.drag-over {
    background: rgba(48, 92, 222, 0.15);
    border-top: 2px solid var(--accent);
}

.tree-item.dragging {
    opacity: 0.4;
}

/* ===== Right Panel (Editor) ===== */
.notes-editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.notes-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

.notes-empty-state svg {
    width: 56px;
    height: 56px;
    stroke: rgba(255, 255, 255, 0.12);
    margin-bottom: 16px;
}

.notes-empty-state p {
    font-size: 0.95rem;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.notes-empty-state span {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.3);
}

/* Editor */
.notes-editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.notes-title-input {
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 700;
    font-family: inherit;
    padding: 20px 24px 8px;
    width: 100%;
}

.notes-title-input::placeholder {
    color: var(--text-secondary);
}

/* Tags Area */
.notes-tags-area {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 4px 24px 12px;
    min-height: 32px;
}

.notes-tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.note-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 100px;
    background: color-mix(in srgb, var(--tag-color, #6366f1) 6%, var(--card-bg));
    border: 1px solid color-mix(in srgb, var(--tag-color, #6366f1) 20%, var(--card-border));
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    animation: tagAppear 0.2s ease;
    transition: all var(--transition);
}

.note-tag:hover {
    background: color-mix(in srgb, var(--tag-color, #6366f1) 12%, var(--card-bg));
    border-color: color-mix(in srgb, var(--tag-color, #6366f1) 40%, var(--card-border));
}

.note-tag-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--tag-color, #6366f1);
    box-shadow: 0 0 6px color-mix(in srgb, var(--tag-color, #6366f1) 50%, transparent);
    flex-shrink: 0;
}

@keyframes tagAppear {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.note-tag-remove {
    width: 16px;
    height: 16px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    line-height: 1;
    transition: all var(--transition);
    padding: 0;
}

.note-tag-remove:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.notes-tag-input {
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.78rem;
    font-family: inherit;
    min-width: 100px;
}

.notes-tag-input::placeholder {
    color: var(--text-secondary);
}

/* Tag Dropdown */
.notes-tag-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 180px;
    overflow-y: auto;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    z-index: 100;
    padding: 4px;
    margin-top: 4px;
}

.notes-tag-dropdown::-webkit-scrollbar {
    width: 3px;
}

.notes-tag-dropdown::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.tag-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition);
}

.tag-dropdown-item:hover {
    background: color-mix(in srgb, var(--tag-color, #6366f1) 12%, var(--card-bg));
}

.tag-dropdown-item .note-tag-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--tag-color, #6366f1);
    box-shadow: 0 0 6px color-mix(in srgb, var(--tag-color, #6366f1) 50%, transparent);
    flex-shrink: 0;
}

/* Toolbar */
.notes-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 8px 20px;
    border-top: 1px solid var(--card-border);
    border-bottom: 1px solid var(--card-border);
}

.toolbar-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    font-weight: 600;
    transition: all var(--transition);
    font-family: inherit;
}

.toolbar-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.toolbar-btn.active {
    background: var(--accent);
    color: #fff;
}

.toolbar-btn svg {
    width: 16px;
    height: 16px;
}

.toolbar-separator {
    width: 1px;
    height: 20px;
    background: var(--card-border);
    margin: 0 4px;
}

/* Diff Bar */
.notes-diff-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: rgba(48, 92, 222, 0.08);
    border-bottom: 1px solid rgba(48, 92, 222, 0.15);
    animation: diffBarSlide 0.3s ease;
}

@keyframes diffBarSlide {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.diff-bar-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 6px;
}

.diff-bar-actions {
    display: flex;
    gap: 8px;
}

.diff-bar-btn {
    padding: 5px 14px;
    border-radius: 6px;
    border: none;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.diff-bar-btn.accept {
    background: #22c55e;
    color: #fff;
}

.diff-bar-btn.accept:hover {
    background: #16a34a;
}

.diff-bar-btn.reject {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.diff-bar-btn.reject:hover {
    background: rgba(239, 68, 68, 0.25);
}

/* Content Area */
.notes-content {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
    color: var(--text-primary);
    font-size: 0.9rem;
    line-height: 1.75;
    outline: none;
    min-height: 200px;
}

.notes-content::-webkit-scrollbar {
    width: 4px;
}

.notes-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.notes-content:empty::before {
    content: attr(data-placeholder);
    color: var(--text-secondary);
    font-style: italic;
    pointer-events: none;
}

/* Content Styling */
.notes-content h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin: 20px 0 12px;
    color: var(--text-primary);
}

.notes-content h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 16px 0 10px;
    color: var(--text-primary);
}

.notes-content h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 14px 0 8px;
    color: var(--text-primary);
}

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

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

.notes-content li {
    margin-bottom: 4px;
}

.notes-content code {
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.85em;
    color: #e879f9;
}

.notes-content pre {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 14px 16px;
    margin: 12px 0;
    overflow-x: auto;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.82rem;
    line-height: 1.6;
}

.notes-content pre code {
    background: none;
    padding: 0;
    color: #e2e8f0;
}

.notes-content a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.notes-content a:hover {
    opacity: 0.8;
}

.notes-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.85rem;
}

.notes-content table th,
.notes-content table td {
    border: 1px solid var(--card-border);
    padding: 8px 12px;
    text-align: left;
}

.notes-content table th {
    background: rgba(255, 255, 255, 0.04);
    font-weight: 600;
}

/* Note Tasks (inline) */
.note-task {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    margin: 6px 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--card-border);
    cursor: pointer;
    transition: all var(--transition);
}

.note-task:hover {
    background: rgba(255, 255, 255, 0.06);
}

.note-task-checkbox {
    width: 18px;
    height: 18px;
    border-radius: 5px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
    padding: 0;
}

.note-task-checkbox:hover {
    border-color: var(--accent);
}

.note-task-checkbox.checked {
    background: var(--accent);
    border-color: var(--accent);
}

.note-task-checkbox.checked svg {
    opacity: 1;
}

.note-task-checkbox svg {
    width: 11px;
    height: 11px;
    stroke: #fff;
    stroke-width: 3;
    opacity: 0;
}

.note-task-text {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.note-task.completed .note-task-text {
    text-decoration: line-through;
    opacity: 0.5;
}

/* Inline Diff Markers */
.diff-added {
    background: rgba(34, 197, 94, 0.15);
    border-left: 3px solid #22c55e;
    padding: 2px 8px;
    margin: 2px 0;
    border-radius: 0 4px 4px 0;
    position: relative;
}

.diff-removed {
    background: rgba(239, 68, 68, 0.12);
    border-left: 3px solid #ef4444;
    padding: 2px 8px;
    margin: 2px 0;
    border-radius: 0 4px 4px 0;
    text-decoration: line-through;
    color: rgba(255, 255, 255, 0.5);
    position: relative;
}

.diff-actions {
    display: inline-flex;
    gap: 4px;
    margin-left: 8px;
    vertical-align: middle;
}

.diff-action-btn {
    padding: 2px 8px;
    border-radius: 4px;
    border: none;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.diff-action-btn.accept {
    background: #22c55e;
    color: #fff;
}

.diff-action-btn.reject {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

/* ===== AI Bar ===== */
.notes-ai-bar {
    padding: 8px 16px;
    flex-shrink: 0;
    background: var(--card-bg);
}

.notes-ai-input-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    padding: 12px 16px;
    transition: border-color var(--transition);
}

.notes-ai-input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(48, 92, 222, 0.1);
}

.notes-ai-icon {
    width: 22px;
    height: 22px;
    color: var(--accent);
    flex-shrink: 0;
}

.notes-ai-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 0.88rem;
    font-family: inherit;
}

.notes-ai-input::placeholder {
    color: var(--text-secondary);
}

.notes-ai-input:disabled {
    opacity: 0.5;
}

.notes-ai-send {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}

.notes-ai-send:hover:not(:disabled) {
    background: #254bbf;
    transform: scale(1.05);
}

.notes-ai-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.notes-ai-send svg {
    width: 18px;
    height: 18px;
}

.notes-ai-send.loading {
    pointer-events: none;
}

.notes-ai-send.loading svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ===== Context Menu ===== */
.notes-context-menu {
    position: fixed;
    z-index: 1000;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 6px;
    min-width: 180px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    animation: ctxMenuAppear 0.15s ease;
}

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

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 14px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
}

.context-menu-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.context-menu-item.delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.context-menu-item svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    #page-notes.active {
        margin: -24px -16px;
        width: calc(100% + 32px);
        height: 100vh;
    }

    .notes-container {
        flex-direction: column;
    }

    .notes-sidebar {
        width: 100%;
        min-width: 100%;
        max-height: 220px;
        border-right: none;
        border-bottom: 1px solid var(--card-border);
    }

    .notes-editor-panel {
        min-height: 300px;
    }

    .notes-title-input {
        font-size: 1.2rem;
        padding: 16px 16px 8px;
    }

    .notes-tags-area {
        padding: 4px 16px 10px;
    }

    .notes-toolbar {
        padding: 6px 12px;
    }

    .notes-content {
        padding: 16px;
    }

    .notes-ai-input-wrapper {
        padding: 10px 12px;
    }
}
