:root {
    --bg-primary: #000000;
    --bg-secondary: #0d0d0d;
    --bg-tertiary: #1a1a1a;
    --bg-hover: #262626;
    --text-primary: #e7e7e7;
    --text-secondary: #a3a3a3;
    --text-muted: #737373;
    --border-color: #262626;
    --accent-color: #3b82f6;
    --user-bg: #1e3a5f;
    --grok-bg: transparent;
    --code-bg: #1e1e1e;
    --scrollbar-thumb: #404040;
    --scrollbar-track: #1a1a1a;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: #525252;
}

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

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

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.logo svg {
    color: var(--accent-color);
}

.actions {
    display: flex;
    gap: 12px;
}

.btn {
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

.btn-primary:hover {
    background: #2563eb;
}

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

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

.sidebar[hidden] {
    display: none;
}

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

.sidebar-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.sidebar-header .count {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 8px;
    border-radius: 12px;
}

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

.conversation-item {
    padding: 12px;
    margin-bottom: 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid transparent;
}

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

.conversation-item.active {
    background: var(--bg-tertiary);
    border-color: var(--accent-color);
}

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

.conversation-item-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.drop-zone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border-color);
    margin: 24px;
    border-radius: 16px;
    transition: all 0.3s;
}

.drop-zone[hidden] {
    display: none !important;
}

.drop-zone.dragover {
    border-color: var(--accent-color);
    background: rgba(59, 130, 246, 0.1);
}

.drop-content {
    text-align: center;
    color: var(--text-secondary);
}

.drop-content svg {
    margin-bottom: 16px;
}

.drop-content p {
    margin: 8px 0;
    font-size: 18px;
}

.drop-content .hint {
    font-size: 14px;
    color: var(--text-muted);
}

.conversation {
    flex: 1;
    overflow-y: auto;
    padding: 0 24px 24px;
}

.conversation-header {
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    padding: 24px 0 16px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 24px;
    z-index: 10;
}

.conversation-header h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.conversation-header .meta {
    font-size: 14px;
    color: var(--text-muted);
}

.messages {
    max-width: 900px;
    margin: 0 auto;
}

.message {
    margin-bottom: 24px;
    padding: 16px 20px;
    border-radius: 12px;
    animation: fadeIn 0.3s ease;
}

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

.message.human {
    background: var(--user-bg);
    margin-left: 48px;
}

.message.grok {
    background: var(--grok-bg);
    border: 1px solid var(--border-color);
}

.message-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.message.human .avatar {
    background: #3b82f6;
    color: white;
}

.message.grok .avatar {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.sender-name {
    font-weight: 600;
    font-size: 14px;
}

.message-time {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: auto;
}

.message-content {
    font-size: 15px;
    line-height: 1.7;
}

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

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

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    margin: 20px 0 12px;
    font-weight: 600;
}

.message-content h1 { font-size: 1.5em; }
.message-content h2 { font-size: 1.3em; }
.message-content h3 { font-size: 1.15em; }
.message-content h4 { font-size: 1em; }

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

.message-content li {
    margin: 6px 0;
}

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

.message-content code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: var(--code-bg);
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
    margin: 12px 0;
    position: relative;
}

.message-content pre code {
    background: transparent;
    padding: 0;
    font-size: 14px;
    line-height: 1.5;
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: #2d2d2d;
    border-radius: 8px 8px 0 0;
    margin-bottom: -8px;
    font-size: 12px;
    color: var(--text-muted);
}

.copy-btn {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

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

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

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

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

.message-content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 12px 0;
}

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

.branch-selector {
    margin-top: 12px;
    position: relative;
}

.branch-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

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

.branch-btn svg {
    transition: transform 0.2s;
}

.branch-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 4px;
    min-width: 300px;
    max-width: 500px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 100;
}

.branch-option {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.branch-option:hover {
    background: var(--bg-hover);
}

.branch-option.active {
    background: var(--bg-tertiary);
}

.branch-radio {
    color: var(--accent-color);
    font-size: 16px;
    line-height: 1;
    flex-shrink: 0;
}

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

@media (max-width: 768px) {
    .header {
        padding: 12px 16px;
    }

    .conversation {
        padding: 0 16px 16px;
    }

    .message {
        padding: 12px 16px;
    }

    .message.human {
        margin-left: 24px;
    }

    .drop-zone {
        margin: 16px;
    }
}
