:root {
    /* Gray Minimalist Palette */
    --gray-0: #fafafa;
    --gray-50: #f5f5f5;
    --gray-100: #e8e8e8;
    --gray-200: #d4d4d4;
    --gray-300: #a3a3a3;
    --gray-400: #737373;
    --gray-500: #525252;
    --gray-600: #404040;
    --gray-700: #2d2d2d;
    --gray-800: #1f1f1f;
    --gray-900: #171717;
    --gray-950: #0a0a0a;

    /* Semantic Colors */
    --bg-primary: var(--gray-50);
    --bg-secondary: var(--gray-0);
    --bg-tertiary: var(--gray-100);
    --bg-sidebar: var(--gray-0);
    --bg-editor: var(--gray-0);
    
    --text-primary: var(--gray-900);
    --text-secondary: var(--gray-600);
    --text-tertiary: var(--gray-400);
    --text-muted: var(--gray-300);
    
    --border-color: var(--gray-200);
    --border-subtle: var(--gray-100);
    --border-strong: var(--gray-300);
    
    --accent-primary: var(--gray-800);
    --accent-hover: var(--gray-700);
    --accent-success: #22c55e;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    --accent-info: #3b82f6;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.1);
    --shadow-inner: inset 0 1px 2px rgba(0, 0, 0, 0.03);
    
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    --font-serif: 'Noto Serif SC', 'Songti SC', 'SimSun', serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', Monaco, monospace;
    
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;
    
    --sidebar-width: 260px;
    --sidebar-collapsed: 0px;
    --header-height: 56px;
    --stats-height: 56px;
    --goal-height: 100px;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: var(--gray-900);
    --bg-secondary: var(--gray-800);
    --bg-tertiary: var(--gray-700);
    --bg-sidebar: var(--gray-800);
    --bg-editor: var(--gray-950);
    
    --text-primary: var(--gray-100);
    --text-secondary: var(--gray-400);
    --text-tertiary: var(--gray-500);
    --text-muted: var(--gray-600);
    
    --border-color: var(--gray-700);
    --border-subtle: var(--gray-800);
    --border-strong: var(--gray-600);
    
    --accent-primary: var(--gray-200);
    --accent-hover: var(--gray-100);
}

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

html, body {
    height: 100%;
    font-family: var(--font-sans);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    transition: width var(--transition-normal), transform var(--transition-normal);
    flex-shrink: 0;
}

.sidebar.collapsed {
    width: 0;
    overflow: hidden;
    border-right: none;
}

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

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

.logo-icon {
    font-size: 20px;
    color: var(--accent-primary);
}

.logo-text {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.3px;
    color: var(--text-primary);
}

.sidebar-toggle {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.sidebar-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.documents-section {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 8px 8px 12px;
    margin-bottom: 4px;
}

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

.document-list {
    list-style: none;
}

.document-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: 2px;
}

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

.document-item.active {
    background: var(--bg-tertiary);
    box-shadow: var(--shadow-sm);
}

.document-item.active .doc-name {
    color: var(--text-primary);
    font-weight: 500;
}

.doc-icon {
    width: 16px;
    height: 16px;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.doc-info {
    flex: 1;
    min-width: 0;
}

.doc-name {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.doc-actions {
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.document-item:hover .doc-actions {
    opacity: 1;
}

.btn-icon-small {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.btn-icon-small:hover {
    background: var(--border-color);
    color: var(--accent-danger);
}

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

.auto-save-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-tertiary);
}

.save-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-success);
}

.save-indicator.saving {
    background: var(--accent-warning);
    animation: pulse 1s infinite;
}

.save-indicator.unsaved {
    background: var(--accent-danger);
}

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

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 20px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.sidebar-show-btn {
    display: none;
}

.sidebar.collapsed ~ .main-content .sidebar-show-btn {
    display: flex;
}

.doc-title-wrapper {
    flex: 1;
    max-width: 400px;
}

.doc-title-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.doc-title-input:hover {
    border-color: var(--border-color);
    background: var(--bg-primary);
}

.doc-title-input:focus {
    outline: none;
    border-color: var(--border-strong);
    background: var(--bg-primary);
}

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

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

.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

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

.btn-icon.active {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
}

/* Dropdown */
.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
    z-index: 100;
    padding: 6px;
}

.dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.dropdown-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

/* Language Selector */
.language-selector {
    display: flex;
    gap: 2px;
    background: var(--bg-tertiary);
    padding: 3px;
    border-radius: var(--radius-md);
    margin-left: 8px;
}

.lang-btn {
    padding: 5px 10px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    font-family: inherit;
}

.lang-btn:hover {
    color: var(--text-secondary);
}

.lang-btn.active {
    color: var(--text-primary);
    background: var(--bg-secondary);
    box-shadow: var(--shadow-sm);
}

/* Goal Panel */
.goal-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition-normal), opacity var(--transition-normal);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    opacity: 0;
}

.goal-panel.open {
    max-height: var(--goal-height);
    opacity: 1;
}

.goal-content {
    display: flex;
    align-items: center;
    gap: 40px;
    padding: 20px 24px;
}

.goal-settings {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.goal-label {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.goal-input-group {
    display: flex;
    gap: 8px;
}

#goalInput {
    width: 90px;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    border-radius: var(--radius-md);
    font-family: inherit;
    text-align: center;
    transition: all var(--transition-fast);
}

#goalInput:focus {
    outline: none;
    border-color: var(--border-strong);
}

#goalType {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    border-radius: var(--radius-md);
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
}

#goalType:focus {
    outline: none;
    border-color: var(--border-strong);
}

.goal-progress-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 400px;
}

.progress-info {
    display: flex;
    align-items: baseline;
    gap: 4px;
    font-size: 14px;
    color: var(--text-secondary);
}

.progress-current {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
}

.progress-separator {
    color: var(--text-muted);
}

.progress-target {
    font-weight: 500;
    color: var(--text-secondary);
}

.progress-unit {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-left: 4px;
}

.progress-bar-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.progress-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-primary);
    border-radius: 3px;
    transition: width var(--transition-normal), background var(--transition-normal);
}

.progress-fill.complete {
    background: var(--accent-success);
}

.progress-text {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-tertiary);
    min-width: 40px;
    text-align: right;
}

.progress-text.complete {
    color: var(--accent-success);
}

.goal-stats {
    display: flex;
    gap: 20px;
    font-size: 12px;
    color: var(--text-muted);
}

.goal-chart-container {
    width: 120px;
    height: 60px;
}

/* Editor Wrapper */
.editor-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.editor-container {
    flex: 1;
    position: relative;
    background: var(--bg-editor);
}

.editor {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 40px 60px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 17px;
    line-height: 1.8;
    font-family: var(--font-serif);
    resize: none;
    outline: none;
    z-index: 2;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.editor::placeholder {
    color: var(--text-muted);
}

.editor::-webkit-scrollbar {
    width: 8px;
}

.editor::-webkit-scrollbar-track {
    background: transparent;
}

.editor::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.editor::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* Syntax Highlight Layer */
.editor-highlight-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 40px 60px;
    font-size: 17px;
    line-height: 1.8;
    font-family: var(--font-serif);
    color: var(--text-primary);
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Markdown Highlighting */
.md-heading {
    color: var(--text-primary);
    font-weight: 600;
}

.md-bold {
    font-weight: 600;
}

.md-italic {
    font-style: italic;
}

.md-code {
    color: var(--accent-info);
    background: var(--bg-tertiary);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.md-link {
    color: var(--accent-info);
    text-decoration: underline;
}

.md-list {
    color: var(--text-secondary);
}

/* Stats Bar */
.stats-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--stats-height);
    padding: 0 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.stat-group {
    display: flex;
    align-items: center;
    gap: 32px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}

.stat-item.clickable {
    cursor: pointer;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    background: transparent;
    border: none;
    font-family: inherit;
}

.stat-item.clickable:hover {
    background: var(--bg-tertiary);
}

.stat-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.5px;
}

.stat-label {
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    overflow: hidden;
    transform: scale(0.95) translateY(10px);
    transition: transform var(--transition-normal);
}

.modal.show .modal-content {
    transform: scale(1) translateY(0);
}

.modal-small {
    max-width: 360px;
}

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

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.modal-body {
    padding: 24px;
    max-height: calc(80vh - 140px);
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-subtle);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 20px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.stat-card-value {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.stat-card-label {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 500;
}

.chart-container {
    height: 200px;
    margin-top: 20px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    font-family: inherit;
}

.btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.btn-secondary {
    background: transparent;
}

.btn-danger {
    background: var(--accent-danger);
    border-color: var(--accent-danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    border-color: #dc2626;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 12px 24px;
    background: var(--gray-800);
    color: var(--gray-100);
    font-size: 13px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    z-index: 2000;
}

.toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Focus Mode */
body.focus-mode {
    --bg-primary: var(--gray-0);
    --bg-secondary: var(--gray-0);
}

body.focus-mode .sidebar,
body.focus-mode .header,
body.focus-mode .stats-bar,
body.focus-mode .goal-panel {
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-slow);
}

body.focus-mode .editor-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 100;
}

body.focus-mode .editor,
body.focus-mode .editor-highlight-layer {
    padding: 60px 15%;
    font-size: 19px;
    line-height: 2;
}

body.focus-mode:hover .header,
body.focus-mode:hover .stats-bar {
    opacity: 0.1;
    pointer-events: auto;
}

body.focus-mode:hover .header:hover,
body.focus-mode:hover .stats-bar:hover {
    opacity: 1;
}

/* Selection */
::selection {
    background: rgba(0, 0, 0, 0.12);
    color: inherit;
}

[data-theme="dark"] ::selection {
    background: rgba(255, 255, 255, 0.15);
}

/* Responsive */
@media (max-width: 1024px) {
    .editor,
    .editor-highlight-layer {
        padding: 30px 40px;
    }
    
    .goal-content {
        flex-direction: column;
        gap: 20px;
        align-items: flex-start;
    }
    
    .goal-chart-container {
        display: none;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 500;
        transform: translateX(-100%);
    }
    
    .sidebar.show {
        transform: translateX(0);
    }
    
    .sidebar.collapsed {
        width: var(--sidebar-width);
        transform: translateX(-100%);
    }
    
    .sidebar-show-btn {
        display: flex !important;
    }
    
    .editor,
    .editor-highlight-layer {
        padding: 20px 24px;
        font-size: 16px;
    }
    
    .goal-panel.open {
        max-height: 180px;
    }
    
    .goal-content {
        padding: 16px 20px;
    }
    
    .stats-bar {
        padding: 0 16px;
    }
    
    .stat-group:first-child {
        gap: 20px;
    }
    
    .stat-item:not(.clickable) .stat-value {
        font-size: 15px;
    }
    
    .header {
        padding: 0 16px;
    }
    
    .doc-title-input {
        font-size: 14px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .stat-card {
        padding: 16px;
    }
    
    .stat-card-value {
        font-size: 22px;
    }
}

@media (max-width: 480px) {
    .language-selector {
        display: none;
    }
    
    .goal-progress-section {
        width: 100%;
    }
    
    .goal-stats {
        flex-direction: column;
        gap: 4px;
    }
}
