/* Docs App Styles */
@import url('../shared/global.css');

:root {
    --sidebar-width: 280px;
    --transition-speed: 0.2s;
}

body {
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-top: 64px; /* Account for fixed topbar */
}

#app {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
}

/* Sidebar */
#sidebar {
    background-color: var(--workspace-sidebar-bg, var(--md-sys-color-surface-container));
    border-right: 1px solid var(--md-sys-color-outline-variant);
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    height: calc(100vh - 64px); /* Account for topbar */
    position: fixed;
    top: 64px;
    left: 0;
    bottom: 0;
    z-index: 900;
}

/* Main content area */
#main-content {
    margin-left: 0;
    margin-top: 0;
    height: calc(100vh - 64px);
    overflow-y: auto;
    flex: 1;
}

/* Drawer (Documents / Trash) */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: color-mix(in srgb, var(--md-sys-color-scrim) 32%, transparent);
    z-index: 2000;
    opacity: 0;
    transition: opacity 180ms ease;
}

.drawer-backdrop.open {
    opacity: 1;
}

.drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    height: 100vh;
    background-color: var(--workspace-sidebar-bg, var(--md-sys-color-surface-container));
    border-right: 1px solid var(--md-sys-color-outline-variant);
    display: flex;
    flex-direction: column;
    z-index: 2001;
    box-shadow: 0 12px 32px color-mix(in srgb, var(--md-sys-color-shadow) 25%, transparent);
    transform: translateX(-24px);
    opacity: 0;
    transition: transform 220ms cubic-bezier(0.2, 0.0, 0.0, 1), opacity 180ms ease;
}

.drawer.open {
    transform: translateX(0px);
    opacity: 1;
}

.docs-empty-state {
    padding: 24px;
    border-radius: 16px;
    border: 1px dashed var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface-container);
    color: var(--md-sys-color-on-surface);
    max-width: 520px;
    margin: 24px auto;
}

.docs-empty-title {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 6px;
}

.docs-empty-subtitle {
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 14px;
}

.docs-empty-action {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 999px;
    border: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    padding: 8px 12px;
    cursor: pointer;
    font: inherit;
}

.docs-empty-action:hover {
    background: var(--md-sys-color-surface-container-high);
}

.sidebar-content {
    flex-grow: 1;
    overflow-y: auto;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid var(--md-sys-color-outline-variant);
}

.sidebar-header {
    padding: 16px 24px;
}

.sidebar-nav {
    list-style: none;
    padding: 8px;
    flex-grow: 1;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-radius: 100px;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    transition: all 0.2s;
    margin-bottom: 4px;
}

.nav-item:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 5%, transparent);
}

.nav-item.active {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    font-weight: 500;
}

.nav-item .material-symbols-rounded {
    font-size: 24px;
}

.sidebar-divider {
    height: 1px;
    background-color: var(--md-sys-color-outline-variant);
    margin: 8px 16px;
}

/* Document List */
#document-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#document-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    transition: all 0.2s;
    margin-bottom: 4px;
    position: relative;
}

#document-list li:hover {
    background-color: var(--md-sys-color-surface-container-high);
}

#document-list li .material-symbols-rounded:first-child {
    font-size: 20px;
}

.doc-action-btn {
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.2s;
    padding: 4px;
    border-radius: 4px;
}

#document-list li:hover .doc-action-btn {
    opacity: 1;
}

.doc-action-btn:hover {
    background-color: var(--md-sys-color-surface-container-highest);
}

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

.doc-actions .doc-action-btn {
    margin-left: 0;
    opacity: 0;
}

#document-list li:hover .doc-actions .doc-action-btn {
    opacity: 1;
}

.doc-action-btn.danger {
    color: var(--md-sys-color-error);
}

/* Document list items */
#document-list .nav-item {
    cursor: pointer;
    user-select: none;
}

#document-list .nav-item:hover {
    background-color: var(--md-sys-color-surface-container-highest);
}

#document-list .nav-item.active {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

/* Main Content */
#main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#doc-tab-bar {
    display: flex;
    background-color: var(--md-sys-color-surface-container);
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    padding: 0 16px;
    overflow-x: auto;
}

#page-tab-bar {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 4px;
    overflow-y: auto;
}

.doc-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    position: relative;
}

.doc-tab:hover {
    background-color: var(--md-sys-color-surface-container-high);
}

.doc-tab.active {
    color: var(--md-sys-color-primary);
    border-bottom-color: var(--md-sys-color-primary);
}

.doc-tab.deep-link-focus {
    animation: docTabPulse 1.1s ease-out;
    border-radius: 10px;
}

@keyframes docTabPulse {
    0% { box-shadow: 0 0 0 0 rgba(103, 80, 164, 0.35); }
    60% { box-shadow: 0 0 0 10px rgba(103, 80, 164, 0.0); }
    100% { box-shadow: 0 0 0 0 rgba(103, 80, 164, 0.0); }
}

.doc-tab .tab-close {
    opacity: 0;
    transition: opacity 0.2s;
    padding: 2px;
    border-radius: 4px;
    font-size: 18px;
}

.doc-tab:hover .tab-close {
    opacity: 1;
}

.doc-tab .tab-close:hover {
    background-color: var(--md-sys-color-surface-container-highest);
}

.doc-tab.doc-drawer-toggle,
.doc-tab.add-doc-tab {
    padding: 12px 12px;
}

.doc-tab.doc-drawer-toggle .material-symbols-rounded,
.doc-tab.add-doc-tab .material-symbols-rounded {
    font-size: 20px;
}

/* In-document (page) tabs */
#page-tabs-container {
    width: var(--doc-tabs-width, 200px);
    background-color: var(--md-sys-color-surface-container);
    border-right: 1px solid var(--md-sys-color-outline-variant);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    max-height: 100%;
    overflow: auto;
    align-self: stretch;
}

.page-tabs-header {
    padding: 12px 16px;
    font-weight: 600;
    color: var(--md-sys-color-on-surface);
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.page-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    transition: all 0.2s;
    border-left: none;
    white-space: nowrap;
    position: relative;
    font-size: 0.9rem;
    border-radius: 10px;
    text-align: left;
}

.page-tab:hover {
    background-color: var(--md-sys-color-surface-container-high);
}

.page-tab.active {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}

.page-tab .tab-close {
    opacity: 0;
    transition: opacity 0.2s;
    padding: 2px;
    border-radius: 4px;
    font-size: 18px;
}

.page-tab:hover .tab-close {
    opacity: 1;
}

.page-tab .tab-close:hover {
    background-color: var(--md-sys-color-surface-container-highest);
}

.page-tab.add-page-tab {
    color: var(--md-sys-color-primary);
    justify-content: center;
}

.page-tab.add-page-tab .material-symbols-rounded {
    font-size: 20px;
}

/* Document Page */
#editor-container {
    flex-grow: 1;
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
}

#editor-layout {
    display: flex;
    flex-direction: row;
    flex-grow: 1;
    overflow: hidden;
    position: relative;
    border-radius: 10px;
    --doc-tabs-width: 200px;
    align-items: flex-start;
}

/* Document Outline */
#doc-outline-container {
    width: 200px;
    padding: 32px 16px;
    border-right: 1px solid var(--md-sys-color-outline-variant);
    overflow-y: auto;
    background-color: var(--md-sys-color-surface-container-low);
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: width 0.3s ease;
}

.outline-header {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--md-sys-color-on-surface-variant);
    padding-left: 8px;
}

#doc-outline {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.outline-item {
    font-size: 13px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.2s;
}

.outline-item:hover {
    background-color: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-on-surface);
}

.outline-item.h1 {
    font-weight: 500;
    font-size: 14px;
}

.outline-item.h2 {
    padding-left: 16px;
}

.outline-item.h3 {
    padding-left: 24px;
}

#document-page {
    background-color: var(--md-sys-color-surface-container-lowest);
    width: 100%;
    max-width: 850px;
    margin: 32px auto;
    padding: 72px;
    padding-bottom: 120px;
    /* Default "paper" height (Letter @ ~96dpi). Grows naturally as you type. */
    min-height: 1056px;
    box-shadow: 0 1px 3px color-mix(in srgb, var(--md-sys-color-shadow) 10%, transparent), 0 1px 1px color-mix(in srgb, var(--md-sys-color-shadow) 5%, transparent);
    display: flex;
    flex-direction: column;
    border-radius: 10px;
    overflow-y: initial;
    position: relative;
}

#doc-word-count {
    position: fixed;
    left: calc(var(--doc-tabs-width, 200px) + 16px);
    bottom: 12px;
    padding: 8px 10px;
    border-radius: 999px;
    border: 1px solid var(--md-sys-color-outline-variant);
    background: color-mix(in srgb, var(--md-sys-color-surface-container-lowest) 92%, transparent);
    color: var(--md-sys-color-on-surface-variant);
    font-size: 12px;
    font-weight: 600;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    user-select: none;
    z-index: 30;
}

#editor-layout {
    overflow-y: auto;
}

#doc-title {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--md-sys-color-on-surface);
    border: none;
    outline: none;
    font-family: 'Kumbh Sans', sans-serif;
}

#doc-active-tab-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 18px;
}

#doc-active-tab-name:empty {
    display: none;
}

#doc-title:empty:before {
    content: attr(placeholder);
    color: #70757a;
}

#doc-editor {
    flex-grow: 1;
    font-size: 16px;
    line-height: 1.6;
    color: var(--md-sys-color-on-surface);
    outline: none;
    min-height: 400px;
}

/* Print Button - Bottom Right */
.print-btn {
    position: fixed;
    right: 24px;
    bottom: 12px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--md-sys-color-outline-variant);
    background: color-mix(in srgb, var(--md-sys-color-surface-container-lowest) 92%, transparent);
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 30;
    transition: all 0.2s ease;
}

.print-btn:hover {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border-color: var(--md-sys-color-primary);
}

.print-btn .material-symbols-rounded {
    font-size: 20px;
}

/* Print Preview Modal */
.print-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.print-preview-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.print-preview-container {
    position: relative;
    width: 90vw;
    max-width: 1000px;
    height: 85vh;
    background: var(--md-sys-color-surface);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.print-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface-container);
}

.print-preview-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--md-sys-color-on-surface);
}

.print-preview-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

#print-preview-info {
    font-size: 13px;
    color: var(--md-sys-color-on-surface-variant);
}

.print-preview-actions .toolbar-btn {
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--md-sys-color-outline);
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.print-preview-actions .toolbar-btn:hover {
    background: var(--md-sys-color-surface-container);
}

.print-preview-actions .toolbar-btn.primary {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border-color: var(--md-sys-color-primary);
}

.print-preview-actions .toolbar-btn.primary:hover {
    background: color-mix(in srgb, var(--md-sys-color-primary) 90%, white);
}

.print-preview-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: #525659; /* Dark gray like print preview */
}

/* Print Preview Page */
.print-preview-page {
    width: 210mm; /* A4 width */
    min-height: 297mm; /* A4 height */
    margin: 0 auto 24px;
    padding: 20mm;
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    position: relative;
}

.print-preview-page:last-child {
    margin-bottom: 0;
}

.print-preview-page .page-number {
    position: absolute;
    bottom: 10mm;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: #666;
}

/* Print styles - hide UI elements */
@media print {
    #global-topbar,
    #sidebar,
    #page-tabs-container,
    .toolbar,
    #doc-word-count,
    .print-btn,
    #animated-caret,
    #doc-comments-container {
        display: none !important;
    }

    #document-page {
        box-shadow: none !important;
        margin: 0 !important;
        padding: 0 !important;
        max-width: none !important;
        width: 100% !important;
    }

    body {
        background: white !important;
    }

    /* Remove URL from print */
    @page {
        margin: 20mm;
    }

    a[href]:after {
        content: none !important;
    }
}

#editor-layout {
    overflow-y: auto;
}

#doc-title {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--md-sys-color-on-surface);
    border: none;
    outline: none;
    font-family: 'Kumbh Sans', sans-serif;
}

#doc-active-tab-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 18px;
}

#doc-active-tab-name:empty {
    display: none;
}

#doc-title:empty:before {
    content: attr(placeholder);
    color: #70757a;
}

#doc-editor {
    flex-grow: 1;
    font-size: 16px;
    line-height: 1.5;
    color: #202124;
    outline: none;
    min-height: 200px;
    font-family: 'Kumbh Sans', sans-serif;
}

#doc-editor img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    cursor: default;
}

#doc-editor hr {
    border: none;
    border-top: 1px solid var(--md-sys-color-outline-variant);
    margin: 18px 0;
}

#doc-editor table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    margin: 12px 0;
    background: var(--md-sys-color-surface);
    border-radius: 10px;
    overflow: hidden;
    border: none;
    outline: none;
}

/* Image resize overlay */
#image-resize-overlay {
    position: fixed;
    z-index: 1500;
    border: 2px solid var(--md-sys-color-primary);
    border-radius: 12px;
    pointer-events: none;
    display: none;
}

#image-resize-handle {
    position: absolute;
    right: -8px;
    bottom: -8px;
    width: 14px;
    height: 14px;
    border-radius: 6px;
    background: var(--md-sys-color-primary);
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    pointer-events: auto;
    cursor: nwse-resize;
}

#doc-editor td,
#doc-editor th {
    border: 1px solid var(--md-sys-color-outline-variant);
    padding: 10px 12px;
    vertical-align: top;
    min-width: 48px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Remove the outer table border outline (keep inner grid lines) */
#doc-editor table tr:first-child > td,
#doc-editor table tr:first-child > th {
    border-top: none;
}

#doc-editor table tr:last-child > td,
#doc-editor table tr:last-child > th {
    border-bottom: none;
}

#doc-editor table tr > td:first-child,
#doc-editor table tr > th:first-child {
    border-left: none;
}

#doc-editor table tr > td:last-child,
#doc-editor table tr > th:last-child {
    border-right: none;
}

#doc-editor pre {
    background: var(--md-sys-color-surface-container);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 10px;
    padding: 12px 14px;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 13px;
    line-height: 1.5;
}

#doc-editor code {
    background: var(--md-sys-color-surface-container);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 8px;
    padding: 1px 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.92em;
}

/* Animated caret (Office-like smooth cursor) */
#doc-editor,
#doc-title {
    caret-color: transparent;
}

#animated-caret {
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    background: var(--md-sys-color-primary);
    border-radius: 2px;
    opacity: 0;
    pointer-events: none;
    transform: translate(0px, 0px);
    transition: transform 90ms cubic-bezier(0.2, 0.0, 0.0, 1), height 90ms cubic-bezier(0.2, 0.0, 0.0, 1), opacity 120ms ease;
    animation: caret-blink 1.05s step-end infinite;
    z-index: 5;
}

#animated-caret.visible {
    opacity: 1;
}

#animated-caret.typing {
    animation: none;
    opacity: 1 !important;
}

@keyframes caret-blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

#doc-editor h1 {
    font-size: 32px;
    font-weight: 700;
    margin-top: 16px;
    margin-bottom: 8px;
    font-family: 'Kumbh Sans', sans-serif;
}

#doc-editor h2 {
    font-size: 24px;
    font-weight: 600;
    margin-top: 14px;
    margin-bottom: 6px;
    font-family: 'Kumbh Sans', sans-serif;
}

#doc-editor h3 {
    font-size: 20px;
    font-weight: 600;
    margin-top: 12px;
    margin-bottom: 4px;
    font-family: 'Kumbh Sans', sans-serif;
}

#doc-editor p {
    margin-bottom: 12px;
}

#document-list {
    transition: opacity 0.2s ease-in-out;
}

#document-list.fade-out {
    opacity: 0;
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 12px 16px;
    background-color: var(--md-sys-color-surface-container);
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scrollbar-gutter: stable both-edges;
}

.toolbar > * {
    flex: 0 0 auto;
}

.toolbar::-webkit-scrollbar {
    height: 10px;
}

.toolbar::-webkit-scrollbar-thumb {
    background: var(--md-sys-color-outline-variant);
    border-radius: 999px;
}

.toolbar::-webkit-scrollbar-thumb:hover {
    background: var(--md-sys-color-outline);
}

.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 14px;
}

.toolbar-btn:hover {
    background-color: var(--md-sys-color-surface-container-high);
}

.toolbar-btn.active {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}

.toolbar-btn .material-symbols-rounded {
    font-size: 20px;
}

.color-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid var(--md-sys-color-outline);
    margin-left: 4px;
}

.toolbar-separator {
    width: 1px;
    height: 24px;
    background-color: var(--md-sys-color-outline-variant);
    margin: 0 4px;
}

.toolbar-btn-group {
    display: flex;
    gap: 4px;
    padding: 4px;
    background-color: var(--md-sys-color-surface-container-high);
    border-radius: 8px;
}

.toolbar-btn-group .toolbar-btn {
    padding: 6px 8px;
}

.toolbar-btn-group .toolbar-btn.active {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}

/* Toolbar Selects */
.toolbar-select-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.toolbar-select {
    padding: 6px 8px;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 4px;
    background-color: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-on-surface);
    font-size: 13px;
    outline: none;
    cursor: pointer;
}

.toolbar-select:hover {
    background-color: var(--md-sys-color-surface-container-highest);
}

/* Color Picker */
.color-picker-popup {
    display: none;
    position: absolute;
    background-color: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 8px;
    box-shadow: 0 2px 8px color-mix(in srgb, var(--md-sys-color-shadow) 20%, transparent);
    z-index: 1000;
    padding: 8px;
}

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

.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    padding: 8px;
}

.color-picker-item {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.color-picker-item:hover {
    border-color: var(--md-sys-color-outline);
}

.color-picker-item.active {
    border-color: var(--md-sys-color-primary);
}

.color-picker-custom {
    width: 100%;
    height: 32px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 8px;
}

.color-picker-custom {
    width: 100%;
    height: 32px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 8px;
}

/* Link Modal */
.link-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: color-mix(in srgb, var(--md-sys-color-scrim) 50%, transparent);
    align-items: center;
    justify-content: center;
}

.link-modal.show {
    display: flex;
}

.link-modal-content {
    background-color: var(--md-sys-color-surface);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 16px color-mix(in srgb, var(--md-sys-color-shadow) 20%, transparent);
}

.link-preview {
    position: fixed;
    z-index: 1200;
    min-width: 280px;
    max-width: 360px;
    background: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 14px;
    box-shadow: 0 12px 30px color-mix(in srgb, var(--md-sys-color-shadow) 18%, transparent);
    padding: 12px;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 140ms ease, transform 160ms cubic-bezier(0.2, 0.0, 0.0, 1);
}

.link-preview.show {
    opacity: 1;
    transform: translateY(0px);
}

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

.link-preview-title {
    flex: 1;
    font-weight: 700;
    color: var(--md-sys-color-on-surface);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-preview-close {
    border: none;
    background: transparent;
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
    border-radius: 10px;
    padding: 6px;
}

.link-preview-close:hover {
    background: var(--md-sys-color-surface-container-high);
}

.link-preview-url {
    font-size: 12px;
    color: var(--md-sys-color-on-surface-variant);
    word-break: break-word;
    line-height: 1.4;
    padding: 6px 0 10px 0;
}

.link-preview-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.link-preview-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-on-surface);
    padding: 8px 12px;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 700;
    font-size: 12px;
}

.link-preview-btn.primary {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border-color: transparent;
}

.link-preview-btn.secondary:hover,
.link-preview-btn.primary:hover {
    filter: brightness(0.98);
}

.link-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.link-modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: var(--md-sys-color-on-surface);
}

.link-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    padding: 4px;
    border-radius: 4px;
}

.link-modal-close:hover {
    background-color: var(--md-sys-color-surface-container-high);
}

.link-input-group {
    margin-bottom: 16px;
}

.link-input-group label {
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
    color: var(--md-sys-color-on-surface-variant);
}

.link-input-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 8px;
    font-size: 14px;
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
}

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

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

.link-modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.link-modal-btn.primary {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.link-modal-btn.primary:hover {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.link-modal-btn.secondary {
    background-color: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-on-surface);
}

.link-modal-btn.secondary:hover {
    background-color: var(--md-sys-color-surface-container-highest);
}

/* Sidebar Button */
.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    background-color: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-on-surface);
}

.sidebar-btn:hover {
    background-color: var(--md-sys-color-surface-container-highest);
}

.sidebar-btn.primary {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.sidebar-btn.primary:hover {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.sidebar-btn .material-symbols-rounded {
    font-size: 20px;
}

/* Context Menu */
.context-menu {
    position: absolute;
    /* Must sit above everything including tooltips */
    z-index: 10001;
    background-color: var(--md-sys-color-surface-container-high);
    border-radius: 8px;
    box-shadow: 0 4px 6px color-mix(in srgb, var(--md-sys-color-shadow) 10%, transparent), 0 1px 3px color-mix(in srgb, var(--md-sys-color-shadow) 8%, transparent);
    /* Elevation 3 appx */
    min-width: 180px;
    padding: 8px 0;
    overflow: hidden;
    animation: fadeIn 0.1s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.context-menu-items {
    list-style: none;
    padding: 0;
    margin: 0;
}

.context-menu-item {
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-size: 14px;
    color: var(--md-sys-color-on-surface);
    transition: background-color 0.1s;
}

.context-menu-item:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

.context-menu-item.delete {
    color: var(--md-sys-color-error, #ba1a1a);
}

.context-menu-item.delete:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-error) 8%, transparent);
}

.context-menu-item .material-symbols-rounded {
    font-size: 20px;
}

.context-divider {
    height: 1px;
    background-color: var(--md-sys-color-outline);
    opacity: 0.12;
    margin: 4px 0;
}

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

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    color: var(--md-sys-color-on-surface);
    font-size: 14px;
    transition: background-color 0.2s;
}

.context-menu-item:hover {
    background-color: var(--md-sys-color-surface-container-highest);
}

.context-menu-item .material-symbols-rounded {
    font-size: 20px;
    color: var(--md-sys-color-on-surface-variant);
}

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

.context-menu-item.danger .material-symbols-rounded {
    color: var(--md-sys-color-error);
}

/* Dirty Indicator */
.doc-tab.dirty span:first-child::after {
    content: '•';
    color: var(--md-sys-color-primary);
    font-size: 20px;
    line-height: 1;
    margin-left: 8px;
    display: inline-block;
    vertical-align: middle;
}
