/* ---------- CSS Variables (Light / Dark) ---------- */
:root {
    --bg-board: #e8e8e8;
    --bg-toolbar: rgba(255,255,255,0.92);
    --text-primary: #1e1e1e;
    --text-secondary: #555;
    --border-light: #ccc;
    --shadow-color: rgba(0,0,0,0.12);
    --sidebar-bg: #f5f5f5;
    --sidebar-border: #ddd;
    --group-hover: #e0e0e0;
    --note-shadow: 0 6px 18px rgba(0,0,0,0.15);
    --input-bg: white;
    --input-border: #ccc;
    --link-color: #555;
    --link-hover: #1e88e5;
}

body.dark {
    --bg-board: #1e1e1e;
    --bg-toolbar: rgba(40,40,40,0.95);
    --text-primary: #e0e0e0;
    --text-secondary: #aaa;
    --border-light: #444;
    --shadow-color: rgba(0,0,0,0.5);
    --sidebar-bg: #2a2a2a;
    --sidebar-border: #444;
    --group-hover: #3a3a3a;
    --note-shadow: 0 6px 18px rgba(0,0,0,0.5);
    --input-bg: #333;
    --input-border: #555;
    --link-color: #aaa;
    --link-hover: #4fc3f7;
}

/* ---------- Reset & Base ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg-board);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    user-select: none;
    transition: background 0.3s, color 0.3s;
}

/* ---------- Toolbar ---------- */
#toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-toolbar);
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 12px var(--shadow-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 999;
    gap: 10px;
    border-bottom: 1px solid var(--border-light);
}
.toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
}
.title-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    min-width: 0;
    overflow: hidden;
}
#toolbar h1 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    white-space: nowrap;
    margin: 0;
    line-height: 1.1;
}
#toolbar h1 .version {
    font-size: 0.65rem;
    font-weight: 400;
    color: var(--text-secondary);
    margin-left: 6px;
    opacity: 0.7;
    flex-shrink: 0;
}
.group-label {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.78rem;
    color: #1e88e5;
    font-weight: 600;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
    display: block;
}
body.dark .group-label {
    color: #4fc3f7;
}

/* Floating Viewport Control Stack */
.floating-controls {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 1000;
}
.floating-btn {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: var(--bg-toolbar);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px var(--shadow-color);
    transition: 0.2s;
}
.floating-btn:hover {
    background: var(--group-hover);
}
.toolbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.toolbar-actions input,
.toolbar-actions button {
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid var(--border-light);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: 0.2s;
    outline: none;
}
.toolbar-actions input {
    min-width: 180px;
    cursor: text;
}
.toolbar-actions button:hover {
    background: var(--group-hover);
}
#btnNewNote {
    background: #1e88e5;
    color: white;
    border-color: #1e88e5;
}
#btnNewNote:hover {
    background: #1565c0;
    border-color: #1565c0;
}
#btnThemeToggle {
    font-size: 1.2rem;
    padding: 2px 10px;
}
#btnToggleLinks.active {
    background: #1e88e5;
    color: white;
    border-color: #1e88e5;
}
#btnToggleLinks:not(.active):hover {
    background: var(--group-hover);
}

/* ---------- Sidebar ---------- */
#sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    bottom: 0;
    width: 200px;
    min-width: 180px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    padding: 15px 10px;
    overflow-y: auto;
    z-index: 100;
    transition: background 0.3s;
}
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}
.sidebar-header button {
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: 50%;
    width: 26px;
    height: 26px;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-primary);
}
.sidebar-header button:hover {
    background: var(--group-hover);
}

#groupList .group-item {
    padding: 8px 12px;
    margin: 4px 0;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    color: var(--text-secondary);
    transition: 0.15s;
}
#groupList .group-item:hover {
    background: var(--group-hover);
    color: var(--text-primary);
}
#groupList .group-item.active {
    background: #1e88e5;
    color: white;
}
#groupList .group-item .badge {
    background: rgba(0,0,0,0.12);
    padding: 0 8px;
    border-radius: 12px;
    font-size: 0.75rem;
}
#groupList .group-item.active .badge {
    background: rgba(255,255,255,0.25);
}
#groupList .group-item .del-group {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    padding: 0 4px;
}
#groupList .group-item .del-group:hover {
    color: #c62828;
}
#groupList .group-item.active .del-group {
    color: rgba(255,255,255,0.7);
}
#groupList .group-item.active .del-group:hover {
    color: white;
}

/* ---------- Board ---------- */
#board {
    position: fixed;
    top: 60px;
    left: 200px;
    right: 0;
    bottom: 0;
    overflow: hidden;
    transition: left 0.2s;
    cursor: grab;
}
#board:active {
    cursor: grabbing;
}
#canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    transform-origin: 0 0;
}

/* SVG overlay for links */
#board svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
    overflow: visible;
}
#board svg path {
    pointer-events: stroke;
    cursor: default;
}
#board svg path:hover {
    stroke: var(--link-hover);
    stroke-width: 3;
}

/* ---------- Sticky Note ---------- */
.note {
    position: absolute;
    min-width: 220px;   /* increased from 210px */
    min-height: 150px;
    padding: 12px 14px 30px 14px;
    border-radius: 6px;
    box-shadow: var(--note-shadow);
    transition: box-shadow 0.15s, background 0.3s;
    cursor: grab;
    font-family: 'Segoe UI', 'Helvetica Neue', sans-serif;
    display: flex;
    flex-direction: column;
}
.note:active {
    cursor: grabbing;
}
.note:hover {
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

/* Drag handle (top bar) */
.note .drag-handle {
    position: absolute;
    top: 2px;
    left: 10%;
    right: 10%;
    height: 10px;
    background: rgba(0,0,0,0.08);
    border-radius: 4px;
    cursor: grab;
    opacity: 0.4;
    transition: opacity 0.2s;
}
.note:hover .drag-handle {
    opacity: 0.8;
}
.note .drag-handle:active {
    cursor: grabbing;
}
body.dark .note .drag-handle {
    background: rgba(255,255,255,0.12);
}

/* 4 Cardinal connection dots for links */
.note .link-dot {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--link-color);
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    pointer-events: none;
    opacity: 0.2;
    transition: opacity 0.2s;
}
.note:hover .link-dot {
    opacity: 0.8;
}
.note .link-dot-top {
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
}
.note .link-dot-bottom {
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
}
.note .link-dot-left {
    left: -5px;
    top: 50%;
    transform: translateY(-50%);
}
.note .link-dot-right {
    right: -5px;
    top: 50%;
    transform: translateY(-50%);
}
body.dark .note .link-dot {
    border-color: #333;
}

.note .note-title {
    font-weight: 600;
    font-size: 0.95rem;
    border: none;
    background: transparent;
    outline: none;
    margin-bottom: 4px;
    padding: 2px 0;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    color: var(--text-primary);
}
.note .note-title:empty::before {
    content: "Title";
    color: #888;
    font-weight: 400;
}
.note .note-content {
    flex: 1;
    font-size: 0.95rem;
    line-height: 1.5;
    outline: none;
    overflow-y: auto;
    padding: 4px 0;
    color: var(--text-primary);
    min-height: 60px;
}
.note .note-content:empty::before {
    content: "Write something...";
    color: #999;
    font-style: italic;
}

/* ---------- Note Controls ---------- */
.note .note-actions {
    position: absolute;
    top: 6px;
    right: 8px;
    display: flex;
    gap: 4px;
    opacity: 0.4;
    transition: opacity 0.2s;
}
.note:hover .note-actions {
    opacity: 1;
}
.note .note-actions button {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 2px 5px;
    border-radius: 4px;
    color: var(--text-secondary);
}
.note .note-actions button:hover {
    background: rgba(0,0,0,0.1);
}
.note .note-actions .btn-delete {
    color: #c62828;
    font-weight: bold;
}

/* Color picker & group dropdown (bottom row) */
.note .note-footer {
    position: absolute;
    bottom: 6px;
    right: 8px;
    left: 8px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    transition: opacity 0.2s, max-height 0.2s;
}
.note .note-footer.collapsed {
    opacity: 0;
    pointer-events: none;
    max-height: 0;
    overflow: hidden;
}
.note .btn-footer-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 2px 4px;
    opacity: 0.4;
    transition: opacity 0.2s;
}
.note:hover .btn-footer-toggle {
    opacity: 0.9;
}
.note .btn-footer-toggle.collapsed {
    position: absolute;
    bottom: 4px;
    right: 6px;
}
.note .color-picker {
    display: flex;
    gap: 4px;
}
.note .color-picker .swatch {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.15);
    cursor: pointer;
    transition: transform 0.1s;
}
.note .color-picker .swatch:hover {
    transform: scale(1.25);
}
.note .color-picker .swatch.active {
    border: 2px solid #222;
    transform: scale(1.1);
}

.note .group-select {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 12px;
    border: 1px solid rgba(0,0,0,0.1);
    background: rgba(255,255,255,0.4);
    color: var(--text-primary);
    outline: none;
    max-width: 120px;   /* wider */
    min-width: 40px;
    width: auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}
.note .group-select option {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Link handle on right edge */
.note .link-handle {
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background: var(--link-color);
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    cursor: grab;
    z-index: 10;
    opacity: 0.3;
    transition: opacity 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    color: white;
    font-weight: bold;
}
.note:hover .link-handle {
    opacity: 0.8;
}
.note .link-handle:hover {
    opacity: 1;
    transform: translateY(-50%) scale(1.2);
}
.note .link-handle.dragging {
    opacity: 1;
    transform: translateY(-50%) scale(1.4);
    cursor: grabbing;
}

/* Resize handle */
.note .resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 50%, rgba(0,0,0,0.15) 50%);
    border-radius: 0 0 6px 0;
}

/* ---------- Hide all ---------- */
.note.hidden {
    display: none !important;
}

/* ---------- Colour presets ---------- */
.note-color-yellow   { background: #fff9c4; }
.note-color-blue     { background: #bbdefb; }
.note-color-green    { background: #c8e6c9; }
.note-color-pink     { background: #f8bbd0; }
.note-color-orange   { background: #ffe0b2; }
.note-color-purple   { background: #e1bee7; }
.note-color-red      { background: #ffcdd2; }
.note-color-gray     { background: #e0e0e0; }

body.dark .note-color-yellow   { background: #5d4e37; color: #f0e6d3; }
body.dark .note-color-blue     { background: #1a3a5c; color: #c5d9f0; }
body.dark .note-color-green    { background: #1d3b1d; color: #c6e6c6; }
body.dark .note-color-pink     { background: #5c2a3f; color: #f0c8d0; }
body.dark .note-color-orange   { background: #5c3d1a; color: #f0d8b8; }
body.dark .note-color-purple   { background: #3d2a5c; color: #d8c8f0; }
body.dark .note-color-red      { background: #5c1a1a; color: #f0c8c8; }
body.dark .note-color-gray     { background: #3a3a3a; color: #d0d0d0; }
body.dark .note .note-title,
body.dark .note .note-content {
    color: inherit;
}
body.dark .note .group-select {
    background: rgba(0,0,0,0.3);
    color: inherit;
}
body.dark .note .resize-handle {
    background: linear-gradient(135deg, transparent 50%, rgba(255,255,255,0.15) 50%);
}
body.dark .note .link-handle {
    border-color: #333;
}

/* ---------- Responsive Mobile UI & Touch Optimizations ---------- */
.mobile-only-btn, .mobile-only-inline, .sidebar-overlay { display: none; }

#board, .note {
    touch-action: none; /* Prevent native pull-to-refresh & scrolling interference */
}

#btnSidebarToggle {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    font-size: 1.2rem;
    padding: 2px 10px;
    border-radius: 6px;
    cursor: pointer;
}

.mobile-sidebar-tools {
    display: none;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-tool-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 10px;
}

.sidebar-tool-grid button {
    padding: 6px;
    font-size: 0.8rem;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-primary);
    cursor: pointer;
}

@media (max-width: 950px), (max-height: 500px) {
    .desktop-only-btn { display: none !important; }
    .mobile-only-btn { display: inline-flex; align-items: center; justify-content: center; }
    .mobile-only-inline { display: inline-block; text-align: center; margin: 0; }
    .mobile-sidebar-tools { display: flex; }
    
    #sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 260px;
        min-width: 260px;
        height: 100dvh;
        z-index: 2000;
        padding-top: 20px;
        padding-bottom: 90px;
        overflow-y: auto;
        box-shadow: 2px 0 12px rgba(0,0,0,0.3);
        transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }
    
    body.sidebar-open #sidebar { left: 0; }
    
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }
    
    body.sidebar-open .sidebar-overlay {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }
    
    #board { left: 0; }
    
    #toolbar {
        height: 52px;
        padding: 0 10px;
    }

    #toolbar h1 {
        font-size: 0.95rem;
    }

    .toolbar-actions {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        gap: 6px;
        flex-wrap: nowrap; /* Prevents button dropping */
    }
    
    .toolbar-actions input {
        width: 105px;
        min-width: 80px;
        padding: 4px 10px;
        font-size: 0.78rem;
    }

    .toolbar-actions button {
        padding: 4px 10px;
        font-size: 0.78rem;
        white-space: nowrap;
    }
}

/* Ensure SVG paths can receive pointer events for Ctrl+Click */
#board svg path {
    pointer-events: stroke !important;
    cursor: pointer;
}

/* ---------- Phase 3 Enhancements ---------- */
.sidebar-resizer {
    position: absolute;
    top: 0; right: 0;
    width: 6px; height: 100%;
    cursor: ew-resize;
    background: transparent;
    z-index: 10;
}
.sidebar-resizer:hover { background: rgba(0,0,0,0.1); }
body.dark .sidebar-resizer:hover { background: rgba(255,255,255,0.1); }

.sidebar-controls { margin-bottom: 10px; }
.sidebar-controls select { 
    width: 100%; padding: 4px; border-radius: 4px; border: 1px solid var(--sidebar-border); 
    background: var(--input-bg); color: var(--text-primary); outline: none; 
}

.group-header { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.group-title-container { display: flex; align-items: center; gap: 6px; flex: 1; overflow: hidden; }
.group-chevron { cursor: pointer; color: var(--text-secondary); font-size: 0.8rem; transition: transform 0.2s; width: 12px; text-align: center; }
.group-chevron.expanded { transform: rotate(90deg); }
.group-name { cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.group-name:hover { color: #1e88e5; }
.group-actions { display: flex; gap: 4px; align-items: center; }
#btnToggleSnap.active { background: #1e88e5; color: white; border-color: #1e88e5; }
.edit-group { background: transparent; border: none; cursor: pointer; color: var(--text-secondary); font-size: 0.9rem; padding: 0 4px; }
.edit-group:hover { color: #1e88e5; }

.nested-notes { margin-left: 20px; margin-top: 4px; display: none; flex-direction: column; gap: 2px; border-left: 1px dashed var(--sidebar-border); padding-left: 6px; }
.nested-notes.expanded { display: flex; }
.nested-note-item { 
    font-size: 0.8rem; padding: 2px 6px; cursor: pointer; color: var(--text-secondary); 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 4px; 
}
.nested-note-item:hover { background: rgba(0,0,0,0.05); color: var(--text-primary); }
body.dark .nested-note-item:hover { background: rgba(255,255,255,0.05); }

/* Collapsed Mode */
body.collapsed-mode .note-content, 
body.collapsed-mode .note-footer, 
body.collapsed-mode .btn-footer-toggle,
body.collapsed-mode .resize-handle { display: none !important; }
body.collapsed-mode .note { min-height: 34px !important; height: auto !important; padding-bottom: 6px; }
.note .note-pinned-tag {
    display: none;
    font-size: 0.65rem;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(0,0,0,0.12);
    margin-right: 6px;
}
body.collapsed-mode .note .note-pinned-tag {
    display: inline-block;
}

/* Camera Center Highlight */
@keyframes pulse-highlight { 
    0% { box-shadow: 0 0 0px #1e88e5; transform: scale(1); } 
    50% { box-shadow: 0 0 25px #1e88e5; transform: scale(1.05); } 
    100% { box-shadow: var(--note-shadow); transform: scale(1); } 
}
.note.highlight-pulse { animation: pulse-highlight 1.5s ease-out; z-index: 1000 !important; }

.camera-transition {
    transition: transform 0.4s ease-in-out !important;
}

/* ---------- Auth Overlay ---------- */
#authOverlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: var(--bg-board); z-index: 9999;
    display: flex; justify-content: center; align-items: center;
}
.auth-box {
    background: var(--bg-toolbar); padding: 40px; border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2); width: 320px; text-align: center;
    border: 1px solid var(--border-light);
}
.auth-box h2 { margin-bottom: 20px; color: var(--text-primary); }
.auth-box input {
    width: 100%; padding: 10px; margin-bottom: 15px; border-radius: 4px;
    border: 1px solid var(--input-border); background: var(--input-bg); color: var(--text-primary); outline: none;
}
.auth-box button {
    width: 100%; padding: 10px; background: #1e88e5; color: white;
    border: none; border-radius: 4px; font-size: 1rem; cursor: pointer; transition: 0.2s;
}
.auth-box button:hover { background: #1565c0; }
.auth-toggle { margin-top: 15px; font-size: 0.9rem; color: var(--text-secondary); }
.auth-toggle a { color: #1e88e5; text-decoration: none; }
.auth-toggle a:hover { text-decoration: underline; }
.auth-error { color: #c62828; font-size: 0.85rem; margin-bottom: 15px; min-height: 1.2rem; }
#btnLogout { background: #d32f2f; color: white; border-color: #d32f2f; }
#btnLogout:hover { background: #b71c1c; border-color: #b71c1c; }

.current-user-badge {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    margin: 0 10px;
    padding: 4px 12px;
    background: rgba(0,0,0,0.05);
    border-radius: 20px;
    border: 1px solid var(--border-light);
}
body.dark .current-user-badge {
    background: rgba(255,255,255,0.05);
}

.note-content a {
    color: #1e88e5;
    text-decoration: underline;
    cursor: pointer;
}
.note-content a:hover {
    color: #1565c0;
}

/* Active Note Highlight Border */
.note.active-selected {
    outline: 2px solid #1e88e5;
}

/* In-Note Image Rescaling & 4-Corner Manipulator */
.note-img-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
    margin: 6px 0;
    user-select: none;
    touch-action: manipulation;
}
.note-img-container img {
    display: block;
    max-width: 100%;
    border-radius: 4px;
    pointer-events: auto;
    cursor: pointer;
    user-select: none;
    -webkit-user-drag: none;
    touch-action: manipulation;
    transition: transform 0.15s ease, filter 0.15s ease;
}
.note-img-container img:active {
    filter: brightness(0.92);
}
.note-img-container .img-resizer {
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 14px;
    height: 14px;
    background: rgba(0,0,0,0.6);
    border: 1px solid white;
    border-radius: 3px;
    cursor: nwse-resize;
    opacity: 0.3;
    transition: opacity 0.2s;
    touch-action: none;
}
.note-img-container:hover .img-resizer {
    opacity: 1;
}
.note-img-container.corner-resize-active {
    outline: 2px dashed #1e88e5;
    outline-offset: 3px;
}
.corner-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: #1e88e5;
    border: 2px solid white;
    border-radius: 50%;
    z-index: 150;
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
    touch-action: none;
}
.corner-handle.tl { top: -7px; left: -7px; cursor: nwse-resize; }
.corner-handle.tr { top: -7px; right: -7px; cursor: nesw-resize; }
.corner-handle.bl { bottom: -7px; left: -7px; cursor: nesw-resize; }
.corner-handle.br { bottom: -7px; right: -7px; cursor: nwse-resize; }

/* In-Note Image Context Menu */
.img-options-menu {
    position: absolute;
    background: var(--bg-toolbar);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    box-shadow: 0 6px 20px var(--shadow-color);
    padding: 8px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 0.8rem;
    min-width: 170px;
    backdrop-filter: blur(6px);
}
.img-options-menu .menu-title {
    font-weight: 600;
    font-size: 0.72rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 4px;
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.img-options-menu button {
    padding: 5px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-light);
    background: var(--input-bg);
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    font-size: 0.78rem;
    transition: background 0.15s;
}
.img-options-menu button:hover {
    background: var(--group-hover);
}
.img-options-menu button.btn-close-menu {
    margin-top: 3px;
    border-color: transparent;
    color: var(--text-secondary);
    text-align: center;
}

/* Markdown Styling & Return Line Preservation */
.note-content h1 { font-size: 1.3rem; margin: 4px 0; }
.note-content h2 { font-size: 1.15rem; margin: 3px 0; }
.note-content h3 { font-size: 1.05rem; margin: 2px 0; }
.note-content ul, .note-content ol { margin-left: 18px; margin-bottom: 4px; }
.note-content blockquote {
    border-left: 3px solid #1e88e5;
    margin: 4px 0;
    padding-left: 8px;
    color: var(--text-secondary);
    font-style: italic;
}
.note-content code {
    background: rgba(0,0,0,0.08);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.85em;
}
body.dark .note-content code {
    background: rgba(255,255,255,0.12);
}
.note-content hr {
    border: none;
    border-top: 1px solid rgba(0,0,0,0.15);
    margin: 8px 0;
}
body.dark .note-content hr {
    border-top-color: rgba(255,255,255,0.2);
}
.note-content .md-line {
    min-height: 1.25em;
    word-break: break-word;
}
.note-content .md-blank-line {
    min-height: 1.25em;
    display: block;
}

/* ---------- Admin Dashboard Overlay & Elements ---------- */
.admin-badge-btn {
    background: #6a1b9a !important;
    color: white !important;
    border-color: #6a1b9a !important;
}
.admin-badge-btn:hover {
    background: #4a148c !important;
    border-color: #4a148c !important;
}

.admin-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.admin-modal {
    background: var(--bg-toolbar);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.35);
    width: 900px;
    max-width: 96vw;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
}

.admin-header h2 {
    font-size: 1.2rem;
    margin: 0;
    color: var(--text-primary);
}

.btn-close-admin {
    background: transparent;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-secondary);
}
.btn-close-admin:hover {
    color: var(--text-primary);
}

.admin-tabs {
    display: flex;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-light);
}

.admin-tab {
    flex: 1;
    padding: 12px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: 0.2s;
}

.admin-tab:hover {
    background: var(--group-hover);
}

.admin-tab.active {
    color: #1e88e5;
    border-bottom-color: #1e88e5;
    background: var(--bg-toolbar);
}

.admin-tab-content {
    display: none;
    padding: 20px;
    overflow-y: auto;
}

.admin-tab-content.active {
    display: block;
}

.admin-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--sidebar-bg);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 14px;
    text-align: center;
}

.stat-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--text-primary);
}

.admin-maintenance-box {
    background: var(--sidebar-bg);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 16px;
}

.admin-maintenance-box h3 {
    font-size: 1rem;
    margin-bottom: 6px;
}

.admin-maintenance-box p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.btn-action-primary {
    padding: 8px 16px;
    background: #1e88e5;
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}
.btn-action-primary:hover {
    background: #1565c0;
}

.admin-status-text {
    margin-left: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.table-responsive {
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.admin-table th, .admin-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    text-align: left;
}

.admin-table th {
    background: var(--sidebar-bg);
    color: var(--text-secondary);
    font-weight: 600;
}

.role-pill {
    font-size: 0.75rem;
    padding: 2px 6px;
    background: rgba(0,0,0,0.08);
    border-radius: 4px;
}

.status-badge {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
}
.badge-active { background: #c8e6c9; color: #2e7d32; }
.badge-pending { background: #ffe0b2; color: #e65100; }
.badge-suspended { background: #ffcdd2; color: #c62828; }

.storage-meta {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.storage-bar-bg {
    width: 100%;
    height: 6px;
    background: rgba(0,0,0,0.1);
    border-radius: 3px;
    overflow: hidden;
}
body.dark .storage-bar-bg { background: rgba(255,255,255,0.15); }

.storage-bar-fill {
    height: 100%;
    background: #1e88e5;
    border-radius: 3px;
}

.admin-actions-cell {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.btn-admin-act {
    padding: 3px 8px;
    font-size: 0.75rem;
    border-radius: 4px;
    border: 1px solid var(--border-light);
    cursor: pointer;
    background: var(--input-bg);
    color: var(--text-primary);
}
.btn-admin-act:hover { background: var(--group-hover); }
.btn-act-approve { color: #2e7d32; border-color: #a5d6a7; }
.btn-act-suspend { color: #e65100; border-color: #ffcc80; }
.btn-act-delete { color: #c62828; border-color: #ef9a9a; }