/* ContextBridge MVP - Chat UI */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-sidebar: #0f1729;
    --bg-input: #1e2a45;
    --bg-user-msg: #2563eb;
    --bg-assistant-msg: #1e293b;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --badge-gpt: #10a37f;
    --badge-gemini: #4285f4;
    --badge-claude: #d97706;
    --fallback-bg: #451a03;
    --fallback-border: #f59e0b;
}

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

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

.app {
    display: flex;
    height: 100vh;
    position: relative;
}

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

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

.logo {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--accent);
}

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

.session-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
    font-size: 14px;
    color: var(--text-secondary);
    transition: background 0.15s;
}

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

.session-item.active {
    background: var(--bg-input);
    color: var(--text-primary);
}

.session-item .title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-item .delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}

.session-item:hover .delete-btn {
    opacity: 1;
}

.session-item .delete-btn:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

/* Buttons */
.btn {
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}

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

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

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    width: 100%;
}

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

/* Main area */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Top bar */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

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

.model-selector label {
    font-size: 14px;
    color: var(--text-secondary);
}

.model-selector select {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 14px;
    cursor: pointer;
}

.health-indicators {
    display: flex;
    gap: 12px;
}

.health-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.health-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    background: var(--text-muted);
}

.health-dot.healthy {
    background: var(--success);
}

.health-dot.unhealthy {
    background: var(--danger);
}

/* Fallback banner */
.fallback-banner {
    background: var(--fallback-bg);
    border-bottom: 2px solid var(--fallback-border);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    color: var(--warning);
}

.fallback-banner.hidden {
    display: none;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
}

/* Chat messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

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

.empty-state h2 {
    font-size: 24px;
    color: var(--text-secondary);
}

.message {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.message-role {
    font-weight: 600;
    text-transform: capitalize;
}

.model-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    color: white;
}

.model-badge.gpt {
    background: var(--badge-gpt);
}

.model-badge.gemini {
    background: var(--badge-gemini);
}

.model-badge.claude {
    background: var(--badge-claude);
}

.message-content {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.6;
}

.message.user .message-content {
    background: var(--bg-user-msg);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--bg-assistant-msg);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message.assistant .message-content div {
    /* Style HTML responses from models */
    line-height: 1.6;
}

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

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

.message.assistant .message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.message.assistant .message-content pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

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

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

/* Model change divider */
.model-change-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 800px;
    width: 100%;
    margin: 8px auto;
    color: var(--text-muted);
    font-size: 13px;
}

.model-change-divider::before,
.model-change-divider::after {
    content: '';
    flex: 1;
    border-top: 1px dashed var(--border);
}

/* Loading indicator */
.loading-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

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

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

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

/* Input area */
.input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    display: flex;
    gap: 12px;
    align-items: flex-end;
    max-width: 100%;
}

.input-area textarea {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 150px;
    line-height: 1.5;
}

.input-area textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.btn-send {
    background: var(--accent);
    color: white;
    padding: 12px 24px;
    font-weight: 600;
    flex-shrink: 0;
}

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

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Usage panel */
.usage-panel {
    position: absolute;
    bottom: 60px;
    left: 16px;
    width: 260px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    z-index: 10;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.usage-panel.hidden {
    display: none;
}

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

.usage-header h3 {
    font-size: 15px;
}

.usage-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

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

.usage-item .model {
    font-weight: 600;
}

.usage-item .tokens {
    color: var(--text-secondary);
}

.hidden {
    display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

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

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

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