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

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --background: #ffffff;
    --surface: #f8fafc;
    --surface-hover: #f1f5f9;
    --border: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;
    --sidebar-width: 280px;
    --header-height: 60px;
    --banner-height: 48px;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --warning: #f59e0b;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
}

/* Floating Sidebar Toggle */
.floating-sidebar-toggle {
    position: fixed;
    top: 80px;
    left: 20px;
    z-index: 1001;
    background: var(--primary-color);
    color: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.floating-sidebar-toggle:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

/* GitHub Banner */
.github-banner {
    background: linear-gradient(135deg, #24292e 0%, #1a1e22 100%);
    color: white;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--shadow-sm);
}

.github-banner.connected {
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
}

.banner-content {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 0.875rem;
}

.banner-content i {
    font-size: 1.25rem;
}

.btn-banner {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-banner:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* App Container */
.app-container {
    display: flex;
    height: calc(100vh - var(--banner-height));
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-width)));
}

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

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-actions {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sync-status {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--border);
}

.sync-status i {
    font-size: 0.5rem;
    color: var(--success);
}

.sync-status.syncing i {
    color: var(--warning);
    animation: pulse 1.5s ease-in-out infinite;
}

.sync-status.error i {
    color: var(--danger);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    justify-content: center;
}

.search-box {
    padding: 0 16px 16px;
    position: relative;
}

.search-box i {
    position: absolute;
    left: 28px;
    top: 12px;
    color: var(--text-tertiary);
    font-size: 0.875rem;
}

.search-box input {
    width: 100%;
    padding: 8px 12px 8px 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
    outline: none;
    transition: all 0.2s;
}

.search-box input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Page Tree */
.page-tree {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.page-item {
    padding: 8px 12px;
    margin: 2px 0;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all 0.2s;
    user-select: none;
}

.page-item:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

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

.page-item i {
    font-size: 0.75rem;
    width: 16px;
}

.page-item .page-icon {
    opacity: 0.7;
}

.page-item .toggle-icon {
    cursor: pointer;
    transition: transform 0.2s;
}

.page-item .toggle-icon.expanded {
    transform: rotate(90deg);
}

.page-children {
    margin-left: 20px;
    display: none;
}

.page-children.expanded {
    display: block;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--background);
}

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

.page-title-input {
    flex: 1;
    font-size: 1.5rem;
    font-weight: 600;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

.page-title-input:hover,
.page-title-input:focus {
    background: var(--surface);
}

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

/* Editor Container */
.editor-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

.editor-pane,
.preview-pane {
    flex: 1;
    overflow: auto;
    padding: 24px;
}

.editor-pane {
    border-right: 1px solid var(--border);
}

.preview-pane.full-width {
    border-right: none;
}

#markdownEditor {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9375rem;
    line-height: 1.7;
    resize: none;
    color: var(--text-primary);
    background: transparent;
}

/* Markdown Preview Styles */
.markdown-content {
    max-width: 800px;
    margin: 0 auto;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-primary);
}

.markdown-content h1 {
    font-size: 2rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.markdown-content h2 {
    font-size: 1.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.markdown-content h3 {
    font-size: 1.25rem;
}

.markdown-content p {
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.markdown-content a {
    color: var(--primary-color);
    text-decoration: none;
}

.markdown-content a:hover {
    text-decoration: underline;
}

.markdown-content ul,
.markdown-content ol {
    margin-bottom: 16px;
    padding-left: 24px;
}

.markdown-content li {
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.markdown-content code {
    background: var(--surface);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.875rem;
    color: var(--danger);
}

.markdown-content pre {
    background: var(--surface);
    padding: 16px;
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 16px;
}

.markdown-content pre code {
    background: transparent;
    padding: 0;
    color: var(--text-primary);
}

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

.markdown-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 16px 0;
}

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

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

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

.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-tertiary);
}

.welcome-message h1 {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

/* Attachments Section */
.attachments-section {
    border-top: 1px solid var(--border);
    padding: 16px 24px;
    background: var(--surface);
}

.attachments-section h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.attachments-list {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.attachment-item:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.attachment-item i {
    font-size: 1rem;
}

.attachment-item .remove-attachment {
    margin-left: 8px;
    cursor: pointer;
    color: var(--text-tertiary);
}

.attachment-item .remove-attachment:hover {
    color: var(--danger);
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-publish,
.btn-icon {
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    outline: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    padding: 10px 16px;
}

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

.btn-secondary {
    background: var(--surface-hover);
    color: var(--text-primary);
    padding: 10px 16px;
}

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

.btn-publish {
    background: var(--success);
    color: white;
    padding: 10px 16px;
}

.btn-publish:hover:not(:disabled) {
    background: #059669;
}

.btn-icon {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px;
    width: 36px;
    height: 36px;
}

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

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--background);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: auto;
}

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

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-body {
    padding: 24px;
}

.modal-body h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.modal-body hr {
    border: none;
    border-top: 1px solid var(--border);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.form-group input[type="text"],
.form-group input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
}

.form-group input[type="text"]:focus,
.form-group input[type="password"]:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group small {
    display: block;
    margin-top: 6px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.form-group small a {
    color: var(--primary-color);
    text-decoration: none;
}

.form-group small a:hover {
    text-decoration: underline;
}

.connection-status {
    padding: 12px;
    border-radius: 6px;
    font-size: 0.875rem;
    margin-top: 16px;
}

.connection-status.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid var(--success);
}

.connection-status.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid var(--danger);
}

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

/* Loading Overlay */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 20px;
}

.loading-overlay.active {
    display: flex;
}

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

.loading-overlay p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

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

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

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: var(--banner-height);
        bottom: 0;
        z-index: 100;
        box-shadow: var(--shadow-lg);
    }

    .editor-pane,
    .preview-pane {
        padding: 16px;
    }

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

    .editor-pane {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
}

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

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

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

.page-item,
.attachment-item {
    animation: fadeIn 0.2s ease;
}

/* Print Styles */
@media print {
    .sidebar,
    .editor-header,
    .attachments-section,
    .github-banner {
        display: none;
    }

    .editor-pane {
        display: none;
    }

    .preview-pane {
        border: none;
    }
}
