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

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --text-primary: #1a1a1a;
    --text-secondary: #6c757d;
    --border-color: #e0e0e0;
    --accent: #5c7cfa;
    --code-bg: #f4f4f4;
    --toolbar-bg: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2a2a2a;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border-color: #3a3a3a;
    --accent: #748ffc;
    --code-bg: #2a2a2a;
    --toolbar-bg: rgba(26, 26, 26, 0.95);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--toolbar-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 20px;
    z-index: 100;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.header.hidden {
    transform: translateY(-100%);
    opacity: 0;
}

.header-content {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand {
    font-size: 18px;
    font-weight: 600;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: flex;
    align-items: center;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

button {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
}

button:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    transform: translateY(-1px);
}

button.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.toolbar {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--toolbar-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    display: flex;
    gap: 4px;
    z-index: 99;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.toolbar.faded {
    opacity: 0.2;
}

.toolbar:hover {
    opacity: 1 !important;
}

.toolbar button {
    padding: 6px 10px;
    font-size: 13px;
    background: transparent;
    border: 1px solid transparent;
}

.toolbar button:hover {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    transform: none;
}

.toolbar button.active {
    background: var(--accent);
    color: white;
}

.toolbar .separator {
    width: 1px;
    background: var(--border-color);
    margin: 4px;
}

.container {
    max-width: 750px;
    margin: 0 auto;
    padding: 120px 20px 40px;
    min-height: 100vh;
}

.editor-wrapper {
    background: var(--bg-primary);
    border-radius: 8px;
    min-height: 500px;
}

.tiptap {
    outline: none;
    min-height: 500px;
    font-size: 18px;
    line-height: 1.7;
    color: var(--text-primary);
}

.tiptap h1 {
    font-size: 2.5em;
    font-weight: 700;
    margin: 1em 0 0.5em;
    line-height: 1.2;
}

.tiptap h2 {
    font-size: 2em;
    font-weight: 600;
    margin: 1em 0 0.5em;
    line-height: 1.3;
}

.tiptap h3 {
    font-size: 1.5em;
    font-weight: 600;
    margin: 1em 0 0.5em;
}

.tiptap h4, .tiptap h5, .tiptap h6 {
    font-size: 1.2em;
    font-weight: 600;
    margin: 1em 0 0.5em;
}

.tiptap p {
    margin: 0 0 1em;
}

.tiptap ul, .tiptap ol {
    padding-left: 1.5em;
    margin: 0 0 1em;
}

.tiptap li {
    margin: 0.25em 0;
}

.tiptap blockquote {
    border-left: 4px solid var(--accent);
    padding-left: 1em;
    margin: 1em 0;
    color: var(--text-secondary);
    font-style: italic;
}

.tiptap pre {
    background: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1em;
    margin: 1em 0;
    overflow-x: auto;
}

.tiptap code {
    background: var(--code-bg);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
    font-size: 0.9em;
}

.tiptap pre code {
    background: transparent;
    padding: 0;
}

.tiptap a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

.tiptap a:hover {
    border-bottom-color: var(--accent);
}

.tiptap hr {
    border: none;
    border-top: 2px solid var(--border-color);
    margin: 2em 0;
}

.tiptap img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 1em 0;
}

.code-view {
    display: none;
    width: 100%;
    min-height: 500px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
    font-size: 14px;
    line-height: 1.6;
    background: var(--code-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    resize: vertical;
    outline: none;
}

.code-view.active {
    display: block;
}

.status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--toolbar-bg);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-bar .status-left {
    display: flex;
    gap: 20px;
}

.status-bar .status-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

.export-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: none;
    min-width: 180px;
}

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

.export-menu button {
    width: 100%;
    text-align: left;
    margin-bottom: 4px;
    background: transparent;
    border: none;
    padding: 8px 12px;
}

.export-menu button:last-child {
    margin-bottom: 0;
}

.export-menu button:hover {
    background: var(--bg-secondary);
}

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: white;
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
}

@media (max-width: 768px) {
    .container {
        padding: 100px 15px 40px;
    }

    .toolbar {
        top: 60px;
        left: 10px;
        right: 10px;
        transform: none;
        flex-wrap: wrap;
    }

    .header-actions {
        flex-wrap: wrap;
    }

    .tiptap {
        font-size: 16px;
    }
}

/* Focus mode styles */
body.focus-mode .header,
body.focus-mode .status-bar {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

body.focus-mode .toolbar {
    opacity: 0;
    transition: opacity 0.3s ease;
}

body.focus-mode .toolbar:hover,
body.focus-mode .header:hover,
body.focus-mode .status-bar:hover {
    opacity: 1;
    pointer-events: all;
}

/* Focus mode trigger zone at top */
.focus-trigger {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    z-index: 98;
    pointer-events: none;
}

body.focus-mode .focus-trigger {
    pointer-events: all;
}

body.focus-mode .focus-trigger:hover ~ .header,
body.focus-mode .focus-trigger:hover ~ .toolbar,
body.focus-mode .focus-trigger:hover ~ .status-bar {
    opacity: 1;
    pointer-events: all;
}

/* Typing indicator */
body.typing .toolbar:not(:hover) {
    opacity: 0.2;
}

/* Print styles */
@media print {
    .header,
    .toolbar,
    .status-bar,
    .document-sidebar {
        display: none;
    }

    .container {
        padding: 0;
        max-width: 100%;
    }

    .tiptap {
        font-size: 12pt;
    }
}

/* Document Sidebar Styles */
.document-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 105;
    display: flex;
    flex-direction: column;
}

body.sidebar-open .document-sidebar {
    transform: translateX(0);
}

body.sidebar-open .header,
body.sidebar-open .container,
body.sidebar-open .toolbar,
body.sidebar-open .status-bar {
    margin-left: 280px;
}

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

.sidebar-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.btn-icon {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

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

.btn-menu {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-primary);
    padding: 4px 8px;
    margin-right: 12px;
    border-radius: 4px;
    transition: background 0.2s;
}

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

.sidebar-actions {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.btn-new-doc {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 10px;
    transition: opacity 0.2s;
}

.btn-new-doc:hover {
    opacity: 0.9;
}

.doc-search {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
}

.doc-search:focus {
    border-color: var(--accent);
}

.document-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.document-item {
    padding: 12px;
    background: var(--bg-primary);
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
}

.document-item:hover {
    background: var(--bg-secondary);
}

.document-item.active {
    background: var(--accent);
    color: white;
}

.document-item .doc-title {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.document-item .doc-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.document-item.active .doc-meta {
    color: rgba(255, 255, 255, 0.8);
}

.doc-actions {
    display: none;
    gap: 4px;
}

.document-item:hover .doc-actions {
    display: flex;
}

.doc-action-btn {
    background: transparent;
    border: none;
    padding: 4px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    border-radius: 3px;
}

.doc-action-btn:hover {
    background: var(--bg-secondary);
}

.document-item.active .doc-action-btn {
    color: rgba(255, 255, 255, 0.8);
}

.document-item.active .doc-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Hide sidebar in focus mode */
body.focus-mode .document-sidebar {
    transform: translateX(-100%);
}

body.focus-mode.sidebar-open .header,
body.focus-mode.sidebar-open .container,
body.focus-mode.sidebar-open .toolbar,
body.focus-mode.sidebar-open .status-bar {
    margin-left: 0;
}

/* Quill Editor Styling */
.ql-container {
    border: none !important;
    font-family: inherit;
    font-size: 18px;
    line-height: 1.7;
}

.ql-editor {
    min-height: 500px;
    padding: 0;
    color: var(--text-primary);
}

.ql-editor h1 {
    font-size: 2.5em;
    font-weight: 700;
    margin: 1em 0 0.5em;
    line-height: 1.2;
}

.ql-editor h2 {
    font-size: 2em;
    font-weight: 600;
    margin: 1em 0 0.5em;
    line-height: 1.3;
}

.ql-editor h3 {
    font-size: 1.5em;
    font-weight: 600;
    margin: 1em 0 0.5em;
}

.ql-editor p {
    margin: 0 0 1em;
}

.ql-editor blockquote {
    border-left: 4px solid var(--accent);
    padding-left: 1em;
    margin: 1em 0;
    color: var(--text-secondary);
    font-style: italic;
}

.ql-editor pre {
    background: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1em;
    margin: 1em 0;
}

.ql-editor code {
    background: var(--code-bg);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
}

.ql-snow .ql-editor pre.ql-syntax {
    background: var(--code-bg);
    color: var(--text-primary);
}

/* Hide Quill toolbar since we use our own */
.ql-toolbar {
    display: none !important;
}