/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Light theme variables */
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #495057;
    --border-color: #dee2e6;
    --accent-color: #4361ee;
    --accent-hover: #3a56d4;
    --success-color: #2ecc71;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
    --border-radius: 10px;
    --transition: all 0.3s ease;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] {
    /* Dark theme variables */
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --bg-tertiary: #2d2d2d;
    --text-primary: #f8f9fa;
    --text-secondary: #adb5bd;
    --border-color: #495057;
    --accent-color: #6c8eff;
    --accent-hover: #5a7eff;
    --glass-bg: rgba(30, 30, 30, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: var(--transition);
    overflow-x: hidden;
    height: 100vh;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Header Styles */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background-color: var(--bg-secondary);
    box-shadow: var(--shadow);
    z-index: 100;
    backdrop-filter: blur(10px);
    background: var(--glass-bg);
    border-bottom: 1px solid var(--glass-border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo i {
    font-size: 24px;
    color: var(--accent-color);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-color);
}

.toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.toolbar-group {
    display: flex;
    gap: 2px;
    padding: 0 8px;
    border-right: 1px solid var(--border-color);
}

.toolbar-group:last-child {
    border-right: none;
}

.toolbar-btn {
    background: var(--bg-tertiary);
    border: none;
    border-radius: 6px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
    transition: var(--transition);
    font-size: 16px;
}

.toolbar-btn:hover {
    background: var(--accent-color);
    color: white;
    transform: translateY(-2px);
}

.toolbar-btn:active {
    transform: translateY(0);
}

.toolbar-btn.active {
    background: var(--accent-color);
    color: white;
    box-shadow: 0 2px 8px rgba(67, 97, 238, 0.3);
}

.header-controls {
    display: flex;
    align-items: center;
}

.theme-toggle {
    background: var(--bg-tertiary);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
    transition: var(--transition);
    font-size: 18px;
}

.theme-toggle:hover {
    background: var(--accent-color);
    color: white;
    transform: rotate(30deg);
}

/* File Bar Styles */
.file-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.file-controls {
    display: flex;
    gap: 10px;
}

.file-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-primary);
    transition: var(--transition);
    font-size: 14px;
    font-weight: 500;
}

.file-btn:hover {
    background: var(--accent-color);
    color: white;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: var(--bg-secondary);
    min-width: 180px;
    box-shadow: var(--shadow-lg);
    border-radius: 8px;
    z-index: 100;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.dropdown-content a {
    color: var(--text-primary);
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    transition: var(--transition);
}

.dropdown-content a:hover {
    background-color: var(--bg-tertiary);
}

.dropdown:hover .dropdown-content {
    display: block;
}

.document-title {
    display: flex;
    align-items: center;
    gap: 15px;
}

#doc-title {
    background: transparent;
    border: 1px solid var(--border-color);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    min-width: 200px;
}

#doc-title:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.auto-save {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Main Container Styles */
.main-container {
    flex: 1;
    padding: 20px;
    overflow: hidden;
}

.split-pane {
    display: flex;
    height: 100%;
    position: relative;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    background: var(--bg-secondary);
}

.editor-pane, .preview-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 200px;
    overflow: hidden;
}

.pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.pane-header h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
}

.pane-stats {
    display: flex;
    gap: 15px;
    font-size: 13px;
    color: var(--text-secondary);
}

.refresh-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
    transition: var(--transition);
}

.refresh-btn:hover {
    background: var(--accent-color);
    color: white;
    transform: rotate(90deg);
}

/* Editor Container */
.editor-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.editor-container pre,
.editor-container textarea {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 20px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 15px;
    line-height: 1.6;
    border: none;
    resize: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.editor-container pre {
    pointer-events: none;
    background: transparent;
    color: transparent;
    z-index: 1;
}

.editor-container textarea {
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: var(--transition);
    z-index: 2;
    caret-color: var(--text-primary);
}

.editor-container textarea:focus {
    outline: none;
}

/* Syntax Highlighting */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
    color: #6a737d;
}

.token.punctuation {
    color: #586069;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
    color: #005cc5;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
    color: #032f62;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
    color: #d73a49;
}

.token.atrule,
.token.attr-value,
.token.keyword {
    color: #d73a49;
}

.token.function,
.token.class-name {
    color: #6f42c1;
}

.token.regex,
.token.important,
.token.variable {
    color: #e36209;
}

/* ============================================
   TIPAP EDITOR STYLES
   ============================================ */

/* TipTap Editor Container */
.tiptap-editor {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    background: var(--bg-secondary);
    outline: none;
    min-height: 100%;
}

.tiptap-editor:focus {
    outline: none;
}

/* Editor typography */
.tiptap-editor h1,
.tiptap-editor h2,
.tiptap-editor h3,
.tiptap-editor h4,
.tiptap-editor h5,
.tiptap-editor h6 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

.tiptap-editor h1 { font-size: 2em; }
.tiptap-editor h2 { font-size: 1.5em; }
.tiptap-editor h3 { font-size: 1.25em; }
.tiptap-editor h4 { font-size: 1.1em; }
.tiptap-editor h5 { font-size: 1em; }
.tiptap-editor h6 { font-size: 0.9em; }

.tiptap-editor p {
    margin-bottom: 1em;
    line-height: 1.6;
}

.tiptap-editor ul,
.tiptap-editor ol {
    padding-left: 1.5em;
    margin-bottom: 1em;
}

.tiptap-editor li {
    margin-bottom: 0.25em;
}

.tiptap-editor blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 20px;
    margin: 1em 0;
    color: var(--text-secondary);
    font-style: italic;
}

.tiptap-editor pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1em 0;
}

.tiptap-editor code {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

.tiptap-editor pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    border-radius: 0;
}

.tiptap-editor a {
    color: var(--accent-color);
    text-decoration: underline;
    transition: var(--transition);
}

.tiptap-editor a:hover {
    color: var(--accent-hover);
}

.tiptap-editor img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1em 0;
}

.tiptap-editor hr {
    border: none;
    border-top: 2px solid var(--border-color);
    margin: 2em 0;
    transition: border-color var(--transition);
}

.tiptap-editor mark {
    background: #ffeb3b;
    color: inherit;
    padding: 2px 4px;
    border-radius: 2px;
}

.tiptap-editor strong {
    font-weight: 600;
}

.tiptap-editor em {
    font-style: italic;
}

.tiptap-editor s {
    text-decoration: line-through;
}

.tiptap-editor u {
    text-decoration: underline;
}

/* ============================================
   TABLE STYLES
   ============================================ */

.tiptap-editor table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
    overflow: hidden;
    table-layout: fixed;
}

.tiptap-editor th,
.tiptap-editor td {
    border: 1px solid var(--border-color);
    padding: 12px;
    text-align: left;
    vertical-align: top;
    min-width: 100px;
}

.tiptap-editor th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-primary);
}

.tiptap-editor td {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.tiptap-editor tr:hover td {
    background: var(--bg-tertiary);
}

.tiptap-editor tr:first-child th {
    border-top-left-radius: 8px;
}

.tiptap-editor tr:first-child td {
    border-top-right-radius: 8px;
}

.tiptap-editor tr:last-child td {
    border-bottom-left-radius: 8px;
}

.tiptap-editor tr:last-child th {
    border-bottom-right-radius: 8px;
}

/* ============================================
   TASK LIST STYLES
   ============================================ */

.tiptap-editor ul[data-type="taskList"] {
    list-style: none;
    padding-left: 0;
    margin: 1em 0;
}

.tiptap-editor ul[data-type="taskList"] li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 0.5em;
}

.tiptap-editor ul[data-type="taskList"] li input[type="checkbox"] {
    margin-top: 4px;
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent-color);
}

.tiptap-editor ul[data-type="taskList"] li[data-checked="true"] > div {
    text-decoration: line-through;
    opacity: 0.7;
}

/* ============================================
   CODE BLOCK STYLES
   ============================================ */

.tiptap-editor pre[data-type="codeBlock"] {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1em 0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.5;
}

.tiptap-editor pre[data-type="codeBlock"] code {
    background: transparent;
    color: inherit;
    padding: 0;
    font-family: inherit;
}

/* ============================================
   SELECTION STYLES
   ============================================ */

.tiptap-editor ::selection {
    background: var(--accent-color);
    color: white;
}

.tiptap-editor ::-moz-selection {
    background: var(--accent-color);
    color: white;
}

/* ============================================
   PLACEHOLDER STYLES
   ============================================ */

.tiptap-editor p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    float: left;
    color: var(--text-secondary);
    pointer-events: none;
    height: 0;
}

/* ============================================
   PREVIEW CONTENT STYLES
   ============================================ */

.preview-content {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    background: var(--bg-secondary);
}

.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

.preview-content h1 { font-size: 2em; }
.preview-content h2 { font-size: 1.5em; }
.preview-content h3 { font-size: 1.25em; }
.preview-content h4 { font-size: 1.1em; }
.preview-content h5 { font-size: 1em; }
.preview-content h6 { font-size: 0.9em; }

.preview-content p {
    margin-bottom: 1em;
    line-height: 1.6;
}

.preview-content ul,
.preview-content ol {
    padding-left: 1.5em;
    margin-bottom: 1em;
}

.preview-content li {
    margin-bottom: 0.25em;
}

.preview-content blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 20px;
    margin: 1em 0;
    color: var(--text-secondary);
    font-style: italic;
}

.preview-content pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1em 0;
}

.preview-content code {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

.preview-content pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

.preview-content a {
    color: var(--accent-color);
    text-decoration: underline;
}

.preview-content a:hover {
    color: var(--accent-hover);
}

.preview-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1em 0;
}

.preview-content hr {
    border: none;
    border-top: 2px solid var(--border-color);
    margin: 2em 0;
}

.preview-content mark {
    background: #ffeb3b;
    color: inherit;
    padding: 2px 4px;
    border-radius: 2px;
}

.preview-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

.preview-content th,
.preview-content td {
    border: 1px solid var(--border-color);
    padding: 12px;
    text-align: left;
}

.preview-content th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.preview-content tr:hover {
    background: var(--bg-tertiary);
}

/* ============================================
   DIVIDER STYLES
   ============================================ */

.divider {
    width: 10px;
    background: var(--bg-tertiary);
    cursor: col-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    z-index: 10;
    user-select: none;
}

.divider:hover {
    background: var(--accent-color);
}

.divider:hover .divider-handle {
    color: white;
}

.divider-handle {
    color: var(--text-secondary);
    transition: color 0.2s ease;
    pointer-events: none;
}

.divider:active {
    background: var(--accent-color);
}

/* ============================================
   TOAST NOTIFICATION STYLES
   ============================================ */

#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
    pointer-events: auto;
    border-left: 4px solid var(--accent-color);
}

.toast.success {
    border-left-color: var(--success-color);
}

.toast.error {
    border-left-color: var(--danger-color);
}

.toast.warning {
    border-left-color: var(--warning-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ============================================
   FOCUS STYLES
   ============================================ */

:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

button:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

input:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* ============================================
   SELECTION STYLES
   ============================================ */

::selection {
    background: var(--accent-color);
    color: white;
}

::-moz-selection {
    background: var(--accent-color);
    color: white;
}

/* ============================================
   RESPONSIVE STYLES
   ============================================ */

@media (max-width: 1024px) {
    .toolbar {
        gap: 4px;
    }
    
    .toolbar-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    .toolbar-group {
        padding: 0 4px;
    }
    
    .file-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
}

@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 15px;
        padding: 10px 15px;
    }
    
    .toolbar {
        width: 100%;
        overflow-x: auto;
        justify-content: flex-start;
        padding-bottom: 5px;
    }
    
    .toolbar-group {
        flex-shrink: 0;
    }
    
    .header-controls {
        position: absolute;
        top: 15px;
        right: 15px;
    }
    
    .main-container {
        padding: 10px;
    }
    
    .split-pane {
        flex-direction: column;
    }
    
    .editor-pane,
    .preview-pane {
        min-height: 300px;
        max-height: 50vh;
    }
    
    .divider {
        width: 100%;
        height: 10px;
        cursor: row-resize;
    }
    
    .divider-handle {
        transform: rotate(90deg);
    }
    
    .pane-header {
        padding: 10px 15px;
    }
    
    .pane-header h3 {
        font-size: 14px;
    }
    
    .pane-stats {
        font-size: 12px;
    }
    
    .file-bar {
        flex-direction: column;
        gap: 10px;
        padding: 10px 15px;
    }
    
    .file-controls {
        width: 100%;
        justify-content: center;
    }
    
    .document-title {
        width: 100%;
        justify-content: center;
    }
    
    #doc-title {
        min-width: auto;
        flex: 1;
        max-width: 200px;
    }
}

@media (max-width: 480px) {
    .logo h1 {
        font-size: 1.2rem;
    }
    
    .toolbar-btn {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }
    
    .file-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .file-btn i {
        display: none;
    }
    
    .theme-toggle {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
    
    .dropdown-content {
        min-width: 150px;
    }
    
    .dropdown-content a {
        padding: 10px 12px;
        font-size: 13px;
    }
}

/* ============================================
   FULLSCREEN STYLES
   ============================================ */

:fullscreen .app-header {
    border-radius: 0;
}

:fullscreen .main-container {
    padding: 0;
}

:fullscreen .split-pane {
    border-radius: 0;
    box-shadow: none;
}

:-webkit-full-screen .app-header {
    border-radius: 0;
}

:-webkit-full-screen .main-container {
    padding: 0;
}

:-webkit-full-screen .split-pane {
    border-radius: 0;
    box-shadow: none;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .app-header,
    .file-bar,
    .divider,
    .pane-header {
        display: none !important;
    }
    
    .main-container {
        padding: 0;
    }
    
    .split-pane {
        display: block;
        box-shadow: none;
    }
    
    .editor-pane {
        display: none;
    }
    
    .preview-pane {
        display: block;
        padding: 20px;
    }
    
    .preview-content {
        overflow: visible;
    }
}

/* ============================================
   SCROLLBAR STYLES
   ============================================ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-tertiary);
}
