﻿* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Feature-flag kill switches (set by js/flags.js). Any element with a
   matching data-flag attribute is hidden when the flag body class is on.
   Example: body.flag-off-ai_chat [data-flag="ai_chat"] { display: none } */
body.flag-off-ai_chat        [data-flag="ai_chat"],
body.flag-off-embeddings     [data-flag="embeddings"],
body.flag-off-video_comments [data-flag="video_comments"],
body.flag-off-e2e_encryption [data-flag="e2e_encryption"],
body.flag-off-public_api     [data-flag="public_api"],
body.flag-off-import         [data-flag="import"],
body.flag-off-export         [data-flag="export"] {
    display: none !important;
}

:root {
    /* Kysteno Unified Palette (Kymapost design language + indigo-violet brand) */

    /* Radii */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;

    /* Text ladder */
    --text: #0F0F14;
    --text-secondary: #52525B;
    --text-muted: #A1A1AA;
    --text-light: #D4D4D8;

    /* Borders */
    --border: #E4E4E7;
    --border-light: #F4F4F5;

    /* Backgrounds */
    --main-bg: #FAFAFA;
    --card-bg: #FFFFFF;
    --bg-hover: #F4F4F5;
    --bg-input: #FAFAFA;

    /* Sidebar aliases (kept for existing rules that reference them) */
    --sidebar-bg: #FFFFFF;
    --sidebar-hover: #F4F4F5;
    --sidebar-active: #E0E7FF;
    --sidebar-text: #0F0F14;
    --sidebar-muted: #A1A1AA;

    /* Brand: indigo-violet */
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --primary-light: #E0E7FF;
    --primary-muted: #A5B4FC;
    --primary-deep: #312E81;
    --accent: #4F46E5;
    --accent-glow: rgba(79, 70, 229, 0.25);

    /* AI accent (Kymapost purple) */
    --ai: #8B5CF6;
    --ai-light: #F5F3FF;

    /* Semantic */
    --danger: #DC2626;
    --danger-light: #FEE2E2;
    --success: #059669;
    --success-light: #D1FAE5;
    --warning: #D97706;
    --warning-light: #FEF3C7;
    --info: #2563EB;
    --info-light: #DBEAFE;

    /* Legacy accents retained for backwards-compat (map to semantic tokens) */
    --accent-orange: #D97706;
    --accent-gold: #D97706;

    /* Shadows */
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-dropdown: 0 4px 16px rgba(0, 0, 0, 0.10);
    --shadow-popover: 0 8px 32px rgba(0, 0, 0, 0.12);
    --shadow-modal: 0 20px 60px rgba(0, 0, 0, 0.20);

    /* Focus ring */
    --focus-ring: 0 0 0 3px var(--primary-light);

    /* Daisy Wheel theming (retinted to indigo-violet) */
    --wheel-ring-tint:   #6366F1;
    --wheel-ring-mid:    #4F46E5;
    --wheel-ring-outer:  #4338CA;
    --wheel-border:      rgba(139, 92, 246, 0.5);
    --wheel-label:       #E0E7FF;
    --wheel-divider:     rgba(255, 255, 255, 0.2);
    --wheel-hover-inner: rgba(79, 70, 229, 0.10);
    --wheel-hover-outer: rgba(255, 255, 255, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: var(--main-bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.section-title,
.sidebar-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

/* Lucide Icons */
[data-lucide] {
    display: inline-block;
    vertical-align: middle;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

/* Auth Screen */
.auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0a0e1a 0%, #0f172a 50%, #1e293b 100%);
    position: relative;
    /* The animated ::before below is 200%×200% and translates by percentages —
       must be clipped to the viewport or it triggers scroll on both axes. */
    overflow-x: hidden;
    overflow-y: auto;
    padding: 20px;
}

.auth-screen::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 50%, rgba(79, 70, 229, 0.15) 0%, transparent 50%),
                radial-gradient(circle at 70% 80%, rgba(94, 234, 212, 0.1) 0%, transparent 40%);
    animation: float 20s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    50% { transform: translate(-2%, 2%) rotate(1deg); }
}

.auth-container {
    background: rgba(255, 255, 255, 0.98);
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.4), 0 0 60px var(--accent-glow);
    width: 100%;
    max-width: 420px;
    position: relative;
    z-index: 1;
    margin: auto;
}

.auth-logo {
    text-align: center;
    margin-bottom: 30px;
    max-height: 250px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.auth-logo-img {
    width: 100%;
    max-width: 180px;
    height: auto;
    max-height: 180px;
    margin-bottom: 10px;
    background: transparent;
    border: none;
    object-fit: contain;
    content: url('https://jxnrajntnyqwgzgosdrc.supabase.co/storage/v1/object/public/kysteno-images/63ddf598-67c1-4929-a553-874da36c84af/Logo.png');
}

.dark-mode .auth-logo-img {
    content: url('https://jxnrajntnyqwgzgosdrc.supabase.co/storage/v1/object/public/kysteno-images/63ddf598-67c1-4929-a553-874da36c84af/Logo.png');
}

.auth-logo h1 {
    font-size: 32px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 5px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.auth-logo p {
    color: var(--text-muted);
    font-size: 14px;
}

.auth-tabs {
    display: flex;
    margin-bottom: 25px;
    border-bottom: 1px solid var(--border);
}

.auth-tab {
    flex: 1;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    border: none;
    background: none;
    font-size: 15px;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.2s;
}

.auth-tab:hover {
    color: var(--text);
}

.auth-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

.auth-input {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    margin-bottom: 15px;
    transition: all 0.2s;
}

.auth-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.auth-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.auth-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.auth-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.auth-error {
    background: #fef2f2;
    color: var(--danger);
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 14px;
    display: none;
}

.auth-error.show {
    display: block;
}

.auth-success {
    background: #f0fdf4;
    color: #16a34a;
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 14px;
    display: none;
}

.auth-success.show {
    display: block;
}

/* Upload progress indicator */
.upload-progress {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--sidebar-bg);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 9999;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.upload-progress.show {
    display: flex;
}

.upload-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* User menu in sidebar */
.user-menu {
    padding: 12px 16px;
    border-top: 1px solid var(--sidebar-hover);
    margin-top: auto;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.user-avatar {
    width: 26px;
    height: 26px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 12px;
    flex-shrink: 0;
}

.user-email {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.logout-btn {
    width: 100%;
    padding: 8px;
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: rgba(79, 70, 229, 0.12);
    color: var(--primary);
}

.user-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.user-action-btn {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
    border: none;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
}

.user-action-btn:hover {
    background: rgba(79, 70, 229, 0.12);
    color: var(--primary);
}

/* Dark Mode */
.dark-mode {
    /* Bear Palette - Dark Mode (Deeper blacks like bear) */
    --main-bg: #0F172A;
    --card-bg: #1E293B;
    --border: #334155;
    --border-light: #334155;
    --text: #F8FAFC;
    --text-muted: #94A3B8;
    --sidebar-bg: #0A0E1A;
    --sidebar-hover: #1E293B;
    --sidebar-active: #334155;
    --sidebar-text: #F8FAFC;
    --sidebar-muted: #94A3B8;
    /* Teal and red stay the same in dark mode */
}

/* Dark mode overrides for new UI elements */
.dark-mode .content-header {
    background: #1E293B;
}
.dark-mode .dashboard-widgets {
    background: #0F172A;
}
.dark-mode .daily-focus-card {
    background: linear-gradient(135deg, #1a1a0f 0%, #1f1d0e 100%);
    border-color: rgba(254, 230, 133, 0.2);
}
.dark-mode .daily-focus-quote {
    color: #F8FAFC;
}
.dark-mode .toc-table th {
    background: rgba(30, 41, 59, 0.8);
}
.dark-mode .header-search {
    background: #1E293B;
    border-color: #334155;
}
.dark-mode .header-search:hover {
    border-color: rgba(165, 180, 252, 0.4);
}
.dark-mode .header-search:focus-within {
    border-color: #818CF8;
    box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.18);
}
.dark-mode .header-search-input {
    color: #F8FAFC;
}
.dark-mode .header-search-shortcut {
    background: #0F172A;
    border-color: #334155;
    color: #94A3B8;
}
.dark-mode .header-create-btn {
    background: var(--primary);
}
.dark-mode .dashboard-action-btn {
    border-color: #334155;
    color: #94A3B8;
}
.dark-mode .dashboard-chip {
    border-color: #334155;
    color: #94A3B8;
}
.dark-mode .widget {
    border-bottom-color: #334155;
}

.dark-mode .ql-toolbar {
    background: #1e293b !important;
    border-color: #334155 !important;
}

.dark-mode .ql-container {
    color: #e2e8f0;
}

.dark-mode .ql-editor.ql-blank::before {
    color: #64748b;
}

.dark-mode .page-title-input {
    background: var(--card-bg);
    color: var(--text);
}

.dark-mode .modal {
    background: #1e293b;
    color: #e2e8f0;
}

.dark-mode .modal-input {
    background: #0f172a;
    color: #e2e8f0;
    border-color: #334155;
}

/* Custom toolbar buttons */
.ql-toolbar button {
    width: 28px !important;
    height: 24px !important;
}

.ql-undo, .ql-redo, .ql-table, .ql-divider, .ql-status, .ql-panel, .ql-video, .ql-toc, .ql-datepicker {
    font-size: 14px !important;
    cursor: pointer;
}

.ql-undo:hover, .ql-redo:hover, .ql-table:hover, .ql-divider:hover, 
.ql-status:hover, .ql-panel:hover, .ql-video:hover, .ql-toc:hover, .ql-datepicker:hover {
    color: var(--primary) !important;
}

/* Status lozenge styles */
.status-lozenge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-todo { background: #dfe1e6; color: #42526e; }
.status-inprogress { background: #deebff; color: #0747a6; }
.status-done { background: #e3fcef; color: #006644; }
.status-blocked { background: #ffebe6; color: #bf2600; }

/* Callout panel styles */
.callout-panel {
    padding: 16px 20px;
    border-radius: 8px;
    margin: 12px 0;
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.callout-panel .callout-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.callout-panel .callout-content {
    flex: 1;
    min-width: 0;
}

.callout-info {
    background: #CCFBF1;
    border-left: 4px solid var(--primary);
}

.callout-success {
    background: #dcfce7;
    border-left: 4px solid #22c55e;
}

.callout-warning {
    background: #fef3c7;
    border-left: 4px solid #f59e0b;
}

.callout-error {
    background: #fee2e2;
    border-left: 4px solid #ef4444;
}

.callout-note {
    background: #f3e8ff;
    border-left: 4px solid #a855f7;
}

/* Dark mode callouts */
.dark-mode .callout-info { background: #004D40; }
.dark-mode .callout-success { background: #14532d; }
.dark-mode .callout-warning { background: #451a03; }
.dark-mode .callout-error { background: #450a0a; }
.dark-mode .callout-note { background: #3b0764; }

/* Callout Block — Editor Specific */
.callout-block-inner {
    margin: 0;
}

.callout-title-field {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    outline: none;
    min-height: 20px;
}

.callout-title-field:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    font-style: italic;
    font-weight: 400;
    pointer-events: none;
}

.callout-content-field {
    font-size: 13px;
    line-height: 1.6;
    outline: none;
    min-height: 20px;
}

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

/* Viewer-mode title/body */
.callout-title-view {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

.callout-body-view {
    font-size: 13px;
    line-height: 1.6;
}

/* Callout type picker in the modal */
.callout-type-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px 10px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--card-bg);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
    text-align: center;
}

.callout-type-option:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.callout-type-option.callout-info    { border-left: 4px solid var(--primary); }
.callout-type-option.callout-success { border-left: 4px solid #22c55e; }
.callout-type-option.callout-warning { border-left: 4px solid #f59e0b; }
.callout-type-option.callout-error   { border-left: 4px solid #ef4444; }
.callout-type-option.callout-note    { border-left: 4px solid #a855f7; }

/* Horizontal divider */
.content-divider {
    border: none;
    border-top: 2px solid var(--border);
    margin: 20px 0;
}

/* Table styles */
.ql-editor table {
    border-collapse: collapse;
    width: 100%;
    margin: 15px 0;
}

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

.ql-editor table th {
    background: #f1f5f9;
    font-weight: 600;
}

.dark-mode .ql-editor table th {
    background: #334155;
}

.page-viewer-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 15px 0;
}

.page-viewer-content table td, .page-viewer-content table th {
    border: 1px solid var(--border);
    padding: 10px 12px;
    text-align: left;
}

.page-viewer-content table th {
    background: #f1f5f9;
    font-weight: 600;
}

.dark-mode .page-viewer-content table th {
    background: #334155;
}

/* TOC in dark mode */
.dark-mode .toc-container {
    background: #1e293b !important;
    border-color: #334155 !important;
}

/* Search Modal */
.search-modal {
    max-width: 600px;
}

.search-input-container {
    position: relative;
    margin-bottom: 15px;
}

.search-input {
    width: 100%;
    padding: 12px 15px 12px 40px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-results {
    max-height: 400px;
    overflow-y: auto;
}

.search-result-item {
    padding: 12px 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.search-result-item:hover {
    border-color: var(--primary);
    background: #f0f9ff;
}

.dark-mode .search-result-item:hover {
    background: #0c4a6e;
}

.search-result-title {
    font-weight: 600;
    margin-bottom: 5px;
}

.search-result-path {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.search-result-snippet {
    font-size: 13px;
    color: var(--text-muted);
}

/* Keyboard Shortcuts Modal */
.shortcuts-modal {
    max-width: 700px;
}

.shortcuts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-top: 20px;
}

.shortcuts-section {
    margin-bottom: 20px;
}

.shortcuts-section-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.shortcut-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}

.shortcut-label {
    font-size: 14px;
    color: var(--text);
}

.shortcut-keys {
    display: flex;
    gap: 4px;
}

.shortcut-key {
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 12px;
    font-family: monospace;
    color: var(--text-muted);
}

.search-result-snippet mark {
    background: #fef08a;
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

.no-results {
    text-align: center;
    padding: 30px;
    color: var(--text-muted);
}

/* Share Modal */
.share-link-container {
    display: flex;
    gap: 10px;
    margin: 15px 0;
}

.share-link-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: #f8fafc;
}

.dark-mode .share-link-input {
    background: #0f172a;
    color: #e2e8f0;
}

/* Profile Modal */
.profile-modal {
    max-width: 600px;
}

.profile-tabs {
    display: flex;
    gap: 5px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}

.profile-tab {
    padding: 10px 20px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    position: relative;
    transition: color 0.2s;
}

.profile-tab:hover {
    color: var(--text);
}

.profile-tab.active {
    color: var(--primary);
}

.profile-tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
}

.profile-tab-content {
    display: none;
}

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

.profile-form-group {
    margin-bottom: 20px;
}

.profile-form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.profile-form-group input,
.profile-form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: var(--card-bg);
    color: var(--text);
    transition: border-color 0.2s;
}

.profile-form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.profile-form-group input:focus,
.profile-form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.profile-form-group input:disabled {
    background: var(--sidebar-bg);
    cursor: not-allowed;
    color: var(--text-muted);
}

.profile-form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.share-list {
    max-height: 400px;
    overflow-y: auto;
}

.share-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    background: var(--card-bg);
}

.share-item-info {
    flex: 1;
}

.share-item-name {
    font-weight: 500;
    font-size: 14px;
    color: var(--text);
    margin-bottom: 4px;
}

.share-item-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.share-item-actions {
    display: flex;
    gap: 8px;
}

.share-item-actions button {
    padding: 6px 12px;
    font-size: 12px;
}

/* Version History Modal */
.version-history-modal {
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.version-history-content {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.version-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin: 20px 0 10px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.version-section-title:first-child {
    margin-top: 0;
}

.version-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    background: var(--card-bg);
    transition: all 0.2s;
}

.version-item:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.1);
}

.version-item.current {
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.1) 0%, rgba(79, 70, 229, 0.05) 100%);
    border-color: var(--primary);
}

.version-item.archived {
    opacity: 0.7;
}

.version-item.archived:hover {
    opacity: 1;
}

.version-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.version-icon {
    font-size: 18px;
}

.version-details {
    flex: 1;
}

.version-time {
    font-weight: 500;
    font-size: 14px;
    color: var(--text);
    margin-bottom: 2px;
}

.version-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.version-note {
    font-style: italic;
    color: var(--primary);
    margin-left: 6px;
}

.version-actions {
    display: flex;
    gap: 6px;
}

.version-actions button {
    padding: 6px 12px;
    font-size: 12px;
}

.version-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--primary);
    color: white;
    font-size: 10px;
    font-weight: 600;
    border-radius: 4px;
    text-transform: uppercase;
    margin-left: 8px;
}

.archived-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--sidebar-bg);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    border-radius: 4px;
    text-transform: uppercase;
}

.snapshot-input-group {
    margin-bottom: 15px;
}

.snapshot-input-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--card-bg);
    color: var(--text);
}

.snapshot-input-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.version-preview-modal .modal {
    max-width: 900px;
    max-height: 90vh;
}

.version-preview-content {
    max-height: calc(90vh - 150px);
    overflow-y: auto;
    padding: 20px;
    background: var(--sidebar-bg);
    border-radius: 8px;
    margin: 15px 0;
}

.dark-mode .action-btn:hover {
    background: rgba(255,255,255,0.08);
}

.dark-mode .page-menu-dropdown {
    background: var(--card-bg);
    border-color: var(--border);
}

.dark-mode .footer-action-btn:hover {
    background: rgba(255,255,255,0.08);
}

.dark-mode .reaction-chip {
    background: var(--card-bg);
}

.dark-mode .reactions-menu {
    background: var(--card-bg);
}

.dark-mode .comment-input {
    background: var(--card-bg);
    color: var(--text);
}

.dark-mode .encrypted-block {
    background: var(--card-bg);
}

.dark-mode .decrypt-btn {
    background: var(--card-bg);
}

.copy-btn {
    padding: 10px 15px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.copy-btn:hover {
    background: var(--primary-hover);
}

.share-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: #f0fdf4;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 14px;
}

.share-status.disabled {
    background: #fef2f2;
}

/* Public View Banner */
.public-banner {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
    padding: 0 20px;
    font-size: 14px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.public-banner a {
    color: white;
    text-decoration: underline;
}

.app {
    display: none;
    height: 100vh;
}

.app.show {
    display: flex;
}

/* Sidebar */
.sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    height: 100vh;
    transition: width 0.25s ease, min-width 0.25s ease, transform 0.25s ease;
    position: relative;
    border-right: 1px solid var(--border);
}

.sidebar.collapsed {
    width: 60px;
    min-width: 60px;
}

.sidebar-toggle {
    position: absolute;
    top: 20px;
    right: -20px;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    z-index: 10;
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    transform: scale(1.1);
    color: var(--primary);
}

.sidebar.collapsed .sidebar-toggle {
    transform: rotate(180deg);
}

.sidebar.collapsed .sidebar-toggle:hover {
    transform: rotate(180deg) scale(1.1);
    color: var(--primary);
}

.sidebar.collapsed .sidebar-header h1 .sidebar-brand {
    display: none;
}

.sidebar.collapsed .sidebar-header {
    padding: 0;
}

.sidebar.collapsed .sidebar-logo {
    width: 40px;
    margin: 5px auto;
}

.sidebar.collapsed .sidebar-header h1 {
    justify-content: center;
}

.sidebar.collapsed .owner-section {
    display: none;
}

.sidebar.collapsed .tree-label,
.sidebar.collapsed .tree-toggle,
.sidebar.collapsed .tree-actions {
    display: none;
}

.sidebar.collapsed .tree-item-header {
    padding: 10px 0;
    justify-content: center;
}

.sidebar.collapsed .tree-icon-btn {
    font-size: 18px;
}

.sidebar.collapsed .tree-children .tree-item-header {
    padding-left: 0;
}

.sidebar.collapsed .user-menu {
    padding: 10px;
}

.sidebar.collapsed .user-info {
    justify-content: center;
}

.sidebar.collapsed .user-email,
.sidebar.collapsed .logout-btn {
    display: none;
}

.sidebar.collapsed .user-actions {
    flex-direction: column;
    gap: 5px;
}

.sidebar.collapsed .user-action-btn {
    padding: 10px;
}

.sidebar.collapsed .sidebar-footer {
    padding: 10px;
}

.sidebar-header {
    padding: 0;
    margin: 0;
    border-bottom: 1px solid var(--sidebar-hover);
    display: flex;
    justify-content: center;
    line-height: 0;
}

/* Compact Workspace Header */
.workspace-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--sidebar-hover);
    transition: background 0.2s;
}

.workspace-header:hover {
    background: var(--sidebar-hover);
}

.workspace-logo {
    flex-shrink: 0;
}

.sidebar-logo-compact {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: cover;
    display: block;
    background: transparent;
}

/* ===== KYSTENO BRAND HEADER ===== */
.kysteno-brand-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}
.kysteno-brand-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--sidebar-text);
    line-height: 1.2;
}
.kysteno-brand-sub {
    font-size: 9px;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: 1.2px;
    text-transform: uppercase;
}

.dark-mode .sidebar-logo-compact {
    /* dark mode handled by img src */
}

/* ===== SIDEBAR NAVIGATION (Figma 2026) ===== */
.sidebar-nav {
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sidebar-nav-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--sidebar-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 4px 8px 6px;
}
.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.1s ease;
    text-decoration: none;
    border-left: 2px solid transparent;
    padding-left: 8px;
}
.sidebar-nav-item i,
.sidebar-nav-item [data-lucide] {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}
.sidebar-nav-item:hover {
    background: var(--bg-hover);
    color: var(--text);
}
.sidebar-nav-item:hover i,
.sidebar-nav-item:hover [data-lucide] {
    opacity: 1;
}
.sidebar-nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
    border-left: 2px solid var(--primary);
}
.sidebar-nav-item.active i,
.sidebar-nav-item.active [data-lucide] {
    color: var(--primary);
    opacity: 1;
}

.workspace-info {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.workspace-label {
    font-size: 9px;
    color: var(--sidebar-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.workspace-name {
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-add-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    font-weight: 400;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.workspace-add-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Sidebar Inline Search */
.sidebar-search-container {
    margin: 8px 12px;
}

.sidebar-search-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--sidebar-hover);
    border: 1px solid var(--border);
    border-radius: 6px;
    transition: all 0.2s;
}

.sidebar-search-container.focused .sidebar-search-input-wrapper,
.sidebar-search-input-wrapper:focus-within {
    border-color: var(--primary);
    background: var(--card-bg);
}

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

.sidebar-search-input::placeholder {
    color: var(--text-muted);
}

.sidebar-search-shortcut {
    font-size: 11px;
    padding: 2px 6px;
    background: var(--main-bg);
    border-radius: 4px;
    color: var(--text-muted);
}

.sidebar-search-clear {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.sidebar-search-clear:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

.sidebar-search-results {
    margin-top: 4px;
    max-height: 300px;
    overflow-y: auto;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.sidebar-search-result {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 13px;
}

.sidebar-search-result:hover {
    background: var(--sidebar-hover);
}

.sidebar-search-result:first-child {
    border-radius: 6px 6px 0 0;
}

.sidebar-search-result:last-child {
    border-radius: 0 0 6px 6px;
}

.sidebar-search-result:only-child {
    border-radius: 6px;
}

.sidebar-search-empty {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}

/* ── Semantic search results divider ── */
.semantic-search-divider {
    padding: 8px 12px 4px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
}
.semantic-search-label {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6366f1;
}
.semantic-result {
    border-left: 2px solid rgba(99, 102, 241, 0.3);
}
.semantic-result:hover {
    border-left-color: #6366f1;
}

/* ============================================================
   GITHUB / GITLAB INTEGRATION
   ============================================================ */

/* ── Gutter commits section ── */
.gutter-commits-section {
    border-top: 1px solid var(--border);
}
.gutter-commits-content {
    padding-top: 6px;
    padding-bottom: 4px;
}
.commits-repo-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}
.commits-repo-link {
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
    word-break: break-all;
    flex: 1;
}
.commits-repo-link:hover {
    text-decoration: underline;
}
.commits-sync-status {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
}
.commits-actions {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.commits-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.commits-action-btn:hover {
    background: var(--hover-bg, rgba(0,0,0,0.05));
    border-color: var(--text-muted);
}
.commits-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.commits-settings-btn {
    padding: 4px 6px;
}
.commits-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.commit-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 7px 6px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text);
    transition: background 0.15s;
    cursor: pointer;
}
.commit-item:hover {
    background: var(--hover-bg, rgba(0,0,0,0.04));
}
.commit-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}
.commit-info {
    flex: 1;
    min-width: 0;
}
.commit-message {
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}
.commit-meta {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
    flex-wrap: wrap;
}
.commit-author {
    font-weight: 500;
}
.commit-sep {
    opacity: 0.4;
}
.commit-sha {
    font-family: monospace;
    font-size: 10px;
    background: var(--code-bg, rgba(0,0,0,0.06));
    padding: 1px 4px;
    border-radius: 3px;
    color: var(--text-muted);
}
.commit-ext-icon {
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.15s;
    margin-top: 3px;
}
.commit-item:hover .commit-ext-icon {
    opacity: 1;
}
.commits-loading,
.commits-empty {
    font-size: 12px;
    color: var(--text-muted);
    padding: 8px 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ── Connect Repo Modal ── */
.connect-repo-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #dc2626;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 12px;
}
.dark-mode .connect-repo-error {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}
.connect-repo-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.5;
}
.connect-repo-hint code {
    background: var(--code-bg, rgba(0,0,0,0.06));
    padding: 1px 4px;
    border-radius: 3px;
    font-family: monospace;
}
.connect-repo-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}
.connect-repo-checkbox input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    flex-shrink: 0;
}
.form-field {
    margin-bottom: 14px;
}
.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.form-select {
    width: 100%;
    padding: 8px 10px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    outline: none;
    box-sizing: border-box;
}
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}
.connect-repo-disconnect-btn {
    background: none;
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #dc2626;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}
.connect-repo-disconnect-btn:hover {
    background: rgba(239, 68, 68, 0.08);
}

/* ── Spin animation for loading states ── */
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Dark mode adjustments ── */
.dark-mode .commit-sha {
    background: rgba(255,255,255,0.08);
}
.dark-mode .commits-action-btn:hover {
    background: rgba(255,255,255,0.07);
}
.dark-mode .form-select {
    background: var(--sidebar-bg);
}

/* ============================================================
   END GITHUB / GITLAB INTEGRATION
   ============================================================ */

.sidebar-header h1 {
    font-size: 0;
    display: flex;
    justify-content: center;
    margin: 0;
    padding: 0;
    line-height: 0;
}

.sidebar-logo {
    width: 65px;
    height: auto;
    border-radius: 0;
    object-fit: contain;
    display: block;
    margin: 5px auto;
    background: transparent;
    border: none;
    content: url('https://jxnrajntnyqwgzgosdrc.supabase.co/storage/v1/object/public/kysteno-images/63ddf598-67c1-4929-a553-874da36c84af/kysteno_logowhite.png');
}

.dark-mode .sidebar-logo {
    content: url('https://jxnrajntnyqwgzgosdrc.supabase.co/storage/v1/object/public/kysteno-images/63ddf598-67c1-4929-a553-874da36c84af/kysteno_logoblack.png');
}

.sidebar-brand {
    display: none;
}

.owner-section {
    padding: 15px 20px;
    border-bottom: 1px solid var(--sidebar-hover);
    transition: background 0.2s;
}

.owner-section:hover {
    background: var(--sidebar-hover);
}

.owner-name {
    font-size: 11px;
    color: var(--sidebar-muted);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.owner-title {
    font-size: 16px;
    font-weight: 600;
}

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

/* Recent Pages & Favorites Sections */
.sidebar-quick-section {
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
}

.sidebar-quick-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    cursor: pointer;
    user-select: none;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-quick-header:hover {
    color: var(--primary);
}

.sidebar-quick-toggle {
    transition: transform 0.2s;
}

.sidebar-quick-section.collapsed .sidebar-quick-toggle {
    transform: rotate(-90deg);
}

.sidebar-quick-section.collapsed .sidebar-quick-list,
.sidebar-quick-section.collapsed .nav-tree {
    display: none;
}

/* When directories is collapsed, don't take up flex space */
.sidebar-quick-section.collapsed {
    flex: 0 0 auto !important;
}

.sidebar-quick-list {
    padding: 0;
    max-height: 150px;
    overflow-y: auto;
}

.sidebar-quick-list::-webkit-scrollbar {
    width: 4px;
}

.sidebar-quick-list::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-quick-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.sidebar-quick-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.sort-toggle-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    transition: all 0.2s;
}

.sort-toggle-btn:hover {
    background: var(--sidebar-hover);
    color: var(--primary);
}

.sidebar-quick-item {
    display: flex;
    align-items: center;
    padding: 5px 16px;
    cursor: pointer;
    transition: all 0.15s;
    gap: 8px;
    color: var(--text);
    font-size: 13px;
}

.sidebar-quick-item:hover {
    background: rgba(79, 70, 229, 0.08);
    color: var(--primary);
}

.sidebar-quick-item.active {
    background: var(--sidebar-active);
    color: var(--primary);
}

.sidebar-quick-item i {
    flex-shrink: 0;
}

.sidebar-quick-item-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-quick-item-star {
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: all 0.15s;
}

.sidebar-quick-item:hover .sidebar-quick-item-star {
    opacity: 1;
}

.sidebar-quick-item-star.starred {
    opacity: 1 !important;
    color: #FFA500;
}

.sidebar-quick-empty {
    padding: 12px 20px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
}

.tree-item {
    user-select: none;
}

.tree-item-header {
    display: flex;
    align-items: center;
    padding: 6px 15px 6px 20px;
    cursor: pointer;
    transition: all 0.15s;
    gap: 8px;
    position: relative;
}

.tree-item-header:hover {
    background: rgba(79, 70, 229, 0.08);
    color: var(--primary);
}
.tree-item-header:hover .tree-name {
    color: var(--primary);
}

.tree-item-header.active {
    background: rgba(79, 70, 229, 0.12);
    border-right: 3px solid var(--primary);
}
.tree-item-header.active .tree-name {
    color: var(--primary);
    font-weight: 600;
}

.tree-toggle {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--sidebar-muted);
    font-size: 10px;
    transition: transform 0.2s;
}

.tree-toggle.expanded {
    transform: rotate(90deg);
}

.tree-toggle.hidden {
    visibility: hidden;
}

.tree-icon {
    font-size: 14px;
}

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

.tree-actions {
    display: none;
    gap: 5px;
}

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

.tree-action-btn {
    background: none;
    border: none;
    color: var(--sidebar-muted);
    cursor: pointer;
    padding: 2px 5px;
    font-size: 12px;
    border-radius: 3px;
}

.tree-action-btn:hover {
    background: var(--sidebar-active);
    color: var(--primary-light);
}

.tree-children {
    display: none;
}

.tree-children.expanded {
    display: block;
}

.tree-children .tree-item-header {
    padding-left: 20px;
}

.tree-children .tree-children .tree-item-header {
    padding-left: 20px;
}

.tree-children .tree-children .tree-children .tree-item-header {
    padding-left: 20px;
}

/* Hide toggle arrows for nested items to remove visual indent */
.tree-children .tree-toggle {
    display: none;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
}

.add-project-btn {
    width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    background: var(--card-bg) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
    border-radius: 50% !important;
    cursor: pointer;
    font-size: 20px !important;
    font-weight: 400 !important;
    transition: all 0.2s;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
}

.add-project-btn:hover {
    background: var(--sidebar-hover) !important;
    border-color: var(--primary) !important;
}

.add-project-btn span {
    display: none !important;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.main-content::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60%;
    height: 60%;
    background-image: url('https://jxnrajntnyqwgzgosdrc.supabase.co/storage/v1/object/public/kysteno-images/63ddf598-67c1-4929-a553-874da36c84af/kysteno_logowhite.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.03;
    pointer-events: none;
    z-index: 0;
}

.dark-mode .main-content::before {
    background-image: url('https://jxnrajntnyqwgzgosdrc.supabase.co/storage/v1/object/public/kysteno-images/63ddf598-67c1-4929-a553-874da36c84af/kysteno_logoblack.png');
    opacity: 0.08;
}

.content-header {
    height: 64px;
    min-height: 64px;
    padding: 0 20px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: none;
    display: flex !important;
    align-items: center;
    justify-content: flex-start;
    position: relative;
    z-index: 100;
    gap: 8px;
}

.content-header.collapsed {
    display: flex !important;
    height: 64px;
    min-height: 64px;
    padding: 0 20px;
    overflow: visible;
}

.content-header.collapsed .breadcrumb,
.content-header.collapsed .content-actions {
    opacity: 0;
    pointer-events: none;
}

/* ===== HEADER BAR ELEMENTS (Figma 2026) ===== */
.header-search {
    flex: 0 1 560px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--main-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: text;
    transition: border-color 0.15s;
    position: relative;
}
.header-search:hover {
    border-color: var(--primary);
}
.header-search-placeholder {
    flex: 1;
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.header-search-shortcut {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    flex-shrink: 0;
}
.header-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.header-icon-btn:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}
.header-create-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    background: var(--primary);
    color: #FFFFFF;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}
.header-create-btn:hover {
    background: var(--primary-hover);
}
.header-spacer {
    flex: 1;
}
.header-create-btn i {
    color: #FFFFFF;
}

/* Header Search - Input & Dropdown */
.header-search-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 13px;
    color: var(--text);
    outline: none;
    min-width: 0;
}
.header-search-input:focus {
    box-shadow: none;
    border: none;
}
.header-search-input::placeholder {
    color: var(--text-muted);
}
.header-search-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-dropdown);
    z-index: 9999;
    overflow: hidden;
}
.header-search-filters {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.header-search-filters .search-filter-row {
    display: flex;
    gap: 6px;
}
.header-search-filters select {
    flex: 1;
    padding: 5px 8px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--main-bg);
    color: var(--text);
    cursor: pointer;
    outline: none;
}
.header-search-filters select:focus {
    border-color: var(--primary);
}
.header-search-filters .search-filter-reset {
    padding: 5px 10px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--main-bg);
    color: var(--text-muted);
    cursor: pointer;
}
.header-search-filters .search-filter-reset:hover {
    color: var(--danger);
    border-color: var(--danger);
}
.header-search-results {
    max-height: 360px;
    overflow-y: auto;
}
.header-search-results .sidebar-search-result-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--border);
}
.header-search-results .sidebar-search-result-item:last-child {
    border-bottom: none;
}
.header-search-results .sidebar-search-result-item:hover {
    background: var(--sidebar-hover);
}
.header-search-results .search-result-name {
    font-weight: 500;
    font-size: 13px;
    color: var(--text);
}
.header-search-results .search-result-snippet {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}
.header-search-results .search-result-labels {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 4px;
}
.header-search-results .search-result-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 3px;
}
.header-search-no-results {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ===== KYMA NAV WHEEL (Daisy Wheel) ===== */
.kyma-wheel-wrap {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
}
.kyma-hub {
    width: 42px;
    height: 42px;
    cursor: pointer;
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(79, 70, 229, 0.4);
    transition: transform 0.2s;
    position: relative;
    z-index: 10;
}
.kyma-hub:hover { transform: scale(1.08); }
.kyma-hub-img { width: 100%; height: 100%; }

/* Wheel panel */
.kyma-wheel-panel {
    position: absolute;
    bottom: -10px;
    right: -10px;
    width: 480px;
    height: 480px;
    opacity: 0;
    transform: scale(0);
    transform-origin: bottom right;
    transition: opacity 0.3s, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}
.kyma-wheel-wrap.expanded .kyma-wheel-panel {
    opacity: 1;
    transform: scale(1);
    pointer-events: all;
}
.kyma-wheel-wrap.expanded .kyma-hub {
    opacity: 0;
    pointer-events: none;
}
/* Outer ring background (teal donut) */
.kyma-outer-ring-bg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 480px;
    height: 480px;
    border-radius: 50%;
    background: radial-gradient(circle closest-side,
        transparent 75.5%,
        var(--wheel-ring-tint) 76%,
        var(--wheel-ring-mid) 88%,
        var(--wheel-ring-outer) 100%
    );
    pointer-events: none;
    z-index: 1;
    border: 2px solid var(--wheel-border);
}
/* Outer ring section divider lines */
.kyma-outer-ring-dividers {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 480px;
    height: 480px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 2;
}
.kyma-outer-ring-dividers .divider-line {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1px;
    height: 58px;
    background: var(--wheel-divider);
    transform-origin: 0 0;
}
/* 8 divider lines at 22.5°, 67.5°, 112.5°, 157.5°, 202.5°, 247.5°, 292.5°, 337.5° */
.kyma-outer-ring-dividers .divider-line:nth-child(1) { transform: rotate(337.5deg) translateY(-183px); }
.kyma-outer-ring-dividers .divider-line:nth-child(2) { transform: rotate(22.5deg) translateY(-183px); }
.kyma-outer-ring-dividers .divider-line:nth-child(3) { transform: rotate(67.5deg) translateY(-183px); }
.kyma-outer-ring-dividers .divider-line:nth-child(4) { transform: rotate(112.5deg) translateY(-183px); }
.kyma-outer-ring-dividers .divider-line:nth-child(5) { transform: rotate(157.5deg) translateY(-183px); }
.kyma-outer-ring-dividers .divider-line:nth-child(6) { transform: rotate(202.5deg) translateY(-183px); }
.kyma-outer-ring-dividers .divider-line:nth-child(7) { transform: rotate(247.5deg) translateY(-183px); }
.kyma-outer-ring-dividers .divider-line:nth-child(8) { transform: rotate(292.5deg) translateY(-183px); }
.kyma-wheel-base-bg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 2;
}
.kyma-wheel-svg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(calc(-50% + 12px), calc(-50% + 1px));
    width: 340px;
    height: auto;
    pointer-events: none;
    z-index: 2;
}
/* Inner ring clickable section overlays */
.kyma-wheel-sections {
    position: absolute;
    width: 340px;
    height: 340px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 4;
    clip-path: circle(50% at 50% 50%);
}
.kyma-section {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    color: transparent;
    font-size: 0;
    text-decoration: none;
    transition: background 0.2s;
}
.kyma-section:hover {
    background: var(--wheel-hover-inner);
}
/* Outer ring clickable section overlays */
.kyma-wheel-outer-sections {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
}
.kyma-outer-section {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    color: transparent;
    font-size: 0;
    text-decoration: none;
    transition: background 0.2s;
}
.kyma-outer-section:hover {
    background: var(--wheel-hover-outer);
}
/* Outer ring labels (non-interactive, positioned at mid-arc) */
.kyma-outer-labels {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none;
}
.kyma-outer-label {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    pointer-events: none;
    color: var(--wheel-label);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
    transform: translate(-50%, -50%);
    transition: color 0.15s, transform 0.15s;
    white-space: nowrap;
}
.kyma-outer-label .outer-icon {
    font-size: 20px;
    line-height: 1;
}
.kyma-outer-label.highlighted {
    color: #ffffff;
    transform: translate(-50%, -50%) scale(1.12);
}
.kyma-wheel-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70px;
    height: 70px;
    cursor: pointer;
    z-index: 5;
    transition: transform 0.2s;
}
.kyma-wheel-center:hover { transform: translate(-50%, -50%) scale(1.06); }
.kyma-wheel-center img { width: 100%; height: 100%; }
/* ============================================================
   Daisy Wheel: Glassmorphic variant (.wheel-glass)
   ============================================================ */

/* Outer ring — frosted glass donut (mask punches the center hole) */
.wheel-glass .kyma-outer-ring-bg {
    background: rgba(79, 70, 229, 0.30);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    mask-image: radial-gradient(circle closest-side,
        transparent 75.5%,
        black 76%,
        black 100%
    );
    -webkit-mask-image: radial-gradient(circle closest-side,
        transparent 75.5%,
        black 76%,
        black 100%
    );
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 0 0 1px rgba(79, 70, 229, 0.2);
}
/* Inner ring — subtle frosted circle behind SVG */
.wheel-glass .kyma-wheel-sections::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(79, 70, 229, 0.12);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    pointer-events: none;
    z-index: 0;
}
/* Brighter dividers in glass mode */
.wheel-glass .kyma-outer-ring-dividers .divider-line {
    background: rgba(255, 255, 255, 0.35);
}
/* Labels — slightly brighter with shadow for legibility */
.wheel-glass .kyma-outer-label {
    color: #e8f4f2;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
/* Outer hover — lighter overlay for glass */
.wheel-glass .kyma-outer-section:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* ============================================================
   Daisy Wheel: Color presets
   ============================================================ */

/* Default indigo (explicit class, mirrors :root defaults) */
.wheel-teal {
    --wheel-ring-tint:   #6366F1;
    --wheel-ring-mid:    #4F46E5;
    --wheel-ring-outer:  #4338CA;
    --wheel-border:      rgba(139, 92, 246, 0.5);
    --wheel-label:       #E0E7FF;
    --wheel-hover-inner: rgba(79, 70, 229, 0.10);
    --wheel-hover-outer: rgba(255, 255, 255, 0.15);
}
/* Dark indigo */
.wheel-dark {
    --wheel-ring-tint:   #312E81;
    --wheel-ring-mid:    #28256B;
    --wheel-ring-outer:  #1E1B4B;
    --wheel-border:      rgba(139, 92, 246, 0.4);
    --wheel-label:       #C7D2FE;
    --wheel-hover-inner: rgba(79, 70, 229, 0.15);
    --wheel-hover-outer: rgba(255, 255, 255, 0.10);
}
/* Midnight navy (pairs well with .wheel-glass) */
.wheel-midnight {
    --wheel-ring-tint:   #1a2540;
    --wheel-ring-mid:    #141c30;
    --wheel-ring-outer:  #111827;
    --wheel-border:      rgba(120, 150, 255, 0.35);
    --wheel-label:       #a8b8d8;
    --wheel-hover-inner: rgba(120, 150, 255, 0.12);
    --wheel-hover-outer: rgba(255, 255, 255, 0.10);
}
/* Deep plum (retired green preset) */
.wheel-forest {
    --wheel-ring-tint:   #6B46C1;
    --wheel-ring-mid:    #5B37B0;
    --wheel-ring-outer:  #4C2A95;
    --wheel-border:      rgba(167, 139, 250, 0.4);
    --wheel-label:       #DDD6FE;
    --wheel-hover-inner: rgba(139, 92, 246, 0.12);
    --wheel-hover-outer: rgba(255, 255, 255, 0.12);
}

/* Theme toggle button — upper-left of expanded wheel, clear of the AI chat button */
.kyma-theme-btn {
    position: absolute;
    top: 8px;
    left: 6px;
    z-index: 20;
    background: var(--card-bg);
    color: var(--primary);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    box-shadow: var(--shadow-dropdown);
    transition: background 0.2s, color 0.2s, transform 0.2s, opacity 0.2s, box-shadow 0.2s;
    line-height: 1;
    padding: 0;
    opacity: 0;
    pointer-events: none;
}
.kyma-wheel-wrap.expanded .kyma-theme-btn {
    opacity: 1;
    pointer-events: all;
}
.kyma-theme-btn:hover {
    background: var(--primary);
    color: #fff;
    transform: rotate(60deg);
    box-shadow: var(--shadow-popover);
}

/* ============================================================
   Responsive: hide outer ring on small screens
   ============================================================ */
/* Responsive: hide outer ring on small screens */
@media (max-width: 520px) {
    .kyma-wheel-panel {
        width: 350px;
        height: 350px;
    }
    .kyma-wheel-outer-sections,
    .kyma-outer-ring-bg,
    .kyma-outer-labels {
        display: none;
    }
    .kyma-wheel-sections {
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        transform: none;
    }
    .kyma-theme-btn {
        top: 8px;
        left: 6px;
    }
}

.page-date {
    font-size: 12px;
    color: var(--text-muted);
}

.edit-mode-label {
    font-size: 12px;
    color: var(--primary);
    font-weight: 500;
    padding: 4px 8px;
    background: var(--accent-glow);
    border-radius: 4px;
}

.save-btn {
    color: var(--primary) !important;
}

.save-btn:hover {
    background: var(--accent-glow) !important;
}

.content-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: transparent;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.action-btn svg {
    flex-shrink: 0;
}

.action-btn:hover {
    background: rgba(0,0,0,0.05);
    color: var(--text);
}

.action-btn.primary {
    background: transparent;
    color: var(--text-muted);
    border: none;
}

.action-btn.primary:hover {
    background: rgba(0,0,0,0.05);
    color: var(--text);
}

.action-btn.danger {
    color: var(--text-muted);
}

.action-btn.danger:hover {
    background: rgba(220, 38, 38, 0.08);
    color: #dc2626;
}

.action-btn-icon {
    padding: 6px 8px;
}

.action-divider {
    width: 1px;
    height: 16px;
    background: var(--border);
    margin: 0 6px;
}

/* Page menu dropdown */
.page-menu-dropdown {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    min-width: 160px;
    z-index: 1000;
    overflow: hidden;
}

.page-menu-dropdown .menu-item {
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s;
}

.page-menu-dropdown .menu-item:hover {
    background: var(--accent-glow);
}

.page-menu-dropdown .menu-item.danger {
    color: #dc2626;
}

.page-menu-dropdown .menu-item.danger:hover {
    background: #fef2f2;
}

.page-menu-dropdown .menu-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.header-toggle {
    display: none;
}

.header-toggle:hover {
    background: var(--primary-hover);
}

/* Position buttons for cover picker */
.position-btn {
    flex: 1;
    padding: 8px 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.position-btn:hover {
    border-color: var(--primary);
}

.position-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Tables */
.kysteno-table-wrapper {
    margin: 0;
    overflow-x: auto;
}

.editor-blocks {
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: flex-start;
}

.editor-blocks:empty {
    display: none;
}

.block-item {
    position: relative;
    border: none;
    border-radius: 6px;
    box-sizing: border-box;
    margin: 0;
    padding-top: 24px; /* Space for drag bar */
}

/* Block width classes */
.block-item.width-full { width: 100%; }
.block-item.width-half { width: calc(50% - 3px); }
.block-item.width-third { width: calc(33.333% - 4px); }
.block-item.width-two-thirds { width: calc(66.666% - 3px); }

.block-item:hover {
    outline: 2px solid var(--primary);
    outline-offset: 0;
}

.block-item .block-controls {
    position: absolute;
    top: 2px;
    right: 4px;
    display: none;
    gap: 2px;
    background: var(--card-bg);
    padding: 2px;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    z-index: 10;
}

.block-item:hover .block-controls {
    display: flex;
}

.block-controls button {
    width: 22px;
    height: 22px;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.block-controls button:hover {
    background: var(--main-bg);
    color: var(--text);
}

.block-controls .block-delete:hover {
    background: #fee2e2;
    color: #dc2626;
}

.block-controls select {
    font-size: 10px;
    padding: 2px 4px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: white;
    cursor: pointer;
}

.block-item .block-drag {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 22px;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 10px;
    background: var(--sidebar-hover);
    border-radius: 6px 6px 0 0;
    opacity: 0.6;
    transition: opacity 0.15s, background 0.15s;
}

.block-item:hover .block-drag {
    opacity: 1;
    background: #6B7280;
    color: white;
}

.block-item .block-drag:active {
    cursor: grabbing;
}

.block-item.dragging {
    opacity: 0.5;
    border: 2px dashed var(--primary);
}

.block-item.drag-over {
    border-top: 2px solid var(--primary);
}

/* Column layout block */
.column-layout {
    display: flex;
    gap: 12px;
    width: 100%;
    background: transparent;
    border-radius: 6px;
    padding: 0;
    min-height: 40px;
}

.column-layout .column {
    flex: 1;
    min-height: 30px;
    border: 1px dashed var(--border);
    border-radius: 4px;
    padding: 8px;
    background: transparent;
}

.column-layout .column.has-bg {
    border: none;
}

.column-layout .column[data-size="1"] { flex: 1; }
.column-layout .column[data-size="2"] { flex: 2; }

.column-layout .column-content {
    min-height: 30px;
}

.column-layout .column-content[contenteditable="true"]:empty:before {
    content: 'Type here...';
    color: var(--text-muted);
    font-style: italic;
}

/* Cell/Column Color Picker */
.color-picker-popup {
    position: fixed;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 9999;
    display: none;
}

.color-picker-popup.visible {
    display: block;
}

.color-picker-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 6px;
    display: block;
}

.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(6, 24px);
    gap: 4px;
}

.color-picker-swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.1s;
}

.color-picker-swatch:hover {
    transform: scale(1.1);
    border-color: var(--primary);
}

.color-picker-swatch.clear {
    background: linear-gradient(135deg, #fff 45%, #ff0000 45%, #ff0000 55%, #fff 55%);
    border: 1px solid var(--border);
}

/* Viewer blocks container */
.viewer-blocks {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: flex-start;
    margin-top: 8px;
}

.viewer-blocks .block-item {
    border: none;
}

.viewer-blocks .block-item:hover {
    border: none;
}

/* Column picker modal */
.column-option {
    padding: 12px;
    background: var(--main-bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
}

.column-option:hover {
    border-color: var(--primary);
    background: var(--accent-glow);
}

/* Hover Preview Card */
.hover-preview {
    position: fixed;
    width: 320px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    padding: 16px;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    transform: translateY(5px);
    transition: opacity 0.15s, transform 0.15s;
}

.hover-preview.visible {
    opacity: 1;
    transform: translateY(0);
}

.hover-preview-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.hover-preview-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: var(--main-bg);
    border-radius: 6px;
}

.hover-preview-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hover-preview-owner {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.hover-preview-owner a {
    color: var(--primary);
    text-decoration: none;
}

.hover-preview-snippet {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
    max-height: 60px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.hover-preview-date {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.dark-mode .hover-preview {
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}

.kysteno-table,
.ql-editor .kysteno-table,
.page-viewer-content table,
.ql-editor table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    font-size: 14px;
    display: table !important;
}

.kysteno-table th,
.kysteno-table td,
.ql-editor table th,
.ql-editor table td,
.page-viewer-content table th,
.page-viewer-content table td {
    border: 1px solid var(--border) !important;
    padding: 10px 12px !important;
    text-align: left;
    min-width: 80px;
    display: table-cell !important;
}

.kysteno-table th,
.ql-editor table th,
.page-viewer-content table th {
    background: var(--main-bg);
    font-weight: 600;
    color: var(--text);
}

.kysteno-table tr,
.ql-editor table tr,
.page-viewer-content table tr {
    display: table-row !important;
}

.kysteno-table tbody,
.ql-editor table tbody,
.page-viewer-content table tbody {
    display: table-row-group !important;
}

.kysteno-table tr:hover td {
    background: rgba(77, 182, 172, 0.05);
}

.kysteno-table td[contenteditable="true"],
.kysteno-table th[contenteditable="true"] {
    cursor: text;
}

.kysteno-table td:focus,
.kysteno-table th:focus {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    background: white;
}

/* ===== ADVANCED TABLE TOOLBAR ===== */
.table-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--main-bg);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    flex-wrap: wrap;
}

.table-filter-input {
    flex: 1;
    min-width: 140px;
    max-width: 260px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    background: var(--card-bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
}

.table-filter-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.table-filter-input::placeholder {
    color: var(--text-muted);
}

.table-toolbar-btn {
    padding: 4px 9px;
    font-size: 11px;
    font-weight: 500;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.table-toolbar-btn:hover {
    background: var(--sidebar-hover);
    color: var(--text);
    border-color: var(--primary);
}

.table-toolbar-label {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ===== SORTABLE HEADERS ===== */
.kysteno-table th.sortable {
    position: relative;
    user-select: none;
}

.kysteno-table th .th-text {
    display: inline-block;
    outline: none;
    min-width: 20px;
    cursor: text;
}

.kysteno-table th .th-text:focus {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
    border-radius: 2px;
    background: white;
}

.kysteno-table th .th-sort-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 4px;
    border-radius: 3px;
    cursor: pointer;
    vertical-align: middle;
    opacity: 0.4;
    font-size: 11px;
    transition: opacity 0.15s, background 0.15s;
}

.kysteno-table th .th-sort-btn::after {
    content: '⇅';
}

.kysteno-table th .th-sort-btn:hover {
    opacity: 1;
    background: var(--sidebar-active);
}

.kysteno-table th.sort-asc .th-sort-btn::after {
    content: '▲';
}

.kysteno-table th.sort-desc .th-sort-btn::after {
    content: '▼';
}

.kysteno-table th.sort-active .th-sort-btn {
    opacity: 1;
    color: var(--primary);
}

.kysteno-table th.sort-active {
    background: rgba(79, 70, 229, 0.07);
    color: var(--primary);
}

/* ===== FORMULA CELLS ===== */
.formula-cell {
    font-style: italic;
    color: var(--text-muted);
    cursor: pointer !important;
    background: rgba(79, 70, 229, 0.04) !important;
}

.formula-cell:hover {
    outline: 2px dashed var(--primary);
    outline-offset: -2px;
}

.formula-cell.formula-error {
    color: #dc2626;
    font-style: normal;
    font-weight: 600;
}

/* ===== ADD ROW / COL BUTTONS ===== */
.table-add-row-btn,
.table-add-col-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
    border-radius: 4px;
}

.table-add-row-btn {
    width: 100%;
    height: 28px;
    margin-top: 2px;
}

.table-add-col-btn {
    min-width: 28px;
    height: 100%;
    margin-left: 2px;
}

.table-add-row-btn:hover,
.table-add-col-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--accent-glow);
}

/* ===== FILTERED ROW HIGHLIGHT ===== */
.kysteno-table tr.filter-match td {
    background: rgba(79, 70, 229, 0.05);
}

/* ===== COL TYPE BADGE ON HEADER ===== */
.col-type-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    opacity: 0.6;
    margin-left: 4px;
    vertical-align: middle;
}

/* ===== DARK MODE ADJUSTMENTS ===== */
.dark-mode .table-toolbar {
    background: var(--card-bg);
    border-color: var(--border);
}

.dark-mode .table-filter-input {
    background: var(--sidebar-hover);
}

.dark-mode .kysteno-table th.sort-active {
    background: rgba(79, 70, 229, 0.2);
}

.dark-mode .formula-cell {
    background: rgba(79, 70, 229, 0.1) !important;
}

.ql-table {
    width: 28px !important;
    height: 24px !important;
    padding: 3px 5px !important;
}

.ql-table svg {
    width: 18px;
    height: 18px;
}

.ql-table-custom {
    background: none;
    border: none;
    cursor: pointer;
    padding: 3px 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ql-table-custom:hover {
    color: var(--primary);
}

.ql-table-custom svg {
    width: 18px;
    height: 18px;
}

.breadcrumb {
    display: none;
}

.breadcrumb span {
    color: var(--text);
    font-weight: 500;
}

.btn {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.btn-icon {
    padding: 8px;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.btn-ai {
    background: var(--ai);
    color: #fff;
}

.btn-ai:hover {
    background: #7C3AED;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #B91C1C;
}

/* Universal focus ring */
input:focus,
select:focus,
textarea:focus,
.header-search:focus-within {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

.content-body {
    flex: 1;
    overflow-y: auto;
    padding: 15px 0px;
    position: relative;
    z-index: 1;
}

/* Welcome Screen / Dashboard */
.welcome-screen {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 10px 15px 15px 15px;
    overflow-y: auto;
}

.dashboard-container {
    width: 100%;
    max-width: 1000px;
}

.dashboard-top-bar {
    display: none;
}

.dashboard-logo-section {
    display: none;
}

.dashboard-logo-small {
    display: none;
}

/* ===== FIGMA DASHBOARD TITLE ROW ===== */
.dashboard-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.dashboard-title-left {
    display: flex;
    align-items: center;
}
.dashboard-page-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}
.dashboard-page-count {
    background: var(--primary);
    color: #FFFFFF;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 12px;
    margin-left: 4px;
}
.dashboard-title-right {
    display: flex;
    align-items: center;
    gap: 6px;
}
.dashboard-action-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}
.dashboard-action-btn:hover {
    background: var(--sidebar-hover);
    color: var(--text);
    border-color: var(--text-muted);
}

/* Filter Chips */
.dashboard-filter-chips {
    margin-bottom: 12px;
}
.dashboard-chip-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 16px;
}
.dashboard-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}
.dashboard-chip:hover {
    background: var(--bg-hover);
    color: var(--text);
}
.dashboard-chip i {
    color: var(--text-muted);
}
.dashboard-chip.chip-active {
    background: var(--primary);
    color: #FFFFFF;
    border-color: var(--primary);
}
.dashboard-chip.chip-active i {
    color: #FFFFFF;
}

/* Dashboard Dropdowns */
.dash-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 180px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-dropdown);
    z-index: 300;
    overflow: hidden;
}
.dash-dropdown.show {
    display: block;
}
.dash-dropdown-item {
    padding: 8px 14px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.1s;
}
.dash-dropdown-item:hover {
    background: var(--sidebar-hover);
}
.dash-dropdown-item.active {
    color: var(--primary);
    font-weight: 600;
}

/* Chip Dropdowns */
.dash-chip-wrapper {
    display: inline-block;
}
.dash-chip-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 200px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    z-index: 300;
    overflow: hidden;
}
.dash-chip-dropdown.show {
    display: block;
}
.dash-chip-dropdown-content {
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-height: 250px;
    overflow-y: auto;
}
.dash-chip-dropdown-content .dash-dropdown-item {
    border-radius: 4px;
}

.dark-mode .dashboard-logo-small {
    content: url('https://jxnrajntnyqwgzgosdrc.supabase.co/storage/v1/object/public/kysteno-images/63ddf598-67c1-4929-a553-874da36c84af/kysteno_logoblack.png');
}

.dashboard-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}

.dashboard-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.filter-btn {
    padding: 6px 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.filter-btn:hover {
    border-color: var(--primary);
    color: var(--text);
}

.filter-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.filter-count {
    background: rgba(0,0,0,0.1);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 11px;
}

.filter-btn.active .filter-count {
    background: rgba(255,255,255,0.2);
}

.toc-table-container {
    background: transparent;
    border-radius: 0;
    border: none;
    overflow: visible;
}

.toc-table {
    width: 100%;
    border-collapse: collapse;
    background: transparent;
}

.toc-table thead {
    background: transparent;
}

.toc-table th {
    text-align: left;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: none;
    border-bottom: 1px solid var(--border);
}

.toc-table td {
    padding: 8px 12px;
    font-size: 14px;
    border: none;
}

.toc-table tbody tr {
    cursor: pointer;
    transition: background 0.15s;
}

.toc-table tbody tr:hover {
    background: rgba(77, 182, 172, 0.08);
}

.toc-table tbody tr:last-child td {
    border-bottom: none;
}

.toc-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.toc-icon {
    font-size: 16px;
}

.toc-parent, .toc-project {
    color: var(--text-muted);
}

.toc-date {
    color: var(--text-muted);
    font-size: 13px;
}

.toc-empty {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

/* Folder view item hover */
#folderView div[onclick]:hover {
    background: rgba(77, 182, 172, 0.08) !important;
}

.dark-mode .toc-table thead {
    background: transparent;
}

.dark-mode .toc-table-container {
    background: transparent;
}

/* Page Viewer */
.page-viewer {
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.page-viewer-scroll {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.page-cover-image {
    width: 100%;
    min-height: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    margin: 0;
}

.page-cover-image.has-cover {
    min-height: 80px;
    /* height set via inline style */
}

/* Editor - show clickable area for adding cover */
.page-cover-image:not(.has-cover):not(.page-cover-view) {
    background: transparent;
    border-bottom: none;
    height: 30px !important;
}

/* Viewer - hide empty cover completely */
.page-cover-view:not(.has-cover) {
    display: none;
}

/* View mode - not clickable */
.page-cover-view {
    cursor: default;
    margin: 0;
}

.page-cover-view:not(.has-cover) {
    display: none;
}

.page-cover-view:not(.has-cover)::after {
    display: none;
}

.page-cover-image:not(.has-cover)::after {
    content: '+ Add cover image';
    display: block;
    text-align: left;
    padding: 6px 20px;
    color: var(--text-muted);
    font-size: 13px;
    opacity: 0;
    transition: opacity 0.2s;
}

.page-cover-image:not(.has-cover):hover {
    background: transparent;
}

.page-cover-image:not(.has-cover):hover::after {
    opacity: 0.7;
}

.page-cover-image.has-cover:hover::after {
    content: 'Change cover';
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
}

/* Hide hover text on view mode */
.page-cover-view.has-cover:hover::after {
    display: none;
}

.page-viewer-header {
    display: none;
}

.page-viewer-header h1 {
    font-size: 13px;
    font-weight: 400;
    margin: 0;
    color: var(--text-muted);
}

.page-meta {
    font-size: 12px;
    color: var(--text-muted);
    opacity: 0.7;
}

.page-viewer-content {
    flex: 1;
    padding: 8px 20px 15px;
    font-size: 16px;
    line-height: 1.7;
}

.page-title-display {
    font-size: 24px;
    font-weight: 400;
    color: var(--text);
    margin: 0;
    line-height: 1.2;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.viewer-title-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
}

.viewer-page-icon {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.viewer-page-icon-emoji {
    font-size: 36px;
    line-height: 1;
    flex-shrink: 0;
}

.viewer-icon-wrapper {
    padding: 4px 20px 0;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    z-index: 100;
    min-width: 0;
    overflow: hidden;
}

/* Add extra padding on right when gutter is visible to prevent overlap */
.main-content.with-gutter .viewer-icon-wrapper {
    padding-right: 30px;
}

.viewer-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

.page-icon-display {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    flex-shrink: 0;
    color: var(--text);
}

.page-icon-display img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
}

/* Page Footer - Labels, Reactions, Comments */
.page-footer {
    padding: 6px 20px 8px;
    margin-top: 8px;
}

.page-footer-divider {
    height: 1px;
    background: var(--border);
    margin-bottom: 6px;
}

.page-footer-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.footer-right {
    display: flex;
    gap: 4px;
}

.footer-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    background: transparent;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.footer-action-btn svg {
    width: 14px;
    height: 14px;
}

.footer-action-btn:hover {
    background: rgba(0,0,0,0.05);
    color: var(--text);
}

/* Labels */
.page-labels {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}

.page-labels:empty {
    display: none;
}

.page-label {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    background: var(--accent-glow);
    border: 1px solid var(--primary);
    border-radius: 10px;
    font-size: 11px;
    color: var(--primary);
    cursor: pointer;
}

.page-label:hover {
    background: var(--primary);
    color: white;
}

.page-label .remove-label {
    font-size: 12px;
    line-height: 1;
    opacity: 0.7;
}

.page-label .remove-label:hover {
    opacity: 1;
}

/* Reactions */
.page-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.page-reactions:empty {
    display: none;
}

.reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    background: var(--main-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.reaction-chip:hover {
    border-color: var(--primary);
    background: var(--accent-glow);
}

.reaction-chip.active {
    border-color: var(--primary);
    background: var(--accent-glow);
}

.reaction-chip .count {
    font-size: 11px;
    color: var(--text-muted);
}

.reactions-menu {
    position: fixed;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    padding: 8px;
    display: flex;
    gap: 4px;
    z-index: 1000;
}

.reactions-menu button {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.15s;
}

.reactions-menu button:hover {
    background: var(--accent-glow);
    transform: scale(1.2);
}

/* Comments */
/* Comments */
.page-comments {
    margin-top: 12px;
}

.page-comments:empty {
    display: none;
}

.comment-box {
    margin-bottom: 12px;
}

.comment-input {
    width: 100%;
    min-height: 60px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    resize: vertical;
    font-family: inherit;
    box-sizing: border-box;
    background: var(--bg);
    color: var(--text);
}

.comment-input:focus {
    outline: none;
    border-color: var(--primary);
}

.comment-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

/* Main comment item */
.comment-item {
    display: flex;
    gap: 10px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    transition: opacity 0.2s;
}

.comment-item.comment-resolved {
    opacity: 0.55;
}

.comment-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 500;
    flex-shrink: 0;
}

.comment-content {
    flex: 1;
    min-width: 0;
}

.comment-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.comment-author {
    font-weight: 500;
    font-size: 13px;
}

.comment-date {
    font-size: 12px;
    color: var(--text-muted);
}

.comment-text {
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.comment-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: auto;
}

.comment-delete:hover {
    background: rgba(220, 38, 38, 0.1);
    color: #dc2626;
}

/* Resolve button */
.comment-resolve {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    transition: all 0.15s;
}

.comment-resolve:hover {
    background: rgba(34, 197, 94, 0.1);
    border-color: #22c55e;
    color: #22c55e;
}

/* Resolved badge */
.resolved-badge {
    font-size: 11px;
    background: rgba(34, 197, 94, 0.12);
    color: #22c55e;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

/* Footer actions row (Reply button) */
.comment-footer-actions {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.reply-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
    transition: color 0.15s;
}

.reply-btn:hover {
    color: var(--primary);
}

/* Replies container */
.replies-container {
    margin-top: 10px;
    padding-left: 16px;
    border-left: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.replies-container:empty {
    display: none;
}

/* Individual reply */
.reply-item {
    display: flex;
    gap: 8px;
}

.reply-avatar {
    width: 22px !important;
    height: 22px !important;
    font-size: 10px !important;
    background: var(--text-muted) !important;
}

/* Reply input box */
.reply-box {
    margin-top: 10px;
    padding-left: 16px;
    border-left: 2px solid var(--primary);
}

.reply-input {
    width: 100%;
    min-height: 48px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    resize: vertical;
    font-family: inherit;
    box-sizing: border-box;
    background: var(--bg);
    color: var(--text);
}

.reply-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Dark mode overrides */
.dark-mode .comment-input,
.dark-mode .reply-input {
    background: var(--card-bg);
    color: var(--text);
}

/* Encrypted Content Block */
.encrypted-block {
    background: var(--main-bg);
    border: none;
    border-radius: 8px;
    padding: 12px;
    margin: 0;
}

.encrypted-block-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-weight: 500;
}

.encrypted-block-header svg {
    color: var(--text-muted);
}

.encrypted-block-content {
    display: none;
}

.encrypted-block.unlocked .encrypted-block-content {
    display: block;
}

.encrypted-block.unlocked .decrypt-btn {
    display: none;
}

.decrypt-btn {
    padding: 6px 12px;
    background: var(--main-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.decrypt-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.page-viewer-content img {
    max-width: 100%;
    border-radius: 8px;
}

.page-viewer-content h1, 
.page-viewer-content h2, 
.page-viewer-content h3 {
    margin-top: 0.8em;
    margin-bottom: 0.3em;
}

.page-viewer-content p {
    margin-bottom: 0.4em;
}

.page-viewer-content ul, 
.page-viewer-content ol {
    margin-bottom: 0.4em;
    padding-left: 1.5em;
}

.page-viewer-content blockquote {
    border-left: 4px solid var(--primary);
    padding-left: 15px;
    margin: 1em 0;
    color: var(--text-muted);
}

.page-viewer-content pre {
    background: #f1f5f9;
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
}

.empty-page-message {
    color: var(--text-muted);
    font-style: italic;
}

/* Page Editor */
.page-editor {
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.page-title-input {
    border: none !important;
    font-size: 24px;
    font-weight: 400;
    padding: 0;
    outline: none;
    flex: 1;
    box-shadow: none !important;
    background: transparent;
    color: var(--text);
}

.page-title-input::placeholder {
    color: var(--text-muted);
}

.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Content starts at top */
    padding: 0 20px 20px;
    min-height: 0;
    overflow-y: auto;
}

/* Content area takes whatever space it needs */
.editor-container #editor {
    flex: 0 0 auto;
}

.editor-container .ql-container {
    flex: 0 0 auto;
}

.editor-container .ql-editor {
    min-height: 50px !important;
}

/* Blocks container - no flex stretching */
.editor-container .editor-blocks {
    flex: 0 0 auto;
}

/* Spacer takes remaining space */
.editor-spacer {
    flex: 1 0 50px; /* Grow to fill, don't shrink, min 50px */
}

/* Footer fixed at bottom */
.editor-footer {
    flex: 0 0 auto;
}

#editor {
    font-size: 16px;
    line-height: 1.7;
}

.ql-toolbar {
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
    margin-bottom: 2px !important;
    background: #fafbfc;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Dark mode toolbar on mobile */
@media (max-width: 768px) {
    .dark-mode .ql-toolbar {
        background: var(--card-bg) !important;
    }
}

.ql-container {
    border: none !important;
    font-size: 16px !important;
    margin: 0 !important;
    padding: 0 !important;
}

.ql-editor {
    min-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
}

.ql-editor:empty,
.ql-editor.ql-blank {
    min-height: 1.5em !important;
}

.ql-editor:focus {
    min-height: 60px;
}

.ql-editor.ql-blank::before {
    font-style: normal;
    color: var(--text-muted);
    left: 0;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 25px;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-modal);
}

.modal.wide {
    max-width: 640px;
}

/* ===== UNIFIED CARD SHELL ===== */
.card,
.panel-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 16px;
}

/* ===== UNIFIED LABEL PILLS (Kymapost semantic pairs) ===== */
.label-pill,
.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 7px;
    line-height: 1.4;
    background: var(--border-light);
    color: var(--text-secondary);
}
.label-pill.danger,
.label-pill.important,
.pill.danger,
.pill.important {
    background: var(--danger-light);
    color: var(--danger);
}
.label-pill.success,
.pill.success {
    background: var(--success-light);
    color: var(--success);
}
.label-pill.info,
.pill.info {
    background: var(--info-light);
    color: var(--info);
}
.label-pill.warning,
.pill.warning {
    background: var(--warning-light);
    color: var(--warning);
}
.label-pill.ai,
.pill.ai {
    background: var(--ai-light);
    color: var(--ai);
}
.label-pill.brand,
.label-pill.primary,
.pill.brand,
.pill.primary {
    background: var(--primary-light);
    color: var(--primary);
}

/* ===== TOASTS ===== */
.toast {
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-popover);
    padding: 12px 16px;
    font-size: 13px;
}
.toast.success {
    border-color: var(--success);
    color: var(--success);
}
.toast.error,
.toast.danger {
    border-color: var(--danger);
    color: var(--danger);
}

.modal h3 {
    margin-bottom: 20px;
    font-size: 18px;
}

.modal-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 20px;
    outline: none;
    transition: all 0.2s;
}

.modal-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.legend-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    background: var(--card-bg);
    color: var(--text);
    outline: none;
    transition: all 0.2s;
}

.legend-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Image Modal */
.image-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.image-option {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.image-option label {
    font-size: 14px;
    font-weight: 500;
}

.image-preview {
    max-width: 100%;
    max-height: 150px;
    border-radius: 8px;
    margin-top: 10px;
}

/* Image props modal */
.image-props-preview {
    text-align: center;
    padding: 10px;
    background: #f5f5f5;
    border-radius: 8px;
}

.size-buttons, .align-buttons, .wrap-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.size-btn, .align-btn, .wrap-btn {
    padding: 8px 12px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.size-btn:hover, .align-btn:hover, .wrap-btn:hover {
    background: var(--main-bg);
    border-color: var(--primary);
}

.size-btn.active, .align-btn.active, .wrap-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.ql-editor img {
    cursor: pointer;
    transition: outline 0.2s;
    max-width: 100%;
    height: auto;
}

.ql-editor img:hover {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

/* Word count */
.editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    margin-top: auto; /* Push to bottom */
    flex-shrink: 0; /* Don't shrink */
}

.word-count {
    display: flex;
    gap: 15px;
}

.word-count span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* In-Page Search */
.in-page-search {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin: 0 20px 10px;
    gap: 12px;
}

.in-page-search-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.in-page-search-input-wrapper input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    color: var(--text);
    outline: none;
}

.in-page-search-count {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.in-page-search-actions {
    display: flex;
    gap: 4px;
}

.in-page-search-actions button {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.in-page-search-actions button:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

/* Search highlight */
.search-highlight {
    background: #FFEB3B;
    padding: 0 2px;
    border-radius: 2px;
}

.search-highlight.current {
    background: #FF9800;
    color: white;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Anchor links on headers */
.page-viewer-content h1,
.page-viewer-content h2,
.page-viewer-content h3 {
    position: relative;
    cursor: pointer;
}

.page-viewer-content h1:hover::before,
.page-viewer-content h2:hover::before,
.page-viewer-content h3:hover::before {
    content: '🔗';
    position: absolute;
    left: -30px;
    opacity: 0.5;
    font-size: 0.7em;
}

.page-viewer-content h1:hover,
.page-viewer-content h2:hover,
.page-viewer-content h3:hover {
    color: var(--primary);
}

.anchor-copied-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--sidebar-bg);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 9999;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 1.7s forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    padding: 8px 0;
    display: none;
    z-index: 1001;
    min-width: 180px;
}

.context-menu.active {
    display: block;
}

.context-menu-item {
    padding: 10px 15px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.15s;
}

.context-menu-item:hover {
    background: var(--main-bg);
}

.context-menu-item.danger {
    color: var(--danger);
}

.context-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 5px 0;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.empty-state h3 {
    color: var(--text);
    margin-bottom: 10px;
}

/* Icon Picker */
.tree-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px;
    border-radius: 4px;
    transition: all 0.15s;
    color: var(--sidebar-text);
}

.tree-icon-btn:hover {
    background: var(--sidebar-active);
    transform: scale(1.2);
}

.page-icon-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 20px 0;
    position: relative;
    z-index: 100;
}

/* Add extra padding on right when gutter is visible to prevent overlap */
.main-content.with-gutter .page-icon-wrapper {
    padding-right: 30px;
}

.page-title-row {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 12px;
}

.page-title-input {
    flex: 1;
}

.editor-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

.page-icon-btn {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
    flex-shrink: 0;
    color: var(--text);
}

.page-icon-btn:hover {
    background: var(--accent-glow);
}

.page-icon-btn.has-icon {
    border-style: solid;
    border-color: transparent;
}

/* Page background and design elements */
.page-background {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    pointer-events: none;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.page-header-bar {
    position: relative;
    z-index: 1;
    padding: 15px 30px;
    display: flex;
    align-items: center;
    min-height: 60px;
}

.page-footer-bar {
    position: relative;
    z-index: 1;
    padding: 15px 30px;
    display: flex;
    align-items: center;
    min-height: 50px;
    margin-top: auto;
    border-top: 1px solid var(--border);
}

/* Drag and Drop styles */
.tree-item-header.dragging {
    opacity: 0.5;
}

.tree-item-header.drag-over {
    background: var(--primary);
    color: white;
    border-radius: 6px;
}

.tree-item-header.drag-over-above::before {
    content: '';
    position: absolute;
    top: 0;
    left: 15px;
    right: 15px;
    height: 2px;
    background: var(--primary);
}

.tree-item-header.drag-over-below::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 15px;
    right: 15px;
    height: 2px;
    background: var(--primary);
}

/* Code block styles */
.code-block-wrapper {
    position: relative;
    margin: 15px 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #334155;
}

.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1e293b;
    padding: 8px 15px;
    border-bottom: 1px solid #334155;
}

.code-block-lang {
    font-size: 12px;
    color: #94a3b8;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.code-block-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.code-block-collapse {
    background: transparent;
    border: none;
    color: #94a3b8;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.code-block-collapse:hover {
    background: #334155;
}

.code-block-copy {
    background: transparent;
    border: 1px solid #475569;
    color: #94a3b8;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
}

.code-block-copy:hover {
    background: #334155;
    border-color: #64748b;
}

.code-block-content {
    display: flex;
    background: #0f172a;
    max-height: 500px;
    overflow: auto;
}

.code-block-content.collapsed {
    max-height: 0;
    overflow: hidden;
}

.code-block-gutter {
    min-width: 45px;
    background: #1e293b;
    padding: 15px 8px;
    text-align: right;
    user-select: none;
    border-right: 1px solid #334155;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #64748b;
}

.code-block-gutter .line-number {
    display: block;
    padding: 0 8px 0 0;
}

.code-block-code {
    flex: 1;
    overflow-x: auto;
}

.code-block-wrapper pre {
    margin: 0 !important;
    padding: 15px !important;
    background: #0f172a !important;
    overflow-x: visible !important;
}

.code-block-wrapper pre code {
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
}

/* ========== CODE REPL ========== */
.code-block-run {
    background: #1d4ed8;
    border: 1px solid #2563eb;
    color: #fff;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: background 0.15s;
}

.code-block-run:hover {
    background: #2563eb;
}

.code-block-run:disabled {
    background: #334155;
    border-color: #475569;
    color: #94a3b8;
    cursor: not-allowed;
}

.repl-output {
    display: none;
    background: #020817;
    border-top: 1px solid #1e3a5f;
    padding: 10px 14px;
    font-family: 'Courier New', monospace;
    font-size: 12.5px;
    line-height: 1.6;
    max-height: 300px;
    overflow-y: auto;
}

.repl-running {
    color: #64748b;
    font-style: italic;
}

.repl-empty {
    color: #22c55e;
    opacity: 0.7;
}

.repl-line-log {
    color: #e2e8f0;
    white-space: pre-wrap;
    word-break: break-word;
}

.repl-line-warn {
    color: #fbbf24;
    white-space: pre-wrap;
    word-break: break-word;
}

.repl-line-error {
    color: #f87171;
    white-space: pre-wrap;
    word-break: break-word;
}

.repl-line-result {
    color: #34d399;
    white-space: pre-wrap;
    word-break: break-word;
    border-left: 2px solid #10b981;
    padding-left: 8px;
    margin: 2px 0;
}

/* SQL REPL — Reset DB button */
.code-block-reset-db {
    background: transparent;
    border: 1px solid #475569;
    color: #94a3b8;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.15s;
}

.code-block-reset-db:hover {
    background: #7c2d12;
    border-color: #ea580c;
    color: #fed7aa;
}

/* SQL REPL — table output */
.repl-table-wrap {
    overflow-x: auto;
    margin: 4px 0;
}

.repl-table {
    border-collapse: collapse;
    font-size: 12px;
    min-width: 100%;
    color: #e2e8f0;
}

.repl-table thead tr {
    background: #1e293b;
    border-bottom: 1px solid #334155;
}

.repl-table th {
    padding: 6px 12px;
    text-align: left;
    font-weight: 600;
    color: #94a3b8;
    white-space: nowrap;
    letter-spacing: 0.3px;
    font-size: 11px;
    text-transform: uppercase;
}

.repl-table td {
    padding: 5px 12px;
    border-bottom: 1px solid #0f2035;
    white-space: nowrap;
}

.repl-table tbody tr:hover {
    background: #0f2035;
}

.repl-null {
    color: #64748b;
    font-style: italic;
}

.repl-row-count {
    color: #475569;
    font-size: 11px;
    padding: 4px 2px;
    text-align: right;
}

/* ---- Edit button ---- */
.code-block-edit {
    background: transparent;
    border: 1px solid #475569;
    color: #94a3b8;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.code-block-edit:hover {
    background: #334155;
    color: #e2e8f0;
}

.code-block-edit.active {
    background: #1e3a5f;
    border-color: #3b82f6;
    color: #93c5fd;
}

/* ---- Editable code textarea ---- */
.repl-editor-wrap {
    display: none;
    background: #0f172a;
    border-top: 1px solid #1e3a5f;
}

.repl-editor-textarea {
    width: 100%;
    min-height: 120px;
    background: #0f172a;
    color: #e2e8f0;
    border: none;
    outline: none;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    padding: 14px 18px;
    resize: vertical;
    box-sizing: border-box;
    caret-color: #60a5fa;
}

.repl-editor-textarea::selection {
    background: #1d4ed8;
}

.repl-editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 14px;
    border-top: 1px solid #1e293b;
    background: #080f1a;
}

.repl-editor-hint {
    font-size: 11px;
    color: #475569;
    font-style: italic;
}

.repl-editor-reset {
    background: transparent;
    border: 1px solid #334155;
    color: #64748b;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
}

.repl-editor-reset:hover {
    background: #1e293b;
    color: #94a3b8;
}

/* Python traceback collapsible */
.repl-traceback {
    margin-top: 4px;
    color: #f87171;
}

.repl-traceback summary {
    cursor: pointer;
    font-size: 11px;
    color: #64748b;
    user-select: none;
}

.repl-traceback pre {
    margin: 4px 0 0 0;
    font-size: 11px;
    color: #f87171;
    white-space: pre-wrap;
    word-break: break-word;
    opacity: 0.8;
}

/* Force hide */
.force-hidden {
    display: none !important;
}

/* ========== BI-DIRECTIONAL LINKS ========== */
.wiki-link {
    color: var(--primary);
    text-decoration: none;
    padding: 2px 4px;
    border-radius: 3px;
    background: var(--accent-glow);
    cursor: pointer;
    transition: all 0.15s;
}

.wiki-link:hover {
    background: var(--primary);
    color: white;
}

.wiki-link.broken {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.link-autocomplete {
    position: absolute;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    min-width: 250px;
}

.link-autocomplete-item {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    transition: background 0.15s;
}

.link-autocomplete-item:hover,
.link-autocomplete-item.selected {
    background: var(--sidebar-hover);
}

.link-autocomplete-item .icon {
    width: 16px;
    height: 16px;
}

.link-autocomplete-empty {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ========== BACKLINKS SECTION ========== */
.backlinks-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.backlink-item {
    padding: 8px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.backlink-item:hover {
    border-color: var(--primary);
    background: var(--sidebar-hover);
}

.backlink-icon {
    width: 16px;
    height: 16px;
}

.backlink-name {
    font-size: 13px;
    font-weight: 500;
    flex: 1;
}

/* ========== TEMPLATE PICKER ========== */
.template-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin: 20px 0;
}

.template-card {
    padding: 16px;
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

.template-card:hover {
    border-color: var(--primary);
    background: var(--sidebar-hover);
}

.template-card.selected {
    border-color: var(--primary);
    background: var(--accent-glow);
}

.template-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.template-name {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.template-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* ========== SMART TEMPLATES — AI GENERATION ========== */

.tmpl-modal {
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
}

.tmpl-ai-section {
  background: var(--card-bg);
  border: 1.5px solid var(--primary);
  border-radius: 10px;
  padding: 16px;
  margin: 16px 0 12px;
}

.tmpl-ai-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.tmpl-ai-badge {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 0.03em;
}

.tmpl-ai-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.tmpl-ai-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.tmpl-ai-textarea {
  flex: 1;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  background: var(--input-bg, var(--sidebar-bg));
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 54px;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.tmpl-ai-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.tmpl-ai-gen-btn {
  white-space: nowrap;
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 13px;
}

.tmpl-ai-preview {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}

.tmpl-ai-preview-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 12px;
  background: var(--sidebar-hover);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tmpl-ai-preview-content {
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.6;
  max-height: 260px;
  overflow-y: auto;
  color: var(--text);
}

.tmpl-ai-preview-content h1 { font-size: 18px; font-weight: 700; margin: 0 0 10px; }
.tmpl-ai-preview-content h2 { font-size: 15px; font-weight: 600; margin: 14px 0 6px; color: var(--text); }
.tmpl-ai-preview-content h3 { font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
.tmpl-ai-preview-content p  { margin: 0 0 8px; }
.tmpl-ai-preview-content ul, .tmpl-ai-preview-content ol { margin: 0 0 8px; padding-left: 20px; }
.tmpl-ai-preview-content li { margin-bottom: 3px; }
.tmpl-ai-preview-content pre { background: var(--sidebar-hover); padding: 8px; border-radius: 4px; font-size: 12px; overflow-x: auto; }

.tmpl-ai-generating {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.tmpl-ai-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: tmplSpin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes tmplSpin {
  to { transform: rotate(360deg); }
}

.tmpl-ai-error {
  padding: 12px 16px;
  font-size: 13px;
  color: #ef4444;
}

.tmpl-ai-use-btn {
  width: 100%;
  margin-top: 10px;
  padding: 9px;
  font-size: 13px;
  font-weight: 600;
}

.tmpl-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 4px;
  color: var(--text-muted);
  font-size: 12px;
}

.tmpl-divider::before,
.tmpl-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
/* ========== SMART TEMPLATES — SUGGEST MISSING SECTIONS ========== */

.gutter-suggest-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--card-bg);
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  margin-top: 6px;
}

.gutter-suggest-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--accent-glow);
}

.gutter-suggest-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.suggest-results {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.suggest-chip {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.15s;
}

.suggest-chip:hover {
  border-color: var(--primary);
}

.suggest-chip-body {
  flex: 1;
  min-width: 0;
}

.suggest-chip-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.suggest-chip-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.suggest-chip-add {
  flex-shrink: 0;
  padding: 4px 10px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
  margin-top: 2px;
}

.suggest-chip-add:hover {
  filter: brightness(1.1);
}

.suggest-chip-add:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: default;
}

.suggest-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 10px 0 4px;
  text-align: center;
}

.suggest-error {
  font-size: 12px;
  color: #ef4444;
  padding: 8px 0;
}
/* ========== SMART TEMPLATES — GUTTER PRE-FILL BUTTON ========== */

.gutter-prefill-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--card-bg);
  color: var(--primary);
  border: 1.5px solid var(--primary);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  margin-top: 6px;
}

.gutter-prefill-btn:hover {
  background: var(--accent-glow);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.2);
}

.gutter-prefill-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ========== TABLE OF CONTENTS ========== */
.toc-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.toc-item {
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 13px;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.toc-item:hover {
    background: var(--sidebar-hover);
}

.toc-item.active {
    background: var(--accent-glow);
    color: var(--primary);
    font-weight: 500;
}

.toc-item.h1 {
    font-weight: 600;
    padding-left: 8px;
}

.toc-item.h2 {
    padding-left: 20px;
}

.toc-item.h3 {
    padding-left: 32px;
    font-size: 12px;
}

.toc-empty {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}

/* ========== PAGE GUTTER ========== */
.page-gutter {
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
    width: 280px;
    min-width: 280px;
    background: var(--card-bg);
    border-left: 1px solid var(--border);
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
    z-index: 90;
}

.page-gutter.hidden {
    display: none;
}

/* Add padding to main content when gutter is visible */
.main-content.with-gutter {
    padding-right: 280px;
}

.gutter-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.gutter-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.gutter-toggle-btn {
    position: fixed;
    right: 280px;
    top: 50%;
    transform: translateX(50%) translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10500;
    transition: all 0.2s;
    pointer-events: auto;
}

.gutter-toggle-btn:hover {
    background: var(--sidebar-hover);
    border-color: var(--primary);
    transform: translateX(50%) translateY(-50%) scale(1.1);
}

.gutter-toggle-btn.rotated {
    transform: translateX(50%) translateY(-50%) rotate(180deg);
}

.gutter-toggle-btn.rotated:hover {
    transform: translateX(50%) translateY(-50%) rotate(180deg) scale(1.1);
}

/* When gutter is hidden, move button to edge */
.gutter-toggle-btn.at-edge {
    right: 20px;
    transform: translateY(-50%);
}

.gutter-toggle-btn.at-edge:hover {
    transform: translateY(-50%) scale(1.1);
}

.gutter-toggle-btn.at-edge.rotated {
    transform: translateY(-50%) rotate(180deg);
}

.gutter-toggle-btn.at-edge.rotated:hover {
    transform: translateY(-50%) rotate(180deg) scale(1.1);
}

/* ========== FILE MANAGER ========== */
.file-manager-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10001;
}

.file-manager-overlay.active {
    display: flex;
}

.file-manager {
    background: var(--card-bg);
    border-radius: 12px;
    width: 90%;
    max-width: 1000px;
    height: 80vh;
    max-height: 700px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

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

.file-manager-title {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.file-manager-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s;
}

.file-manager-close:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

.file-manager-tabs {
    display: flex;
    gap: 4px;
    padding: 16px 24px 0;
    border-bottom: 1px solid var(--border);
}

.file-manager-tab {
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.file-manager-tab:hover {
    color: var(--text);
    background: var(--sidebar-hover);
}

.file-manager-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.file-manager-toolbar {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 12px;
    align-items: center;
}

.file-upload-btn {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.file-upload-btn:hover {
    background: var(--primary-hover);
}

.file-search-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    background: var(--main-bg);
    color: var(--text);
}

.file-search-input:focus {
    outline: none;
    border-color: var(--primary);
}

.file-manager-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
}

.file-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--card-bg);
    position: relative; /* For pin button positioning */
}

.file-item:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(77, 182, 172, 0.15);
}

.file-item.selected {
    border-color: var(--primary);
    background: var(--accent-glow);
}

.file-thumbnail {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 6px;
    background: var(--main-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-bottom: 8px;
}

.file-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.file-thumbnail-icon {
    font-size: 32px;
    color: var(--text-muted);
}

.file-name {
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.file-meta {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
}

.file-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.file-list-item:hover {
    border-color: var(--primary);
    background: var(--accent-glow);
}

.file-list-item.selected {
    border-color: var(--primary);
    background: var(--accent-glow);
}

.file-list-icon {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background: var(--main-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-list-info {
    flex: 1;
    min-width: 0;
}

.file-list-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-list-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.file-manager-actions {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.file-action-btns {
    display: flex;
    gap: 8px;
}

.file-action-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.file-action-btn:hover {
    border-color: var(--primary);
    background: var(--accent-glow);
}

.file-action-btn.primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.file-action-btn.primary:hover {
    background: var(--primary-hover);
}

.file-action-btn.danger {
    border-color: var(--danger);
    color: var(--danger);
}

.file-action-btn.danger:hover {
    background: var(--danger);
    color: white;
}

.file-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.file-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.file-empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.file-empty-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.file-empty-subtitle {
    font-size: 14px;
}

/* Drag and drop */
.file-manager-content.drag-over {
    border: 2px dashed var(--primary);
    background: var(--accent-glow);
}

/* ========================================
   KEYSTONA - Claude-Style AI Chat Interface
   ======================================== */

/* ===== AI CHAT WIDGET CONTAINER ===== */
.ai-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'SF Pro Display', sans-serif;
}

/* ===== FLOATING BUTTON (Collapsed State) ===== */
.ai-chat-button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 24px rgba(79, 70, 229, 0.4), 0 2px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chat-button:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 32px rgba(79, 70, 229, 0.5), 0 4px 12px rgba(0, 0, 0, 0.15);
}

.ai-chat-button .ai-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

/* Light mode: show white bg icon, hide dark bg icon */
.ai-chat-button .ai-icon-light {
    display: block;
}
.ai-chat-button .ai-icon-dark {
    display: none;
}

/* Dark mode: show dark bg icon, hide light bg icon */
.dark-mode .ai-chat-button .ai-icon-light {
    display: none;
}
.dark-mode .ai-chat-button .ai-icon-dark {
    display: block;
}

/* ===== CHAT WINDOW (Half-Screen Panel) ===== */
.ai-chat-window {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    width: 50vw;
    height: 100vh;
    background: #FFFFFF;
    box-shadow: -4px 0 32px rgba(0, 0, 0, 0.12);
    flex-direction: row;
    overflow: hidden;
    animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chat-window.active {
    display: flex;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Dark mode support */
.dark-mode .ai-chat-window {
    background: #1a1a1a;
}

/* ===== CLAUDE-STYLE SIDEBAR ===== */
.ai-sidebar {
    width: 52px;
    min-width: 52px;
    height: 100%;
    background: #F9F9F9;
    border-right: 1px solid #E8E8E8;
    display: flex;
    flex-direction: column;
    transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.dark-mode .ai-sidebar {
    background: #1f1f1f;
    border-right-color: #333;
}

.ai-sidebar.expanded {
    width: 240px;
}

/* Toggle button positioned on the divider */
.ai-sidebar-toggle {
    position: absolute;
    left: 52px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 48px;
    background: #fff;
    border: 1px solid #E8E8E8;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    transition: all 0.2s;
    z-index: 10;
    padding: 0;
}

.ai-sidebar-toggle:hover {
    background: #f0f0f0;
    color: #1a1a1a;
}

.dark-mode .ai-sidebar-toggle {
    background: #2a2a2a;
    border-color: #444;
    color: #999;
}

.dark-mode .ai-sidebar-toggle:hover {
    background: #333;
    color: #fff;
}

/* Adjust toggle position when sidebar is expanded */
.ai-sidebar.expanded ~ .ai-sidebar-toggle {
    left: 240px;
}

.ai-sidebar-toggle .ai-sidebar-icon {
    width: 16px;
    height: 16px;
}

.ai-sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px;
}

.ai-sidebar-section {
    margin-bottom: 8px;
}

.ai-sidebar-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    color: #444;
    font-size: 14px;
    text-align: left;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.ai-sidebar-item:hover {
    background: #E8E8E8;
    color: #1a1a1a;
}

.dark-mode .ai-sidebar-item {
    color: #bbb;
}

.dark-mode .ai-sidebar-item:hover {
    background: #333;
    color: #fff;
}

.ai-sidebar-item i,
.ai-sidebar-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.ai-sidebar-item span {
    opacity: 0;
    transition: opacity 0.15s;
}

.ai-sidebar.expanded .ai-sidebar-item span {
    opacity: 1;
}

.ai-sidebar-divider {
    height: 1px;
    background: #E8E8E8;
    margin: 8px 12px;
}

.dark-mode .ai-sidebar-divider {
    background: #333;
}

.ai-sidebar-label {
    font-size: 11px;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 12px 4px;
    opacity: 0;
    transition: opacity 0.15s;
}

.ai-sidebar.expanded .ai-sidebar-label {
    opacity: 1;
}

.ai-sidebar-recents-list {
    max-height: 200px;
    overflow-y: auto;
}

.ai-sidebar-recent-item {
    padding: 8px 12px;
    font-size: 13px;
    color: #666;
    cursor: pointer;
    border-radius: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
}

.ai-sidebar.expanded .ai-sidebar-recent-item {
    opacity: 1;
}

.ai-sidebar-recent-item:hover {
    background: #E8E8E8;
    color: #1a1a1a;
}

.dark-mode .ai-sidebar-recent-item {
    color: #888;
}

.dark-mode .ai-sidebar-recent-item:hover {
    background: #333;
    color: #fff;
}

.ai-sidebar-footer {
    padding: 12px;
    border-top: 1px solid #E8E8E8;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dark-mode .ai-sidebar-footer {
    border-top-color: #333;
}

.ai-sidebar-footer .ai-sidebar-settings {
    margin-top: 4px;
}

.ai-sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.ai-sidebar-user:hover {
    background: #E8E8E8;
}

.dark-mode .ai-sidebar-user:hover {
    background: #333;
}

.ai-sidebar-avatar {
    width: 28px;
    height: 28px;
    background: #1a1a1a;
    color: #fff;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.dark-mode .ai-sidebar-avatar {
    background: #E8E8E8;
    color: #1a1a1a;
}

.ai-sidebar-username {
    font-size: 13px;
    color: #444;
    opacity: 0;
    transition: opacity 0.15s;
    white-space: nowrap;
}

.ai-sidebar.expanded .ai-sidebar-username {
    opacity: 1;
}

.dark-mode .ai-sidebar-username {
    color: #ccc;
}

/* ===== MAIN CHAT AREA ===== */
.ai-chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ===== CHAT HEADER ===== */
.ai-chat-header {
    background: #FAFAFA;
    border-bottom: 1px solid #E5E5E5;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.dark-mode .ai-chat-header {
    background: #242424;
    border-bottom-color: #333;
}

.ai-chat-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 15px;
    color: #1a1a1a;
}

.dark-mode .ai-chat-title {
    color: #FFFFFF;
}

.ai-chat-title .ai-chat-status {
    display: none;
}

/* Header icon image */
.ai-header-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    object-fit: cover;
}

.ai-current-chat-title {
    font-weight: 400;
    color: #666;
    margin-left: 8px;
}

.dark-mode .ai-current-chat-title {
    color: #999;
}

/* Hide old controls, show new ones */
.ai-chat-actions {
    display: none !important;
}

.ai-saved-chats-dropdown {
    display: none;
}

/* Window Controls */
.ai-window-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-window-control-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.15s;
}

.ai-window-control-btn:hover {
    background: #E5E5E5;
    color: #1a1a1a;
}

.dark-mode .ai-window-control-btn:hover {
    background: #333;
    color: #FFF;
}

.ai-window-control-btn.close:hover {
    background: #FEE2E2;
    color: #DC2626;
}

.dark-mode .ai-window-control-btn.close:hover {
    background: #7F1D1D;
    color: #FCA5A5;
}

/* ===== CHAT MESSAGES AREA ===== */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    background: #FFFFFF;
    position: relative;
}

/* Watermark brain background */
.ai-chat-messages::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70%;
    max-width: 500px;
    aspect-ratio: 1;
    background-image: url('https://jxnrajntnyqwgzgosdrc.supabase.co/storage/v1/object/public/kysteno-images/63ddf598-67c1-4929-a553-874da36c84af/ai_brainwhite.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.06;
    pointer-events: none;
    z-index: 0;
}

.ai-chat-messages > * {
    position: relative;
    z-index: 1;
}

.dark-mode .ai-chat-messages {
    background: #1a1a1a;
}

.dark-mode .ai-chat-messages::before {
    background-image: url('https://jxnrajntnyqwgzgosdrc.supabase.co/storage/v1/object/public/kysteno-images/63ddf598-67c1-4929-a553-874da36c84af/ai_brainblack.png');
    opacity: 0.08;
}

/* Custom scrollbar */
.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 3px;
}

.dark-mode .ai-chat-messages::-webkit-scrollbar-thumb {
    background: #4B5563;
}

/* ===== MESSAGE STYLES ===== */
.ai-message {
    display: flex;
    gap: 16px;
    max-width: 100%;
    animation: messageAppear 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Avatar */
.ai-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.ai-message.ai .ai-message-avatar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
}

.ai-message.user .ai-message-avatar {
    background: #E5E5E5;
    color: #666;
}

.dark-mode .ai-message.user .ai-message-avatar {
    background: #333;
    color: #CCC;
}

/* Message Content */
.ai-message-content {
    flex: 1;
    min-width: 0;
    max-width: 720px;
}

/* Message Bubble */
.ai-message-bubble {
    font-size: 15px;
    line-height: 1.7;
    color: #1a1a1a;
    word-wrap: break-word;
}

.dark-mode .ai-message-bubble {
    color: #E5E5E5;
}

/* User messages - subtle background */
.ai-message.user .ai-message-bubble {
    background: #F5F5F5;
    padding: 12px 16px;
    border-radius: 12px;
    color: #1a1a1a;
}

.dark-mode .ai-message.user .ai-message-bubble {
    background: #2a2a2a;
    color: #E5E5E5;
}

/* AI messages - no background, just clean text */
.ai-message.ai .ai-message-bubble {
    background: transparent;
    padding: 0;
}

/* Code blocks in messages */
.ai-message-bubble pre {
    background: #1E1E1E;
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
    margin: 12px 0;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
    font-size: 13px;
    line-height: 1.5;
}

.ai-message-bubble code {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
    font-size: 13px;
}

.ai-message-bubble p code {
    background: #F3F4F6;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.dark-mode .ai-message-bubble p code {
    background: #374151;
}

/* Message timestamp */
.ai-message-time {
    font-size: 11px;
    color: #9CA3AF;
    margin-top: 6px;
}

/* ===== THINKING INDICATOR ===== */
.ai-thinking {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    color: #6B7280;
    font-size: 14px;
}

.ai-thinking-icon {
    width: 20px;
    height: 20px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.ai-thinking-text {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* ===== TYPING INDICATOR (Bouncing Dots) ===== */
.ai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
}

.ai-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.ai-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% { 
        transform: translateY(0); 
        opacity: 0.4;
    }
    30% { 
        transform: translateY(-8px); 
        opacity: 1;
    }
}

/* ===== IMAGE GENERATION INDICATOR ===== */
.ai-creating-image {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: #FFF7ED;
    border: 1px solid #FED7AA;
    border-radius: 12px;
    color: #9A3412;
    font-size: 14px;
}

.dark-mode .ai-creating-image {
    background: #431407;
    border-color: #9A3412;
    color: #FED7AA;
}

.ai-creating-image-icon {
    font-size: 24px;
    animation: paintBrush 1s ease-in-out infinite;
}

@keyframes paintBrush {
    0%, 100% { transform: rotate(-10deg); }
    50% { transform: rotate(10deg); }
}

/* ===== CHAT INPUT ===== */
.ai-chat-input {
    padding: 16px 24px 24px;
    border-top: 1px solid #E5E5E5;
    background: #FAFAFA;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-shrink: 0;
}

.dark-mode .ai-chat-input {
    background: #242424;
    border-top-color: #333;
}

.ai-input-field {
    flex: 1;
    background: #FFFFFF;
    border: 1px solid #E5E5E5;
    border-radius: 12px;
    padding: 14px 18px;
    font-size: 15px;
    resize: none;
    max-height: 150px;
    min-height: 48px;
    font-family: inherit;
    color: #1a1a1a;
    line-height: 1.5;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.dark-mode .ai-input-field {
    background: #1a1a1a;
    border-color: #333;
    color: #E5E5E5;
}

.ai-input-field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.ai-input-field::placeholder {
    color: #9CA3AF;
}

/* Send Button */
.ai-send-btn {
    width: 48px;
    height: 48px;
    background: #1a1a1a;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}

.dark-mode .ai-send-btn {
    background: #E5E5E5;
    color: #1a1a1a;
}

.ai-send-btn:hover {
    background: #333;
    transform: scale(1.02);
}

.dark-mode .ai-send-btn:hover {
    background: #FFF;
}

.ai-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.ai-send-btn svg,
.ai-send-btn i {
    width: 20px;
    height: 20px;
}

/* ===== EMPTY STATE ===== */
.ai-chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px;
    text-align: center;
}

.ai-empty-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 24px;
}

.ai-empty-title {
    font-size: 20px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 8px;
}

.dark-mode .ai-empty-title {
    color: #FFF;
}

.ai-empty-subtitle {
    font-size: 15px;
    color: #6B7280;
    margin-bottom: 32px;
    max-width: 320px;
    line-height: 1.5;
}

/* Suggestion Chips */
.ai-suggestion-chips {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 400px;
}

.ai-suggestion-chip {
    padding: 14px 18px;
    background: #FFFFFF;
    border: 1px solid #E5E5E5;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 14px;
    text-align: left;
    color: #1a1a1a;
}

.dark-mode .ai-suggestion-chip {
    background: #2a2a2a;
    border-color: #333;
    color: #E5E5E5;
}

.ai-suggestion-chip:hover {
    border-color: var(--primary);
    background: #FFF7ED;
}

.dark-mode .ai-suggestion-chip:hover {
    background: #431407;
    border-color: var(--primary);
}

/* ===== CHAT HISTORY PANEL ===== */
.ai-chat-history {
    display: none;
}

/* ===== ARTIFACTS PANEL ===== */
.ai-artifacts-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 45%;
    background: #FAFAFA;
    border-left: 1px solid #E5E5E5;
    display: none;
    flex-direction: column;
}

.dark-mode .ai-artifacts-panel {
    background: #242424;
    border-left-color: #333;
}

.ai-artifacts-panel.active {
    display: flex;
}

.artifacts-header {
    padding: 16px 20px;
    border-bottom: 1px solid #E5E5E5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 14px;
}

.dark-mode .artifacts-header {
    border-bottom-color: #333;
}

.artifacts-content {
    flex: 1;
    overflow: auto;
    padding: 20px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .ai-chat-window {
        width: 100vw;
    }
}

@media (max-width: 768px) {
    .ai-chat-window {
        width: 100vw;
        border-radius: 0;
    }
    
    .ai-chat-messages {
        padding: 20px 16px;
    }
    
    .ai-chat-input {
        padding: 12px 16px 20px;
    }
    
    .ai-message-content {
        max-width: 100%;
    }
}

/* ===== HIDE OLD EXPANDABLE MODES (We now use half-screen always) ===== */
.ai-chat-widget.mode-widget,
.ai-chat-widget.mode-docked,
.ai-chat-widget.mode-expanded,
.ai-chat-widget.mode-fullscreen {
    /* Reset all old modes */
    position: fixed;
    bottom: 24px;
    right: 24px;
    top: auto;
    left: auto;
}

.ai-chat-widget.mode-widget .ai-chat-window,
.ai-chat-widget.mode-docked .ai-chat-window,
.ai-chat-widget.mode-expanded .ai-chat-window,
.ai-chat-widget.mode-fullscreen .ai-chat-window {
    /* Force half-screen for all modes */
    position: fixed;
    top: 0;
    right: 0;
    width: 50vw;
    height: 100vh;
    border-radius: 0;
    max-width: none;
    max-height: none;
}
/* ========== COLOR DOTS ========== */
.page-marker {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 1px;
    flex-shrink: 0;
}

.page-markers-container {
    position: absolute;
    left: 52px;
    top: 3px;
    display: inline-flex;
    align-items: center;
    gap: 1px;
    pointer-events: none;
    height: 0;
    overflow: visible;
}

.dot-blue { background: #3B82F6; }
.dot-green { background: #10B981; }
.dot-purple { background: #8B5CF6; }
.dot-red { background: #EF4444; }
.dot-yellow { background: #F59E0B; }
.dot-gray { background: #6B7280; }

.dot-tooltip {
    position: absolute;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.4;
    color: var(--text);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    white-space: nowrap;
    pointer-events: none;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 8px;
}

.dot-tooltip-line {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.dot-tooltip-line:last-child {
    margin-bottom: 0;
}

/* Pin Feature Styles */
.pin-btn {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-right: 4px;
}

.pin-btn:hover {
    background: var(--primary);
    color: white;
    transform: rotate(-15deg);
}

.pin-btn.pinned {
    color: var(--primary);
}

.pin-btn.pinned:hover {
    background: var(--sidebar-hover);
    color: var(--danger);
    transform: rotate(0deg);
}

.pinned-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--primary);
    font-weight: 600;
}

.pin-divider {
    border-top: 1px solid var(--border);
    margin: 8px 0;
    position: relative;
}

.pin-divider::after {
    content: 'PINNED';
    position: absolute;
    top: -8px;
    left: 8px;
    background: var(--sidebar-bg);
    padding: 0 6px;
    font-size: 9px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.dark-mode .pin-divider::after {
    background: var(--sidebar-bg);
}

/* ========== KNOWLEDGE HEALTH UI ========== */
.page-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.status-draft {
    background: #F3F4F6;
    color: #6B7280;
    border: 1px solid var(--border);
}

.status-active {
    background: #DCFCE7;
    color: #16A34A;
    border: 1px solid #BBF7D0;
}

.status-deprecated {
    background: #FEF3C7;
    color: #D97706;
    border: 1px solid #FDE68A;
}

.status-archived {
    background: #F3F4F6;
    color: #9CA3AF;
    border: 1px solid var(--border);
}

.page-owner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.page-owner:hover {
    border-color: var(--primary);
}

.owner-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
}

.owner-info {
    flex: 1;
    min-width: 0;
}

.owner-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.owner-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.page-reviewed {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.reviewed-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
}

.reviewed-label {
    color: var(--text-muted);
}

.reviewed-date {
    font-weight: 500;
}

.reviewed-date.stale {
    color: var(--danger);
}

.mark-reviewed-btn {
    padding: 6px 12px;
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.mark-reviewed-btn:hover {
    background: var(--sidebar-hover);
    border-color: var(--primary);
}

.gutter-markers-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.gutter-marker-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.gutter-marker-content {
    flex: 1;
    min-width: 0;
}

.gutter-marker-label {
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 2px;
}

.gutter-marker-note {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
}

.remove-dot-btn {
    width: 18px;
    height: 18px;
    padding: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    transition: all 0.15s;
    flex-shrink: 0;
}

.remove-dot-btn:hover {
    background: var(--danger);
    color: white;
}

.add-dot-btn, .edit-dots-btn, .add-marker-btn {
    padding: 8px 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
    color: var(--text);
}

.add-dot-btn:hover, .edit-dots-btn:hover, .add-marker-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--accent-glow);
}

@media (max-width: 1024px) {
    .page-gutter {
        position: fixed;
        right: 0;
        top: 0;
        height: 100vh;
        z-index: 99;
        box-shadow: -4px 0 12px rgba(0, 0, 0, 0.1);
    }
}

/* MOBILE: Hide gutter by default, don't let it overlap editor */
@media (max-width: 768px) {
    /* Allow sidebar to slide out of app bounds on mobile */
    .app.show {
        overflow: visible !important;
    }

    body {
        overflow-x: hidden;
    }
    /* ===== SIDEBAR: slide-over on mobile ===== */
    .sidebar {
        position: fixed !important;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        width: 240px !important;
        min-width: 240px !important;
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }

    .sidebar.mobile-open {
        transform: translateX(0) !important;
        width: 240px !important;
        min-width: 240px !important;
        display: flex !important;
    }

    /* Sidebar overlay backdrop */
    .sidebar-mobile-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 199;
    }

    .sidebar-mobile-backdrop.active {
        display: block;
    }

    /* Main content takes full width */
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding-right: 0 !important;
    }

    .main-content.with-gutter {
        padding-right: 0 !important;
    }

    /* Hamburger button to open sidebar */
    .mobile-sidebar-btn {
        display: flex !important;
    }

    /* ===== GUTTER: fully hide on mobile ===== */
    .page-gutter:not(.mobile-gutter-open) {
        display: none !important;
    }

    /* Hide gutter toggle button on mobile */
    .gutter-toggle-btn {
        display: none !important;
    }

    /* ===== TOOLBAR: horizontal scroll row ===== */
    .ql-toolbar.ql-snow {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 8px 12px !important;
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
        border-top: none !important;
        margin-bottom: 0 !important;
        position: sticky;
        top: 0;
        z-index: 100;
        background: var(--main-bg, #fff);
    }

    .ql-toolbar.ql-snow::-webkit-scrollbar {
        display: none;
    }

    .ql-toolbar.ql-snow .ql-formats {
        display: inline-flex !important;
        flex-shrink: 0;
        margin-right: 4px !important;
    }

    .ql-toolbar.ql-snow button,
    .ql-toolbar.ql-snow .ql-picker-label {
        min-width: 38px !important;
        height: 38px !important;
        padding: 6px !important;
        flex-shrink: 0;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
    }

    /* ===== EDITOR: tighter padding ===== */
    .ql-editor {
        padding: 16px !important;
    }

    .page-title-input {
        font-size: 20px !important;
    }

    /* ===== CONTENT: prevent horizontal overflow ===== */
    .main-content,
    .content-body,
    .page-viewer,
    .page-editor {
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Dark mode toolbar */
    .dark-mode .ql-toolbar.ql-snow {
        background: var(--card-bg) !important;
    }

    /* ===== MOBILE HEADER ===== */
    .content-header {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 14px;
    }

    .mobile-sidebar-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border: none;
        background: var(--sidebar-hover);
        border-radius: 8px;
        cursor: pointer;
        flex-shrink: 0;
        color: var(--text);
    }

    .breadcrumb {
        flex: 1;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 13px;
    }

    /* Dashboard table horizontal scroll */
    .toc-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Dashboard label filters wrap */
    .dashboard-label-filters {
        flex-wrap: wrap;
        gap: 6px;
    }

    /* ===== TOP ACTION BAR: prevent clipping ===== */
    .content-header {
        padding: 6px 10px;
        flex-wrap: nowrap;
        overflow: hidden;
        justify-content: flex-start;
    }

    .content-actions {
        display: flex;
        align-items: center;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-shrink: 1;
        gap: 2px;
    }

    .content-actions::-webkit-scrollbar {
        display: none;
    }

    /* Make action buttons tighter on mobile */
    .action-btn {
        padding: 6px 8px !important;
        font-size: 12px !important;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Hide text labels on very small screens, keep icons */
    .action-btn span {
        display: none;
    }

    /* Keep the edit-mode label visible */
    .edit-mode-label {
        font-size: 11px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Page header bar tighter on mobile */
    .page-header-bar {
        padding: 10px 14px;
        flex-wrap: wrap;
        gap: 8px;
        min-height: auto;
    }
    /* Hamburger inside viewer actions bar */
    .mobile-menu-in-viewer {
        display: flex !important;
        margin-right: 4px;
    }

    /* Viewer actions scrollable row */
    .viewer-actions {
        display: flex;
        align-items: center;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 2px;
        padding: 6px 10px;
        flex-wrap: nowrap;
    }

    .viewer-actions::-webkit-scrollbar {
        display: none;
    }

    /* ===== RIGHT GUTTER: slide-in panel on mobile ===== */
    .page-gutter {
        position: fixed !important;
        right: 0;
        top: 0;
        height: 100vh;
        width: 300px !important;
        min-width: 300px !important;
        z-index: 1000;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        box-shadow: -4px 0 20px rgba(0,0,0,0.15);
        overflow-y: auto;
    }

    .page-gutter.mobile-gutter-open {
        display: flex !important;
        transform: translateX(0) !important;
    }

    /* Show info button only on mobile */
    .mobile-info-btn {
        display: inline-flex !important;
    }
    /* Remove desktop gutter padding on mobile */
    .dashboard-main {
        padding-right: 0 !important;
    }
    /* Close button for mobile gutter */
    .mobile-gutter-close {
        display: flex !important;
    }
}
.mobile-menu-in-viewer {
    display: none;
}
.mobile-info-btn {
    display: none;
}
.mobile-gutter-close {
    display: none;
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    background: var(--sidebar-hover);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
    z-index: 10;
}
/* ========== FIX: Sync viewer with editor spacing ========== */
/* Hide empty paragraphs with just a br (Quill adds these) */
.page-viewer-content p:empty,
.page-viewer-content p:has(br:only-child) {
    margin: 0;
    padding: 0;
    height: 0;
    line-height: 0;
    font-size: 0;
}

.page-viewer-content p > br:only-child {
    display: none;
}

.page-viewer-content p {
    margin-bottom: 0;
    min-height: 0;
}
/* ========== @MENTION AUTOCOMPLETE ========== */

.mention-dropdown {
    position: absolute;
    z-index: 9999;
    background: var(--card-bg, #fff);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    max-height: 220px;
    overflow-y: auto;
}

.mention-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.1s;
    font-size: 13px;
}

.mention-item:hover,
.mention-item.active {
    background: var(--hover-bg, rgba(0, 0, 0, 0.05));
}

.mention-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}

.mention-label {
    flex: 1;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mention-match {
    background: transparent;
    color: var(--primary);
    font-weight: 700;
}

/* @mention chips inside rendered comment text */
.mention-chip {
    display: inline-block;
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    border-radius: 4px;
    padding: 0 4px;
    font-weight: 500;
    font-size: 0.95em;
}

.dark-mode .mention-dropdown {
    background: var(--card-bg);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.dark-mode .mention-chip {
    background: rgba(99, 102, 241, 0.2);
}
/* ========== TEXT-SELECTION COMMENTING ========== */

/* Floating bubble that appears above selection */
.selection-bubble {
    position: absolute;
    z-index: 8000;
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.selection-bubble.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.selection-bubble-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 6px 13px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.45);
    white-space: nowrap;
    transition: background 0.15s, box-shadow 0.15s;
}

.selection-bubble-btn:hover {
    background: #4f46e5;
    box-shadow: 0 6px 18px rgba(99, 102, 241, 0.55);
}

/* Inline comment modal (floating card) */
.inline-comment-modal {
    position: fixed;
    z-index: 8001;
    width: 400px;
    max-width: calc(100vw - 32px);
}

.inline-comment-modal-inner {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.16);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Quoted text snippet inside the modal */
.inline-comment-quote {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: rgba(99, 102, 241, 0.06);
    border-left: 3px solid var(--primary);
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.inline-comment-quote-text {
    font-style: italic;
    word-break: break-word;
}

/* Highlighted text in viewerContent */
.inline-comment-highlight {
    background: rgba(253, 224, 71, 0.45);
    border-bottom: 2px solid rgba(234, 179, 8, 0.7);
    border-radius: 2px;
    cursor: pointer;
    transition: background 0.15s;
}

.inline-comment-highlight:hover {
    background: rgba(253, 224, 71, 0.7);
}

/* Quoted text snippet shown inside comment card in the footer */
.comment-quoted-text {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    background: rgba(99, 102, 241, 0.06);
    border-left: 3px solid var(--primary);
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 4px;
    line-height: 1.5;
    word-break: break-word;
}

/* Flash animation when clicking a highlight to jump to its card */
@keyframes commentFlash {
    0%   { background: rgba(99, 102, 241, 0.15); }
    50%  { background: rgba(99, 102, 241, 0.3); }
    100% { background: transparent; }
}

.comment-card-flash {
    animation: commentFlash 1.8s ease forwards;
    border-radius: 6px;
}

/* Dark mode */
.dark-mode .inline-comment-modal-inner {
    background: var(--card-bg);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.dark-mode .inline-comment-highlight {
    background: rgba(253, 224, 71, 0.2);
    border-bottom-color: rgba(234, 179, 8, 0.5);
}

.dark-mode .inline-comment-highlight:hover {
    background: rgba(253, 224, 71, 0.35);
}
/* ========================================
   KYSTENO - Notification Bell & Panel
   ======================================== */

.notif-bell-wrapper {
  position: relative;
  flex: 1;
}

.notif-bell-wrapper .user-action-btn {
  position: relative;
  width: 100%;
}

.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  pointer-events: none;
  line-height: 1;
}

.notif-badge.hidden {
  display: none;
}

/* Panel */
.notif-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: 320px;
  max-height: 440px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
}

.notif-panel.hidden {
  display: none;
}

.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.notif-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.notif-mark-all {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s;
}

.notif-mark-all:hover {
  background: var(--accent-glow);
}

/* List */
.notif-list {
  overflow-y: auto;
  flex: 1;
}

.notif-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* Individual item */
.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  position: relative;
}

.notif-item:last-child {
  border-bottom: none;
}

.notif-item:hover {
  background: var(--sidebar-hover);
}

.notif-item.unread {
  background: var(--accent-glow);
  border-left: 3px solid var(--primary);
}

.notif-item.unread:hover {
  background: var(--sidebar-active);
}

.notif-icon {
  font-size: 16px;
  flex-shrink: 0;
  margin-top: 1px;
}

.notif-content {
  flex: 1;
  min-width: 0;
}

.notif-text {
  font-size: 12px;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 2px;
}

.notif-body {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.notif-time {
  font-size: 10px;
  color: var(--text-muted);
}

.notif-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
  margin-top: 5px;
}
/* ===== MOBILE FIXED HAMBURGER ===== */
.mobile-hamburger-fixed {
    display: none;
}

@media (max-width: 768px) {
    .mobile-hamburger-fixed {
        display: flex !important;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 12px;
        left: 12px;
        width: 40px;
        height: 40px;
        background: var(--card-bg);
        border: 1px solid var(--border);
        border-radius: 10px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.12);
        cursor: pointer;
        z-index: 300;
        color: var(--text);
    }

    /* Push content down so hamburger doesn't overlap top of page */
    .main-content {
        padding-top: 60px !important;
    }
}
/* ============================================================
   COMMAND PALETTE (Cmd+K)
   ============================================================ */

.cmd-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 8000;
    animation: cmdBackdropIn 0.15s ease;
}
.cmd-backdrop.open { display: block; }

@keyframes cmdBackdropIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.cmd-palette {
    display: none;
    position: fixed;
    top: 18%;
    left: 50%;
    transform: translateX(-50%);
    width: 620px;
    max-width: calc(100vw - 32px);
    max-height: 68vh;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.10);
    z-index: 8001;
    flex-direction: column;
    overflow: hidden;
    animation: cmdSlideIn 0.16s cubic-bezier(0.4, 0, 0.2, 1);
}
.cmd-palette.open { display: flex; }

@keyframes cmdSlideIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.cmd-input-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.cmd-search-icon { color: var(--text-muted); flex-shrink: 0; }
.cmd-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 16px;
    color: var(--text);
    outline: none;
    font-family: inherit;
}
.cmd-input::placeholder { color: var(--text-muted); }
.cmd-esc-hint {
    font-size: 11px;
    padding: 3px 7px;
    background: var(--sidebar-hover);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-muted);
    font-family: monospace;
    cursor: pointer;
    flex-shrink: 0;
    user-select: none;
}

.cmd-results {
    overflow-y: auto;
    flex: 1;
    padding: 6px 0;
}
.cmd-results::-webkit-scrollbar { width: 4px; }
.cmd-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.cmd-group {
    padding: 8px 18px 3px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    user-select: none;
}

.cmd-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 18px;
    cursor: pointer;
    transition: background 0.08s;
}
.cmd-item:hover    { background: var(--sidebar-hover); }
.cmd-item.is-active { background: var(--accent-glow); }

.cmd-icon {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    background: var(--sidebar-hover);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-muted);
}
.cmd-icon.teal   { background:rgba(79, 70, 229,0.12); border-color:rgba(79, 70, 229,0.25); color:var(--primary); }
.cmd-icon.blue   { background:rgba(59,130,246,0.10); border-color:rgba(59,130,246,0.20); color:#3b82f6; }
.cmd-icon.purple { background:rgba(139,92,246,0.10); border-color:rgba(139,92,246,0.20); color:#8b5cf6; }
.cmd-icon.orange { background:rgba(249,115,22,0.10); border-color:rgba(249,115,22,0.20); color:#f97316; }
.cmd-icon.green  { background:rgba(34,197,94,0.10);  border-color:rgba(34,197,94,0.20);  color:#22c55e; }

.cmd-item-body { flex: 1; min-width: 0; }
.cmd-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cmd-label mark {
    background: rgba(79, 70, 229,0.18);
    color: var(--primary);
    border-radius: 2px;
    padding: 0 1px;
    font-weight: 700;
    font-style: normal;
}
.cmd-sub {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.cmd-shortcut { display: flex; gap: 3px; flex-shrink: 0; }
.cmd-shortcut kbd {
    padding: 2px 6px;
    background: var(--sidebar-hover);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 11px;
    font-family: monospace;
    color: var(--text-muted);
}

.cmd-empty {
    padding: 36px 18px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.cmd-footer {
    display: flex;
    gap: 16px;
    padding: 9px 18px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.cmd-footer span {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}
.cmd-footer kbd {
    padding: 1px 5px;
    background: var(--sidebar-hover);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 10px;
    font-family: monospace;
}

.dark-mode .cmd-palette {
    box-shadow: 0 24px 60px rgba(0,0,0,0.55), 0 4px 16px rgba(0,0,0,0.35);
}

@media (max-width: 640px) {
    .cmd-palette {
        top: 0; left: 0; right: 0;
        transform: none;
        width: 100%; max-width: 100%;
        border-radius: 0 0 14px 14px;
        max-height: 80vh;
    }
}
/* ========== MERMAID DIAGRAM BLOCK ========== */
.mermaid-block-editor {
  padding: 8px;
  background: var(--main-bg);
  border-radius: 6px;
}

.mermaid-panes {
  display: flex;
  gap: 12px;
  min-height: 200px;
}

.mermaid-code-pane,
.mermaid-preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mermaid-pane-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.mermaid-textarea {
  flex: 1;
  min-height: 180px;
  padding: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
}

.mermaid-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.mermaid-preview-pane .mermaid-preview {
  flex: 1;
  min-height: 180px;
  padding: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mermaid-render-block {
  padding: 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mermaid-render-block svg,
.mermaid-preview svg {
  max-width: 100%;
  height: auto;
}

.mermaid-empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
}

.mermaid-error {
  color: #ef4444;
  font-size: 12px;
  font-family: 'Courier New', monospace;
}

/* ========== EMBED BLOCK ========== */
.embed-preview-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-bg);
}

.embed-preview-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
}

.embed-provider-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.embed-preview-url {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'Courier New', monospace;
}

.embed-preview-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 120px;
  padding: 24px;
  background: var(--main-bg);
}

.embed-preview-icon {
  font-size: 28px;
  opacity: 0.4;
}

.embed-preview-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.embed-preview-hint {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.6;
  font-style: italic;
}

/* Viewer: live iframe */
.embed-iframe-wrapper {
  width: 100%;
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.embed-iframe-wrapper iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: none;
}

.embed-error {
  padding: 16px;
  color: #ef4444;
  font-size: 13px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* Dark mode */
.dark-mode .embed-preview-card { background: var(--card-bg); }
.dark-mode .embed-preview-placeholder { background: var(--main-bg); }

/* ===== VERSION TIME MACHINE — TIMELINE STRIP ===== */
.vtm-strip-wrap {
    position: relative;
    padding: 18px 0 10px;
}

.vtm-strip-track {
    position: relative;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    margin: 0 14px;
}

.vtm-dot {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    border: 2px solid var(--sidebar-bg);
    cursor: pointer;
    transition: transform 0.15s, background 0.15s;
    z-index: 2;
}

.vtm-dot:hover {
    transform: translate(-50%, -50%) scale(1.5);
    z-index: 3;
}

.vtm-dot.live {
    background: var(--primary);
}

.vtm-dot.manual {
    background: #f97316;
    border-radius: 3px;
}

.vtm-dot.sel-a {
    background: #f97316;
    box-shadow: 0 0 0 3px rgba(249,115,22,0.25);
    transform: translate(-50%, -50%) scale(1.35);
}

.vtm-dot.sel-b {
    background: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229,0.25);
    transform: translate(-50%, -50%) scale(1.35);
}

.vtm-dot.sel-a.sel-b {
    background: #8b5cf6;
    box-shadow: 0 0 0 3px rgba(139,92,246,0.25);
}

.vtm-strip-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-muted);
    margin: 4px 14px 0;
}

/* Scrub slider */
.vtm-scrub-row {
    border-top: 1px solid var(--border-color);
    margin-top: 10px;
    padding-top: 10px;
}

.vtm-scrub-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.vtm-scrub-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.vtm-scrub-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

.vtm-scrub-slider {
    width: 100%;
    height: 4px;
    accent-color: #8b5cf6;
}

/* Preview pane (scrub mode) */
.vtm-preview-pane {
    background: var(--main-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 12px;
    overflow: hidden;
}

.vtm-preview-label {
    font-size: 11px;
    font-weight: 600;
    padding: 6px 12px;
    background: rgba(139,92,246,0.08);
    color: #7c3aed;
    border-bottom: 1px solid var(--border-color);
}

.dark-mode .vtm-preview-label { background: rgba(139,92,246,0.14); }

.vtm-preview-footer {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
    background: var(--sidebar-bg);
}

/* Dim A/B sliders when scrub mode is active */
.diff-timeline-track.scrub-active {
    opacity: 0.35;
    pointer-events: none;
    user-select: none;
}

.dark-mode .vtm-preview-label { background: rgba(139,92,246,0.14); }

.vtm-preview-content {
    padding: 12px 16px;
    font-size: 13px;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
    color: var(--text-primary);
}

/* Stats bar + playback */
.vtm-stats-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--sidebar-bg);
    border-radius: 8px;
    margin-top: 8px;
    gap: 12px;
    flex-wrap: wrap;
}

.vtm-stats-counts {
    display: flex;
    gap: 12px;
    font-size: 12px;
    flex-wrap: wrap;
}

.vtm-stat {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
}

.vtm-stat-added   { color: #16a34a; }
.vtm-stat-removed { color: #dc2626; }
.vtm-stat-changed { color: #ea580c; }

.vtm-play-btn {
    font-size: 12px;
    padding: 4px 12px;
    min-width: 80px;
}

.vtm-play-btn.playing {
    background: #7c3aed;
    color: #fff;
    border-color: #7c3aed;
}

/* ===== VERSION DIFF VISUALIZATION ===== */
.version-diff-modal {
    max-width: 95vw;
    width: 1100px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 20px;
}

.version-diff-header {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    gap: 10px;
}

.version-diff-header h3 {
    margin: 0;
}

/* Timeline */
.diff-timeline-section {
    background: var(--sidebar-bg);
    border-radius: 10px;
    padding: 14px 16px 10px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
}

.diff-timeline-track {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.diff-slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.diff-slider-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    min-width: 72px;
}

.diff-slider {
    flex: 1;
    height: 4px;
    border-radius: 4px;
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    border: none;
    background: var(--border);
}

.diff-slider-a {
    accent-color: #f97316;
}

.diff-slider-b {
    accent-color: var(--primary);
}

.diff-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.diff-slider-a::-webkit-slider-thumb { background: #f97316; }
.diff-slider-b::-webkit-slider-thumb { background: var(--primary); }

.diff-pin-label {
    font-size: 11px;
    color: var(--text-muted);
    min-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.diff-legend {
    display: flex;
    gap: 16px;
    font-size: 11px;
    color: var(--text-muted);
}

.diff-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.diff-legend-added { color: #16a34a; }
.diff-legend-changed { color: #ea580c; }
.diff-legend-removed { color: #dc2626; }

/* Panes */
.diff-panes {
    display: flex;
    gap: 12px;
    flex: 1;
    min-height: 0;
    max-height: calc(92vh - 300px);
    overflow: hidden;
}

.diff-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    min-width: 0;
}

.diff-pane-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
}

.diff-pane-label-a {
    background: rgba(249, 115, 22, 0.08);
    color: #ea580c;
    border-bottom-color: rgba(249, 115, 22, 0.2);
}

.diff-pane-label-b {
    background: rgba(79, 70, 229, 0.08);
    color: var(--primary-hover);
    border-bottom-color: rgba(79, 70, 229, 0.2);
}

.dark-mode .diff-pane-label-a { background: rgba(249,115,22,0.12); }
.dark-mode .diff-pane-label-b { background: rgba(79, 70, 229,0.12); }

.diff-pane-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    font-size: 14px;
    line-height: 1.6;
    background: var(--main-bg);
}

/* Diff highlight classes */
.diff-seg {
    display: block;
    padding: 2px 6px;
    border-radius: 3px;
    margin: 1px 0;
    border-left: 3px solid transparent;
    transition: background 0.1s;
}

.diff-seg-added {
    background: rgba(22, 163, 74, 0.08);
    border-left-color: #16a34a;
}

.diff-seg-changed {
    background: rgba(234, 88, 12, 0.10);
    border-left-color: #ea580c;
}

.diff-seg-removed {
    background: rgba(220, 38, 38, 0.08);
    border-left-color: #dc2626;
    text-decoration: line-through;
    opacity: 0.6;
}

.diff-seg-same {
    border-left-color: transparent;
}

/* Version item Compare button */
.btn-compare {
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-compare:hover {
    border-color: var(--primary);
    color: var(--primary);
}

@media (max-width: 768px) {
    .diff-panes {
        flex-direction: column;
        max-height: none;
    }
    .version-diff-modal {
        width: 100%;
        max-height: 98vh;
    }
}
/* Version item layout fix — prevent button overflow */
.version-item {
    flex-wrap: wrap;
    gap: 8px;
}

.version-info {
    min-width: 0;
    flex: 1 1 200px;
}

.version-details {
    min-width: 0;
}

.version-time {
    white-space: normal;
    word-break: break-word;
}

.version-meta {
    white-space: normal;
    word-break: break-word;
}

.version-actions {
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
}

.version-actions button,
.btn-compare {
    white-space: nowrap;
}
/* ========== TIPTAP EDITOR ========== */
.tiptap-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 16px;
  background: var(--sidebar-hover, #f5f5f5);
  border-bottom: 1px solid var(--border, #e0e0e0);
  position: sticky;
  top: 0;
  z-index: 10;
}
.tiptap-toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-right: 8px;
  border-right: 1px solid var(--border, #e0e0e0);
}
.tiptap-toolbar-group:last-child { border-right: none; }
.tiptap-toolbar button, .tiptap-toolbar select {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 7px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text, #333);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s;
  min-width: 28px;
  height: 28px;
}
.tiptap-toolbar button:hover { background: var(--sidebar-active, #e8e8e8); }
.tiptap-toolbar button.is-active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.tiptap-toolbar select {
  padding: 4px 6px;
  border: 1px solid var(--border, #e0e0e0);
  border-radius: 4px;
  font-size: 12px;
  min-width: 90px;
  height: 28px;
  background: var(--card-bg, #fff);
}

/* ProseMirror (Tiptap content area) */
.tiptap-editor .ProseMirror {
  padding: 24px 32px;
  min-height: 300px;
  outline: none;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text, #333);
}
.tiptap-editor .ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  color: var(--text-muted, #aaa);
  pointer-events: none;
  float: left;
  height: 0;
}
.tiptap-editor .ProseMirror h1 { font-size: 2em; font-weight: 700; margin: 0.5em 0; }
.tiptap-editor .ProseMirror h2 { font-size: 1.5em; font-weight: 600; margin: 0.5em 0; }
.tiptap-editor .ProseMirror h3 { font-size: 1.2em; font-weight: 600; margin: 0.4em 0; }
.tiptap-editor .ProseMirror ul  { list-style: disc;    padding-left: 1.5em; }
.tiptap-editor .ProseMirror ol  { list-style: decimal; padding-left: 1.5em; }
.tiptap-editor .ProseMirror blockquote {
  border-left: 4px solid var(--primary);
  margin: 1em 0; padding: 0.5em 1em;
  color: var(--text-muted, #666);
  background: var(--sidebar-hover, #f9f9f9);
  border-radius: 0 6px 6px 0;
}
.tiptap-editor .ProseMirror pre {
  background: #1e1e2e; color: #cdd6f4;
  padding: 1em 1.2em; border-radius: 6px;
  font-size: 13px; overflow-x: auto;
}
.tiptap-editor .ProseMirror code {
  background: var(--sidebar-hover, #f0f0f0);
  padding: 2px 5px; border-radius: 3px; font-size: 0.9em;
}
/* Reset inline-code styles inside code blocks — prevents white overlay on pre>code */
.tiptap-editor .ProseMirror pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  color: inherit;
}
.tiptap-editor .ProseMirror img {
  max-width: 100%; border-radius: 6px;
  cursor: pointer; display: block; margin: 8px 0;
}
.tiptap-editor .ProseMirror a {
  color: var(--primary); text-decoration: underline;
}
.tiptap-editor .ProseMirror hr {
  border: none; border-top: 2px solid var(--border, #e0e0e0); margin: 1.5em 0;
}

/* Slash command menu */
.slash-menu {
  position: absolute;
  z-index: 1000;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border, #e0e0e0);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  min-width: 200px;
  max-height: 320px;
  overflow-y: auto;
  padding: 4px;
}
.slash-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.1s;
}
.slash-menu-item:hover,
.slash-menu-item.active {
  background: var(--sidebar-active, #f0f0f0);
}
.slash-menu-icon {
  width: 24px; text-align: center;
  font-size: 14px; font-weight: 600;
  color: var(--text-muted, #888);
}
.slash-menu-label { color: var(--text, #333); }
/* ========== PIN SYSTEM ========== */
.tree-pin-badge {
  font-size: 11px;
  opacity: 0.75;
  flex-shrink: 0;
  line-height: 1;
  margin-left: 2px;
  transition: opacity 0.15s;
}
.tree-item:hover .tree-pin-badge {
  opacity: 1;
}