:root {
    --background: 0 0% 100%;
    --foreground: 224 71.4% 4.1%;
    --card: 0 0% 100%;
    --card-foreground: 224 71.4% 4.1%;
    --popover: 0 0% 100%;
    --popover-foreground: 224 71.4% 4.1%;
    --primary: 262.1 83.3% 57.8%;
    --primary-foreground: 210 20% 98%;
    --secondary: 210 40% 96.1%;
    --secondary-foreground: 222.2 47.4% 11.2%;
    --muted: 210 40% 96.1%;
    --muted-foreground: 215.4 16.3% 46.9%;
    --accent: 210 40% 96.1%;
    --accent-foreground: 222.2 47.4% 11.2%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 210 20% 98%;
    --border: 214.3 31.8% 91.4%;
    --input: 214.3 31.8% 91.4%;
    --ring: 262.1 83.3% 57.8%;
    --radius: 0.75rem;
    --sidebar-width: 260px;
}

[data-theme="dark"] {
    --background: 224 71.4% 4.1%;
    --foreground: 210 20% 98%;
    --card: 224 71.4% 4.1%;
    --card-foreground: 210 20% 98%;
    --popover: 224 71.4% 4.1%;
    --popover-foreground: 210 20% 98%;
    --primary: 263.4 70% 50.4%;
    --primary-foreground: 210 20% 98%;
    --secondary: 217.2 32.6% 17.5%;
    --secondary-foreground: 210 20% 98%;
    --muted: 217.2 32.6% 17.5%;
    --muted-foreground: 215 20.2% 65.1%;
    --accent: 217.2 32.6% 17.5%;
    --accent-foreground: 210 20% 98%;
    --destructive: 0 62.8% 30.6%;
    --destructive-foreground: 210 20% 98%;
    --border: 217.2 32.6% 17.5%;
    --input: 217.2 32.6% 17.5%;
    --ring: 263.4 70% 50.4%;
}

[data-theme="sepia"] {
    --background: 35 30% 88%;
    --foreground: 25 20% 20%;
    --card: 35 30% 85%;
    --card-foreground: 25 20% 20%;
    --primary: 25 50% 45%;
    --primary-foreground: 35 30% 95%;
    --muted: 35 20% 82%;
    --muted-foreground: 25 10% 40%;
    --border: 35 20% 78%;
    --accent: 35 20% 80%;
    --accent-foreground: 25 20% 20%;
}

[data-theme="solarized"] {
    --background: 44 40% 90%;
    --foreground: 192 10% 30%;
    --card: 44 40% 85%;
    --card-foreground: 192 10% 30%;
    --primary: 175 60% 35%;
    --primary-foreground: 44 40% 95%;
    --muted: 44 30% 82%;
    --muted-foreground: 192 10% 45%;
    --border: 44 30% 78%;
    --accent: 175 60% 85%;
    --accent-foreground: 192 10% 30%;
}

[data-theme="ocean"] {
    --background: 220 40% 10%;
    --foreground: 210 20% 90%;
    --card: 220 40% 12%;
    --card-foreground: 210 20% 90%;
    --primary: 199 89% 48%;
    --primary-foreground: 210 20% 98%;
    --muted: 220 30% 18%;
    --muted-foreground: 215 20% 60%;
    --border: 220 30% 22%;
    --accent: 199 89% 48%;
    --accent-foreground: 210 20% 98%;
}

body {
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    font-family: 'Inter Variable', 'Inter', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 16px;
    overflow: hidden;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.sidebar {
    width: var(--sidebar-width);
    background-color: hsl(var(--background));
    border-right: 1px solid hsl(var(--border));
    display: flex;
    flex-direction: column;
    user-select: none;
    transition: all 0.3s ease;
    z-index: 100;
}

/* Mobile Sidebar Indentation Implementation */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: 10px 0 30px rgba(0,0,0,0.1);
    }
    .sidebar.open {
        transform: translateX(0);
    }
}

.tree-node {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    border-radius: var(--radius);
    margin: 2px 12px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: hsl(var(--muted-foreground));
}

.tree-node:hover {
    background-color: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
    transform: translateX(4px);
}

.tree-node.active {
    background-color: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    font-weight: 600;
    box-shadow: 0 4px 14px -3px hsla(var(--primary), 0.5);
    transform: scale(1.02);
    z-index: 10;
}

.tree-node i {
    transition: transform 0.2s ease;
}
.tree-node:hover i {
    transform: scale(1.2);
}
.tree-node.drag-over {
    background-color: hsl(var(--primary) / 0.1);
    box-shadow: inset 0 0 0 2px hsl(var(--primary));
}

#filenameDisplay {
    width: auto;
    max-width: 200px;
}

/* Split Screen Layout */
.workspace-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    background-color: hsl(var(--background));
}

#editor {
    flex: 1;
    padding: 2rem 3rem;
    border: none;
    resize: none;
    background-color: transparent;
    color: hsl(var(--foreground));
    font-family: 'JetBrains Mono', 'Fira Code', 'Menlo', 'Monaco', 'Consolas', monospace;
    font-size: 16px;
    line-height: 1.8;
    outline: none;
    border-right: 1px solid hsl(var(--border));
}

#preview-pane {
    flex: 1;
    padding: 2rem 3rem;
    overflow-y: auto;
    background-color: hsl(var(--muted)/0.3);
}

/* Resizer handle */
.resizer {
    width: 4px;
    cursor: col-resize;
    background-color: hsl(var(--border));
    transition: background-color 0.2s;
    z-index: 50;
}
.resizer:hover, .resizer.dragging {
    background-color: hsl(var(--primary));
    width: 6px;
}

/* Full Screen Modes */
.workspace-container.mode-editor #preview-pane,
.workspace-container.mode-editor .resizer {
    display: none !important;
}
.workspace-container.mode-preview #editor,
.workspace-container.mode-preview .resizer {
    display: none !important;
}
.workspace-container.mode-editor #editor {
    flex: 1 0 100% !important;
}
.workspace-container.mode-preview #preview-pane {
    flex: 1 0 100% !important;
}

.preview-content {
    background-color: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
    max-width: 800px;
    margin: 0 auto;
}

/* Markdown Body Overrides for Chinese & Size */
.markdown-body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑" !important;
    font-size: 16px !important;
    line-height: 1.75 !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 {
    font-family: inherit;
    font-weight: 600;
}

/* Shadcn Dialog Styles */
.modal-container {
    position: fixed;
    inset: 0;
    background-color: hsl(var(--foreground) / 0.15);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: none; /* Changed from flex to none to prevent auto-show */
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.15s ease-out;
    font-size: 15px;
}

.modal-content {
    background-color: hsl(var(--background));
    width: 100%;
    max-width: 32rem;
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border));
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    animation: zoomIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid hsl(var(--border));
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    position: relative;
    font-size: 16px;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    max-height: 70vh;
    font-size: 14px;
    line-height: 1.6;
}

.modal-footer {
    padding: 1rem 1.5rem;
    background-color: hsl(var(--muted)/0.3);
    border-top: 1px solid hsl(var(--border));
    display: flex;
    justify-content: center;
}

.close-button {
    position: absolute;
    right: 1.5rem;
    top: 1.5rem;
    opacity: 0.5;
    transition: opacity 0.2s;
}
.close-button:hover { opacity: 1; }

/* Context Menu */
.context-menu {
    position: fixed;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    z-index: 5000;
    display: none;
    flex-direction: column;
    padding: 4px;
    min-width: 160px;
    backdrop-filter: blur(8px);
    animation: fadeIn 0.1s ease-out;
}

.context-item {
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    border-radius: calc(var(--radius) - 4px);
    display: flex;
    align-items: center;
    gap: 8px;
    color: hsl(var(--foreground));
    transition: all 0.15s;
}

.context-item:hover {
    background-color: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.context-item i {
    font-size: 14px;
    width: 16px;
    text-align: center;
    opacity: 0.7;
}

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

@keyframes zoomIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@media (max-width: 1024px) {
    #preview-pane { display: none; }
    .workspace-container.mode-split #preview-pane { display: none; }
    .workspace-container.mode-preview #preview-pane { display: block; flex: 1 0 100% !important; }
}

/* Mobile Edit/Preview Buttons */
.mobile-toggle {
    display: none;
}
@media (max-width: 768px) {
    .mobile-toggle {
        display: flex;
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 1000;
        gap: 8px;
        background: hsl(var(--background));
        padding: 6px;
        border-radius: 50px;
        border: 1px solid hsl(var(--border));
        box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1);
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: hsl(var(--border)); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground)); }

/* Toasts */
.toast-item {
    pointer-events: auto;
    animation: toast-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 240px;
}

.toast-item.exiting {
    animation: toast-out 0.2s ease forwards;
}

@keyframes toast-in {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes toast-out {
    to { transform: translateX(100%); opacity: 0; }
}
