/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-sidebar: #f8fafc;
    --bg-main: #ffffff;
    --bg-editor: #ffffff;
    --border: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
    font-family: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    overflow: hidden;
}

/* Layout */
.app {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

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

.logo {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--primary);
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    background: transparent;
    color: var(--text-primary);
}

.btn:hover {
    background: var(--border);
}

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

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

.btn-new {
    width: 100%;
    padding: 10px;
}

.btn-icon {
    padding: 8px;
    font-size: 16px;
}

.search-box {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.search-box input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
}

.search-box input:focus {
    border-color: var(--primary);
}

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

.note-item {
    padding: 12px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.2s;
}

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

.note-item.active {
    background: var(--primary);
    color: white;
}

.note-item-title {
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.note-item-preview {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.note-item.active .note-item-preview {
    color: rgba(255,255,255,0.7);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
}

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

.note-title {
    flex: 1;
    font-size: 20px;
    font-weight: 600;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
}

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

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

.last-saved {
    font-size: 12px;
    color: var(--text-muted);
    margin-right: 8px;
}

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

.note-content {
    flex: 1;
    width: 50%;
    padding: 24px;
    border: none;
    outline: none;
    font-size: 16px;
    line-height: 1.8;
    resize: none;
    font-family: inherit;
    background: var(--bg-editor);
}

.preview-pane {
    flex: 1;
    width: 50%;
    padding: 24px;
    border-left: 1px solid var(--border);
    overflow-y: auto;
    line-height: 1.8;
    display: none;
}

.preview-pane.active {
    display: block;
}

/* AI Panel */
.ai-panel {
    width: 360px;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: #fafafa;
    display: none;
}

.ai-panel.active {
    display: flex;
}

.ai-header {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.ai-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.model-select {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
}

.ai-content {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.7;
}

.ai-hint {
    color: var(--text-muted);
    text-align: center;
    padding: 40px 20px;
}

.ai-input-area {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-prompt {
    width: 100%;
    height: 60px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    resize: none;
    outline: none;
    font-family: inherit;
}

.ai-prompt:focus {
    border-color: var(--primary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    display: none;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 24px;
    border-radius: 12px;
    width: 480px;
    max-width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h3 {
    margin-bottom: 8px;
}

.modal-content > p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}

.api-keys {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
}

.api-key-item label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.api-key-item input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
}

.api-key-item input:focus {
    border-color: var(--primary);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* AI Message Styles */
.ai-message {
    margin-bottom: 16px;
    padding: 12px;
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

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

.ai-message-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 6px;
    color: var(--text-muted);
}

.ai-message.user .ai-message-label {
    color: rgba(255,255,255,0.7);
}

.ai-message-content {
    font-size: 14px;
}

.ai-message-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.ai-message-content code {
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 12px;
}

.ai-message-content p {
    margin-bottom: 8px;
}

.ai-message-content p:last-child {
    margin-bottom: 0;
}

.ai-message-content ul, .ai-message-content ol {
    margin-left: 20px;
    margin-bottom: 8px;
}

.ai-message-content h1, 
.ai-message-content h2, 
.ai-message-content h3 {
    margin: 16px 0 8px;
}

/* Loading */
.ai-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 20px;
}

.ai-loading span {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: bounce 1.4s ease-in-out infinite both;
}

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

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        z-index: 100;
        transition: left 0.3s;
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .ai-panel {
        position: fixed;
        right: -360px;
        top: 0;
        bottom: 0;
        z-index: 100;
        transition: right 0.3s;
    }
    
    .ai-panel.active {
        right: 0;
    }
    
    .note-content {
        width: 100%;
    }
    
    .preview-pane {
        display: none !important;
    }
}
