:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #242424;
    --bg-elevated: #2a2a2a;
    --text-primary: #f5f5f5;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    --border-color: #333333;
    --border-light: #404040;
    --accent-primary: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --success: #22c55e;
    --success-glow: rgba(34, 197, 94, 0.3);
    --error: #ef4444;
    --error-glow: rgba(239, 68, 68, 0.3);
    --warning: #f59e0b;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    line-height: 1.5;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 50px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

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

.logo-icon {
    width: 22px;
    height: 22px;
    color: var(--accent-primary);
}

.logo-text {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.preview-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.toggle-btn {
    width: 36px;
    height: 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    transition: all var(--transition-fast);
}

.toggle-btn:hover {
    border-color: var(--border-light);
}

.toggle-slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.toggle-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.toggle-btn.active .toggle-slider {
    left: 18px;
    background: white;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    transition: all var(--transition-normal);
}

.status-badge.connected {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
}

.status-badge.connected .status-dot {
    background: var(--success);
    box-shadow: 0 0 8px var(--success-glow);
}

.status-badge.disconnected {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

.status-badge.disconnected .status-dot {
    background: var(--error);
    box-shadow: 0 0 8px var(--error-glow);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

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

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.editor-wrapper {
    flex: 1;
    display: flex;
    flex-direction: row;
    background: var(--bg-primary);
    overflow: hidden;
}

.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin: 10px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    overflow: hidden;
    min-width: 0;
}

.editor-wrapper.preview-active .editor-container {
    flex: 2;
}

#editor {
    flex: 1;
    width: 100%;
    padding: 14px;
    font-size: 14px;
    line-height: 1.6;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', 'Fira Code', 'Monaco', monospace;
}

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

.editor-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 8px 14px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
}

.char-count {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.preview-panel {
    display: none;
    flex: 1;
    flex-direction: column;
    margin: 10px 10px 10px 0;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border-left: 1px solid var(--border-color);
}

.editor-wrapper.preview-active .preview-panel {
    display: flex;
}

.preview-header {
    padding: 8px 14px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.preview-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.preview-content {
    flex: 1;
    padding: 14px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
}

.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
    margin-top: 0;
    margin-bottom: 12px;
    font-weight: 600;
    line-height: 1.3;
}

.preview-content h1 { font-size: 24px; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.preview-content h2 { font-size: 20px; }
.preview-content h3 { font-size: 18px; }
.preview-content h4 { font-size: 16px; }
.preview-content h5 { font-size: 15px; }
.preview-content h6 { font-size: 14px; color: var(--text-secondary); }

.preview-content p {
    margin: 0 0 12px 0;
}

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

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

.preview-content code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 13px;
}

.preview-content pre {
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 0 0 12px 0;
}

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

.preview-content blockquote {
    border-left: 3px solid var(--accent-primary);
    margin: 0 0 12px 0;
    padding-left: 12px;
    color: var(--text-secondary);
}

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

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

.preview-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 12px 0;
}

.preview-content img {
    max-width: 100%;
    border-radius: var(--radius-sm);
}

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

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

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

.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-section {
    padding: 14px;
}

.sidebar-section + .sidebar-section {
    border-top: 1px solid var(--border-color);
}

.online-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

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

.online-count {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--accent-primary);
    color: white;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
}

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

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

.icon-btn svg {
    width: 14px;
    height: 14px;
}

.user-card {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-status {
    font-size: 11px;
    color: var(--success);
}

.user-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    transition: all var(--transition-fast);
}

.user-item:last-child {
    border-bottom: none;
}

.user-item:hover {
    background: transparent;
}

.user-item .user-avatar {
    width: 36px;
    height: 36px;
    font-size: 14px;
    border-radius: 50%;
}

.user-item .user-info {
    flex: 1;
}

.typing-indicator {
    font-size: 11px;
    color: var(--accent-primary);
    animation: fadeIn 0.3s ease;
}

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

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

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

.modal-content {
    position: relative;
    width: 100%;
    max-width: 420px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

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

.modal-title {
    font-size: 16px;
    font-weight: 600;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

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

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    transition: all var(--transition-fast);
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

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

.color-options {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.color-option {
    width: 100%;
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.color-option:hover {
    transform: scale(1.1);
}

.color-option.selected {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--bg-secondary);
}

.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.color-picker {
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: transparent;
}

.color-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker::-webkit-color-swatch {
    border: none;
    border-radius: var(--radius-sm);
}

.color-preview {
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

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

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: 200px;
        border-left: none;
        border-top: 1px solid var(--border-color);
    }
    
    .online-section {
        flex: none;
    }
    
    .user-list {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
    }
    
    .user-item {
        flex-shrink: 0;
    }
}
