/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    transition: all 0.3s ease;
}

/* CSS 变量 - 浅色主题 */
:root {
    --primary-color: #2196F3;
    --primary-hover: #1976D2;
    --secondary-color: #FFC107;
    --success-color: #4CAF50;
    --danger-color: #F44336;
    --warning-color: #FF9800;
    
    --bg-color: #ffffff;
    --surface-color: #f8f9fa;
    --border-color: #e0e0e0;
    --text-color: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    
    --sidebar-bg: #f5f5f5;
    --editor-bg: #ffffff;
    --toolbar-bg: #ffffff;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.15);
    
    --border-radius: 8px;
    --transition: all 0.3s ease;
}

/* 深色主题 */
[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --surface-color: #2d2d2d;
    --border-color: #404040;
    --text-color: #ffffff;
    --text-secondary: #cccccc;
    --text-muted: #999999;
    
    --sidebar-bg: #252525;
    --editor-bg: #1e1e1e;
    --toolbar-bg: #2d2d2d;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.4);
}

/* 应用容器 */
#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 工具栏 */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 100;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 同步指示器 */
.sync-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 12px;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.sync-indicator.syncing {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.sync-indicator.syncing .sync-icon {
    animation: spin 1s linear infinite;
}

.sync-indicator.error {
    color: #e74c3c;
    border-color: #e74c3c;
}

.sync-indicator.success {
    color: #27ae60;
    border-color: #27ae60;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.toolbar-center {
    flex: 1;
    text-align: center;
}

.app-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
}

/* 按钮样式 */
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--border-radius);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--surface-color);
    color: var(--text-color);
}

.btn-primary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--border-radius);
    background: var(--primary-color);
    color: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--surface-color);
    color: var(--text-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: var(--border-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* 主要内容区域 */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* 侧边栏 */
.sidebar {
    width: 300px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
}

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

.search-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 14px;
    transition: var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

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

.note-item {
    padding: 12px;
    margin-bottom: 4px;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    border-left: 3px solid transparent;
    position: relative;
}

.note-item:hover {
    background: var(--surface-color);
}

.note-item.active {
    background: var(--surface-color);
    border-left-color: var(--primary-color);
}

.note-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-preview {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.note-date {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* 删除笔记按钮样式 */
.delete-note-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s ease;
    z-index: 2;
}

.note-item:hover .delete-note-btn {
    opacity: 1;
    transform: scale(1);
}

.delete-note-btn:hover {
    background: var(--danger-color);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(244, 67, 54, 0.3);
}

.delete-note-btn:active {
    transform: scale(0.95);
}

.delete-note-btn svg {
    width: 14px;
    height: 14px;
    transition: all 0.2s ease;
}

.delete-note-btn:hover svg {
    transform: scale(1.1);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    text-align: center;
    color: var(--text-muted);
}

.empty-state svg {
    margin-bottom: 16px;
}

.empty-state p {
    margin-bottom: 8px;
    font-size: 14px;
}

/* 编辑器区域 */
.editor-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--editor-bg);
}

.editor-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    flex-direction: column;
    gap: 12px;
}

@media (min-width: 768px) {
    .editor-header {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }
}

/* Markdown 工具栏 */
.markdown-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    flex-wrap: wrap;
}

.markdown-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 12px;
    font-weight: 600;
}

.markdown-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-1px);
}

.markdown-btn:active {
    transform: translateY(0);
}

.markdown-btn.active {
    background: var(--primary-color);
    color: white;
}

.markdown-text {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

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

.note-title-input {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
    padding: 8px 0;
    outline: none;
    margin-bottom: 8px;
}

@media (min-width: 768px) {
    .note-title-input {
        flex: 1;
        width: auto;
        margin-bottom: 0;
    }
}

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

.editor-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.editor-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.editor-wrapper {
    flex: 1;
    display: flex;
    position: relative;
}

.editor-textarea {
    flex: 1;
    padding: 20px;
    border: none;
    background: transparent;
    color: var(--text-color);
    font-size: 16px;
    line-height: 1.6;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    resize: none;
    outline: none;
    overflow-y: auto;
}

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

.preview-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--bg-color);
    border-left: 1px solid var(--border-color);
}

/* Markdown 预览样式 */
.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
    margin: 20px 0 10px 0;
    color: var(--text-color);
    font-weight: 600;
}

.preview-content h1 { font-size: 28px; }
.preview-content h2 { font-size: 24px; }
.preview-content h3 { font-size: 20px; }
.preview-content h4 { font-size: 18px; }
.preview-content h5 { font-size: 16px; }
.preview-content h6 { font-size: 14px; }

.preview-content p {
    margin: 10px 0;
    line-height: 1.6;
}

.preview-content code {
    background: var(--surface-color);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
}

.preview-content pre {
    background: var(--surface-color);
    padding: 16px;
    border-radius: var(--border-radius);
    overflow-x: auto;
    margin: 16px 0;
}

.preview-content pre code {
    background: none;
    padding: 0;
}

.preview-content blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 16px;
    margin: 16px 0;
    color: var(--text-secondary);
    font-style: italic;
}

.preview-content ul,
.preview-content ol {
    margin: 10px 0;
    padding-left: 20px;
}

.preview-content li {
    margin: 4px 0;
}

.preview-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
}

.preview-content th,
.preview-content td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

.preview-content th {
    background: var(--surface-color);
    font-weight: 600;
}

/* 设置面板 */
.settings-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    background: var(--bg-color);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    transition: var(--transition);
    z-index: 1000;
}

.settings-panel.open {
    right: 0;
}

.settings-content {
    height: 100%;
    display: flex;
    flex-direction: column;
}

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

.settings-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
}

.settings-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.setting-group {
    margin-bottom: 24px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
}

.setting-group select,
.setting-group input[type="text"],
.setting-group input[type="email"],
.setting-group input[type="password"],
.setting-group input[type="url"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.setting-group select:focus,
.setting-group input[type="text"]:focus,
.setting-group input[type="email"]:focus,
.setting-group input[type="password"]:focus,
.setting-group input[type="url"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.setting-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

/* AI 设置样式 */
.ai-settings {
    background: rgba(33, 150, 243, 0.05);
    border: 1px solid rgba(33, 150, 243, 0.1);
    border-radius: 8px;
    padding: 15px;
    margin-top: 10px;
}

.ai-settings label {
    color: var(--primary-color);
    font-weight: 600;
}

/* AI 按钮样式 */
.btn-icon:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-icon.ai-button {
    background: linear-gradient(135deg, var(--primary-color), #667eea);
    color: white;
    border: none;
}

.btn-icon.ai-button:hover:not(:disabled) {
    background: linear-gradient(135deg, #667eea, var(--primary-color));
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

/* 加载指示器 */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading p {
    color: white;
    font-size: 16px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -300px;
        top: 60px;
        height: calc(100vh - 60px);
        z-index: 999;
        transition: var(--transition);
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .toolbar-center {
        display: none;
    }
    
    .settings-panel {
        width: 100%;
        right: -100%;
    }
    
    .editor-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .editor-actions {
        justify-content: center;
    }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface-color);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* 动画效果 */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.slide-in {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { transform: translateX(-20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* 字体大小变体 */
.font-small {
    --editor-font-size: 14px;
}

.font-medium {
    --editor-font-size: 16px;
}

.font-large {
    --editor-font-size: 18px;
}

.editor-textarea {
    font-size: var(--editor-font-size, 16px);
}

/* 全屏模式 */
.app-container.fullscreen {
    .editor-section {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        z-index: 9999;
        background: var(--bg-color);
    }
    
    .sidebar,
    .toolbar {
        display: none;
    }
}

/* AI 聊天面板样式 */
.ai-chat-panel {
    position: fixed;
    bottom: -100%;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    height: 70vh;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    transition: bottom 0.3s ease;
    z-index: 1001;
    display: flex;
    flex-direction: column;
}

.ai-chat-panel.open {
    bottom: 0;
}

.ai-chat-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.ai-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 12px 12px 0 0;
}

.ai-chat-header h3 {
    margin: 0;
    color: var(--text-color);
    font-size: 1.1rem;
    font-weight: 600;
}

.ai-chat-controls {
    display: flex;
    gap: 8px;
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.ai-message,
.user-message {
    display: flex;
    gap: 12px;
    max-width: 85%;
}

.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ai-avatar,
.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-avatar {
    background: linear-gradient(135deg, var(--primary-color), #667eea);
    color: white;
}

.user-avatar {
    background: var(--bg-secondary);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.message-content {
    background: var(--bg-secondary);
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    flex: 1;
}

.user-message .message-content {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.message-content p {
    margin: 0;
    line-height: 1.5;
    font-size: 0.9rem;
}

.ai-chat-input-area {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.ai-chat-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 15px;
}

#ai-chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 0.9rem;
    resize: none;
    min-height: 40px;
    max-height: 100px;
    font-family: inherit;
}

#ai-chat-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

#ai-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
}

#ai-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-chat-suggestions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.suggestion-btn {
    padding: 6px 12px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    color: var(--text-color);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.suggestion-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* AI 加载动画 */
.ai-typing {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
}

.ai-typing span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.ai-typing span:nth-child(1) {
    animation-delay: -0.32s;
}

.ai-typing span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 消息提示样式 */
.message-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-left: 4px solid var(--primary-color);
    z-index: 10000;
    transform: translateX(100%);
    opacity: 0;
    transition: all 0.3s ease;
    max-width: 300px;
    word-wrap: break-word;
}

.message-toast.show {
    transform: translateX(0);
    opacity: 1;
}

.message-toast.message-error {
    border-left-color: #e74c3c;
    background: #fdf2f2;
    color: #c53030;
}

.message-toast.message-success {
    border-left-color: #27ae60;
    background: #f0fff4;
    color: #2d7d32;
}

.message-toast.message-warning {
    border-left-color: #f39c12;
    background: #fffbf0;
    color: #b7791f;
}