/* ============================================================
   NOTES SYSTEM
   ============================================================ */

.notes-shell {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
}

/* ---- Sidebar ---- */
.notes-sidebar {
    width: 260px;
    min-width: 260px;
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.notes-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    background: #fff;
    font-size: 0.95rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* ---- Collapsed panel rail ---- */
.notes-rail {
    width: 32px;
    min-width: 32px;
    background: #f1f5f9;
    border-right: 1px solid #e2e8f0;
    display: flex;
    justify-content: center;
    padding-top: 0.5rem;
}

/* ---- Middle pages panel ---- */
.notes-pages-panel {
    width: 240px;
    min-width: 240px;
    background: #fcfdfe;
    border-right: 1px solid #e2e8f0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.notes-pages-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid #eef2f6;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 5;
}

.notes-pages-panel-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notes-pages-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 0.5rem;
    padding: 2rem 1rem;
    color: #9ca3af;
    font-size: 0.82rem;
    text-align: center;
}

.notes-pages-empty p { margin: 0; }

/* ---- Unread (not yet read by this user) ---- */
.notes-unread { font-weight: 700; color: #111827; }
.notes-section-header .notes-unread { color: #111827; }

.notes-empty-nav {
    padding: 1.5rem 1rem;
    color: #9ca3af;
    font-size: 0.85rem;
    text-align: center;
}

/* ---- Category ---- */
.notes-category-header {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    user-select: none;
    gap: 0.5rem;
    transition: background 0.1s;
}

.notes-category-header:hover { background: #f1f5f9; }
.notes-category.active > .notes-category-header { background: #e0f2fe; }

.notes-category-name {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notes-category-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.15s; }
.notes-category-header:hover .notes-category-actions { opacity: 1; }

/* ---- Section ---- */
.notes-sections { padding-left: 4px; }

.notes-section-header {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    cursor: pointer;
    font-size: 0.825rem;
    color: #374151;
    gap: 0.25rem;
    transition: background 0.1s;
}

.notes-section-header:hover { background: #f1f5f9; }
.notes-section-header.active {
    background: #e0f2fe;
    color: #1d4ed8;
    font-weight: 600;
    box-shadow: inset 3px 0 0 #2563eb;
}

.notes-section-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notes-section-actions { display: flex; gap: 2px; margin-left: auto; opacity: 0; transition: opacity 0.15s; }
.notes-section-header:hover .notes-section-actions { opacity: 1; }

.notes-add-section {
    padding: 0.3rem 1rem;
    font-size: 0.78rem;
    color: #6b7280;
    cursor: pointer;
    transition: color 0.1s;
}

.notes-add-section:hover { color: #2563eb; }

/* ---- Sub-sections (top-level pages shown under a section in the left) ---- */
.notes-subsections {
    padding-left: 22px;
    border-left: 1px solid #e2e8f0;
    margin-left: 22px;
}

.notes-subsection-item {
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: #374151;
    border-radius: 4px;
    transition: background 0.1s;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.notes-subsection-item:hover { background: #f1f5f9; }
.notes-subsection-item.active {
    background: #bfdbfe;
    color: #1e3a8a;
    font-weight: 600;
    box-shadow: inset 3px 0 0 #2563eb;
}

.notes-subsection-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notes-subsection-actions { display: flex; gap: 2px; margin-left: auto; opacity: 0; transition: opacity 0.15s; }
.notes-subsection-item:hover .notes-subsection-actions { opacity: 1; }

/* ---- Page tree ---- */
.notes-page-item {
    padding: 0.28rem 0.75rem;
    font-size: 0.82rem;
    cursor: pointer;
    color: #374151;
    border-radius: 4px;
    margin: 1px 4px;
    transition: background 0.1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 2px;
}

.notes-page-item:hover { background: #f1f5f9; }
.notes-page-item.active {
    background: #bfdbfe;
    color: #1e3a8a;
    font-weight: 600;
    box-shadow: inset 3px 0 0 #2563eb;
}

.notes-page-move-btn {
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    padding: 0 2px;
    font-size: 0.8rem;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s, color 0.1s;
}

.notes-page-item:hover .notes-page-move-btn { opacity: 1; }
.notes-page-move-btn:hover { color: #1d4ed8; }

/* ---- Drag & drop feedback ---- */
.notes-drop-target {
    outline: 2px dashed #2563eb;
    outline-offset: -2px;
    background: #eff6ff !important;
}

/* Sibling reorder drop line (between page items). Normally a thin invisible
   hit area; shows a blue bar when the dragged page is hovering over it. */
.notes-page-drop-line {
    height: 6px;
    margin: 0 8px;
    border-radius: 3px;
    transition: background 0.1s;
}
.notes-page-drop-line.active {
    background: #2563eb;
    box-shadow: 0 0 0 1px rgba(37,99,235,0.3);
}

.notes-section-header[draggable="true"],
.notes-page-item[draggable="true"] { cursor: grab; }

.notes-section-header[draggable="true"]:active,
.notes-page-item[draggable="true"]:active { cursor: grabbing; }

/* ---- Main content ---- */
.notes-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #fff;
    min-height: 0;
}

.notes-no-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #9ca3af;
}

/* ---- Page header ---- */
.notes-page-header {
    padding: 1rem 1.5rem 0.75rem;
    border-bottom: 1px solid #f1f5f9;
    background: #fff;
    flex: 0 0 auto;
    z-index: 5;
}

.notes-page-title-row {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.notes-page-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    cursor: text;
}

.notes-title-input {
    font-size: 1.5rem;
    font-weight: 700;
    border: none;
    border-bottom: 2px solid #3b82f6;
    outline: none;
    width: 100%;
    max-width: 600px;
    background: transparent;
}

.notes-page-meta { font-size: 0.75rem; color: #9ca3af; }

.notes-page-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.notes-subpages-label { font-size: 0.8rem; color: #6b7280; }

/* Persistent formatting bar in the (sticky) page header.
   Stays visible while scrolling long pages; acts on the focused block. */
.notes-format-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 0.5rem;
    padding: 4px 6px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    width: fit-content;
}

/* ---- Canvas ---- */
.notes-canvas {
    flex: 1;
    position: relative;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem;
    background: #fafafa;
    background-image: radial-gradient(#e5e7eb 1px, transparent 1px);
    background-size: 24px 24px;
}

/* ---- Block ---- */
.notes-block {
    position: absolute;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    min-height: 60px;
    overflow: visible;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.notes-block:hover { border-color: #93c5fd; }
.notes-block-active { border-color: #3b82f6 !important; box-shadow: 0 0 0 2px rgba(59,130,246,0.2); z-index: 10; }

/* When active, push content below the in-block toolbar so it isn't overlapped */
.notes-block-active .notes-block-text,
.notes-block-active .notes-block-heading { padding-top: 2.5rem; }

.notes-block-toolbar {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    padding: 2px 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
    z-index: 20;
}

.notes-block-drag-handle {
    cursor: grab;
    color: #9ca3af;
    font-size: 1.1rem;
    padding: 0 4px;
    user-select: none;
}

.notes-block-text,
.notes-block-heading {
    padding: 0.5rem 0.75rem;
    min-height: 40px;
    outline: none;
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.notes-block-heading {
    font-size: 1.15rem;
    font-weight: 700;
    color: #1e293b;
    border-bottom: 2px solid #f1f5f9;
    padding-bottom: 0.5rem;
}

/* ---- Inline tables inside text blocks (imported / inserted at caret) ---- */
.notes-block-text table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.5rem 0;
    font-size: 0.85rem;
    table-layout: fixed;
}

.notes-block-text th,
.notes-block-text td {
    border: 1px solid #cbd5e1;
    padding: 0.35rem 0.5rem;
    text-align: left;
    vertical-align: top;
    white-space: normal;
    word-break: break-word;
    position: relative;
    /* Right border acts as a drag target for column resizing. */
    cursor: text;
}

/* Visual hint that the right edge of a cell is draggable to resize the column. */
.notes-block-text th::after,
.notes-block-text td::after {
    content: "";
    position: absolute;
    top: 0;
    right: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
}

.notes-block-text th {
    background: #f1f5f9;
    font-weight: 600;
    color: #1e293b;
}

.notes-block-text img {
    max-width: 100%;
    height: auto;
}

/* ---- Checkbox (task) list ---- */
.notes-checklist {
    list-style: none;
    padding-left: 0.25rem;
    margin: 0.25rem 0;
}

.notes-checklist li {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.notes-checklist li input[type="checkbox"] {
    margin-top: 0.3rem;
    flex-shrink: 0;
    cursor: pointer;
}

/* Imported (Joplin/Markdown) task lists use Markdig's .contains-task-list. */
.contains-task-list {
    list-style: none;
    padding-left: 0.25rem;
    margin: 0.25rem 0;
}

.contains-task-list .task-list-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.contains-task-list input[type="checkbox"] {
    margin-top: 0.3rem;
    flex-shrink: 0;
    cursor: pointer;
}

/* Nested sub-lists: wrap onto a new line and indent, rather than sitting
   inline next to the checkbox/bullet of the flex list item. */
.notes-checklist li,
.contains-task-list .task-list-item { flex-wrap: wrap; }

.notes-checklist li > ul,
.notes-checklist li > ol,
.contains-task-list li > ul,
.contains-task-list li > ol {
    flex-basis: 100%;
    margin: 0.25rem 0 0 1.5rem;
}

/* ---- Table block ---- */
.notes-table-block { overflow-x: auto; padding: 0.5rem; }

.notes-table-scroll { overflow-x: auto; }

.notes-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--notes-table-font, 0.85rem);
    line-height: var(--notes-table-lh, 1.4);
    table-layout: fixed;
}

.notes-table td {
    border: 1px solid #e5e7eb;
    padding: 0.3rem 0.5rem;
    min-width: 40px;
    outline: none;
    vertical-align: top;
    position: relative;
}

.notes-table .notes-table-header {
    background: #f8fafc;
    font-weight: 600;
    color: #374151;
}

.notes-table-row-actions {
    border: none !important;
    width: 20px;
    padding: 0 !important;
    vertical-align: middle;
}

.notes-table-cell-input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: inherit;
    line-height: inherit;
    padding: 0;
    min-width: 40px;
}

.notes-table-header-input {
    font-weight: 600;
    color: #374151;
}

.notes-table-actions {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.4rem;
}

/* ---- Table size / line-height settings toolbar ---- */
.notes-table-settings {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 0.4rem;
}

.notes-table-settings-group {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 0.1rem 0.35rem;
}

.notes-table-settings-label {
    font-size: 0.8rem;
    color: #6b7280;
    min-width: 0.9rem;
    text-align: center;
}

.notes-table-settings-value {
    font-size: 0.75rem;
    color: #374151;
    min-width: 2.4rem;
    text-align: center;
}

/* ---- Column resize handle ---- */
.notes-table-col-resizer {
    position: absolute;
    top: 0;
    right: -3px;
    width: 7px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
    touch-action: none;
    z-index: 2;
}

.notes-table-col-resizer:hover {
    background: rgba(59, 130, 246, 0.35);
}

.notes-table-resizing {
    user-select: none;
    cursor: col-resize;
}

/* ---- Resize handle ---- */
.notes-block-resize {
    position: absolute;
    opacity: 0;
    transition: opacity 0.15s;
}

/* Bottom-right corner: resize width + height together. */
.notes-block-resize-se {
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    cursor: se-resize;
    background: linear-gradient(135deg, transparent 50%, #93c5fd 50%);
    border-bottom-right-radius: 6px;
}

/* Right edge: resize width only. */
.notes-block-resize-e {
    top: 50%;
    right: -3px;
    transform: translateY(-50%);
    width: 8px;
    height: 36px;
    cursor: ew-resize;
    background: #93c5fd;
    border-radius: 4px;
}

.notes-block:hover .notes-block-resize,
.notes-block-active .notes-block-resize { opacity: 1; }

/* ---- Rich text format buttons ---- */
.notes-fmt-btn {
    background: none;
    border: 1px solid #e5e7eb;
    border-radius: 3px;
    padding: 1px 5px;
    cursor: pointer;
    font-size: 0.78rem;
    color: #374151;
    line-height: 1.4;
    transition: background 0.1s;
}

.notes-fmt-btn:hover { background: #f1f5f9; }
.notes-fmt-btn-on { background: #dbeafe; border-color: #3b82f6; }

/* ---- HTML source editor (per block) ---- */
.notes-html-editor {
    width: 100%;
    height: 220px;
    min-height: 120px;
    margin-top: 2.5rem;
    box-sizing: border-box;
    font-family: Consolas, Menlo, monospace;
    font-size: 0.8rem;
    line-height: 1.4;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 0.5rem;
    resize: vertical;
    outline: none;
    background: #f8fafc;
    color: #0f172a;
}

.notes-html-editor-actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
    padding: 4px 0 0;
}

.notes-fmt-sep {
    display: inline-block;
    width: 1px;
    height: 16px;
    background: #e5e7eb;
    margin: 0 3px;
    vertical-align: middle;
}

/* ---- Search ---- */
.notes-search-bar {
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid #e2e8f0;
    background: #fff;
}

.notes-search-input {
    width: 100%;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 0.3rem 0.5rem;
    font-size: 0.82rem;
    outline: none;
    background: #f8fafc;
}

.notes-search-input:focus { border-color: #93c5fd; background: #fff; }

.notes-search-results { padding: 0.25rem 0; }

/* ---- Inline rename ---- */
.notes-inline-rename {
    border: none;
    border-bottom: 1px solid #3b82f6;
    outline: none;
    background: transparent;
    font-size: inherit;
    font-weight: inherit;
    width: 100%;
    padding: 0;
}

/* ---- Image block ---- */
.notes-block-image-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.notes-block-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

.notes-image-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    gap: 0.5rem;
    cursor: pointer;
    width: 100%;
    height: 100%;
    font-size: 0.8rem;
}

.notes-image-placeholder:hover { color: #3b82f6; }

/* ---- Toolbar divider ---- */
.notes-toolbar-divider {
    display: inline-block;
    width: 1px;
    height: 24px;
    background: #e5e7eb;
    margin: 0 4px;
    vertical-align: middle;
}

/* ---- Page item with rename input ---- */
.notes-page-item span {
    cursor: pointer;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Print media query ---- */
@media print {
    .notes-sidebar,
    .notes-pages-panel,
    .notes-page-header,
    .notes-block-toolbar,
    .notes-block-resize { display: none !important; }

    .notes-shell { display: block; }
    .notes-canvas { position: relative; min-height: unset; background: none; }
    .notes-block { box-shadow: none; border: 1px solid #ccc; }
}
/* ---- Dialogs ---- */
.notes-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.notes-dialog {
    background: #fff;
    border-radius: 8px;
    padding: 1.5rem;
    width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.notes-dialog h5 { margin: 0 0 1rem; font-weight: 700; }

.notes-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}

.notes-colour-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0.5rem 0 0.75rem;
    align-items: center;
}

.notes-colour-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s, border-color 0.1s;
}

.notes-colour-swatch:hover { transform: scale(1.15); }
.notes-colour-swatch.selected { border-color: #1e293b; transform: scale(1.15); }

/* ---- Read-only / lock badge ---- */
.notes-readonly-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: #e5e7eb;
    color: #4b5563;
}

/* ---- Live collaboration presence ---- */
.notes-live-editors {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: #dcfce7;
    color: #166534;
}

.notes-live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 0 rgba(34,197,94,0.6);
    animation: notes-live-pulse 1.6s infinite;
}

.notes-live-chip {
    background: #bbf7d0;
    color: #14532d;
    border-radius: 999px;
    padding: 0.05rem 0.45rem;
}

.notes-live-label {
    color: #166534;
    font-weight: 500;
    opacity: 0.85;
}

@keyframes notes-live-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(34,197,94,0.6); }
    70%  { box-shadow: 0 0 0 6px rgba(34,197,94,0); }
    100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* ---- Edit history panel ---- */
.notes-history-panel {
    margin: 0.5rem 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fafafa;
    padding: 0.5rem 0.75rem;
    max-height: 260px;
    overflow-y: auto;
}

.notes-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.notes-history-empty { font-size: 0.8rem; color: #9ca3af; }

.notes-history-list { list-style: none; margin: 0; padding: 0; }

.notes-history-list li {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: baseline;
    padding: 0.3rem 0;
    border-bottom: 1px solid #eef0f2;
    font-size: 0.8rem;
}

.notes-history-action { font-weight: 600; color: #1e293b; }
.notes-history-user { color: #3b82f6; }
.notes-history-time { color: #9ca3af; margin-left: auto; }
.notes-history-detail { flex-basis: 100%; color: #6b7280; font-style: italic; }

