/* CSS Variables */
:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --bg-hover: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    --accent: #6366f1;
    --accent-hover: #5558e3;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --border: #333333;
    --border-color: #333333;
    --shadow: rgba(0, 0, 0, 0.3);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --font-mono: 'Menlo', 'Monaco', 'Courier New', monospace;
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Base */
html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

#app {
    height: 100%;
}

.screen {
    height: 100%;
}

.hidden {
    display: none !important;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

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

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

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

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

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

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

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

/* Login Screen */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-primary) 0%, #1a1a2e 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: 0 20px 40px var(--shadow);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.logo {
    font-size: 48px;
    margin-bottom: 16px;
}

.login-header h1 {
    font-size: 24px;
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-secondary);
}

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

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

.form-group input {
    width: 100%;
    padding: 12px 16px;
    font-size: 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

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

#login-form .btn {
    width: 100%;
    margin-top: 8px;
}

.error-message {
    color: var(--error);
    font-size: 14px;
    margin-top: 16px;
    text-align: center;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    padding: 0 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

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

.logo-small {
    font-size: 24px;
}

.header-left h1 {
    font-size: 18px;
    font-weight: 600;
}

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

#user-display {
    color: var(--text-secondary);
    font-size: 14px;
}

.status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 20px;
}

.status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

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

.status.connected::before {
    background: var(--success);
}

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

.status.disconnected::before {
    background: var(--error);
}

/* Main Container */
.main-container {
    display: flex;
    height: calc(100% - 60px);
}

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

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

.sidebar-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.session-item {
    display: flex;
    flex-direction: column;
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid transparent;
}

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

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

.session-header {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.session-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border-radius: var(--radius-md);
    font-size: 14px;
    flex-shrink: 0;
}

.session-info {
    flex: 1;
    min-width: 0;
}

.session-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-status {
    font-size: 11px;
    color: var(--text-muted);
}

.session-close {
    opacity: 0;
    padding: 4px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    flex-shrink: 0;
}

.session-item:hover .session-close {
    opacity: 1;
}

.session-close:hover {
    background: var(--error);
    color: white;
}

/* Context Bar (Cline-style) */
.context-bar-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 8px 0;
    border-top: 1px solid var(--border);
    font-size: 11px;
    font-family: var(--font-mono);
}

.context-current {
    color: var(--text-secondary);
    min-width: 35px;
    text-align: right;
    transition: all 0.3s ease;
}

.context-current.updating {
    color: #f1c40f;
    animation: statPulse 0.5s ease-out;
}

.context-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.context-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #3498db, #2980b9);
    border-radius: 3px;
    transition: width 0.5s ease-out, background 0.3s ease;
    position: relative;
}

.context-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.2) 50%,
        transparent 100%
    );
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

.context-bar-fill.warning {
    background: linear-gradient(90deg, #f39c12, #e67e22);
}

.context-bar-fill.danger {
    background: linear-gradient(90deg, #e74c3c, #c0392b);
    animation: pulseDanger 1s ease-in-out infinite;
}

@keyframes pulseDanger {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

.context-max {
    color: var(--text-muted);
    min-width: 35px;
}

/* Session Stats (Cline-style) */
.session-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px 12px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    font-size: 11px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    color: var(--text-muted);
    font-weight: 400;
}

.stat-value {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-weight: 500;
    transition: all 0.3s ease;
}

.stat-value.cost-value {
    color: #2ecc71;
}

/* Animation for stat updates */
.stat-value.updating {
    animation: statPulse 0.5s ease-out;
    color: #f1c40f;
}

.stat-value.cost-value.updating {
    color: #27ae60;
    text-shadow: 0 0 8px rgba(46, 204, 113, 0.6);
}

@keyframes statPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
    100% {
        transform: scale(1);
    }
}

/* Loading indicator for active request */
.session-item.api-active .session-icon {
    animation: iconPulse 1s ease-in-out infinite;
}

.session-item.api-active::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: #f1c40f;
    border-radius: 50%;
    animation: blink 1s ease-in-out infinite;
}

.session-item {
    position: relative;
}

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

@keyframes blink {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.4;
        transform: scale(0.8);
    }
}

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

.server-info {
    font-size: 12px;
    color: var(--text-muted);
}

.server-info .label {
    color: var(--text-secondary);
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Tab Bar */
.tab-bar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
}

.tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
}

.tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

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

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    font-size: 14px;
    color: var(--text-muted);
    border-radius: 50%;
    transition: all 0.2s;
}

.tab-close:hover {
    background: var(--error);
    color: white;
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.no-session {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.no-session-content {
    text-align: center;
}

.no-session .icon {
    font-size: 64px;
    display: block;
    margin-bottom: 16px;
}

.no-session h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

.no-session p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* Chat Panel */
.chat-panel {
    display: none;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
    scroll-behavior: smooth;
}

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

.messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 20px;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.6;
}

.message.user {
    align-self: flex-end;
    background: var(--accent);
    color: white;
}

.message.assistant {
    align-self: flex-start;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}

.message.system {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    padding: 8px 16px;
}

.message.error {
    align-self: center;
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    border: 1px solid var(--error);
}

.message pre {
    background: var(--bg-primary);
    padding: 12px;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 8px 0;
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

.message code {
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

/* Terminal output styles */
.message .code-block {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px;
    margin: 8px 0;
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.4;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* Terminal colors */
.message span[style*="color"] {
    /* Ensure terminal colors are visible */
}

/* Dim text */
.message span[style*="opacity"] {
    opacity: 0.7;
}

/* Blink animation removed - not used */

/* Input Area */
.input-area {
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.input-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#message-input {
    flex: 1;
    padding: 12px 16px;
    font-size: 14px;
    font-family: inherit;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    resize: none;
    max-height: 150px;
    transition: border-color 0.2s;
}

#message-input:focus {
    outline: none;
    border-color: var(--accent);
}

.input-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
}

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

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

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

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

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

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

/* OAuth Message Box */
.message.oauth {
    align-self: stretch;
    max-width: 100%;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
    border: 2px solid var(--accent);
    padding: 0;
}

.oauth-box {
    padding: 20px;
}

.oauth-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    font-size: 18px;
}

.oauth-icon {
    font-size: 24px;
}

.oauth-message {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.oauth-url-container {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.oauth-url-link {
    flex: 1;
    display: inline-block;
    padding: 14px 24px;
    background: var(--accent);
    color: white;
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    text-align: center;
    transition: all 0.2s;
}

.oauth-url-link:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.oauth-copy-btn {
    padding: 14px 20px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.oauth-copy-btn:hover {
    background: var(--bg-hover);
}

.oauth-url-display {
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-primary);
    padding: 12px;
    border-radius: var(--radius-sm);
    word-break: break-all;
    margin-bottom: 20px;
}

.oauth-instructions {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
}

.oauth-instructions strong {
    display: block;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.oauth-instructions ol {
    padding-left: 20px;
    color: var(--text-secondary);
}

.oauth-instructions li {
    margin-bottom: 8px;
}

.oauth-input-hint {
    font-size: 13px;
    color: var(--accent);
    text-align: center;
    padding: 12px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: var(--radius-sm);
}

/* API Messages (from Cline/OpenAI API) */
.message.api-user,
.message.api-assistant {
    padding: 0;
    background: transparent;
}

.api-message-box {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    margin: var(--spacing-xs) 0;
}

.api-message-box.api-user {
    border-left: 3px solid #9b59b6;
    background: rgba(155, 89, 182, 0.1);
}

.api-message-box.api-assistant {
    border-left: 3px solid #3498db;
    background: rgba(52, 152, 219, 0.1);
}

.api-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
    font-size: 0.75rem;
}

.api-badge {
    background: linear-gradient(135deg, #9b59b6, #3498db);
    color: white;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.api-role {
    color: var(--text-secondary);
    font-weight: 500;
}

.api-request-id {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.7rem;
}

.api-content {
    color: var(--text-primary);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.api-cost {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    margin-top: var(--spacing-sm);
    padding-top: var(--spacing-sm);
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
}

.cost-label {
    color: var(--text-secondary);
}

.cost-value {
    color: #2ecc71;
    font-weight: 600;
    font-family: var(--font-mono);
}

.api-cost .tokens {
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.api-cost .duration {
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* Project Selector */
.sidebar-section {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-section h2 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.project-selector {
    display: flex;
    gap: 6px;
    align-items: center;
}

.project-selector select {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    padding: 6px 8px;
    font-size: 13px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    text-overflow: ellipsis;
}

.project-selector select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 400px;
    max-width: 90vw;
}

.modal-content h3 {
    font-size: 16px;
    margin-bottom: 16px;
}

.modal-content .form-group {
    margin-bottom: 12px;
}

.modal-content label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.modal-content input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
}

.modal-content input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

/* Modal Tabs */
.modal-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.modal-tab {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-tab:hover {
    color: var(--text-primary);
}

.modal-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.modal-tab-content {
    /* shown/hidden via .hidden class */
}

/* Repo List */
.repo-list {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.repo-loading {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.repo-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

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

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

.repo-info {
    flex: 1;
    min-width: 0;
    margin-right: 12px;
}

.repo-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.repo-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 500;
    color: var(--warning);
    background: rgba(245, 158, 11, 0.15);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    margin-left: 6px;
    vertical-align: middle;
}

.repo-desc {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.repo-clone-btn {
    flex-shrink: 0;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .header-left h1 {
        display: none;
    }

    .oauth-url-container {
        flex-direction: column;
    }

    .api-cost {
        flex-wrap: wrap;
    }
}
